Example #1
0
        private bool LoadItemIntoRow(int row, NZString ITEM_CD)
        {
            ItemValidator itemValidator = new ItemValidator();

            if (ITEM_CD != null)
            {
                BusinessException error = itemValidator.CheckItemNotExist(ITEM_CD);
                if (error != null)
                {
                    shtView.Cells[row, (int)eColView.ITEM_DESC].Value     = null;
                    shtView.Cells[row, (int)eColView.ORDER_UM_CLS].Value  = null;
                    shtView.Cells[row, (int)eColView.INV_UM_CLS].Value    = null;
                    shtView.Cells[row, (int)eColView.ORDER_UM_RATE].Value = null;
                    shtView.Cells[row, (int)eColView.INV_UM_RATE].Value   = null;
                    return(false);
                }

                ItemBIZ itemBIZ = new ItemBIZ();
                ItemDTO itemDTO = itemBIZ.LoadItem(ITEM_CD);
                shtView.Cells[row, (int)eColView.ITEM_CD].Value   = itemDTO.ITEM_CD.Value;
                shtView.Cells[row, (int)eColView.ITEM_DESC].Value = itemDTO.ITEM_DESC.Value;
                //shtView.Cells[row, (int)eColView.ORDER_UM_CLS].Value = itemDTO.ORDER_UM_CLS.Value;
                //shtView.Cells[row, (int)eColView.INV_UM_CLS].Value = itemDTO.INV_UM_CLS.Value;
                //shtView.Cells[row, (int)eColView.ORDER_UM_RATE].Value = itemDTO.ORDER_UM_RATE.Value;
                //shtView.Cells[row, (int)eColView.INV_UM_RATE].Value = itemDTO.INV_UM_RATE.Value;

                //shtView.Cells[row, (int)eColView.LOT_CONTROL_CLS].Value = itemDTO.LOT_CONTROL_CLS.Value;



                //if (itemDTO.LOT_CONTROL_CLS == 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)
                //    {
                //        RunningNumberBIZ runningNoBiz = new RunningNumberBIZ();

                //        NZString strLotNoPrefix = runningNoBiz.GenerateLotNoPrefix(new NZDateTime(null, dtReceiveDate.Value));
                //        NZInt iLastRunningNo = runningNoBiz.GetLastLotNoRunningBox(strLotNoPrefix, new NZString(cboStoredLoc, (string)cboStoredLoc.SelectedValue), itemDTO.ITEM_CD, new NZInt(null, 0));

                //        ReceivingEntryController rcvController = new ReceivingEntryController();
                //        NZString strLotNo = rcvController.GenerateLotNo(strLotNoPrefix, ref iLastRunningNo);
                //        shtView.Cells[row, (int)eColView.LOT_NO].Value = strLotNo.StrongValue;

                //    }
                //}
                //else
                //{
                //    shtView.Cells[row, (int)eColView.LOT_NO].Value = null;
                //}

                ItemProcessDTO processDTO = itemBIZ.LoadItemProcess(ITEM_CD);
                //shtView.Cells[row, (int)eColView.LOT_SIZE].Value = processDTO.LOT_SIZE.NVL(0);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Insert new record into database.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int AddNew(Database database, ItemProcessDTO data)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            sb.AppendLine(" INSERT INTO " + data.TableName + "(");
            sb.AppendLine("  " + ItemProcessDTO.eColumns.CRT_BY);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.CRT_DATE);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.CRT_MACHINE);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_BY);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_DATE);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_MACHINE);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.ITEM_CD);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.ITEM_SEQ);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.PROCESS_CD);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.WEIGHT);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.PRODUCTION_LEADTIME);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.QTY_PER_DAY);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.SUPPLIER_CD);
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.OLD_DATA);
            sb.AppendLine(") VALUES(");
            sb.AppendLine("   @CRT_BY");
            sb.AppendLine("   ,GETDATE()");
            sb.AppendLine("   ,@CRT_MACHINE");
            sb.AppendLine("   ,@UPD_BY");
            sb.AppendLine("   ,GETDATE()");
            sb.AppendLine("   ,@UPD_MACHINE");
            sb.AppendLine("   ,@ITEM_CD");
            sb.AppendLine("   ,@ITEM_SEQ");
            sb.AppendLine("   ,@PROCESS_CD");
            sb.AppendLine("   ,@WEIGHT");
            sb.AppendLine("   ,@PRODUCTION_LEADTIME");
            sb.AppendLine("   ,@QTY_PER_DAY");
            sb.AppendLine("   ,@SUPPLIER_CD");
            sb.AppendLine("   ,@OLD_DATA");
            sb.AppendLine(" )");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters
            req.Parameters.Add("@CRT_BY", DataType.NVarChar, data.CRT_BY.Value);
            req.Parameters.Add("@CRT_MACHINE", DataType.NVarChar, data.CRT_MACHINE.Value);
            req.Parameters.Add("@UPD_BY", DataType.NVarChar, data.UPD_BY.Value);
            req.Parameters.Add("@UPD_MACHINE", DataType.NVarChar, data.UPD_MACHINE.Value);
            req.Parameters.Add("@ITEM_CD", DataType.Default, data.ITEM_CD.StrongValue);
            req.Parameters.Add("@ITEM_SEQ", DataType.Default, data.ITEM_SEQ.StrongValue);
            req.Parameters.Add("@PROCESS_CD", DataType.NVarChar, data.PROCESS_CD.Value);
            req.Parameters.Add("@WEIGHT", DataType.Number, data.WEIGHT.Value);
            req.Parameters.Add("@PRODUCTION_LEADTIME", DataType.Default, data.PRODUCTION_LEADTIME.Value);
            req.Parameters.Add("@QTY_PER_DAY", DataType.Number, data.QTY_PER_DAY.Value);
            req.Parameters.Add("@SUPPLIER_CD", DataType.NVarChar, data.SUPPLIER_CD.Value);
            req.Parameters.Add("@OLD_DATA", DataType.Default, data.OLD_DATA.Value);
            #endregion

            return(db.ExecuteNonQuery(req));
        }
