コード例 #1
0
        /// <summary>
        /// คัดลอกค่าที่เป็น Header ของ Model ไปเก็บไว้ใน DTO
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dto"></param>
        private void AssignHeaderToDTO(ReceivingEntryUIDM model, InventoryTransactionDTO dto)
        {
            dto.TRANS_DATE  = model.RECEIVE_DATE;
            dto.SLIP_NO     = model.RECEIVE_NO;
            dto.TRANS_CLS   = model.RECEIVE_TYPE;
            dto.REF_SLIP_NO = model.PO_NO;
            dto.OTHER_DL_NO = model.INVOICE_NO;
            dto.REMARK      = model.REMARK;
            dto.LOC_CD      = model.STORED_LOC;
            dto.DEALING_NO  = model.DEALING_NO;
            dto.SCREEN_TYPE = DataDefine.ScreenType.ReceivingEntry.ToNZString();

            dto.REF_SLIP_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eREF_SLIP_CLS.PurchseOrder);

            if (dto.TRANS_CLS.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Receiving))
            {
                dto.IN_OUT_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.In);
            }
            else
            {
                dto.IN_OUT_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.Out);
            }

            if (dto.REF_NO.IsNull)
            {
                RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();
                NZString         runningNo        = runningNumberBIZ.GetCompleteRunningNo(DataDefine.RECEIVE_REF_NO.ToNZString(), DataDefine.TRANSACTION_TABLE_NAME.ToNZString());
                dto.REF_NO = runningNo;
            }
        }
コード例 #2
0
        private void Add()
        {
            ValidateAllRows();
            RunningNumberBIZ bizRunning = new RunningNumberBIZ();
            NZString         strPONo    = bizRunning.GetCompleteRunningNo(new NZString(null, "PO_NO"), new NZString(null, "TB_PURCHASE_ORDER_H_TR"));

            PurchaseOrderHDTO        hDTOPurchaseOrder = GeneratePurchaseOrderHDTO(strPONo);
            List <PurchaseOrderDDTO> dDTOPurchaseOrder = GeneratePurchaseOrderDDTO(strPONo, eModifyState.Add);

            m_BIZPurchaseOrder.AddPO(hDTOPurchaseOrder, dDTOPurchaseOrder);
        }
コード例 #3
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            //eScreenMode ePreviousMode = m_eScreenMode;

            try {
                this.Cursor = Cursors.WaitCursor;

                //if (string.Empty.Equals(txtRecoverDay.Text))
                //{
                //    ErrorItem err = new ErrorItem(null, TKPMessages.eValidate.VLM0143.ToString());
                //    throw new BusinessException(err);
                //}

                MessageDialogResult dr = MessageDialog.ShowConfirmation(this, new EVOFramework.Message(TKPMessages.eConfirm.CFM0005.ToString()).MessageDescription);
                if (dr == MessageDialogResult.Yes)
                {
                    picWaiting.Visible = true;

                    SetScreenMode(eScreenMode.Simulate);

                    RunningNumberBIZ bizRunning = new RunningNumberBIZ();
                    NZString         strMRPNo   = bizRunning.GetCompleteRunningNo(new NZString(null, CONST_STR_MRP_NO), new NZString(null, "TB_MRP_H_TR"));
                    m_strMRPNo = strMRPNo;

                    if (RunProcess())
                    {
                        MessageDialog.ShowInformation(this, "Information", new EVOFramework.Message(Messages.eInformation.INF9003.ToString()).MessageDescription);

                        LoadData(m_strMRPNo);
                        SetDefaultControl();
                    }
                    else
                    {
                        txtMRPNo.Clear();
                        ClearSpread(shtViewHeader, shtViewDetail);
                    }
                }
            }
            catch (ValidateException ex) {
                MessageDialog.ShowBusiness(this, ex.ErrorResults[0].Message);
            }
            catch (BusinessException ex) {
                MessageDialog.ShowBusiness(this, ex.Error.Message);
            }
            catch (Exception ex) {
                MessageDialog.ShowBusiness(this, ex.Message);
            }
            finally {
                picWaiting.Visible = false;
                SetScreenMode(eScreenMode.View);
                this.Cursor = Cursors.Default;
            }
        }
コード例 #4
0
        public NZString GeneratePackNo()
        {
            CommonLib.Common.CurrentDatabase.KeepConnection = true;
            CommonLib.Common.CurrentDatabase.BeginTransaction(IsolationLevel.Serializable);

            NZString PackNo = new NZString();

            try
            {

                #region Lock Running Number gen.

                TransactionLockDAO daoTrans = new TransactionLockDAO(CommonLib.Common.CurrentDatabase);
                TransactionLockDTO dtoTrans = new TransactionLockDTO();
                NZString key1 = new NZString(null, "PACK_NO_AUTO_GEN");
                NZString key2 = new NZString(null, "INV_TRANS_TR");
                if (!daoTrans.Exist(null, key1, key2))
                {
                    dtoTrans.KEY1 = key1;
                    dtoTrans.KEY2 = key2;
                    dtoTrans.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dtoTrans.CRT_DATE.Value = DateTime.Now;
                    dtoTrans.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
                    daoTrans.AddNew(null, dtoTrans);
                }

                // lock transaction
                daoTrans.SelectWithKeys(null, key1, key2);
                // end of lock transaction

                #endregion

                List<InventoryTransactionDTO> dtoList = new List<InventoryTransactionDTO>();

                RunningNumberBIZ bizRunning = new RunningNumberBIZ();
                PackNo = bizRunning.GetCompleteRunningNo(new NZString(null, "PACK_NO_AUTO_GEN"), new NZString(null, "TB_INV_TRANS_TR"));

                daoTrans.DeleteWithKeys(null, key1, key2);
                CommonLib.Common.CurrentDatabase.Commit();
            }
            catch (BusinessException)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }
            catch (Exception)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }

            return PackNo;
        }
コード例 #5
0
        private void dtReceiveDate_ValueChanged(object sender, EventArgs e)
        {
            if (dtReceiveDate.Value.HasValue)
            {
                int row = shtView.Rows.Count;
                if (row > 0)
                {
                    RunningNumberBIZ runningNoBiz = new RunningNumberBIZ();

                    for (int i = 0; i < row; i++)
                    {
                        //shtView.Cells[i, (int)eColView.LOT_NO].Value = dtReceiveDate.Value.Value.ToString(DataDefine.LOT_NO_FORMAT);

                        string oLotControlCls = Convert.ToString(shtView.Cells[i, (int)eColView.LOT_CONTROL_CLS].Value);

                        string strItemCode = Convert.ToString(shtView.Cells[i, (int)eColView.ITEM_CD].Value);

                        if (oLotControlCls == DataDefine.Convert2ClassCode(DataDefine.eLOT_CONTROL_CLS.Yes))
                        {
                            //shtView.Cells[row, (int)eColView.LOT_NO].Value = dtReceiveDate.Value.Value.ToString(DataDefine.LOT_NO_FORMAT);

                            if (rdoReceive.Checked)
                            {
                                NZString strLotNoPrefix = runningNoBiz.GenerateLotNoPrefix(new NZDateTime(null, dtReceiveDate.Value));
                                NZInt    iLastRunningNo = runningNoBiz.GetLastLotNoRunningBox(strLotNoPrefix, new NZString(cboStoredLoc, (string)cboStoredLoc.SelectedValue), (NZString)strItemCode, new NZInt(null, 0));

                                ReceivingEntryController rcvController = new ReceivingEntryController();
                                NZString strLotNo = rcvController.GenerateLotNo(strLotNoPrefix, ref iLastRunningNo);
                                shtView.Cells[i, (int)eColView.LOT_NO].Value = strLotNo.StrongValue;
                            }
                        }
                        else
                        {
                            shtView.Cells[i, (int)eColView.LOT_NO].Value = null;
                        }
                    }
                }
            }
        }
コード例 #6
0
        public void AddCustomerOrderDetail(Database database, List <CustomerOrderViewDTO> ListAdd)
        {
            //== Dispatcher Transaction Type.
            RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();

            for (int i = 0; i < ListAdd.Count; i++)
            {
                if (ListAdd[i].ORDER_DETAIL_NO.IsNull || ListAdd[i].ORDER_DETAIL_NO.Value == null || ListAdd[i].ORDER_DETAIL_NO.Value.ToString() == "")
                {
                    // Generate new Transaction ID.
                    NZString runningNo = runningNumberBIZ.GetCompleteRunningNo((NZString)"CUSTOMER_ORDER_DETAIL_NO", (NZString)"TB_CUSTOMER_ORDERD_TR");
                    ListAdd[i].ORDER_DETAIL_NO = runningNo;
                }

                // Add Inventory transaction.
                CustomerOrderDDAO dao = new CustomerOrderDDAO(database);
                ListAdd[i].CRT_BY      = CommonLib.Common.CurrentUserInfomation.UserCD;
                ListAdd[i].CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
                ListAdd[i].UPD_BY      = CommonLib.Common.CurrentUserInfomation.UserCD;
                ListAdd[i].UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;

                if (dao.AddNewOrUpdate(database, CustomerOrderViewDTO2CustomerOrderDDTO(ListAdd[i])) <= 0)
                {
                    throw new ValidateException("Insert failed. Data is missing, Please check your data.");
                }

                //data.TRANS_CLS = transType;
                // Start update stock.
                //UpdateInventoryOnhand(database, data, DataDefine.eOperationClass.Add);

                //if (data.TRANS_CLS == DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Receiving))
                //{
                //    dao.UpdatePOBalance(null, data, data.QTY.StrongValue);
                //}
            }
        }
