private bool checkInsertedUserData(List <Tuple <string, string> > userData) { bool isError = false; try { for (int i = 0; i < userData.Count; i++) { switch (userData[i].Item1) { //validate User Name case "userName": if (VALIDATION.isEmptyTextBox(userData[i].Item2)) { COM_MESSAGE.validationMessage("User Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterAndNumberOnly(userData[i].Item2)) { COM_MESSAGE.validationMessage("User Name should contains only Letters and Numbers !!!"); isError = true; } } break; //validate First Name case "firstName": if (VALIDATION.isEmptyTextBox(userData[i].Item2)) { COM_MESSAGE.validationMessage("First Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterOnly(userData[i].Item2)) { COM_MESSAGE.validationMessage("First Name should contains only Letters !!!"); isError = true; } } break; //validate Last Name case "lastName": if (VALIDATION.isEmptyTextBox(userData[i].Item2)) { COM_MESSAGE.validationMessage("Last Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterOnly(userData[i].Item2)) { COM_MESSAGE.validationMessage("Last Name should contains only Letters !!!"); isError = true; } } break; //validate NIC case "idNumber": if (VALIDATION.isEmptyTextBox(userData[i].Item2)) { COM_MESSAGE.validationMessage("NIC Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterAndNumberOnly(userData[i].Item2)) { COM_MESSAGE.validationMessage("NIC should contains only Letters and Numbers !!!"); isError = true; } } break; //validate email - it can be empty case "email": if (!VALIDATION.isEmptyTextBox(userData[i].Item2)) { if (!VALIDATION.isEmail(userData[i].Item2)) { COM_MESSAGE.validationMessage("email is not in correct format !!!"); isError = true; } } break; //validate user Role case "userRole": if (VALIDATION.isEmptyTextBox(userData[i].Item2)) { COM_MESSAGE.validationMessage("User Role Cannot be Empty !!!"); isError = true; } break; //validate Phone number case "phoneNo": if (!VALIDATION.isEmptyTextBox(userData[i].Item2)) { if (!VALIDATION.isNumberOnly(userData[i].Item2)) { COM_MESSAGE.validationMessage("Phone Number should contains only Numbers !!!"); isError = true; } } break; default: isError = true; break; } } } catch (Exception ex) { throw ex; } return(isError); }
private bool checkInsertedDealerData(List <Tuple <string, string> > dealerData) { bool isError = false; try { for (int i = 0; i < dealerData.Count; i++) { switch (dealerData[i].Item1) { case "dealerName": if (VALIDATION.isEmptyTextBox(dealerData[i].Item2)) { COM_MESSAGE.validationMessage("Dealer Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterAndNumberOnly(dealerData[i].Item2)) { COM_MESSAGE.validationMessage("Dealer Name should contains only Numbers and letters !!!"); isError = true; } } break; case "companyName": if (VALIDATION.isEmptyTextBox(dealerData[i].Item2)) { COM_MESSAGE.validationMessage("Company Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterAndNumberOnly(dealerData[i].Item2)) { COM_MESSAGE.validationMessage("Company Name should contains only Numbers and letters !!!"); isError = true; } } break; case "phoneNo": if (!VALIDATION.isEmptyTextBox(dealerData[i].Item2)) { if (!VALIDATION.isNumberOnly(dealerData[i].Item2)) { COM_MESSAGE.validationMessage("Phone Number should contains only numbers !!!"); isError = true; } } break; case "mobile": if (!VALIDATION.isEmptyTextBox(dealerData[i].Item2)) { if (!VALIDATION.isNumberOnly(dealerData[i].Item2)) { COM_MESSAGE.validationMessage("Mobile Phone Number should contains only numbers !!!"); isError = true; } } break; default: break; } } } catch (Exception ex) { throw ex; } return(isError); }
private void btn_create_Click(object sender, EventArgs e) { bool isError = false; string userName = txt_userName.Text; string firstName = txt_firstName.Text; string lastName = txt_lastName.Text; string idNumber = txt_nic.Text; string email = txt_email.Text; string userRole = dropDown_userRole.SelectedItem.ToString(); string phoneNo = txt_phoneNumber.Text; //validate User Name if (VALIDATION.isEmptyTextBox(userName)) { COM_MESSAGE.validationMessage("User Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterAndNumberOnly(userName)) { COM_MESSAGE.validationMessage("User Name should contains only Letters and Numbers !!!"); isError = true; } } //validate First Name if (VALIDATION.isEmptyTextBox(firstName)) { COM_MESSAGE.validationMessage("First Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterOnly(firstName)) { COM_MESSAGE.validationMessage("First Name should contains only Letters !!!"); isError = true; } } //validate Last Name if (VALIDATION.isEmptyTextBox(lastName)) { COM_MESSAGE.validationMessage("Last Name Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterOnly(lastName)) { COM_MESSAGE.validationMessage("Last Name should contains only Letters !!!"); isError = true; } } //validate NIC if (VALIDATION.isEmptyTextBox(idNumber)) { COM_MESSAGE.validationMessage("NIC Cannot be Empty !!!"); isError = true; } else { if (!VALIDATION.isLetterAndNumberOnly(idNumber)) { COM_MESSAGE.validationMessage("NIC should contains only Letters and Numbers !!!"); isError = true; } } //validate email - it can be empty if (!VALIDATION.isEmptyTextBox(email)) { if (!VALIDATION.isEmail(email)) { COM_MESSAGE.validationMessage("email is not in correct format !!!"); isError = true; } } //validate user Role if (VALIDATION.isEmptyTextBox(userRole)) { COM_MESSAGE.validationMessage("User Role Cannot be Empty !!!"); isError = true; } //validate Phone number if (!VALIDATION.isEmptyTextBox(phoneNo)) { if (!VALIDATION.isNumberOnly(phoneNo)) { COM_MESSAGE.validationMessage("Phone Number should contains only Numbers !!!"); isError = true; } } if (!isError) { //insert data to db CREATEUSER._userId = Convert.ToInt16(txt_userID.Text); CREATEUSER._userName = userName; CREATEUSER._firstName = firstName; CREATEUSER._lastName = lastName; CREATEUSER._dob = Convert.ToDateTime(txt_dob.Text); CREATEUSER._idNumber = idNumber; CREATEUSER._address = txt_address.Text; CREATEUSER._email = email; CREATEUSER._userRole = userRole; CREATEUSER._roleId = Convert.ToInt16(dropDown_userRole.SelectedValue); } }