示例#1
0
        private void ValidateBeforeSave(UnPackingEntryUIDM model)
        {
            PackingValidator validator = new PackingValidator();

            ValidateException.ThrowErrorItem(validator.CheckUnpackingDate(model.UNPACKING_DATE));
            ValidateException.ThrowErrorItem(validator.CheckEmptyShiftType(model.SHIFT_CLS));
            ValidateException.ThrowErrorItem(validator.CheckEmptyMasterNo(model.ITEM_CD));

            if (shtView.RowCount == 0)
            {
                ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0186.ToString()));
            }

            int count = 0;

            for (int i = 0; i < shtView.RowCount; i++)
            {
                Boolean Flag = Convert.ToBoolean(shtView.Cells[i, (int)eColView.CHECKBOX].Value);
                if (Flag == false)
                {
                    count += 1;
                }
            }
            if (count == shtView.RowCount)
            {
                ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0201.ToString()));
            }
        }
示例#2
0
        /// <summary>
        /// Set Default Value into selected cell, will be used when select Item Code.
        /// </summary>
        private void SetItemCDandItemDesc()
        {
            eItemType[]    itemTypeEnum = { eItemType.All };
            ItemFindDialog dialog       = new ItemFindDialog(eSqlOperator.Equal, itemTypeEnum);

            dialog.ShowDialog(this);
            if (dialog.IsSelected)
            {
                shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value = dialog.SelectedItem.ITEM_CD.StrongValue;

                // set default into ItemCode, ItemDesc, Unit, InventoryU/M and Rate of unit.
                ErrorItem errItem = ValidateDupplicateItem();
                if (errItem != null)
                {
                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value   = string.Empty;
                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_DESC].Value = string.Empty;
                    ValidateException.ThrowErrorItem(errItem);
                }
                ValidateException.ThrowErrorItem(errItem);

                shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_DESC].Value = dialog.SelectedItem.ITEM_DESC.StrongValue;
                //shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.UNIT].Value = dialog.SelectedItem.ORDER_UM_CLS.StrongValue;
                //shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.INV_UM].Value = dialog.SelectedItem.INV_UM_CLS.StrongValue;
                //shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.RATE].Value = dialog.SelectedItem.INV_UM_RATE.StrongValue / dialog.SelectedItem.ORDER_UM_RATE.StrongValue;
            }
        }
示例#3
0
        private void GenerateTmpDemandOrderDTOList(List <TmpDemandOrderDTO> dtoDemandOrderList)
        {
            DateTime dtmSelect = Convert.ToDateTime(dtpDemand.Value);

            for (int iRow = 0; iRow < shtView.Rows.Count; iRow++)
            {
                #region validation
                ValidateException.ThrowErrorItem(
                    PurchaseOrderEntryValidation.CheckEmptyString((NZString)Convert.ToString(shtView.Cells[iRow, (int)eColumn.ITEM_DESC].Value), Messages.eValidate.VLM0129));
                #endregion
                for (int iColumn = (int)eColumn.Day1; iColumn < DateTime.DaysInMonth(dtmSelect.Year, dtmSelect.Month) + (int)eColumn.Day1; iColumn++)
                {
                    TmpDemandOrderDTO dtoTmpDemandOrder = new TmpDemandOrderDTO
                    {
                        CRT_BY      = CommonLib.Common.CurrentUserInfomation.UserCD,
                        CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine,
                        CRT_DATE    = (NZDateTime)DateTime.UtcNow,
                        CUSTOMER_CD = (NZString)txtCusCD.Text,
                        DUE_DATE    = (NZDateTime)(new DateTime(dtmSelect.Year, dtmSelect.Month, (iColumn - 2))),
                        ITEM_CD     = (NZString)Convert.ToString(shtView.Cells[iRow, (int)eColumn.ITEM_CD].Value.ToString()),
                        ITEM_DESC   = (NZString)Convert.ToString(shtView.Cells[iRow, (int)eColumn.ITEM_DESC].Value),
                        ORDER_QTY   = (NZDecimal)(Convert.ToDecimal(shtView.Cells[iRow, iColumn].Value)),
                        ORDER_TYPE  = null,
                        YEAR_MONTH  = (NZDateTime)dtpDemand.Value,
                    };

                    if (dtoTmpDemandOrder.ORDER_QTY > 0)
                    {
                        dtoDemandOrderList.Add(dtoTmpDemandOrder);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Do action after change record , such as set default and validate data.
        /// </summary>
        private void CheckChangingInRecord()
        {
            if (shtView.Rows.Count > 0)
            {
                // ตรวจว่าข้อมูลใน PO ซ้ำหรือไม่
                ValidateException.ThrowErrorItem(ValidateDupplicateItem());

                int iRow = shtView.ActiveRowIndex;
                int iCol = shtView.ActiveColumnIndex;

                NZDecimal decQty        = new NZDecimal(null, shtView.GetValue(iRow, (int)eColumn.PO_QTY));
                NZDecimal decUnitPrice  = new NZDecimal(null, shtView.GetValue(iRow, (int)eColumn.UNIT_PRICE));
                NZDecimal decReceiveQty = new NZDecimal(null, shtView.GetValue(iRow, (int)eColumn.RECEIVE_QTY));
                NZDecimal decRate       = new NZDecimal(null, shtView.GetValue(iRow, (int)eColumn.RATE));

                // เซ็ต Amount
                if ((iCol == (int)eColumn.PO_QTY || iCol == (int)eColumn.UNIT_PRICE))
                {
                    shtView.Cells[iRow, (int)eColumn.AMOUNT].Value = (decQty.IsNull ? 0 : decQty.StrongValue) *
                                                                     (decUnitPrice.IsNull ? 0 : decUnitPrice.StrongValue);
                }

                // กำหนด Formula + value ให้ Inventory Qty
                shtView.Cells[iRow, (int)eColumn.INV_QTY].Formula = shtView.Cells[iRow, (int)eColumn.PO_QTY].ToString() + "*" + shtView.Cells[iRow, (int)eColumn.RATE].ToString();
                shtView.Cells[iRow, (int)eColumn.INV_QTY].Value   = (decQty.IsNull ? 0 : decQty.StrongValue) *
                                                                    (decRate.IsNull ? 0 : decRate.StrongValue);

                // กำหนด modifystate = edit (กรณีที่ไม่ใช่ record ที่เพิ่ง add มาใหม่)
                if (Convert.ToInt32(shtView.Cells[iRow, (int)eColumn.ModifyState].Value) != (int)eModifyState.Add)
                {
                    shtView.Cells[iRow, (int)eColumn.ModifyState].Value = (int)eModifyState.Edit;
                }
            }
        }
示例#5
0
        private void mnuDelete_Click(object sender, EventArgs e)
        {
            try
            {
                string MACHINE_CD = shtView.GetValue(shtView.ActiveRowIndex, (int)eColView.MACHINE_CD).ToString();

                MachineValidator validator = new MachineValidator();
                ErrorItem        errorItem = null;
                errorItem = validator.ValidateBeforeDelete(MACHINE_CD.ToNZString());
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }

                MessageDialogResult dr = MessageDialog.ShowConfirmation(this, new Message(Messages.eConfirm.CFM9002.ToString()), MessageDialogButtons.YesNo);
                if (dr == MessageDialogResult.No)
                {
                    return;
                }


                m_machineController.DeleteMachine(MACHINE_CD.ToNZString());
                LoadData(false);

                MessageDialog.ShowInformation(this, null, new Message(Messages.eInformation.INF9003.ToString()).MessageDescription);
            }
            catch (ValidateException err)
            {
                MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message);
                err.ErrorResults[0].FocusOnControl();
            }
        }
示例#6
0
        private void DeletePO()
        {
            int iActive = shtView.ActiveRowIndex;
            List <PurchaseOrderDDTO> dDTOPurchaseOrderList = new List <PurchaseOrderDDTO>();

            ValidateException.ThrowErrorItem(
                PurchaseOrderEntryValidation.CheckEmptyString(
                    (NZString)Convert.ToString(shtView.Cells[iActive, (int)eColumn.PO_LINE].Value),
                    Messages.eValidate.VLM0142));

            dDTOPurchaseOrderList.Add(new PurchaseOrderDDTO
            {
                PO_NO = (NZString)Convert.ToString(shtView.Cells[iActive, (int)eColumn.PO_NO].Value),

                PO_LINE = (NZDecimal)Convert.ToDecimal(shtView.Cells[iActive, (int)eColumn.PO_LINE].Value),

                RECEIVE_QTY = (NZDecimal)Convert.ToDecimal(shtView.Cells[iActive, (int)eColumn.RECEIVE_QTY].Value),
                ITEM_CD     = (NZString)Convert.ToString(shtView.Cells[iActive, (int)eColumn.ITEM_CD].Value),
                DUE_DATE    = (NZDateTime)Convert.ToDateTime(shtView.Cells[iActive, (int)eColumn.DUE_DATE].Value)
            });
            new PurchaseOrderBIZ().DeletePOLine(GeneratePurchaseOrderHDTO(), dDTOPurchaseOrderList);

            MessageDialog.ShowInformation(this, "Information", new EVOFramework.Message(Messages.eInformation.INF9003.ToString()).MessageDescription);
            OnRefresh();
        }
示例#7
0
        private void ValidateRequireField()
        {
            SalesUnitPriceValidator validator = new SalesUnitPriceValidator();

            ErrorItem errorItem = null;

            errorItem = validator.CheckEmptyMasterNo(new NZString(txtPartNo, txtPartNo.Text));
            if (null != errorItem)
            {
                ValidateException.ThrowErrorItem(errorItem);
            }

            errorItem = validator.CheckEmptyStartEffeciveDate(new NZDateTime(dtStartEffDate, dtStartEffDate.Value));
            if (null != errorItem)
            {
                ValidateException.ThrowErrorItem(errorItem);
            }

            errorItem = validator.CheckEmptyCurrency(new NZString(cboCurrency, cboCurrency.SelectedValue));
            if (null != errorItem)
            {
                ValidateException.ThrowErrorItem(errorItem);
            }

            errorItem = validator.CheckEmptyPrice(numPrice.ToNZDecimal());
            if (null != errorItem)
            {
                ValidateException.ThrowErrorItem(errorItem);
            }
        }
示例#8
0
        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);
        }