Example #3
0
        /// <summary>
        /// Check exist before manipulate data. If found record will update data. Otherwise insert new data.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int AddNewOrUpdate(Database database, ItemProcessDTO data)
        {
            Database db = UseDatabase(database);

            if (Exist(database, data.ITEM_CD, data.ITEM_SEQ))
            {
                return(UpdateWithoutPK(db, data));
            }

            return(AddNew(db, data));
        }
Example #4
0
        public void ValidateBeforeSaveNew(ItemDTO dtoItem, ItemProcessDTO dtoItemProcess)
        {
            ValidateException validateException = new ValidateException();

            //ErrorItem errorItem = null;

            #region mandatory check
            //errorItem = CheckEmptyItemCode(dtoItem.ITEM_CD);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyItemDesc(dtoItem.ITEM_DESC);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //validateException.ThrowIfHasError();

            //errorItem = CheckEmptyItemType(dtoItem.ITEM_CLS);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyLotControlType(dtoItem.LOT_CONTROL_CLS);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyStoreLoc(dtoItemProcess.STORE_LOC_CD);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyInventoryUM(dtoItem.INV_UM_CLS);
            //if (null != errorItem) ValidateException.ThrowErrorItem(errorItem);
            //errorItem = CheckEmptyOrderUM(dtoItem.ORDER_UM_CLS);
            //if (null != errorItem) ValidateException.ThrowErrorItem(errorItem);
            //errorItem = CheckEmptyOrderUMRate(dtoItem.ORDER_UM_RATE);
            //if (null != errorItem) ValidateException.ThrowErrorItem(errorItem);

            //errorItem = CheckEmptyUnitConvert(dtoItem.INV_UM_RATE, dtoItem.ORDER_UM_RATE);
            //if (null != errorItem) ValidateException.ThrowErrorItem(errorItem);

            //errorItem = CheckEmptyOrderProcess(dtoItemProcess.ORDER_PROCESS_CLS);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyConsumptionClass(dtoItemProcess.CONSUMTION_CLS);
            //if (null != errorItem) ValidateException.ThrowErrorItem(errorItem);

            BusinessException businessException = CheckItemExist(dtoItem.ITEM_CD);
            if (businessException != null)
            {
                throw businessException;
            }

            #endregion
        }
Example #5
0
        public ItemProcessDTO LoadWeightByItemProcessCount(Database database, ItemProcessDTO data, NZInt processCount)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            string tableName = EVOFramework.Data.DTOUtility.ReadTableName(typeof(ItemProcessDTO));
            sb.AppendLine(" select top(1) *  ");
            sb.AppendLine(" from ( ");
            sb.AppendLine("     SELECT TOP(@ProcessCount)");
            sb.AppendLine("     " + ItemProcessDTO.eColumns.CRT_BY);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.CRT_DATE);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.CRT_MACHINE);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.UPD_BY);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.UPD_DATE);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.UPD_MACHINE);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.ITEM_CD);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.ITEM_SEQ);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.PROCESS_CD);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.WEIGHT);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.PRODUCTION_LEADTIME);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.QTY_PER_DAY);
            sb.AppendLine("     ," + ItemProcessDTO.eColumns.SUPPLIER_CD);
            sb.AppendLine("     FROM " + tableName);
            sb.AppendLine("     WHERE ");
            sb.AppendLine("     " + ItemProcessDTO.eColumns.ITEM_CD + "=@ITEM_CD");
            sb.AppendLine("     AND " + ItemProcessDTO.eColumns.PROCESS_CD + "=@PROCESS_CD");
            sb.AppendLine("     ORDER BY " + ItemProcessDTO.eColumns.ITEM_SEQ + " ASC ");
            sb.AppendLine(" ) a ");
            sb.AppendLine(" ORDER BY " + ItemProcessDTO.eColumns.ITEM_SEQ + " DESC ");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters

            req.Parameters.Add("@ProcessCount", DataType.Int32, processCount.Value);
            req.Parameters.Add("@ITEM_CD", DataType.NVarChar, data.ITEM_CD.Value);
            req.Parameters.Add("@PROCESS_CD", DataType.NVarChar, data.PROCESS_CD.Value);
            #endregion

            List <ItemProcessDTO> list = db.ExecuteForList <ItemProcessDTO>(req);

            if (list != null && list.Count > 0)
            {
                return(list[0]);
            }

            return(null);
        }
Example #6
0
        public ItemWeightDTO ConvertKGtoPCS(NZString MasterNo, NZString ProcessNo, NZDecimal QtyKG, NZInt processCount)
        {
            ItemWeightDTO weightDTO = new ItemWeightDTO();


            NZDecimal decQtyPCS = null;
            //ถ้า convert จาก KG เป็น PCS จะ ใช้น้ำหนักตาม Process
            ItemProcessDAO dao = new ItemProcessDAO();

            ItemProcessDTO itemProcess = new ItemProcessDTO();

            itemProcess.ITEM_CD    = MasterNo;
            itemProcess.PROCESS_CD = ProcessNo;
            itemProcess            = dao.LoadWeightByItemProcessCount(CommonLib.Common.CurrentDatabase, itemProcess, new NZInt(null, (processCount.NVL(0) <= 1 ? 1 : processCount.Value)));

            if (itemProcess != null)
            {
                weightDTO.ItemCD    = MasterNo;
                weightDTO.ProcessCD = ProcessNo;
                weightDTO.QtyKG     = QtyKG;

                decimal decQtyKG = QtyKG.NVL(0);


                if (itemProcess.WEIGHT.NVL(0) == 0)
                {
                    decQtyPCS = null;
                }
                else
                {
                    decQtyPCS = new NZDecimal(null, Math.Round(QtyKG / itemProcess.WEIGHT * 1000, MidpointRounding.AwayFromZero));
                }

                if (decQtyPCS != null && decQtyPCS.NVL(0) > 10000000)
                {
                    EVOFramework.ErrorItem errorItem = null;

                    errorItem = new EVOFramework.ErrorItem(QtyKG.Owner, Rubik.TKPMessages.eValidate.VLM0184.ToString());

                    EVOFramework.ValidateException.ThrowErrorItem(errorItem);
                }

                weightDTO.QtyPCS = decQtyPCS;
            }

            return(weightDTO);
        }