コード例 #7
0
        public InventoryTransactionDTO ConvertToInventoryTransactionDTO(DateTime argStockTakingDate, DateTime argAdjustDate, DataRow dr)
        {

            InventoryTransactionDTO dto = new InventoryTransactionDTO();

            RunningNumberBIZ bizRunning = new RunningNumberBIZ();
            NZString SlipNo = bizRunning.GetCompleteRunningNo(new NZString(null, "ADJUST_NO"), new NZString(null, "TB_INV_TRANS_TR"));
            dto.SLIP_NO = SlipNo;


            dto.TRANS_ID = new NZString(null, "-"); // new transaction แน่ๆเพราะ adjust ใหม่
            dto.ITEM_CD = new NZString(null, dr[(int)eStockTakingUpdateColum.ITEM_CD]);
            dto.LOC_CD = new NZString(null, dr[(int)eStockTakingUpdateColum.LOC_CD]);

            if (dr[(int)eStockTakingUpdateColum.LOT_NO] == DBNull.Value)
            {
                dto.LOT_NO = new NZString(null, null);
            }
            else
            {
                dto.LOT_NO = new NZString(null, dr[(int)eStockTakingUpdateColum.LOT_NO]);
            }

            if (dr[(int)eStockTakingUpdateColum.PACK_NO] == DBNull.Value)
            {
                dto.PACK_NO = new NZString(null, null);
            }
            else
            {
                dto.PACK_NO = new NZString(null, dr[(int)eStockTakingUpdateColum.PACK_NO]);
            }

            if (dr[(int)eStockTakingUpdateColum.EXTERNAL_LOT_NO] == DBNull.Value)
            {
                dto.EXTERNAL_LOT_NO = new NZString(null, null);
            }
            else
            {
                dto.EXTERNAL_LOT_NO = new NZString(null, dr[(int)eStockTakingUpdateColum.EXTERNAL_LOT_NO]);
            }

            if (dr[(int)eStockTakingUpdateColum.FG_NO] == DBNull.Value)
            {
                dto.FG_NO = new NZString(null, null);
            }
            else
            {
                dto.FG_NO = new NZString(null, dr[(int)eStockTakingUpdateColum.FG_NO]);
            }

            //modify on 30 oct 2010
            //change adjust date from stock taking date to be
            //   - end period date :  current date > end period date 
            //   - current date : current date <= end period date
            dto.TRANS_DATE = new NZDateTime(null, argAdjustDate);
            dto.TRANS_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Adjustment);
            dto.TRAN_SUB_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eADJUST_TYPE.StockTaking);

            decimal decQty = 0;
            decQty = Convert.ToDecimal(dr[(int)eStockTakingUpdateColum.DIFF_QTY]);
            if (decQty > 0)
            {
                dto.IN_OUT_CLS = new NZString(null, DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.In));
                dto.QTY = new NZDecimal(null, decQty);
                dto.EFFECT_STOCK = new NZInt(null, 1);
            }
            else
            {
                dto.IN_OUT_CLS = new NZString(null, DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.Out));
                dto.QTY = new NZDecimal(null, Math.Abs(decQty));
                dto.EFFECT_STOCK = new NZInt(null, -1);
            }

            //dto.OBJ_ITEM_CD =
            //dto.REF_NO =
            //dto.REF_SLIP_NO =
            //dto.REF_SLIP_CLS =
            //dto.OTHER_DL_NO =
            dto.REMARK = new NZString(null, "Stock Taking on " + argStockTakingDate.ToString("dd/MM/yyyy"));
            dto.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            dto.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
            dto.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            dto.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;

            return dto;
        }
コード例 #8
0
        internal void SaveDataEditMode(IssueByOrderUIDM model)
        {
            //== 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()));
            }

            //model.DATA_VIEW.AcceptChanges();


            // 20100324 11:44 Add by Teerayut S.
            // Comment: Move begin transaction from business class to controller class.
            // add try..catch block to control transaction scope.
            Common.CurrentDatabase.KeepConnection = true;
            Common.CurrentDatabase.BeginTransaction(IsolationLevel.Serializable);
            // 20100324 End Teerayut S.

            try
            {
                DataTable dtData = model.DATA_VIEW;

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

                InventoryBIZ biz = new InventoryBIZ();

                List <InventoryTransactionDTO> listAdd_from    = null;
                List <InventoryTransactionDTO> listUpdate_from = null;
                List <InventoryTransactionDTO> listDelete_from = null;

                List <InventoryTransactionDTO> listAdd_to    = null;
                List <InventoryTransactionDTO> listUpdate_to = null;
                List <InventoryTransactionDTO> listDelete_to = null;

                //== Insert process.
                if (dtAdd != null && dtAdd.Rows.Count > 0)
                {
                    listAdd_from = ConvertDataTableToList(dtAdd, DataDefine.eIN_OUT_CLASS.Out);
                    listAdd_to   = ConvertDataTableToList(dtAdd, DataDefine.eIN_OUT_CLASS.In);
                    NZString runningNo;

                    if (model.SLIP_NO.IsNull)
                    {
                        RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();
                        runningNo = runningNumberBIZ.GetCompleteRunningNo((NZString)"ISSUE_SLIP_NO", (NZString)"TB_INV_TRANS_TR");
                    }
                    else
                    {
                        runningNo = model.SLIP_NO;
                    }

                    for (int i = 0; i < listAdd_from.Count; i++)
                    {
                        InventoryTransactionDTO dto_from = listAdd_from[i];
                        InventoryTransactionDTO dto_to   = listAdd_to[i];
                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto_from, DataDefine.eIN_OUT_CLASS.Out);
                        AssignHeaderToDTO(model, dto_to, DataDefine.eIN_OUT_CLASS.In);

                        dto_from.SLIP_NO     = runningNo;
                        dto_from.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_from.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto_from.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_from.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                        dto_to.REF_SLIP_NO = runningNo;
                        dto_to.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_to.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto_to.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_to.UPD_MACHINE = Common.CurrentUserInfomation.Machine;
                    }
                }

                //== Update process.
                if (dtModify != null && dtModify.Rows.Count > 0)
                {
                    listUpdate_from = ConvertDataTableToList(dtModify, DataDefine.eIN_OUT_CLASS.Out);
                    listUpdate_to   = ConvertDataTableToList(dtModify, DataDefine.eIN_OUT_CLASS.In);

                    for (int i = 0; i < listUpdate_from.Count; i++)
                    {
                        InventoryTransactionDTO dto_from = listUpdate_from[i];
                        InventoryTransactionDTO dto_to   = listUpdate_to[i];

                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto_from, DataDefine.eIN_OUT_CLASS.Out);
                        AssignHeaderToDTO(model, dto_to, DataDefine.eIN_OUT_CLASS.In);

                        dto_from.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_from.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto_from.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_from.UPD_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto_to.CRT_BY        = Common.CurrentUserInfomation.UserCD;
                        dto_to.CRT_MACHINE   = Common.CurrentUserInfomation.Machine;
                        dto_to.UPD_BY        = Common.CurrentUserInfomation.UserCD;
                        dto_to.UPD_MACHINE   = Common.CurrentUserInfomation.Machine;
                    }
                }


                //== Delete process.
                if (dtDelete != null && dtDelete.Rows.Count > 0)
                {
                    listDelete_from = ConvertDataTableToList(dtDelete, DataDefine.eIN_OUT_CLASS.Out);
                    listDelete_to   = ConvertDataTableToList(dtDelete, DataDefine.eIN_OUT_CLASS.In);

                    for (int i = 0; i < listDelete_from.Count; i++)
                    {
                        InventoryTransactionDTO dto_from = listDelete_from[i];
                        InventoryTransactionDTO dto_to   = listDelete_to[i];

                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto_from, DataDefine.eIN_OUT_CLASS.Out);
                        AssignHeaderToDTO(model, dto_to, DataDefine.eIN_OUT_CLASS.In);
                    }
                }


                // ------ Update Header Process -------------
                List <InventoryTransactionDTO> listUpdateHeader_from = new List <InventoryTransactionDTO>();
                List <InventoryTransactionDTO> listUpdateHeader_to   = new List <InventoryTransactionDTO>();

                if (dtData != null && dtData.Rows.Count > 0)
                {
                    listUpdateHeader_from = ConvertDataTableToList(dtData, DataDefine.eIN_OUT_CLASS.Out);
                    listUpdateHeader_to   = ConvertDataTableToList(dtData, DataDefine.eIN_OUT_CLASS.In);

                    for (int i = 0; i < listUpdateHeader_from.Count; i++)
                    {
                        InventoryTransactionDTO dto_from = listUpdateHeader_from[i];
                        InventoryTransactionDTO dto_to   = listUpdateHeader_to[i];

                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto_from, DataDefine.eIN_OUT_CLASS.Out);
                        AssignHeaderToDTO(model, dto_to, DataDefine.eIN_OUT_CLASS.In);

                        dto_from.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_from.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto_from.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto_from.UPD_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto_to.CRT_BY        = Common.CurrentUserInfomation.UserCD;
                        dto_to.CRT_MACHINE   = Common.CurrentUserInfomation.Machine;
                        dto_to.UPD_BY        = Common.CurrentUserInfomation.UserCD;
                        dto_to.UPD_MACHINE   = Common.CurrentUserInfomation.Machine;

                        biz.UpdateIssueHeader(listUpdateHeader_from[i]);
                        biz.UpdateIssueHeader(listUpdateHeader_to[i]);
                    }
                }

                // --------- End ----------------------

                biz.UpdateIssueByOrder(listAdd_from, listAdd_to, listUpdate_from, listUpdate_to, listDelete_from, listDelete_to);

                CommonLib.Common.CurrentDatabase.Commit();
            }
            catch (Exception err)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }
        }