示例#9
0
        private void ValidateBeforeSave()
        {
            AdjustmentValidator  adjustmentValidator = new AdjustmentValidator();
            ItemValidator        itemValidator       = new ItemValidator();
            DealingValidator     locationValidator   = new DealingValidator();
            TransactionValidator valTran             = new TransactionValidator();
            CommonBizValidator   commonVal           = new CommonBizValidator();

            ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyAdjustDate(new NZDateTime(dtAdjustDate, dtAdjustDate.Value)));
            ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyReasonCode(new NZString(cboReasonCode, cboReasonCode.SelectedValue)));
            ValidateException.ThrowErrorItem(valTran.DateIsInCurrentPeriod(new NZDateTime(dtAdjustDate, dtAdjustDate.Value)));
            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(new NZString(txtMasterNo, txtMasterNo.Text.Trim())));
            ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(new NZString(cboStoredLoc, cboStoredLoc.SelectedValue)));

            if (cboStoredLoc.SelectedValue == null)
            {
                return;
            }

            string strProcess = cboStoredLoc.SelectedValue.ToString();
            DealingConstraintDTO constriant = bizConstraint.LoadDealingConstraint(strProcess.ToNZString());

            AdjustmentValidator validator = new AdjustmentValidator();
            ErrorItem           errorItem = null;

            //if (constriant != null && constriant.ENABLE_PACK_FLAG.StrongValue == 1)
            //{
            //    errorItem = validator.CheckEmptyPackNo(txtPackNo.ToNZString());
            //    if (null != errorItem)
            //        ValidateException.ThrowErrorItem(errorItem);//error.AddError(errorItem);
            //}

            if (rdoDecrease.Checked && constriant != null && constriant.ENABLE_PACK_FLAG.StrongValue == 1)
            {
                errorItem = validator.CheckEmptyPackNo(txtPackNo.ToNZString());
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }
            }

            if (constriant != null && constriant.ENABLE_LOT_FLAG.StrongValue == 1)
            {
                errorItem = validator.CheckEmptyLotNo(txtLotNo.ToNZString());
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);//error.AddError(errorItem);
                }
                FormatUtil.CheckFormatLotNo(new NZString(txtLotNo, txtLotNo.Text.Trim()));

                //errorItem = validator.CheckEmptyCustomerLotNo(txtCustomerLotNo.ToNZString());
                //if (null != errorItem)
                //    ValidateException.ThrowErrorItem(errorItem);//error.AddError(errorItem);
            }

            ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyAdjustQty(new NZDecimal(txtAdjustQty, txtAdjustQty.Decimal)));
            ValidateException.ThrowErrorItem(adjustmentValidator.CheckIsZeroAdjustQty(new NZDecimal(txtAdjustQty, txtAdjustQty.Decimal)));
        }
示例#10
0
        /// <summary>
        /// Generate PO Header.
        /// </summary>
        /// <param name="strPONo">PO No of PO Header.</param>
        /// <returns>PO Header</returns>
        private PurchaseOrderHDTO GeneratePurchaseOrderHDTO(NZString strPONo)
        {
            NZDateTime dtmPO         = new NZDateTime(dtmPODate, dtmPODate.Value);
            NZString   strSupplierCD = new NZString(cboSupplierCode, cboSupplierCode.SelectedValue);
            NZString   strDeliveryTo = chkOurFactory.Checked ? new NZString(cboDelivery, cboDelivery.Text) : new NZString(cboDelivery, cboDelivery.SelectedValue);
            NZString   strCurrency   = new NZString(cboCurrency, cboCurrency.SelectedValue);
            NZString   strVatRate    = new NZString(txtVatRate, txtVatRate.Text);
            string     strVatType    = (Convert.ToInt32(strVatRate) > 0) ? "02" : "01";

            #region validation

            ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckDateTimeValue(dtmPO, Messages.eValidate.VLM0116));
            ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckEmptyString(strSupplierCD, Messages.eValidate.VLM0118));
            if (!chkOurFactory.Checked)
            {
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckEmptyString((NZString)strDeliveryTo, Messages.eValidate.VLM0119));
            }
            ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckEmptyString((NZString)strCurrency, Messages.eValidate.VLM0121));
            if (this.m_ScreenStateEnum == eScreenState.Add)
            {
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckPurchaseOrderItem((NZInt)shtView.Rows.Count));
            }

            #endregion


            PurchaseOrderHDTO hDTO = new PurchaseOrderHDTO
            {
                CRT_BY      = CommonLib.Common.CurrentUserInfomation.UserCD,
                CRT_DATE    = (NZDateTime)DateTime.UtcNow,
                CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine,
                UPD_BY      = CommonLib.Common.CurrentUserInfomation.UserCD,
                UPD_DATE    = (NZDateTime)DateTime.UtcNow,
                UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine,

                PO_NO     = strPONo,
                PO_DATE   = (NZDateTime)dtmPO,
                IS_ACTIVE = (NZBoolean)m_bIsActived, //(NZBoolean)((m_iPOStatus == 1) ? true : false),
                PO_TYPE   = (NZString)"01",          //(NZString)(cboPOType.SelectedValue.ToString()),

                IS_EXPORT = (NZBoolean)false,        //(NZBoolean)chkExport.Checked,
                ADDRESS   = (NZString)"",            // (NZString)txtAddress.Text,

                SUPPLIER_CD     = (NZString)strSupplierCD,
                DELIVERY_TO     = (NZString)strDeliveryTo,
                TERM_OF_PAYMENT = (NZString)(Convert.ToString(cboTermOfPayment.SelectedValue)),

                STATUS   = (NZString)"0",
                VAT_TYPE = (NZString)strVatType,
                VAT_RATE = (NZDecimal)Convert.ToDecimal(strVatRate),
                CURRENCY = (NZString)(cboCurrency.SelectedValue.ToString()),

                REMARK = (NZString)txtRemark.Text,
            };

            return(hDTO);
        }
示例#11
0
        private void ValidateBeforeSave()
        {
            ItemValidator itemValidator = new ItemValidator();

            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(txtMasterNo.Text.ToNZString()));

            //PackingValidator validator = new PackingValidator();
            //ValidateException.ThrowErrorItem(validator.CheckEmptyFGNo(txtFGNo.Text.ToNZString()));
        }
示例#12
0
        /// <summary>
        /// Load Item Description and other description into SpreadSheet require ItemCode from SpreadSheet for do operation.
        /// </summary>
        /// <param name="iRow">Selected row , load description for this row.</param>
        private void LoadItem(int iRow)
        {
            try
            {
                if (shtView.Cells[iRow, (int)eColumn.ITEM_CD].Value != null)
                {
                    #region validateion
                    List <string> strItemCDList = new List <string>();
                    for (int i = 0; i < shtView.Rows.Count; i++)
                    {
                        if (i != iRow)
                        {
                            strItemCDList.Add(Convert.ToString(shtView.Cells[i, (int)eColumn.ITEM_CD].Value));
                        }
                    }
                    ErrorItem errItem = ValidateDupplicateItem();
                    if (errItem != null)
                    {
                        shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value   = string.Empty;
                        shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_DESC].Value = string.Empty;
                        ValidateException.ThrowErrorItem(errItem);
                    }
                    #endregion

                    shtView.Cells[iRow, (int)eColumn.KeptStatus].Value = shtView.Cells[iRow, (int)eColumn.STATUS].Value;
                    ItemBIZ bizItem = new ItemBIZ();
                    ItemDTO dtoItem = bizItem.LoadItem((NZString)Convert.ToString(shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value));

                    if (dtoItem != null)
                    {
                        shtView.Cells[iRow, (int)eColumn.ITEM_DESC].Value = dtoItem.ITEM_DESC.StrongValue;
                        //shtView.Cells[iRow, (int)eColumn.UNIT].Value = dtoItem.ORDER_UM_CLS.StrongValue;
                        //shtView.Cells[iRow, (int)eColumn.INV_UM].Value = dtoItem.INV_UM_CLS.StrongValue;
                        //shtView.Cells[iRow, (int)eColumn.RATE].Value = dtoItem.INV_UM_RATE.StrongValue / dtoItem.ORDER_UM_RATE.StrongValue;
                        shtView.Cells[iRow, (int)eColumn.INV_QTY].Value = Convert.ToDecimal(shtView.Cells[iRow, (int)eColumn.PO_QTY].Value) * Convert.ToDecimal(shtView.Cells[iRow, (int)eColumn.RATE].Value);
                    }
                    else
                    {
                        shtView.Cells[iRow, (int)eColumn.ITEM_DESC].Value = null;
                        shtView.Cells[iRow, (int)eColumn.UNIT].Value      = null;
                        shtView.Cells[iRow, (int)eColumn.INV_UM].Value    = null;
                        shtView.Cells[iRow, (int)eColumn.RATE].Value      = null;
                        shtView.Cells[iRow, (int)eColumn.INV_QTY].Value   = null;
                    }
                }
            }
            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();
            }
        }
示例#13
0
        protected virtual void OnSave()
        {
            // Validate data
            try {
                ItemValidator itemValidator = new ItemValidator();
                ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(txtItemCode.ToNZString()));
                BusinessException itemException = itemValidator.CheckItemNotExist(txtItemCode.ToNZString());
                if (itemException != null)
                {
                    ValidateException.ThrowErrorItem(itemException.Error);
                }

                if (txtUpperQty.Decimal == 0)
                {
                    ValidateException.ThrowErrorItem(new ErrorItem(txtUpperQty, string.Empty, "Can't input zero"));
                }

                if (txtLowerQty.Decimal == 0)
                {
                    ValidateException.ThrowErrorItem(new ErrorItem(txtLowerQty, string.Empty, "Can't input zero"));
                }

                ItemController controller = new ItemController();
                ItemUIDM       uidm       = controller.LoadItem(txtItemCode.Text.Trim().ToNZString());

                BOMRegisterUIDM model = new BOMRegisterUIDM();
                model.ITEM_CD   = uidm.ITEM_CD;
                model.ITEM_DESC = uidm.ITEM_DESC;
                //model.ITEM_CLS = uidm.ITEM_CLS;
                //model.LOT_CONTROL_CLS = uidm.LOT_CONTROL_CLS;
                //model.ORDER_LOC_CD = uidm.ORDER_LOC_CD;
                //model.STORE_LOC_CD = uidm.STORE_LOC_CD;
                //model.ORDER_PROCESS_CLS = uidm.ORDER_PROCESS_CLS;
                //model.CONSUMTION_CLS = uidm.CONSUMTION_CLS;
                //model.PACK_SIZE = uidm.PACK_SIZE;
                //model.INV_UM_CLS = uidm.INV_UM_CLS;
                //model.ORDER_UM_CLS = uidm.ORDER_UM_CLS;
                //model.INV_UM_RATE = uidm.INV_UM_RATE;
                //model.ORDER_UM_RATE = uidm.ORDER_UM_RATE;
                model.LOWER_QTY.Value          = txtLowerQty.Decimal;
                model.UPPER_QTY.Value          = txtUpperQty.Decimal;
                model.CHILD_ORDER_LOC_CD.Value = (chkChildOrderLoc.Checked ? null : (string)cboOrderLoc.SelectedValue);
                model.MRP_FLAG.Value           = (chkMRPFlag.Checked ? null : (string)cboMRPFlag.SelectedValue);

                m_model = model;

                this.Close();
            }
            catch (ValidateException err) {
                MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message);
                err.ErrorResults[0].FocusOnControl();
            }
        }
