public ConfirmResponse(IDbName _database, int _ekanbanDeviceId, int _confirmQty) { try { EKanbanTaskQuery eKanbanTaskQuery = new EKanbanTaskQuery(_database); SequenceQuery sequenceQuery = new SequenceQuery(_database); ComponentQuery componentQuery = new ComponentQuery(_database); StockQuery stockQuery = new StockQuery(_database); ScheduleQuery scheduleQuery = new ScheduleQuery(_database); SysHistoryQuery sysHistoryQuery = new SysHistoryQuery(_database); var Interface = eKanbanTaskQuery.GetLastEKanbanInterface(_ekanbanDeviceId); var his = sysHistoryQuery.GetEKanbanHistory(Interface); if (Interface.SysActionCode == (int)SYS_MODELS._ENUM.SysActionCode.EKANBAN_CONFIRM_ITEM) { ConfirmSuccess = true; EMessage = "EKanban is already conform!"; return; } Interface.SysActionCode = (int)SYS_MODELS._ENUM.SysActionCode.EKANBAN_CONFIRM_ITEM; Interface.LastUpdate = DateTime.Now; if (!eKanbanTaskQuery.UpdateEKanbanInterface(Interface)) { ConfirmSuccess = false; EMessage = "EKanban is already conform!"; return; } List <Schedule> schedules = new List <Schedule>(); foreach (var item in Interface.EKanbanLoadings) { var sch = scheduleQuery.GetSchedule(ShareFuncs.GetInt(item.OriginalPo_Id)); var Seq = sequenceQuery.GetOriginalSequence(ShareFuncs.GetInt(item.OriginalSequence_Id)); if (sch != null) { var stock = stockQuery.GetPrepareStockMeasure(sch); if (stock != null) { StockConfirmSequence stockConfirm = new StockConfirmSequence { FinishTime = DateTime.Now, SequenceNo = Seq.SequenceNo, SequenceQty = Seq.Quantity, StockMeasure_Id = stock.id, }; StockMessage = "Update stock message successfully"; if (!stockQuery.AddNewStockConfirm(stockConfirm)) { StockMessage = "An error orcured while updating stock"; } stock.ConfirmUpdateTime = DateTime.Now; stock.EKanbanConfirmQty += Seq.Quantity; if (!stockQuery.UpdateStockMeasure(stock)) { StockMessage = "An error orcured while updating stock"; } } } item.SysActionCode = (int)SYS_MODELS._ENUM.SysActionCode.SEQUENCE_CONFORM; item.LastUpdate = DateTime.Now; item.ConfirmQty = _confirmQty; eKanbanTaskQuery.UpdateEKanbanLoading(item); string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(Interface); his.Data = jsonStr; his.DateTime = DateTime.Now; sysHistoryQuery.UpdateEKanbanHis(his); EKanbanConfirmHis eKanbanConfirmHis = new EKanbanConfirmHis { Conform = true, DateTime = DateTime.Now, EKanbanHis_Id = his.id, OriginalSequence_Id = Seq.id, SequenceNo = Seq.SequenceNo, SequenceQty = Seq.Quantity, }; sysHistoryQuery.AddNewConfirmHistory(eKanbanConfirmHis); } ConfirmSuccess = true; EMessage = "EKanban is conform successfully"; } catch (Exception e) { EMessage = e.Message; } }
/// <summary> /// Thêm thông tin vào Ekanban /// </summary> private void AddSequenceToEKanban() { if (SelectedEKanbanDevice == null || SelectedEKanbanDevice.id == 0) { MessageBox.Show("An Error orcured while adding Sequence to EKanban.\r\nError: Missing Ekanban device.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var ekbLoading = EKanbanTaskQuery.GetEKanbanLoading(SelectedSequence.id); if (ekbLoading != null) { MessageBox.Show("An Error orcured while adding Sequence to EKanban.\r\nError: The sequence is already added.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (SelectedOriginalPo.id == 0 || SelectedSequence.id == 0 || SelectedSchedule.id == 0) { MessageBox.Show("An Error orcured while adding Sequence to EKanban.\r\nError: Missing data.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var dresult = MessageBox.Show("Make sure you want to continue?", "Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dresult != DialogResult.Yes) { return; } int action = 0; SysActionCode SysCode = SysActionCode.UNKNOW; EKanbanHis EkanbanHis = new EKanbanHis(); if (SelectedEKanbanInterface == null) { action = 0; } else { if (SelectedEKanbanInterface.id != 0) { SysCode = (SysActionCode)SelectedEKanbanInterface.SysActionCode; EkanbanHis = SysHistoryQuery.GetEKanbanHistory(SelectedEKanbanInterface); } } switch (SysCode) { case SysActionCode.SEQUENCE_PREPARING: case SysActionCode.EKANBAN_ADD_NEW_ITEM: dresult = MessageBox.Show("EKanban is holding data, do you want to continue?", "Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dresult != DialogResult.Yes) { return; } action = 1; break; case SysActionCode.SEQUENCE_CONFORM: case SysActionCode.EKANBAN_CONFIRM_ITEM: action = 0; break; default: break; } switch (action) { case 0: // add new interface List <EKanbanComponent> eKanbanComponent = new List <EKanbanComponent>(); foreach (var item in SelectShoeComponent) { if (item.AddToEkanban) { eKanbanComponent.Add(new EKanbanComponent { ShoeComponent_Id = item.Id, CuttingType_Id = item.CuttingType.id, }); } } // add new interface EKanbanInterface eKanbanInterface = new EKanbanInterface { LastUpdate = DateTime.Now, PO = GetShortPoNumber(SelectedSchedule.PoNumber), Line = SelectedScheduleLine, EKanbanDevice_Id = SelectedEKanbanDevice.id, POqty = SelectedSchedule.Quantity.ToString(), SysActionCode = (int)SysActionCode.EKANBAN_ADD_NEW_ITEM, EkanbanComponents = new List <EKanbanComponent>(eKanbanComponent), SequenceNo = SelectedSequence.SequenceNo.ToString(), CartQty = SelectedSequence.Quantity.ToString(), EKanbanLoadings = new List <EKanbanLoading> { new EKanbanLoading { SysActionCode = (int)SysActionCode.SEQUENCE_PREPARING, OriginalPo_Id = SelectedOriginalPo.id, OriginalSequence_Id = SelectedSequence.id, LastUpdate = DateTime.Now, SequenceQty = SelectedSequence.Quantity } } }; if (EKanbanTaskQuery.AddNewEKanbanInterface(eKanbanInterface)) { var inf1 = EKanbanTaskQuery.FindEKanbanInterface(eKanbanInterface.id); string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(inf1); EkanbanHis = new EKanbanHis { EKanbanInterface_Id = eKanbanInterface.id, EKanbanDevice_Id = SelectedEKanbanDevice.id, DateTime = DateTime.Now, ProductionLine_Id = SelectedSchedule.ProductionLine_Id, Data = jsonStr, }; MessageBox.Show("Add new Ekanban Interface successfully", "Message"); bool success = SysHistoryQuery.AddNewEKanbanHisotry(EkanbanHis); if (!success) { MessageBox.Show("Add new Ekanban history record error", "Message"); return; } } else { MessageBox.Show("An error orcured while adding new Po to Ekanban.\r\nError: Failed to add new Ekanban interface to database.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } break; case 1: // update interface EKanbanLoading eKanbanLoading = new EKanbanLoading { EKanbanInterface_Id = SelectedEKanbanInterface.id, SysActionCode = (int)SysActionCode.SEQUENCE_PREPARING, OriginalPo_Id = SelectedOriginalPo.id, OriginalSequence_Id = SelectedSequence.id, LastUpdate = DateTime.Now, SequenceQty = SelectedSequence.Quantity, }; bool exp1 = EKanbanTaskQuery.AddNewEKanbanLoading(eKanbanLoading); if (!exp1) { MessageBox.Show("An error orcured while adding new Po to Ekanban.\r\nError: Failed to add EkanbanLoading to database.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } SelectedEKanbanInterface.PO += $",{GetShortPoNumber(SelectedSchedule.PoNumber)}"; SelectedEKanbanInterface.SequenceNo += $",{SelectedSequence.SequenceNo}"; SelectedEKanbanInterface.POqty += $",{SelectedSchedule.Quantity}"; SelectedEKanbanInterface.CartQty += $",{SelectedSequence.Quantity}"; SelectedEKanbanInterface.LastUpdate = DateTime.Now; bool exp2 = EKanbanTaskQuery.UpdateEKanbanInterface(SelectedEKanbanInterface); EKanbanInterface inf2 = EKanbanTaskQuery.FindEKanbanInterface(SelectedEKanbanInterface.id); var his = SysHistoryQuery.GetEKanbanHistory(SelectedEKanbanInterface); string jsonStr2 = Newtonsoft.Json.JsonConvert.SerializeObject(inf2); his.Data = jsonStr2; his.DateTime = DateTime.Now; SysHistoryQuery.UpdateEKanbanHis(his); if (exp1 && exp2) { MessageBox.Show("Add new Po to Ekanban succeesfully", "Message"); } if (!exp2) { MessageBox.Show("An error orcured while adding new Po to Ekanban.\r\nError: Failed to update Ekanban interface.", "Message"); EKanbanTaskQuery.DeleteEKanbanLoading(eKanbanLoading); return; } // update interface break; } UpdateSelectedSchedule(); UpdateSelectedEkanbanDevice(); UpdateSelectedOriginalSequence(); AddNewStockMeasure(); AddNewHistory(EkanbanHis.id); }