From b3213dd851773d584267be1ce832cc5aaba68661 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Mon, 21 May 2018 17:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=89=B2=E5=93=81=E7=A7=B0=E9=87=8D?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=E8=B0=83=E6=95=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs | 4 + ButcherFactory.BO/BaseInfo/Goods.cs | 4 + ButcherFactory.BO/Bill/SegmentProduction.cs | 4 + ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs | 4 +- ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs | 4 +- .../LocalBL/FormClientGoodsSetBL.cs | 2 + .../LocalBL/SegmentProductionBL.cs | 93 ++++++++++++++++++- ButcherFactory.BO/Utils/AppContext.cs | 2 + .../SegmentProductionForm.cs | 31 ++++--- .../SegmentProductionPrint.cs | 8 +- 10 files changed, 138 insertions(+), 18 deletions(-) diff --git a/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs b/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs index 0d27008..0493d4f 100644 --- a/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs +++ b/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs @@ -35,6 +35,10 @@ namespace ButcherFactory.BO [Join("Goods_ID", "ID")] public string Goods_Name { get; set; } + [ReferenceTo(typeof(Goods), "Spec")] + [Join("Goods_ID", "ID")] + public string Goods_Spec { get; set; } + public decimal? StandardWeight { get; set; } public decimal? StandardWeightUp { get; set; } diff --git a/ButcherFactory.BO/BaseInfo/Goods.cs b/ButcherFactory.BO/BaseInfo/Goods.cs index 25166b6..10f1bbb 100644 --- a/ButcherFactory.BO/BaseInfo/Goods.cs +++ b/ButcherFactory.BO/BaseInfo/Goods.cs @@ -11,6 +11,10 @@ namespace ButcherFactory.BO [KeyField("ID", KeyGenType.assigned)] public class Goods : BaseInfo { + public string Code { get; set; } + + public string Spec { get; set; } + public string MainUnit { get; set; } public decimal? Standard { get; set; } diff --git a/ButcherFactory.BO/Bill/SegmentProduction.cs b/ButcherFactory.BO/Bill/SegmentProduction.cs index 33d5b96..96a0f6a 100644 --- a/ButcherFactory.BO/Bill/SegmentProduction.cs +++ b/ButcherFactory.BO/Bill/SegmentProduction.cs @@ -27,6 +27,10 @@ namespace ButcherFactory.BO [Join("Goods_ID", "ID")] public string Goods_Name { get; set; } + [ReferenceTo(typeof(Goods), "Spec")] + [Join("Goods_ID", "ID")] + public string Goods_Spec { get; set; } + public long? GroupID { get; set; } public bool Submited { get; set; } diff --git a/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs b/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs index e4d3500..7bf71b1 100644 --- a/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs +++ b/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs @@ -218,8 +218,10 @@ namespace ButcherFactory.BO.LocalBL class CarcassInStoreObj { + [JsonIgnore] public long ID { get; set; } - public int RowVersion { get; set; } + [JsonIgnore] + public long RowVersion { get; set; } public string BarCode { get; set; } public long? InStoreWorker_ID { get; set; } public long? WorkUnit_ID { get; set; } diff --git a/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs b/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs index 7e11b94..1c37238 100644 --- a/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs +++ b/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs @@ -306,8 +306,10 @@ namespace ButcherFactory.BO.LocalBL class CarcassTakeOutObj { + [JsonIgnore] public long ID { get; set; } - public int RowVersion { get; set; } + [JsonIgnore] + public long RowVersion { get; set; } public string BarCode { get; set; } public long? TakeOutWorker_ID { get; set; } public long? WorkUnit_ID { get; set; } diff --git a/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs b/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs index de6cbe4..b2450d5 100644 --- a/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs +++ b/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs @@ -65,6 +65,7 @@ namespace ButcherFactory.BO.LocalBL 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.OrderBy.Expressions.Add(DQOrderByExpression.Create(main, "ID")); query.OrderBy.Expressions.Add(DQOrderByExpression.Create(detail, "ID")); @@ -83,6 +84,7 @@ namespace ButcherFactory.BO.LocalBL entity.StandardWeight = (decimal?)reader[3]; entity.StandardWeightUp = (decimal?)reader[4]; entity.StandardWeightLow = (decimal?)reader[5]; + entity.Goods_Spec = (string)reader[6]; if (result.ContainsKey(key)) result[key].Add(entity); else diff --git a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs index 0fcc74b..4f69309 100644 --- a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs +++ b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs @@ -2,6 +2,8 @@ using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2.DQuery; using Forks.EnterpriseServices.SqlDoms; +using Forks.JsonRpc.Client; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -25,6 +27,7 @@ namespace ButcherFactory.BO.LocalBL query.Columns.Add(DQSelectColumn.Field("Goods_Name")); query.Columns.Add(DQSelectColumn.Field("GroupID")); query.Columns.Add(DQSelectColumn.Field("TrunOutID")); + query.Columns.Add(DQSelectColumn.Field("Goods_Spec")); query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Delete", false), DQCondition.EQ("Submited", submited))); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); if (submited) @@ -44,6 +47,7 @@ namespace ButcherFactory.BO.LocalBL entity.Goods_Name = (string)reader[4]; entity.GroupID = (long?)reader[5]; entity.TrunOutID = (long?)reader[6]; + entity.Goods_Spec = (string)reader[7]; entity.Submited = submited; list.Add(entity); } @@ -64,7 +68,7 @@ namespace ButcherFactory.BO.LocalBL 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); + entity.BarCode = string.Format("260912011{0:yyyyMMdd}{1:00000}", batchDate, entity.RowIndex); session.Insert(entity); session.Commit(); return entity; @@ -125,5 +129,92 @@ namespace ButcherFactory.BO.LocalBL delete.Where.Conditions.Add(DQCondition.EQ("ID", id)); delete.EExecute(); } + + public static void UploadSegmentInfo() + { + try + { + using (var session = DmoSession.New()) + { + var needUpload = GetUnSyncData(session); + if (needUpload.Count == 0) + return; + + var json = JsonConvert.SerializeObject(needUpload); + RpcFacade.Call(RpcPath + "Insert", json); + foreach (var item in needUpload) + SetLocalAsSyncd(item, session); + session.Commit(); + } + } + catch + { +#if DEBUG + throw; +#endif + } + } + + static List GetUnSyncData(IDmoSession session) + { + var query = new DQueryDom(new JoinAlias("_main", typeof(SegmentProduction))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Columns.Add(DQSelectColumn.Field("RowVersion")); + query.Columns.Add(DQSelectColumn.Field("BarCode")); + query.Columns.Add(DQSelectColumn.Field("UserID")); + query.Columns.Add(DQSelectColumn.Field("WorkUnit_ID")); + query.Columns.Add(DQSelectColumn.Field("ProductBatch_ID")); + query.Columns.Add(DQSelectColumn.Field("Goods_ID")); + query.Columns.Add(DQSelectColumn.Field("Weight")); + query.Columns.Add(DQSelectColumn.Field("CreateTime")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Submited", true), DQCondition.EQ("Sync", false))); + query.Range = SelectRange.Top(10); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); + + var upload = new List(); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var obj = new SegmentProductionMin(); + obj.ID = (long)reader[0]; + obj.RowVersion = (int)reader[1]; + obj.BarCode = (string)reader[2]; + obj.Worker_ID = (long)reader[3]; + obj.WorkUnit_ID = (long?)reader[4]; + obj.ProductBatch_ID = (long?)reader[5]; + obj.Goods_ID = (long)reader[6]; + obj.Weight = (decimal)reader[7]; + obj.ProductTime = (DateTime)reader[8]; + upload.Add(obj); + } + } + return upload; + } + + static void SetLocalAsSyncd(SegmentProductionMin obj, IDmoSession session) + { + var update = new DQUpdateDom(typeof(SegmentProduction)); + update.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", obj.ID), DQCondition.EQ("RowVersion", obj.RowVersion))); + update.Columns.Add(new DQUpdateColumn("Sync", true)); + session.ExecuteNonQuery(update); + } + } + + class SegmentProductionMin + { + [JsonIgnore] + public long ID { get; set; } + [JsonIgnore] + public long RowVersion { get; set; } + public string BarCode { get; set; } + public DateTime? ProductTime { get; set; } + public long? Worker_ID { get; set; } + public long? WorkUnit_ID { get; set; } + public long? ProductBatch_ID { get; set; } + public long? Goods_ID { get; set; } + public decimal? Weight { get; set; } + public DateTime? InStoreTime { get; set; } + } } diff --git a/ButcherFactory.BO/Utils/AppContext.cs b/ButcherFactory.BO/Utils/AppContext.cs index 1ba2f65..effb2e2 100644 --- a/ButcherFactory.BO/Utils/AppContext.cs +++ b/ButcherFactory.BO/Utils/AppContext.cs @@ -37,6 +37,8 @@ namespace ButcherFactory.BO.Utils public string SqlConnection { get; set; } + public string TraceBackUrl { get; set; } + public void Save() { XmlUtil.SerializerObjToFile(this); diff --git a/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs b/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs index eb8600b..641a04a 100644 --- a/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs +++ b/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs @@ -152,6 +152,7 @@ namespace ButcherFactory.SegmentProduction_ Start(true); var entity = SegmentProductionBL.Insert(detail.Goods_ID, weight, workUnitID, batchID.Value, batchDate.Value); entity.Goods_Name = detail.Goods_Name; + entity.Goods_Spec = detail.Goods_Spec; GoodsLabel.Text = entity.Goods_Name; unSubmitList.Insert(0, entity); historyList.Insert(0, entity); @@ -185,18 +186,18 @@ namespace ButcherFactory.SegmentProduction_ void UpLoadLocalData() { - //while (true) - //{ - // if (this.IsHandleCreated) - // { - // this.Invoke(new Action(() => - // { - // if (netStateWatch1.NetState) - // CarcassInStoreBL.UploadCarcassInfo(); - // })); - // } - // Thread.Sleep(2000); - //} + while (true) + { + if (this.IsHandleCreated) + { + this.Invoke(new Action(() => + { + if (netStateWatch1.NetState) + SegmentProductionBL.UploadSegmentInfo(); + })); + } + Thread.Sleep(2000); + } } private void closeBtn_Click(object sender, EventArgs e) @@ -215,11 +216,15 @@ namespace ButcherFactory.SegmentProduction_ if (arr.Any()) { var groupID = SegmentProductionBL.SetListGroupID(arr.Select(x => x.ID)); + var bk = new List(); foreach (var item in arr) + { item.GroupID = groupID; + bk.Add(item); + } Start(false); if (barPrintCheck.Checked) - SegmentProductionPrint.PrintEnd(arr); + SegmentProductionPrint.PrintEnd(bk); } else throw new Exception("本次开始之后未生产任何商品"); diff --git a/ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs b/ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs index 319dee0..6a41c42 100644 --- a/ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs +++ b/ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs @@ -1,4 +1,5 @@ using ButcherFactory.BO; +using ButcherFactory.BO.Utils; using System; using System.Collections.Generic; using System.IO; @@ -20,15 +21,18 @@ namespace ButcherFactory.SegmentProduction_ dt = DateTime.Today; var dic = new Dictionary(); dic.Add("$Goods_Name", entity.Goods_Name); + dic.Add("$Goods_Spec", entity.Goods_Spec); + dic.Add("$Weight", entity.Weight.ToString("#0.######")); dic.Add("$Date", dt.Value.ToString("yyyy/MM/dd")); var imgUrl = string.Format(IMGFILE, id); - BwpClientPrint.BwpClientWebPrint.Create2DPic(entity.BarCode, imgUrl, 120); + var url = string.Format(AppContext.ConnectInfo.TraceBackUrl + "?code={0}", entity.BarCode); + BwpClientPrint.BwpClientWebPrint.Create2DPic(url, imgUrl, 120); dic.Add("$ImageUrl", imgUrl); BwpClientPrint.BwpClientWebPrint.Print(PRINTFILE, dic); AfterPrint(); } - public static void PrintEnd(IEnumerable list) + public static void PrintEnd(List list) { string firstRow = "{0}:{1}{2}"; string template = "{0}:{1}{2}";