diff --git a/ButcherFactory.BO/Base/ExtensionObj.cs b/ButcherFactory.BO/Base/ExtensionObj.cs new file mode 100644 index 0000000..198c013 --- /dev/null +++ b/ButcherFactory.BO/Base/ExtensionObj.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ButcherFactory.BO +{ + public class ExtensionObj + { + public long? LongExt1 { get; set; } + + public long? LongExt2 { get; set; } + + public decimal? DecimalExt1 { get; set; } + + public string StringExt1 { get; set; } + } +} diff --git a/ButcherFactory.BO/Base/SimpleBackObjs.cs b/ButcherFactory.BO/Base/SimpleBackObjs.cs deleted file mode 100644 index 84b40f4..0000000 --- a/ButcherFactory.BO/Base/SimpleBackObjs.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ButcherFactory.BO -{ - public class IDRowVersion - { - public long ID { get; set; } - - public int RowVersion { get; set; } - } -} diff --git a/ButcherFactory.BO/Base/SyncBill.cs b/ButcherFactory.BO/Base/SyncBill.cs index 004b682..71c2073 100644 --- a/ButcherFactory.BO/Base/SyncBill.cs +++ b/ButcherFactory.BO/Base/SyncBill.cs @@ -16,7 +16,7 @@ namespace ButcherFactory.BO public int RowVersion { get; set; } [DbColumn(DbType = SqlDbType.DateTime)] - public DateTime? CreateTime { get; set; } + public DateTime CreateTime { get; set; } public long UserID { get; set; } diff --git a/ButcherFactory.BO/Bill/CarcassInStore.cs b/ButcherFactory.BO/Bill/CarcassInStore.cs index ac93939..ea05c11 100644 --- a/ButcherFactory.BO/Bill/CarcassInStore.cs +++ b/ButcherFactory.BO/Bill/CarcassInStore.cs @@ -1,4 +1,5 @@ -using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DataDictionary; +using Forks.EnterpriseServices.DomainObjects2; using System; using System.Collections.Generic; using System.Linq; @@ -8,6 +9,8 @@ using System.Threading.Tasks; namespace ButcherFactory.BO { [MapToTable("Butcher_CarcassInStore")] + [DBIndex("IDX_Butcher_CarcassInStore_Clustered", "BarCode", false, 0)] + [DBIndexType("IDX_Butcher_CarcassInStore_Clustered", IndexType.Clustered)] public class CarcassInStore : SyncBill { public CarcassInStore() @@ -25,8 +28,6 @@ namespace ButcherFactory.BO public decimal? Weight { get; set; } - public long? UpID { get; set; } - public decimal? BeforeWeight { get; set; } [NonDmoProperty] diff --git a/ButcherFactory.BO/ButcherFactory.BO.csproj b/ButcherFactory.BO/ButcherFactory.BO.csproj index 2d2d3be..63b5855 100644 --- a/ButcherFactory.BO/ButcherFactory.BO.csproj +++ b/ButcherFactory.BO/ButcherFactory.BO.csproj @@ -60,7 +60,7 @@ - + diff --git a/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs b/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs index 4b1174a..2ad3359 100644 --- a/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs +++ b/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs @@ -18,50 +18,66 @@ namespace ButcherFactory.BO.LocalBL { const string RpcPath = @"/MainSystem/B3ClientService/Rpcs/CarcassInStoreRpc/"; static Dictionary _goodsNames = new Dictionary(); - public static List DoWithPadData(long? workUnitID, long? productBatch) + public static List DoWithPadData(long? workUnitID, long? batchID) { var json = RpcFacade.Call(RpcPath + "GetUnSyncPadData"); var data = JsonConvert.DeserializeObject>(json); var list = new List(); if (data.Count == 0) return list; + + var goodsBarCode = data.Select(x => new Tuple(x.Goods_ID, x.BarCode)); + list = InsertOrUpdate(workUnitID, batchID, goodsBarCode); + + var backInfo = data.Select(x => new ExtensionObj { LongExt1 = x.ID, DecimalExt1 = x.RowVersion }); + RpcFacade.Call(RpcPath + "SetPadDataSync", JsonConvert.SerializeObject(backInfo)); + return list; + } + + public static List InsertOrUpdate(long? workUnitID, long? batchID, long goodsID, string barCode) + { + var list = new List> { new Tuple(goodsID, barCode) }; + return InsertOrUpdate(workUnitID, batchID, list); + } + + static List InsertOrUpdate(long? workUnitID, long? batchID, IEnumerable> data) + { + var list = new List(); using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection)) { foreach (var item in data) { - var id = UpdateIfExist(item, session); + var id = GetExistWithUpdate(item, session); if (id.HasValue) { var exist = new CarcassInStore(); list.Add(exist); exist.ID = id.Value; - exist.Goods_ID = item.Goods_ID; - exist.Goods_Name = GetGoodsName(item.Goods_ID, session); + exist.Goods_ID = item.Item1; + exist.Goods_Name = GetGoodsName(item.Item1, session); } else { - var entity = CreateCarcassInStore(item); - entity.WorkUnit_ID = workUnitID; - entity.ProductBatch_ID = productBatch; - entity.Goods_Name = GetGoodsName(item.Goods_ID, session); + var entity = CreateCarcassInStore(workUnitID, batchID, item); + entity.Goods_Name = GetGoodsName(item.Item1, session); session.Insert(entity); list.Add(entity); } } session.Commit(); } - var backInfo = data.Select(x => new IDRowVersion { ID = x.ID, RowVersion = x.RowVersion }); - RpcFacade.Call(RpcPath + "SetPadDataSync", JsonConvert.SerializeObject(backInfo)); return list; } - private static CarcassInStore CreateCarcassInStore(PadCarcassInStore item) + static CarcassInStore CreateCarcassInStore(long? workUnitID, long? batchID, Tuple goodsCode) { var entity = new CarcassInStore(); entity.FromPad = true; + entity.WorkUnit_ID = workUnitID; + entity.ProductBatch_ID = batchID; entity.UserID = AppContext.Worker.ID; - entity.BarCode = item.BarCode; - entity.Goods_ID = item.Goods_ID; + entity.BarCode = goodsCode.Item2; + entity.Goods_ID = goodsCode.Item1; return entity; } @@ -77,15 +93,15 @@ namespace ButcherFactory.BO.LocalBL return _goodsNames[id]; } - static long? UpdateIfExist(PadCarcassInStore data, IDmoSession session) + static long? GetExistWithUpdate(Tuple goodsCode, IDmoSession session) { var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore))); query.Columns.Add(DQSelectColumn.Field("ID")); - query.Where.Conditions.Add(DQCondition.EQ("BarCode", data.BarCode)); + query.Where.Conditions.Add(DQCondition.EQ("BarCode", goodsCode.Item2)); var id = (long?)session.ExecuteScalar(query); if (id == null) return null; - Update(id.Value, "Goods_ID", data.Goods_ID, session); + Update(id.Value, "Goods_ID", goodsCode.Item1, session); return id.Value; } @@ -108,16 +124,6 @@ namespace ButcherFactory.BO.LocalBL } } - public static long Insert(CarcassInStore entity) - { - using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection)) - { - session.Insert(entity); - session.Commit(); - return entity.ID; - } - } - public static BindingList GetLocalDataWithState(bool history) { var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore))); @@ -169,5 +175,103 @@ namespace ButcherFactory.BO.LocalBL var list = query.EExecuteList(); return list.Select(x => new ClientGoodsSet_Detail { Goods_ID = x.Item1, Goods_Name = x.Item2 }); } + + public static List GetBeforeWeight(IEnumerable codeList) + { + var json = RpcFacade.Call(RpcPath + "GetWeightInfo", codeList); + var list = JsonConvert.DeserializeObject>(json); + if (list.Any()) + { + using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection)) + { + foreach (var item in list) + SaveWeightInDB(item, session); + session.Commit(); + } + } + return list; + } + + static void SaveWeightInDB(ExtensionObj obj, IDmoSession session) + { + var update = new DQUpdateDom(typeof(CarcassInStore)); + update.Where.Conditions.Add(DQCondition.EQ("BarCode", obj.StringExt1)); + update.Columns.Add(new DQUpdateColumn("Weight", obj.DecimalExt1)); + session.ExecuteNonQuery(update); + } + + public static void UploadCarcassInfo() + { + using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection)) + { + var needUpload = GetUnSyncData(session); + if (needUpload.Count == 0) + return; + + var json = JsonConvert.SerializeObject(needUpload); + RpcFacade.Call(RpcPath + "UploadCarcassInfo", json); + foreach (var item in needUpload) + SetLocalAsSyncd(item, session); + session.Commit(); + } + } + + static List GetUnSyncData(IDmoSession session) + { + var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore))); + 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.IsNotNull(DQExpression.Field("Weight")), 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 CarcassInStoreObj(); + obj.ID = (long)reader[0]; + obj.RowVersion = (int)reader[1]; + obj.BarCode = (string)reader[2]; + obj.InStoreWorker_ID = (long)reader[3]; + obj.WorkUnit_ID = (long?)reader[4]; + obj.ProductBatch_ID = (long?)reader[5]; + obj.InStoreGoods_ID = (long)reader[6]; + obj.InStoreWeight = (decimal)reader[7]; + obj.InStoreTime = (DateTime)reader[8]; + upload.Add(obj); + } + } + return upload; + } + + static void SetLocalAsSyncd(CarcassInStoreObj obj, IDmoSession session) + { + var update = new DQUpdateDom(typeof(CarcassInStore)); + update.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", obj.ID), DQCondition.EQ("RowVersion", obj.RowVersion))); + update.Columns.Add(new DQUpdateColumn("Sync", true)); + update.EExecute(); + } + } + + class CarcassInStoreObj + { + public long ID { get; set; } + public int RowVersion { get; set; } + public string BarCode { get; set; } + public long? InStoreWorker_ID { get; set; } + public long? WorkUnit_ID { get; set; } + public long? ProductBatch_ID { get; set; } + public long? InStoreGoods_ID { get; set; } + public decimal? InStoreWeight { get; set; } + public DateTime? InStoreTime { get; set; } } } diff --git a/ButcherFactory.BO/Utils/Extensions.cs b/ButcherFactory.BO/Utils/Extensions.cs index 20d9f6d..1841a7c 100644 --- a/ButcherFactory.BO/Utils/Extensions.cs +++ b/ButcherFactory.BO/Utils/Extensions.cs @@ -290,5 +290,14 @@ namespace ButcherFactory.BO return session.ExecuteList(query); } } + + public static void EExecute(this DQUpdateDom update) + { + using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection)) + { + session.ExecuteNonQuery(update); + session.Commit(); + } + } } } diff --git a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.Designer.cs b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.Designer.cs index 7886c49..5b74257 100644 --- a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.Designer.cs +++ b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.Designer.cs @@ -32,41 +32,41 @@ System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.productBatchSelect = new System.Windows.Forms.ComboBox(); - this.workUnitSelect = new System.Windows.Forms.ComboBox(); - this.splitContainer2 = new System.Windows.Forms.SplitContainer(); - this.groupBox2 = new System.Windows.Forms.GroupBox(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.closeBtn = new WinFormControl.UButton(); this.uTimerLabel1 = new WinFormControl.UTimerLabel(); + this.productBatchSelect = new System.Windows.Forms.ComboBox(); + this.workUnitSelect = new System.Windows.Forms.ComboBox(); this.uScanPanel1 = new WinFormControl.UScanPanel(); this.netStateWatch1 = new WinFormControl.NetStateWatch(); this.uWeightControl1 = new WinFormControl.UWeightControl(); this.uLabel1 = new WinFormControl.ULabel(); this.uLabel2 = new WinFormControl.ULabel(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); this.historyDataGrid = new WinFormControl.UDataGridView(); - this.uLabel4 = new WinFormControl.ULabel(); - this.needSubmitGrid = new WinFormControl.UDataGridView(); - this.uLabel3 = new WinFormControl.ULabel(); - this.U_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.U_BarCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.U_Goods_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.U_Weight = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.H_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.H_BarCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.H_Goods_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.H_Weight = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.H_BeforeWeight = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.H_Discont = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.uLabel4 = new WinFormControl.ULabel(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.needSubmitGrid = new WinFormControl.UDataGridView(); + this.U_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.U_BarCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.U_Goods_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.U_Weight = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.uLabel3 = new WinFormControl.ULabel(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -76,8 +76,8 @@ this.splitContainer2.Panel2.SuspendLayout(); this.splitContainer2.SuspendLayout(); this.groupBox2.SuspendLayout(); - this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.historyDataGrid)).BeginInit(); + this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.needSubmitGrid)).BeginInit(); this.SuspendLayout(); // @@ -112,84 +112,6 @@ this.splitContainer1.SplitterDistance = 86; this.splitContainer1.TabIndex = 0; // - // productBatchSelect - // - this.productBatchSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.productBatchSelect.Font = new System.Drawing.Font("宋体", 15F); - this.productBatchSelect.FormattingEnabled = true; - this.productBatchSelect.Location = new System.Drawing.Point(843, 47); - this.productBatchSelect.Name = "productBatchSelect"; - this.productBatchSelect.Size = new System.Drawing.Size(170, 28); - this.productBatchSelect.TabIndex = 4; - // - // workUnitSelect - // - this.workUnitSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.workUnitSelect.Font = new System.Drawing.Font("宋体", 15F); - this.workUnitSelect.FormattingEnabled = true; - this.workUnitSelect.Location = new System.Drawing.Point(843, 11); - this.workUnitSelect.Name = "workUnitSelect"; - this.workUnitSelect.Size = new System.Drawing.Size(170, 28); - this.workUnitSelect.TabIndex = 3; - // - // splitContainer2 - // - this.splitContainer2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; - this.splitContainer2.IsSplitterFixed = true; - this.splitContainer2.Location = new System.Drawing.Point(0, 0); - this.splitContainer2.Name = "splitContainer2"; - // - // splitContainer2.Panel1 - // - this.splitContainer2.Panel1.BackColor = System.Drawing.Color.Transparent; - this.splitContainer2.Panel1.Controls.Add(this.groupBox2); - this.splitContainer2.Panel1.Controls.Add(this.groupBox1); - // - // splitContainer2.Panel2 - // - this.splitContainer2.Panel2.BackColor = System.Drawing.Color.Transparent; - this.splitContainer2.Panel2.Controls.Add(this.flowLayoutPanel1); - this.splitContainer2.Size = new System.Drawing.Size(1164, 521); - this.splitContainer2.SplitterDistance = 840; - this.splitContainer2.TabIndex = 0; - // - // groupBox2 - // - this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.groupBox2.Controls.Add(this.historyDataGrid); - this.groupBox2.Controls.Add(this.uLabel4); - this.groupBox2.Location = new System.Drawing.Point(11, 254); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Padding = new System.Windows.Forms.Padding(5); - this.groupBox2.Size = new System.Drawing.Size(815, 254); - this.groupBox2.TabIndex = 1; - this.groupBox2.TabStop = false; - // - // groupBox1 - // - this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.groupBox1.Controls.Add(this.needSubmitGrid); - this.groupBox1.Controls.Add(this.uLabel3); - this.groupBox1.Location = new System.Drawing.Point(11, 15); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Padding = new System.Windows.Forms.Padding(5); - this.groupBox1.Size = new System.Drawing.Size(815, 226); - this.groupBox1.TabIndex = 0; - this.groupBox1.TabStop = false; - // - // flowLayoutPanel1 - // - this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); - this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(318, 519); - this.flowLayoutPanel1.TabIndex = 0; - // // closeBtn // this.closeBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -222,6 +144,26 @@ this.uTimerLabel1.TabIndex = 8; this.uTimerLabel1.Text = "3月30日 8:54:07"; // + // productBatchSelect + // + this.productBatchSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.productBatchSelect.Font = new System.Drawing.Font("宋体", 15F); + this.productBatchSelect.FormattingEnabled = true; + this.productBatchSelect.Location = new System.Drawing.Point(843, 47); + this.productBatchSelect.Name = "productBatchSelect"; + this.productBatchSelect.Size = new System.Drawing.Size(170, 28); + this.productBatchSelect.TabIndex = 4; + // + // workUnitSelect + // + this.workUnitSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.workUnitSelect.Font = new System.Drawing.Font("宋体", 15F); + this.workUnitSelect.FormattingEnabled = true; + this.workUnitSelect.Location = new System.Drawing.Point(843, 11); + this.workUnitSelect.Name = "workUnitSelect"; + this.workUnitSelect.Size = new System.Drawing.Size(170, 28); + this.workUnitSelect.TabIndex = 3; + // // uScanPanel1 // this.uScanPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -272,6 +214,43 @@ this.uLabel2.TabIndex = 6; this.uLabel2.Text = "生产批次:"; // + // splitContainer2 + // + this.splitContainer2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.splitContainer2.IsSplitterFixed = true; + this.splitContainer2.Location = new System.Drawing.Point(0, 0); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.BackColor = System.Drawing.Color.Transparent; + this.splitContainer2.Panel1.Controls.Add(this.groupBox2); + this.splitContainer2.Panel1.Controls.Add(this.groupBox1); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.BackColor = System.Drawing.Color.Transparent; + this.splitContainer2.Panel2.Controls.Add(this.flowLayoutPanel1); + this.splitContainer2.Size = new System.Drawing.Size(1164, 521); + this.splitContainer2.SplitterDistance = 840; + this.splitContainer2.TabIndex = 0; + // + // groupBox2 + // + this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox2.Controls.Add(this.historyDataGrid); + this.groupBox2.Controls.Add(this.uLabel4); + this.groupBox2.Location = new System.Drawing.Point(11, 254); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Padding = new System.Windows.Forms.Padding(5); + this.groupBox2.Size = new System.Drawing.Size(815, 254); + this.groupBox2.TabIndex = 1; + this.groupBox2.TabStop = false; + // // historyDataGrid // this.historyDataGrid.AllowUserToAddRows = false; @@ -308,6 +287,57 @@ this.historyDataGrid.Size = new System.Drawing.Size(805, 230); this.historyDataGrid.TabIndex = 2; // + // H_ID + // + this.H_ID.DataPropertyName = "ID"; + this.H_ID.HeaderText = "序号"; + this.H_ID.Name = "H_ID"; + this.H_ID.ReadOnly = true; + this.H_ID.Width = 80; + // + // H_BarCode + // + this.H_BarCode.DataPropertyName = "BarCode"; + this.H_BarCode.HeaderText = "条码"; + this.H_BarCode.Name = "H_BarCode"; + this.H_BarCode.ReadOnly = true; + this.H_BarCode.Width = 250; + // + // H_Goods_Name + // + this.H_Goods_Name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.H_Goods_Name.DataPropertyName = "Goods_Name"; + this.H_Goods_Name.HeaderText = "产品名称"; + this.H_Goods_Name.Name = "H_Goods_Name"; + this.H_Goods_Name.ReadOnly = true; + // + // H_Weight + // + this.H_Weight.DataPropertyName = "Weight"; + dataGridViewCellStyle3.Format = "#0.######"; + this.H_Weight.DefaultCellStyle = dataGridViewCellStyle3; + this.H_Weight.HeaderText = "入库重量"; + this.H_Weight.Name = "H_Weight"; + this.H_Weight.ReadOnly = true; + // + // H_BeforeWeight + // + this.H_BeforeWeight.DataPropertyName = "BeforeWeight"; + dataGridViewCellStyle4.Format = "#0.######"; + this.H_BeforeWeight.DefaultCellStyle = dataGridViewCellStyle4; + this.H_BeforeWeight.HeaderText = "胴体重量"; + this.H_BeforeWeight.Name = "H_BeforeWeight"; + this.H_BeforeWeight.ReadOnly = true; + // + // H_Discont + // + this.H_Discont.DataPropertyName = "Discont"; + dataGridViewCellStyle5.Format = "#0.######"; + this.H_Discont.DefaultCellStyle = dataGridViewCellStyle5; + this.H_Discont.HeaderText = "损耗"; + this.H_Discont.Name = "H_Discont"; + this.H_Discont.ReadOnly = true; + // // uLabel4 // this.uLabel4.AutoSize = true; @@ -319,6 +349,19 @@ this.uLabel4.TabIndex = 1; this.uLabel4.Text = "已提交"; // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.needSubmitGrid); + this.groupBox1.Controls.Add(this.uLabel3); + this.groupBox1.Location = new System.Drawing.Point(11, 15); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Padding = new System.Windows.Forms.Padding(5); + this.groupBox1.Size = new System.Drawing.Size(815, 226); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + // // needSubmitGrid // this.needSubmitGrid.AllowUserToAddRows = false; @@ -353,17 +396,6 @@ this.needSubmitGrid.Size = new System.Drawing.Size(805, 202); this.needSubmitGrid.TabIndex = 1; // - // uLabel3 - // - this.uLabel3.AutoSize = true; - this.uLabel3.BackColor = System.Drawing.Color.White; - this.uLabel3.Font = new System.Drawing.Font("宋体", 13F); - this.uLabel3.Location = new System.Drawing.Point(8, -1); - this.uLabel3.Name = "uLabel3"; - this.uLabel3.Size = new System.Drawing.Size(62, 18); - this.uLabel3.TabIndex = 0; - this.uLabel3.Text = "待提交"; - // // U_ID // this.U_ID.DataPropertyName = "ID"; @@ -398,56 +430,24 @@ this.U_Weight.ReadOnly = true; this.U_Weight.Width = 200; // - // H_ID - // - this.H_ID.DataPropertyName = "ID"; - this.H_ID.HeaderText = "序号"; - this.H_ID.Name = "H_ID"; - this.H_ID.ReadOnly = true; - this.H_ID.Width = 80; - // - // H_BarCode - // - this.H_BarCode.DataPropertyName = "BarCode"; - this.H_BarCode.HeaderText = "条码"; - this.H_BarCode.Name = "H_BarCode"; - this.H_BarCode.ReadOnly = true; - this.H_BarCode.Width = 250; - // - // H_Goods_Name - // - this.H_Goods_Name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.H_Goods_Name.DataPropertyName = "Goods_Name"; - this.H_Goods_Name.HeaderText = "产品名称"; - this.H_Goods_Name.Name = "H_Goods_Name"; - this.H_Goods_Name.ReadOnly = true; - // - // H_Weight - // - this.H_Weight.DataPropertyName = "Weight"; - dataGridViewCellStyle3.Format = "#0.######"; - this.H_Weight.DefaultCellStyle = dataGridViewCellStyle3; - this.H_Weight.HeaderText = "入库重量"; - this.H_Weight.Name = "H_Weight"; - this.H_Weight.ReadOnly = true; - // - // H_BeforeWeight + // uLabel3 // - this.H_BeforeWeight.DataPropertyName = "BeforeWeight"; - dataGridViewCellStyle4.Format = "#0.######"; - this.H_BeforeWeight.DefaultCellStyle = dataGridViewCellStyle4; - this.H_BeforeWeight.HeaderText = "胴体重量"; - this.H_BeforeWeight.Name = "H_BeforeWeight"; - this.H_BeforeWeight.ReadOnly = true; + this.uLabel3.AutoSize = true; + this.uLabel3.BackColor = System.Drawing.Color.White; + this.uLabel3.Font = new System.Drawing.Font("宋体", 13F); + this.uLabel3.Location = new System.Drawing.Point(8, -1); + this.uLabel3.Name = "uLabel3"; + this.uLabel3.Size = new System.Drawing.Size(62, 18); + this.uLabel3.TabIndex = 0; + this.uLabel3.Text = "待提交"; // - // H_Discont + // flowLayoutPanel1 // - this.H_Discont.DataPropertyName = "Discont"; - dataGridViewCellStyle5.Format = "#0.######"; - this.H_Discont.DefaultCellStyle = dataGridViewCellStyle5; - this.H_Discont.HeaderText = "损耗"; - this.H_Discont.Name = "H_Discont"; - this.H_Discont.ReadOnly = true; + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(318, 519); + this.flowLayoutPanel1.TabIndex = 0; // // CarcassInStoreForm // @@ -471,9 +471,9 @@ this.splitContainer2.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.historyDataGrid)).EndInit(); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.historyDataGrid)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.needSubmitGrid)).EndInit(); this.ResumeLayout(false); diff --git a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs index 15e04f2..1ad1799 100644 --- a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs +++ b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs @@ -38,6 +38,8 @@ namespace ButcherFactory.CarcassInStore_ Thread uploadData; BindingList needSubmitedList; BindingList historyList; + long? workUnitID; + long? batchID; public CarcassInStoreForm() { InitializeComponent(); @@ -51,6 +53,20 @@ namespace ButcherFactory.CarcassInStore_ if (uploadData != null && uploadData.IsAlive) uploadData.Abort(); }; + workUnitSelect.SelectedIndexChanged += delegate + { + if (workUnitSelect.SelectedValue == null) + workUnitID = null; + else + workUnitID = ((WorkUnit)workUnitSelect.SelectedValue).ID; + }; + productBatchSelect.SelectedIndexChanged += delegate + { + if (productBatchSelect.SelectedValue == null) + batchID = null; + else + batchID = ((ProductBatch)productBatchSelect.SelectedValue).ID; + }; } protected override void OnLoad(EventArgs e) @@ -62,28 +78,38 @@ namespace ButcherFactory.CarcassInStore_ syncPadTask = new Thread(SyncPadData); syncPadTask.Start(); + syncBeforeWeight = new Thread(GetBeforeWeight); + syncBeforeWeight.Start(); + + uploadData = new Thread(UpLoadLocalData); + uploadData.Start(); + #region WeightReceiveData uWeightControl1.ReceivedValue += (weight) => { - this.Invoke(new Action(() => + lock (_lock) { - var last = needSubmitedList.LastOrDefault(); - if (last == null) - { - SoundPalyUtil.PlaySound(SoundType.Error); - return; - } - else + this.Invoke(new Action(() => { - last.Weight = weight; - CarcassInStoreBL.Update(last.ID, "Weight", weight); - needSubmitedList.Remove(last); - needSubmitGrid.Refresh(); - historyList.Insert(0, last); - historyDataGrid.Refresh(); - SoundPalyUtil.PlaySound(SoundType.ShotSucc); - } - })); + var last = needSubmitedList.LastOrDefault(); + if (last == null) + { + SoundPalyUtil.PlaySound(SoundType.Error); + return; + } + else + { + last.Weight = weight; + CarcassInStoreBL.Update(last.ID, "Weight", weight); + needSubmitedList.Remove(last); + needSubmitGrid.Refresh(); + historyList.Insert(0, last); + historyDataGrid.Refresh(); + SoundPalyUtil.PlaySound(SoundType.ShotSucc); + } + })); + } }; + #endregion } void LoadBind() @@ -111,13 +137,65 @@ namespace ButcherFactory.CarcassInStore_ { for (var i = 0; i < 10; i++) { - var btn = new UButton() { Width = 90, Height = 50, Text = item.Goods_Name, Tag = item.ID, Font = new Font("宋体", 15), Margin = new Padding(8, 14, 8, 0), PlaySound = true }; - + var btn = new UButton() { Width = 90, Height = 50, Text = item.Goods_Name, Tag = item.Goods_ID, Font = new Font("宋体", 15), Margin = new Padding(8, 14, 8, 0), PlaySound = true }; + btn.Click += (sender, e) => + { + if (string.IsNullOrEmpty(uScanPanel1.TextBox.Text)) + throw new Exception("请先扫码"); + if (uScanPanel1.TextBox.Text.Length != 23) + throw new Exception("条码格式不正确"); + var c = sender as UButton; + var list = CarcassInStoreBL.InsertOrUpdate(workUnitID, batchID, (long)c.Tag, uScanPanel1.TextBox.Text); + AfterUpdateOrInsert(list); + }; flowLayoutPanel1.Controls.Add(btn); } } } + static object _lock = new object(); + void AfterUpdateOrInsert(List list) + { + lock (_lock) + { + bool upNeedRefresh = false; + bool downNeedRefresh = false; + foreach (var item in list) + { + if (string.IsNullOrEmpty(item.BarCode)) + { + var first = historyList.FirstOrDefault(x => x.ID == item.ID); + if (first != null) + { + first.Goods_Name = item.Goods_Name; + downNeedRefresh = true; + } + else + { + var upFirst = needSubmitedList.FirstOrDefault(x => x.ID == item.ID); + if (upFirst != null) + { + upFirst.Goods_Name = item.Goods_Name; + upNeedRefresh = true; + } + } + } + else + { + needSubmitedList.Add(item); + var ordered = needSubmitedList.OrderByDescending(x => x.ID).ToList(); + needSubmitedList.Clear(); + ordered.ForEach(x => needSubmitedList.Add(x)); + upNeedRefresh = true; + } + } + if (upNeedRefresh) + needSubmitGrid.Refresh(); + if (downNeedRefresh) + historyDataGrid.Refresh(); + } + } + void BindGrid() { needSubmitedList = CarcassInStoreBL.GetLocalDataWithState(false); @@ -139,44 +217,36 @@ namespace ButcherFactory.CarcassInStore_ { if (netStateWatch1.NetState) { - var list = CarcassInStoreBL.DoWithPadData((long?)workUnitSelect.SelectedValue, (long?)productBatchSelect.SelectedValue); + var list = CarcassInStoreBL.DoWithPadData(workUnitID, batchID); + if (list.Any()) + AfterUpdateOrInsert(list); + } + })); + } + Thread.Sleep(2000); + } + } + + void GetBeforeWeight(object obj) + { + while (true) + { + if (this.IsHandleCreated) + { + this.Invoke(new Action(() => + { + if (netStateWatch1.NetState) + { + var list = needSubmitedList.Where(x => x.BeforeWeight == null); if (list.Any()) { - bool n1 = false; - bool n2 = false; - foreach (var item in list) + var back = CarcassInStoreBL.GetBeforeWeight(list.Select(x => x.BarCode)); + if (back.Any()) { - if (string.IsNullOrEmpty(item.BarCode)) - { - var hf = historyList.FirstOrDefault(x => x.ID == item.ID); - if (hf != null) - { - hf.Goods_Name = item.Goods_Name; - n2 = true; - } - else - { - var uf = needSubmitedList.FirstOrDefault(x => x.ID == item.ID); - if (uf != null) - { - uf.Goods_Name = item.Goods_Name; - n1 = true; - } - } - } - else - { - needSubmitedList.Add(item); - var old = needSubmitedList.OrderByDescending(x => x.ID).ToList(); - needSubmitedList.Clear(); - old.ForEach(x => needSubmitedList.Add(x)); - n1 = true; - } - } - if (n1) + foreach (var item in back) + list.First(x => x.BarCode == item.StringExt1).Weight = item.DecimalExt1; needSubmitGrid.Refresh(); - if (n2) - historyDataGrid.Refresh(); + } } } })); @@ -185,6 +255,22 @@ namespace ButcherFactory.CarcassInStore_ } } + void UpLoadLocalData(object obj) + { + while (true) + { + if (this.IsHandleCreated) + { + this.Invoke(new Action(() => + { + if (netStateWatch1.NetState) + CarcassInStoreBL.UploadCarcassInfo(); + })); + } + Thread.Sleep(2000); + } + } + private void closeBtn_Click(object sender, EventArgs e) { Close(); diff --git a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.resx b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.resx index 0d1ddbc..50d556c 100644 --- a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.resx +++ b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + @@ -126,6 +132,39 @@ KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII= + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + True @@ -144,6 +183,15 @@ True + + True + + + True + + + True + True @@ -156,4 +204,13 @@ True + + True + + + True + + + True + \ No newline at end of file