Esempio n. 1
0
        public Exception Process(Exception exception)
        {
            var adoException = exception as GenericADOException;
            if ((adoException != null) && DataWasTruncated(adoException))
            {
                exception = new ApplicationErrorException(ServiceError.DataSizeWasExceeded)
                {
                    {"EntityType", adoException.GetEntityType()}
                };
            }

            return exception;
        }
        public Exception Process(Exception exception)
        {
            var adoException = exception as GenericADOException;
            if ((adoException != null) && AppliesToThisPolicy(adoException))
            {
                exception = new ApplicationErrorException(ServiceError.RecordIsUsedByAnotherRecord)
                {
                    {"EntityType", adoException.GetEntityType()}
                };
            }

            return exception;
        }
        public Exception Process(Exception exception)
        {
            var adoException = exception as GenericADOException;
            if ((adoException != null) && IsUniqueConstraintViolation(adoException))
            {
                exception = new ApplicationErrorException(ServiceError.NameCodeOrNumberIsNotUnique)
                {
                    {"EntityType", adoException.GetEntityType()}
                };
            }

            return exception;
        }
Esempio n. 4
0
        public void ValidateSiteData(doSite doSite)
        {
            if (doSite == null)
            {
                return;
            }

            doSite.ValidateSiteData = true;
            try
            {
                IMasterHandler mhandler = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
                ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

                #region Building Usage

                if (CommonUtil.IsNullOrEmpty(doSite.BuildingUsageCode) == false)
                {
                    List <tbm_BuildingUsage> blst = mhandler.GetTbm_BiuldingUsage();
                    if (blst.Count > 0)
                    {
                        foreach (tbm_BuildingUsage b in blst)
                        {
                            if (doSite.BuildingUsageCode == b.BuildingUsageCode)
                            {
                                doSite.BuildingUsageName   = b.BuildingUsageName;
                                doSite.BuildingUsageNameEN = b.BuildingUsageNameEN;
                                doSite.BuildingUsageNameLC = b.BuildingUsageNameLC;
                                doSite.BuildingUsageNameJP = b.BuildingUsageNameJP;
                                break;
                            }
                        }
                    }
                }

                #endregion
                #region Province Data

                if (CommonUtil.IsNullOrEmpty(doSite.ProvinceCode) == false)
                {
                    List <tbm_Province> plst = mhandler.GetTbm_Province();
                    if (plst.Count > 0)
                    {
                        foreach (tbm_Province pv in plst)
                        {
                            if (doSite.ProvinceCode == pv.ProvinceCode)
                            {
                                doSite.ProvinceNameEN = pv.ProvinceNameEN;
                                doSite.ProvinceNameLC = pv.ProvinceNameLC;
                                break;
                            }
                        }
                    }
                }

                #endregion
                #region District

                if (CommonUtil.IsNullOrEmpty(doSite.DistrictCode) == false)
                {
                    List <tbm_District> dlst = mhandler.GetTbm_District(doSite.ProvinceCode);
                    if (dlst.Count > 0)
                    {
                        foreach (tbm_District d in dlst)
                        {
                            if (doSite.ProvinceCode == d.ProvinceCode &&
                                doSite.DistrictCode == d.DistrictCode)
                            {
                                doSite.DistrictNameEN = d.DistrictNameEN;
                                doSite.DistrictNameLC = d.DistrictNameLC;
                                break;
                            }
                        }
                    }
                }

                #endregion

                ApplicationErrorException.CheckMandatoryField <doSite, ValidateSite>(doSite);
            }
            catch
            {
                doSite.ValidateSiteData = false;
            }
            try
            {
                doCustomer cust = CommonUtil.CloneObject <doSite, doCustomer>(doSite);

                IMasterHandler mhandler = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
                mhandler.CreateAddressFull(cust);

                doSite.AddressFullEN = cust.AddressFullEN;
                doSite.AddressFullLC = cust.AddressFullLC;
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 5
0
        public List <tbm_Site> UpdateSite(doSite site)
        {
            try
            {
                ApplicationErrorException.CheckMandatoryField <doSite, tbm_SiteCondition>(site);

                //Check whether this record is the most updated data
                List <doGetTbm_Site> sList = this.GetTbm_Site(site.SiteCode);
                if (DateTime.Compare(sList[0].UpdateDate.Value, site.UpdateDate.Value) != 0)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0019);
                }

                dsTransDataModel dsTrans = CommonUtil.dsTransData;
                site.CreateDate = dsTrans.dtOperationData.ProcessDateTime;
                site.CreateBy   = dsTrans.dtUserData.EmpNo;
                site.UpdateDate = dsTrans.dtOperationData.ProcessDateTime;
                site.UpdateBy   = dsTrans.dtUserData.EmpNo;

                List <tbm_Site> lst = this.UpdateSite(site.SiteCode,
                                                      site.CustCode,
                                                      site.SiteNo,
                                                      site.SiteNameEN,
                                                      site.SiteNameLC,
                                                      site.SECOMContactPerson,
                                                      site.PersonInCharge,
                                                      site.PhoneNo,
                                                      site.BuildingUsageCode,
                                                      site.AddressEN,
                                                      site.AlleyEN,
                                                      site.RoadEN,
                                                      site.SubDistrictEN,
                                                      site.AddressFullEN,
                                                      site.AddressLC,
                                                      site.AlleyLC,
                                                      site.RoadLC,
                                                      site.SubDistrictLC,
                                                      site.AddressFullLC,
                                                      site.DistrictCode,
                                                      site.ProvinceCode,
                                                      site.ZipCode,
                                                      site.UpdateDate,
                                                      site.UpdateBy);

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

                return(lst);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// validate input data confirm and register data into database
        /// </summary>
        /// <returns></returns>
        public ActionResult ICS031_Confirm()
        {
            ICS031_ScreenParameter param        = GetScreenObject <ICS031_ScreenParameter>();
            ICS031_RegisterData    RegisterData = new ICS031_RegisterData();
            CommonUtil             comUtil      = new CommonUtil();

            // reuse param that send on Register Click
            if (param != null)
            {
                RegisterData = param.RegisterData;
            }

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            ObjectResultData resByIssue   = new ObjectResultData();
            ObjectResultData resByInvoice = new ObjectResultData();

            tbt_DebtTarget doTbt_DebtTarget = new tbt_DebtTarget();

            try
            {
                // Common Check Sequence

                // System Suspend
                ICommonHandler handlerCommon  = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                IIncomeHandler iincomeHandler = ServiceContainer.GetService <IIncomeHandler>() as IIncomeHandler;

                if (handlerCommon.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }


                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        #region tbt_DebtTarget
                        // Comment by Jirawat Jannet @ 2016-10-13
                        //for (int i = 0; i < RegisterData.Detail1.Count; i++)
                        //{
                        //    doTbt_DebtTarget = new tbt_DebtTarget();
                        //    doTbt_DebtTarget.BillingOfficeCode = RegisterData.Detail1[i].txtBillingOfficeCode;

                        //    doTbt_DebtTarget.AmountAll = (decimal?)Convert.ToDecimal(RegisterData.Detail1[i].txtAmountAll);
                        //    doTbt_DebtTarget.DetailAll = (int?)Convert.ToInt32(RegisterData.Detail1[i].txtDetailAll);
                        //    doTbt_DebtTarget.Amount2Month = (decimal?)Convert.ToDecimal(RegisterData.Detail1[i].txtAmount2Month);
                        //    doTbt_DebtTarget.Detail2Month = (int?)Convert.ToInt32(RegisterData.Detail1[i].txtDetail2Month);
                        //    if (iincomeHandler.UpdateTbt_DebtTarget(doTbt_DebtTarget) == 0)
                        //    {
                        //        throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7121, null);
                        //    }
                        //}
                        #endregion

                        // add by Jirawat jannet @ 2016-10-13
                        #region tbt_DebtTarget edit by Jirawat Jannet

                        string currencyLocal = MiscellaneousTypeCommon.getCurrencyName(CurrencyUtil.C_CURRENCY_LOCAL);
                        string currencyUs    = MiscellaneousTypeCommon.getCurrencyName(CurrencyUtil.C_CURRENCY_US);

                        foreach (var g in RegisterData.Detail1.GroupBy(m => m.txtBillingOfficeCode).Select(m => m.Key))
                        {
                            var local = RegisterData.Detail1.Where(m => m.txtBillingOfficeCode == g && m.txtCurrency == currencyLocal).First();
                            var us    = RegisterData.Detail1.Where(m => m.txtBillingOfficeCode == g && m.txtCurrency == currencyUs).First();

                            doTbt_DebtTarget = new tbt_DebtTarget();
                            doTbt_DebtTarget.BillingOfficeCode = local.txtBillingOfficeCode;

                            doTbt_DebtTarget.AmountAll    = (decimal?)Convert.ToDecimal(local.txtAmountAll);
                            doTbt_DebtTarget.DetailAll    = (int?)Convert.ToInt32(local.txtDetailAll);
                            doTbt_DebtTarget.Amount2Month = (decimal?)Convert.ToDecimal(local.txtAmount2Month);
                            doTbt_DebtTarget.Detail2Month = (int?)Convert.ToInt32(local.txtDetail2Month);

                            doTbt_DebtTarget.AmountAllUsd    = (decimal?)Convert.ToDecimal(us.txtAmountAll);
                            doTbt_DebtTarget.DetailAllUsd    = (int?)Convert.ToInt32(us.txtDetailAll);
                            doTbt_DebtTarget.Amount2MonthUsd = (decimal?)Convert.ToDecimal(us.txtAmount2Month);
                            doTbt_DebtTarget.Detail2MonthUsd = (int?)Convert.ToInt32(us.txtDetail2Month);

                            if (iincomeHandler.UpdateTbt_DebtTarget(doTbt_DebtTarget) == 0)
                            {
                                throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7121, null);
                            }
                        }

                        #endregion



                        scope.Complete();
                    }
                    catch (Exception ex)
                    {
                        // Fail rollback all record
                        scope.Dispose();
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        res.AddErrorMessage(ex);
                        return(Json(res));
                    }
                }


                // return "1" to js is every thing OK
                if (res.MessageList == null || res.MessageList.Count == 0)
                {
                    res.ResultData = "1";
                }
                else
                {
                    res.ResultData = "0";
                }
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }