diff --git a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs index cda6b3c..8221c1d 100644 --- a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs +++ b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs @@ -36,13 +36,14 @@ namespace ButcherFactory.BO.LocalBL query.Columns.Add(DQSelectColumn.Field("ShotPrintName")); query.Columns.Add(DQSelectColumn.Field("MainUnit")); query.Columns.Add(DQSelectColumn.Field("TotalCode_ID")); - query.Columns.Add(DQSelectColumn.Field("TotalCode_Code")); + query.Columns.Add(DQSelectColumn.Field("TotalCode_Code")); + query.Columns.Add(DQSelectColumn.Field("CreateTime")); query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("InStored", false), DQCondition.EQ("Delete", false), DQCondition.EQ("Submited", submited))); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); if (submited) { query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("CreateTime", DateTime.Today)); - query.Range = SelectRange.Top(20); + query.Range = SelectRange.Top(50); } var list = new BindingList(); using (var session = DmoSession.New()) @@ -68,6 +69,7 @@ namespace ButcherFactory.BO.LocalBL entity.MainUnit = (string)reader[12]; entity.TotalCode_ID = (long)reader[13]; entity.TotalCode_Code = (string)reader[14]; + entity.CreateTime = (DateTime)reader[15]; list.Add(entity); } } @@ -76,6 +78,31 @@ namespace ButcherFactory.BO.LocalBL return list; } + public static BindingList GetInStoreList() + { + var query = new DQueryDom(new JoinAlias(typeof(SegmentProduction))); + + query.Columns.Add(DQSelectColumn.Field("TotalCode_ID")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("InStored", true) )); + query.GroupBy.Expressions.Add(DQExpression.Field("TotalCode_ID")); + query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("CreateTime", DateTime.Today)); + + var list = new BindingList(); + using (var session = DmoSession.New()) + { + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + list.Add((long)reader[0] ); + } + } + } + + return list; + } + + public static BindingList GetTotalCode( DateTime date) { var query = new DQueryDom(new JoinAlias(typeof(TotalCode))); @@ -398,7 +425,7 @@ namespace ButcherFactory.BO.LocalBL query.Columns.Add(DQSelectColumn.Field("StatisticNumber")); query.Columns.Add(DQSelectColumn.Field("TotalCode_Code")); query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Submited", true), DQCondition.EQ("Sync", false), DQCondition.EQ("Delete", false))); - //query.Where.Conditions.Add(DQCondition.LessThan("CreateTime", DateTime.Now.AddMinutes(-1))); + query.Where.Conditions.Add(DQCondition.LessThan("CreateTime", DateTime.Now.AddMinutes(-1))); query.Range = SelectRange.Top(10); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); diff --git a/ButcherFactory.Form/Controls/CodePanel.Designer.cs b/ButcherFactory.Form/Controls/CodePanel.Designer.cs index e3c58b3..2fd2d85 100644 --- a/ButcherFactory.Form/Controls/CodePanel.Designer.cs +++ b/ButcherFactory.Form/Controls/CodePanel.Designer.cs @@ -37,21 +37,21 @@ this.flowLayoutPanel1.AutoScroll = true; this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 46); + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 50); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(101, 552); + this.flowLayoutPanel1.Size = new System.Drawing.Size(105, 552); this.flowLayoutPanel1.TabIndex = 0; this.flowLayoutPanel1.WrapContents = false; // // Button // - this.Button.BackColor = System.Drawing.Color.Violet; - this.Button.Font = new System.Drawing.Font("黑体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Button.BackColor = System.Drawing.Color.LightGray; + this.Button.Font = new System.Drawing.Font("黑体", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.Button.ForeColor = System.Drawing.Color.Black; this.Button.Location = new System.Drawing.Point(3, 3); this.Button.Name = "Button"; - this.Button.SelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(15)))), ((int)(((byte)(215)))), ((int)(((byte)(107))))); - this.Button.Size = new System.Drawing.Size(90, 40); + this.Button.SelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.Button.Size = new System.Drawing.Size(99, 40); this.Button.TabIndex = 1; this.Button.UseVisualStyleBackColor = false; // @@ -59,11 +59,10 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.Controls.Add(this.Button); this.Controls.Add(this.flowLayoutPanel1); this.Name = "CodePanel"; - this.Size = new System.Drawing.Size(101, 598); + this.Size = new System.Drawing.Size(105, 602); this.ResumeLayout(false); } diff --git a/ButcherFactory.Form/Controls/CodePanel.cs b/ButcherFactory.Form/Controls/CodePanel.cs index 91aa561..bc983e3 100644 --- a/ButcherFactory.Form/Controls/CodePanel.cs +++ b/ButcherFactory.Form/Controls/CodePanel.cs @@ -17,9 +17,14 @@ namespace ButcherFactory.Controls InitializeComponent(); } - public void Add(Control v) + public void Add(Control v, bool top = false) { + flowLayoutPanel1.Controls.Add(v); + if (top) + { + flowLayoutPanel1.Controls.SetChildIndex(v, 0); + } } } } diff --git a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs index 42a8b09..70641bd 100644 --- a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs +++ b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs @@ -415,6 +415,7 @@ this.flowLayoutPanel3.AutoScroll = true; this.flowLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutPanel3.Location = new System.Drawing.Point(5, 19); + this.flowLayoutPanel3.Margin = new System.Windows.Forms.Padding(0); this.flowLayoutPanel3.Name = "flowLayoutPanel3"; this.flowLayoutPanel3.Size = new System.Drawing.Size(437, 357); this.flowLayoutPanel3.TabIndex = 4; @@ -506,7 +507,7 @@ // colorButton1 // this.colorButton1.BackColor = System.Drawing.Color.Blue; - this.colorButton1.Font = new System.Drawing.Font("宋体", 13F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.colorButton1.Font = new System.Drawing.Font("宋体", 28F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.colorButton1.ForeColor = System.Drawing.Color.White; this.colorButton1.Location = new System.Drawing.Point(13, 178); this.colorButton1.Name = "colorButton1"; diff --git a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs index c14a092..b498a3e 100644 --- a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs +++ b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs @@ -37,6 +37,7 @@ namespace ButcherFactory.SegmentProductionAuto_ Thread checkInStoreState; Thread initTask; BindingList historyList; + BindingList deleteList; BindingList allCode; Dictionary> goodsSetDic; long? batchID; @@ -339,8 +340,8 @@ namespace ButcherFactory.SegmentProductionAuto_ entity.Goods_Spec = detail.Goods_Spec; entity.MainUnit = detail.MainUnit; entity.ShotPrintName = detail.ShotPrintName; - - _codePanel.Add(initSegmentBt(entity)); + + _codePanel.Add(initSegmentBt(entity, _codePanel,_totalCode),true); historyList.Insert(0, entity); @@ -365,15 +366,17 @@ namespace ButcherFactory.SegmentProductionAuto_ SegmentProduction current; ColorButton _labelBt; - private ColorButton initSegmentBt(SegmentProduction entity) + private ColorButton initSegmentBt(SegmentProduction entity, CodePanel parent, TotalCode tCode) { var bt = new ColorButton() { Text = entity.ShortCode }; bt.Tag = entity; - bt.Width = 90; + bt.Width = 98; bt.Height = 35; - bt.Font = new Font("黑体", 13, FontStyle.Bold); - bt.BackColor = Color.DarkCyan; - bt.SelectedColor = Color.DarkOrange; + bt.Font = new Font("黑体", 15, FontStyle.Bold); + bt.ForeColor = Color.Black; + bt.BackColor = System.Drawing.SystemColors.ButtonFace; + + bt.SelectedColor = Color.Cyan; bt.Click += delegate { bt.Selected = !bt.Selected; @@ -387,8 +390,10 @@ namespace ButcherFactory.SegmentProductionAuto_ _codePanel.Button.Selected = false; _codePanel.Button.Invalidate(); } - _totalCode = null; - _codePanel = null; + parent.Button.Selected = true; + parent.Button.Invalidate(); + _totalCode = tCode; + _codePanel = parent; } else { @@ -427,6 +432,7 @@ namespace ButcherFactory.SegmentProductionAuto_ void BindGrid() { historyList = SegmentProductionBL.GetListByState(true); + deleteList = SegmentProductionBL.GetInStoreList(); allCode = SegmentProductionBL.GetTotalCode(DateTime.Now); RefreshCodePanel(); @@ -442,12 +448,16 @@ namespace ButcherFactory.SegmentProductionAuto_ codeButtons.Clear(); foreach (var item in allCode) { - var details = historyList.Where(x => x.TotalCode_ID == item.ID); + if (deleteList.Contains(item.ID)) + { + continue; + } + var details = historyList.Where(x => x.TotalCode_ID == item.ID); var n = new CodePanel(); AddCodeButton(n, item); foreach (var seg in details) { - n.Add(initSegmentBt(seg)); + n.Add(initSegmentBt(seg,n,item)); } flowLayoutPanel3.Controls.Add(n); } @@ -479,25 +489,47 @@ namespace ButcherFactory.SegmentProductionAuto_ if (netStateWatch1.NetState) { if (historyList.Any()) - { - var arr = historyList.Reverse().Take(20); + { + int c = 50; + if (historyList.Count() < 50) + { + c = historyList.Count; + } + var arr = historyList.Reverse().Take(c); var inStored = SegmentProductionBL.GetInStoreState(arr.Select(x => x.BarCode).ToList()); var tag = arr.Where(x => inStored.Contains(x.BarCode)); if (tag.Any()) { SegmentProductionBL.SetInStored(tag.Select(x => x.ID).ToList()); this.Invoke(new Action(() => - { + { + var groupByTotal = tag.GroupBy(x => x.TotalCode_ID); + foreach (var item2 in groupByTotal) + { + var f = codeButtons.FirstOrDefault(x => ((TotalCode)x.Tag).ID == item2.Key); + if (f != null) + { + flowLayoutPanel3.Controls.Remove(f.Parent); + codeButtons.Remove(f); + } + + } + foreach (var item in tag) - historyList.Remove(item); - //historyDataGrid.ClearSelection(); - //historyDataGrid.Refresh(); + historyList.Remove(item); + })); } } } + } + catch (Exception ex) + { + this.Invoke(new Action(() => + { + msglbl.Text = "ERROR" + ex.Message ?? string.Empty; + })); } - catch { } Thread.Sleep(5000); } } @@ -543,15 +575,12 @@ namespace ButcherFactory.SegmentProductionAuto_ private void deleteBtn_Click(object sender, EventArgs e) { - if (_totalCode == null || _codePanel == null) - { - if (current == null) - return; + //if (_totalCode == null || _codePanel == null) + if (current != null) + { if (MessageBox.Show("确定删除选中记录?", "删除确认", MessageBoxButtons.OKCancel) != DialogResult.OK) return; - - //var tag = historyDataGrid.SelectedRows[0].DataBoundItem as SegmentProduction; - + if (current.CreateTime.AddMinutes(1) < DateTime.Now) { MessageBox.Show("已超出可删除时间范围"); @@ -565,15 +594,19 @@ namespace ButcherFactory.SegmentProductionAuto_ var parent=_labelBt.Parent; parent.Controls.Remove(_labelBt); } - //RefreshCodePanel(); + var thd = new Thread(new ParameterizedThreadStart(RefreshTask)); thd.Start(d); current = null; } - else + else if (_totalCode != null && _codePanel != null) { var deleteList = historyList.Where(x => x.TotalCode_ID == _totalCode.ID).ToList(); - + if (deleteList.Count > 0) + { + MessageBox.Show("总码下已有条码,不允许直接删除总码"); + return; + } SegmentProductionBL.DeleteTotalCode(_totalCode); allCode.Remove(_totalCode); codeButtons.Remove(_codePanel.Button); @@ -683,10 +716,11 @@ namespace ButcherFactory.SegmentProductionAuto_ n.Button.Text = tCode.ShortCode; n.Button.Click += delegate { - current = null; + n.Button.Selected = !n.Button.Selected; if (n.Button.Selected) - { + { + current = null; _codePanel = n; _totalCode = tCode; if (_labelBt != null) @@ -738,6 +772,10 @@ namespace ButcherFactory.SegmentProductionAuto_ if (dmos.Length == 0) { throw new Exception(string.Format("此码不包含任何产品!")); + } + foreach (var item in dmos) + { + item.TotalCode_Code = _totalCode.BarCode; } NotAuto.SegmentSumCodePrint.Print(dmos, "SegmentSumCode.html"); var log = new SegmentLog(dmos[0].TotalCode_Code, "总码"); diff --git a/ButcherFactory.Form/SegmentProduction_/SegmentSumCodePrint.cs b/ButcherFactory.Form/SegmentProduction_/SegmentSumCodePrint.cs index 5f063eb..72db704 100644 --- a/ButcherFactory.Form/SegmentProduction_/SegmentSumCodePrint.cs +++ b/ButcherFactory.Form/SegmentProduction_/SegmentSumCodePrint.cs @@ -35,10 +35,15 @@ namespace ButcherFactory.SegmentProduction_ dic.Add("$Goods_Name", info); dic.Add("$Date", DateTime.Now.ToString("yyyy/MM/dd HH:mm")); - var code = entity.TotalCode_Code; + var code = entity.TotalCode_Code; + if (!string.IsNullOrEmpty(code)) + { + if (code.Length > 6) + code = code.Substring(code.Length - 6); + } dic.Add("$Code", code); var imgUrl = string.Format(IMGFILE, id); - var url = string.Format(AppContext.ConnectInfo.TraceBackUrl + "?code={0}",entity.TotalCode_Code); + var url = string.Format("{0}",entity.TotalCode_Code); BwpClientPrint.BwpClientWebPrint.Create2DPic(url, imgUrl, 120); dic.Add("$ImageUrl", imgUrl);