diff --git a/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs b/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs index 2d2fa61..b460122 100644 --- a/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs +++ b/ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs @@ -37,6 +37,10 @@ namespace ButcherFactory.BO [Join("Goods_ID", "ID")] public string Goods_Code { get; set; } + [ReferenceTo(typeof(Goods), "GoodsType")] + [Join("Goods_ID", "ID")] + public short? GoodsType { 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 40a57b9..b53e5d8 100644 --- a/ButcherFactory.BO/BaseInfo/Goods.cs +++ b/ButcherFactory.BO/BaseInfo/Goods.cs @@ -21,5 +21,7 @@ namespace ButcherFactory.BO public decimal? UpWeight { get; set; } public decimal? DownWeight { get; set; } + + public short? GoodsType { get; set; } } } diff --git a/ButcherFactory.BO/Bill/StockUpEntity.cs b/ButcherFactory.BO/Bill/StockUpEntity.cs index 7ccdbb9..5e7ab8d 100644 --- a/ButcherFactory.BO/Bill/StockUpEntity.cs +++ b/ButcherFactory.BO/Bill/StockUpEntity.cs @@ -7,13 +7,13 @@ using System.Threading.Tasks; namespace ButcherFactory.BO { - public class StockUpEntity + public class SaleOutStoreInfo { - public DateTime Date { get; set; } - public long DeliverGoodsLine_ID { get; set; } + public DateTime? Date { get; set; } public string DeliverGoodsLine_Name { get; set; } - public long? SequenceNumber { get; set; } - public long Goods_ID { get; set; } + public string Customer_Name { get; set; } + public long BillID { get; set; } + public long DetailID { get; set; } public string Goods_Name { get; set; } public string Goods_Spec { get; set; } public string Goods_Code { get; set; } @@ -28,18 +28,24 @@ namespace ButcherFactory.BO } } - public class StockUpDetail + [KeyField("ID", KeyGenType.identity)] + [MapToTable("Butcher_SegmentStockUp")] + public class SegmentStockUp { public long ID { get; set; } + public bool Sync { get; set; } + public DateTime Date { get; set; } - public long DeliverGoodsLine_ID { get; set; } - - public string DeliverGoodsLine_Name { get; set; } + public long DetailID { get; set; } public string BarCode { get; set; } + public decimal? SecondNumber { get; set; } + + public decimal? UnitNumber { get; set; } + [NonDmoProperty] public string ShortCode { @@ -53,18 +59,13 @@ namespace ButcherFactory.BO } } - public long Goods_ID { get; set; } - - public string Goods_Code { get; set; } - - public string Goods_Spec { get; set; } - + [NonDmoProperty] public string Goods_Name { get; set; } - public long SaleOutStoreID { get; set; } - - public decimal? SecondNumber { get; set; } + [NonDmoProperty] + public string DeliverGoodsLine_Name { get; set; } - public decimal? UnitNumber { get; set; } + [NonDmoProperty] + public long BillID { get; set; } } } diff --git a/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs b/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs index a91cbcc..aefd7d1 100644 --- a/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs +++ b/ButcherFactory.BO/LocalBL/FormClientGoodsSetBL.cs @@ -67,6 +67,7 @@ namespace ButcherFactory.BO.LocalBL 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.OrderBy.Expressions.Add(DQOrderByExpression.Create(main, "ID")); query.OrderBy.Expressions.Add(DQOrderByExpression.Create(detail, "ID")); @@ -87,6 +88,7 @@ namespace ButcherFactory.BO.LocalBL entity.StandardWeightLow = (decimal?)reader[5]; entity.Goods_Spec = (string)reader[6]; entity.Goods_Code = (string)reader[7]; + entity.GoodsType = (short?)reader[8]; if (result.ContainsKey(key)) result[key].Add(entity); else diff --git a/ButcherFactory.BO/LocalBL/SegmentStockUpBL.cs b/ButcherFactory.BO/LocalBL/SegmentStockUpBL.cs index 095a68b..b52d95f 100644 --- a/ButcherFactory.BO/LocalBL/SegmentStockUpBL.cs +++ b/ButcherFactory.BO/LocalBL/SegmentStockUpBL.cs @@ -1,6 +1,7 @@ using ButcherFactory.BO.Utils; using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; using Forks.JsonRpc.Client; using Newtonsoft.Json; using System; @@ -26,49 +27,95 @@ namespace ButcherFactory.BO.LocalBL return JsonConvert.DeserializeObject(json); } - public static List GetStockUpEntity(DateTime date, string code) + public static List GetSaleOutStoreList(DateTime date) { - var json = RpcFacade.Call(RpcPath + "SaleOutStoreRpc/GetSaleOutStoreByGoodsCode", date, code); - return JsonConvert.DeserializeObject>(json); + var json = RpcFacade.Call(RpcPath + "SaleOutStoreRpc/GetSaleOutStoreByDate", date); + var list = JsonConvert.DeserializeObject>(json); + foreach (var item in list) + item.Date = date; + return list; } - public static List RefreshList(DateTime date, IEnumerable goodsIDs) + public static List GetLocalList(DateTime date) { - var json = RpcFacade.Call(RpcPath + "SaleOutStoreRpc/GetSaleOutStoreByGoodsIDs", date, JsonConvert.SerializeObject(goodsIDs)); - return JsonConvert.DeserializeObject>(json); + var query = new DmoQuery(typeof(SegmentStockUp)); + query.Where.Conditions.Add(DQCondition.EQ("Date", date)); + return query.EExecuteList().Cast().ToList(); } - public static bool CheckBarCodeUsed(string barCode) + public static void DeleteOld() { - return RpcFacade.Call(RpcPath + "SaleOutStoreRpc/CheckBarCodeUsed",barCode); + var delete = new DQDeleteDom(typeof(SegmentStockUp)); + delete.Where.Conditions.Add(DQCondition.And(DQCondition.LessThan("Date", DateTime.Today.AddDays(-2)), DQCondition.EQ("Sync", true))); + delete.EExecute(); } - public static List GetDetails(DateTime date, long driverLineID, long goodsID) + public static void SyncToServer() { - var json = RpcFacade.Call(RpcPath + "SaleOutStoreRpc/GetStockUpDetails", date, driverLineID, goodsID); - return JsonConvert.DeserializeObject>(json); + try + { + using (var session = DmoSession.New()) + { + var list = GetUnSyncList(session); + if (list.Count == 0) + return; + var arr = JsonConvert.SerializeObject(list.Select(x => new { DetailID = x.DetailID, BarCode = x.BarCode, SecondNumber=x.SecondNumber,UnitNumber=x.UnitNumber })); + RpcFacade.Call(RpcPath + "SaleOutStoreRpc/InsertStockUpDetail", arr); + SetLocalSync(session, list.First().ID, list.Last().ID); + session.Commit(); + } + } + catch + { + #if DEBUG + throw; +#endif + } } - public static string InsertStockUpDetail(StockUpDetail detail) + static List GetUnSyncList(IDmoSession session) { - var min = new MinStockUpDetail() { BarCode = detail.BarCode, SecondNumber = detail.SecondNumber, UnitNumber = detail.UnitNumber }; - var json = JsonConvert.SerializeObject(min); - var bkJson = RpcFacade.Call(RpcPath + "SaleOutStoreRpc/InsertStockUpDetail", detail.Date, detail.Goods_ID, detail.DeliverGoodsLine_ID, json); - if (string.IsNullOrEmpty(bkJson)) - return string.Empty; - var backInfo = JsonConvert.DeserializeObject(bkJson); - detail.SaleOutStoreID = backInfo.LongExt1.Value; - detail.ID = backInfo.LongExt2.Value; - return backInfo.StringExt1; + var query = new DQueryDom(new JoinAlias(typeof(SegmentStockUp))); + query.Where.Conditions.Add(DQCondition.EQ("Sync", false)); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Columns.Add(DQSelectColumn.Field("DetailID")); + query.Columns.Add(DQSelectColumn.Field("BarCode")); + query.Columns.Add(DQSelectColumn.Field("SecondNumber")); + query.Columns.Add(DQSelectColumn.Field("UnitNumber")); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); + query.Range = SelectRange.Top(50); + var list = new List(); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var entity = new SegmentStockUp(); + entity.ID = (long)reader[0]; + entity.DetailID = (long)reader[1]; + entity.BarCode = (string)reader[2]; + entity.SecondNumber = (decimal?)reader[3]; + entity.UnitNumber = (decimal?)reader[4]; + list.Add(entity); + } + } + return list; } - class MinStockUpDetail + static void SetLocalSync(IDmoSession session, long min, long max) { - public string BarCode { get; set; } - - public decimal? SecondNumber { get; set; } + var update = new DQUpdateDom(typeof(SegmentStockUp)); + update.Columns.Add(new DQUpdateColumn("Sync", true)); + update.Where.Conditions.Add(DQCondition.Between("ID", min, max)); + session.ExecuteNonQuery(update); + } - public decimal? UnitNumber { get; set; } + public static void Insert(SegmentStockUp detail) + { + using (var session = DmoSession.New()) + { + session.Insert(detail); + session.Commit(); + } } } } diff --git a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs index b22f3b1..e6c0ec2 100644 --- a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs +++ b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs @@ -165,7 +165,12 @@ namespace ButcherFactory.SegmentProductionAuto_ historyDataGrid.Refresh(); } if (barPrintCheck.Checked) - NotAuto.SegmentProductionPrint.Print(entity, batchDate, config.Template); + { + var template = config.Template; + if (detail.GoodsType.HasValue) + template = detail.GoodsType == 0 ? "SegmentProductionPrint.html" : "SegmentProductionPrint1.html"; + NotAuto.SegmentProductionPrint.Print(entity, batchDate, template); + } if (!testCkBox.Checked) { taskDataGrid.DataSource = SegmentProductionBL.GetProductTask(batchDate ?? DateTime.Today, entity); diff --git a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.Designer.cs b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.Designer.cs index 0c7f71b..12027e0 100644 --- a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.Designer.cs +++ b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.Designer.cs @@ -41,8 +41,6 @@ System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); this.uScanPanel1 = new WinFormControl.UScanPanel(); - this.label1 = new System.Windows.Forms.Label(); - this.dataPicker = new System.Windows.Forms.Label(); this.panel4 = new System.Windows.Forms.Panel(); this.goodsLbl = new System.Windows.Forms.Label(); this.driveLineLbl = new System.Windows.Forms.Label(); @@ -50,9 +48,6 @@ this.dhNumberLbl = new System.Windows.Forms.Label(); this.panel5 = new System.Windows.Forms.Panel(); this.mainGridView = new WinFormControl.UDataGridView(); - this.D_DeliverGoodsLine_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.D_Goods_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.D_Date = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.D_Finishd = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.D_DeliverGoodsLine_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.D_Goods_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -65,6 +60,12 @@ this.panel6 = new System.Windows.Forms.Panel(); this.label13 = new System.Windows.Forms.Label(); this.detailGridView = new WinFormControl.UDataGridView(); + this.B_DeliverGoodsLine_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.B_ShortCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.B_Goods_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.B_SaleOutStoreID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.B_SecondNumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.B_UnitNumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dhUnitNumLbl = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.bhUnitNumLbl = new System.Windows.Forms.Label(); @@ -74,12 +75,6 @@ this.panel7 = new System.Windows.Forms.Panel(); this.printCk = new System.Windows.Forms.CheckBox(); this.refresh = new ButcherFactory.Controls.ColorButton(); - this.B_DeliverGoodsLine_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.B_ShortCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.B_Goods_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.B_SaleOutStoreID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.B_SecondNumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.B_UnitNumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.roundPanel1.SuspendLayout(); this.panel5.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).BeginInit(); @@ -104,40 +99,16 @@ this.roundPanel1.Controls.Add(this.driveLineLbl); this.roundPanel1.Controls.Add(this.goodsLbl); this.roundPanel1.Controls.Add(this.panel4); - this.roundPanel1.Controls.Add(this.dataPicker); this.roundPanel1.Controls.Add(this.uScanPanel1); - this.roundPanel1.Controls.Add(this.label1); // // uScanPanel1 // this.uScanPanel1.BackColor = System.Drawing.Color.Transparent; - this.uScanPanel1.Location = new System.Drawing.Point(271, 14); + this.uScanPanel1.Location = new System.Drawing.Point(18, 9); this.uScanPanel1.Name = "uScanPanel1"; this.uScanPanel1.Size = new System.Drawing.Size(303, 32); this.uScanPanel1.TabIndex = 0; // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("宋体", 14F); - this.label1.Location = new System.Drawing.Point(16, 19); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(85, 19); - this.label1.TabIndex = 1; - this.label1.Text = "发货日期"; - // - // dataPicker - // - this.dataPicker.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.dataPicker.Font = new System.Drawing.Font("宋体", 14F); - this.dataPicker.Location = new System.Drawing.Point(107, 14); - this.dataPicker.Name = "dataPicker"; - this.dataPicker.Size = new System.Drawing.Size(120, 30); - this.dataPicker.TabIndex = 2; - this.dataPicker.Text = "2018-08-08"; - this.dataPicker.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.dataPicker.Click += new System.EventHandler(this.dataPicker_Click); - // // panel4 // this.panel4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) @@ -228,9 +199,6 @@ this.mainGridView.ColumnHeadersHeight = 30; this.mainGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; this.mainGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.D_DeliverGoodsLine_ID, - this.D_Goods_ID, - this.D_Date, this.D_Finishd, this.D_DeliverGoodsLine_Name, this.D_Goods_Name, @@ -256,28 +224,6 @@ this.mainGridView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.mainGridView_CellClick); this.mainGridView.RowPrePaint += new System.Windows.Forms.DataGridViewRowPrePaintEventHandler(this.mainGridView_RowPrePaint); // - // D_DeliverGoodsLine_ID - // - this.D_DeliverGoodsLine_ID.DataPropertyName = "DeliverGoodsLine_ID"; - this.D_DeliverGoodsLine_ID.HeaderText = "DeliverGoodsLine_ID"; - this.D_DeliverGoodsLine_ID.Name = "D_DeliverGoodsLine_ID"; - this.D_DeliverGoodsLine_ID.ReadOnly = true; - this.D_DeliverGoodsLine_ID.Visible = false; - // - // D_Goods_ID - // - this.D_Goods_ID.HeaderText = "Goods_ID"; - this.D_Goods_ID.Name = "D_Goods_ID"; - this.D_Goods_ID.ReadOnly = true; - this.D_Goods_ID.Visible = false; - // - // D_Date - // - this.D_Date.HeaderText = "Date"; - this.D_Date.Name = "D_Date"; - this.D_Date.ReadOnly = true; - this.D_Date.Visible = false; - // // D_Finishd // this.D_Finishd.DataPropertyName = "Finishd"; @@ -432,6 +378,60 @@ this.detailGridView.Size = new System.Drawing.Size(580, 320); this.detailGridView.TabIndex = 6; // + // B_DeliverGoodsLine_Name + // + this.B_DeliverGoodsLine_Name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.B_DeliverGoodsLine_Name.DataPropertyName = "DeliverGoodsLine_Name"; + this.B_DeliverGoodsLine_Name.HeaderText = "线路名称"; + this.B_DeliverGoodsLine_Name.MinimumWidth = 100; + this.B_DeliverGoodsLine_Name.Name = "B_DeliverGoodsLine_Name"; + this.B_DeliverGoodsLine_Name.ReadOnly = true; + // + // B_ShortCode + // + this.B_ShortCode.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.B_ShortCode.DataPropertyName = "ShortCode"; + this.B_ShortCode.HeaderText = "条码"; + this.B_ShortCode.MinimumWidth = 90; + this.B_ShortCode.Name = "B_ShortCode"; + this.B_ShortCode.ReadOnly = true; + // + // B_Goods_Name + // + this.B_Goods_Name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.B_Goods_Name.DataPropertyName = "Goods_Name"; + this.B_Goods_Name.HeaderText = "产品名称"; + this.B_Goods_Name.MinimumWidth = 100; + this.B_Goods_Name.Name = "B_Goods_Name"; + this.B_Goods_Name.ReadOnly = true; + // + // B_SaleOutStoreID + // + this.B_SaleOutStoreID.DataPropertyName = "SaleOutStoreID"; + this.B_SaleOutStoreID.HeaderText = "销售出库单"; + this.B_SaleOutStoreID.Name = "B_SaleOutStoreID"; + this.B_SaleOutStoreID.ReadOnly = true; + // + // B_SecondNumber + // + this.B_SecondNumber.DataPropertyName = "SecondNumber"; + dataGridViewCellStyle3.Format = "#0.######"; + this.B_SecondNumber.DefaultCellStyle = dataGridViewCellStyle3; + this.B_SecondNumber.HeaderText = "数量"; + this.B_SecondNumber.Name = "B_SecondNumber"; + this.B_SecondNumber.ReadOnly = true; + this.B_SecondNumber.Width = 80; + // + // B_UnitNumber + // + this.B_UnitNumber.DataPropertyName = "UnitNumber"; + dataGridViewCellStyle4.Format = "#0.######"; + this.B_UnitNumber.DefaultCellStyle = dataGridViewCellStyle4; + this.B_UnitNumber.HeaderText = "重量"; + this.B_UnitNumber.Name = "B_UnitNumber"; + this.B_UnitNumber.ReadOnly = true; + this.B_UnitNumber.Width = 80; + // // dhUnitNumLbl // this.dhUnitNumLbl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; @@ -529,60 +529,6 @@ this.refresh.UseVisualStyleBackColor = false; this.refresh.Click += new System.EventHandler(this.refresh_Click); // - // B_DeliverGoodsLine_Name - // - this.B_DeliverGoodsLine_Name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.B_DeliverGoodsLine_Name.DataPropertyName = "DeliverGoodsLine_Name"; - this.B_DeliverGoodsLine_Name.HeaderText = "线路名称"; - this.B_DeliverGoodsLine_Name.MinimumWidth = 100; - this.B_DeliverGoodsLine_Name.Name = "B_DeliverGoodsLine_Name"; - this.B_DeliverGoodsLine_Name.ReadOnly = true; - // - // B_ShortCode - // - this.B_ShortCode.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.B_ShortCode.DataPropertyName = "ShortCode"; - this.B_ShortCode.HeaderText = "条码"; - this.B_ShortCode.MinimumWidth = 90; - this.B_ShortCode.Name = "B_ShortCode"; - this.B_ShortCode.ReadOnly = true; - // - // B_Goods_Name - // - this.B_Goods_Name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.B_Goods_Name.DataPropertyName = "Goods_Name"; - this.B_Goods_Name.HeaderText = "产品名称"; - this.B_Goods_Name.MinimumWidth = 100; - this.B_Goods_Name.Name = "B_Goods_Name"; - this.B_Goods_Name.ReadOnly = true; - // - // B_SaleOutStoreID - // - this.B_SaleOutStoreID.DataPropertyName = "SaleOutStoreID"; - this.B_SaleOutStoreID.HeaderText = "销售出库单"; - this.B_SaleOutStoreID.Name = "B_SaleOutStoreID"; - this.B_SaleOutStoreID.ReadOnly = true; - // - // B_SecondNumber - // - this.B_SecondNumber.DataPropertyName = "SecondNumber"; - dataGridViewCellStyle3.Format = "#0.######"; - this.B_SecondNumber.DefaultCellStyle = dataGridViewCellStyle3; - this.B_SecondNumber.HeaderText = "数量"; - this.B_SecondNumber.Name = "B_SecondNumber"; - this.B_SecondNumber.ReadOnly = true; - this.B_SecondNumber.Width = 80; - // - // B_UnitNumber - // - this.B_UnitNumber.DataPropertyName = "UnitNumber"; - dataGridViewCellStyle4.Format = "#0.######"; - this.B_UnitNumber.DefaultCellStyle = dataGridViewCellStyle4; - this.B_UnitNumber.HeaderText = "重量"; - this.B_UnitNumber.Name = "B_UnitNumber"; - this.B_UnitNumber.ReadOnly = true; - this.B_UnitNumber.Width = 80; - // // SegmentStockUpForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -610,8 +556,6 @@ #endregion private WinFormControl.UScanPanel uScanPanel1; - private System.Windows.Forms.Label dataPicker; - private System.Windows.Forms.Label label1; private System.Windows.Forms.Label dhNumberLbl; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label driveLineLbl; @@ -632,9 +576,12 @@ private System.Windows.Forms.Panel panel7; private Controls.ColorButton refresh; private System.Windows.Forms.CheckBox printCk; - private System.Windows.Forms.DataGridViewTextBoxColumn D_DeliverGoodsLine_ID; - private System.Windows.Forms.DataGridViewTextBoxColumn D_Goods_ID; - private System.Windows.Forms.DataGridViewTextBoxColumn D_Date; + private System.Windows.Forms.DataGridViewTextBoxColumn B_DeliverGoodsLine_Name; + private System.Windows.Forms.DataGridViewTextBoxColumn B_ShortCode; + private System.Windows.Forms.DataGridViewTextBoxColumn B_Goods_Name; + private System.Windows.Forms.DataGridViewTextBoxColumn B_SaleOutStoreID; + private System.Windows.Forms.DataGridViewTextBoxColumn B_SecondNumber; + private System.Windows.Forms.DataGridViewTextBoxColumn B_UnitNumber; private System.Windows.Forms.DataGridViewTextBoxColumn D_Finishd; private System.Windows.Forms.DataGridViewTextBoxColumn D_DeliverGoodsLine_Name; private System.Windows.Forms.DataGridViewTextBoxColumn D_Goods_Name; @@ -643,11 +590,5 @@ private System.Windows.Forms.DataGridViewTextBoxColumn D_UnitNum; private System.Windows.Forms.DataGridViewTextBoxColumn D_SSecondNumber; private System.Windows.Forms.DataGridViewTextBoxColumn D_SUnitNum; - private System.Windows.Forms.DataGridViewTextBoxColumn B_DeliverGoodsLine_Name; - private System.Windows.Forms.DataGridViewTextBoxColumn B_ShortCode; - private System.Windows.Forms.DataGridViewTextBoxColumn B_Goods_Name; - private System.Windows.Forms.DataGridViewTextBoxColumn B_SaleOutStoreID; - private System.Windows.Forms.DataGridViewTextBoxColumn B_SecondNumber; - private System.Windows.Forms.DataGridViewTextBoxColumn B_UnitNumber; } } \ No newline at end of file diff --git a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.cs b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.cs index c843231..029be36 100644 --- a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.cs +++ b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.cs @@ -10,6 +10,7 @@ using System.Data; using System.Drawing; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -30,18 +31,91 @@ namespace ButcherFactory.SegmentStockUp_ #endregion DateTime sendTime = DateTime.Today; - List allMain; - List allDetail; - BindingList mainList; - BindingList detailList; + List allMain; + List allDetail; + BindingList mainList; + BindingList detailList; + Thread uploadData; + Thread refreshFromServer; public SegmentStockUpForm() { InitializeComponent(); - allMain = new List(); - allDetail = new List(); - dataPicker.Text = sendTime.ToString("yyyy-MM-dd"); + allMain = new List(); + allDetail = new List(); + // dataPicker.Text = sendTime.ToString("yyyy-MM-dd"); uScanPanel1.AfterScan += uScanPanel1_AfterScan; + this.FormClosing += delegate + { + if (uploadData != null && uploadData.IsAlive) + uploadData.Abort(); + if (refreshFromServer != null && refreshFromServer.IsAlive) + refreshFromServer.Abort(); + }; + } + + protected override void OnLoad(EventArgs e) + { + var initTask = new Thread(LoadBind); + initTask.Start(); + uploadData = new Thread(UpLoadLocalData); + uploadData.Start(); + refreshFromServer = new Thread(RefreshFromServer); + refreshFromServer.Start(); + base.OnLoad(e); + } + + private void LoadBind() + { + this.Invoke(new Action(() => + { + SegmentStockUpBL.DeleteOld(); + allDetail = SegmentStockUpBL.GetLocalList(sendTime); + })); + } + + private void UpLoadLocalData() + { + while (true) + { + this.Invoke(new Action(() => + { + SegmentStockUpBL.SyncToServer(); + })); + Thread.Sleep(5000); + } + } + + private void RefreshFromServer() + { + while (true) + { + RefreshData(); + Thread.Sleep(2 * 60 * 1000); + } + } + + void RefreshData() + { + try + { + allMain = SegmentStockUpBL.GetSaleOutStoreList(sendTime); + foreach (var g in allDetail.GroupBy(x => x.DetailID)) + { + var first = allMain.FirstOrDefault(x => x.DetailID == g.Key); + if (first != null) + { + first.SUnitNum = g.Sum(x => x.UnitNumber ?? 0); + first.SSecondNumber = g.Sum(x => x.SecondNumber ?? 0); + } + } + } + catch + { +#if DEBUG + throw; +#endif + } } void uScanPanel1_AfterScan() @@ -54,89 +128,69 @@ namespace ButcherFactory.SegmentStockUp_ InfoBox.Show("错误", "条码已使用过", Color.Green, 1); return; } - if (SegmentStockUpBL.CheckBarCodeUsed(code)) - { - InfoBox.Show("错误", "条码已使用过", Color.Green, 1); - return; - } var info = SegmentStockUpBL.StockUpScan(code); if (info == null) { InfoBox.Show("错误", "条码未入库", Color.Blue, 1); return; } - if (!allMain.Any(x => x.Goods_Code == info.StringExt1 && x.Date == sendTime)) - { - var gt = SegmentStockUpBL.GetStockUpEntity(sendTime, info.StringExt1); - allMain.AddRange(gt); - var first = gt.Where(x => !x.Finishd).OrderBy(x => x.SequenceNumber).FirstOrDefault(); - if (first != null) - FillAllDetail(sendTime, first.DeliverGoodsLine_ID, first.Goods_ID); - else - { - InfoBox.Show("提示", "没有订单", Color.Red, 1); - return; - } - } - InsertDetail(info); - } - - void InsertDetail(ExtensionObj scan) - { - var first = allMain.Where(x => x.Date == sendTime && x.Goods_Code == scan.StringExt1 && !x.Finishd).OrderBy(x => x.SequenceNumber).FirstOrDefault(); + var first = allMain.FirstOrDefault(x => !x.Finishd && x.Goods_Code == info.StringExt1); if (first == null) { InfoBox.Show("提示", "没有订单", Color.Red, 1); return; } - var detail = new StockUpDetail(); + InsertDetail(info, first); + } + + void InsertDetail(ExtensionObj scan,SaleOutStoreInfo saleOutStore) + { + var detail = new SegmentStockUp(); detail.BarCode = uScanPanel1.TextBox.Text; detail.Date = sendTime; - detail.DeliverGoodsLine_ID = first.DeliverGoodsLine_ID; - detail.DeliverGoodsLine_Name = first.DeliverGoodsLine_Name; - detail.Goods_Code = first.Goods_Code; - detail.Goods_ID = first.Goods_ID; - detail.Goods_Name = first.Goods_Name; - detail.Goods_Spec = first.Goods_Spec; + detail.DetailID = saleOutStore.DetailID; + detail.DeliverGoodsLine_Name = saleOutStore.DeliverGoodsLine_Name; + detail.Goods_Name = saleOutStore.Goods_Name; + detail.BillID = saleOutStore.BillID; detail.UnitNumber = scan.DecimalExt1; - if (detail.UnitNumber.HasValue && first.Rate.HasValue) - detail.SecondNumber = detail.UnitNumber * first.Rate; - var customer = SegmentStockUpBL.InsertStockUpDetail(detail); - if (string.IsNullOrEmpty(customer)) - { - InfoBox.Show("提示", "没有订单", Color.Red, 1); - return; - } + if (detail.UnitNumber.HasValue && saleOutStore.Rate.HasValue) + detail.SecondNumber = detail.UnitNumber * saleOutStore.Rate; + SegmentStockUpBL.Insert(detail); allDetail.Add(detail); - first.SSecondNumber = (first.SSecondNumber ?? 0) + (detail.SecondNumber ?? 0); - first.SUnitNum = (first.SUnitNum ?? 0) + (detail.UnitNumber ?? 0); if (printCk.Checked) - SegmentStockUpPrint.Print(detail, customer); - BindMainGrid(sendTime, first.Goods_ID); + SegmentStockUpPrint.Print(detail, saleOutStore.Customer_Name); + saleOutStore.SSecondNumber = (saleOutStore.SSecondNumber ?? 0) + (detail.SecondNumber ?? 0); + saleOutStore.SUnitNum = (saleOutStore.SUnitNum ?? 0) + (detail.UnitNumber ?? 0); + BindMainGrid(saleOutStore); } - void FillAllDetail(DateTime date, long driverLineID, long goodsID) + void BindMainGrid(SaleOutStoreInfo saleOutStore) { - if (allDetail.Any(x => x.Date == date && x.DeliverGoodsLine_ID == driverLineID && x.Goods_ID == goodsID)) - return; - var n = SegmentStockUpBL.GetDetails(date, driverLineID, goodsID); - allDetail.AddRange(n); - } - - void BindMainGrid(DateTime date, long goodsID) - { - var main = allMain.Where(x => x.Date == date && x.Goods_ID == goodsID).OrderBy(x => x.Finishd).OrderBy(x => x.SequenceNumber); - mainList = new BindingList(main.ToList()); + var main = new List(); + foreach (var g in allMain.Where(x => x.Goods_Name == saleOutStore.Goods_Name).GroupBy(x => x.DeliverGoodsLine_Name)) + { + var item = new SaleOutStoreInfo(); + var f = g.First(); + main.Add(item); + item.DeliverGoodsLine_Name = g.Key; + item.Goods_Name = f.Goods_Name; + item.Goods_Spec = f.Goods_Spec; + item.SecondNumber = g.Sum(x => x.SecondNumber ?? 0); + item.UnitNum = g.Sum(x => x.UnitNum ?? 0); + item.SSecondNumber = g.Sum(x => x.SSecondNumber ?? 0); + item.SUnitNum = g.Sum(x => x.SUnitNum ?? 0); + } + mainList = new BindingList(main.OrderBy(x => x.Finishd).ToList()); mainGridView.DataSource = mainList; mainGridView.Refresh(); - BindDetail(main.FirstOrDefault()); + BindDetail(main.Where(x => x.DeliverGoodsLine_Name == saleOutStore.DeliverGoodsLine_Name).First()); } - void BindDetail(StockUpEntity first) + void BindDetail(SaleOutStoreInfo first) { - if (first != null) - { + //if (first != null) + //{ driveLineLbl.Text = first.DeliverGoodsLine_Name; goodsLbl.Text = first.Goods_Name; @@ -144,50 +198,44 @@ namespace ButcherFactory.SegmentStockUp_ dhUnitNumLbl.Text = string.Format("{0:#0.##}", first.UnitNum); bhNumberLbl.Text = string.Format("{0:#0.##}", first.SSecondNumber); bhUnitNumLbl.Text = string.Format("{0:#0.##}", first.SUnitNum); - if (!allDetail.Any(x => x.Date == first.Date && x.DeliverGoodsLine_ID == first.DeliverGoodsLine_ID && x.Goods_ID == first.Goods_ID)) - allDetail.AddRange(SegmentStockUpBL.GetDetails(first.Date, first.DeliverGoodsLine_ID, first.Goods_ID)); - var detail = allDetail.Where(x => x.Date == first.Date && x.DeliverGoodsLine_ID == first.DeliverGoodsLine_ID && x.Goods_ID == first.Goods_ID).OrderByDescending(x => x.ID); - detailList = new BindingList(detail.ToList()); - } - else - { - driveLineLbl.Text = string.Empty; - goodsLbl.Text = string.Empty; - dhNumberLbl.Text = string.Empty; - dhUnitNumLbl.Text = string.Empty; - bhNumberLbl.Text = string.Empty; - bhUnitNumLbl.Text = string.Empty; - - detailList = new BindingList(); - } + var detail = allDetail.Where(x => x.DeliverGoodsLine_Name == first.DeliverGoodsLine_Name && x.Goods_Name == first.Goods_Name).OrderByDescending(x => x.ID); + detailList = new BindingList(detail.ToList()); + //} + //else + //{ + // driveLineLbl.Text = string.Empty; + // goodsLbl.Text = string.Empty; + // dhNumberLbl.Text = string.Empty; + // dhUnitNumLbl.Text = string.Empty; + // bhNumberLbl.Text = string.Empty; + // bhUnitNumLbl.Text = string.Empty; + + // detailList = new BindingList(); + //} detailGridView.DataSource = detailList; detailGridView.Refresh(); } private void refresh_Click(object sender, EventArgs e) { - if (mainList == null || !mainList.Any()) - return; - allMain = SegmentStockUpBL.RefreshList(sendTime, allMain.Select(x => x.Goods_ID).Distinct()); - allDetail.Clear(); - BindMainGrid(sendTime, mainList.First().Goods_ID); + RefreshData(); } - private void dataPicker_Click(object sender, EventArgs e) - { - var cs = new CalendarSelecter(); - if (cs.ShowDialog() == true) - { - sendTime = cs.Result; - dataPicker.Text = sendTime.ToString("yyyy-MM-dd"); - } - } + //private void dataPicker_Click(object sender, EventArgs e) + //{ + // var cs = new CalendarSelecter(); + // if (cs.ShowDialog() == true) + // { + // sendTime = cs.Result; + // dataPicker.Text = sendTime.ToString("yyyy-MM-dd"); + // } + //} private void mainGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) return; - var item = mainGridView.CurrentRow.DataBoundItem as StockUpEntity; + var item = mainGridView.CurrentRow.DataBoundItem as SaleOutStoreInfo; BindDetail(item); } diff --git a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.resx b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.resx index d1e40c1..9c034be 100644 --- a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.resx +++ b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpForm.resx @@ -135,15 +135,6 @@ True - - True - - - True - - - True - True diff --git a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.cs b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.cs index 86b2f5b..b6ab8a5 100644 --- a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.cs +++ b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.cs @@ -40,11 +40,11 @@ namespace ButcherFactory.SegmentStockUp_ // PrintAPI.B_ClosePrn(); //} - public static void Print(StockUpDetail entity, string customer) + public static void Print(SegmentStockUp entity, string customer) { var templateString = File.ReadAllText("PrintTemplate\\SegmentStockUpPrint.txt", Encoding.UTF8); - var str = string.Format(templateString, customer, entity.DeliverGoodsLine_Name, entity.Date,entity.BarCode); + var str = string.Format(templateString, customer, entity.DeliverGoodsLine_Name, entity.Date, entity.BarCode); var printName = GetZebraPrintName(); diff --git a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.txt b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.txt index 64e6d91..4a87659 100644 --- a/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.txt +++ b/ButcherFactory.Form/SegmentStockUp_/SegmentStockUpPrint.txt @@ -3,8 +3,9 @@ ^SEE:GB18030.DAT^FS ^CWJ,E:MSUNG24.FNT^FS ^CI26 -^FT20,100^AJN,36,36 ^FH\^FD客户:{0}^FS -^FT20,200^AJN,36,36 ^FH\^FD线路:{1}^FS -^FT20,300^AJN,36,36 ^FH\^FD日期:{2:yyyy/MM/dd}^FS +^FT20,80^AJN,36,36 ^FH\^FD客户:{0}^FS +^FT20,160^AJN,36,36 ^FH\^FD线路:{1}^FS +^FT20,240^AJN,36,36 ^FH\^FD日期:{2:yyyy/MM/dd}^FS +^FT10,350^BCN,80^FD{3}^FS ^PQ1,0,1,Y ^XZ \ No newline at end of file