public int UpdateConsumption(List <InventoryTransactionDTO> dtoInvTrnsList) { try { InventoryTransactionDAO InventoryTransaction = new InventoryTransactionDAO(CommonLib.Common.CurrentDatabase); for (int i = 0; i < dtoInvTrnsList.Count; i++) { #region Validate Mandatory IssueEntryValidator valIssue = new IssueEntryValidator(); ErrorItem errorItem = null; errorItem = valIssue.CheckIssueDate(dtoInvTrnsList[i].TRANS_DATE); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } #endregion InventoryTransaction.UpdateWithoutPK(null, dtoInvTrnsList[i]); } } catch (Exception) { //CommonLib.Common.CurrentDatabase.Rollback(); throw; } return(1); }
public override void OnSaveAndClose() { try { fpIssueList.StopCellEditing(); // ต้องเรียกก่อน Save เสมอ เพื่อ Commit ข้อมูลการแก้ไขล่าสุดบน Grid // ใช้ได้เฉพาะกับ Sheet ที่ผูก DataSource CtrlUtil.SpreadSheetRowEndEdit(shtIssueList, shtIssueList.ActiveRowIndex); RemoveRowUnused(); // Validate Data before Save IssueEntryValidator valIssue = new IssueEntryValidator(); ErrorItem errorItem; errorItem = valIssue.CheckIssueDate(new NZDateTime(dtIssueDate, dtIssueDate.Value)); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } errorItem = valIssue.CheckEmptySubType(new NZString(cboSubType, cboSubType.SelectedValue)); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } //errorItem = valIssue.CheckEmptyItemCode(new NZString(txtItemCode, txtItemCode.Text)); //if (null != errorItem) ValidateException.ThrowErrorItem(errorItem); errorItem = valIssue.CheckEmptyLocFrom(new NZString(cboFromLoc, cboFromLoc.SelectedValue)); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } errorItem = valIssue.CheckEmptyLocTo(new NZString(cboToLoc, cboToLoc.SelectedValue)); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } errorItem = valIssue.CheckFromToLocation(new NZString(cboFromLoc, cboFromLoc.SelectedValue), new NZString(cboToLoc, cboToLoc.SelectedValue)); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } for (int i = 0; i < shtIssueList.Rows.Count; i++) { if (!ValidateRowSpread(i, true)) { return; } } MessageDialogResult dr = MessageDialog.ShowConfirmation(this, new EVOFramework.Message(Messages.eConfirm.CFM9001.ToString()).MessageDescription); switch (dr) { case MessageDialogResult.Cancel: return; case MessageDialogResult.No: // this.Close(); return; case MessageDialogResult.Yes: break; } if (m_Mode == eSaveMode.ADD) //|| (m_Mode == eSaveMode.UPDATE)) { if (SaveData()) { MessageDialog.ShowInformation(this, "Information", new EVOFramework.Message(Messages.eInformation.INF9003.ToString()).MessageDescription); Close(); } } else { if (SaveDataEditMode()) { MessageDialog.ShowInformation(this, "Information", new EVOFramework.Message(Messages.eInformation.INF9003.ToString()).MessageDescription); Close(); } } } catch (ValidateException err) { for (int i = 0; i < err.ErrorResults.Count; i++) { MessageDialog.ShowBusiness(this, err.ErrorResults[i].Message); err.ErrorResults[i].FocusOnControl(); } } catch (BusinessException err) { MessageDialog.ShowBusiness(this, err.Error.Message); err.Error.FocusOnControl(); } catch (Exception ex) { MessageDialog.ShowBusiness(this, ex.Message); } }
public int AddIssueConsumption(List <InventoryTransactionDTO> dtoInvTrnsList) { try { #region Validate Mandatory IssueEntryValidator valIssue = new IssueEntryValidator(); InventoryOnhandValidator valINV = new InventoryOnhandValidator(); ErrorItem errorItem = null; if (dtoInvTrnsList.Count > 0) { errorItem = valIssue.CheckIssueDate(dtoInvTrnsList[0].TRANS_DATE); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } } // CHECK EXIST INVENTORY ONHAND //for (int i = 0; i < dtoInvTrnsList.Count; i++) //{ // if (dtoInvTrnsList[i].IN_OUT_CLS.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.Out)) // { // // NZString YearMonth = new NZString(null, dtoInvTrnsList[i].TRANS_DATE.StrongValue.ToString("yyyyMM")); // errorItem = valINV.CheckOnhandQty(dtoInvTrnsList[i].IN_OUT_CLS.StrongValue, dtoInvTrnsList[i].QTY, dtoInvTrnsList[i].ITEM_CD, // dtoInvTrnsList[i].LOC_CD, dtoInvTrnsList[i].LOT_NO); // if (null != errorItem) ValidateException.ThrowErrorItem(errorItem); // } //} #endregion // lock transaction TransactionLockDAO daoTrans = new TransactionLockDAO(CommonLib.Common.CurrentDatabase); TransactionLockDTO dtoTrans = new TransactionLockDTO(); NZString key1 = new NZString(null, "ISSUE_TRANS_ID"); NZString key2 = new NZString(null, "INV_TRANS_TR"); if (!daoTrans.Exist(null, key1, key2)) { dtoTrans.KEY1 = key1; dtoTrans.KEY2 = key2; dtoTrans.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD; dtoTrans.CRT_DATE.Value = DateTime.Now; dtoTrans.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine; daoTrans.AddNew(null, dtoTrans); } // end of lock transaction InventoryTransactionDAO InventoryTransaction = new InventoryTransactionDAO(CommonLib.Common.CurrentDatabase); RunningNumberBIZ bizRunning = new RunningNumberBIZ(); NZString TransID = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR")); NZString RefID = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR")); NZString ConsumptionID = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR")); // if load success then lock transaction daoTrans.SelectWithKeys(null, key1, key2); // end of lock transaction dtoInvTrnsList[0].TRANS_ID = TransID; dtoInvTrnsList[0].REF_NO = RefID; dtoInvTrnsList[1].TRANS_ID = RefID; dtoInvTrnsList[1].REF_NO = TransID; dtoInvTrnsList[2].TRANS_ID = ConsumptionID; dtoInvTrnsList[2].REF_NO = RefID; for (int i = 0; i < dtoInvTrnsList.Count; i++) { InventoryTransaction.AddNew(null, dtoInvTrnsList[i]); } daoTrans.DeleteWithKeys(null, key1, key2); CommonLib.Common.CurrentDatabase.Commit(); } catch (ValidateException) { CommonLib.Common.CurrentDatabase.Rollback(); throw; } catch (BusinessException) { CommonLib.Common.CurrentDatabase.Rollback(); throw; } catch (Exception) { CommonLib.Common.CurrentDatabase.Rollback(); throw; } finally { if (CommonLib.Common.CurrentDatabase.DBConnectionState == ConnectionState.Open) { CommonLib.Common.CurrentDatabase.Close(); } } return(1); }
private bool CheckMandatory() { try { IssueEntryValidator val = new IssueEntryValidator(); CommonBizValidator commonVal = new CommonBizValidator(); #region Mandatory check ErrorItem errorItem; NZString FromLoc = new NZString(cboFromLoc, cboFromLoc.SelectedValue); NZString ToLoc = new NZString(cboToLoc, cboToLoc.SelectedValue); NZString ItemCD = new NZString(txtItemCode, txtItemCode.Text); NZString LotNo = new NZString(txtLotNo, txtLotNo.Text); InventoryPeriodBIZ biz = new InventoryPeriodBIZ(); InventoryPeriodDTO dto = biz.LoadPeriodByDate(new NZDateTime(dtIssueDate, dtIssueDate.Value)); errorItem = val.CheckIssueDate(new NZDateTime(null, dtIssueDate.Value)); if (null != errorItem) { // ถ้าเป็น issue ของเดือนถัดไปจะต้องทำได้ errorItem = val.CheckIssueMonth(new NZDateTime(null, dtIssueDate.Value)); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } } errorItem = val.CheckEmptyItemCode(ItemCD); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } errorItem = val.CheckEmptyLocFrom(FromLoc); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } errorItem = val.CheckEmptyLocTo(ToLoc); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } errorItem = val.CheckFromToLocation(FromLoc, ToLoc); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } if (m_Mode == eSaveMode.ADD) { //if (txtLotNo.Text == string.Empty) // ValidateException.ThrowErrorItem(new ErrorItem(txtLotNo, // TKPMessages.eValidate.VLM0067.ToString(), // new[] { FromLoc.StrongValue })); errorItem = commonVal.CheckInputLot(ItemCD, FromLoc, LotNo, true); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } } if (txtIssueQty.Text.Trim() == string.Empty) { txtIssueQty.Text = "0"; } if (txtOnHandQty.Text.Trim() == string.Empty) { txtOnHandQty.Text = "0"; } errorItem = val.CheckIssueQTY(new NZDecimal(txtIssueQty, Convert.ToDecimal(txtIssueQty.Text))); if (null != errorItem) { ValidateException.ThrowErrorItem(errorItem); } #endregion return(true); } catch (BusinessException err) { MessageDialog.ShowBusiness(this, err.Error.Message); err.Error.FocusOnControl(); } catch (ValidateException err) { MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message); err.ErrorResults[0].FocusOnControl(); } return(false); }