コード例 #9
0
        /// <summary>
        /// Save new data.
        /// </summary>
        /// <param name="model"></param>
        public void SaveAdd(AdjustmentEntryUIDM model)
        {
            try
            {
                CommonLib.Common.CurrentDatabase.KeepConnection = true;
                CommonLib.Common.CurrentDatabase.BeginTransaction(System.Data.IsolationLevel.Serializable);

                AdjustmentValidator  adjustmentValidator = new AdjustmentValidator();
                ItemValidator        itemValidator       = new ItemValidator();
                DealingValidator     locationValidator   = new DealingValidator();
                TransactionValidator valTran             = new TransactionValidator();
                CommonBizValidator   commonVal           = new CommonBizValidator();

                //ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyAdjustDate(model.AdjustDate));
                //ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyReasonCode(model.ReasonCode));
                //ValidateException.ThrowErrorItem(valTran.DateIsInCurrentPeriod(model.AdjustDate));
                //ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(model.ItemCode));

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

                //ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(model.StoredLoc));
                ValidateException.ThrowErrorItem(locationValidator.CheckNotExistsLocationCode(model.StoredLoc));
                ValidateException.ThrowErrorItem(commonVal.CheckInputLot(model.ItemCode, new NZString(), model.LotNo, false));

                //ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyAdjustQty(model.AdjustQty));
                //ValidateException.ThrowErrorItem(adjustmentValidator.CheckIsZeroAdjustQty(model.AdjustQty));

                #region Lock Running Number gen.

                TransactionLockDAO daoTrans = new TransactionLockDAO(CommonLib.Common.CurrentDatabase);
                TransactionLockDTO dtoTrans = new TransactionLockDTO();
                NZString           key1     = new NZString(null, "ADJUST_NO");
                NZString           key2     = new NZString(null, "INV_TRANS_TR");
                if (!daoTrans.Exist(null, key1, key2))
                {
                    dtoTrans.KEY1           = key1;
                    dtoTrans.KEY2           = key2;
                    dtoTrans.CRT_BY         = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dtoTrans.CRT_DATE.Value = DateTime.Now;
                    dtoTrans.CRT_MACHINE    = CommonLib.Common.CurrentUserInfomation.Machine;
                    daoTrans.AddNew(null, dtoTrans);
                }

                // lock transaction
                daoTrans.SelectWithKeys(null, key1, key2);
                // end of lock transaction

                #endregion

                RunningNumberBIZ bizRunning = new RunningNumberBIZ();
                NZString         SlipNo     = bizRunning.GetCompleteRunningNo(new NZString(null, "ADJUST_NO"), new NZString(null, "TB_INV_TRANS_TR"));
                model.AdjustNo = SlipNo;

                NZString GroupTransID = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_GROUP_ID"), new NZString(null, "TB_INV_TRANS_TR"));
                model.GroupTransID = GroupTransID;

                #region Generate pack_no if it is empty

                DealingConstraintBIZ bizConstraint = new DealingConstraintBIZ();

                string strProcess = model.StoredLoc.StrongValue;
                DealingConstraintDTO constriant = bizConstraint.LoadDealingConstraint(strProcess.ToNZString());
                if (constriant != null && constriant.ENABLE_PACK_FLAG.StrongValue == 1 && model.PackNo.IsNull)
                {
                    NZString PackNo = bizRunning.GetCompleteRunningNo(new NZString(null, "PACK_NO_AUTO_GEN"), new NZString(null, "TB_INV_TRANS_TR"));
                    model.PackNo = PackNo;
                }

                #endregion

                InventoryBIZ inventoryBIZ = new InventoryBIZ();

                InventoryTransactionDTO dto = ConvertUIDMToDTO(model);
                inventoryBIZ.AddInventoryTransaction(CommonLib.Common.CurrentDatabase, dto, true);

                CommonLib.Common.CurrentDatabase.Commit();
            }
            catch (System.Exception)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }
        }
コード例 #10
0
        //public CustomerOrderEntryUIDM LoadData(NZString orderNo)
        //{

        //    CustomerOrderBIZ biz = new CustomerOrderBIZ();
        //    List<CustomerOrderViewDTO> listViewDTO = DTOUtility.ConvertDataTableToList<CustomerOrderViewDTO>(biz.LoadCustomerOrderEntry(orderNo, false));
        //    if (listViewDTO != null)
        //    {
        //        if (listViewDTO.Count > 0)
        //        {
        //            CustomerOrderEntryUIDM model = MapDTOToUIDM(listViewDTO[0]);
        //            model.DATA_VIEW = DTOUtility.ConvertListToDataTable(listViewDTO);

        //            //== Ensure that data has not modified.
        //            model.DATA_VIEW.AcceptChanges();

        //            return model;
        //        }
        //    }
        //    return new CustomerOrderEntryUIDM();
        //}

        #region SaveData
        public void Save(CustomerOrderEntryUIDM model, Common.eScreenMode Mode)
        {
            try
            {
                Common.CurrentDatabase.KeepConnection = true;
                Common.CurrentDatabase.BeginTransaction(IsolationLevel.Serializable);

                CustomerOrderBIZ biz = new CustomerOrderBIZ();

                #region Validate Data
                //== 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 dtNonDelete = model.DATA_VIEW.GetChanges(DataRowState.Unchanged | DataRowState.Added | DataRowState.Modified);
                List <CustomerOrderViewDTO> listData = DTOUtility.ConvertDataTableToList <CustomerOrderViewDTO>(dtNonDelete);

                #endregion


                DataTable dtData   = model.DATA_VIEW.Copy();
                DataTable dtAdd    = dtData.GetChanges(DataRowState.Added);
                DataTable dtModify = dtData.GetChanges(DataRowState.Modified);
                DataTable dtDelete = dtData.GetChanges(DataRowState.Deleted);

                //ORDER_DETAIL_NO,
                //ITEM_CD,
                //ITEM_CD_BTN,
                //PART_NO,
                //ITEM_DELIVERY_DATE,
                //OLD_ITEM_DELIVERY_DATE,
                //QTY,
                //OLD_QTY,
                //PRICE,
                //AMOUNT,
                //PRICE_THB,
                //AMOUNT_THB

                // แก้บั๊ก GetChange แล้ว Data ไม่ถูกต้อง
                dtData.AcceptChanges();
                if (dtModify != null && dtModify.Rows.Count > 0)
                {
                    for (int i = 0; i < dtModify.Rows.Count; i++)
                    {
                        for (int j = 0; j < dtData.Rows.Count; j++)
                        {
                            if (Convert.ToString(dtModify.Rows[i]["ORDER_DETAIL_NO"]) == Convert.ToString(dtData.Rows[j]["ORDER_DETAIL_NO"]))
                            {
                                dtModify.Rows[i]["ITEM_CD"]            = dtData.Rows[j]["ITEM_CD"];
                                dtModify.Rows[i]["PART_NO"]            = dtData.Rows[j]["PART_NO"];
                                dtModify.Rows[i]["ITEM_DELIVERY_DATE"] = dtData.Rows[j]["ITEM_DELIVERY_DATE"];
                                dtModify.Rows[i]["QTY"]        = dtData.Rows[j]["QTY"];
                                dtModify.Rows[i]["PRICE"]      = dtData.Rows[j]["PRICE"];
                                dtModify.Rows[i]["AMOUNT"]     = dtData.Rows[j]["AMOUNT"];
                                dtModify.Rows[i]["PRICE_THB"]  = dtData.Rows[j]["PRICE_THB"];
                                dtModify.Rows[i]["AMOUNT_THB"] = dtData.Rows[j]["AMOUNT_THB"];
                            }
                        }
                    }
                }
                List <CustomerOrderViewDTO> listAdd    = new List <CustomerOrderViewDTO>();
                List <CustomerOrderViewDTO> listUpdate = new List <CustomerOrderViewDTO>();
                List <CustomerOrderViewDTO> listDelete = new List <CustomerOrderViewDTO>();


                //มีการปรับให้ทำคำสั่งทีละ set ของ add , update , delete เลย
                //ที่เริ่มจาก delete ก่อนเพราะ consumption จะได้มีการเอาไปใช้สำหรับตัวที่ add ได้เลย ไม่ต้องค้างไว้ lot หน้า
                //== Delete process.
                if (dtDelete != null && dtDelete.Rows.Count > 0)
                {
                    listDelete = DTOUtility.ConvertDataTableToList <CustomerOrderViewDTO>(dtDelete);
                    for (int i = 0; i < listDelete.Count; i++)
                    {
                        AssignHeaderToDTO(model, listDelete[i], Mode);
                    }

                    biz.SaveCustomerOrder(Common.CurrentDatabase, null, null, listDelete, Mode);

                    // When detail row <= 0 then delete header row

                    if ((dtAdd == null || dtAdd.Rows.Count == 0) &&
                        (dtModify == null || dtModify.Rows.Count == 0) &&
                        biz.LoadCustomerOrderEntry(listDelete[0].ORDER_NO, false).Count <= 0)
                    {
                        biz.DeleteCustomerOrderHeader(Common.CurrentDatabase, listDelete);
                    }
                }

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

                    List <CustomerOrderViewDTO> listAddEachDetail = null;

                    NZString         runningNo        = null;
                    RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();

                    if (model.ORDER_NO.IsNull)
                    {
                        runningNo      = runningNumberBIZ.GetCompleteRunningNo((NZString)"CUSTOMER_ORDER_NO", (NZString)"TB_CUSTOMER_ORDERH_TR");
                        model.ORDER_NO = runningNo;
                        // Insert Header
                        AssignHeaderToDTO(model, listAdd[0], Mode);
                        biz.AddCustomerOrderHeader(Common.CurrentDatabase, listAdd[0]);
                    }
                    else
                    {
                        runningNo = model.ORDER_NO;
                    }


                    listAddEachDetail = new List <CustomerOrderViewDTO>();

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

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

                        //dto.TRANS_ID = runningNumberBIZ.GetCompleteRunningNo(DataDefine.TRANS_ID.ToNZString(), DataDefine.TRANSACTION_TABLE_NAME.ToNZString());

                        //add header ใส่ list
                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                        // Check all lines.


                        listAddEachDetail.Add(dto);
                    }

                    biz.SaveCustomerOrder(Common.CurrentDatabase, listAddEachDetail, null, null, Mode);
                }

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


                    List <CustomerOrderViewDTO> listUpdateDetail = new List <CustomerOrderViewDTO>();


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

                        CustomerOrderBIZ bizCustomer = new CustomerOrderBIZ();

                        CustomerOrderDDTO dtoDDTO = bizCustomer.LoadCustomerOrderDetail(dto.ORDER_NO.StrongValue, dto.ORDER_DETAIL_NO);

                        // 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;

                        //add header ใส่ list
                        listUpdateDetail.Add(dto);
                    }

                    biz.SaveCustomerOrder(Common.CurrentDatabase, null, listUpdateDetail, null, Mode);
                }


                //Update Header for Edit Case
                //if (Mode == Common.eScreenMode.EDIT && dtData != null && dtData.Rows.Count > 0)
                //{
                //    listUpdate = DTOUtility.ConvertDataTableToList<CustomerOrderViewDTO>(dtData);

                //    for (int i = 0; i < listUpdate.Count; i++)
                //    {
                //        CustomerOrderViewDTO 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.UpdateCustomerOrderHeader(Common.CurrentDatabase, dto);
                //    }
                //}

                Common.CurrentDatabase.Commit();
            }
            catch (Exception)
            {
                Common.CurrentDatabase.Rollback();
                throw;
            }
        }