示例#14
0
        private void DeleteItem()
        {
            try
            {
                if (shtItemView.Rows.Count == 0)
                {
                    return;
                }
                if (shtItemView.ActiveRowIndex < 0)
                {
                    return;
                }

                NZString ItemCD = new NZString(null, shtItemView.Cells[shtItemView.ActiveRowIndex, (int)eColView.ITEM_CD].Text);

                ItemValidator validator = new ItemValidator();
                ErrorItem     errorItem = validator.ValidateBeforeDelete(ItemCD);
                if (errorItem != null)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }

                errorItem = validator.CheckExistsTransactionByItem(ItemCD);
                if (errorItem != null)
                {
                    MessageDialog.ShowBusiness(this, errorItem.Message);
                }


                MessageDialogResult dr = MessageDialog.ShowConfirmation(this, new EVOFramework.Message(SystemMaintenance.Messages.eConfirm.CFM9002.ToString()).MessageDescription);
                switch (dr)
                {
                case MessageDialogResult.Cancel:
                    return;

                case MessageDialogResult.No:
                    return;

                case MessageDialogResult.Yes:
                    break;
                }

                ItemController ctlItem = new ItemController();
                ctlItem.DeleteItem(ItemCD);

                shtItemView.RemoveRows(shtItemView.ActiveRowIndex, 1);
            }
            catch (ValidateException err)
            {
                MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message);
                err.ErrorResults[0].FocusOnControl();
            }
        }
示例#15
0
        private bool CheckMandatory()
        {
            try
            {
                InventoryPeriodValidator val = new InventoryPeriodValidator();

                #region Mandatory check

                ErrorItem errorItem = null;
                errorItem = val.CheckEmptyYearMonth(new NZString(null, dtInventoryMonth.Value.HasValue ? dtInventoryMonth.Value.Value.ToString("yyyyMM") : null));
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }

                errorItem = val.CheckEmptyPeriodBeginDate(new NZDateTime(null, dtPeriodFrom.Value));
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }

                errorItem = val.CheckEmptyPeriodEndDate(new NZDateTime(null, dtPeriodTo.Value));
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }

                errorItem = val.CheckPeriodBeginToEndDate(new NZDateTime(null, dtPeriodFrom.Value),
                                                          new NZDateTime(null, dtPeriodTo.Value));
                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);
        }
示例#16
0
        private void EditDemandOrder()
        {
            List <TmpDemandOrderDTO> dtoListDemandOrderUpdate = new List <TmpDemandOrderDTO>();

            GenerateTmpDemandOrderDTOList(dtoListDemandOrderUpdate);

            ValidateException.ThrowErrorItem(DemandOrderSimpleValidation.CheckRecord(new NZInt(null, dtoListDemandOrderUpdate.Count)));

            DemandOrderDTO dtoDemandOrder = GenerateHeaderDemandOrderDTO();

            if (dtoListDemandOrderUpdate.Count > 0)
            {
                m_BIZDemandOrder.Update(dtoDemandOrder, dtoListDemandOrderUpdate);
            }
        }
示例#17
0
        private bool ValidateMandatory()
        {
            if (!dtInvoiceDate.Value.HasValue)
            {
                ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0105.ToString(), new object[] { "Delivery Date" }));
                return(false);
            }
            if (cboCustomerCode.SelectedValue == null)
            {
                ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0105.ToString(), new object[] { "Customer Code" }));
                return(false);
            }

            // Validate Data before Save
            if (shtCustomerOrder.Rows.Count == 0)
            {
                ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0190.ToString()));
            }

            //if (!CheckChooseLotForOrder())
            //{
            //    ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0194.ToString()));
            //}
            //if (!CheckChooseLotOverRemain())
            //{
            //    ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0214.ToString()));
            //}

            ShipEntryValidator       valShip   = new ShipEntryValidator();
            IssueEntryValidator      valIssue  = new IssueEntryValidator();
            InventoryOnhandValidator valINV    = new InventoryOnhandValidator();
            TransactionValidator     valTRN    = new TransactionValidator();
            CommonBizValidator       commonVal = new CommonBizValidator();
            ErrorItem errorItem;


            errorItem = valTRN.DateIsInCurrentPeriod(new NZDateTime(dtInvoiceDate, dtInvoiceDate.Value));
            if (null != errorItem)
            {
                ValidateException.ThrowErrorItem(errorItem);
            }


            NZString YearMonth = new InventoryPeriodBIZ().LoadCurrentPeriod().YEAR_MONTH;

            return(true);
        }
示例#18
0
        private bool ValidateBeforeSave(PackingEntryUIDM model)
        {
            if (shtView.RowCount == 0)
            {
                ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0186.ToString()));
            }

            for (int iRow = 0; iRow < shtView.RowCount; iRow++)
            {
                if (!ValidateRowSpread(iRow, true))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#19
0
        private void LoadItemDesc(int iRow)
        {
            try
            {
                #region validateion
                List <string> strItemCDList = new List <string>();
                for (int i = 0; i < shtView.Rows.Count; i++)
                {
                    if (i != iRow)
                    {
                        strItemCDList.Add(Convert.ToString(shtView.Cells[i, (int)eColumn.ITEM_CD].Value));
                    }
                }
                ErrorItem errItem = PurchaseOrderEntryValidation.CheckDupItem
                                        (new NZString(null, shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value), strItemCDList);
                if (errItem != null)
                {
                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value   = string.Empty;
                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_DESC].Value = string.Empty;
                    ValidateException.ThrowErrorItem(errItem);
                }
                #endregion

                ItemBIZ bizItem = new ItemBIZ();
                ItemDTO dtoItem = bizItem.LoadItem((NZString)Convert.ToString(shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value));

                if (dtoItem != null)
                {
                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_DESC].Value = Convert.ToString(dtoItem.ITEM_DESC);
                }
                else
                {
                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_DESC].Value = string.Empty;
                }
            }
            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();
            }
        }
示例#20
0
        /// <summary>
        /// Check InventoryMonth ว่า = Current Period ? if No --> error
        /// Check if ใน Current period มี Item Lot ที่ qty <0 ให้ออก Confirm Msg ถามว่าจะทำต่อ?
        /// ถ้าเป้น Rolling Down To Period ต้อง Exist ใน TB_INV_ONHAND_TR
        /// </summary>
        /// <param name="ProcessType"></param>
        /// <param name="YearMonth"></param>
        /// <returns></returns>
        public ErrorItem CheckBeforeRunClosingProcess(eMonthlyCloseProcess ProcessType, NZString YearMonth)
        {
            ErrorItem err = null;
            InventoryOnhandValidator valINV = new InventoryOnhandValidator();

            ValidateException.ThrowErrorItem(CheckCurrentPeriod(YearMonth));

            if (ProcessType == eMonthlyCloseProcess.ROLLING_DOWN)
            {
                int      iYM      = Convert.ToInt32(YearMonth.StrongValue);
                NZString PreMonth = new DateTime(iYM / 100, iYM % 100, 1).AddMonths(-1).ToString("yyyyMM").ToNZString();
                ValidateException.ThrowErrorItem(valINV.CheckIfExistWithYearMonth(PreMonth));
            }

            err = valINV.CheckIfItemLotHasNegativeQty(YearMonth);

            return(err);
        }
示例#21
0
        private DemandOrderDTO GenerateHeaderDemandOrderDTO()
        {
            ValidateException.ThrowErrorItem(DemandOrderSimpleValidation.CheckEmptyDemandMonth(dtpDemand.Value));
            ValidateException.ThrowErrorItem(DemandOrderSimpleValidation.CheckEmptyCustomerCode(new NZString(txtCusCD, txtCusCD.Text.ToNZString())));
            ValidateException.ThrowErrorItem(DemandOrderSimpleValidation.CheckEmptyCustomerName(new NZString(txtCusCD, txtCusName.Text)));

            return(new DemandOrderDTO
            {
                CUSTOMER_CD = (NZString)txtCusCD.Text,
                YEAR_MONTH = (NZDateTime)dtpDemand.Value,
                CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD,
                CRT_DATE = (NZDateTime)DateTime.UtcNow,
                CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine,
                UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD,
                UPD_DATE = (NZDateTime)DateTime.UtcNow,
                UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine,
            });
        }
示例#22
0
        public void ValidateBeforeSaveAdd(InventoryTransactionDTO data)
        {
            //Validate Item Code
            ItemValidator itemValidator = new ItemValidator();

            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(data.ITEM_CD));

            BusinessException itemNotFound = itemValidator.CheckItemNotExist(data.ITEM_CD);

            if (itemNotFound != null)
            {
                ValidateException.ThrowErrorItem(itemNotFound.Error);
            }
            if (data.TRANS_ID.IsNull)
            {
                if (data.TRANS_CLS.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Receiving))
                {
                    ValidateException.ThrowErrorItem(CheckExistReceiveItem(data.ITEM_CD, data.LOT_NO, data.LOC_CD));
                }
                else
                {
                    ValidateException.ThrowErrorItem(CheckNotExistReceiveItem(data.ITEM_CD, data.LOT_NO, data.LOC_CD));
                }


                ////ถ้า Receive ต้อง check ว่า lot นั้นไม่เคยทำ receive มาก่อน
                //if (model.RECEIVE_TYPE.StrongValue.Equals(DataDefine.eTRANS_TYPE_string.Receiving))
                //{
                //    ValidateException.ThrowErrorItem(receivingValidator.CheckExistReceiveItem(dto.ITEM_CD, dto.LOT_NO));
                //}
                //else
                //{
                //    ValidateException.ThrowErrorItem(receivingValidator.CheckNotExistReceiveItem(dto.ITEM_CD, dto.LOT_NO));
                //}
            }


            //Validate Receive Qty
            if (data.QTY.IsNull || data.QTY.StrongValue <= 0)
            {
                ValidateException.ThrowErrorItem(new ErrorItem(data.QTY.Owner, TKPMessages.eValidate.VLM0043.ToString()));
            }
        }