Example #7
0
        public string GetItemDescription(NZString ItemCD)
        {
            ItemBIZ bizItem = new ItemBIZ();
            ItemDTO dtoItem = bizItem.LoadItem(ItemCD);

            ItemProcessDTO dtoItemProcess = bizItem.LoadItemProcess(ItemCD);

            if (dtoItem == null || dtoItem.SHORT_NAME.IsNull)
            {
                return(string.Empty);
            }

            SelectedItemData        = dtoItem;
            SelectedItemProcessData = dtoItemProcess;

            return(dtoItem.SHORT_NAME.StrongValue);
        }
Example #8
0
        /// <summary>
        /// Update record by using the table's primary key.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data">Data which to update.</param>
        /// <param name="oldITEM_CD">Old Key #1</param>
        /// <param name="oldITEM_SEQ">Old Key #2</param>
        /// <returns></returns>
        public int UpdateWithPK(Database database, ItemProcessDTO data, NZInt oldITEM_CD, NZInt oldITEM_SEQ)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            sb.AppendLine(" UPDATE " + data.TableName);
            sb.AppendLine(" SET ");
            sb.AppendLine("  " + ItemProcessDTO.eColumns.UPD_BY + "=@UPD_BY");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_DATE + "=GETDATE()");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_MACHINE + "=@UPD_MACHINE");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.ITEM_CD + "=@ITEM_CD");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.ITEM_SEQ + "=@ITEM_SEQ");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.PROCESS_CD + "=@PROCESS_CD");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.WEIGHT + "=@WEIGHT");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.PRODUCTION_LEADTIME + "=@PRODUCTION_LEADTIME");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.QTY_PER_DAY + "=@QTY_PER_DAY");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.SUPPLIER_CD + "=@SUPPLIER_CD");
            sb.AppendLine("  ," + ItemProcessDTO.eColumns.OLD_DATA + "=@OLD_DATA");
            sb.AppendLine(" WHERE ");
            sb.AppendLine("  " + ItemProcessDTO.eColumns.ITEM_CD + "=@oldITEM_CD");
            sb.AppendLine("  AND " + ItemProcessDTO.eColumns.ITEM_SEQ + "=@oldItemProcess");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters
            req.Parameters.Add("@UPD_BY", DataType.NVarChar, data.UPD_BY.Value);
            req.Parameters.Add("@UPD_MACHINE", DataType.NVarChar, data.UPD_MACHINE.Value);
            req.Parameters.Add("@ITEM_CD", DataType.Default, data.ITEM_CD.Value);
            req.Parameters.Add("@ITEM_SEQ", DataType.Default, data.ITEM_SEQ.Value);
            req.Parameters.Add("@PROCESS_CD", DataType.NVarChar, data.PROCESS_CD.Value);
            req.Parameters.Add("@WEIGHT", DataType.Number, data.WEIGHT.Value);
            req.Parameters.Add("@PRODUCTION_LEADTIME", DataType.Default, data.PRODUCTION_LEADTIME.Value);
            req.Parameters.Add("@QTY_PER_DAY", DataType.Number, data.QTY_PER_DAY.Value);
            req.Parameters.Add("@SUPPLIER_CD", DataType.NVarChar, data.SUPPLIER_CD.Value);
            req.Parameters.Add("@OLD_DATA", DataType.Default, data.OLD_DATA.Value);
            req.Parameters.Add("@oldITEM_CD", DataType.Default, oldITEM_CD);
            req.Parameters.Add("@oldITEM_SEQ", DataType.Default, oldITEM_SEQ);
            #endregion

            return(db.ExecuteNonQuery(req));
        }
Example #9
0
        /// <exception cref="BusinessException"><c>BusinessException</c>.</exception>
        public void ValidateBeforeSaveUpdate(ItemDTO dtoItem, ItemProcessDTO dtoItemProcess)
        {
            ValidateException validateException = new ValidateException();
            ErrorItem         errorItem         = null;

            #region mandatory check
            errorItem = CheckEmptyItemCode(dtoItem.ITEM_CD);
            if (errorItem != null)
            {
                validateException.AddError(errorItem);
            }

            //errorItem = CheckEmptyItemDesc(dtoItem.ITEM_DESC);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyItemType(dtoItem.ITEM_CLS);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyLotControlType(dtoItem.LOT_CONTROL_CLS);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyOrderProcess(dtoItemProcess.ORDER_PROCESS_CLS);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);

            //errorItem = CheckEmptyStoreLoc(dtoItemProcess.STORE_LOC_CD);
            //if (errorItem != null)
            //    validateException.AddError(errorItem);
            validateException.ThrowIfHasError();
            #endregion

            BusinessException businessException = CheckItemNotExist(dtoItem.ITEM_CD);
            if (businessException != null)
            {
                throw businessException;
            }
        }