コード例 #11
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);
        }
コード例 #12
0
        public void SaveInvoiceEntry(InvoiceEntryUIDM model, Common.eScreenMode Mode)
        {
            try
            {
                Common.CurrentDatabase.KeepConnection = true;
                Common.CurrentDatabase.BeginTransaction(IsolationLevel.Serializable);

                InvoiceBIZ biz = new InvoiceBIZ();

                #region Validate Data
                //== 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         dtNonDelete = model.DATA_VIEW.GetChanges(DataRowState.Unchanged | DataRowState.Added | DataRowState.Modified);
                List <InvoiceDTO> listData    = DTOUtility.ConvertDataTableToList <InvoiceDTO>(dtNonDelete);

                #endregion


                DataTable dtData   = model.DATA_VIEW;
                DataTable dtAdd    = dtData.GetChanges(DataRowState.Added);
                DataTable dtModify = dtData.GetChanges(DataRowState.Modified);
                DataTable dtDelete = dtData.GetChanges(DataRowState.Deleted);

                // แก้บั๊ก GetChange แล้ว Data ไม่ถูกต้อง
                if (dtModify != null && dtModify.Rows.Count > 0)
                {
                    for (int i = 0; i < dtModify.Rows.Count; i++)
                    {
                        for (int j = 0; j < dtData.Rows.Count; j++)
                        {
                            if (Convert.ToString(dtModify.Rows[i]["TRANS_ID"]) == Convert.ToString(dtData.Rows[j]["TRANS_ID"]))
                            {
                                dtModify.Rows[i]["PO_NO"]           = dtData.Rows[j]["PO_NO"];
                                dtModify.Rows[i]["ORDER_NO"]        = dtData.Rows[j]["ORDER_NO"];
                                dtModify.Rows[i]["ORDER_DETAIL_NO"] = dtData.Rows[j]["ORDER_DETAIL_NO"];
                                dtModify.Rows[i]["ITEM_CD"]         = dtData.Rows[j]["ITEM_CD"];
                                dtModify.Rows[i]["SHORT_NAME"]      = dtData.Rows[j]["SHORT_NAME"];
                                dtModify.Rows[i]["ITEM_DESC"]       = dtData.Rows[j]["ITEM_DESC"];
                                dtModify.Rows[i]["UNIT"]            = dtData.Rows[j]["UNIT"];
                                dtModify.Rows[i]["QTY"]             = dtData.Rows[j]["QTY"];
                                dtModify.Rows[i]["PRICE"]           = dtData.Rows[j]["PRICE"];
                                dtModify.Rows[i]["AMOUNT"]          = dtData.Rows[j]["AMOUNT"];
                            }
                        }
                    }
                }
                List <InvoiceDTO> listAdd    = new List <InvoiceDTO>();
                List <InvoiceDTO> listUpdate = new List <InvoiceDTO>();
                List <InvoiceDTO> listDelete = new List <InvoiceDTO>();


                //มีการปรับให้ทำคำสั่งทีละ set ของ add , update , delete เลย
                //ที่เริ่มจาก delete ก่อนเพราะ consumption จะได้มีการเอาไปใช้สำหรับตัวที่ add ได้เลย ไม่ต้องค้างไว้ lot หน้า
                //== Delete process.
                if (dtDelete != null && dtDelete.Rows.Count > 0)
                {
                    listDelete = DTOUtility.ConvertDataTableToList <InvoiceDTO>(dtDelete);
                    for (int i = 0; i < listDelete.Count; i++)
                    {
                        AssignHeaderToDTO(model, listDelete[i], Mode);
                    }

                    foreach (InvoiceDTO dto in listDelete)
                    {
                        biz.Delete(dto.TRANS_ID.StrongValue);
                    }
                }

                //== Insert process.
                if (dtAdd != null && dtAdd.Rows.Count > 0)
                {
                    NZString BillNo  = null;
                    NZString TransID = null;
                    listAdd = DTOUtility.ConvertDataTableToList <InvoiceDTO>(dtAdd);
                    if (!listAdd[0].TRANS_ID.IsNull && listAdd[0].TRANS_ID.StrongValue != "")
                    {
                        TransID = listAdd[0].TRANS_ID;
                    }

                    RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();

                    if (model.BILL_NO.IsNull)
                    {
                        BillNo        = runningNumberBIZ.GetCompleteRunningNo((NZString)"BILL_NO", (NZString)"BILL_NO");
                        model.BILL_NO = BillNo;
                    }
                    else
                    {
                        BillNo = model.BILL_NO;
                    }

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

                        if (dto.TRANS_ID.IsNull)
                        {
                            TransID      = runningNumberBIZ.GetCompleteRunningNo((NZString)"INVOICE_TRANS_ID", (NZString)"TRANS_ID");
                            dto.TRANS_ID = TransID;
                        }

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

                        //dto.TRANS_ID = runningNumberBIZ.GetCompleteRunningNo(DataDefine.TRANS_ID.ToNZString(), DataDefine.TRANSACTION_TABLE_NAME.ToNZString());

                        //add header ใส่ list
                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;
                    }

                    foreach (InvoiceDTO dto in listAdd)
                    {
                        biz.Add_New(dto);
                    }
                }

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

                    foreach (InvoiceDTO dto in listUpdate)
                    {
                        // 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;
                    }

                    foreach (InvoiceDTO dto in listUpdate)
                    {
                        biz.Update_WithOut_PK(dto);
                    }
                }

                Common.CurrentDatabase.Commit();
            }
            catch (Exception)
            {
                Common.CurrentDatabase.Rollback();
                throw;
            }
        }
