/// <summary> /// ایجاد شماره کارمندی جدید /// </summary> /// <param name="employees">لیستی از تمام کارمندان</param> /// <returns>شماره کارمندی جدید</returns> public static EmployeeID NewEmployeeID(IList <Employee> employees) { ///[Initializing new employee id variables] GregorianCalendar greogianCalendar = new GregorianCalendar(); int l_yearPart = int.Parse(greogianCalendar.GetYear(DateTime.Now).ToString().Remove(0, 2)); int l_monthPart = greogianCalendar.GetMonth(DateTime.Now); int l_lastSerial = 0; ///[Initializing new employee id variables] ///[Determine l_lastSerial value] if (employees.Count > 0) { EmployeeID lastEmployeeID = employees.Last().EmployeeID; if (lastEmployeeID.m_monthPart == l_monthPart && lastEmployeeID.m_yearPart == l_yearPart) { l_lastSerial = lastEmployeeID.m_serialPart; } } ///[Determine l_lastSerial value] ///[New employeeID is generated and returned] EmployeeID newEmployeeID = new EmployeeID(); newEmployeeID.m_yearPart = int.Parse(greogianCalendar.GetYear(DateTime.Now).ToString().Remove(0, 2)); newEmployeeID.m_monthPart = greogianCalendar.GetMonth(DateTime.Now); newEmployeeID.m_serialPart = l_lastSerial + 1; return(newEmployeeID); ///[New employeeID is generated and returned] }
/// <summary> /// برسی صحت شماره کارمندی /// </summary> /// <param name="employeeIDinput">شماره کارمندی</param> /// <param name="dateOfEmployement">تاریخ استخدام کارمند</param> /// <returns>نتیجه برسی</returns> public static bool IsValid(EmployeeID employeeIDinput, DateTime dateOfEmployement) { ///[Validating EmployeeID] GregorianCalendar greogianCalendar = new GregorianCalendar(); int l_yearPart = int.Parse(greogianCalendar.GetYear(dateOfEmployement).ToString().Remove(0, 2)); int l_monthPart = greogianCalendar.GetMonth(dateOfEmployement); return(employeeIDinput.m_yearPart == l_yearPart && dateOfEmployement.Month == l_monthPart); ///[Validating EmployeeID] }
/// <summary> /// از رشته ورودی یک نمونه از EmployeeID می سازد. و موفقیت یا عدم موفقیت را بر می گرداند /// </summary> /// <param name="input">رشته ورودی</param> /// <param name="result">نتیجه</param> /// <returns>نتیجه Parse</returns> public static bool TryParse(string input, out EmployeeID result) { result = null; try { result = Parse(input); } catch (Exception) { return(false); } return(true); }
/// <summary> /// برسی یکسان بودن نمونه جاری با نمونه ورودی /// </summary> /// <param name="obj">نمونه وردی</param> /// <returns>نتیجه برسی</returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if ((EmployeeID)obj == null) { return(false); } EmployeeID employeeId1 = this; EmployeeID employeeId2 = (EmployeeID)obj; return((employeeId1.m_yearPart == employeeId2.m_yearPart) && (employeeId1.m_monthPart == employeeId2.m_monthPart) && (employeeId1.m_serialPart == employeeId2.m_serialPart)); }
/// <summary> /// برسی یکسان بودن نمونه جاری با نمونه ورودی /// </summary> /// <param name="obj">نمونه وردی</param> /// <returns>نتیجه برسی</returns> public override bool Equals(object obj) { bool areEqual = true; if (obj == null) { return(false); } if (!(obj is Employee)) { return(false); } Employee A = (Employee)this; Employee B = (Employee)obj; areEqual &= A.ID.Equals(B.ID); areEqual &= A.FirstName == B.FirstName; areEqual &= A.LastName == B.LastName; areEqual &= A.Gender == B.Gender; areEqual &= A.DateOfBirth == B.DateOfBirth; areEqual &= IRNationalID.Equals(A.NationalID, B.NationalID); areEqual &= A.IdentityNumber == B.IdentityNumber; areEqual &= EmployeeID.Equals(A.EmployeeID, B.EmployeeID); areEqual &= WorkSchedule.Equals(A.WorkSchedule, B.WorkSchedule); // areEqual &= A.ProfilePicture ==B.ProfilePicture; areEqual &= A.ContactInformations.Count == B.ContactInformations.Count; for (int i = 0; areEqual && i < A.ContactInformations.Count; i++) { areEqual &= ContactInformation.Equals(A.ContactInformations[i], B.ContactInformations[i]); } return(areEqual); }