|
|
using ButcherFactory.BO.Utils;
|
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace ButcherFactory.BO.LocalBL
|
|
|
{
|
|
|
public static class FormClientGoodsSetBL
|
|
|
{
|
|
|
public static IEnumerable<ClientGoodsSet_Detail> GetGoodsList()
|
|
|
{
|
|
|
var main = new JoinAlias(typeof(ClientGoodsSet));
|
|
|
var detail = new JoinAlias(typeof(ClientGoodsSet_Detail));
|
|
|
var query = new DQueryDom(main);
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ClientGoodsSet_ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Name", detail));
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create(detail, "Goods_ID"));
|
|
|
var list = query.EExecuteList<long, string>();
|
|
|
return list.Select(x => new ClientGoodsSet_Detail { Goods_ID = x.Item1, Goods_Name = x.Item2 });
|
|
|
}
|
|
|
|
|
|
public static Dictionary<string, IEnumerable<ClientGoodsSet_Detail>> GetGoodsSetDic()
|
|
|
{
|
|
|
var main = new JoinAlias(typeof(ClientGoodsSet));
|
|
|
var detail = new JoinAlias(typeof(ClientGoodsSet_Detail));
|
|
|
var set = new JoinAlias(typeof(GoodsSetTemp));
|
|
|
var query = new DQueryDom(main);
|
|
|
query.RegisterQueryTable(typeof(GoodsSetTemp), new string[] { "DetailID" }, GoodsSetTemp.GetQueryDom());
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ClientGoodsSet_ID"));
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(set), DQCondition.EQ(detail, "ID", set, "DetailID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Name", main));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Name", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("DetailID", set));
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create(main, "ID"));
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create(detail, "ID"));
|
|
|
var list = query.EExecuteList<string, string, long, long?>();
|
|
|
var result = new Dictionary<string, IEnumerable<ClientGoodsSet_Detail>>();
|
|
|
foreach (var item in list.GroupBy(x => x.Item1))
|
|
|
{
|
|
|
var arr = item.Select(x => new ClientGoodsSet_Detail { Goods_Name = x.Item2, ID = x.Item3, Selected = x.Item4.HasValue });
|
|
|
result.Add(item.Key, arr);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static Dictionary<string, List<ClientGoodsSet_Detail>> GetSelectedDetail()
|
|
|
{
|
|
|
var main = new JoinAlias(typeof(ClientGoodsSet));
|
|
|
var detail = new JoinAlias(typeof(ClientGoodsSet_Detail));
|
|
|
var set = new JoinAlias(typeof(GoodsSetTemp));
|
|
|
var query = new DQueryDom(main);
|
|
|
query.RegisterQueryTable(typeof(GoodsSetTemp), new string[] { "DetailID" }, GoodsSetTemp.GetQueryDom());
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ClientGoodsSet_ID"));
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(set), DQCondition.EQ(detail, "ID", set, "DetailID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Name", main));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Name", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("StandardWeight", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("StandardWeightUp", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("StandardWeightLow", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Spec", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Code", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("GoodsType", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("StandardPic", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("MainUnit", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ShotPrintName", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("EachNumber", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("NoTotalCode", detail));
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create(main, "ID"));
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create(detail, "ID"));
|
|
|
|
|
|
var result = new Dictionary<string, List<ClientGoodsSet_Detail>>();
|
|
|
using (var session = DmoSession.New())
|
|
|
{
|
|
|
using (var reader = session.ExecuteReader(query))
|
|
|
{
|
|
|
var key = string.Empty;
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
key = (string)reader[0];
|
|
|
var entity = new ClientGoodsSet_Detail();
|
|
|
entity.Goods_ID = (long)reader[1];
|
|
|
entity.Goods_Name = (string)reader[2];
|
|
|
entity.StandardWeight = (decimal?)reader[3];
|
|
|
entity.StandardWeightUp = (decimal?)reader[4];
|
|
|
entity.StandardWeightLow = (decimal?)reader[5];
|
|
|
entity.Goods_Spec = (string)reader[6];
|
|
|
entity.Goods_Code = (string)reader[7];
|
|
|
entity.GoodsType = (short?)reader[8];
|
|
|
entity.StandardPic = (bool)reader[9];
|
|
|
entity.MainUnit = (string)reader[10];
|
|
|
entity.ShotPrintName = (string)reader[11];
|
|
|
entity.EachNumber = (int?)reader[12];
|
|
|
entity.NoTotalCode = (bool)reader[13];
|
|
|
if (result.ContainsKey(key))
|
|
|
result[key].Add(entity);
|
|
|
else
|
|
|
result.Add(key, new List<ClientGoodsSet_Detail> { entity });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static void InsertWorkerGoodsSet(long detailID)
|
|
|
{
|
|
|
using (var session = DmoSession.New())
|
|
|
{
|
|
|
if (!ExistSet(detailID, session))
|
|
|
{
|
|
|
var entity = new WorkerGoodsSetProfile { Worker_ID = AppContext.Worker.ID, ClientGoodsSet_Detail_ID = detailID };
|
|
|
session.Insert(entity);
|
|
|
session.Commit();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static bool ExistSet(long detailID, IDmoSession session)
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WorkerGoodsSetProfile)));
|
|
|
query.Columns.Add(DQSelectColumn.Create(DQExpression.Value(1), "c"));
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Worker_ID", AppContext.Worker.ID), DQCondition.EQ("ClientGoodsSet_Detail_ID", detailID)));
|
|
|
return query.EExecuteScalar(session) != null;
|
|
|
}
|
|
|
|
|
|
public static void DeleteWorkGoodsSet(long detailID)
|
|
|
{
|
|
|
var delete = new DQDeleteDom(typeof(WorkerGoodsSetProfile));
|
|
|
delete.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Worker_ID", AppContext.Worker.ID), DQCondition.EQ("ClientGoodsSet_Detail_ID", detailID)));
|
|
|
delete.EExecute();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class GoodsSetTemp
|
|
|
{
|
|
|
public long DetailID { get; set; }
|
|
|
|
|
|
public static DQueryDom GetQueryDom()
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WorkerGoodsSetProfile)));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ClientGoodsSet_Detail_ID"));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Worker_ID", AppContext.Worker.ID));
|
|
|
return query;
|
|
|
}
|
|
|
}
|
|
|
}
|