/// <summary>
        /// - Check system suspending.<br />
        /// - Check user permission for screen IVS250.<br />
        /// - Get inventory head office.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult IVS250_Authority(IVS250_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                GetScreenObject <IVS250_ScreenParameter>();
                ICommonHandler comh = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (comh.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }
                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_REGISTER_PURCHASE_ORDER, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

                IInventoryHandler handInven    = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                List <doOffice>   IvHeadOffice = handInven.GetInventoryHeadOffice();

                if (IvHeadOffice.Count <= 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4016);
                    return(Json(res));
                }
                ICommonHandler        ComH   = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <doSystemConfig> config = ComH.GetSystemConfig(ConfigName.C_VAT_THB);

                param.m_VatTHB = Convert.ToDecimal(config[0].ConfigValue);
                param.office   = IvHeadOffice[0];

                List <doSystemConfig> configWht = ComH.GetSystemConfig(ConfigName.C_WHT);
                param.m_WHT = Convert.ToDecimal(configWht[0].ConfigValue);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(InitialScreenEnvironment <IVS250_ScreenParameter>("IVS250", param, res));
        }
        /// <summary>
        /// Get email of default department
        /// </summary>
        /// <returns></returns>
        private String getEmailsOfDefaultDepartment()
        {
            //1.1 Get default department to send email
            ICommonHandler        handCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            List <doSystemConfig> doSystem   = handCommon.GetSystemConfig(ConfigName.C_CONFIG_DEPARTMENT_NOTIFY_CHANGE_FEE);
            String strDeptCode = doSystem[0].ConfigValue;

            //1.2 Get employee belonging to default department
            //1.2.1 Get belonging list
            IEmployeeMasterHandler handMaster  = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler;
            List <dtBelonging>     dtBelonging = handMaster.GetBelonging(null, strDeptCode, null, null);

            List <tbm_Employee> empList = new List <tbm_Employee>();

            foreach (dtBelonging belonging in dtBelonging)
            {
                tbm_Employee employee = new tbm_Employee();
                employee.EmpNo = belonging.EmpNo;
                empList.Add(employee);
            }

            //1.2.2 Get employee list
            List <tbm_Employee> dtEmployee = handMaster.GetEmployeeList(empList);

            //1.3 Generate list of email
            //1.3.1 Set emailTo = Combine all dtEmployee.EmailAddrss with seperated by semi-colon
            StringBuilder sbEmailTo = new StringBuilder("");

            foreach (tbm_Employee employee in dtEmployee)
            {
                sbEmailTo.Append(employee.EmailAddress + ";");
            }

            if (sbEmailTo.Length > 0)
            {
                sbEmailTo = sbEmailTo.Remove(sbEmailTo.Length - 1, 1);
            }

            return(sbEmailTo.ToString());
        }
        /// <summary>
        /// Check email suffix
        /// </summary>
        /// <param name="addr"></param>
        /// <returns></returns>
        public ActionResult CMS060_CheckEmailSuffix(List <dtEmailAddress> addr)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                #region Get Email suffix

                string emailSuffix = "";

                ICommonHandler        chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <doSystemConfig> emlst    = chandler.GetSystemConfig(ConfigName.C_EMAIL_SUFFIX);
                if (emlst.Count > 0)
                {
                    emailSuffix = emlst[0].ConfigValue;
                }

                #endregion

                foreach (dtEmailAddress a in addr)
                {
                    //if (a.EmailAddress.IndexOf(emailSuffix) < 0)
                    if (String.IsNullOrEmpty(a.EmailAddress) == false &&
                        a.EmailAddress.ToUpper().IndexOf(emailSuffix.ToUpper()) < 0)    //Modify by Jutarat A. on 21112012
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0151);
                        return(Json(res));
                    }
                }

                res.ResultData = true;
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        public bool SendEmailChangePlanBeforeStart(doChangePlanBeforeStartEmail templateObj)
        {
            try
            {
                if (templateObj == null)
                {
                    throw new ArgumentNullException("templateObj");
                }

                ICommonHandler common = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                var            config = common.GetSystemConfig(ConfigName.C_CONFIG_CHANGEPLAN_BEFORE_START_EMAIL).FirstOrDefault();

                if (config == null)
                {
                    throw new ApplicationException("Missing tbs_configuration : " + ConfigName.C_CONFIG_CHANGEPLAN_BEFORE_START_EMAIL);
                }

                EmailTemplateUtil mailUtil = new EmailTemplateUtil(EmailTemplateName.C_EMAIL_TEMPLATE_NAME_CHANGEPLAN_BEFORE_START);
                var mailTemplate           = mailUtil.LoadTemplate(templateObj);

                doEmailProcess mailMsg = new doEmailProcess();
                mailMsg.MailFrom      = CommonUtil.dsTransData.dtUserData.EmailAddress;
                mailMsg.MailFromAlias = null;
                mailMsg.MailTo        = config.ConfigValue;
                mailMsg.Subject       = mailTemplate.TemplateSubject;
                mailMsg.Message       = mailTemplate.TemplateContent;
                mailMsg.IsBodyHtml    = true;

                ICommonHandler comHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                comHandler.SendMail(mailMsg);

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }