public static bool DeleteItemsSync(int[] itemIDs, out string errorMessage) { try { using (WMSEntities wmsEntities = new WMSEntities()) { foreach (int id in itemIDs) { ShipmentTicketItem item = (from s in wmsEntities.ShipmentTicketItem where s.ID == id select s).FirstOrDefault(); if (item == null) { continue; } if (item.ScheduledJobAmount > 0) { errorMessage = "不能删除已分配翻包的零件!"; return(false); } //把库存已分配发货数减回去 decimal? amount = item.ShipmentAmount * item.UnitAmount; StockInfo stockInfo = (from s in wmsEntities.StockInfo where s.ID == item.StockInfoID select s).FirstOrDefault(); if (stockInfo == null) { continue; } stockInfo.ScheduledShipmentAmount -= amount ?? 0; wmsEntities.ShipmentTicketItem.Remove(item); } wmsEntities.SaveChanges(); errorMessage = null; return(true); } } catch { errorMessage = "操作失败,请检查网络连接"; return(false); } }
private bool importItemHandler(List <ShipmentTicketItem> results, Dictionary <string, string[]> unimportedColumns) { List <ShipmentTicketItem> realImportList = new List <ShipmentTicketItem>(); //真正要导入的ShipmentTicketItem(有的一个result项可能对应多个导入项) Dictionary <int, decimal> dicImportedSupplyIDAmountNoUnit = new Dictionary <int, decimal>(); try { WMSEntities wmsEntities = new WMSEntities(); for (int i = 0; i < results.Count; i++) { string supplyNoOrComponentName = unimportedColumns["SupplyNoOrComponentName"][i]; string realName = null; string jobPersonName = unimportedColumns["JobPersonName"][i]; string confirmPersonName = unimportedColumns["ConfirmPersonName"][i]; //封装的根据 零件名/供货代号 获取 零件/供货的函数 if (Utilities.GetSupplyOrComponentAmbiguous(supplyNoOrComponentName, out DataAccess.Component component, out Supply supply, out string errorMessage, -1, wmsEntities) == false) { MessageBox.Show(string.Format("行{0}:{1}", i + 1, errorMessage), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } StockInfoView[] stockInfoViews = null; //如果填写的是供货 if (supply != null) { realName = supply.No; stockInfoViews = (from s in wmsEntities.StockInfoView where s.SupplyID == supply.ID && s.ProjectID == this.projectID && s.WarehouseID == this.warehouseID && s.ShipmentAreaAmount - s.ScheduledShipmentAmount > 0 orderby s.InventoryDate ascending select s).ToArray(); } //否则填写的是零件 else if (component != null) { realName = component.Name; stockInfoViews = (from s in wmsEntities.StockInfoView where s.ComponentID == component.ID && s.ProjectID == this.projectID && s.WarehouseID == this.warehouseID && s.ShipmentAreaAmount - s.ScheduledShipmentAmount > 0 orderby s.InventoryDate ascending select s).ToArray(); } int jobPersonID = -1; int confirmPersonID = -1; //搜索作业人名 if (string.IsNullOrWhiteSpace(jobPersonName) == false) { if (Utilities.GetPersonByNameAmbiguous(jobPersonName, out Person jobPerson, out errorMessage, wmsEntities) == false) { MessageBox.Show(string.Format("行{0}:{1}", i + 1, errorMessage), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } jobPersonID = jobPerson.ID; } //搜索确认人名 if (string.IsNullOrWhiteSpace(confirmPersonName) == false) { if (Utilities.GetPersonByNameAmbiguous(confirmPersonName, out Person confirmPerson, out errorMessage, wmsEntities) == false) { MessageBox.Show(string.Format("行{0}:{1}", i + 1, errorMessage), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } confirmPersonID = confirmPerson.ID; } //计算总共还有多少可以发货的零件,如果不够提示库存不足 decimal totalShipmentableAmountNoUnit = stockInfoViews.Sum((stockInfoView) => { decimal shipmentableAmountNoUnit = (stockInfoView.ShipmentAreaAmount ?? 0) - stockInfoView.ScheduledShipmentAmount; if (dicImportedSupplyIDAmountNoUnit.ContainsKey(stockInfoView.ID)) { shipmentableAmountNoUnit -= dicImportedSupplyIDAmountNoUnit[stockInfoView.ID]; } shipmentableAmountNoUnit = shipmentableAmountNoUnit < 0 ? 0 : shipmentableAmountNoUnit; return(shipmentableAmountNoUnit); }); if (totalShipmentableAmountNoUnit < results[i].ShipmentAmount * results[i].UnitAmount) { MessageBox.Show(string.Format("行{0}:零件\"{1}\"库存不足,库存可发货数:{2} \n(如果之前行有重复此零件,则此数量为库存数减去之前行分配的数量)", i + 1, realName, Utilities.DecimalToString(totalShipmentableAmountNoUnit)), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } results[i].ShipmentTicketID = this.shipmentTicketID; results[i].JobPersonID = jobPersonID == -1 ? null : (int?)jobPersonID; results[i].ConfirmPersonID = confirmPersonID == -1 ? null : (int?)confirmPersonID; decimal curAmountNoUnit = 0; for (int j = 0; j < stockInfoViews.Length; j++) { ShipmentTicketItem newItem = new ShipmentTicketItem(); Utilities.CopyProperties(results[i], newItem); newItem.StockInfoID = stockInfoViews[j].ID; //计算当前StockInfo里还有多少可以发的数量 decimal curShipmentableAmountNoUnit = (stockInfoViews[j].ShipmentAreaAmount ?? 0) - stockInfoViews[j].ScheduledShipmentAmount; if (dicImportedSupplyIDAmountNoUnit.ContainsKey(stockInfoViews[j].ID)) { curShipmentableAmountNoUnit -= dicImportedSupplyIDAmountNoUnit[stockInfoViews[j].ID]; } if (curShipmentableAmountNoUnit <= 0) { continue; //当前如果没有可发货的数量,就跳过 } //当前StockInfo的数量小于要发货的数量 if (curAmountNoUnit + curShipmentableAmountNoUnit < results[i].ShipmentAmount * results[i].UnitAmount) { newItem.ShipmentAmount = curShipmentableAmountNoUnit / newItem.UnitAmount; realImportList.Add(newItem); //把已经发货的数量加到dicImportedSupplyIDAmountNoUnit里,在COMMIT之前,下轮循环用 if (dicImportedSupplyIDAmountNoUnit.ContainsKey(newItem.StockInfoID.Value) == false) { dicImportedSupplyIDAmountNoUnit.Add(newItem.StockInfoID.Value, curShipmentableAmountNoUnit); } else { dicImportedSupplyIDAmountNoUnit[newItem.StockInfoID.Value] += curShipmentableAmountNoUnit; } curAmountNoUnit += newItem.ShipmentAmount.Value * newItem.UnitAmount.Value; } else //当前StockInfo数量大于等于需要发货的数量 { newItem.ShipmentAmount = (results[i].ShipmentAmount * results[i].UnitAmount - curAmountNoUnit) / results[i].UnitAmount; realImportList.Add(newItem); //把已经发货的数量加到dicImportedSupplyIDAmountNoUnit里,在COMMIT之前,下轮循环用 if (dicImportedSupplyIDAmountNoUnit.ContainsKey(newItem.StockInfoID.Value) == false) { dicImportedSupplyIDAmountNoUnit.Add(newItem.StockInfoID.Value, ((results[i].ShipmentAmount * results[i].UnitAmount - curAmountNoUnit) ?? 0)); } else { dicImportedSupplyIDAmountNoUnit[newItem.StockInfoID.Value] += ((results[i].ShipmentAmount * results[i].UnitAmount - curAmountNoUnit) ?? 0); } //更新curAmountNoUnit curAmountNoUnit += newItem.ShipmentAmount.Value * (newItem.UnitAmount ?? 1); break; } } } foreach (ShipmentTicketItem item in realImportList) { //增加条目,记录库存分配发货数量 StockInfo stockInfo = (from s in wmsEntities.StockInfo where s.ID == item.StockInfoID select s).FirstOrDefault(); stockInfo.ScheduledShipmentAmount += (item.ShipmentAmount ?? 0) * (item.UnitAmount ?? 1); //设置发货单条目初始信息 item.ScheduledJobAmount = 0; wmsEntities.ShipmentTicketItem.Add(item); } wmsEntities.SaveChanges(); this.Search(); MessageBox.Show("导入成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.standardImportForm.Close(); } catch (Exception ex) { MessageBox.Show("操作失败,请检查网络连接!\n请把如下错误信息反馈给我们!\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(false); }
private void buttonAlter_Click(object sender, EventArgs e) { int[] ids = Utilities.GetSelectedIDs(this.reoGridControlMain); if (ids.Length != 1) { MessageBox.Show("请选择一项进行修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.curStockInfoID == -1) { MessageBox.Show("请选择零件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } WMSEntities wmsEntities = new WMSEntities(); int id = ids[0]; ShipmentTicketItem shipmentTicketItem = null; try { shipmentTicketItem = (from s in wmsEntities.ShipmentTicketItem where s.ID == id select s).FirstOrDefault(); } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (shipmentTicketItem == null) { MessageBox.Show("发货单条目不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } StockInfo oriStockInfo = (from s in wmsEntities.StockInfo where s.ID == shipmentTicketItem.StockInfoID select s).FirstOrDefault(); shipmentTicketItem.StockInfoID = this.curStockInfoID; StockInfo newStockInfo = (from s in wmsEntities.StockInfo where s.ID == this.curStockInfoID select s).FirstOrDefault(); if (newStockInfo == null) { MessageBox.Show("零件不存在,请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } shipmentTicketItem.ConfirmPersonID = this.curConfirmPersonID == -1 ? null : (int?)this.curConfirmPersonID; shipmentTicketItem.JobPersonID = this.curJobPersonID == -1 ? null : (int?)this.curJobPersonID; decimal oriShipmentAmount = shipmentTicketItem.ShipmentAmount * (shipmentTicketItem.UnitAmount ?? 1) ?? 0; if (Utilities.CopyTextBoxTextsToProperties(this, shipmentTicketItem, ShipmentTicketItemViewMetaData.KeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (shipmentTicketItem.ShipmentAmount <= 0) { MessageBox.Show("发货数量必须大于0!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } decimal?deltaStockAmount = (shipmentTicketItem.ShipmentAmount * shipmentTicketItem.UnitAmount) - oriShipmentAmount; decimal shipmentableAmount = (newStockInfo.ShipmentAreaAmount ?? 0) - newStockInfo.ScheduledShipmentAmount; shipmentableAmount = shipmentableAmount < 0 ? 0 : shipmentableAmount; if (deltaStockAmount > shipmentableAmount) { MessageBox.Show("库存不足!当前可发货库存数量:" + Utilities.DecimalToString(shipmentableAmount) + "个", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //把库存已分配发货数量同步! if (oriStockInfo != newStockInfo) { if (oriStockInfo != null) { oriStockInfo.ScheduledShipmentAmount -= oriShipmentAmount; } if (newStockInfo != null) { newStockInfo.ScheduledShipmentAmount += (shipmentTicketItem.ShipmentAmount * shipmentTicketItem.UnitAmount) ?? 0; } } else { newStockInfo.ScheduledShipmentAmount += deltaStockAmount ?? 0; } try { wmsEntities.SaveChanges(); } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Invoke(new Action(() => { this.Search(); Utilities.SelectLineByID(this.reoGridControlMain, shipmentTicketItem.ID); })); MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void buttonAdd_Click(object sender, EventArgs e) { if (this.curStockInfoID == -1) { MessageBox.Show("请选择零件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ShipmentTicketItem shipmentTicketItem = new ShipmentTicketItem(); shipmentTicketItem.StockInfoID = this.curStockInfoID; shipmentTicketItem.ShipmentTicketID = this.shipmentTicketID; shipmentTicketItem.ConfirmPersonID = this.curConfirmPersonID == -1 ? null : (int?)this.curConfirmPersonID; shipmentTicketItem.JobPersonID = this.curJobPersonID == -1 ? null : (int?)this.curJobPersonID; if (Utilities.CopyTextBoxTextsToProperties(this, shipmentTicketItem, ShipmentTicketItemViewMetaData.KeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (shipmentTicketItem.ShipmentAmount < shipmentTicketItem.ScheduledJobAmount) { MessageBox.Show("发货数量不能小于已分配翻包作业数量!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } WMSEntities wmsEntities = new WMSEntities(); try { //不扣除库存发货区数量,但记录库存已分配发货数量 StockInfo stockInfo = (from s in wmsEntities.StockInfo where s.ID == shipmentTicketItem.StockInfoID select s).FirstOrDefault(); if (stockInfo == null) { MessageBox.Show("零件不存在,请重新选择", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } decimal shipmentableAmount = (stockInfo.ShipmentAreaAmount ?? 0) - stockInfo.ScheduledShipmentAmount; shipmentableAmount = shipmentableAmount < 0 ? 0 : shipmentableAmount; if (shipmentTicketItem.ShipmentAmount * shipmentTicketItem.UnitAmount > shipmentableAmount) { MessageBox.Show("添加失败,库存可发货数量不足!可发货数:" + Utilities.DecimalToString(shipmentableAmount), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } stockInfo.ScheduledShipmentAmount += shipmentTicketItem.ShipmentAmount * shipmentTicketItem.UnitAmount ?? 0; wmsEntities.ShipmentTicketItem.Add(shipmentTicketItem); wmsEntities.SaveChanges(); } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Invoke(new Action(() => { this.Search(shipmentTicketItem.ID); })); MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void buttonDelete_Click(object sender, EventArgs e) { int[] ids = Utilities.GetSelectedIDs(this.reoGridControlMain); if (ids.Length == 0) { MessageBox.Show("请选择要删除的项目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } WMSEntities wmsEntities = new WMSEntities(); //如果被出库单引用了,不能删除 try { StringBuilder sbIDArray = new StringBuilder(); foreach (int id in ids) { sbIDArray.Append(id + ","); } sbIDArray.Length--; int countRef = wmsEntities.Database.SqlQuery <int>(string.Format("SELECT COUNT(*) FROM PutOutStorageTicket WHERE JobTicketID IN ({0})", sbIDArray.ToString())).Single(); if (countRef > 0) { MessageBox.Show("删除失败,作业单被出库单引用,请先删除出库单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { MessageBox.Show("操作失败,请检查您的网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MessageBox.Show("确定要删除选中项吗?\n重要提示:\n删除后所有零件的分配翻包数量将会退回发货单中,无视实际翻包数量!\n请谨慎操作!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } this.labelStatus.Text = "正在删除"; new Thread(new ThreadStart(() => { try { List <int> shipmentTicketIDs = new List <int>(); foreach (int id in ids) { JobTicket jobTicket = (from j in wmsEntities.JobTicket where j.ID == id select j).FirstOrDefault(); if (jobTicket.State != JobTicketViewMetaData.STRING_STATE_UNFINISHED) { MessageBox.Show("删除失败,只能删除未完成翻包的作业单!\n如果需要强行删除,请使用修改功能将单据状态改为未完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } foreach (JobTicketItem jobTicketItem in jobTicket.JobTicketItem) { ShipmentTicketItem shipmentTicketItem = (from s in wmsEntities.ShipmentTicketItem where s.ID == jobTicketItem.ShipmentTicketItemID select s).FirstOrDefault(); if (shipmentTicketItem == null) { continue; } //如果删除作业单,则发货单直接把计划翻包数量的全部数量加回来,无视实际翻包数量 shipmentTicketItem.ScheduledJobAmount -= ((jobTicketItem.ScheduledAmount ?? 0) * (jobTicketItem.UnitAmount ?? 1)) / (shipmentTicketItem.UnitAmount ?? 1); } if (jobTicket.ShipmentTicketID != null) { shipmentTicketIDs.Add(jobTicket.ShipmentTicketID.Value); } wmsEntities.Database.ExecuteSqlCommand(string.Format("DELETE FROM JobTicket WHERE ID = {0}", id)); } wmsEntities.SaveChanges(); foreach (int shipmentTicketID in shipmentTicketIDs) { ShipmentTicketUtilities.UpdateShipmentTicketStateSync(shipmentTicketID, wmsEntities); } } catch { MessageBox.Show("删除失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Invoke(new Action(() => { this.Search(true); })); })).Start(); }
/// <summary> /// 无脑生成作业单,不选零件不填数量。 /// </summary> /// <param name="shipmentTicketIDs"></param> /// <param name="wmsEntities"></param> public static bool GenerateJobTicketFullSync(int shipmentTicketID, WMSEntities wmsEntities, DateTime?createTime = null) { ShipmentTicket shipmentTicket = (from s in wmsEntities.ShipmentTicket where s.ID == shipmentTicketID select s).FirstOrDefault(); if (shipmentTicket == null) { MessageBox.Show("发货单不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ShipmentTicketItem[] shipmentTicketItems = (from s in wmsEntities.ShipmentTicketItem where s.ShipmentTicketID == shipmentTicketID select s).ToArray(); List <JobTicketItem> newJobTicketItems = new List <JobTicketItem>(); for (int i = 0; i < shipmentTicketItems.Length; i++) { ShipmentTicketItem shipmentTicketItem = shipmentTicketItems[i]; if (shipmentTicketItem == null) { MessageBox.Show("发货单条目不存在,可能已被删除,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } decimal restScheduableAmount = (shipmentTicketItem.ShipmentAmount - (shipmentTicketItem.ScheduledJobAmount ?? 0)) ?? 0; if (restScheduableAmount <= 0) { continue; } var jobTicketItem = new JobTicketItem(); jobTicketItem.ScheduledAmount = restScheduableAmount; jobTicketItem.StockInfoID = shipmentTicketItem.StockInfoID; jobTicketItem.ShipmentTicketItemID = shipmentTicketItem.ID; jobTicketItem.State = JobTicketItemViewMetaData.STRING_STATE_UNFINISHED; jobTicketItem.Unit = shipmentTicketItem.Unit; jobTicketItem.UnitAmount = shipmentTicketItem.UnitAmount; jobTicketItem.RealAmount = 0; shipmentTicketItem.ScheduledJobAmount = (shipmentTicketItem.ScheduledJobAmount ?? 0) + jobTicketItem.ScheduledAmount; newJobTicketItems.Add(jobTicketItem); } if (newJobTicketItems.Count == 0) { MessageBox.Show("发货单 " + shipmentTicket.No + " 中无可分配翻包的零件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } JobTicket newJobTicket = new JobTicket(); foreach (JobTicketItem item in newJobTicketItems) { newJobTicket.JobTicketItem.Add(item); } wmsEntities.JobTicket.Add(newJobTicket); newJobTicket.State = JobTicketViewMetaData.STRING_STATE_UNFINISHED; newJobTicket.ShipmentTicketID = shipmentTicket.ID; newJobTicket.ProjectID = GlobalData.ProjectID; newJobTicket.WarehouseID = GlobalData.WarehouseID; newJobTicket.CreateUserID = GlobalData.UserID; newJobTicket.CreateTime = createTime ?? DateTime.Now; if (string.IsNullOrWhiteSpace(newJobTicket.JobTicketNo)) { DateTime createDay = new DateTime(shipmentTicket.CreateTime.Value.Year, shipmentTicket.CreateTime.Value.Month, shipmentTicket.CreateTime.Value.Day); DateTime nextDay = createDay.AddDays(1); int maxRankOfToday = Utilities.GetMaxTicketRankOfDay((from j in wmsEntities.JobTicket where j.CreateTime >= createDay && j.CreateTime < nextDay select j.JobTicketNo).ToArray()); newJobTicket.JobTicketNo = Utilities.GenerateTicketNo("Z", newJobTicket.CreateTime.Value, maxRankOfToday + 1); } wmsEntities.SaveChanges(); //更新发货单状态 ShipmentTicketUtilities.UpdateShipmentTicketStateSync(shipmentTicketID, wmsEntities, true); return(true); }
private void buttonModify_Click(object sender, EventArgs e) { int[] ids = Utilities.GetSelectedIDs(this.reoGridControlMain); if (ids.Length != 1) { MessageBox.Show("请选择一项进行修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int id = ids[0]; WMSEntities wmsEntities1 = new WMSEntities(); JobTicketItem jobTicketItem = null; try { jobTicketItem = (from j in wmsEntities1.JobTicketItem where j.ID == id select j).FirstOrDefault(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (jobTicketItem == null) { MessageBox.Show("作业任务不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Invoke(new Action(() => { decimal oriScheduledAmountNoUnit = (jobTicketItem.ScheduledAmount ?? 0) * (jobTicketItem.UnitAmount ?? 1); //原翻包数量*单位 if (Utilities.CopyTextBoxTextsToProperties(this, jobTicketItem, JobTicketItemViewMetaData.KeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Utilities.CopyComboBoxsToProperties(this, jobTicketItem, JobTicketItemViewMetaData.KeyNames) == false) { MessageBox.Show("内部错误:拷贝单选框数据失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (jobTicketItem.RealAmount > jobTicketItem.ScheduledAmount) { MessageBox.Show("实际翻包数量不能超过计划翻包数量!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (jobTicketItem.RealAmount < jobTicketItem.ScheduledPutOutAmount) { MessageBox.Show("实际翻包数量不能小于已分配出库数量!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //如果修改了计划翻包数量,这个数量不可以大于发货单剩余可分配翻包数量 //新的计划翻包数量 decimal newScheduledAmountNoUnit = (jobTicketItem.ScheduledAmount ?? 0) * (jobTicketItem.UnitAmount ?? 1); //变化的计划翻包数量 decimal deltaScheduledAmountNoUnit = newScheduledAmountNoUnit - oriScheduledAmountNoUnit; if (deltaScheduledAmountNoUnit != 0) { if (jobTicketItem.ScheduledAmount < jobTicketItem.RealAmount) { MessageBox.Show("计划翻包数量不可以小于实际翻包数量!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ShipmentTicketItem shipmentTicketItem = (from s in wmsEntities1.ShipmentTicketItem where s.ID == jobTicketItem.ShipmentTicketItemID select s).FirstOrDefault(); if (shipmentTicketItem != null) { //发货总数量 decimal shipmentAmountNoUnit = (shipmentTicketItem.ShipmentAmount ?? 0) * (shipmentTicketItem.UnitAmount ?? 1); //剩余可分配翻包数量 decimal restScheduableAmountNoUnit = shipmentAmountNoUnit - (shipmentTicketItem.ScheduledJobAmount ?? 0) * (shipmentTicketItem.UnitAmount ?? 1); if (restScheduableAmountNoUnit < deltaScheduledAmountNoUnit) { MessageBox.Show(string.Format("发货单剩余可分配翻包数量不足!\n剩余可分配翻包数:{0}({1})", Utilities.DecimalToString(restScheduableAmountNoUnit / (jobTicketItem.UnitAmount ?? 1)), jobTicketItem.Unit), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //把多的计划翻包数量加进发货单的已分配发货数里 shipmentTicketItem.ScheduledJobAmount += deltaScheduledAmountNoUnit / shipmentTicketItem.UnitAmount; } } int jobPersonID = this.JobPersonIDGetter(); int confirmPersonID = this.ConfirmPersonIDGetter(); jobTicketItem.JobPersonID = jobPersonID == -1 ? null : (int?)jobPersonID; jobTicketItem.ConfirmPersonID = confirmPersonID == -1 ? null : (int?)confirmPersonID; if (jobTicketItem.RealAmount == jobTicketItem.ScheduledAmount) { jobTicketItem.State = JobTicketItemViewMetaData.STRING_STATE_ALL_FINISHED; } else if (jobTicketItem.RealAmount == 0) { jobTicketItem.State = JobTicketItemViewMetaData.STRING_STATE_UNFINISHED; } else { jobTicketItem.State = JobTicketItemViewMetaData.STRING_STATE_PART_FINISHED; } try { wmsEntities1.SaveChanges(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.UpdateJobTicketStateSync(); this.Invoke(new Action(() => this.Search())); MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); })); }