Example #10
0
        private void SetOrderLoactionandMRPFlag()
        {
            for (int iRow = 0; iRow < shtView.RowCount; iRow++)
            {
                if (Convert.ToString(shtView.Cells[iRow, (int)eColView.CHILD_ORDER_LOC].Value) == string.Empty)
                {
                    BOMBIZ         bizBOM = new BOMBIZ();
                    ItemProcessDTO dto    = bizBOM.LoadLocationandMRPFLag(Convert.ToString(shtView.Cells[iRow, (int)eColView.ITEM_CD].Value));
                    if (dto != null)
                    {
                        //shtView.Cells[iRow, (int)eColView.CHILD_ORDER_LOC].Value = dto.ORDER_LOC_CD;
                        shtView.Cells[iRow, (int)eColView.CHILD_ORDER_LOC].ForeColor = Color.Gray;
                        //shtView.Cells[iRow, (int)eColView.CHILD_ORDER_LOC].HorizontalAlignment = FarPoint.Win.Spread.she
                    }
                }
                else
                {
                    shtView.Cells[iRow, (int)eColView.CHILD_ORDER_LOC].ForeColor = Color.Black;
                }

                if (Convert.ToString(shtView.Cells[iRow, (int)eColView.MRP_FLAG].Value) == string.Empty)
                {
                    BOMBIZ         bizBOM = new BOMBIZ();
                    ItemProcessDTO dto    = bizBOM.LoadLocationandMRPFLag(Convert.ToString(shtView.Cells[iRow, (int)eColView.ITEM_CD].Value));
                    if (dto != null)
                    {
                        //shtView.Cells[iRow, (int)eColView.MRP_FLAG].Value = dto.MRP_FLAG.StrongValue == string.Empty ? "" : bizBOM.LoadMRPFLag(dto.MRP_FLAG);
                        shtView.Cells[iRow, (int)eColView.MRP_FLAG].ForeColor = Color.Gray;
                    }
                }
                else
                {
                    shtView.Cells[iRow, (int)eColView.MRP_FLAG].ForeColor = Color.Black;
                }
            }
        }
