From 4f7142334d41dee19486af13df689e164eb1a52e Mon Sep 17 00:00:00 2001 From: robin <3504557@qq.com> Date: Tue, 27 Apr 2021 10:12:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=87=8D=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ButcherFactory.Form.csproj | 1 + .../SegmentProductionAutoForm.cs | 49 ++++++++++++++++--- .../SegmentProductionAuto_/WeightDetails.cs | 44 +++++++++++++++++ 3 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 ButcherFactory.Form/SegmentProductionAuto_/WeightDetails.cs diff --git a/ButcherFactory.Form/ButcherFactory.Form.csproj b/ButcherFactory.Form/ButcherFactory.Form.csproj index 136a9c1..70ea1af 100644 --- a/ButcherFactory.Form/ButcherFactory.Form.csproj +++ b/ButcherFactory.Form/ButcherFactory.Form.csproj @@ -213,6 +213,7 @@ SegmentPickUpForm.cs + Form diff --git a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs index a7e0b9c..5bab25b 100644 --- a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs +++ b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs @@ -87,8 +87,8 @@ namespace ButcherFactory.SegmentProductionAuto_ uploadData.Abort(); if (checkInStoreState != null && checkInStoreState.IsAlive) checkInStoreState.Abort(); - } - + } + WeightDetails mCache; protected override void OnLoad(EventArgs e) { base.OnLoad(e); @@ -98,8 +98,27 @@ namespace ButcherFactory.SegmentProductionAuto_ checkInStoreState = new Thread(CheckInStored); checkInStoreState.Start(); - uploadData = new Thread(UpLoadLocalData); - uploadData.Start(); + uploadData = new Thread(UpLoadLocalData); + uploadData.Start(); + mCache = XmlUtil.DeserializeFromFile(); + var del = new List(); + if (mCache.Cache == null) + { + mCache.Cache = new Dictionary>(); + } + foreach (var item in mCache.Cache) + { + if (item.Value == null || item.Value.Count == 0) + { + del.Add(item.Key); + } + } + foreach (var v in del) + { + mCache.Cache.Remove(v); + } + wDic = mCache.Cache; + } void LoadBind() @@ -183,12 +202,24 @@ namespace ButcherFactory.SegmentProductionAuto_ if ((item.EachNumber ?? 0) > 0) { bTag.Label.MaxCount = item.EachNumber.Value; - bTag.Label.Text = string.Format("{0}-0", item.EachNumber.Value); + if (wDic.ContainsKey(item.Goods_ID)) + { + var l = wDic[item.Goods_ID]; + bTag.Label.Text = string.Format("{0}-{1}", item.EachNumber.Value, l.Count); + } + else + { + bTag.Label.Text = string.Format("{0}-0", item.EachNumber.Value); + } bTag.Button.Click += delegate { if (batchID == null) throw new Exception("请先选择批次"); - var weight = uWeightControl1.Weight; + var weight = uWeightControl1.Weight; +//#if DEBUG +// if (weight == 0) +// weight = (item.StandardWeightLow ?? 4.0m) + 0.1m; +//#endif if (weight == 0) throw new Exception("重量不能为0"); if (item.StandardWeight.HasValue) @@ -217,6 +248,8 @@ namespace ButcherFactory.SegmentProductionAuto_ weight = l.Sum(x => x); InsertSegmentProduction(item, weight); } + mCache.Cache = wDic; + XmlUtil.SerializerObjToFile(mCache); }; bTag.Label.Click += delegate @@ -256,6 +289,10 @@ namespace ButcherFactory.SegmentProductionAuto_ var btn = sender as ColorButton; var detail = btn.Tag as ClientGoodsSet_Detail; var weight = uWeightControl1.Weight; +//#if DEBUG +// if (weight == 0) +// weight = (detail.StandardWeightLow ?? 4.0m) + 0.1m; +//#endif if (weight == 0) throw new Exception("重量不能为0"); if (detail.StandardWeight.HasValue) diff --git a/ButcherFactory.Form/SegmentProductionAuto_/WeightDetails.cs b/ButcherFactory.Form/SegmentProductionAuto_/WeightDetails.cs new file mode 100644 index 0000000..da5d3cc --- /dev/null +++ b/ButcherFactory.Form/SegmentProductionAuto_/WeightDetails.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace ButcherFactory.SegmentProductionAuto_ +{ + [XmlType("KeyValue"), XmlRoot("KeyValue")] + public class SerializableKeyValuePair + { + public TKey Key { get; set; } + public TValue Value { get; set; } + } + + public static class SerializableKeyValuePairExtensions + { + public static SerializableKeyValuePair ToSerializablePair(this KeyValuePair pair) + { + return new SerializableKeyValuePair { Key = pair.Key, Value = pair.Value }; + } + } + + public class WeightDetails + { + + [XmlIgnore] + public Dictionary> Cache { get; set; } + + [XmlArray("Cache")] + public SerializableKeyValuePair>[] CacheArray + { + get + { + return Cache == null ? null : Cache.Select(p => p.ToSerializablePair()).ToArray(); + } + set + { + Cache = value == null ? null : value.ToDictionary(p => p.Key, p => p.Value); + } + } + } +}