コード例 #13
0
        private List <InventoryTransactionDTO> SplitBoxSize(ReceivingEntryUIDM receivingModel
                                                            , List <InventoryTransactionViewDTO> argReceivingList)
        {
            List <InventoryTransactionDTO> listSplitBox = new List <InventoryTransactionDTO>();

            RunningNumberBIZ runningNoBiz   = new RunningNumberBIZ();
            NZString         strLotNoPrefix = runningNoBiz.GenerateLotNoPrefix(new NZDateTime(null, receivingModel.RECEIVE_DATE.StrongValue));

            Dictionary <string, NZInt> dictLastRunningNo = new Dictionary <string, NZInt>();
            NZInt iLastRunningNo = new NZInt();

            InventoryTransactionDTO transDTO = null;

            foreach (InventoryTransactionViewDTO receivingDTO in argReceivingList)
            {
                iLastRunningNo = new NZInt(null, 0);

                //lot size == 0 ไม่ต้องแตก lot
                if ((receivingDTO.LOT_CONTROL_CLS != DataDefine.Convert2ClassCode(DataDefine.eLOT_CONTROL_CLS.Yes)) ||
                    (receivingDTO.LOT_SIZE.NVL(0) <= 0)
                    )
                {
                    transDTO = new InventoryTransactionDTO();

                    transDTO.ITEM_CD         = receivingDTO.ITEM_CD;
                    transDTO.LOT_NO          = receivingDTO.LOT_NO;
                    transDTO.PRICE           = receivingDTO.PRICE;
                    transDTO.QTY             = receivingDTO.QTY;
                    transDTO.EXTERNAL_LOT_NO = receivingDTO.EXTERNAL_LOT_NO;


                    listSplitBox.Add(transDTO);
                }
                else
                {
                    int iTotalBox = (int)Math.Ceiling(receivingDTO.QTY.NVL(0) / receivingDTO.LOT_SIZE.NVL(1));

                    if (dictLastRunningNo.ContainsKey(receivingDTO.ITEM_CD.StrongValue))
                    {
                        iLastRunningNo = dictLastRunningNo[receivingDTO.ITEM_CD.StrongValue];
                    }
                    else
                    {
                        iLastRunningNo = runningNoBiz.GetLastLotNoRunningBox(strLotNoPrefix, receivingModel.STORED_LOC, receivingDTO.ITEM_CD, new NZInt(null, 0));
                        dictLastRunningNo.Add(receivingDTO.ITEM_CD.StrongValue, iLastRunningNo);
                    }

                    NZDecimal dRemainQty = new NZDecimal(null, receivingDTO.QTY.StrongValue);
                    for (int iBox = 0; iBox < iTotalBox; iBox++)
                    {
                        transDTO = new InventoryTransactionDTO();

                        transDTO.ITEM_CD         = receivingDTO.ITEM_CD;
                        transDTO.LOT_NO          = GenerateLotNo(strLotNoPrefix, ref iLastRunningNo);
                        transDTO.PRICE           = receivingDTO.PRICE;
                        transDTO.EXTERNAL_LOT_NO = receivingDTO.EXTERNAL_LOT_NO;

                        if (dRemainQty.NVL(0) >= receivingDTO.LOT_SIZE.NVL(0))
                        {
                            transDTO.QTY     = new NZDecimal(null, receivingDTO.LOT_SIZE.StrongValue);
                            dRemainQty.Value = dRemainQty.StrongValue - transDTO.QTY.StrongValue;
                        }
                        else
                        {
                            transDTO.QTY = new NZDecimal(null, dRemainQty.StrongValue);
                        }



                        listSplitBox.Add(transDTO);
                    }
                }
            }

            return(listSplitBox);
        }
コード例 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <exception cref="!:EVOFramework.ValidateException"><c>ValidateException</c>.</exception>
        public void Save(ReceivingEntryUIDM model, Common.eScreenMode Mode)
        {
            try
            {
                Common.CurrentDatabase.KeepConnection = true;
                Common.CurrentDatabase.BeginTransaction(IsolationLevel.Serializable);

                InventoryBIZ      biz      = new InventoryBIZ();
                InventoryTransBIZ bizTrans = new InventoryTransBIZ();

                #region Validate Data
                //== Validate Header, contain: Receive Date, Stored Loc.
                ReceivingValidator receivingValidator = new ReceivingValidator();
                DealingValidator   locationValidator  = new DealingValidator();
                ItemValidator      itemValidator      = new ItemValidator();
                CommonBizValidator commonVal          = new CommonBizValidator();

                ValidateException.ThrowErrorItem(receivingValidator.CheckReceiveDate(model.RECEIVE_DATE));
                ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(model.STORED_LOC));
                ValidateException.ThrowErrorItem(locationValidator.CheckNotExistsLocationCode(model.STORED_LOC));
                // Check for Supplier Type
                ValidateException.ThrowErrorItem(receivingValidator.CheckForSupplierType(model.DEALING_NO));

                //== 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 dtNonDelete = model.DATA_VIEW.GetChanges(DataRowState.Unchanged | DataRowState.Added | DataRowState.Modified);
                List <InventoryTransactionViewDTO> listData = DTOUtility.ConvertDataTableToList <InventoryTransactionViewDTO>(dtNonDelete);

                //== Validate Item cannot duplicate on ITEM_CD and LOT_NO
                List <string> listCheckKeyDuplicate = new List <string>();
                for (int i = 0; i < listData.Count; i++)
                {
                    BusinessException err = itemValidator.CheckItemNotExist(listData[i].ITEM_CD);
                    if (err != null)
                    {
                        ValidateException.ThrowErrorItem(err.Error);
                    }
                    string strKey = listData[i].ITEM_CD.NVL(String.Empty)
                                    + listData[i].LOT_NO.NVL(String.Empty)
                                    + listData[i].EXTERNAL_LOT_NO.NVL(String.Empty)
                    ;

                    if (listCheckKeyDuplicate.Contains(strKey))
                    {
                        ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0096.ToString(), new object[] { listData[i].ITEM_CD.NVL(String.Empty), listData[i].LOT_NO.NVL(String.Empty), listData[i].EXTERNAL_LOT_NO.NVL(String.Empty) }));
                    }

                    listCheckKeyDuplicate.Add(strKey);
                }



                for (int i = 0; i < listData.Count; i++)
                {
                    InventoryTransactionViewDTO viewDTO = listData[i];

                    //== Check LotNo If item use lot control class.
                    ValidateException.ThrowErrorItem(commonVal.CheckInputLot(viewDTO.ITEM_CD, new NZString(), viewDTO.LOT_NO, false));
                }
                #endregion


                DataTable dtData = model.DATA_VIEW;

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

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


                //มีการปรับให้ทำคำสั่งทีละ set ของ add , update , delete เลย
                //ที่เริ่มจาก delete ก่อนเพราะ consumption จะได้มีการเอาไปใช้สำหรับตัวที่ add ได้เลย ไม่ต้องค้างไว้ lot หน้า
                //== Delete process.
                if (dtDelete != null && dtDelete.Rows.Count > 0)
                {
                    listDelete = DTOUtility.ConvertDataTableToList <InventoryTransactionDTO>(dtDelete);

                    List <InventoryTransactionDTO> listDeleteConsumption = null;
                    for (int i = 0; i < listDelete.Count; i++)
                    {
                        InventoryTransactionDTO dto = listDelete[i];

                        listDeleteConsumption = bizTrans.LoadConsumptionItemByRefNo(dto.REF_NO);
                        biz.ReceivingItems(Common.CurrentDatabase, null, null, listDeleteConsumption);
                    }
                }
                biz.ReceivingItems(Common.CurrentDatabase, null, null, listDelete);



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

                    //ถ้ากรณี receiving ให้แตกเป็น lot ย่อยตาม lot size ให้
                    if (model.RECEIVE_TYPE.StrongValue.Equals(DataDefine.eTRANS_TYPE_string.Receiving))
                    {
                        listAdd = SplitBoxSize(model, DTOUtility.ConvertDataTableToList <InventoryTransactionViewDTO>(dtAdd));
                    }
                    else
                    {
                        listAdd = DTOUtility.ConvertDataTableToList <InventoryTransactionDTO>(dtAdd);
                    }
                    NZString         runningNo        = null;
                    RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();

                    if (model.RECEIVE_NO.IsNull)
                    {
                        runningNo = runningNumberBIZ.GetCompleteRunningNo(DataDefine.RECEIVE_SLIP_NO.ToNZString(), DataDefine.TRANSACTION_TABLE_NAME.ToNZString());
                    }
                    else
                    {
                        runningNo = model.RECEIVE_NO;
                    }

                    List <InventoryTransactionDTO> listAddEachDetail = null;

                    for (int i = 0; i < listAdd.Count; i++)
                    {
                        listAddEachDetail = new List <InventoryTransactionDTO>();

                        InventoryTransactionDTO dto = listAdd[i];

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

                        //ถ้า 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));
                        //}

                        //dto.TRANS_ID = runningNumberBIZ.GetCompleteRunningNo(DataDefine.TRANS_ID.ToNZString(), DataDefine.TRANSACTION_TABLE_NAME.ToNZString());
                        dto.SLIP_NO     = runningNo;
                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                        // Check all lines.
                        receivingValidator.ValidateBeforeSaveAdd(dto);

                        //add header ใส่ list
                        listAddEachDetail.Add(dto);
                        #region Do Consumption if Item Process Type is SP and Receive Type is Receiving
                        if (model.RECEIVE_TYPE.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Receiving))
                        {
                            // load for item process type
                            ItemBIZ        bizItem = new ItemBIZ();
                            ItemProcessDTO dtoItem = bizItem.LoadItemProcess(dto.ITEM_CD);
                            //if (dtoItem.ORDER_PROCESS_CLS.StrongValue == DataDefine.ORDER_PROCESS_CLS_SUBCONTACT)
                            //{
                            //    List<InventoryTransactionDTO> dtoConsumptionTr = CreateConsumptionDTO(dto);
                            //    if (dtoConsumptionTr != null && dtoConsumptionTr.Count > 0)
                            //    {
                            //        listAddEachDetail.AddRange(dtoConsumptionTr);

                            //        //for (int j = 0; j < dtoConsumptionTr.Count; j++)
                            //        //{
                            //        //    listAddEachDetail.Add(dtoConsumptionTr[j]);
                            //        //}
                            //    }

                            //}
                        }
                        #endregion

                        biz.ReceivingItems(Common.CurrentDatabase, listAddEachDetail, null, null);
                    }
                }

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


                    List <InventoryTransactionDTO> listUpdateDetail      = null;
                    List <InventoryTransactionDTO> listAddConsumption    = null;
                    List <InventoryTransactionDTO> listDeleteConsumption = null;

                    for (int i = 0; i < listUpdate.Count; i++)
                    {
                        listUpdateDetail      = new List <InventoryTransactionDTO>();
                        listAddConsumption    = new List <InventoryTransactionDTO>();
                        listDeleteConsumption = new List <InventoryTransactionDTO>();

                        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;

                        // Check all lines.
                        receivingValidator.ValidateBeforeSaveAdd(dto);


                        //Clear consumption เดิมก่อน
                        listDeleteConsumption = bizTrans.LoadConsumptionItemByRefNo(dto.REF_NO);
                        biz.ReceivingItems(Common.CurrentDatabase, null, null, listDeleteConsumption);

                        //add header ใส่ list
                        listUpdateDetail.Add(dto);

                        #region Do Consumption if Item Process Type is SP
                        if (model.RECEIVE_TYPE.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Receiving))
                        {
                            // load for item process type
                            ItemBIZ        bizItem = new ItemBIZ();
                            ItemProcessDTO dtoItem = bizItem.LoadItemProcess(dto.ITEM_CD);
                            //if (dtoItem.ORDER_PROCESS_CLS.StrongValue == DataDefine.ORDER_PROCESS_CLS_SUBCONTACT)
                            //{
                            //    List<InventoryTransactionDTO> dtoConsumptionTr = CreateConsumptionDTO(dto);
                            //    if (dtoConsumptionTr != null && dtoConsumptionTr.Count > 0)
                            //    {
                            //        listAddConsumption.AddRange(dtoConsumptionTr);
                            //        //for (int j = 0; j < dtoConsumptionTr.Count; j++)
                            //        //{
                            //        //    listConsumption.Add(dtoConsumptionTr[j]);
                            //        //}
                            //    }
                            //}
                        }
                        #endregion


                        biz.ReceivingItems(Common.CurrentDatabase, listAddConsumption, listUpdateDetail, null);
                    }
                }


                //ปรับให้ไปสั่ง add delete แต่ละตัวไป เพราะว่ากรณีที่ตัด consumption
                //จะมีโอกาสข้าม lot  ถ้าคำนวณ โดยไม่ตัด mat ก่อน มันจะตัด lot เดิมตลอด
                //biz.ReceivingItems(Common.CurrentDatabase, listAdd, listUpdate, listDelete, listConsumption);
                //biz.ReceivingItems(Common.CurrentDatabase, null, listUpdate, null, null);



                //Update Header for Edit Case
                if (Mode == Common.eScreenMode.EDIT && 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);

                        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(Common.CurrentDatabase, dto);
                    }
                }

                Common.CurrentDatabase.Commit();
            }
            catch (Exception)
            {
                Common.CurrentDatabase.Rollback();
                throw;
            }
        }
