/// <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; } }