Example #11
0
        public MultiWorkResultEntryUIDM LoadForEditMultiWorkResult(NZString transID)
        {
            //== Load Header (Work Result)
            InventoryTransBIZ bizInventoryTransaction = new InventoryTransBIZ();
            InventoryBIZ      bizInventory            = new InventoryBIZ();


            ItemBIZ bizItem = new ItemBIZ();

            InventoryTransactionDTO transDTO = bizInventoryTransaction.LoadByTransactionID(transID);

            if (transDTO == null)
            {
                return(null);
            }


            //เอา transDTO ไปหา group
            //แล้วก็ group -> แปลงเป็น column ตาม spread


            ItemDTO        dtoItem        = bizItem.LoadItem(transDTO.ITEM_CD);
            ItemProcessDTO dtoItemProcess = bizItem.LoadItemProcess(transDTO.ITEM_CD);

            MultiWorkResultEntryUIDM model = new MultiWorkResultEntryUIDM();

            //model.ChildItemCode = ;// ต้องไปดึงมาจาก consumption ตัวแรก
            //model.OrderLoc=;

            //model.CONSUMTION_CLS = dtoItemProcess.CONSUMTION_CLS;
            model.ForMachine        = transDTO.FOR_MACHINE;
            model.ItemCode          = transDTO.ITEM_CD;
            model.ItemDesc          = dtoItem.ITEM_DESC;
            model.Remark            = transDTO.REMARK;
            model.ShiftClass        = transDTO.SHIFT_CLS;
            model.StoredLoc         = transDTO.LOC_CD;
            model.TRAN_SUB_CLS      = transDTO.TRAN_SUB_CLS;
            model.WorkOrderNo       = transDTO.REF_SLIP_NO;
            model.WorkResultDate    = transDTO.TRANS_DATE;
            model.WorkResultGroupNo = transDTO.GROUP_TRANS_ID;

            List <InventoryTransactionDTO> listTrans = bizInventoryTransaction.LoadGroupTransaction(transDTO.GROUP_TRANS_ID, DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.WorkResult).ToNZString());

            //new list ของ multi work result เพื่อใส่ข้อมูล เป็น row ก่อน
            //แล้วพอวนใส่เสร็จค่อย convert เป็น datatable เพื่อ set value ให้ model.DataView
            List <MultiWorkResultEntryViewDTO> listMultiWorkResult = new List <MultiWorkResultEntryViewDTO>();



            foreach (InventoryTransactionDTO dtoTran in listTrans)
            {
                MultiWorkResultEntryViewDTO multiDTO = new MultiWorkResultEntryViewDTO();
                multiDTO.GOOD_QTY            = dtoTran.QTY;
                multiDTO.GOOD_TRANSACTION_ID = dtoTran.TRANS_ID;
                //multiDTO.LOT_NO = dtoTran.LOT_NO;
                multiDTO.NG_QTY    = dtoTran.NG_QTY;
                multiDTO.NG_REASON = dtoTran.NG_REASON;

                multiDTO.RESERVE_QTY    = dtoTran.RESERVE_QTY;
                multiDTO.WORK_RESULT_NO = dtoTran.SLIP_NO;

                InventoryTransactionDTO dtoNGTrans = bizInventoryTransaction.LoadNGWorkResult(dtoTran.SLIP_NO);
                if (dtoNGTrans != null && !dtoNGTrans.TRANS_ID.IsNull)
                {
                    multiDTO.NG_TRANSACTION_ID = dtoNGTrans.TRANS_ID;
                }

                InventoryTransactionDTO dtoReserveTrans = bizInventoryTransaction.LoadReserveResult(dtoTran.SLIP_NO);
                if (dtoReserveTrans != null && !dtoReserveTrans.TRANS_ID.IsNull)
                {
                    multiDTO.RESERVE_TRANSACTION_ID = dtoReserveTrans.TRANS_ID;
                }



                List <WorkResultEntryViewDTO> consumptionList = bizInventory.LoadWorkResultConsumptionList(dtoTran.SLIP_NO);
                if (consumptionList != null && consumptionList.Count == 1)
                {
                    //model.OrderLoc = consumptionList[0].LOC_CD;
                    //model.ChildItemCode = consumptionList[0].ITEM_CD;
                    //multiDTO.CONSUMPTION_TRANSACTION_ID = consumptionList[0].TRANS_ID;
                    //multiDTO.ON_HAND_QTY = consumptionList[0].ON_HAND_QTY;
                    //multiDTO.LOT_NO = consumptionList[0].LOT_NO;
                }
                else
                {
                    throw new NotSupportedException("Comsumption != 1 item");
                    //if (dtoItemProcess != null)
                    //    model.OrderLoc = dtoItemProcess.ORDER_LOC_CD;
                }


                //multiDTO.ON_HAND_QTY = new NZDecimal(null, 0);//onhand + good + ng + reserve
                //ActualOnhandViewDTO onhandConsumption = bizInventory.LoadActualInventoryOnHand(model.ChildItemCode, model.OrderLoc, multiDTO.LOT_NO);
                //if (onhandConsumption == null)
                //{
                //    multiDTO.ON_HAND_QTY.Value = multiDTO.GOOD_QTY.NVL(0) + multiDTO.NG_QTY.NVL(0) + multiDTO.RESERVE_QTY.NVL(0);
                //}
                //else
                //{
                //    multiDTO.ON_HAND_QTY.Value = onhandConsumption.ONHAND_QTY.NVL(0) + multiDTO.GOOD_QTY.NVL(0) + multiDTO.NG_QTY.NVL(0) + multiDTO.RESERVE_QTY.NVL(0);
                //}



                listMultiWorkResult.Add(multiDTO);
            }

            model.DataView = DTOUtility.ConvertListToDataTable <MultiWorkResultEntryViewDTO>(listMultiWorkResult);

            model.DataView.AcceptChanges();
            return(model);
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="transactionID"></param>
        /// <returns></returns>
        public WorkResultEntryUIDM LoadForEditWorkResult(NZString transactionID)
        {
            //== Load Header (Work Result)
            InventoryTransBIZ bizInventoryTransaction = new InventoryTransBIZ();
            ItemBIZ           bizItem = new ItemBIZ();

            InventoryTransactionDTO dtoInventoryTransaction = bizInventoryTransaction.LoadByTransactionID(transactionID);

            if (dtoInventoryTransaction == null)
            {
                return(null);
            }

            ItemDTO             dtoItem        = bizItem.LoadItem(dtoInventoryTransaction.ITEM_CD);
            ItemProcessDTO      dtoItemProcess = bizItem.LoadItemProcess(dtoInventoryTransaction.ITEM_CD);
            WorkResultEntryUIDM model          = new WorkResultEntryUIDM();

            model.TransactionID       = dtoInventoryTransaction.TRANS_ID;
            model.ItemCode            = dtoInventoryTransaction.ITEM_CD;
            model.ItemDesc            = dtoItem.ITEM_DESC;
            model.LotNo               = dtoInventoryTransaction.LOT_NO;
            model.StoredLoc           = dtoInventoryTransaction.LOC_CD;
            model.Remark              = dtoInventoryTransaction.REMARK;
            model.WorkOrderNo         = dtoInventoryTransaction.REF_SLIP_NO;
            model.WorkResultDate      = dtoInventoryTransaction.TRANS_DATE;
            model.WorkResultQty.Value = dtoInventoryTransaction.QTY.NVL(0) + dtoInventoryTransaction.NG_QTY.NVL(0) + dtoInventoryTransaction.RESERVE_QTY.NVL(0);
            model.GoodQty.Value       = dtoInventoryTransaction.QTY.NVL(0);
            model.WorkResultNo        = dtoInventoryTransaction.SLIP_NO;
            model.ShipClass           = dtoInventoryTransaction.SHIFT_CLS;
            //model.CONSUMTION_CLS = dtoItemProcess.CONSUMTION_CLS;
            model.ReserveQty = dtoInventoryTransaction.RESERVE_QTY;
            model.NGQty      = dtoInventoryTransaction.NG_QTY;
            model.ForMachine = dtoInventoryTransaction.FOR_MACHINE;
            model.NGReason   = dtoInventoryTransaction.NG_REASON;
            //model.LotSize = dtoItemProcess.LOT_SIZE;

            //model.OrderLoc = dtoItemProcess.ORDER_LOC_CD;


            InventoryTransactionDTO dtoNGTrans = bizInventoryTransaction.LoadNGWorkResult(model.WorkResultNo);

            if (dtoNGTrans != null && !dtoNGTrans.TRANS_ID.IsNull)
            {
                model.NGTransactionID = dtoNGTrans.TRANS_ID;
            }

            InventoryTransactionDTO dtoReserveTrans = bizInventoryTransaction.LoadReserveResult(model.WorkResultNo);

            if (dtoReserveTrans != null && !dtoReserveTrans.TRANS_ID.IsNull)
            {
                model.ReserveTransactionID = dtoReserveTrans.TRANS_ID;
            }


            InventoryBIZ bizInventory             = new InventoryBIZ();
            List <WorkResultEntryViewDTO> dtoList = bizInventory.LoadWorkResultConsumptionList(model.WorkResultNo);

            model.DataView = DTOUtility.ConvertListToDataTable(dtoList);

            model.DataView.AcceptChanges();
            return(model);
        }