コード例 #15
0
        internal void SaveAddIssue(IssueByItemUIDM uidmIssue)
        {
            List <InventoryTransactionDTO> dtoInvTrnsList = new List <InventoryTransactionDTO>();
            InventoryTransactionDTO        dtoInvTrns; // = new InventoryTransactionDTO();

            InventoryBIZ bizInv = new InventoryBIZ();

            //20100311 add by pichet
            CommonLib.Common.CurrentDatabase.KeepConnection = true;
            CommonLib.Common.CurrentDatabase.BeginTransaction(IsolationLevel.Serializable);
            //20100311 end add

            #region Add New Trans Record
            RunningNumberBIZ bizRunning    = new RunningNumberBIZ();
            NZString         TransID       = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR"));
            NZString         RefID         = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR"));
            NZString         ConsumptionID = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR"));

            // up
            dtoInvTrns            = new InventoryTransactionDTO();
            dtoInvTrns.TRANS_ID   = TransID;
            dtoInvTrns.REF_NO     = RefID;
            dtoInvTrns.ITEM_CD    = uidmIssue.ITEM_CD;
            dtoInvTrns.LOC_CD     = uidmIssue.FROM_LOC_CD;
            dtoInvTrns.LOT_NO     = uidmIssue.LOT_NO.StrongValue.Trim() == string.Empty ? new NZString() : uidmIssue.LOT_NO;
            dtoInvTrns.TRANS_DATE = uidmIssue.TRANS_DATE;
            if (dtoInvTrns.TRANS_DATE.IsNull)
            {
                dtoInvTrns.TRANS_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            }
            dtoInvTrns.TRANS_CLS        = DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Issue_Consumption).ToNZString();
            dtoInvTrns.IN_OUT_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.Out);
            dtoInvTrns.QTY                = uidmIssue.QTY;
            dtoInvTrns.REMARK             = uidmIssue.REMARK;
            dtoInvTrns.CRT_BY             = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoInvTrns.CRT_DATE.Value     = CommonLib.Common.GetDatabaseDateTime();
            dtoInvTrns.CRT_MACHINE        = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoInvTrns.UPD_BY             = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoInvTrns.UPD_DATE.Value     = CommonLib.Common.GetDatabaseDateTime();
            dtoInvTrns.UPD_MACHINE        = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoInvTrns.REF_SLIP_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eREF_SLIP_CLS.Issue);
            dtoInvTrns.REF_SLIP_NO        = uidmIssue.REF_SLIP_NO;
            dtoInvTrns.REF_SLIP_NO2       = uidmIssue.REF_SLIP_NO2;
            dtoInvTrns.TRAN_SUB_CLS       = uidmIssue.TRAN_SUB_CLS;
            dtoInvTrns.FOR_CUSTOMER       = uidmIssue.FOR_CUSTOMER;
            dtoInvTrns.FOR_MACHINE        = uidmIssue.FOR_MACHINE;
            dtoInvTrns.TRANS_CLS          = DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Issue_Consumption).ToNZString();
            dtoInvTrns.SCREEN_TYPE        = DataDefine.ScreenType.IssueConsumption.ToNZString();

            dtoInvTrnsList.Add(dtoInvTrns);

            // down
            dtoInvTrns            = new InventoryTransactionDTO();
            dtoInvTrns.TRANS_ID   = RefID;
            dtoInvTrns.REF_NO     = TransID;
            dtoInvTrns.ITEM_CD    = uidmIssue.ITEM_CD;
            dtoInvTrns.LOC_CD     = uidmIssue.TO_LOC_CD;
            dtoInvTrns.LOT_NO     = uidmIssue.LOT_NO.StrongValue.Trim() == string.Empty ? new NZString() : uidmIssue.LOT_NO;
            dtoInvTrns.TRANS_DATE = uidmIssue.TRANS_DATE;
            if (dtoInvTrns.TRANS_DATE.IsNull)
            {
                dtoInvTrns.TRANS_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            }
            dtoInvTrns.TRANS_CLS        = DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Issue_Consumption).ToNZString();
            dtoInvTrns.IN_OUT_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.In);
            dtoInvTrns.QTY                = uidmIssue.QTY;
            dtoInvTrns.REMARK             = uidmIssue.REMARK;
            dtoInvTrns.CRT_BY             = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoInvTrns.CRT_DATE.Value     = CommonLib.Common.GetDatabaseDateTime();
            dtoInvTrns.CRT_MACHINE        = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoInvTrns.UPD_BY             = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoInvTrns.UPD_DATE.Value     = CommonLib.Common.GetDatabaseDateTime();
            dtoInvTrns.UPD_MACHINE        = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoInvTrns.REF_SLIP_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eREF_SLIP_CLS.Issue);
            dtoInvTrns.REF_SLIP_NO        = uidmIssue.REF_SLIP_NO;
            dtoInvTrns.REF_SLIP_NO2       = uidmIssue.REF_SLIP_NO2;
            dtoInvTrns.TRAN_SUB_CLS       = uidmIssue.TRAN_SUB_CLS;
            dtoInvTrns.FOR_CUSTOMER       = uidmIssue.FOR_CUSTOMER;
            dtoInvTrns.FOR_MACHINE        = uidmIssue.FOR_MACHINE;
            dtoInvTrns.SCREEN_TYPE        = DataDefine.ScreenType.IssueConsumption.ToNZString();
            dtoInvTrnsList.Add(dtoInvTrns);

            // consumption
            dtoInvTrns            = new InventoryTransactionDTO();
            dtoInvTrns.TRANS_ID   = ConsumptionID;
            dtoInvTrns.REF_NO     = TransID;
            dtoInvTrns.ITEM_CD    = uidmIssue.ITEM_CD;
            dtoInvTrns.LOC_CD     = uidmIssue.TO_LOC_CD;
            dtoInvTrns.LOT_NO     = uidmIssue.LOT_NO.StrongValue.Trim() == string.Empty ? new NZString() : uidmIssue.LOT_NO;
            dtoInvTrns.TRANS_DATE = uidmIssue.TRANS_DATE;
            if (dtoInvTrns.TRANS_DATE.IsNull)
            {
                dtoInvTrns.TRANS_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            }
            dtoInvTrns.TRANS_CLS        = DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Consumption).ToNZString();
            dtoInvTrns.IN_OUT_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.Out);
            dtoInvTrns.QTY                = uidmIssue.QTY;
            dtoInvTrns.REMARK             = uidmIssue.REMARK;
            dtoInvTrns.CRT_BY             = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoInvTrns.CRT_DATE.Value     = CommonLib.Common.GetDatabaseDateTime();
            dtoInvTrns.CRT_MACHINE        = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoInvTrns.UPD_BY             = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoInvTrns.UPD_DATE.Value     = CommonLib.Common.GetDatabaseDateTime();
            dtoInvTrns.UPD_MACHINE        = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoInvTrns.REF_SLIP_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eREF_SLIP_CLS.Issue);
            dtoInvTrns.REF_SLIP_NO        = uidmIssue.REF_SLIP_NO;
            dtoInvTrns.REF_SLIP_NO2       = uidmIssue.REF_SLIP_NO2;
            //dtoInvTrns.TRAN_SUB_CLS = uidmIssue.TRAN_SUB_CLS;
            dtoInvTrns.FOR_CUSTOMER = uidmIssue.FOR_CUSTOMER;
            dtoInvTrns.FOR_MACHINE  = uidmIssue.FOR_MACHINE;
            dtoInvTrns.SCREEN_TYPE  = DataDefine.ScreenType.IssueConsumption.ToNZString();

            dtoInvTrnsList.Add(dtoInvTrns);

            #endregion

            try
            {
                // REWRITE UPDATE STOCK ONHAND METHOD
                // CHANGE TO USE THE COMMON FUNCTION
                bizInv.AddInventoryTransactions(CommonLib.Common.CurrentDatabase, dtoInvTrnsList, false);
                CommonLib.Common.CurrentDatabase.Commit();
            }
            catch (Exception ex)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }
            finally
            {
                if (CommonLib.Common.CurrentDatabase.DBConnectionState == ConnectionState.Open)
                {
                    CommonLib.Common.CurrentDatabase.Close();
                }
            }
        }
