diff --git a/ButcherFactory.BO/LocalBL/SegmentInStoreBL.cs b/ButcherFactory.BO/LocalBL/SegmentInStoreBL.cs index 5b2d430..356563f 100644 --- a/ButcherFactory.BO/LocalBL/SegmentInStoreBL.cs +++ b/ButcherFactory.BO/LocalBL/SegmentInStoreBL.cs @@ -80,7 +80,7 @@ namespace ButcherFactory.BO.LocalBL var json = RpcFacade.Call(RpcPath + "GetUnInStoreList"); var list = JsonConvert.DeserializeObject>(json); //var inStored = GetInstoredList(list.Select(x => x.BarCode)); - // var result = list.Where(x => !inStored.Any(y => x.BarCode == y)).ToList(); + // var result = list.Where(x => !inStored.Any(y => x.BarCode == y)).ToList(); var idx = 1; foreach (var item in list) { @@ -109,7 +109,7 @@ namespace ButcherFactory.BO.LocalBL } } - public static SegmentInStore InsertInStore(string barCode, long? storeID, int rowIndex) + public static SegmentInStore InsertInStore(string barCode, long? storeID, int rowIndex, out string msg) { using (var session = DmoSession.New()) { @@ -158,20 +158,22 @@ namespace ButcherFactory.BO.LocalBL //if inStored Error 已入库 //if isBacking Error 正在退库 //if back Error 已退库 - var msg = "已入库"; + var append = "已入库"; switch (localData.Item2) { case 1: - msg = "正在退库"; + append = "正在退库"; break; case 2: - msg = "已退库"; + append = "已退库"; break; } - throw new Exception(string.Format("入库失败!当前条码{0}", msg)); + msg = string.Format("入库失败!当前条码{0}", append); + return null; } } session.Commit(); + msg = string.Empty; return entity; } } @@ -187,27 +189,27 @@ namespace ButcherFactory.BO.LocalBL return query.EExecuteScalar(session); } - public static void SetAsBacking(string barCode, int rowIndex) + public static string SetAsBacking(string barCode, int rowIndex) { using (var session = DmoSession.New()) { var localData = GetLocalData(session, barCode); if (localData == null) - throw new Exception("未入库,无法退库"); + return "未入库,无法退库"; switch (localData.Item2) { case -1: - throw new Exception("已删除,无法退库"); + return "已删除,无法退库"; case 1: - throw new Exception("已在退库中,等待提交"); + return "已在退库中,等待提交"; case 2: - throw new Exception("已退库,无法重复退库"); + return "已退库,无法重复退库"; default: Update(session, localData.Item1, new Tuple("State", 1), new Tuple("RowIndex", rowIndex)); session.Commit(); - break; + return string.Empty; } } } diff --git a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs index 8ce286a..3344fc5 100644 --- a/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs +++ b/ButcherFactory.BO/LocalBL/SegmentProductionBL.cs @@ -72,14 +72,14 @@ namespace ButcherFactory.BO.LocalBL entity.WorkUnit_ID = workUnitID; entity.ProductBatch_ID = productBatchID; entity.RowIndex = GenerateRowIndex(productBatchID, session); - entity.BarCode = string.Format("260912011{0:yyyyMMdd}{1}{2:00000}", batchDate,AppContext.ConnectInfo.ClientCode, entity.RowIndex); + entity.BarCode = string.Format("260912011{0:yyyyMMdd}{1}{2:00000}", batchDate, AppContext.ConnectInfo.ClientCode, entity.RowIndex); session.Insert(entity); session.Commit(); return entity; } } - public static SegmentProduction InsertAndSetGroupID(long goodsID, decimal weight, long? workUnitID, long productBatchID, DateTime batchDate,bool test) + public static SegmentProduction InsertAndSetGroupID(long goodsID, decimal weight, long? workUnitID, long productBatchID, DateTime batchDate, bool test) { using (var session = DmoSession.New()) { @@ -175,7 +175,7 @@ namespace ButcherFactory.BO.LocalBL { var update = new DQUpdateDom(typeof(SegmentProduction)); update.Columns.Add(new DQUpdateColumn("InStored", true)); - update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"),ids.Select(x=>DQExpression.Value(x)).ToArray())); + update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())); update.EExecute(); } @@ -209,7 +209,7 @@ namespace ButcherFactory.BO.LocalBL var query = new DQueryDom(new JoinAlias(typeof(SegmentProduction))); query.Columns.Add(DQSelectColumn.Sum("Weight")); query.Columns.Add(DQSelectColumn.Count()); - query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ProductBatch_ID", detail.ProductBatch_ID), DQCondition.EQ("Goods_ID", detail.Goods_ID))); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Delete", false), DQCondition.EQ("ProductBatch_ID", detail.ProductBatch_ID), DQCondition.EQ("Goods_ID", detail.Goods_ID))); using (var session = DmoSession.New()) { using (var reader = session.ExecuteReader(query)) @@ -261,6 +261,7 @@ namespace ButcherFactory.BO.LocalBL query.Columns.Add(DQSelectColumn.Field("Goods_ID")); query.Columns.Add(DQSelectColumn.Field("Weight")); query.Columns.Add(DQSelectColumn.Field("CreateTime")); + query.Columns.Add(DQSelectColumn.Field("Delete")); query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Submited", true), DQCondition.EQ("Sync", false))); query.Range = SelectRange.Top(10); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); @@ -280,6 +281,7 @@ namespace ButcherFactory.BO.LocalBL obj.Goods_ID = (long)reader[6]; obj.Weight = (decimal)reader[7]; obj.ProductTime = (DateTime)reader[8]; + obj.Delete = (bool)reader[9]; upload.Add(obj); } } @@ -293,6 +295,35 @@ namespace ButcherFactory.BO.LocalBL update.Columns.Add(new DQUpdateColumn("Sync", true)); session.ExecuteNonQuery(update); } + + public static void SetAsDelete(long id, string barCode) + { + var canDelete = CheckCanDelete(barCode); + if (canDelete == null) + throw new Exception("网络中断,请稍后再试!"); + else if (canDelete == false) + throw new Exception("已入库,不允许删除!"); + + var update = new DQUpdateDom(typeof(SegmentProduction)); + update.Where.Conditions.Add(DQCondition.EQ("ID", id)); + update.Columns.Add(new DQUpdateColumn("Sync", false)); + update.Columns.Add(new DQUpdateColumn("Delete", true)); + update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1)))); + update.EExecute(); + } + + static bool? CheckCanDelete(string barCode) + { + try + { + var rst = RpcFacade.Call(RpcPath + "CheckInStored", JsonConvert.SerializeObject(new List { barCode })); + return JsonConvert.DeserializeObject>(rst).Count == 0; + } + catch + { + return null; + } + } } class SegmentProductionMin @@ -309,7 +340,7 @@ namespace ButcherFactory.BO.LocalBL public long? Goods_ID { get; set; } public decimal? Weight { get; set; } public DateTime? InStoreTime { get; set; } - + public bool Delete { get; set; } } class TaskTemp diff --git a/ButcherFactory.BO/Utils/XmlUtil.cs b/ButcherFactory.BO/Utils/XmlUtil.cs index 6f05c1b..725394f 100644 --- a/ButcherFactory.BO/Utils/XmlUtil.cs +++ b/ButcherFactory.BO/Utils/XmlUtil.cs @@ -39,23 +39,40 @@ namespace ButcherFactory.BO.Utils using (var reader = new StreamReader(fileName)) { var xs = new XmlSerializer(typeof(T)); - object obj = xs.Deserialize(reader); - reader.Close(); - return (T)obj; + try + { + object obj = xs.Deserialize(reader); + return (T)obj; + } + catch + { + return new T(); + } + finally + { + reader.Close(); + } } } - public static T XmlDeserializeObject(string xmlOfObject) where T : class + public static T XmlDeserializeObject(string xmlOfObject) where T : class,new() { using (MemoryStream ms = new MemoryStream()) { using (StreamWriter sr = new StreamWriter(ms, Encoding.UTF8)) { - sr.Write(xmlOfObject); - sr.Flush(); - ms.Seek(0, SeekOrigin.Begin); - XmlSerializer serializer = new XmlSerializer(typeof(T)); - return serializer.Deserialize(ms) as T; + try + { + sr.Write(xmlOfObject); + sr.Flush(); + ms.Seek(0, SeekOrigin.Begin); + XmlSerializer serializer = new XmlSerializer(typeof(T)); + return serializer.Deserialize(ms) as T; + } + catch + { + return new T(); + } } } } diff --git a/ButcherFactory.Form/Controls/InfoBox.Designer.cs b/ButcherFactory.Form/Controls/InfoBox.Designer.cs index e9560ac..84cb6f5 100644 --- a/ButcherFactory.Form/Controls/InfoBox.Designer.cs +++ b/ButcherFactory.Form/Controls/InfoBox.Designer.cs @@ -35,9 +35,9 @@ // button1 // this.button1.Font = new System.Drawing.Font("宋体", 15F); - this.button1.Location = new System.Drawing.Point(180, 278); + this.button1.Location = new System.Drawing.Point(143, 278); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(120, 56); + this.button1.Size = new System.Drawing.Size(200, 56); this.button1.TabIndex = 0; this.button1.Text = "确定"; this.button1.UseVisualStyleBackColor = true; diff --git a/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs b/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs index bfd649e..c098338 100644 --- a/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs +++ b/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs @@ -13,6 +13,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using ButcherFactory.Utils; using ButcherFactory.BO.LocalBL; +using ButcherFactory.Controls; namespace ButcherFactory.SegmentInStore_ { @@ -140,7 +141,12 @@ namespace ButcherFactory.SegmentInStore_ if (isBack) { var idx = backStoreList.Any() ? backStoreList.First().RowIndex.Value : 0; - SegmentInStoreBL.SetAsBacking(uScanPanel1.TextBox.Text, idx + 1); + var msg = SegmentInStoreBL.SetAsBacking(uScanPanel1.TextBox.Text, idx + 1); + if (!string.IsNullOrEmpty(msg)) + { + InfoBox.Show("错误", msg, Color.Red, 2); + return; + } BindBackGrid(); var fir = inStoreList.FirstOrDefault(x => x.BarCode == uScanPanel1.TextBox.Text); if (fir != null) @@ -152,7 +158,13 @@ namespace ButcherFactory.SegmentInStore_ else { var idx = inStoreList.Any() ? inStoreList.First().RowIndex.Value : 0; - var entity = SegmentInStoreBL.InsertInStore(uScanPanel1.TextBox.Text, storeID, idx + 1); + string msg; + var entity = SegmentInStoreBL.InsertInStore(uScanPanel1.TextBox.Text, storeID, idx + 1,out msg); + if (!string.IsNullOrEmpty(msg)) + { + InfoBox.Show("错误", msg, Color.Red, 2); + return; + } inStoreList.Insert(0, entity); if (inStoreList.Count >= 30) inStoreList.RemoveAt(30); diff --git a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs index dc157c1..c009416 100644 --- a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs +++ b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.Designer.cs @@ -47,6 +47,7 @@ this.T_Last = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.GoodsLabel = new WinFormControl.ULabel(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.templateBtn = new ButcherFactory.Controls.ColorButton(); this.closeBtn = new ButcherFactory.Controls.ColorButton(); this.uWeightControl1 = new ButcherFactory.Controls.WeightControl(); this.testCkBox = new System.Windows.Forms.CheckBox(); @@ -69,7 +70,7 @@ 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.templateBtn = new ButcherFactory.Controls.ColorButton(); + this.deleteBtn = new ButcherFactory.Controls.ColorButton(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.taskDataGrid)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -221,6 +222,20 @@ this.splitContainer1.SplitterDistance = 87; this.splitContainer1.TabIndex = 1; // + // templateBtn + // + this.templateBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(144)))), ((int)(((byte)(98)))), ((int)(((byte)(222))))); + this.templateBtn.Font = new System.Drawing.Font("宋体", 15F); + this.templateBtn.ForeColor = System.Drawing.Color.White; + this.templateBtn.Location = new System.Drawing.Point(648, 35); + this.templateBtn.Name = "templateBtn"; + this.templateBtn.SelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(234)))), ((int)(((byte)(106))))); + this.templateBtn.Size = new System.Drawing.Size(111, 41); + this.templateBtn.TabIndex = 23; + this.templateBtn.Text = "选择标签"; + this.templateBtn.UseVisualStyleBackColor = false; + this.templateBtn.Click += new System.EventHandler(this.templateBtn_Click); + // // closeBtn // this.closeBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -348,6 +363,7 @@ // // splitContainer2.Panel2 // + this.splitContainer2.Panel2.Controls.Add(this.deleteBtn); this.splitContainer2.Panel2.Controls.Add(this.rePrintBtn); this.splitContainer2.Panel2.Controls.Add(this.groupBox1); this.splitContainer2.Panel2.Controls.Add(this.groupBox2); @@ -496,19 +512,20 @@ this.H_Weight.Name = "H_Weight"; this.H_Weight.ReadOnly = true; // - // templateBtn - // - this.templateBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(144)))), ((int)(((byte)(98)))), ((int)(((byte)(222))))); - this.templateBtn.Font = new System.Drawing.Font("宋体", 15F); - this.templateBtn.ForeColor = System.Drawing.Color.White; - this.templateBtn.Location = new System.Drawing.Point(648, 35); - this.templateBtn.Name = "templateBtn"; - this.templateBtn.SelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(234)))), ((int)(((byte)(106))))); - this.templateBtn.Size = new System.Drawing.Size(111, 41); - this.templateBtn.TabIndex = 23; - this.templateBtn.Text = "选择标签"; - this.templateBtn.UseVisualStyleBackColor = false; - this.templateBtn.Click += new System.EventHandler(this.templateBtn_Click); + // deleteBtn + // + this.deleteBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.deleteBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(25))))); + this.deleteBtn.Font = new System.Drawing.Font("宋体", 15F); + this.deleteBtn.ForeColor = System.Drawing.Color.White; + this.deleteBtn.Location = new System.Drawing.Point(178, 129); + this.deleteBtn.Name = "deleteBtn"; + this.deleteBtn.SelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(234)))), ((int)(((byte)(106))))); + this.deleteBtn.Size = new System.Drawing.Size(111, 41); + this.deleteBtn.TabIndex = 23; + this.deleteBtn.Text = "删除"; + this.deleteBtn.UseVisualStyleBackColor = false; + this.deleteBtn.Click += new System.EventHandler(this.deleteBtn_Click); // // SegmentProductionAutoForm // @@ -573,5 +590,6 @@ private Controls.ColorButton goodsSetBtn; private System.Windows.Forms.CheckBox testCkBox; private Controls.ColorButton templateBtn; + private Controls.ColorButton deleteBtn; } } \ No newline at end of file diff --git a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs index e6c0ec2..218a941 100644 --- a/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs +++ b/ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs @@ -102,7 +102,7 @@ namespace ButcherFactory.SegmentProductionAuto_ } productBatchSelect.EBindComboBox(x => x.Date == DateTime.Today, 6, "Date"); config = XmlUtil.DeserializeFromFile(); - workUnitSelect.EBindComboBox(x => x.ID == config.WorkUnitID); + workUnitSelect.EBindComboBox(x => x.ID == config.WorkUnitID, top: 100); BindGoods(); BindGrid(); @@ -162,6 +162,7 @@ namespace ButcherFactory.SegmentProductionAuto_ if (historyList.Count > 30) historyList.RemoveAt(30); historyDataGrid.FirstDisplayedScrollingRowIndex = 0; + historyDataGrid.Rows[0].Selected = true; historyDataGrid.Refresh(); } if (barPrintCheck.Checked) @@ -173,9 +174,19 @@ namespace ButcherFactory.SegmentProductionAuto_ } if (!testCkBox.Checked) { + var thd = new Thread(new ParameterizedThreadStart(RefreshTask)); + thd.Start(entity); + } + } + + void RefreshTask(object obj) + { + this.Invoke(new Action(() => + { + var entity = obj as SegmentProduction; taskDataGrid.DataSource = SegmentProductionBL.GetProductTask(batchDate ?? DateTime.Today, entity); taskDataGrid.Refresh(); - } + })); } void BindGrid() @@ -263,5 +274,23 @@ namespace ButcherFactory.SegmentProductionAuto_ { new TemplateSelector(config).ShowDialog(); } + + private void deleteBtn_Click(object sender, EventArgs e) + { + if (historyDataGrid.CurrentRow == null) + return; + if (MessageBox.Show( "确定删除选中记录?","删除确认", MessageBoxButtons.OKCancel) != DialogResult.OK) + return; + var item = historyDataGrid.CurrentRow.DataBoundItem as SegmentProduction; + SegmentProductionBL.SetAsDelete(item.ID, item.BarCode); + historyList.Remove(item); + historyDataGrid.DataSource = historyList; + if (historyList.Any()) + historyDataGrid.Rows[0].Selected = true; + historyDataGrid.Refresh(); + + var thd = new Thread(new ParameterizedThreadStart(RefreshTask)); + thd.Start(item); + } } } diff --git a/ButcherFactory.Login/App.xaml.cs b/ButcherFactory.Login/App.xaml.cs index e8b5707..a0e0cf0 100644 --- a/ButcherFactory.Login/App.xaml.cs +++ b/ButcherFactory.Login/App.xaml.cs @@ -1,4 +1,5 @@ -using System; +using ButcherFactory.BO.Utils; +using System; using System.Collections.Generic; using System.Configuration; using System.Data; @@ -45,6 +46,8 @@ namespace ButcherFactory.Login var tempImages = new System.IO.DirectoryInfo("TempImg").GetFiles(); foreach (var f in tempImages) f.Delete(); + if (e.Args.Length == 1 && e.Args[0] == "true") + UpdateDb(); } /// @@ -92,5 +95,22 @@ namespace ButcherFactory.Login MessageBox.Show("错误:" + e.Exception.Message + " \n详细信息:" + e.Exception.StackTrace); e.Handled = true; } + + void UpdateDb() + { + try + { + if (!string.IsNullOrEmpty(AppContext.ConnectInfo.SqlConnection)) + { + DbUtil.UpdateDatabase(AppContext.ConnectInfo.SqlConnection); + } + } + catch + { +#if DEBUG + throw; +#endif + } + } } } diff --git a/SelfHelpClient/ReadCardForm.Designer.cs b/SelfHelpClient/ReadCardForm.Designer.cs index 1a9d95b..86e4690 100644 --- a/SelfHelpClient/ReadCardForm.Designer.cs +++ b/SelfHelpClient/ReadCardForm.Designer.cs @@ -64,6 +64,7 @@ // ganyingPanel // this.ganyingPanel.BackgroundImage = global::SelfHelpClient.Properties.Resources.ganying; + this.ganyingPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.ganyingPanel.Location = new System.Drawing.Point(327, 31); this.ganyingPanel.Name = "ganyingPanel"; this.ganyingPanel.Size = new System.Drawing.Size(221, 152); @@ -96,6 +97,7 @@ // shuakaPanel // this.shuakaPanel.BackgroundImage = global::SelfHelpClient.Properties.Resources.shuaka; + this.shuakaPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.shuakaPanel.Location = new System.Drawing.Point(451, 175); this.shuakaPanel.Name = "shuakaPanel"; this.shuakaPanel.Size = new System.Drawing.Size(279, 258);