Example #13
0
        internal void AddNewItem(ItemUIDM uidmItem)
        {
            ValidateException validationException = new ValidateException();
            ItemValidator     itemValidator       = new ItemValidator();

            itemValidator.CheckItemExist(uidmItem.ITEM_CD);
            //validationException.AddError(businessException.Error);
            //validationException.ThrowIfHasError();

            #region dtoItem

            ItemDTO dtoItem = new ItemDTO();
            dtoItem.CRT_BY         = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoItem.CRT_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            dtoItem.CRT_MACHINE    = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoItem.UPD_BY         = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoItem.UPD_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            dtoItem.UPD_MACHINE    = CommonLib.Common.CurrentUserInfomation.Machine;

            dtoItem.ITEM_CD      = uidmItem.ITEM_CD;
            dtoItem.SHORT_NAME   = uidmItem.SHORT_NAME;
            dtoItem.ITEM_DESC    = uidmItem.ITEM_DESC;
            dtoItem.ROUTING_TEXT = uidmItem.ROUTING_TEXT;

            #region Product Tab

            dtoItem.KIND_OF_PRODUCT    = uidmItem.KIND_OF_PRODUCT;
            dtoItem.CUSTOMER_CD        = uidmItem.CUSTOMER_CD;
            dtoItem.CUSTOMER_USE_POINT = uidmItem.CUSTOMER_USE_POINT;
            dtoItem.WEIGHT             = uidmItem.WEIGHT;
            dtoItem.BOI             = uidmItem.BOI;
            dtoItem.PRODUCTION_DI   = uidmItem.PRODUCTION_DI;
            dtoItem.ITEM_LEVEL      = uidmItem.ITEM_LEVEL;
            dtoItem.MAT_NAME        = uidmItem.MAT_NAME;
            dtoItem.MAT_SIZE        = uidmItem.MAT_SIZE;
            dtoItem.MAT_SUPPLIER_CD = uidmItem.SUPPLIER_NAME;
            dtoItem.KIND_OF_MAT     = uidmItem.KIND_OF_MAT;
            dtoItem.MAT_DI          = uidmItem.MAT_DI;
            dtoItem.REMARK          = uidmItem.REMARK;

            #endregion

            #region Screw Tab

            dtoItem.SCREW_KIND    = uidmItem.SCREW_KIND;
            dtoItem.SCREW_HEAD    = uidmItem.SCREW_HEAD;
            dtoItem.SCREW_M       = uidmItem.SCREW_M;
            dtoItem.SCREW_L       = uidmItem.SCREW_L;
            dtoItem.SCREW_TYPE    = uidmItem.SCREW_TYPE;
            dtoItem.SCREW_REMARK1 = uidmItem.SCREW_REMARK1;
            dtoItem.SCREW_REMARK2 = uidmItem.SCREW_REMARK2;
            dtoItem.HEXABULAR     = uidmItem.HEXABULAR;

            #endregion

            #region Machine Tab

            dtoItem.PROCESS1      = uidmItem.PROCESS1;
            dtoItem.MACHINE_TYPE1 = uidmItem.MACHINE_TYPE1;
            dtoItem.PROCESS2      = uidmItem.PROCESS2;
            dtoItem.MACHINE_TYPE2 = uidmItem.MACHINE_TYPE2;
            dtoItem.PROCESS3      = uidmItem.PROCESS3;
            dtoItem.MACHINE_TYPE3 = uidmItem.MACHINE_TYPE3;
            dtoItem.PROCESS4      = uidmItem.PROCESS4;
            dtoItem.MACHINE_TYPE4 = uidmItem.MACHINE_TYPE4;
            dtoItem.PROCESS5      = uidmItem.PROCESS5;
            dtoItem.MACHINE_TYPE5 = uidmItem.MACHINE_TYPE5;
            dtoItem.PROCESS6      = uidmItem.PROCESS6;
            dtoItem.MACHINE_TYPE6 = uidmItem.MACHINE_TYPE6;

            #endregion

            #region Heat Treatment Tab

            dtoItem.HEAT_FLAG          = uidmItem.HEAT_FLAG;
            dtoItem.HEAT_TYPE          = uidmItem.HEAT_TYPE;
            dtoItem.HEAT_HARDNESS      = uidmItem.HEAT_HARDNESS;
            dtoItem.HEAT_CORE_HARDNESS = uidmItem.HEAT_CORE_HARDNESS;
            dtoItem.HEAT_CASE_DEPTH    = uidmItem.HEAT_CASE_DEPTH;

            #endregion

            #region Plating Tab

            dtoItem.PLATING_FLAG         = uidmItem.PLATING_FLAG;
            dtoItem.PLATING_KIND         = uidmItem.PLATING_KIND;
            dtoItem.PLATING_SUPPLIER_CD  = uidmItem.PLATING_SUPPLIER_NAME;
            dtoItem.PLATING_THICKNESS1_1 = uidmItem.PLATING_THICKNESS1_1;
            dtoItem.PLATING_THICKNESS1_2 = uidmItem.PLATING_THICKNESS1_2;
            dtoItem.PLATING_THICKNESS2_1 = uidmItem.PLATING_THICKNESS2_1;
            dtoItem.PLATING_THICKNESS2_2 = uidmItem.PLATING_THICKNESS2_2;
            dtoItem.PLATING_KTC          = uidmItem.PLATING_KTC;
            dtoItem.BAKING_FLAG          = uidmItem.BAKING_FLAG;
            dtoItem.BAKING_TIME          = uidmItem.BAKING_TIME;
            dtoItem.BAKING_TEMP          = uidmItem.BAKING_TEMP;

            #endregion

            #region Other Tab

            dtoItem.OTHER_TREATMENT1_FLAG      = uidmItem.OTHER_TREATMENT1_FLAG;
            dtoItem.OTHER_TREATMENT1_KIND      = uidmItem.OTHER_TREATMENT1_KIND;
            dtoItem.OTHER_TREATMENT1_CONDITION = uidmItem.OTHER_TREATMENT1_CONDITION;
            dtoItem.OTHER_TREATMENT2_FLAG      = uidmItem.OTHER_TREATMENT2_FLAG;
            dtoItem.OTHER_TREATMENT2_KIND      = uidmItem.OTHER_TREATMENT2_KIND;
            dtoItem.OTHER_TREATMENT2_CONDITION = uidmItem.OTHER_TREATMENT2_CONDITION;

            #endregion

            dtoItem.OLD_DATA = new NZInt(null, 0);

            //ItemProcessDTO dtoItemProcess = new ItemProcessDTO();
            //dtoItemProcess.ITEM_CD = uidmItem.ITEM_CD;
            //dtoItemProcess.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //dtoItemProcess.CRT_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            //dtoItemProcess.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
            //dtoItemProcess.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //dtoItemProcess.UPD_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            //dtoItemProcess.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;

            #endregion

            List <ItemProcessDTO> listNew          = new List <ItemProcessDTO>();
            List <BOMDTO>         listNewComponent = new List <BOMDTO>();
            List <ItemMachineDTO> listNewMachine   = new List <ItemMachineDTO>();

            //Add
            uidmItem.DataView.AcceptChanges();
            uidmItem.DataComponentView.AcceptChanges();

            #region Routing

            DataTable dtNew = uidmItem.DataView;
            if (dtNew != null)
            {
                foreach (DataRow dr in dtNew.Rows)
                {
                    ItemProcessDTO dto = new ItemProcessDTO();

                    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;
                    dto.ITEM_CD             = uidmItem.ITEM_CD;
                    dto.ITEM_SEQ            = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.ITEM_SEQ]);
                    dto.PROCESS_CD          = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.PROCESS_CD]);
                    dto.WEIGHT              = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.WEIGHT]);
                    dto.PRODUCTION_LEADTIME = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.PRODUCTION_LEADTIME]);
                    dto.QTY_PER_DAY         = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.QTY_PER_DAY]);
                    dto.SUPPLIER_CD         = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.SUPPLIER_CD]);
                    dto.OLD_DATA            = new NZInt(null, 0);


                    listNew.Add(dto);
                }
            }

            ////Edit
            //DataTable dtEdit = uidmItem.DataView.GetChanges(DataRowState.Modified);
            //if (dtEdit != null)
            //{
            //    foreach (DataRow dr in dtEdit.Rows)
            //    {
            //        ItemProcessDTO dto = new ItemProcessDTO();
            //        //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;
            //        dto.ITEM_CD = new NZInt(null, Convert.ToInt32(uidmItem.ITEM_CD.StrongValue));
            //        dto.ITEM_SEQ = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.ITEM_SEQ]);
            //        dto.PROCESS_CD = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.PROCESS_CD]);
            //        dto.PROCESS_CD = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.PROCESS_NAME]);
            //        dto.WEIGHT = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.WEIGHT]);
            //        dto.PRODUCTION_LEADTIME = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.PRODUCTION_LEADTIME]);
            //        dto.QTY_PER_DAY = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.QTY_PER_DAY]);
            //        dto.SUPPLIER_CD = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.SUPPLIER_CD]);
            //        dto.OLD_DATA = new NZInt(null, 0);

            //        listEdit.Add(dto);
            //    }
            //}

            ////delete
            //DataTable dtDelete = uidmItem.DataView.GetChanges(DataRowState.Deleted);
            //if (dtDelete != null)
            //{
            //    listDelete = DTOUtility.ConvertDataTableToList<ItemProcessDTO>(dtDelete);

            //    for (int i = 0; i < listDelete.Count; i++)
            //    {
            //        listDelete[i].ITEM_CD = new NZInt(null, Convert.ToInt32(uidmItem.ITEM_CD.StrongValue));
            //    }

            //}

            #endregion

            #region Component

            int       iComponet_Seq  = 0;
            DataTable dtNewComponent = uidmItem.DataComponentView;//.GetChanges(DataRowState.Added);
            if (dtNewComponent != null)
            {
                foreach (DataRow dr in dtNewComponent.Rows)
                {
                    iComponet_Seq = iComponet_Seq + 1;
                    BOMDTO dto = new BOMDTO();
                    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;
                    dto.UPPER_ITEM_CD = uidmItem.ITEM_CD;
                    dto.LOWER_ITEM_CD = new NZString(null, dr[(int)ItemComponentDTO.eColumns.ITEM_CD]);
                    dto.ITEM_SEQ      = new NZInt(null, iComponet_Seq);
                    dto.UPPER_QTY     = new NZDecimal(null, dr[(int)ItemComponentDTO.eColumns.PCS]);
                    dto.LOWER_QTY     = new NZDecimal(null, 1);
                    dto.OLD_DATA      = new NZInt(null, 0);

                    listNewComponent.Add(dto);
                }
            }
            //DataTable dtEditComponent = uidmItem.DataView.GetChanges(DataRowState.Modified);
            //if (dtEditComponent != null)
            //{
            //    foreach (DataRow dr in dtEditComponent.Rows)
            //    {
            //        BOMDTO dto = new BOMDTO();
            //        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;
            //        dto.UPPER_ITEM_CD = uidmItem.ITEM_CD;
            //        dto.LOWER_ITEM_CD = new NZString(null, dr[(int)ItemComponentDTO.eColumns.ITEM_CD]);
            //        dto.ITEM_SEQ = new NZInt(null, iComponet_Seq);
            //        dto.UPPER_QTY = new NZDecimal(null, dr[(int)ItemComponentDTO.eColumns.PCS]);
            //        dto.LOWER_QTY = new NZDecimal(null, 1);
            //        dto.OLD_DATA = new NZInt(null, 0);


            //        listEditComponent.Add(dto);
            //    }
            //}

            //DataTable dtDeleteComponent = uidmItem.DataView.GetChanges(DataRowState.Deleted);
            //if (dtDeleteComponent != null)
            //{
            //    List<ItemComponentDTO> list = DTOUtility.ConvertDataTableToList<ItemComponentDTO>(dtDeleteComponent);

            //    for (int i = 0; i < list.Count; i++)
            //    {
            //        BOMDTO dto = new BOMDTO();
            //        dto.UPPER_ITEM_CD = uidmItem.ITEM_CD;
            //        dto.LOWER_ITEM_CD = new NZString(null, list[i].ITEM_CD);
            //        dto.ITEM_SEQ = new NZInt(null, iComponet_Seq);
            //        listDeleteComponent.Add(dto);
            //    }
            //}

            #endregion

            #region Item Machine

            DataTable dtItemMachine = uidmItem.DataItemMachine;
            if (dtItemMachine != null)
            {
                int iRunNo = 0;
                foreach (DataRow dr in dtItemMachine.Rows)
                {
                    iRunNo = iRunNo + 1;
                    ItemMachineDTO dto = new ItemMachineDTO();
                    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;
                    dto.ITEM_CD         = uidmItem.ITEM_CD;
                    dto.RUN_NO          = new NZInt(null, iRunNo);
                    dto.MACHINE_PROCESS = new NZString(null, dr[(int)ItemMachineDTO.eColumns.MACHINE_PROCESS]);
                    dto.MACHINE_TYPE    = new NZString(null, dr[(int)ItemMachineDTO.eColumns.MACHINE_TYPE]);
                    dto.OLD_DATA        = new NZInt(null, 0);
                    listNewMachine.Add(dto);
                }
            }

            #endregion

            ItemBIZ biz = new ItemBIZ();
            biz.AddNew(dtoItem, listNew, listNewComponent, listNewMachine);
            //biz.UpdateWithoutPK(dtoItem, listNew, listEdit, listDelete, listNewComponent, listEditComponent, listDeleteComponent);
        }
