/// <summary> /// Validated date /// </summary> /// <param name="date"></param> /// <param name="type"></param> /// <returns></returns> public bool ValidateDate(string date, dateType type) { bool valid = false; //!< bool if date was valid CultureInfo culture; //!< Culture information culture = CultureInfo.CreateSpecificCulture("en-US"); //!< Culture of date string[] formats = { "yyyy/MM/dd", "yyyy/M/dd", "yyyy/M/d", "yyyy/MM/d" }; //!< Date format DateTime dateValue; //!< Date value if (DateTime.TryParseExact(date, formats, new CultureInfo("en-US"), DateTimeStyles.None, out dateValue)) { switch (type) { case dateType.HIRE: dateOfHire = dateValue; if ((this.dateOfBirth==null||dateValue >= dateOfBirth )&& dateValue <= DateTime.Now) { valid = true; } else { if (dateValue <= dateOfBirth) { //AddToLogString("\tDate of Hire Error: Must be after the employee was born."); employeeEx.AddError("\tDate of Hire Error: Must be after the employee was born."); } else { //AddToLogString("\tDate of Hire Error: Must be before the current date."); employeeEx.AddError("\tDate of Hire Error: Must be before the current date."); } } break; case dateType.TERMINATE: dateOfTermination = dateValue; if (dateValue >= dateOfHire && dateValue <= DateTime.Now) { valid = true; } else { if (dateValue <= dateOfHire) { //AddToLogString("\tDate of Termination Error: Must be after the employee was born."); employeeEx.AddError("\tDate of Termination Error: Must be after the employee was hired."); } else { //AddToLogString("\tDate of Termination Error: Must be before the current date."); employeeEx.AddError("\tDate of Termination Error: Must be before the current date."); } } break; } } else { if (type == dateType.HIRE) { //AddToLogString("\tDate of Hire Error: Invalid format.\n||\t\tTried: " + date); employeeEx.AddError("\tDate of Hire Error: Invalid format. Tried: " + date); } else if(type == dateType.TERMINATE) { //AddToLogString("\tDate of Termination Error: Invalid format.\n||\t\tTried: " + date); employeeEx.AddError("\tDate of Termination Error: Invalid format. Tried: " + date); } } return valid; }
/// <summary> /// Validate BusinessNumber that follows the bussiness rules and formating of the information /// </summary> /// <param name="businessNumber"></param> /// <returns>validSin</returns> /*private bool ValidateBusinessNumber(string businessNumber) { int newSin = 0; //!< SIN try { Int32.TryParse(businessNumber.Replace(" ", string.Empty), out newSin); } catch(FormatException e) { employeeEx.AddError("\tBusiness Number Error: " + e.Message + " Tried: " + businessNumber); //AddToLogString("Business Number Error: " + e.Message + " \n||\t\tTried: " + businessNumber); } int[] tempSin = new int[9]; ///< int array int[] sin = new int[9]; ///< int array int[] year = new int[4]; ///< int array int tempYear = dateOfBirth.Year; double totalSin = 0; ///<totalSin bool validSin = false; ///< bool which gets return indicating if it was valid int toAdd = 0; //!< Amount to add int theSin = newSin; //!< assign theSin to newSin for (int x = 8; x >= 0; x--) //splits the SIN into an array { sin[x] = newSin % 10; newSin /= 10; } for(int x = 3; x >= 0; x--) { year[x] = tempYear % 10; tempYear /= 10; } if (sin[0] == year[2] && sin[1] == year[3]) { for (int x = 0; x < 8; x++) { toAdd = sinCheck[x] * sin[x]; if (toAdd >= 10) { toAdd = (toAdd % 10) + (toAdd / 10); } totalSin += toAdd; } if ((Math.Ceiling(totalSin / 10) * 10 - totalSin) == sin[8]) { validSin = true; } else { //AddToLogString("\tBusiness Number Error: Not a valid business number"); employeeEx.AddError("\tBusiness Number Error: Not a valid business number. Tried: " + businessNumber); } } else if (theSin == 0) { validSin = true; } else { //AddToLogString("\tBusiness Number Error: First two digits must match the company's date of incorporation."); //employeeEx.AddError("Business Number Error: First two digits must match the company's date of incorporation."); } return validSin; }*/ /// <summary> /// Validating all dates for the contract employees /// </summary> /// <param name="date"></param> /// <param name="type"></param> /// <returns></returns> public bool ValidateDate(string date, dateType type) { bool valid = false; //!< validation on date CultureInfo culture; //!< culture format culture = CultureInfo.CreateSpecificCulture("en-US"); //!< en-US usa style of date string[] formats = { "yyyy/MM/dd", "yyyy/M/dd", "yyyy/M/d", "yyyy/MM/d" }; //!< different date format DateTime dateValue; if (DateTime.TryParseExact(date, formats, new CultureInfo("en-US"), DateTimeStyles.None, out dateValue)) { switch (type) { case dateType.CONTRACT_START: contractStartDate = dateValue; if (dateValue >= dateOfBirth && dateValue <= DateTime.Now) { valid = true; } else { if (dateValue <= dateOfBirth) { //AddToLogString("\tContract Start Date Error: Must be after the company was created."); employeeEx.AddError("\tContract Start Date Error: Must be after the company was created."); } else { //AddToLogString("\tContract Start Date Error: Must be before the current date."); employeeEx.AddError("\tContract Start Date Error: Must be before the current date."); } } break; case dateType.CONTRACT_END: contractStopDate = dateValue; if (dateValue >= contractStartDate && dateValue <= DateTime.Now) { valid = true; } else { if (dateValue <= dateOfBirth) { //AddToLogString("\tContract Stop Date Error: Must be after the company was created."); employeeEx.AddError("\tContract Stop Date Error: Must be after the company was created."); } else { //AddToLogString("\tContract Stop Date Error: Must be before the current date."); employeeEx.AddError("\tContract Stop Date Error: Must be before the current date."); } } break; } } else { if (type == dateType.CONTRACT_START) { //AddToLogString("\tContract Start Date Error: Invalid format.\n||\t\tTried: " + date); employeeEx.AddError("\tContract Start Date Error: Invalid format. Tried: " + date); } else if (type == dateType.CONTRACT_END) { employeeEx.AddError("\tContract Stop Date Error: Invalid format. Tried: " + date); //AddToLogString("\tContract Stop Date Error: Invalid format.\n||\t\tTried: " + date); } } return valid; }