示例#23
0
        private void GenWorkingCalendarToDB()
        {
            ValidateException.ThrowErrorItem(WorkingCalendarValidation.CheckEmptyDemandMonth((NZInt)Convert.ToInt32(txtNoOfMonth.Text)));

            switch (ShowConfirmMessage(Messages.eConfirm.CFM9012))
            {
            case MessageDialogResult.Cancel:
                return;

            case MessageDialogResult.No:
                return;

            case MessageDialogResult.Yes:
                break;
            }

            // เตรียมข้อมูลสำหรับ gen
            bool[] bStopingDay =
            {
                evoCheckBoxDay1.Checked,
                evoCheckBoxDay2.Checked,
                evoCheckBoxDay3.Checked,
                evoCheckBoxDay4.Checked,
                evoCheckBoxDay5.Checked,
                evoCheckBoxDay6.Checked,
                evoCheckBoxDay7.Checked
            };
            int iNoOfMonth = Convert.ToInt32(txtNoOfMonth.Text);

            //DateTime dateTime = Convert.ToDateTime(Convert.ToDateTime(evoDateTextBoxStartMY.DateValue).ToString("MM-01-yyyy"));
            DateTime dtmSelectedMonth = (DateTime)evoDateTextBoxStartMY.DateValue;

            dtmSelectedMonth = dtmSelectedMonth.AddDays(0 - dtmSelectedMonth.Day);
            dtmSelectedMonth = dtmSelectedMonth.AddDays(1);

            m_BIZWorkingCalendar.CreateWorkingCalendar(iNoOfMonth, dtmSelectedMonth, bStopingDay);
            UpdateDateTextBox();
            MessageDialog.ShowInformation(this, "Information", new EVOFramework.Message(Messages.eInformation.INF9003.ToString()).MessageDescription);
            GenerateCalendar();
        }
示例#24
0
        //public ErrorItem CheckInputLot(NZString itemCode, NZString lotNo) {
        //    ItemBIZ biz = new ItemBIZ();
        //    ItemDTO dto = biz.LoadItem(itemCode);

        //    switch (DataDefine.ConvertValue2Enum<DataDefine.eLOT_CONTROL_CLS>(dto.LOT_CONTROL_CLS.StrongValue)) {
        //        case DataDefine.eLOT_CONTROL_CLS.No:
        //            if (!lotNo.IsNull || lotNo.StrongValue != string.Empty) {
        //                return new ErrorItem(lotNo.Owner, TKPMessages.eValidate.VLM0065.ToString());
        //            }
        //            break;
        //        case DataDefine.eLOT_CONTROL_CLS.Yes:
        //            if (lotNo.IsNull || lotNo.StrongValue.Trim() == String.Empty) {
        //                return new ErrorItem(lotNo.Owner, TKPMessages.eValidate.VLM0050.ToString(), new object[] { itemCode.StrongValue });
        //            }
        //            break;
        //    }

        //    return null;
        //}
        #endregion

        #region Business Validate
        /// <summary>
        /// Validate data before load consumption list.
        /// </summary>
        /// <param name="itemCode"></param>
        /// <param name="orderLocation"></param>
        /// <param name="qty"></param>
        public void ValidateBeforeLoadConsumption(NZString itemCode, NZString orderLocation, NZDecimal qty, NZString ConsumptionCls)
        {
            //== Check ItemCode.
            ItemValidator itemValidator = new ItemValidator();

            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(itemCode));

            BusinessException businessException = itemValidator.CheckItemNotExist(itemCode);

            if (businessException != null)
            {
                ValidateException.ThrowErrorItem(businessException.Error);
            }

            //== Check Order Location.
            DealingValidator locationValidator = new DealingValidator();

            if (ConsumptionCls.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eCONSUMPTION_CLS.Manual))
            {
                ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(orderLocation));
                ValidateException.ThrowErrorItem(locationValidator.CheckNotExistsLocationCode(orderLocation));
            }
        }
示例#25
0
        private void fpView_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
        {
            try
            {
                eItemType[]    itemTypeEnum = { eItemType.All };
                ItemFindDialog dialog       = new ItemFindDialog(eSqlOperator.Equal, itemTypeEnum);
                dialog.ShowDialog(this);
                if (dialog.IsSelected)
                {
                    #region validateion
                    int           iRow          = shtView.ActiveRowIndex;
                    List <string> strItemCDList = new List <string>();
                    for (int i = 0; i < shtView.Rows.Count; i++)
                    {
                        if (i != iRow)
                        {
                            strItemCDList.Add(Convert.ToString(shtView.Cells[i, (int)eColumn.ITEM_CD].Value));
                        }
                    }
                    ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckDupItem(dialog.SelectedItem.ITEM_CD, strItemCDList));
                    #endregion

                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_CD].Value   = dialog.SelectedItem.ITEM_CD.ToString();
                    shtView.Cells[shtView.ActiveRowIndex, (int)eColumn.ITEM_DESC].Value = dialog.SelectedItem.ITEM_DESC.ToString();
                }
            }
            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();
            }
        }
示例#26
0
        /// <summary>
        /// Validate Value of rows in SpreadSheet.
        /// </summary>
        private void ValidateAllRows()
        {
            for (int iRow = 0; iRow < shtView.RowCount; iRow++)
            {
                NZString   strItemCD      = new NZString(null, shtView.Cells[iRow, (int)eColumn.ITEM_CD].Value, null);
                NZString   strItemDesc    = new NZString(null, shtView.Cells[iRow, (int)eColumn.ITEM_DESC].Value, null);
                NZDateTime dtmRequireDate = new NZDateTime(null, shtView.Cells[iRow, (int)eColumn.DUE_DATE].Value, null);
                NZDecimal  decUnitPrice   = new NZDecimal(null, shtView.Cells[iRow, (int)eColumn.UNIT_PRICE].Value, null);
                NZDecimal  decQty         = new NZDecimal(null, shtView.Cells[iRow, (int)eColumn.PO_QTY].Value, null);
                NZString   strUnit        = new NZString(null, shtView.Cells[iRow, (int)eColumn.UNIT].Value, null);
                NZDecimal  decAmount      = new NZDecimal(null, shtView.Cells[iRow, (int)eColumn.AMOUNT].Value, null);
                NZDecimal  decReceiveQty  = new NZDecimal(null, shtView.Cells[iRow, (int)eColumn.RECEIVE_QTY].Value, 0);
                NZString   strStatus      = new NZString(null, shtView.Cells[iRow, (int)eColumn.STATUS].Value, null);

                #region Validateion before Generate DDTO
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckEmptyString(strItemDesc, Messages.eValidate.VLM0129));
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckDateTimeValue(dtmRequireDate, Messages.eValidate.VLM0130));
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckDecimalValue(decUnitPrice, Messages.eValidate.VLM0131));
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckEmptyString(strUnit, Messages.eValidate.VLM0133));
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckDecimalValue(decQty, Messages.eValidate.VLM0132));
                ValidateException.ThrowErrorItem(PurchaseOrderEntryValidation.CheckEmptyString(strStatus, Messages.eValidate.VLM0137));
                #endregion
            }
        }
示例#27
0
        private bool ValidateData()
        {
            NZString      ItemCD = new NZString(txtPartNo, txtPartNo.Text.Trim());
            ItemValidator val    = new ItemValidator();
            ErrorItem     err;

            err = val.CheckEmptyItemCode(ItemCD);
            if (err != null)
            {
                ValidateException.ThrowErrorItem(err);
            }
            BusinessException bizErr = val.CheckItemNotExist(ItemCD);

            if (bizErr != null)
            {
                ValidateException.ThrowErrorItem(bizErr.Error);
            }

            if (txtNumberofCopies.Text.Trim() == string.Empty || txtNumberofCopies.Double == 0)
            {
                txtNumberofCopies.Double = 1;
            }
            return(true);
        }
