Exemplo n.º 1
0
        /// <summary>
        /// Insert project stockout memo
        /// </summary>
        /// <param name="doInsert"></param>
        /// <returns></returns>
        public List <tbt_ProjectStockOutMemo> InsertTbt_ProjectStockOutMemo(tbt_ProjectStockOutMemo doInsert)
        {
            try
            {
                //set CreateDate, CreateBy, UpdateDate and UpdateBy
                doInsert.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                doInsert.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                doInsert.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                doInsert.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;

                List <tbt_ProjectStockOutMemo> doInsertList = new List <tbt_ProjectStockOutMemo>();
                doInsertList.Add(doInsert);
                List <tbt_ProjectStockOutMemo> insertList = base.InsertTbt_ProjectStockOutMemo(CommonUtil.ConvertToXml_Store <tbt_ProjectStockOutMemo>(doInsertList));

                //Insert Log
                if (insertList.Count > 0)
                {
                    doTransactionLog logData = new doTransactionLog();
                    logData.TransactionType = doTransactionLog.eTransactionType.Insert;
                    logData.TableName       = TableName.C_TBL_NAME_PRJ_STOCKOUT;
                    logData.TableData       = CommonUtil.ConvertToXml(insertList);
                    ILogHandler hand = ServiceContainer.GetService <ILogHandler>() as ILogHandler;
                    hand.WriteTransactionLog(logData);
                }

                return(insertList);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Using when Inventory stock-out intrument by project code
        /// </summary>
        /// <param name="strProjectCode"></param>
        /// <param name="doInstrumentList"></param>
        /// <param name="strStockOutMemo"></param>
        public void UpdateStockOutInstrument(string strProjectCode, List <doInstrument> doInstrumentList, string strStockOutMemo)
        {
            try
            {
                //1.	Check mandatory data
                //strProjectCode and instrument at least 1 are require fields.
                doUpdateStockOutInstrumentData updateDo = new doUpdateStockOutInstrumentData();
                updateDo.ProjectCode = strProjectCode;
                ApplicationErrorException.CheckMandatoryField(updateDo);
                if (CommonUtil.IsNullOrEmpty(strProjectCode))
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0007, "Project Code");
                }
                if (doInstrumentList.Count <= 0)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0007, "Instrument");
                }

                //2.	Begin tran;

                //3.	Validate business
                //3.1	Project code must exist in project table
                List <tbt_Project> projectList = base.GetTbt_Project(strProjectCode);

                //3.1.2.	Check project exist
                //If doTbt_Project	is null Then
                if (projectList.Count <= 0 || projectList[0] == null)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0011, strProjectCode);
                }

                //3.2	Project status must not be ‘Last completed’ or ‘Canceled’
                //3.2.1.	Project status must not be ‘Last completed’
                if (projectList[0].ProjectStatus == ProjectStatus.C_PROJECT_STATUS_LASTCOMPLETE)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3075);
                }

                //3.2.2.	Project status must not be ‘Canceled’
                if (projectList[0].ProjectStatus == ProjectStatus.C_PROJECT_STATUS_CANCEL)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3076);
                }

                //3.3	Check exist in instrument master for all instruments in doInstrumentList
                //3.3.1.	Loop all instrument in doInstrumentList
                IInstrumentMasterHandler hand = ServiceContainer.GetService <IInstrumentMasterHandler>() as IInstrumentMasterHandler;
                foreach (doInstrument doIn in doInstrumentList)
                {
                    //3.3.1.1.	Set local variable
                    // blnExistInstrument = False

                    //3.3.1.2.	Check exist instrument in master
                    List <bool?> blnExistInstrument = hand.CheckExistInstrument(doIn.InstrumentCode);

                    //3.3.1.3.	If blnExistInstrument = False Then
                    if (blnExistInstrument[0].Value == false)
                    {
                        throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0011, doIn.InstrumentCode);
                    }
                }

                using (TransactionScope scope = new TransactionScope())
                {
                    //Prepare insert data
                    tbt_ProjectStockoutInstrument doInsert = new tbt_ProjectStockoutInstrument();
                    doInsert.ProjectCode = strProjectCode;

                    //4.	Insert/update data in project stock-out intrument table
                    //4.1.1.	Loop all instrument in doInstrumentList
                    foreach (doInstrument doIn in doInstrumentList)
                    {
                        //4.1.1.2.	Check exist project stock-out intrument table
                        List <tbt_ProjectStockoutInstrument> doTbt_ProjectStockoutIntrument = this.GetTbt_ProjectStockoutInstrument(strProjectCode, doIn.InstrumentCode);

                        if (doTbt_ProjectStockoutIntrument.Count <= 0)
                        {
                            //4.1.1.3.	In case not exist: insert data to project stock-out intrument table
                            doInsert.InstrumentCode = doIn.InstrumentCode;
                            doInsert.InstrumentQty  = doIn.InstrumentQty;
                            this.InsertTbt_ProjectStockoutInstrument(doInsert);
                        }
                        else
                        {
                            //4.1.1.4.	In case exist: update data to project stock-out intrument table
                            doTbt_ProjectStockoutIntrument[0].InstrumentQty = doTbt_ProjectStockoutIntrument[0].InstrumentQty + doIn.InstrumentQty;
                            this.UpdateTbt_ProjectStockoutInstrument(doTbt_ProjectStockoutIntrument[0]);
                        }
                    }

                    //=============== TRS update 11/06/2012 =======================
                    tbt_ProjectStockOutMemo doStockoutMemo = new tbt_ProjectStockOutMemo();
                    doStockoutMemo.ProjectCode = strProjectCode;
                    doStockoutMemo.Memo        = strStockOutMemo;
                    InsertTbt_ProjectStockOutMemo(doStockoutMemo);
                    //=============================================================

                    scope.Complete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }