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.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ButcherFactory.BO.LocalBL
|
|
{
|
|
public static class SegmentProductionBL
|
|
{
|
|
const string RpcPath = @"/MainSystem/B3ClientService/Rpcs/SegmentProductionRpc/";
|
|
|
|
public static BindingList<SegmentProduction> GetListByState(bool submited)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(SegmentProduction)));
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Columns.Add(DQSelectColumn.Field("RowIndex"));
|
|
query.Columns.Add(DQSelectColumn.Field("BarCode"));
|
|
query.Columns.Add(DQSelectColumn.Field("Weight"));
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Name"));
|
|
query.Columns.Add(DQSelectColumn.Field("GroupID"));
|
|
query.Columns.Add(DQSelectColumn.Field("TrunOutID"));
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Delete", false), DQCondition.EQ("Submited", submited)));
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true));
|
|
if (submited)
|
|
query.Range = SelectRange.Top(20);
|
|
var list = new BindingList<SegmentProduction>();
|
|
using (var session = DmoSession.New())
|
|
{
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var entity = new SegmentProduction();
|
|
entity.ID = (long)reader[0];
|
|
entity.RowIndex = (int?)reader[1];
|
|
entity.BarCode = (string)reader[2];
|
|
entity.Weight = (decimal)reader[3];
|
|
entity.Goods_Name = (string)reader[4];
|
|
entity.GroupID = (long?)reader[5];
|
|
entity.TrunOutID = (long?)reader[6];
|
|
entity.Submited = submited;
|
|
list.Add(entity);
|
|
}
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public static SegmentProduction Insert(long goodsID, decimal weight, long? workUnitID, long productBatchID, DateTime batchDate)
|
|
{
|
|
using (var session = DmoSession.New())
|
|
{
|
|
var entity = new SegmentProduction();
|
|
entity.Goods_ID = goodsID;
|
|
entity.Weight = weight;
|
|
entity.UserID = AppContext.Worker.ID;
|
|
entity.WorkUnit_ID = workUnitID;
|
|
entity.ProductBatch_ID = productBatchID;
|
|
entity.RowIndex = GenerateRowIndex(productBatchID, session);
|
|
entity.BarCode = string.Format("A26091201{0:yyyyMMdd}{1:00000}", batchDate, entity.RowIndex);
|
|
session.Insert(entity);
|
|
session.Commit();
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
static int GenerateRowIndex(long productBatchID, IDmoSession session)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias("_main", typeof(SegmentProduction)));
|
|
query.Columns.Add(DQSelectColumn.Max("RowIndex"));
|
|
query.Where.Conditions.Add(DQCondition.EQ("ProductBatch_ID", productBatchID));
|
|
return (query.EExecuteScalar<int?>(session) ?? 0) + 1;
|
|
}
|
|
|
|
public static long SetListGroupID(IEnumerable<long> ids)
|
|
{
|
|
using (var session = DmoSession.New())
|
|
{
|
|
var groupID = ids.Max();
|
|
BatchUpdate(ids, session, new Tuple<string, object>("GroupID", groupID));
|
|
session.Commit();
|
|
return groupID;
|
|
}
|
|
}
|
|
|
|
static void BatchUpdate(IEnumerable<long> ids, IDmoSession session, params Tuple<string, object>[] keyValues)
|
|
{
|
|
var update = new DQUpdateDom(typeof(SegmentProduction));
|
|
update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray()));
|
|
foreach (var item in keyValues)
|
|
update.Columns.Add(new DQUpdateColumn(item.Item1, item.Item2));
|
|
update.Columns.Add(new DQUpdateColumn("Sync", false));
|
|
update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1))));
|
|
session.ExecuteNonQuery(update);
|
|
}
|
|
|
|
public static void BatchUpdate(IEnumerable<long> ids, params Tuple<string, object>[] keyValues)
|
|
{
|
|
using (var session = DmoSession.New())
|
|
{
|
|
BatchUpdate(ids, session, keyValues);
|
|
session.Commit();
|
|
}
|
|
}
|
|
|
|
public static void TrunBack(IEnumerable<long> ids)
|
|
{
|
|
using (var session = DmoSession.New())
|
|
{
|
|
BatchUpdate(ids, session, new Tuple<string, object>("TrunOutID", null));
|
|
session.Commit();
|
|
}
|
|
}
|
|
|
|
public static void Delete(long id)
|
|
{
|
|
var delete = new DQDeleteDom(typeof(SegmentProduction));
|
|
delete.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
delete.EExecute();
|
|
}
|
|
}
|
|
}
|