private bool validateInput() { StringBuilder builder = new StringBuilder(); int isError = 0; if (txt_name.Text.ToString().Length > 0) { if (!Encrption.Is_Alphabetic(txt_name.Text.ToString())) { isError++; builder.Append("Name must be alphabetic").AppendLine(); } } else { isError++; builder.Append("Please enter name").AppendLine(); } if (txt_fathername.Text.ToString().Length > 0) { if (!Encrption.Is_Alphabetic(txt_fathername.Text.ToString())) { isError++; builder.Append("Father name must be alphabetic").AppendLine(); } } else { isError++; builder.Append("Please enter father name").AppendLine(); } if (txt_email.Text.ToString().Length > 0) { if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString())) { isError++; builder.Append("Please enter valid email").AppendLine(); } } else { isError++; builder.Append("Please enter email").AppendLine(); } Employee employee = new Employee(); if (this.isEditEmployee == true) { // Mobile if (txt_mobile.Text.ToString().Length > 0) { if (double.TryParse(txt_mobile.Text.ToString(), out double result)) { if (txt_mobile.Text.ToString().Length != 11) { isError++; builder.Append("mobile lenght should be 11 digits").AppendLine(); } else { if (!this.mobile_no.Equals(txt_mobile.Text.ToString())) { if (employee.checkPhoneAlreadyExist(txt_mobile.Text.ToString())) { isError++; builder.Append("Mobile number already exists").AppendLine(); } } } } else { isError++; builder.Append("Mobile number must be numeric").AppendLine(); } } else { isError++; builder.Append("please enter mobile number").AppendLine(); } // Nic if (txt_nic.Text.ToString().Length > 0) { if (double.TryParse(txt_nic.Text.ToString(), out double result)) { if (txt_nic.Text.ToString().Length != 13) { isError++; builder.Append("Nic lenght should be 13 digits").AppendLine(); } else { if (!this.cnic_no.Equals(txt_nic.Text.ToString())) { if (employee.checkNicAlreadyExist(txt_nic.Text.ToString())) { isError++; builder.Append("Nic number already exist").AppendLine(); } } } } else { isError++; builder.Append("Nic number must be numeric").AppendLine(); } } else { isError++; builder.Append("Please enter nic number").AppendLine(); } } else { // Mobile if (txt_mobile.Text.ToString().Length > 0) { if (double.TryParse(txt_mobile.Text.ToString(), out double result)) { if (txt_mobile.Text.ToString().Length != 11) { isError++; builder.Append("mobile lenght should be 11 digits").AppendLine(); } else { if (employee.checkPhoneAlreadyExist(txt_mobile.Text.ToString())) { isError++; builder.Append("Mobile number already exists").AppendLine(); } } } else { isError++; builder.Append("Mobile number must be numeric").AppendLine(); } } else { isError++; builder.Append("please enter mobile number").AppendLine(); } // Nic if (txt_nic.Text.ToString().Length > 0) { if (double.TryParse(txt_nic.Text.ToString(), out double result)) { if (txt_nic.Text.ToString().Length != 13) { isError++; builder.Append("Nic lenght should be 13 digits").AppendLine(); } else { if (employee.checkNicAlreadyExist(txt_nic.Text.ToString())) { isError++; builder.Append("Nic number already exist").AppendLine(); } } } else { isError++; builder.Append("Nic number must be numeric").AppendLine(); } } else { isError++; builder.Append("Please enter nic number").AppendLine(); } } if (txt_address.Text.Length > 0) { if (txt_address.Text.ToString().Length > 191) { isError++; builder.Append("Address is too long").AppendLine(); } } else { isError++; builder.Append("please enter address").AppendLine(); } if (isError > 0) { MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { return(true); } }
private bool validateUser() { int isError = 0; StringBuilder builder = new StringBuilder(); if (txt_email.Text.ToString().Length > 0) { if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString())) { isError++; builder.Append("Please enter valid email").AppendLine(); } } else { isError++; builder.Append("Please enter email").AppendLine(); } if (txt_name.Text.ToString().Length > 0) { if (Encrption.Is_Alphabetic(txt_name.Text.ToString())) { if (txt_name.Text.ToString().Length > 191) { isError++; builder.Append("Name is too long").AppendLine(); } } else { isError++; builder.Append("Name must be alphabetic").AppendLine(); } } else { isError++; builder.Append("Please enter name").AppendLine(); } if (txt_username.Text.ToString().Length > 0) { if (txt_username.Text.ToString().Length > 191) { isError++; builder.Append("Username is too long").AppendLine(); } } else { isError++; builder.Append("Please enter username").AppendLine(); } if (txt_password.Text.ToString().Length > 0) { if (txt_password.Text.ToString().Length < 6 || txt_password.Text.ToString().Length > 20) { isError++; builder.Append("Password must be in between 6 to 20 characters").AppendLine(); } } else { isError++; builder.Append("Please enter password").AppendLine(); } if (isError > 0) { MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { return(true); } }