public int ValidateDeptDtls(EntityAddDepartment objEntityAddDept) { var reg = new Regex("^[a-zA-Z ]*$"); int res = 0; if (!reg.IsMatch(objEntityAddDept.DeptName) || String.IsNullOrWhiteSpace(objEntityAddDept.DeptName) || objEntityAddDept.DeptName.Length > 25) { if (String.IsNullOrWhiteSpace(objEntityAddDept.DeptName)) { throw new ArgumentNullException(); } else if (objEntityAddDept.DeptName.Length > 25) { throw new ArgumentOutOfRangeException(); } else { throw new ArgumentException(); } } else if (objEntityAddDept.DeptSal < 10000 || objEntityAddDept.DeptSal > 2000000) { throw new ArgumentOutOfRangeException(); } else if (double.TryParse(objEntityAddDept.DeptLoc, out double _) || String.IsNullOrWhiteSpace(objEntityAddDept.DeptLoc)) { if (String.IsNullOrWhiteSpace(objEntityAddDept.DeptLoc)) { throw new ArgumentNullException(); } else { throw new ArgumentException(); } } else { res = 1; } return(res); }
public int BusinessAddDeptDtls(EntityAddDepartment objEntityAddDept) { if (ValidateDeptDtls(objEntityAddDept) == 1) { SqlParameter[] objDataParams = new SqlParameter[3]; objDataParams[0] = new SqlParameter("@DeptName", SqlDbType.VarChar, 25) { Value = objEntityAddDept.DeptName }; objDataParams[1] = new SqlParameter("@DeptSalary", SqlDbType.VarChar, 25) { Value = objEntityAddDept.DeptSal }; objDataParams[2] = new SqlParameter("@DeptLocation", SqlDbType.VarChar, 25) { Value = objEntityAddDept.DeptLoc }; int result; try { result = objDataAddDept.DataAddDepartmentDetails(objDataParams); } catch (SqlException) { return(4); } return(result); } return(3); }
public void StoreData(string name, string sal, string loc) { int result = 0; var reg = new Regex("^[a-zA-Z ]*$"); if (double.TryParse(sal, out double _)) { objEntityAddDept = new EntityAddDepartment { DeptName = name.Trim(), DeptSal = Convert.ToDouble(sal), DeptLoc = loc }; if (!reg.IsMatch(objEntityAddDept.DeptName) || String.IsNullOrWhiteSpace(objEntityAddDept.DeptName) || objEntityAddDept.DeptName.Length > 25) { if (objEntityAddDept.DeptName.Any(char.IsDigit)) { MessageBox.Show("Invalid Department Name. Only Alphabets allowed!"); } else if (objEntityAddDept.DeptName.Length > 25) { MessageBox.Show("Department name must be less than 25 characters!"); } else { MessageBox.Show("Invalid Department Name. Null/Empty Not Allowed!"); } } else if (objEntityAddDept.DeptSal < 10000 || objEntityAddDept.DeptSal > 1000000) { MessageBox.Show("Invalid Salary. Must be an int in between 10000 and 1000000!"); } else if (String.IsNullOrWhiteSpace(objEntityAddDept.DeptLoc)) { MessageBox.Show("Invalid Location. Null/Empty not allowed!"); } else { result = Businessobj.BusinessAddDeptDtls(objEntityAddDept); if (result == 0) { MessageBox.Show("Error occured. Department not Added."); } else if (result == 1) { MessageBox.Show("Department Successfully Added"); } else if (result == 3) { MessageBox.Show("Program Error Occurred"); } else { MessageBox.Show("Department Id already Exist!"); } } } else if (!double.TryParse(sal, out double _)) { MessageBox.Show("Invalid Department Salary Must be only Digits!"); } }
public AddDeptDtls() { InitializeComponent(); objEntityAddDept = new EntityAddDepartment(); Businessobj = new BusinessAddDepartment(); }
public void Init() { objBusinessAddDept = new BusinessAddDepartment(); objEntityAddDept = new EntityAddDepartment(); }