コード例 #16
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();
                }
            }
        }
コード例 #17
0
        internal NZString SaveShipmentEntry(ShipmentEntryUIDM model, Common.eScreenMode Mode, DataTable OldOrder, DataTable NewOrder, DataTable OldLot, DataTable NewLot)
        {
            Database db     = Common.CurrentDatabase.CreateNewDatabase();
            NZString SlipNo = new NZString();


            try
            {
                db.KeepConnection = true;
                db.BeginTransaction(IsolationLevel.Serializable);

                //bizShipment.AddShipmentEntry(dtoInvTrnsList);
                ShipmentBIZ         bizShipment = new ShipmentBIZ();
                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 dtAdd    = new DataTable();
                DataTable dtModify = new DataTable();
                DataTable dtDelete = new DataTable();

                if (Mode == Common.eScreenMode.ADD || OldOrder.Rows.Count <= 0)
                {
                    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();

                    // Manage for Update and Delete
                    for (int i = 0; i < OldOrder.Rows.Count; i++)
                    {
                        string  OrderDetailNo      = Convert.ToString(OldOrder.Rows[i]["ORDER_DETAIL_NO"]);
                        decimal ShipQTY            = Convert.ToDecimal(OldOrder.Rows[i]["SHIP_QTY"]);
                        string  ItemCd             = Convert.ToString(OldOrder.Rows[i]["ITEM_CD"]);
                        bool    found_order_detail = false;
                        for (int j = 0; j < NewOrder.Rows.Count; j++)
                        {
                            if (Convert.ToString(NewOrder.Rows[j]["ORDER_DETAIL_NO"]) == OrderDetailNo &&
                                Convert.ToString(NewOrder.Rows[j]["ITEM_CD"]) == ItemCd &&
                                Convert.ToDecimal(NewOrder.Rows[j]["SHIP_QTY"]) != ShipQTY)
                            {
                                found_order_detail = true;
                                // Delete Old
                                for (int k = 0; k < OldLot.Rows.Count; k++)
                                {
                                    if (Convert.ToString(OldLot.Rows[k]["REF_SLIP_NO"]) == OrderDetailNo &&
                                        Convert.ToString(OldLot.Rows[k]["ITEM_CD"]) == ItemCd)
                                    {
                                        DataRow row = dtDelete.NewRow();
                                        row["TRANS_ID"]    = OldLot.Rows[k]["TRANS_ID"];
                                        row["ITEM_CD"]     = OldLot.Rows[k]["ITEM_CD"];
                                        row["LOC_CD"]      = OldLot.Rows[k]["LOC_CD"];
                                        row["TRANS_DATE"]  = OldLot.Rows[k]["TRANS_DATE"];
                                        row["TRANS_CLS"]   = OldLot.Rows[k]["TRANS_CLS"];
                                        row["IN_OUT_CLS"]  = OldLot.Rows[k]["IN_OUT_CLS"];
                                        row["QTY"]         = OldLot.Rows[k]["QTY"];
                                        row["REF_SLIP_NO"] = OrderDetailNo;
                                        dtDelete.Rows.Add(row);
                                    }
                                }
                                //bizShipment.AddShipmentEntry(db, null, null, DTOUtility.ConvertDataTableToList<InventoryTransactionDTO>(dtDelete));

                                // Add New
                                for (int l = 0; l < NewLot.Rows.Count; l++)
                                {
                                    if (Convert.ToString(NewLot.Rows[l]["REF_SLIP_NO"]) == OrderDetailNo &&
                                        Convert.ToString(NewLot.Rows[l]["ITEM_CD"]) == ItemCd)
                                    {
                                        dtAdd.ImportRow(NewLot.Rows[l]);
                                    }
                                }
                            }
                            else if (Convert.ToString(NewOrder.Rows[j]["ORDER_DETAIL_NO"]) == OrderDetailNo &&
                                     Convert.ToString(NewOrder.Rows[j]["ITEM_CD"]) == ItemCd &&
                                     Convert.ToDecimal(NewOrder.Rows[j]["SHIP_QTY"]) == ShipQTY)
                            {
                                found_order_detail = true;
                                bool diff_pack = false;

                                for (int x = 0; x < NewLot.Rows.Count; x++)
                                {
                                    bool   check_same = false;
                                    string pack_no    = Convert.ToString(NewLot.Rows[x]["PACK_NO"]);
                                    string lot_no     = Convert.ToString(NewLot.Rows[x]["LOT_NO"]);

                                    for (int y = 0; y < OldLot.Rows.Count; y++)
                                    {
                                        if (Convert.ToString(OldLot.Rows[y]["REF_SLIP_NO"]) == OrderDetailNo &&
                                            Convert.ToString(OldLot.Rows[y]["ITEM_CD"]) == ItemCd &&
                                            Convert.ToString(OldLot.Rows[y]["PACK_NO"]) == pack_no &&
                                            Convert.ToString(OldLot.Rows[y]["LOT_NO"]) == lot_no)
                                        {
                                            check_same = true;
                                            continue;
                                        }
                                    }

                                    if (!check_same)
                                    {
                                        diff_pack = !check_same;
                                        continue;
                                    }
                                }

                                if (diff_pack)
                                {
                                    // Delete Old
                                    for (int k = 0; k < OldLot.Rows.Count; k++)
                                    {
                                        if (Convert.ToString(OldLot.Rows[k]["REF_SLIP_NO"]) == OrderDetailNo &&
                                            Convert.ToString(OldLot.Rows[k]["ITEM_CD"]) == ItemCd)
                                        {
                                            DataRow row = dtDelete.NewRow();
                                            row["TRANS_ID"]    = OldLot.Rows[k]["TRANS_ID"];
                                            row["ITEM_CD"]     = OldLot.Rows[k]["ITEM_CD"];
                                            row["LOC_CD"]      = OldLot.Rows[k]["LOC_CD"];
                                            row["TRANS_DATE"]  = OldLot.Rows[k]["TRANS_DATE"];
                                            row["TRANS_CLS"]   = OldLot.Rows[k]["TRANS_CLS"];
                                            row["IN_OUT_CLS"]  = OldLot.Rows[k]["IN_OUT_CLS"];
                                            row["QTY"]         = OldLot.Rows[k]["QTY"];
                                            row["REF_SLIP_NO"] = OrderDetailNo;
                                            dtDelete.Rows.Add(row);
                                        }
                                    }
                                    //bizShipment.AddShipmentEntry(db, null, null, DTOUtility.ConvertDataTableToList<InventoryTransactionDTO>(dtDelete));

                                    // Add New
                                    for (int l = 0; l < NewLot.Rows.Count; l++)
                                    {
                                        if (Convert.ToString(NewLot.Rows[l]["REF_SLIP_NO"]) == OrderDetailNo &&
                                            Convert.ToString(NewLot.Rows[l]["ITEM_CD"]) == ItemCd)
                                        {
                                            dtAdd.ImportRow(NewLot.Rows[l]);
                                        }
                                    }
                                }
                            }

                            // In  update have remove order
                            if (j == NewOrder.Rows.Count - 1 && !found_order_detail)
                            {
                                for (int k = 0; k < OldLot.Rows.Count; k++)
                                {
                                    if (Convert.ToString(OldLot.Rows[k]["REF_SLIP_NO"]) == OrderDetailNo &&
                                        Convert.ToString(OldLot.Rows[k]["ITEM_CD"]) == ItemCd)
                                    {
                                        DataRow row = dtDelete.NewRow();
                                        row["TRANS_ID"]    = OldLot.Rows[k]["TRANS_ID"];
                                        row["ITEM_CD"]     = OldLot.Rows[k]["ITEM_CD"];
                                        row["LOC_CD"]      = OldLot.Rows[k]["LOC_CD"];
                                        row["TRANS_DATE"]  = OldLot.Rows[k]["TRANS_DATE"];
                                        row["TRANS_CLS"]   = OldLot.Rows[k]["TRANS_CLS"];
                                        row["IN_OUT_CLS"]  = OldLot.Rows[k]["IN_OUT_CLS"];
                                        row["QTY"]         = OldLot.Rows[k]["QTY"];
                                        row["REF_SLIP_NO"] = OrderDetailNo;
                                        dtDelete.Rows.Add(row);
                                    }
                                }
                            }
                        }
                    }

                    // Manage for check add new order on update mode
                    for (int i = 0; i < NewOrder.Rows.Count; i++)
                    {
                        string OrderDetailNo      = Convert.ToString(NewOrder.Rows[i]["ORDER_DETAIL_NO"]);
                        string ItemCd             = Convert.ToString(NewOrder.Rows[i]["ITEM_CD"]);
                        bool   found_order_detail = false;
                        for (int j = 0; j < OldOrder.Rows.Count; j++)
                        {
                            if (Convert.ToString(OldOrder.Rows[j]["ORDER_DETAIL_NO"]) == OrderDetailNo &&
                                Convert.ToString(OldOrder.Rows[j]["ITEM_CD"]) == ItemCd)
                            {
                                found_order_detail = true;
                            }

                            // Not found old order in new order then add new order
                            if (j == OldOrder.Rows.Count - 1 && !found_order_detail)
                            {
                                for (int l = 0; l < NewLot.Rows.Count; l++)
                                {
                                    if (Convert.ToString(NewLot.Rows[l]["REF_SLIP_NO"]) == OrderDetailNo &&
                                        Convert.ToString(NewLot.Rows[l]["ITEM_CD"]) == ItemCd)
                                    {
                                        dtAdd.ImportRow(NewLot.Rows[l]);
                                    }
                                }
                            }
                        }
                    }
                }

                InventoryBIZ biz = new InventoryBIZ();

                List <InventoryTransactionDTO> listAdd    = null;
                List <InventoryTransactionDTO> listUpdate = null;
                List <InventoryTransactionDTO> listDelete = 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)"DELIVERY_SLIP_NO", (NZString)"TB_INV_TRANS_TR");
                    }
                    else
                    {
                        runningNo_SLIP_NO = model.SLIP_NO;
                    }

                    SlipNo = runningNo_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);

                        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);

                        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;
                    }
                }


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

                bizShipment.AddShipmentEntry(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);

                            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]);
                        }

                        SlipNo = listUpdate[0].SLIP_NO;
                    }

                    //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();

                return(SlipNo);
            }
            catch
            {
                db.Rollback();
                throw;
            }
            finally
            {
                if (db.DBConnectionState == ConnectionState.Open)
                {
                    db.Close();
                }
            }
        }
