/// <summary>
        ///   Check all form controls have valid data if not display user to message and return fail
        /// </summary>
        /// <returns> form validation sucuss or Fail </returns>
        private bool IsFormvalidate()
        {
            try
            {
                bool  validateResult   = true;
                bool  isControlFocused = true;
                Regex alphanumericpatt = new Regex("^[A-Za-z0-9!@#$%&*()-{}.,/ ]+$");
                //--- Supplier code already exists --//--
                if (!string.IsNullOrEmpty(txtSupplierCode.Text) && string.IsNullOrEmpty(editSupplierCode))
                {
                    var IssupplierModel = supplierManager.GetSupplierByID(txtSupplierCode.Text);
                    if (IssupplierModel != null)
                    {
                        CommonFunc.SetErrorProvidertoControl(ref supplierErrorProvider, ref txtSupplierCode, "Supplier code already exists", true);
                        txtSupplierCode.Focus();
                        validateResult   = false;
                        isControlFocused = false;
                    }
                    else
                    {
                        supplierErrorProvider.SetError(txtSupplierCode, string.Empty);
                        txtSupplierCode.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }


                if (!CommonFunc.SetErrorProvidertoControl(ref supplierErrorProvider, ref txtName, "Supplier Name value required"))
                {
                    if (isControlFocused)
                    {
                        this.txtName.Focus();
                    }

                    validateResult   = false;
                    isControlFocused = false;
                }
                if (!CommonFunc.SetErrorProvidertoControl(ref supplierErrorProvider, ref txtContactPerson, "Contact Person value required"))
                {
                    if (isControlFocused)
                    {
                        this.txtContactPerson.Focus();
                    }
                    validateResult   = false;
                    isControlFocused = false;
                }

                if (!CommonFunc.validateEmailId(this.txtEmailAddress.Text.ToString()) && !string.IsNullOrEmpty(this.txtEmailAddress.Text.ToString()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref supplierErrorProvider, ref txtEmailAddress, "E-mail should in standard E-mail format.", true))
                    {
                        if (isControlFocused)
                        {
                            txtEmailAddress.Focus();
                        }
                        validateResult   = false;
                        isControlFocused = false;
                    }
                }
                else
                {
                    supplierErrorProvider.SetError(txtEmailAddress, string.Empty);
                    txtEmailAddress.BorderColor = CommonFunc.DefaultBorderColor;
                }
                if (!string.IsNullOrEmpty(txtVatTanNo.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtVatTanNo.Text) == false)
                    {
                        validateResult = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref supplierErrorProvider, ref txtVatTanNo, "Vat Tin No allows Alphanumeric Character", false))
                        {
                            this.txtVatTanNo.Focus();
                        }
                    }
                    else
                    {
                        supplierErrorProvider.SetError(txtVatTanNo, string.Empty);
                        txtVatTanNo.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtCstTinNo.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtCstTinNo.Text) == false)
                    {
                        validateResult = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref supplierErrorProvider, ref txtCstTinNo, "CST Tin No allows Alphanumeric Character", false))
                        {
                            this.txtCstTinNo.Focus();
                        }
                    }
                    else
                    {
                        supplierErrorProvider.SetError(txtCstTinNo, string.Empty);
                        txtCstTinNo.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                return(validateResult);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        private bool IsFormValidate()
        {
            try
            {
                bool isValid     = true;
                bool isSiteValid = true;


                Regex sitecodepatt     = new Regex("^[A-Za-z0-9]+$");
                Regex alphanumericpatt = new Regex("^[A-Za-z0-9!@#$%&*()-{}.,/ ]+$");
                Regex numberpatt       = new Regex("^[0-9]+$");
                Regex alphapatt        = new Regex("^[A-Za-z ]+$");
                if (string.IsNullOrEmpty(txtSiteCode.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtSiteCode, "Site Code Required"))
                    {
                        this.txtSiteCode.Focus();
                        isValid = false;
                    }
                }
                else
                {
                    if (sitecodepatt.IsMatch(txtSiteCode.Text) == false)
                    {
                        isValid     = false;
                        isSiteValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtSiteCode, "Site Code Allows Alphanumeric Character", false))
                        {
                            this.txtSiteCode.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtSiteCode, string.Empty);
                        txtSiteCode.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtCorporateName.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtCorporateName.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtCorporateName, "Corporate Name Allows Alphanumeric Character", false))
                        {
                            this.txtCorporateName.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtCorporateName, string.Empty);
                        txtCorporateName.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }


                if (string.IsNullOrEmpty(txtOfficialName.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtOfficialName, "Site Name Required"))
                    {
                        this.txtSiteCode.Focus();
                        isValid = false;
                    }
                }
                else
                {
                    if (alphanumericpatt.IsMatch(txtOfficialName.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtOfficialName, "Site Name Allows Alphanumeric Character", false))
                        {
                            this.txtSiteCode.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtOfficialName, string.Empty);
                        txtOfficialName.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtAddress1.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtAddress1.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtAddress1, "Address Allows Alphanumeric Character", false))
                        {
                            this.txtAddress1.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtAddress1, string.Empty);
                        txtAddress1.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtAddress2.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtAddress2.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtAddress2, "Address Allows Alphanumeric Character", false))
                        {
                            this.txtAddress2.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtAddress2, string.Empty);
                        txtAddress2.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtAddress3.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtAddress3.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtAddress3, "Address Allows Alphanumeric Character", false))
                        {
                            this.txtAddress3.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtAddress3, string.Empty);
                        txtAddress3.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (string.IsNullOrEmpty(txtCountry.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtCountry, "Country Code Required"))
                    {
                        this.txtCountry.Focus();
                        isValid = false;
                    }
                }
                else
                {
                    if (alphapatt.IsMatch(txtCountry.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtCountry, "Country Allows Character Only", false))
                        {
                            this.txtCountry.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtCountry, string.Empty);
                        txtCountry.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }

                if (string.IsNullOrEmpty(txtCurrencyCode.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtCurrencyCode, "Currency Code Required"))
                    {
                        this.txtCurrencyCode.Focus();
                        isValid = false;
                    }
                }

                else
                {
                    errorProvider.SetError(txtCurrencyCode, string.Empty);
                    txtCurrencyCode.BorderColor = CommonFunc.DefaultBorderColor;
                    var IsCurrencyExist = this.siteManager.GetCurrencySymbol(txtCurrencyCode.Text.Trim());
                    if (IsCurrencyExist == null)
                    {
                        if (string.IsNullOrEmpty(txtCurrencySymol.Text.Trim()))
                        {
                            if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtCurrencySymol, "Currency Symbol Required"))
                            {
                                this.txtCurrencySymol.Focus();
                                isValid = false;
                            }
                        }
                        else
                        {
                            errorProvider.SetError(txtCurrencySymol, string.Empty);
                            txtCurrencySymol.BorderColor = CommonFunc.DefaultBorderColor;
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtCurrencySymol, string.Empty);
                        txtCurrencySymol.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }

                if (!string.IsNullOrEmpty(txtEmail.Text.Trim()))
                {
                    if (!CommonFunc.validateEmailId(this.txtEmail.Text.ToString()) && !string.IsNullOrEmpty(this.txtEmail.Text.ToString()))
                    {
                        if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtEmail, "E-mail Should in Standard E-mail Format.", true))
                        {
                            isValid = false;
                            txtEmail.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtEmail, string.Empty);
                        txtEmail.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtContactPerson.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtContactPerson.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtContactPerson, "Contact Person Allows Alphanumeric Character", false))
                        {
                            this.txtContactPerson.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtContactPerson, string.Empty);
                        txtContactPerson.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtContactNumber.Text.Trim()))
                {
                    if (numberpatt.IsMatch(txtContactNumber.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtContactNumber, "Contact Number Allows Numeric Only", false))
                        {
                            this.txtContactNumber.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtContactNumber, string.Empty);
                        txtContactNumber.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtFaxNo.Text.Trim()))
                {
                    if (numberpatt.IsMatch(txtFaxNo.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtFaxNo, "Fax Number Allows Numeric Only", false))
                        {
                            this.txtFaxNo.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtFaxNo, string.Empty);
                        txtFaxNo.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtTaxNo.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtTaxNo.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtTaxNo, "Tax Number Allows Alphanumeric Only", false))
                        {
                            this.txtTaxNo.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtTaxNo, string.Empty);
                        txtTaxNo.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (!string.IsNullOrEmpty(txtLicenceNo.Text.Trim()))
                {
                    if (alphanumericpatt.IsMatch(txtLicenceNo.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtLicenceNo, "License Number Allows Numeric Only", false))
                        {
                            this.txtLicenceNo.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtLicenceNo, string.Empty);
                        txtLicenceNo.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }

                if (string.IsNullOrEmpty(finYearBeginDate.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref finYearBeginDate, "Financial Year Begin Date required"))
                    {
                        this.finYearBeginDate.Focus();
                        isValid = false;
                    }
                }
                else
                {
                    errorProvider.SetError(finYearBeginDate, string.Empty);
                    finYearBeginDate.BorderColor = CommonFunc.DefaultBorderColor;
                }
                if (string.IsNullOrEmpty(finYearEndDate.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref finYearEndDate, "Financial Year End Date required"))
                    {
                        this.finYearEndDate.Focus();
                        isValid = false;
                    }
                }
                else
                {
                    errorProvider.SetError(finYearEndDate, string.Empty);
                    finYearEndDate.BorderColor = CommonFunc.DefaultBorderColor;
                }
                if (!string.IsNullOrEmpty(finYearBeginDate.Text.Trim()))
                {
                    if (string.IsNullOrEmpty(finYearEndDate.Text.Trim()))
                    {
                        isValid = false;
                        if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref finYearEndDate, "Please select a valid End Date"))
                        {
                            this.finYearEndDate.Focus();
                        }
                    }
                    else
                    {
                        DateTime beginDate = Convert.ToDateTime(finYearBeginDate.Value);
                        DateTime endDate   = Convert.ToDateTime(finYearEndDate.Value);
                        int      addDays   = 364;
                        string   FiscYear  = DateTime.Now.Year.ToString();
                        if (Convert.ToInt32(FiscYear.Substring(FiscYear.Length - 2)) % 4 == 0)
                        {
                            addDays = 365;
                        }
                        if (endDate >= beginDate.AddDays(addDays))
                        {
                            errorProvider.SetError(finYearEndDate, string.Empty);
                            finYearEndDate.BorderColor = CommonFunc.DefaultBorderColor;
                        }
                        else
                        {
                            isValid = false;
                            if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref finYearEndDate, "Difference between the Start Date and End Date should be 1 year. Please select a valid End Date"))
                            {
                                this.finYearEndDate.Focus();
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(txtSiteCode.Text.Trim()) && flagAddEdit == false && isSiteValid == true)
                {
                    var IsSiteExist = this.siteManager.GetSiteByID(txtSiteCode.Text.Trim());
                    if (IsSiteExist != null)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtSiteCode, "Site Name Already Exist", false))
                        {
                            this.txtSiteCode.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtSiteCode, string.Empty);
                        txtSiteCode.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                return(isValid);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }