屠宰场管理服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.1 KiB

using BWP.B3ClientService.BO;
using BWP.B3Frameworks.Utils;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSingSoft.WebPluginFramework;
namespace BWP.B3ClientService.BL
{
public static class GradeAndWeightBL
{
public static void UpdataOrInsert(GradeAndWeight_Detail obj, IDmoSession session)
{
if (string.IsNullOrEmpty(obj.BarCode))
return;
var id = GetID(obj.BarCode, session);
if (id.HasValue)
Update(id.Value, obj, session);
else
Insert(obj, session);
}
static long? GetID(string code, IDmoSession session)
{
var query = new DQueryDom(new JoinAlias(typeof(CarcassFullInfo)));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Where.Conditions.Add(DQCondition.EQ("BarCode", code));
return query.EExecuteScalar<long?>(session);
}
static void Update(long id, GradeAndWeight_Detail obj, IDmoSession session)
{
var update = new DQUpdateDom(typeof(CarcassFullInfo));
update.Columns.Add(new DQUpdateColumn("ButcherDate", obj.Date));
update.Columns.Add(new DQUpdateColumn("GradeTime", obj.Time));
update.Columns.Add(new DQUpdateColumn("GradeProductBatch_ID", obj.ProductBatch_ID));
//update.Columns.Add(new DQUpdateColumn("GradeWorker_ID", obj.Worker_ID));
update.Columns.Add(new DQUpdateColumn("Livestock_ID", obj.Livestock_ID));
update.Columns.Add(new DQUpdateColumn("GradeWeight", obj.Weight));
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
session.ExecuteNonQuery(update);
}
static void Insert(GradeAndWeight_Detail obj, IDmoSession session)
{
var entity = new CarcassFullInfo();
entity.BarCode = obj.BarCode;
entity.ButcherDate = obj.Date;
entity.GradeTime = obj.Time;
entity.GradeProductBatch_ID = obj.ProductBatch_ID;
//entity.GradeWorker_ID = obj.Worker_ID;
entity.Livestock_ID = obj.Livestock_ID;
entity.GradeWeight = obj.Weight;
session.Insert(entity);
}
public static void Delete(string barCode, IDmoSession session)
{
if (string.IsNullOrEmpty(barCode))
return;
var infos = GetExistInfo(barCode, session);
if (infos == null)
return;
if (infos.Item2.HasValue)
Update(infos.Item1, new GradeAndWeight_Detail(), session);
else
Delete(infos.Item1, session);
}
static void Delete(long id, IDmoSession session)
{
var delete = new DQDeleteDom(typeof(CarcassFullInfo));
delete.Where.Conditions.Add(DQCondition.EQ("ID", id));
session.ExecuteNonQuery(delete);
}
static Tuple<long, DateTime?> GetExistInfo(string barCode, IDmoSession session)
{
var query = new DQueryDom(new JoinAlias(typeof(CarcassFullInfo)));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Columns.Add(DQSelectColumn.Field("InStoreTime"));
query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode));
return query.EExecuteScalar<long, DateTime?>(session);
}
}
}