示例#28
0
        public bool SaveData(MultiWorkResultEntryUIDM model)
        {
            ItemBIZ             bizItem      = new ItemBIZ();
            ClassListBIZ        bizClassList = new ClassListBIZ();
            InventoryBIZ        biz          = new InventoryBIZ();
            IssueEntryValidator valLot       = new IssueEntryValidator();

            #region Validate data

            MultiWorkResultEntryValidator workResultEntryValidator = new MultiWorkResultEntryValidator();
            ItemValidator      itemValidator     = new ItemValidator();
            DealingValidator   locationValidator = new DealingValidator();
            CommonBizValidator commonVal         = new CommonBizValidator();
            ValidateException.ThrowErrorItem(workResultEntryValidator.CheckWorkResultDate(model.WorkResultDate));
            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(model.ItemCode));
            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(model.ChildItemCode));
            ValidateException.ThrowErrorItem(workResultEntryValidator.CheckEmptyShiftType(model.ShiftClass));

            BusinessException itemFound = itemValidator.CheckItemNotExist(model.ItemCode);
            if (itemFound != null)
            {
                ValidateException.ThrowErrorItem(itemFound.Error);
            }

            ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(model.OrderLoc));
            ValidateException.ThrowErrorItem(locationValidator.CheckNotExistsLocationCode(model.OrderLoc));

            ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(model.StoredLoc));
            ValidateException.ThrowErrorItem(locationValidator.CheckNotExistsLocationCode(model.StoredLoc));

            #endregion

            DataTable dtData = null;
            if (model.DataView == null)
            {
                MultiWorkResultEntryViewDTO dto = new MultiWorkResultEntryViewDTO();
                dto.CreateDataTableSchema(out dtData);
            }
            else
            {
                dtData = model.DataView;
            }


            DataTable dtAdd    = dtData.GetChanges(DataRowState.Added);
            DataTable dtUpdate = dtData.GetChanges(DataRowState.Modified);
            DataTable dtDelete = dtData.GetChanges(DataRowState.Deleted);

            DataTable dtUnChanged = dtData.GetChanges(DataRowState.Unchanged);

            List <InventoryTransactionDTO> listAdd    = new List <InventoryTransactionDTO>();
            List <InventoryTransactionDTO> listUpdate = new List <InventoryTransactionDTO>();
            List <InventoryTransactionDTO> listDelete = new List <InventoryTransactionDTO>();

            List <MultiWorkResultEntryViewDTO> listViewAdd    = DTOUtility.ConvertDataTableToList <MultiWorkResultEntryViewDTO>(dtAdd);
            List <MultiWorkResultEntryViewDTO> listViewUpdate = DTOUtility.ConvertDataTableToList <MultiWorkResultEntryViewDTO>(dtUpdate);
            List <MultiWorkResultEntryViewDTO> listViewDelete = DTOUtility.ConvertDataTableToList <MultiWorkResultEntryViewDTO>(dtDelete);
            List <MultiWorkResultEntryViewDTO> listUnchanged  = DTOUtility.ConvertDataTableToList <MultiWorkResultEntryViewDTO>(dtUnChanged);



            Database db = null;
            try
            {
                db = Common.CurrentDatabase;
                db.KeepConnection = true;
                db.BeginTransaction();

                NZString runningNo            = new NZString();
                NZString strWorkResultGroupNo = new NZString();

                InventoryTransactionDTO dtoWorkResult    = null;
                InventoryTransactionDTO dtoNGResult      = null;
                InventoryTransactionDTO dtoReserveResult = null;
                InventoryTransactionDTO dtoConsumption   = null;


                InventoryTransBIZ bizTran = new InventoryTransBIZ();
                SysConfigBIZ      bizSYS  = new SysConfigBIZ();

                SysConfigDTO dtoSYS = bizSYS.LoadByPK(DataDefine.eSYSTEM_CONFIG.TRN080.SYS_GROUP_ID, (NZString)DataDefine.eSYSTEM_CONFIG.TRN080.SYS_KEY.NG_LOC_CD.ToString());

                //SysConfigDTO dtoSupplyLot = bizSYS.LoadByPK((NZString)"SUPPLY", (NZString)"SUPP_LOT");

                NZString strNGLocation = null;
                if (dtoSYS == null || dtoSYS.CHAR_DATA.IsNull || dtoSYS.CHAR_DATA.StrongValue == "ORDER_LOC")
                {
                    strNGLocation = model.OrderLoc;
                }
                else
                {
                    strNGLocation = dtoSYS.CHAR_DATA;
                }

                RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();

                //set Work Result Group No ให้กับทุกตัว
                //ถ้าheader ยังไม่มีก็ genใหม่
                //ถ้าheader มีแล้ว ก็ใช้ตัวนั้น
                if (model.WorkResultGroupNo.IsNull)
                {
                    strWorkResultGroupNo    = runningNumberBIZ.GetCompleteRunningNo((NZString)"WORK_RESULT_GROUP_NO", (NZString)"TB_INV_TRANS_TR");
                    model.WorkResultGroupNo = strWorkResultGroupNo;
                }

                foreach (MultiWorkResultEntryViewDTO dtoAdd in listViewAdd)
                {
                    runningNo = runningNumberBIZ.GetCompleteRunningNo((NZString)"WORK_RESULT_SLIP_NO", (NZString)"TB_INV_TRANS_TR");

                    //ถ้าใส่จำนวนใดจำนวนหนึ่งมา ก็จะ save ได้
                    if (dtoAdd.GOOD_QTY.NVL(0) + dtoAdd.NG_QTY.NVL(0) + dtoAdd.RESERVE_QTY.NVL(0) > 0)
                    {
                        dtoWorkResult         = CreateDTOForWorkResult(model, dtoAdd);
                        dtoWorkResult.SLIP_NO = runningNo;
                        listAdd.Add(dtoWorkResult);

                        if (dtoAdd.NG_QTY.NVL(0) > 0)
                        {
                            dtoNGResult         = CreateDTOForNGResult(model, dtoAdd, strNGLocation);
                            dtoNGResult.SLIP_NO = runningNo;
                            listAdd.Add(dtoNGResult);
                        }

                        //เฉพาะ work result ที่จะมี reserve ได้
                        if (DataDefine.eTRAN_SUB_CLS.WR.ToString().Equals(model.TRAN_SUB_CLS))
                        {
                            if (dtoAdd.RESERVE_QTY.NVL(0) > 0)
                            {
                                dtoReserveResult         = CreateDTOForReserveResult(model, dtoAdd);
                                dtoReserveResult.SLIP_NO = runningNo;
                                listAdd.Add(dtoReserveResult);
                            }
                        }

                        dtoConsumption        = CreateDTOForConsumption(model, dtoAdd);
                        dtoConsumption.REF_NO = dtoWorkResult.SLIP_NO;
                        listAdd.Add(dtoConsumption);
                    }
                }

                foreach (MultiWorkResultEntryViewDTO dtoUnchanged in listUnchanged)
                {
                    dtoWorkResult = CreateDTOForWorkResult(model, dtoUnchanged);
                    listUpdate.Add(dtoWorkResult);
                }


                foreach (MultiWorkResultEntryViewDTO dtoUpdate in listViewUpdate)
                {
                    dtoWorkResult = CreateDTOForWorkResult(model, dtoUpdate);
                    listUpdate.Add(dtoWorkResult);

                    if (dtoUpdate.NG_QTY.NVL(0) > 0)
                    {
                        dtoNGResult = CreateDTOForNGResult(model, dtoUpdate, strNGLocation);

                        if (dtoNGResult.TRANS_ID.IsNull)
                        {
                            listAdd.Add(dtoNGResult);
                        }
                        else
                        {
                            listUpdate.Add(dtoNGResult);
                        }
                    }

                    //เฉพาะ work result ที่จะมี reserve ได้
                    if (DataDefine.eTRAN_SUB_CLS.WR.ToString().Equals(model.TRAN_SUB_CLS))
                    {
                        if (dtoUpdate.RESERVE_QTY.NVL(0) > 0)
                        {
                            dtoReserveResult = CreateDTOForReserveResult(model, dtoUpdate);

                            if (dtoReserveResult.TRANS_ID.IsNull)
                            {
                                listAdd.Add(dtoReserveResult);
                            }
                            else
                            {
                                listUpdate.Add(dtoReserveResult);
                            }
                        }
                    }

                    dtoConsumption        = CreateDTOForConsumption(model, dtoUpdate);
                    dtoConsumption.REF_NO = dtoWorkResult.SLIP_NO;
                    //consumption ใช้การ add เพราะ ใช้การ clear แล้ว insert ใหม่ เลยต้อง add consumption ใหม่ตลอด
                    listAdd.Add(dtoConsumption);

                    biz.ClearConsumption(Common.CurrentDatabase, dtoWorkResult);
                }



                foreach (MultiWorkResultEntryViewDTO dtoDelete in listViewDelete)
                {
                    dtoWorkResult = CreateDTOForWorkResult(model, dtoDelete);
                    listDelete.Add(dtoWorkResult);

                    if (dtoDelete.NG_QTY.NVL(0) > 0)
                    {
                        dtoNGResult = CreateDTOForNGResult(model, dtoDelete, strNGLocation);
                        listDelete.Add(dtoNGResult);
                    }

                    //เฉพาะ work result ที่จะมี reserve ได้
                    if (DataDefine.eTRAN_SUB_CLS.WR.ToString().Equals(model.TRAN_SUB_CLS))
                    {
                        if (dtoDelete.RESERVE_QTY.NVL(0) > 0)
                        {
                            dtoReserveResult = CreateDTOForReserveResult(model, dtoDelete);
                            listDelete.Add(dtoReserveResult);
                        }
                    }

                    dtoConsumption = CreateDTOForConsumption(model, dtoDelete);
                    listDelete.Add(dtoConsumption);
                }


                biz.WorkResultItems(Common.CurrentDatabase, listAdd, listUpdate, listDelete);

                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                throw ex;
            }
            finally
            {
                if (db.DBConnectionState == ConnectionState.Open)
                {
                    db.Close();
                }
            }

            return(true);
        }