コード例 #18
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);
        }
コード例 #19
0
        public int AddIssueConsumption(List <InventoryTransactionDTO> dtoInvTrnsList)
        {
            try
            {
                #region Validate Mandatory
                IssueEntryValidator      valIssue = new IssueEntryValidator();
                InventoryOnhandValidator valINV   = new InventoryOnhandValidator();

                ErrorItem errorItem = null;

                if (dtoInvTrnsList.Count > 0)
                {
                    errorItem = valIssue.CheckIssueDate(dtoInvTrnsList[0].TRANS_DATE);
                    if (null != errorItem)
                    {
                        ValidateException.ThrowErrorItem(errorItem);
                    }
                }


                // CHECK EXIST INVENTORY ONHAND
                //for (int i = 0; i < dtoInvTrnsList.Count; i++)
                //{


                //    if (dtoInvTrnsList[i].IN_OUT_CLS.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.Out))
                //    {
                //        // NZString YearMonth = new NZString(null, dtoInvTrnsList[i].TRANS_DATE.StrongValue.ToString("yyyyMM"));

                //        errorItem = valINV.CheckOnhandQty(dtoInvTrnsList[i].IN_OUT_CLS.StrongValue, dtoInvTrnsList[i].QTY, dtoInvTrnsList[i].ITEM_CD,
                //                                            dtoInvTrnsList[i].LOC_CD, dtoInvTrnsList[i].LOT_NO);
                //        if (null != errorItem) ValidateException.ThrowErrorItem(errorItem);
                //    }


                //}

                #endregion

                // lock transaction
                TransactionLockDAO daoTrans = new TransactionLockDAO(CommonLib.Common.CurrentDatabase);
                TransactionLockDTO dtoTrans = new TransactionLockDTO();
                NZString           key1     = new NZString(null, "ISSUE_TRANS_ID");
                NZString           key2     = new NZString(null, "INV_TRANS_TR");
                if (!daoTrans.Exist(null, key1, key2))
                {
                    dtoTrans.KEY1           = key1;
                    dtoTrans.KEY2           = key2;
                    dtoTrans.CRT_BY         = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dtoTrans.CRT_DATE.Value = DateTime.Now;
                    dtoTrans.CRT_MACHINE    = CommonLib.Common.CurrentUserInfomation.Machine;
                    daoTrans.AddNew(null, dtoTrans);
                }
                // end of lock transaction


                InventoryTransactionDAO InventoryTransaction = new InventoryTransactionDAO(CommonLib.Common.CurrentDatabase);

                RunningNumberBIZ bizRunning    = new RunningNumberBIZ();
                NZString         TransID       = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR"));
                NZString         RefID         = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR"));
                NZString         ConsumptionID = bizRunning.GetCompleteRunningNo(new NZString(null, "TRAN_ID"), new NZString(null, "TB_INV_TRANS_TR"));
                // if load success then lock transaction
                daoTrans.SelectWithKeys(null, key1, key2);
                // end of lock transaction

                dtoInvTrnsList[0].TRANS_ID = TransID;
                dtoInvTrnsList[0].REF_NO   = RefID;
                dtoInvTrnsList[1].TRANS_ID = RefID;
                dtoInvTrnsList[1].REF_NO   = TransID;
                dtoInvTrnsList[2].TRANS_ID = ConsumptionID;
                dtoInvTrnsList[2].REF_NO   = RefID;
                for (int i = 0; i < dtoInvTrnsList.Count; i++)
                {
                    InventoryTransaction.AddNew(null, dtoInvTrnsList[i]);
                }

                daoTrans.DeleteWithKeys(null, key1, key2);
                CommonLib.Common.CurrentDatabase.Commit();
            }
            catch (ValidateException)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }
            catch (BusinessException)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }
            catch (Exception)
            {
                CommonLib.Common.CurrentDatabase.Rollback();
                throw;
            }
            finally
            {
                if (CommonLib.Common.CurrentDatabase.DBConnectionState == ConnectionState.Open)
                {
                    CommonLib.Common.CurrentDatabase.Close();
                }
            }
            return(1);
        }