Ejemplo n.º 1
0
        private bool ValidateTax()
        {
            try
            {
                bool isValid = true;

                if (string.IsNullOrEmpty(txtTaxName.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtTaxName, "Tax Name Required"))
                    {
                        this.txtTaxName.Focus();
                        isValid = false;
                    }
                }
                else
                {
                    Regex patt = new Regex("^[A-Za-z0-9-.% ]+$");
                    if (patt.IsMatch(txtTaxName.Text) == false)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtTaxName, "Tax Name Allows AlphaNumeric,space,%,-", false))
                        {
                            this.txtTaxName.Focus();
                        }
                    }
                    else
                    {
                        errorProvider.SetError(txtTaxName, string.Empty);
                        txtTaxName.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }
                if (string.IsNullOrEmpty(txtTaxValue.Text.Trim()))
                {
                    if (!CommonFunc.SetErrorProvidertoControl(ref errorProvider, ref txtTaxValue, "Tax Value Required"))
                    {
                        this.txtTaxValue.Focus();
                        isValid = false;
                    }
                }
                else
                {
                    decimal taxval = Convert.ToDecimal(txtTaxValue.Value.ToString().Trim());
                    if (taxval <= 0)
                    {
                        isValid = false;
                        if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtTaxValue, "Value Should be Greater Than 0", false))
                        {
                            this.txtTaxValue.Focus();
                            return(isValid);
                        }
                    }
                    if (rdoTVTPercent.Checked == true)
                    {
                        if (taxval > Convert.ToDecimal("100.00"))
                        {
                            isValid = false;
                            if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtTaxValue, "Tax Value Can Not be Greater Than 100", false))
                            {
                                this.txtTaxValue.Focus();
                                return(isValid);
                            }
                        }
                    }
                    else
                    {
                        if (taxval > Convert.ToDecimal("1000000.00"))
                        {
                            isValid = false;
                            if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtTaxValue, "Tax Value Can Not be Greater Than 1000000", false))
                            {
                                this.txtTaxValue.Focus();
                                return(isValid);
                            }
                        }
                    }

                    if (txtTaxValue.Text.Contains("."))
                    {
                        string[] decKeys = txtTaxValue.Text.Split('.');
                        if (decKeys[1].Length > 2)
                        {
                            isValid = false;
                            if (!CommonFunc.SetCustomErrorProvidertoControl(ref errorProvider, ref txtTaxValue, "Only Two Decimal Digits Allowed", false))
                            {
                                this.txtTaxValue.Focus();
                            }
                        }
                        else
                        {
                            errorProvider.SetError(txtTaxValue, string.Empty);
                            txtTaxValue.BorderColor = CommonFunc.DefaultBorderColor;
                        }
                    }

                    else
                    {
                        errorProvider.SetError(txtTaxValue, string.Empty);
                        txtTaxValue.BorderColor = CommonFunc.DefaultBorderColor;
                    }
                }

                if ((cmbDocumentType.SelectedValue == null))
                {
                    if (!CommonFunc.SetErrorProviderComboControl(ref errorProvider, ref cmbDocumentType, "Please Select Document Type", false))
                    {
                        this.cmbDocumentType.Focus();
                        isValid = false;
                    }
                    //CommonFunc.ShowMessage("Required", Models.Enums.MessageType.Information);
                }

                if ((cmbAppliedon.SelectedValue == null))
                {
                    if (!CommonFunc.SetErrorProviderComboControl(ref errorProvider, ref cmbAppliedon, "Please Select Applied On ", false))
                    {
                        this.cmbAppliedon.Focus();
                        isValid = false;
                    }
                }
                return(isValid);
            }
            catch (Exception ex)
            {
                Logger.Log(ex, Logger.LogingLevel.Error);
                throw ex;
            }
        }