示例#29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns>If save data operation completed will return true. Otherwise return false.</returns>
        public bool SaveData(WorkResultEntryUIDM model, DataDefine.eCONSUMPTION_CLS ConsumptionClass)
        {
            ItemBIZ             bizItem      = new ItemBIZ();
            ClassListBIZ        bizClassList = new ClassListBIZ();
            InventoryBIZ        biz          = new InventoryBIZ();
            IssueEntryValidator valLot       = new IssueEntryValidator();
            // Load default over consumption checking.
            ClassListDTO dtoOverConsumptionCheck = bizClassList.LoadByPK((NZString)DataDefine.OVER_CONSUME_CHK, (NZString)DataDefine.Convert2ClassCode(DataDefine.eOVER_CONSUME_CHK.DEFAULT));
            bool         bOverConsumeChk         = false;

            if (dtoOverConsumptionCheck != null && dtoOverConsumptionCheck.CLS_DESC.NVL(String.Empty) == "1")
            {
                bOverConsumeChk = true;
            }


            //string mode = "UPD";
            //if (model.WorkOrderNo.IsNull)
            //{
            //    mode = "ADD";
            //}

            #region Validate data
            //== Validate Header, contain: ItemCode, Order Location and Qty.
            #region Validate mandatory
            WorkResultEntryValidator workResultEntryValidator = new WorkResultEntryValidator();
            ItemValidator            itemValidator            = new ItemValidator();
            DealingValidator         locationValidator        = new DealingValidator();
            CommonBizValidator       commonVal = new CommonBizValidator();
            ValidateException.ThrowErrorItem(workResultEntryValidator.CheckWorkResultDate(model.WorkResultDate));
            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(model.ItemCode));
            ValidateException.ThrowErrorItem(workResultEntryValidator.CheckEmptyShiftType(model.ShipClass));
            ValidateException.ThrowErrorItem(workResultEntryValidator.CheckDifferentLocationOfItem(model.DataView));

            BusinessException itemFound = itemValidator.CheckItemNotExist(model.ItemCode);
            if (itemFound != null)
            {
                ValidateException.ThrowErrorItem(itemFound.Error);
            }
            if (ConsumptionClass != DataDefine.eCONSUMPTION_CLS.No)
            {
                ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(model.OrderLoc));
                ValidateException.ThrowErrorItem(locationValidator.CheckNotExistsLocationCode(model.OrderLoc));
            }

            ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(model.StoredLoc));
            ValidateException.ThrowErrorItem(locationValidator.CheckNotExistsLocationCode(model.StoredLoc));
            ValidateException.ThrowErrorItem(workResultEntryValidator.CheckWorkResultQty(model.WorkResultQty));
            ValidateException.ThrowErrorItem(workResultEntryValidator.CheckWorkResultGoodQty((NZDecimal)(model.WorkResultQty.StrongValue - model.NGQty.StrongValue)));

            // Check LotNo
            ValidateException.ThrowErrorItem(commonVal.CheckInputLot(model.ItemCode, new NZString(), model.LotNo, false));
            #endregion

            //== Validate Detail list.
            if (ConsumptionClass == DataDefine.eCONSUMPTION_CLS.Manual)
            {
                List <WorkResultEntryViewDTO> listItems = DTOUtility.ConvertDataTableToList <WorkResultEntryViewDTO>(model.DataView);

                #region Validate detail list.
                // Check ItemCD & LotNo
                List <string> listInvalidLotNo          = new List <string>();
                List <string> listInvalidConsumptionQty = new List <string>();

                for (int i = 0; i < listItems.Count; i++)
                {
                    BusinessException itemChildNotFound = itemValidator.CheckItemNotExist(listItems[i].ITEM_CD);
                    if (itemChildNotFound != null)
                    {
                        ValidateException.ThrowErrorItem(itemChildNotFound.Error);
                    }

                    ItemDTO dtoItem             = bizItem.LoadItem(listItems[i].ITEM_CD);
                    WorkResultEntryViewDTO line = listItems[i];
                    //line.LOT_CONTROL_CLS = dtoItem.LOT_CONTROL_CLS;

                    if (line.LOT_CONTROL_CLS.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eLOT_CONTROL_CLS.Yes) &&
                        (line.LOT_NO.IsNull || line.LOT_NO.StrongValue.Trim() == string.Empty))
                    {
                        if (listInvalidLotNo.Contains(line.ITEM_CD.StrongValue))
                        {
                            continue;
                        }
                        listInvalidLotNo.Add(line.ITEM_CD.StrongValue);
                    }

                    if (bOverConsumeChk)
                    {
                        if (line.CONSUMPTION_QTY.StrongValue > line.ON_HAND_QTY.StrongValue)
                        {
                            if (listInvalidConsumptionQty.Contains(line.ITEM_CD.StrongValue))
                            {
                                continue;
                            }
                            listInvalidConsumptionQty.Add(line.ITEM_CD.StrongValue);
                        }
                    }
                    ValidateException.ThrowErrorItem(commonVal.CheckInputLot(line.ITEM_CD, line.LOC_CD, line.LOT_NO, true));
                }

                // Generate item doesn't input LOT_NO
                if (listInvalidLotNo.Count > 0)
                {
                    listInvalidLotNo.Sort();

                    string errorItems = string.Empty;
                    for (int i = 0; i < listInvalidLotNo.Count; i++)
                    {
                        if (i != 0)
                        {
                            errorItems += ", ";
                        }
                        errorItems += listInvalidLotNo[i];
                    }

                    ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0050.ToString(), new object[] { errorItems }));
                    return(false);
                }


                // Generate list item that input consumption qty more than stock onhand qty.
                if (listInvalidConsumptionQty.Count > 0)
                {
                    listInvalidConsumptionQty.Sort();

                    string errorItems = string.Empty;
                    for (int i = 0; i < listInvalidConsumptionQty.Count; i++)
                    {
                        if (i != 0)
                        {
                            errorItems += ", ";
                        }
                        errorItems += listInvalidConsumptionQty[i];
                    }

                    ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0051.ToString(), new object[] { errorItems }));
                    return(false);
                }
                #endregion

                // Validate Child Item to support Parent Item.
                #region Validate Child Item to support Parent item.
                // Summary Consumption Qty by Item (not include LotNo) and then check compare with RequestQty.
                InventoryBIZ bizInventory = new InventoryBIZ();
                List <WorkResultEntryViewDTO> listSourceChildItems = bizInventory.LoadConsumptionListFromItemCode(model.ItemCode, model.OrderLoc, model.WorkResultQty);
                for (int i = 0; i < listSourceChildItems.Count; i++)
                {
                    object objSumByItem = model.DataView.Compute(
                        String.Format("SUM({0})", WorkResultEntryViewDTO.eColumns.CONSUMPTION_QTY),
                        String.Format("{0} = '{1}'", WorkResultEntryViewDTO.eColumns.ITEM_CD, listSourceChildItems[i].ITEM_CD.StrongValue)
                        );



                    decimal sumConsumptionQty = 0;
                    if (objSumByItem != null && objSumByItem != DBNull.Value)
                    {
                        sumConsumptionQty = Convert.ToDecimal(objSumByItem);
                    }

                    decimal diffQty = Math.Abs(sumConsumptionQty - listSourceChildItems[i].CONSUMPTION_QTY.StrongValue);
                    if (sumConsumptionQty < listSourceChildItems[i].REQUEST_QTY.StrongValue)  // Total of ConsumtpionQty < RequestQty
                    {
                        // Confirmation to continue save.
                        MessageDialogResult dr = MessageDialog.ShowConfirmation(null, Message.LoadMessage(TKPMessages.eConfirm.CFM0001.ToString(),
                                                                                                          new object[]
                        {
                            listSourceChildItems[i].ITEM_CD.StrongValue,
                            model.ItemCode.StrongValue,
                            diffQty.ToString(DataDefine.DEFAULT_FORMAT_NUMBER)
                        }),
                                                                                MessageDialogButtons.YesNo);

                        if (dr == MessageDialogResult.No)
                        {
                            return(false);
                        }
                    }
                    else if (sumConsumptionQty > listSourceChildItems[i].REQUEST_QTY.StrongValue)  // Total of ConsumtpionQty > RequestQty
                    {
                        // Confirmation to continue save.
                        MessageDialogResult dr = MessageDialog.ShowConfirmation(null, Message.LoadMessage(TKPMessages.eConfirm.CFM0002.ToString(),
                                                                                                          new object[]
                        {
                            listSourceChildItems[i].ITEM_CD.StrongValue,
                            model.ItemCode.StrongValue,
                            diffQty.ToString(DataDefine.DEFAULT_FORMAT_NUMBER)
                        }),
                                                                                MessageDialogButtons.YesNo);

                        if (dr == MessageDialogResult.No)
                        {
                            return(false);
                        }
                    }
                }
                #endregion
            }

            #endregion
            DataTable dtData;
            if (model.DataView == null)
            {
                WorkResultEntryViewDTO dto = new WorkResultEntryViewDTO();
                dto.CreateDataTableSchema(out dtData);
            }
            else
            {
                dtData = model.DataView;
            }


            DataTable dtAdd    = dtData.GetChanges(DataRowState.Added);
            DataTable dtUpdate = dtData.GetChanges(DataRowState.Modified);
            DataTable dtDelete = dtData.GetChanges(DataRowState.Deleted);

            List <InventoryTransactionDTO> listAdd    = new List <InventoryTransactionDTO>();
            List <InventoryTransactionDTO> listUpdate = new List <InventoryTransactionDTO>();
            List <InventoryTransactionDTO> listDelete = new List <InventoryTransactionDTO>();
            Database db = null;
            try
            {
                db = Common.CurrentDatabase;
                db.KeepConnection = true;
                db.BeginTransaction();

                //TransactionValidator valTran = new TransactionValidator();
                //InventoryTransBIZ bizTran = new InventoryTransBIZ();
                //bizTran.l

                #region Header
                NZString runningNo = new NZString();

                //ให้ generate lot ใหม่อีกครั้ง กรณีกรอกพร้อมกัน 2 เครื่อง ไม่งั้นมันจะ insert ข้อมูลมั่ว
                // ที่ใส่ตรงนี้เพราะว่า จะได้แก้ model.LotNo ก่อนที่จะสร้าง  object dto
                //เนื่องจาก reserve ก็มีดึง lot no ไปใช้
                if (model.WorkResultNo.IsNull)
                {
                    RunningNumberBIZ runnningBiz      = new RunningNumberBIZ();
                    NZString         strCompleteLotNo = runnningBiz.GetCompleteLotNo(new NZDateTime(null, model.WorkResultDate.StrongValue), model.StoredLoc, model.ItemCode, new NZInt(null, 0));
                    model.LotNo = strCompleteLotNo;
                }

                InventoryTransactionDTO dtoWorkResult    = CreateDTOForWorkResult(model);
                InventoryTransactionDTO dtoNGResult      = CreateDTOForNGResult(model);
                InventoryTransactionDTO dtoReserveResult = CreateDTOForReserveResult(model);

                InventoryTransBIZ bizTran = new InventoryTransBIZ();
                bizTran.LockRefSlipNumber(dtoWorkResult.REF_SLIP_NO);

                if (model.WorkResultNo.IsNull)
                {
                    RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();
                    runningNo = runningNumberBIZ.GetCompleteRunningNo((NZString)"WORK_RESULT_SLIP_NO", (NZString)"TB_INV_TRANS_TR");

                    // Create new transaction.
                    dtoWorkResult.SLIP_NO    = runningNo;
                    dtoNGResult.SLIP_NO      = runningNo;
                    dtoReserveResult.SLIP_NO = runningNo;

                    listAdd.Add(dtoWorkResult);
                    if (model.NGQty.NVL(0) > 0)
                    {
                        listAdd.Add(dtoNGResult);
                    }

                    if (model.ReserveQty.NVL(0) > 0)
                    {
                        listAdd.Add(dtoReserveResult);
                    }
                }
                else
                {
                    // Update old transaction
                    runningNo = model.WorkResultNo;

                    listUpdate.Add(dtoWorkResult);

                    if (!model.NGTransactionID.IsNull) // UPDATE NG IF IT ALREADY HAS NG QTY
                    {
                        listUpdate.Add(dtoNGResult);
                    }
                    else if (model.NGQty.NVL(0) > 0) // ADD NEW NG TRANS IF NEW NG IS INPUT
                    {
                        //dtoNGResult.SLIP_NO = dtoWorkResult.SLIP_NO;
                        listAdd.Add(dtoNGResult);
                    }

                    if (!model.ReserveTransactionID.IsNull) // UPDATE Reserve IF IT ALREADY HAS Reserve QTY
                    {
                        listUpdate.Add(dtoReserveResult);
                    }
                    else if (model.ReserveQty.NVL(0) > 0) // ADD NEW Reserve TRANS IF NEW NG IS INPUT
                    {
                        //dtoReserveResult.SLIP_NO = dtoWorkResult.SLIP_NO;
                        listAdd.Add(dtoNGResult);
                    }
                }

                #endregion

                #region Detail

                #region Do Auto Consumption
                if (ConsumptionClass == DataDefine.eCONSUMPTION_CLS.Auto)
                {
                    // WHEN CONSUMPTION IS AUTO
                    // DELETE ALL OLD TRANSACTION FIRST THEN ADD NEW

                    //Modify by Bunyapat L.
                    //28 Apr 2011
                    //ให้สั่ง ClearConsumption ไปเลย
                    List <WorkResultEntryViewDTO>  listTMPDelete = null;
                    List <InventoryTransactionDTO> listTmpDelete = null;

                    if (dtData != null && dtData.Rows.Count > 0)
                    {
                        listTMPDelete = DTOUtility.ConvertDataTableToList <WorkResultEntryViewDTO>(dtData);
                        listTmpDelete = new List <InventoryTransactionDTO>();
                        for (int i = 0; i < listTMPDelete.Count; i++)
                        {
                            WorkResultEntryViewDTO  line = listTMPDelete[i];
                            InventoryTransactionDTO dto  = CreateDTOForConsumption(model, line);
                            dto.REF_NO = runningNo;

                            listTmpDelete.Add(dto);
                        }

                        // Move to delete below section
                        //biz.WorkResultItems(Common.CurrentDatabase, null, null, listTmpDelete);
                    }

                    biz.ClearConsumption(Common.CurrentDatabase, dtoWorkResult);

                    if (dtData != null && dtData.Rows.Count > 0)
                    {
                        List <WorkResultEntryViewDTO> listTMPAdd = DTOUtility.ConvertDataTableToList <WorkResultEntryViewDTO>(dtData);

                        // GET LOCATION INFORMATION
                        DealingBIZ bizLoc = new DealingBIZ();
                        for (int i = 0; i < listTMPAdd.Count; i++)
                        {
                            DealingDTO dtoLoc        = bizLoc.LoadLocation(listTMPAdd[i].LOC_CD);
                            bool       AllowNegative = dtoLoc.ALLOW_NEGATIVE.StrongValue == "01";


                            // GET CONSUMPTION ITEM FROM FIFO PROCESS WRITE BY KIMMIK.
                            List <ActualOnhandViewDTO> dtoListActOnhand = biz.FifoListingProcess(Common.CurrentDatabase
                                                                                                 , listTMPAdd[i].ITEM_CD.StrongValue, listTMPAdd[i].LOC_CD.StrongValue
                                                                                                 , listTMPAdd[i].CONSUMPTION_QTY.StrongValue
                                                                                                 , !AllowNegative, AllowNegative);
                            if (dtoListActOnhand != null && dtoListActOnhand.Count > 0)
                            {
                                for (int j = 0; j < dtoListActOnhand.Count; j++)
                                {
                                    InventoryTransactionDTO dto = CreateDTOForConsumption(model, dtoListActOnhand[j]);
                                    dto.REF_NO = runningNo;

                                    listAdd.Add(dto);
                                }
                            }
                        }
                    }
                    biz.WorkResultItems(Common.CurrentDatabase, listAdd, listUpdate, listDelete);
                }
                #endregion

                #region Do Manual Consumption
                if (ConsumptionClass == DataDefine.eCONSUMPTION_CLS.Manual)
                {
                    List <InventoryTransactionDTO> listTmpDelete = new List <InventoryTransactionDTO>();
                    //== Update process.
                    //Modify by Bunyapat L.
                    //28 Apr 2011
                    //Manual consumption ให้ใช้การ insert เข้า Delete ทุกตัวที่เป็นตัวเก่า
                    //แล้วค่อย Add ตัวใหม่แทน เพราะข้างใน function มันจะทำการ clear consumption ทั้งหมด ไม่งั้นจะเกิด bug ตอน update
                    if (dtUpdate != null && dtUpdate.Rows.Count > 0)
                    {
                        List <WorkResultEntryViewDTO> listViewUpdate = DTOUtility.ConvertDataTableToList <WorkResultEntryViewDTO>(dtUpdate);


                        for (int i = 0; i < listViewUpdate.Count; i++)
                        {
                            WorkResultEntryViewDTO line = listViewUpdate[i];

                            // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                            InventoryTransactionDTO dto = CreateDTOForConsumption(model, line);
                            dto.REF_NO = runningNo;

                            //listUpdate.Add(dto);
                            listAdd.Add(dto);
                            listTmpDelete.Add((InventoryTransactionDTO)dto.Clone());
                        }
                    }

                    //== Insert process.
                    if (dtAdd != null && dtAdd.Rows.Count > 0)
                    {
                        List <WorkResultEntryViewDTO> listViewAdd = DTOUtility.ConvertDataTableToList <WorkResultEntryViewDTO>(dtAdd);

                        for (int i = 0; i < listViewAdd.Count; i++)
                        {
                            WorkResultEntryViewDTO  line = listViewAdd[i];
                            InventoryTransactionDTO dto  = CreateDTOForConsumption(model, line);
                            dto.REF_NO = runningNo;

                            listAdd.Add(dto);
                        }
                    }


                    //== Delete process.
                    if (dtDelete != null && dtDelete.Rows.Count > 0)
                    {
                        List <WorkResultEntryViewDTO> listViewDelete = DTOUtility.ConvertDataTableToList <WorkResultEntryViewDTO>(dtDelete);
                        for (int i = 0; i < dtDelete.Rows.Count; i++)
                        {
                            WorkResultEntryViewDTO line = listViewDelete[i];

                            // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                            InventoryTransactionDTO dto = CreateDTOForConsumption(model, line);
                            dto.REF_NO = runningNo;

                            listDelete.Add(dto);
                        }
                    }
                    biz.WorkResultItems(Common.CurrentDatabase, null, null, listTmpDelete);
                    biz.WorkResultItems(Common.CurrentDatabase, listAdd, listUpdate, listDelete);
                }
                #endregion

                #region Do No Consumption
                if (ConsumptionClass == DataDefine.eCONSUMPTION_CLS.No)
                {
                    biz.WorkResultItems(Common.CurrentDatabase, listAdd, listUpdate, listDelete);
                }
                #endregion
                #endregion

                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
            finally
            {
                if (db.DBConnectionState == ConnectionState.Open)
                {
                    db.Close();
                }
            }

            return(true);
        }
