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; } if (ShipmentTicketUtilities.DeleteItemsSync(ids, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Search(); MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
/// <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 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(); }
private void buttonDelete_Click(object sender, EventArgs e) { int[] deleteIDs = this.GetSelectedIDs(); if (deleteIDs.Length == 0) { MessageBox.Show("请选择您要删除的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } WMSEntities wmsEntities = new WMSEntities(); //如果被作业单引用了,不能删除 try { StringBuilder sbIDArray = new StringBuilder(); foreach (int id in deleteIDs) { sbIDArray.Append(id + ","); } sbIDArray.Length--; int countRef = wmsEntities.Database.SqlQuery <int>(string.Format("SELECT COUNT(*) FROM JobTicket WHERE ShipmentTicketID 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("您真的要删除这些记录吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } this.labelStatus.Text = "正在删除..."; new Thread(new ThreadStart(() => { try { foreach (int ticketID in deleteIDs) { int[] itemIDs = (from s in wmsEntities.ShipmentTicketItem where s.ShipmentTicketID == ticketID select s.ID).ToArray(); if (ShipmentTicketUtilities.DeleteItemsSync(itemIDs, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } wmsEntities.Database.ExecuteSqlCommand("DELETE FROM ShipmentTicket WHERE ID = @shipmentTicketID", new SqlParameter("shipmentTicketID", ticketID)); } wmsEntities.SaveChanges(); } catch { MessageBox.Show("删除失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Invoke(new Action(() => { this.Search(true); })); })).Start(); }