Example #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;
            }
        }
Example #15
0
        public int UpdateByItemCD(Database database, ItemProcessDTO data)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            sb.AppendLine(" UPDATE " + data.TableName);
            sb.AppendLine(" SET ");
            //sb.AppendLine("  " + ItemProcessDTO.eColumns.ORDER_PROCESS_CLS + "=:ORDER_PROCESS_CLS");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.ORDER_LOC_CD + "=:ORDER_LOC_CD");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.STORE_LOC_CD + "=:STORE_LOC_CD");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.PACK_SIZE + "=:PACK_SIZE");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.CONSUMTION_CLS + "=:CONSUMTION_CLS");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_BY + "=:UPD_BY");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_DATE + "=GETDATE()");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.UPD_MACHINE + "=:UPD_MACHINE");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.LOT_SIZE + "=:LOT_SIZE");

            ////Modify by Sansanee K. 03 June 2011 Case Add Filed
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.REORDER_POINT + "=:REORDER_POINT");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.SAFETY_STOCK + "=:SAFETY_STOCK");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.MINIMUM_ORDER + "=:MINIMUM_ORDER");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.MAX_CAPACITY + "=:MAX_CAPACITY");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.LEADTIME + "=:LEADTIME");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.SAFETY_LEADTIME + "=:SAFETY_LEADTIME");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.MRP_FLAG + "=:MRP_FLAG");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.ORDER_CONDITION + "=:ORDER_CONDITION");
            //sb.AppendLine("  ," + ItemProcessDTO.eColumns.YIELD + "=:YIELD");

            sb.AppendLine(" WHERE ");
            sb.AppendLine("  " + ItemProcessDTO.eColumns.ITEM_CD + "=:ITEM_CD");
            //sb.AppendLine("  AND " + ItemProcessDTO.eColumns.ORDER_PROCESS_CLS + "=:ORDER_PROCESS_CLS");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters
            //req.Parameters.Add("ITEM_CD", DataType.NVarChar, data.ITEM_CD.Value);
            //req.Parameters.Add("ORDER_PROCESS_CLS", DataType.NVarChar, data.ORDER_PROCESS_CLS.Value);
            //req.Parameters.Add("ORDER_LOC_CD", DataType.NVarChar, data.ORDER_LOC_CD.Value);
            //req.Parameters.Add("STORE_LOC_CD", DataType.NVarChar, data.STORE_LOC_CD.Value);
            //req.Parameters.Add("PACK_SIZE", DataType.Number, data.PACK_SIZE.Value);
            //req.Parameters.Add("CONSUMTION_CLS", DataType.NVarChar, data.CONSUMTION_CLS.Value);
            //req.Parameters.Add("UPD_BY", DataType.NVarChar, data.UPD_BY.Value);
            //req.Parameters.Add("UPD_MACHINE", DataType.NVarChar, data.UPD_MACHINE.Value);
            //req.Parameters.Add("LOT_SIZE", DataType.NVarChar, data.LOT_SIZE.Value);

            ////Modify by Sansanee K. 03 June 2011 Case Add Filed
            //req.Parameters.Add("REORDER_POINT", DataType.Number, data.REORDER_POINT.Value);
            //req.Parameters.Add("SAFETY_STOCK", DataType.Number, data.SAFETY_STOCK.Value);
            //req.Parameters.Add("MINIMUM_ORDER", DataType.Number, data.MINIMUM_ORDER.Value);
            //req.Parameters.Add("MAX_CAPACITY", DataType.Number, data.MAX_CAPACITY.Value);
            //req.Parameters.Add("LEADTIME", DataType.Number, data.LEADTIME.Value);
            //req.Parameters.Add("SAFETY_LEADTIME", DataType.Number, data.SAFETY_LEADTIME.Value);
            //req.Parameters.Add("MRP_FLAG", DataType.NVarChar, data.MRP_FLAG.Value);
            //req.Parameters.Add("ORDER_CONDITION", DataType.NVarChar, data.ORDER_CONDITION.Value);
            //req.Parameters.Add("YIELD", DataType.Number, data.YIELD.Value);
            #endregion

            return(db.ExecuteNonQuery(req));
        }