示例#30
0
        public void Save(ReturnEntryUIDM model, Common.eScreenMode Mode)
        {
            NZString  m_EditSlipNo;
            DataTable m_OldReturn = new DataTable();
            DataTable m_NewReturn = new DataTable();

            ReturnBIZ bizReturn = new ReturnBIZ();

            Database db = Common.CurrentDatabase.CreateNewDatabase();

            try
            {
                db.KeepConnection = true;
                db.BeginTransaction(IsolationLevel.Serializable);
                ShipmentBIZ bizShipment = new ShipmentBIZ();
                //bizShipment.AddShipmentEntry(dtoInvTrnsList);
                if (Mode != Common.eScreenMode.ADD)
                {
                    m_EditSlipNo = model.SLIP_NO;
                    m_OldReturn  = bizReturn.Load_ReturnListEntry(m_EditSlipNo, false);
                }

                IssueEntryValidator val       = new IssueEntryValidator();
                CommonBizValidator  commonVal = new CommonBizValidator();


                //== If data not has to processing.
                if (model.DATA_VIEW == null || model.DATA_VIEW.Rows.Count == 0)
                {
                    ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0055.ToString()));
                }

                DataTable dtData     = model.DATA_VIEW;
                DataTable dtUnChange = new DataTable();
                DataTable dtAdd      = new DataTable();
                DataTable dtModify   = new DataTable();
                DataTable dtDelete   = new DataTable();

                //if (Mode == Common.eScreenMode.ADD || m_OldReturn.Rows.Count <= 0)
                //{
                dtUnChange = dtData.GetChanges(DataRowState.Unchanged);
                dtAdd      = dtData.GetChanges(DataRowState.Added);
                dtModify   = dtData.GetChanges(DataRowState.Modified);
                dtDelete   = dtData.GetChanges(DataRowState.Deleted);

                /*}
                 * else
                 * {
                 *  dtAdd = dtData.Clone();
                 *  dtModify = dtData.Clone();
                 *  dtDelete = dtData.Clone();
                 *
                 *  m_NewReturn = model.DATA_VIEW.Copy();
                 *  m_NewReturn.AcceptChanges();
                 *
                 *  // Manage for Update and Delete
                 *  for (int i = 0; i < m_OldReturn.Rows.Count; i++)
                 *  {
                 *      string OrderDetailNo = Convert.ToString(m_OldReturn.Rows[i]["REF_SLIP_NO"]);
                 *      string ItemCd = Convert.ToString(m_OldReturn.Rows[i]["ITEM_CD"]);
                 *
                 *      //decimal ShipQTY = Convert.ToDecimal(m_OldReturn.Rows[i]["SHIP_QTY"]);
                 *      //decimal RemainableQTY = Convert.ToDecimal(m_OldReturn.Rows[i]["RETURNABLE_QTY"]);
                 *      decimal ReturnQTY = Convert.ToDecimal(m_OldReturn.Rows[i]["RETURN_QTY"]);
                 *
                 *      bool found_order_detail = false;
                 *      for (int j = 0; j < m_NewReturn.Rows.Count; j++)
                 *      {
                 *
                 *          if (Convert.ToString(m_NewReturn.Rows[j]["REF_SLIP_NO"]) == OrderDetailNo
                 *              && Convert.ToString(m_NewReturn.Rows[j]["ITEM_CD"]) == ItemCd
                 *              && Convert.ToDecimal(m_NewReturn.Rows[j]["RETURN_QTY"]) != ReturnQTY)
                 *          {
                 *              found_order_detail = true;
                 *
                 *              // Delete Old
                 *              DataRow row = dtDelete.NewRow();
                 *              row["TRANS_ID"] = m_OldReturn.Rows[i]["TRANS_ID"];
                 *              row["ITEM_CD"] = m_OldReturn.Rows[i]["ITEM_CD"];
                 *              row["LOC_CD"] = m_OldReturn.Rows[i]["LOC_CD"];
                 *              row["TRANS_DATE"] = m_OldReturn.Rows[i]["TRANS_DATE"];
                 *              row["TRANS_CLS"] = m_OldReturn.Rows[i]["TRANS_CLS"];
                 *              row["IN_OUT_CLS"] = m_OldReturn.Rows[i]["IN_OUT_CLS"];
                 *              row["RETURN_QTY"] = m_OldReturn.Rows[i]["RETURN_QTY"];
                 *              row["REF_SLIP_NO"] = OrderDetailNo;
                 *              dtDelete.Rows.Add(row);
                 *
                 *
                 *              if (Convert.ToString(m_NewReturn.Rows[j]["REF_SLIP_NO"]) == OrderDetailNo
                 *                  && Convert.ToString(m_NewReturn.Rows[j]["ITEM_CD"]) == ItemCd)
                 *              {
                 *                  dtAdd.ImportRow(m_NewReturn.Rows[j]);
                 *              }
                 *
                 *          }
                 *          else if (Convert.ToString(m_NewReturn.Rows[j]["REF_SLIP_NO"]) == OrderDetailNo
                 *              && Convert.ToString(m_NewReturn.Rows[j]["ITEM_CD"]) == ItemCd
                 *              && Convert.ToDecimal(m_NewReturn.Rows[j]["RETURN_QTY"]) == ReturnQTY)
                 *          {
                 *              found_order_detail = true;
                 *          }
                 *
                 *          // In  update have remove order
                 *          if (j == m_NewReturn.Rows.Count - 1 && !found_order_detail)
                 *          {
                 *              // Delete Old
                 *              DataRow row = dtDelete.NewRow();
                 *              row["TRANS_ID"] = m_OldReturn.Rows[i]["TRANS_ID"];
                 *              row["ITEM_CD"] = m_OldReturn.Rows[i]["ITEM_CD"];
                 *              row["LOC_CD"] = m_OldReturn.Rows[i]["LOC_CD"];
                 *              row["TRANS_DATE"] = m_OldReturn.Rows[i]["TRANS_DATE"];
                 *              row["TRANS_CLS"] = m_OldReturn.Rows[i]["TRANS_CLS"];
                 *              row["IN_OUT_CLS"] = m_OldReturn.Rows[i]["IN_OUT_CLS"];
                 *              row["RETURN_QTY"] = m_OldReturn.Rows[i]["RETURN_QTY"];
                 *              row["REF_SLIP_NO"] = OrderDetailNo;
                 *              dtDelete.Rows.Add(row);
                 *          }
                 *      }
                 *  }
                 *
                 *  // Manage for check add new order on update mode
                 *  for (int i = 0; i < m_NewReturn.Rows.Count; i++)
                 *  {
                 *      string OrderDetailNo = Convert.ToString(m_NewReturn.Rows[i]["REF_SLIP_NO"]);
                 *      string ItemCd = Convert.ToString(m_NewReturn.Rows[i]["ITEM_CD"]);
                 *
                 *      //decimal ShipQTY = Convert.ToDecimal(m_NewReturn.Rows[i]["SHIP_QTY"]);
                 *      //decimal RemainableQTY = Convert.ToDecimal(m_NewReturn.Rows[i]["RETURNABLE_QTY"]);
                 *      decimal ReturnQTY = Convert.ToDecimal(m_NewReturn.Rows[i]["RETURN_QTY"]);
                 *      bool found_order_detail = false;
                 *      for (int j = 0; j < m_OldReturn.Rows.Count; j++)
                 *      {
                 *
                 *          if (Convert.ToString(m_OldReturn.Rows[j]["REF_SLIP_NO"]) == OrderDetailNo
                 *              && Convert.ToString(m_OldReturn.Rows[j]["ITEM_CD"]) == ItemCd
                 *              && Convert.ToDecimal(m_OldReturn.Rows[j]["RETURN_QTY"]) != ReturnQTY)
                 *          {
                 *              found_order_detail = true;
                 *          }
                 *
                 *
                 *          // Not found old order in new order then add new order
                 *          if (j == m_OldReturn.Rows.Count - 1 && !found_order_detail)
                 *          {
                 *              if (Convert.ToString(m_NewReturn.Rows[i]["REF_SLIP_NO"]) == OrderDetailNo
                 *                      && Convert.ToString(m_NewReturn.Rows[i]["ITEM_CD"]) == ItemCd)
                 *              {
                 *                  dtAdd.ImportRow(m_NewReturn.Rows[i]);
                 *              }
                 *          }
                 *      }
                 *  }
                 * }*/

                InventoryBIZ biz = new InventoryBIZ();

                List <InventoryTransactionDTO> listAdd      = null;
                List <InventoryTransactionDTO> listUpdate   = null;
                List <InventoryTransactionDTO> listDelete   = null;
                List <InventoryTransactionDTO> listUnChange = null;

                //== Insert process.
                if (dtAdd != null && dtAdd.Rows.Count > 0)
                {
                    listAdd = new List <InventoryTransactionDTO>();
                    listAdd = DTOUtility.ConvertDataTableToList <InventoryTransactionDTO>(dtAdd);
                    RunningNumberBIZ runningNumberBIZ         = new RunningNumberBIZ();
                    NZString         runningNo_SLIP_NO        = null;
                    NZString         runningNo_GROUP_TRANS_ID = null;

                    if (model.SLIP_NO.IsNull || model.SLIP_NO.Value == "")
                    {
                        runningNo_SLIP_NO = runningNumberBIZ.GetCompleteRunningNo((NZString)"RETURN_NO", (NZString)"TB_INV_TRANS_TR");
                    }
                    else
                    {
                        runningNo_SLIP_NO = model.SLIP_NO;
                    }

                    if (model.GROUP_TRANS_ID.IsNull)
                    {
                        runningNo_GROUP_TRANS_ID = runningNumberBIZ.GetCompleteRunningNo(new NZString(null, "TRAN_GROUP_ID"), new NZString(null, "TB_INV_TRANS_TR"));
                    }
                    else
                    {
                        runningNo_GROUP_TRANS_ID = model.SLIP_NO;
                    }

                    for (int i = 0; i < listAdd.Count; i++)
                    {
                        InventoryTransactionDTO dto = listAdd[i];

                        // มีการ Gen Running Number ของ NO_LOT_TRANS_ID ไว้แล้วใน InventoryBIZ FN: AddInventoryTransaction
                        //NZString runningNo_LOT_TRANS_ID = runningNumberBIZ.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR"));
                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto, Mode);

                        dto.SLIP_NO        = runningNo_SLIP_NO;
                        dto.GROUP_TRANS_ID = runningNo_GROUP_TRANS_ID;

                        //dto.TRANS_ID = runningNo_LOT_TRANS_ID;

                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                        listAdd[i] = dto;
                        // check for lot no if ship type is SHIP
                        //if (model.TRANS_CLS.StrongValue != DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Shipment_Return))
                        //    ValidateException.ThrowErrorItem(commonVal.CheckInputLot(dto.ITEM_CD, dto.LOC_CD, dto.LOT_NO, true));
                    }
                }

                //== Update process.
                if (dtModify != null && dtModify.Rows.Count > 0)
                {
                    listUpdate = DTOUtility.ConvertDataTableToList <InventoryTransactionDTO>(dtModify);

                    for (int i = 0; i < listUpdate.Count; i++)
                    {
                        InventoryTransactionDTO dto = listUpdate[i];

                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto, Mode);

                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                        listUpdate[i] = dto;
                    }
                }

                //== Update for Unchage กรณีที่ header เปลี่ยนแต่ส่วนของ Spread ไม่มีการเปลี่ยนแปลงต้องใช้ UnChanged ช่วย Update
                if (dtUnChange != null && dtUnChange.Rows.Count > 0)
                {
                    listUnChange = DTOUtility.ConvertDataTableToList <InventoryTransactionDTO>(dtUnChange);
                    if (listUpdate == null)
                    {
                        listUpdate = new List <InventoryTransactionDTO>();
                    }
                    for (int i = 0; i < listUnChange.Count; i++)
                    {
                        InventoryTransactionDTO dto = listUnChange[i];

                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto, Mode);

                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;
                        //dto.QTY.Value = 0;

                        listUpdate.Add(dto);
                    }
                }


                //== Delete process.
                if (dtDelete != null && dtDelete.Rows.Count > 0)
                {
                    listDelete = DTOUtility.ConvertDataTableToList <InventoryTransactionDTO>(dtDelete);
                }

                bizReturn.SaveShipmentEntry(db, listAdd, listUpdate, listDelete);

                //if (Mode == Common.eScreenMode.EDIT)
                //{
                //    if (dtData != null && dtData.Rows.Count > 0)
                //    {
                //        listUpdate = DTOUtility.ConvertDataTableToList<InventoryTransactionDTO>(dtData);

                //        for (int i = 0; i < listUpdate.Count; i++)
                //        {
                //            InventoryTransactionDTO dto = listUpdate[i];

                //            // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                //            AssignHeaderToDTO(model, dto,Mode);

                //            dto.CRT_BY = Common.CurrentUserInfomation.UserCD;
                //            dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                //            dto.UPD_BY = Common.CurrentUserInfomation.UserCD;
                //            dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                //            DeliveryBIZ bizDelivery = new DeliveryBIZ();
                //            bizDelivery.UpdateReceiveHeader(db, listUpdate[i]);
                //        }
                //    }

                //    //if (dtDelete != null && dtDelete.Rows.Count > 0)
                //    //{
                //    //    ShipmentEntryController ctlShip = new ShipmentEntryController();

                //    //    for (int i = 0; i < dtDelete.Rows.Count; i++)
                //    //    {
                //    //        NZString strOrderDetailNo = dtDelete.Rows[i]["REF_SLIP_NO"].ToString().ToNZString();
                //    //        decimal dQTY = Convert.ToDecimal(dtDelete.Rows[i]["QTY"]);
                //    //        if (dQTY == null || dQTY <= 0) continue;
                //    //        ctlShip.UpdateShipQTY(strOrderDetailNo, dQTY * -1);
                //    //    }
                //    //}

                //    //if (dtAdd != null && dtAdd.Rows.Count > 0)
                //    //{
                //    //    ShipmentEntryController ctlShip = new ShipmentEntryController();

                //    //    for (int i = 0; i < dtAdd.Rows.Count; i++)
                //    //    {
                //    //        NZString strOrderDetailNo = dtAdd.Rows[i]["REF_SLIP_NO"].ToString().ToNZString();
                //    //        decimal dQTY = Convert.ToDecimal(dtAdd.Rows[i]["QTY"]);
                //    //        if (dQTY == null || dQTY <= 0) continue;
                //    //        ctlShip.UpdateShipQTY(strOrderDetailNo, dQTY);
                //    //    }
                //    //}

                //}

                //if (Mode == Common.eScreenMode.EDIT)
                //{
                //    if (dtAdd != null && dtAdd.Rows.Count > 0)
                //    {
                //        listUpdate = DTOUtility.ConvertDataTableToList<InventoryTransactionDTO>(dtAdd);

                //        for (int i = 0; i < listUpdate.Count; i++)
                //        {
                //            InventoryTransactionDTO dto = listUpdate[i];

                //            // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                //            AssignHeaderToDTO(model, dto);

                //            dto.CRT_BY = Common.CurrentUserInfomation.UserCD;
                //            dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                //            dto.UPD_BY = Common.CurrentUserInfomation.UserCD;
                //            dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                //            //biz.UpdateReceiveHeader(db, dto);

                //            biz.UpdateInventoryOnhand(db, dto, DataDefine.eOperationClass.Add);
                //        }
                //    }
                //}
                db.Commit();
            }
            catch
            {
                db.Rollback();
                throw;
            }
            finally
            {
                if (db.DBConnectionState == ConnectionState.Open)
                {
                    db.Close();
                }
            }
        }