From 4f91b02bee2fd05433827a7e94f4da4753803b41 Mon Sep 17 00:00:00 2001 From: robin <3504557@qq.com> Date: Fri, 7 May 2021 17:54:14 +0800 Subject: [PATCH] add xianpin --- ButcherFactory.BO/Bill/SegmentProduction.cs | 6 +- ButcherFactory.BO/Bill/TotalCode.cs | 8 +- .../LocalBL/SegmentProductionBL.cs | 56 +++++++-- .../SegmentProductionAutoForm.cs | 113 +++++++++++++----- 4 files changed, 142 insertions(+), 41 deletions(-) diff --git a/ButcherFactory.BO/Bill/SegmentProduction.cs b/ButcherFactory.BO/Bill/SegmentProduction.cs index 9e0547a..66e1720 100644 --- a/ButcherFactory.BO/Bill/SegmentProduction.cs +++ b/ButcherFactory.BO/Bill/SegmentProduction.cs @@ -57,7 +57,11 @@ namespace ButcherFactory.BO [ReferenceTo(typeof(Goods), "Code")] [Join("Goods_ID", "ID")] - public string Goods_Code { get; set; } + public string Goods_Code { get; set; } + + [ReferenceTo(typeof(Goods), "GoodsType")] + [Join("Goods_ID", "ID")] + public short? GoodsType { get; set; } public long? GroupID { get; set; } diff --git a/ButcherFactory.BO/Bill/TotalCode.cs b/ButcherFactory.BO/Bill/TotalCode.cs index 4172f37..357eee9 100644 --- a/ButcherFactory.BO/Bill/TotalCode.cs +++ b/ButcherFactory.BO/Bill/TotalCode.cs @@ -12,7 +12,13 @@ namespace ButcherFactory.BO public class TotalCode : SyncBill { public string BarCode { get; set; } - + + private short _goodsType=1; + [DbColumn(DefaultValue = 1)] + public short GoodsType { + get { return _goodsType; } + set { _goodsType = value; } + } [NonDmoProperty] public string ShortCode diff --git a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs index 8221c1d..af4b3ee 100644 --- a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs +++ b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs @@ -105,15 +105,16 @@ namespace ButcherFactory.BO.LocalBL public static BindingList GetTotalCode( DateTime date) { - var query = new DQueryDom(new JoinAlias(typeof(TotalCode))); + var query = new DQueryDom(new JoinAlias(typeof(TotalCode))); query.Columns.Add(DQSelectColumn.Field("ID")); query.Columns.Add(DQSelectColumn.Field("RowIndex")); query.Columns.Add(DQSelectColumn.Field("BarCode")); + query.Columns.Add(DQSelectColumn.Field("GoodsType")); query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("CreateTime", date.Date)); query.Where.Conditions.Add(DQCondition.LessThan("CreateTime", date.Date.AddDays(1))); - query.Where.Conditions.Add(DQCondition.And( DQCondition.EQ("Delete", false) )); + query.Where.Conditions.Add(DQCondition.And( DQCondition.EQ("Delete", false) )); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("GoodsType")); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID",true)); - var list = new BindingList(); using (var session = DmoSession.New()) { @@ -124,8 +125,8 @@ namespace ButcherFactory.BO.LocalBL var entity = new TotalCode(); entity.ID = (long)reader[0]; entity.RowIndex = (int?)reader[1]; - entity.BarCode = (string)reader[2]; - + entity.BarCode = (string)reader[2]; + entity.GoodsType = (short)reader[3]; list.Add(entity); } } @@ -205,10 +206,51 @@ namespace ButcherFactory.BO.LocalBL } } - static int TotalCodeRowIndex( DateTime date, IDmoSession session) + public static TotalCode InitFreshTotalCode() + { + TotalCode entity = null; + var date = DateTime.Now; + using (var session = DmoSession.New()) + { + var tuple = GetFreshTotalCode(date, session); + if (tuple == null) + { + entity = new TotalCode(); + entity.UserID = AppContext.Worker.ID; + entity.GoodsType = 0; + entity.RowIndex = 1; + // 年月日+2位机器号 + entity.BarCode = string.Format("{0:yyyyMMdd}{1}", date, AppContext.ConnectInfo.ClientCode); + session.Insert(entity); + session.Commit(); + } + else + { + entity = new TotalCode(); + entity.ID = tuple.Item1; + entity.BarCode = tuple.Item2; + entity.GoodsType = 0; + } + + } return entity; + } + + static Tuple GetFreshTotalCode(DateTime date, IDmoSession session) + { + var query = new DQueryDom(new JoinAlias("_main", typeof(TotalCode))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Columns.Add(DQSelectColumn.Field("BarCode")); + query.Where.Conditions.Add(DQCondition.EQ("GoodsType", 0)); + query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("CreateTime", date.Date)); + query.Where.Conditions.Add(DQCondition.LessThan("CreateTime", date.Date.AddDays(1))); + return query.EExecuteScalar(session) ; + } + + static int TotalCodeRowIndex( DateTime date, IDmoSession session,short type=1) { - var query = new DQueryDom(new JoinAlias("_main", typeof(TotalCode))); + var query = new DQueryDom(new JoinAlias("_main", typeof(TotalCode))); query.Columns.Add(DQSelectColumn.Max("RowIndex")); + query.Where.Conditions.Add(DQCondition.EQ("GoodsType", type)); query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("CreateTime", date.Date)); query.Where.Conditions.Add(DQCondition.LessThan("CreateTime", date.Date.AddDays(1))); return (query.EExecuteScalar(session) ?? 0) + 1; diff --git a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs index b498a3e..c50bf74 100644 --- a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs +++ b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs @@ -90,7 +90,8 @@ namespace ButcherFactory.SegmentProductionAuto_ if (checkInStoreState != null && checkInStoreState.IsAlive) checkInStoreState.Abort(); } - public WeightDetails mCache; + public WeightDetails mCache; + protected override void OnLoad(EventArgs e) { base.OnLoad(e); @@ -120,7 +121,7 @@ namespace ButcherFactory.SegmentProductionAuto_ mCache.Cache.Remove(v); } wDic = mCache.Cache; - + _freshTotalCode = SegmentProductionBL.InitFreshTotalCode(); } void LoadBind() @@ -213,32 +214,46 @@ namespace ButcherFactory.SegmentProductionAuto_ { bTag.Label.Text = string.Format("{0}-0", item.EachNumber.Value); } + ClientGoodsSet_Detail g = item; bTag.Button.Click += delegate { - if (batchID == null) - throw new Exception("请先选择批次"); - if (_totalCode == null || _codePanel == null) + if (batchID == null) { + MessageBox.Show("请先选择批次!"); + return; + } + if (g.GoodsType == 1) { - throw new Exception(string.Format("请先选择总码!")); + if (_totalCode == null || _codePanel == null) + { + MessageBox.Show("请先选择总码!"); + return; + } } + var weight = uWeightControl1.Weight; #if DEBUG if (weight == 0) - weight = (item.StandardWeightLow ?? 4.0m) + 0.1m; + weight = (g.StandardWeightLow ?? 4.0m) + 0.1m; #endif if (weight == 0) - throw new Exception("重量不能为0"); - if (item.StandardWeight.HasValue) + { + MessageBox.Show("重量不能为0"); + return; + } + if (g.StandardWeight.HasValue) { - if (weight < (item.StandardWeightLow ?? 0) || weight > (item.StandardWeightUp ?? 0)) - throw new Exception(string.Format("重量必须在{0:#0.######}-{1:#0.######}之间", item.StandardWeightLow, item.StandardWeightUp)); - weight = item.StandardWeight.Value; + if (weight < (g.StandardWeightLow ?? 0) || weight > (g.StandardWeightUp ?? 0)) + { + MessageBox.Show(string.Format("重量必须在{0:#0.######}-{1:#0.######}之间", g.StandardWeightLow, g.StandardWeightUp)); + return; + } + weight = g.StandardWeight.Value; } List l = null; - if (wDic.ContainsKey(item.Goods_ID)) + if (wDic.ContainsKey(g.Goods_ID)) { - l = wDic[item.Goods_ID]; - if (l.Count >= item.EachNumber.Value) + l = wDic[g.Goods_ID]; + if (l.Count >= g.EachNumber.Value) { l.Clear(); } @@ -246,13 +261,13 @@ namespace ButcherFactory.SegmentProductionAuto_ } else { - wDic.Add(item.Goods_ID, l = new List() { weight }); + wDic.Add(g.Goods_ID, l = new List() { weight }); } bTag.Label.MinCount = l.Count(); - if (l.Count >= item.EachNumber.Value) + if (l.Count >= g.EachNumber.Value) { weight = l.Sum(x => x); - InsertSegmentProduction(item, weight); + InsertSegmentProduction(g, weight); } mCache.Cache = wDic; XmlUtil.SerializerObjToFile(mCache); @@ -261,9 +276,9 @@ namespace ButcherFactory.SegmentProductionAuto_ bTag.Label.Click += delegate { List l = new List(0); - if (wDic.ContainsKey(item.Goods_ID)) + if (wDic.ContainsKey(g.Goods_ID)) { - l = wDic[item.Goods_ID]; + l = wDic[g.Goods_ID]; } new WeightView(this, bTag).ShowDialog(); }; @@ -327,13 +342,33 @@ namespace ButcherFactory.SegmentProductionAuto_ entity.WorkUnit_ID = config.WorkUnitID; entity.ProductBatch_ID = batchID.Value; entity.StandardPic = detail.StandardPic; + entity.GoodsType = detail.GoodsType; + if (!string.IsNullOrEmpty(statisticNumberBox.Text)) entity.StatisticNumber = decimal.Parse(statisticNumberBox.Text); - if (_totalCode == null || _codePanel==null) + + TotalCode thisTotal = null; + CodePanel thisPanel; + if (entity.GoodsType == 0) { - throw new Exception(string.Format("请先选择总码!" )); + entity.TotalCode_ID = _freshTotalCode.ID; + thisTotal = _freshTotalCode; + thisPanel = _freshPanel; + } + else + { + if (_totalCode == null || _codePanel == null) + { + throw new Exception(string.Format("请先选择总码!")); + } + if(_totalCode.GoodsType==0){ + throw new Exception(string.Format("只有鲜品才可以选择鲜品总码!")); + } + entity.TotalCode_ID = _totalCode.ID; + thisTotal = _totalCode; + thisPanel = _codePanel; } - entity.TotalCode_ID = _totalCode.ID; + SegmentProductionBL.InsertAndSetGroupID(entity, batchDate.Value); entity.Goods_Code = detail.Goods_Code; entity.Goods_Name = detail.Goods_Name; @@ -341,7 +376,7 @@ namespace ButcherFactory.SegmentProductionAuto_ entity.MainUnit = detail.MainUnit; entity.ShotPrintName = detail.ShotPrintName; - _codePanel.Add(initSegmentBt(entity, _codePanel,_totalCode),true); + thisPanel.Add(initSegmentBt(entity, thisPanel, thisTotal), true); historyList.Insert(0, entity); @@ -448,10 +483,18 @@ namespace ButcherFactory.SegmentProductionAuto_ codeButtons.Clear(); foreach (var item in allCode) { - if (deleteList.Contains(item.ID)) + if (item.GoodsType == 0) + { + + } + else { - continue; + if (deleteList.Contains(item.ID)) + { + continue; + } } + var details = historyList.Where(x => x.TotalCode_ID == item.ID); var n = new CodePanel(); AddCodeButton(n, item); @@ -468,12 +511,10 @@ namespace ButcherFactory.SegmentProductionAuto_ while (true) { try - { - //this.Invoke(new Action(() => - //{ + { if (netStateWatch1.NetState) SegmentProductionBL.UploadSegmentInfo(); - //})); + } catch { } Thread.Sleep(2000); @@ -698,7 +739,9 @@ namespace ButcherFactory.SegmentProductionAuto_ } CodePanel _codePanel; + CodePanel _freshPanel; TotalCode _totalCode; + TotalCode _freshTotalCode; private void colorButton1_Click(object sender, EventArgs e) { var n = new CodePanel(); @@ -707,13 +750,19 @@ namespace ButcherFactory.SegmentProductionAuto_ allCode.Insert(0, tCode); AddCodeButton(n, tCode,true); flowLayoutPanel3.Controls.Add(n); - flowLayoutPanel3.Controls.SetChildIndex(n, 0); + flowLayoutPanel3.Controls.SetChildIndex(n, 1); } private void AddCodeButton(CodePanel n, TotalCode tCode,bool add=false) { n.Button.Tag = tCode; - n.Button.Text = tCode.ShortCode; + if (tCode.GoodsType == 0) + { + n.Button.Text ="鲜品"; + _freshPanel = n; + } + else + n.Button.Text = tCode.ShortCode; n.Button.Click += delegate {