Exemplo n.º 1
0
        /// <summary>
        /// Validate customer data
        /// </summary>
        /// <param name="cust"></param>
        /// <param name="isFullValidate"></param>
        public void ValidateCustomerData(doCustomer cust, bool isFullValidate = false)
        {
            IMasterHandler mhandler = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
            ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

            doCompanyType cType = null;

            cust.ValidateCustomerData = true;
            try
            {
                #region Set Misc Data

                MiscTypeMappingList miscList = new MiscTypeMappingList();
                miscList.AddMiscType(cust);
                chandler.MiscTypeMappingList(miscList);

                #endregion
                #region Company Type

                List <doCompanyType> clst = mhandler.GetCompanyType(cust.CompanyTypeCode);
                if (clst.Count > 0)
                {
                    cType = clst[0];
                    cust.CompanyTypeName = clst[0].CompanyTypeName;
                }

                #endregion
                #region Nationality Data

                if (CommonUtil.IsNullOrEmpty(cust.RegionCode) == false)
                {
                    List <tbm_Region> nlst = mhandler.GetTbm_Region();
                    if (nlst.Count > 0)
                    {
                        foreach (tbm_Region r in nlst)
                        {
                            if (cust.RegionCode == r.RegionCode)
                            {
                                cust.Nationality = r.Nationality;
                                break;
                            }
                        }
                    }
                }

                #endregion
                #region BusinessType Data

                if (CommonUtil.IsNullOrEmpty(cust.BusinessTypeCode) == false)
                {
                    List <tbm_BusinessType> blst = mhandler.GetTbm_BusinessType();
                    if (blst.Count > 0)
                    {
                        foreach (tbm_BusinessType b in blst)
                        {
                            if (cust.BusinessTypeCode == b.BusinessTypeCode)
                            {
                                cust.BusinessTypeName = b.BusinessTypeName;
                                break;
                            }
                        }
                    }
                }

                #endregion
                #region Province Data

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

                #endregion
                #region District

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

                #endregion

                if (CommonUtil.IsNullOrEmpty(cust.CustTypeName) || cust.CustTypeCode != CustomerType.C_CUST_TYPE_JURISTIC)
                {
                    cust.CompanyTypeName = null;
                }
                if (CommonUtil.IsNullOrEmpty(cust.CompanyTypeName) || cust.CompanyTypeCode != CompanyType.C_COMPANY_TYPE_PUBLIC_CO_LTD)
                {
                    cust.FinancialMaketTypeName = null;
                }

                if (CommonUtil.IsNullOrEmpty(cust.CustCode))
                {
                    if (isFullValidate)
                    {
                        ApplicationErrorException.CheckMandatoryField <doCustomer, ValidateCustomer_Full>(cust);
                    }
                    else if (CommonUtil.IsNullOrEmpty(cust.CustCode) == true)
                    {
                        ApplicationErrorException.CheckMandatoryField <doCustomer, ValidateCustomer_CodeNull>(cust);
                    }
                    else
                    {
                        ApplicationErrorException.CheckMandatoryField <doCustomer, ValidateCustomer>(cust);
                    }
                }
            }
            catch
            {
                cust.ValidateCustomerData = false;
            }
            try
            {
                if (cType == null)
                {
                    cType = new doCompanyType();
                }

                cust.CustFullNameEN =
                    CommonUtil.TextList(new string[] { cType.CustNamePrefixEN,
                                                       cust.CustNameEN,
                                                       cType.CustNameSuffixEN }, " ");
                cust.CustFullNameLC =
                    CommonUtil.TextList(new string[] { cType.CustNamePrefixLC,
                                                       cust.CustNameLC,
                                                       cType.CustNameSuffixLC }, " ");

                mhandler.CreateAddressFull(cust);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Validate user inputed data.<br />
        /// - Set usage.<br />
        /// - Set province.<br />
        /// - Set district.<br />
        /// - Check require field.
        /// </summary>
        /// <returns></returns>
        public ActionResult MAS040_ValidateData()
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                doSite doSite = null;

                MAS040_ScreenParameter siteData = GetScreenObject <MAS040_ScreenParameter>();
                if (siteData != null)
                {
                    if (siteData.doSite != null)
                    {
                        doSite = siteData.doSite;
                    }
                }

                if (doSite != null)
                {
                    IMasterHandler mhandler = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;

                    #region Usage

                    if (CommonUtil.IsNullOrEmpty(doSite.BuildingUsageCode) == false)
                    {
                        List <tbm_BuildingUsage> ulst = mhandler.GetTbm_BiuldingUsage();
                        if (ulst.Count > 0)
                        {
                            foreach (tbm_BuildingUsage u in ulst)
                            {
                                if (doSite.BuildingUsageCode == u.BuildingUsageCode)
                                {
                                    doSite.BuildingUsageName = u.BuildingUsageName;
                                    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
                }

                MAS040_ValidateCombo validate = CommonUtil.CloneObject <doSite, MAS040_ValidateCombo>(doSite);
                ValidatorUtil.BuildErrorMessage(res, new object[] { validate });

                if (doSite != null)
                {
                    if (doSite.ValidateSiteData == false)
                    {
                        MAS040_CheckRequiredField cSiteDo = CommonUtil.CloneObject <doSite, MAS040_CheckRequiredField>(doSite);

                        /*
                         * if (CommonUtil.IsNullOrEmpty(cSiteDo.BuildingUsageName))
                         *  cSiteDo.BuildingUsageCode = null;
                         */
                        if ((CommonUtil.IsNullOrEmpty(cSiteDo.ProvinceCode) == false) &&
                            (CommonUtil.IsNullOrEmpty(cSiteDo.ProvinceNameEN)) &&
                            (CommonUtil.IsNullOrEmpty(cSiteDo.ProvinceNameLC)))
                        {
                            cSiteDo.ProvinceNameEN = cSiteDo.ProvinceCode;
                            cSiteDo.ProvinceNameLC = cSiteDo.ProvinceCode;
                        }

                        if ((CommonUtil.IsNullOrEmpty(cSiteDo.DistrictCode) == false) &&
                            (CommonUtil.IsNullOrEmpty(cSiteDo.DistrictNameEN)) &&
                            (CommonUtil.IsNullOrEmpty(cSiteDo.DistrictNameLC)))
                        {
                            cSiteDo.DistrictNameEN = cSiteDo.DistrictCode;
                            cSiteDo.DistrictNameLC = cSiteDo.DistrictCode;
                        }

                        ValidatorUtil.BuildErrorMessage(res, new object[] { cSiteDo });
                    }
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validate customer data.<br />
        /// - Set company type.<br />
        /// - Set nationality.<br />
        /// - Set business type.<br />
        /// - Set province.<br />
        /// - Set district.<br />
        /// - Check require field.
        /// </summary>
        /// <returns></returns>
        public ActionResult MAS050_ValidateData()
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                doCustomer custDo = null;

                MAS050_ScreenParameter custData = GetScreenObject <MAS050_ScreenParameter>();
                if (custData != null)
                {
                    if (custData.doCustomer != null)
                    {
                        custDo = custData.doCustomer;
                    }
                }

                if (custDo != null)
                {
                    IMasterHandler mhandler = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
                    ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

                    #region Set Misc Data

                    MiscTypeMappingList miscList = new MiscTypeMappingList();
                    miscList.AddMiscType(custDo);
                    chandler.MiscTypeMappingList(miscList);

                    #endregion
                    #region Company Type

                    if (CommonUtil.IsNullOrEmpty(custDo.CompanyTypeCode) == false)
                    {
                        List <doCompanyType> clst = mhandler.GetCompanyType(custDo.CompanyTypeCode);
                        if (clst.Count > 0)
                        {
                            custDo.CompanyTypeName = clst[0].CompanyTypeName;
                        }
                    }

                    #endregion
                    #region Nationality Data

                    if (CommonUtil.IsNullOrEmpty(custDo.RegionCode) == false)
                    {
                        List <tbm_Region> nlst = mhandler.GetTbm_Region();
                        if (nlst.Count > 0)
                        {
                            foreach (tbm_Region r in nlst)
                            {
                                if (custDo.RegionCode == r.RegionCode)
                                {
                                    custDo.Nationality = r.Nationality;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion
                    #region BusinessType Data

                    if (CommonUtil.IsNullOrEmpty(custDo.BusinessTypeCode) == false)
                    {
                        List <tbm_BusinessType> blst = mhandler.GetTbm_BusinessType();
                        if (blst.Count > 0)
                        {
                            foreach (tbm_BusinessType b in blst)
                            {
                                if (custDo.BusinessTypeCode == b.BusinessTypeCode)
                                {
                                    custDo.BusinessTypeName = b.BusinessTypeName;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion
                    #region Province Data

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

                    #endregion
                    #region District

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

                    #endregion

                    if (CommonUtil.IsNullOrEmpty(custDo.CustTypeName) || custDo.CustTypeCode != CustomerType.C_CUST_TYPE_JURISTIC)
                    {
                        custDo.CompanyTypeName = null;
                    }
                    if (CommonUtil.IsNullOrEmpty(custDo.CompanyTypeName) || custDo.CompanyTypeCode != CompanyType.C_COMPANY_TYPE_PUBLIC_CO_LTD)
                    {
                        custDo.FinancialMaketTypeName = null;
                    }
                }

                MAS050_ValidateCombo validate = CommonUtil.CloneObject <doCustomer, MAS050_ValidateCombo>(custDo);
                ValidatorUtil.BuildErrorMessage(res, new object[] { validate });

                if (custDo != null)
                {
                    if (custDo.ValidateCustomerData == false)
                    {
                        object validate1 = null;
                        if (custData.CallerScreenID == ScreenID.C_SCREEN_ID_PROJ_NEW ||
                            custData.CallerScreenID == ScreenID.C_SCREEN_ID_PROJ_CHANGE ||
                            custData.CallerScreenID == ScreenID.C_SCREEN_ID_QTN_TARGET)
                        {
                            if (CommonUtil.IsNullOrEmpty(custDo.CustCode) == true)
                            {
                                MAS050_CheckRequiredFieldCustNull cCustDo = CommonUtil.CloneObject <doCustomer, MAS050_CheckRequiredFieldCustNull>(custDo);
                                validate1 = cCustDo;
                            }
                            else
                            {
                                MAS050_CheckRequiredFieldNotFull cCustDo = CommonUtil.CloneObject <doCustomer, MAS050_CheckRequiredFieldNotFull>(custDo);
                                validate1 = cCustDo;
                            }
                        }
                        else
                        {
                            MAS050_CheckRequiredField cCustDo = CommonUtil.CloneObject <doCustomer, MAS050_CheckRequiredField>(custDo);
                            validate1 = cCustDo;
                        }

                        ValidatorUtil.BuildErrorMessage(res, new object[] { validate1 });
                    }
                }

                //Add by Jutarat A. on 02012014
                if (custDo != null)
                {
                    if (custDo.CustTypeCode == CustomerType.C_CUST_TYPE_JURISTIC ||
                        custDo.CustTypeCode == CustomerType.C_CUST_TYPE_ASSOCIATION ||
                        custDo.CustTypeCode == CustomerType.C_CUST_TYPE_PUBLIC_OFFICE)
                    {
                        if (custDo.DummyIDFlag != null && custDo.DummyIDFlag.Value == false)
                        {
                            if (CommonUtil.IsNullOrEmpty(custDo.IDNo) == false && custDo.IDNo.Length != 15)
                            {
                                res.AddErrorMessage(MessageUtil.MODULE_MASTER,
                                                    "MAS050",
                                                    MessageUtil.MODULE_MASTER,
                                                    MessageUtil.MessageList.MSG1060,
                                                    null,
                                                    new string[] { "IDNo" });
                                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                                return(Json(res));
                            }
                        }
                    }
                }
                //End Add
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
Exemplo 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;
            }
        }