public DateRecords(TimeDurationInfo tdi) { if (tdi != null) { Hours = CommonMethods.ComputeHours(tdi.StartTime, tdi.EndTime); Record = tdi.StartTime.ToString("yyyy/MM/dd HH:00") + " - " + tdi.EndTime.ToString("yyyy/MM/dd HH:00"); mTDI = tdi; } }
public TimeDurationInfo ToTimeDurationInfo() { if (Hours > 0 && Record != string.Empty) { mTDI = new TimeDurationInfo(); string[] times = Record.Split('-'); DateTime startTime = Convert.ToDateTime(times[0].Trim()); DateTime endTime = Convert.ToDateTime(times[1].Trim()); mTDI.StartTime = startTime; mTDI.EndTime = endTime; } return(mTDI); }
private static Employee PrepareData() { List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition("Email", "*****@*****.**", SearchComparator.Equal, SearchType.SearchString)); Employee employee = CommonDAL <Employee> .GetSingleObject(conditions); List <TimeDurationInfo> list = new List <TimeDurationInfo>(); list.Add(TimeDurationInfo.CreateTimeDurationInfo(DateTime.Now.AddDays(-1), DateTime.Now)); for (int i = 0; i < 150; i++) { LeaveBLL.ApplyLeave(employee.PKEmployeeID.ToString(), "test multi thread", "Annual", "test multi thread", list); } return(employee); }
public void TestTimeDurationInfoTimeStamp() { // Insert an employee role Role employeeRole = Role.CreateRole(Guid.NewGuid().ToString()); employeeRole.Save(); // Insert an employee. Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Tian", DateTime.Now, "Liu"); employee.IsActive = true; employee.ServiceYears = 10; List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, employeeRole.PKRoleID)); employee.SetRoleList(employeeRoleList); employee.Save(); Guid employeeGuid = employee.PKEmployeeID; // Insert a manager role Role managerRole = Role.CreateRole(Guid.NewGuid().ToString()); managerRole.Save(); // Insert an employee who is a manager Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu"); manager.IsActive = true; manager.ServiceYears = 8; List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>(); managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID)); manager.SetRoleList(managerRoleList); manager.Save(); Guid managerGuid = manager.PKEmployeeID; // Insert a leave type DateTime leaveTypeStartTime = Convert.ToDateTime("01/01/2000"); DateTime leaveTypeEndTime = Convert.ToDateTime("01/01/3000"); LeaveType leaveType = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime); leaveType.PKLeaveTypeID = Guid.NewGuid(); leaveType.SetKnowledgeDate(DateTime.Now); leaveType.Save(); Guid leaveTypeGuid = leaveType.PKLeaveTypeID; // Insert a leave time duration for this leave DateTime durationStartTime = Convert.ToDateTime("02/02/2001"); DateTime durationEndTime = Convert.ToDateTime("02/05/2001"); TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime); List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>(); timeDurationList.Add(timeDurationInfo); // Insert a leave info LeaveInfo leaveInfo = LeaveInfo.CreateLeaveInfo(employeeGuid, managerGuid, leaveTypeGuid, LeaveStatus.Accepted, "For Test", "Test Description", timeDurationList); leaveInfo.Save(); Guid leaveGuid = leaveInfo.PKLeaveInfoID; timeDurationInfo.FKLeaveInfoID = leaveGuid; timeDurationInfo.KnowledgeDate = DateTime.Now; timeDurationInfo.IsDeleted = false; timeDurationInfo.Save(); Guid tdGuid = timeDurationInfo.PKTDInfoID; // Get the inserted time duration info List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition("PKTDInfoID", tdGuid.ToString(), SearchComparator.Equal, SearchType.SearchString)); TimeDurationInfo testTimeDuration1 = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions); TimeDurationInfo testTimeDuration2 = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions); // Update the inseted time duratioin info testTimeDuration1.EndTime = Convert.ToDateTime("02/10/2001"); testTimeDuration1.Save(); testTimeDuration2.EndTime = Convert.ToDateTime("02/11/2002"); testTimeDuration2.Save(); // Get the updated time duration info TimeDurationInfo updatedTimeDuration = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions); Assert.AreEqual(testTimeDuration1.EndTime, updatedTimeDuration.EndTime); Assert.AreNotEqual(testTimeDuration2.EndTime, updatedTimeDuration.EndTime); // Delete inserted items timeDurationInfo.Delete(); leaveInfo.Delete(); leaveType.Delete(); employee.Delete(); manager.Delete(); employeeRole.Delete(); managerRole.Delete(); }
public void TestApproveLeave() { // Insert a manager role Role managerRole = Role.CreateRole(Guid.NewGuid().ToString()); managerRole.Save(); // Insert an employee who is a manager Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu"); manager.IsActive = true; manager.ServiceYears = 8; List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>(); managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID)); manager.SetRoleList(managerRoleList); manager.Save(); Guid managerGuid = manager.PKEmployeeID; // Insert a role Role role = Role.CreateRole(Guid.NewGuid().ToString()); role.Save(); // Insert an employee. Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji"); employee.IsActive = true; employee.ServiceYears = 10; employee.FKReportManagerID = managerGuid; List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID)); employee.SetRoleList(employeeRoleList); employee.Save(); Guid employeeGuid = employee.PKEmployeeID; // Insert a leave type DateTime leaveTypeStartTime = Convert.ToDateTime("01/01/2000"); DateTime leaveTypeEndTime = Convert.ToDateTime("01/01/3000"); LeaveType leaveType = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime); leaveType.PKLeaveTypeID = Guid.NewGuid(); leaveType.Save(); Guid leaveTypeGuid = leaveType.PKLeaveTypeID; // Insert a leave time duration for this leave DateTime durationStartTime = Convert.ToDateTime("02/02/2001"); DateTime durationEndTime = Convert.ToDateTime("02/05/2001"); TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime); DateTime durationStartTime2 = Convert.ToDateTime("02/02/2011"); DateTime durationEndTime2 = Convert.ToDateTime("02/05/2011"); TimeDurationInfo timeDurationInfo2 = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2); List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>(); timeDurationList.Add(timeDurationInfo); timeDurationList.Add(timeDurationInfo2); LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList); // Approve the applying leave. LeaveBLL.ApproveLeave(managerGuid.ToString(), leave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted); // Get the employee's leave list List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition("FKSubmitEmployeeID", employeeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString)); List <LeaveInfo> leaveList = CommonDAL <LeaveInfo> .GetObjects(conditions); Assert.IsTrue(leaveList[0].PKLeaveInfoID == leave.PKLeaveInfoID && leaveList[0].Status == LeaveStatus.Accepted); leave.Delete(); leaveType.Delete(); employee.Delete(); role.Delete(); manager.Delete(); managerRole.Delete(); }
public void TestGetMyTeamLeaves() { // Insert a manager role Role managerRole = Role.CreateRole(Guid.NewGuid().ToString()); managerRole.Save(); // Insert an employee who is a manager Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu"); manager.IsActive = true; manager.ServiceYears = 8; List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>(); managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID)); manager.SetRoleList(managerRoleList); manager.Save(); Guid managerGuid = manager.PKEmployeeID; // Insert a role Role role = Role.CreateRole(Guid.NewGuid().ToString()); role.Save(); // Insert an employee. Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji"); employee.IsActive = true; employee.ServiceYears = 10; employee.FKReportManagerID = managerGuid; List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID)); employee.SetRoleList(employeeRoleList); employee.Save(); Guid employeeGuid = employee.PKEmployeeID; // Insert a leave type DateTime leaveTypeStartTime = Convert.ToDateTime("01/01/2000"); DateTime leaveTypeEndTime = Convert.ToDateTime("01/01/3000"); LeaveType leaveType = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime); leaveType.PKLeaveTypeID = Guid.NewGuid(); leaveType.Save(); Guid leaveTypeGuid = leaveType.PKLeaveTypeID; // Insert a leave time duration for this leave DateTime durationStartTime = Convert.ToDateTime("02/02/2001"); DateTime durationEndTime = Convert.ToDateTime("02/05/2001"); TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime); DateTime durationStartTime2 = Convert.ToDateTime("02/02/2011"); DateTime durationEndTime2 = Convert.ToDateTime("02/05/2011"); TimeDurationInfo timeDurationInfo2 = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2); List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>(); timeDurationList.Add(timeDurationInfo); timeDurationList.Add(timeDurationInfo2); LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList); // Get the employee's leave list List <LeaveInfo> leaveList = LeaveBLL.GetMyTeamLeaves(managerGuid.ToString(), true); // Compare these two list bool result = leave.PKLeaveInfoID == leaveList[0].PKLeaveInfoID; if (result) { //foreach (LeaveInfo leave in leave) //{ // bool existAndEqual = false; // foreach (LeaveInfo leaveItem in leaveList) // { // if (leave.FirstStartTime == leaveItem.FirstStartTime && leave.LastEndTime == leaveItem.LastEndTime) // { // existAndEqual = true; // break; // } // } // result = existAndEqual; // if (!result) break; //} } Assert.IsTrue(result); //foreach (LeaveInfo leave in leave) //{ leave.Delete(); //} leaveType.Delete(); employee.Delete(); role.Delete(); manager.Delete(); managerRole.Delete(); }
public void TestUpdateLeaveInfoTransact() { // Insert an employee role Role employeeRole = Role.CreateRole(Guid.NewGuid().ToString()); employeeRole.Save(); // Insert an employee. Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Tian", DateTime.Now, "Liu"); employee.IsActive = true; employee.ServiceYears = 10; List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, employeeRole.PKRoleID)); employee.SetRoleList(employeeRoleList); employee.Save(); Guid employeeGuid = employee.PKEmployeeID; // Insert a manager role Role managerRole = Role.CreateRole(Guid.NewGuid().ToString()); managerRole.Save(); // Insert an employee who is a manager Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu"); manager.IsActive = true; manager.ServiceYears = 8; List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>(); managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID)); manager.SetRoleList(managerRoleList); manager.Save(); Guid managerGuid = manager.PKEmployeeID; // Insert a leave type DateTime leaveTypeStartTime = Convert.ToDateTime("01/01/2000"); DateTime leaveTypeEndTime = Convert.ToDateTime("01/01/3000"); LeaveType leaveType = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime); leaveType.PKLeaveTypeID = Guid.NewGuid(); leaveType.SetKnowledgeDate(DateTime.Now); leaveType.Save(); Guid leaveTypeGuid = leaveType.PKLeaveTypeID; // Insert a leave time duration for this leave DateTime durationStartTime = Convert.ToDateTime("02/02/2001"); DateTime durationEndTime = Convert.ToDateTime("02/05/2001"); TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime); List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>(); timeDurationList.Add(timeDurationInfo); // Insert a leave info LeaveInfo leaveInfo = LeaveInfo.CreateLeaveInfo(employeeGuid, managerGuid, leaveTypeGuid, LeaveStatus.Accepted, "For Test", "Test Description", timeDurationList); leaveInfo.Save(); Guid leaveGuid = leaveInfo.PKLeaveInfoID; // Get the leave info inserted just now List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition("PKLeaveInfoID", leaveGuid.ToString(), SearchComparator.Equal, SearchType.SearchString)); LeaveInfo testLeaveInfo = CommonDAL <LeaveInfo> .GetSingleObject(conditions); // Update the leave info testLeaveInfo.Reason = "Update test leave reason"; try { testLeaveInfo.Save(); } catch { Console.WriteLine("Throw exception for transact unit test"); } // Get the updated leave info LeaveInfo updatedLeaveInfo = CommonDAL <LeaveInfo> .GetSingleObject(conditions); Assert.AreNotEqual(testLeaveInfo.Reason, updatedLeaveInfo.Reason); // Delete the leave, leave type, employees and roles leaveInfo.Delete(); leaveType.Delete(); employee.Delete(); manager.Delete(); employeeRole.Delete(); managerRole.Delete(); }
public void TestDeleteEmployeeLeaveSummaryByApproveLeave() { // Insert a manager role Role managerRole = Role.CreateRole(Guid.NewGuid().ToString()); managerRole.Save(); // Insert an employee who is a manager Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu"); manager.IsActive = true; manager.ServiceYears = 8; List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>(); managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID)); manager.SetRoleList(managerRoleList); manager.Save(); Guid managerGuid = manager.PKEmployeeID; // Insert a role Role role = Role.CreateRole(Guid.NewGuid().ToString()); role.Save(); // Insert an employee. Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji"); employee.IsActive = true; employee.ServiceYears = 10; employee.FKReportManagerID = managerGuid; List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID)); employee.SetRoleList(employeeRoleList); employee.Save(); Guid employeeGuid = employee.PKEmployeeID; // Insert a leave type DateTime leaveTypeStartTime = Convert.ToDateTime("01/01/2000"); DateTime leaveTypeEndTime = Convert.ToDateTime("01/01/3000"); LeaveType leaveType = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime); leaveType.PKLeaveTypeID = Guid.NewGuid(); leaveType.Save(); Guid leaveTypeGuid = leaveType.PKLeaveTypeID; // Insert a leave time duration for this leave DateTime durationStartTime = Convert.ToDateTime("02/02/2001"); DateTime durationEndTime = Convert.ToDateTime("02/05/2001"); TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime); DateTime durationStartTime2 = Convert.ToDateTime("02/02/2011"); DateTime durationEndTime2 = Convert.ToDateTime("02/05/2011"); TimeDurationInfo timeDurationInfo2 = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2); List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>(); timeDurationList.Add(timeDurationInfo); timeDurationList.Add(timeDurationInfo2); int leaveHours = CommonMethods.ComputeHours(timeDurationList); LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList); // Approve the applying leave. LeaveBLL.ApproveLeave(managerGuid.ToString(), leave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted); // Get the inserted employee leave summary List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition("FKEmployeeID", employeeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString)); conditions.Add(SearchCondition.CreateSearchCondition("FKLeaveTypeID", leaveTypeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString)); EmployeeLeaveSummary employeeLeaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions); // Apply another leave DateTime durationStartTime3 = DateTime.Parse("03/04/2011"); DateTime durationEndtime3 = DateTime.Parse("03/08/2011"); TimeDurationInfo timeDurationInfo3 = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime3, durationEndtime3); DateTime durationStartTime4 = DateTime.Parse("03/10/2011"); DateTime durationEndtime4 = DateTime.Parse("03/11/2011"); TimeDurationInfo timeDurationInfo4 = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime4, durationEndtime4); List <TimeDurationInfo> timeDurationList2 = new List <TimeDurationInfo>(); timeDurationList2.Add(timeDurationInfo3); timeDurationList2.Add(timeDurationInfo4); int newLeaveHours = CommonMethods.ComputeHours(timeDurationList2); LeaveInfo newLeave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "New Leave", leaveType.Name, "New Leave Desc", timeDurationList2); LeaveInfo delLeave = LeaveBLL.ApproveLeave(managerGuid.ToString(), newLeave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted); delLeave.Delete(); // Get the update leave summary EmployeeLeaveSummary updatedLeaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions); Assert.AreEqual(updatedLeaveSummary.UsedHours, leaveHours); // Delete inserted items employeeLeaveSummary.Delete(); leave.Delete(); leaveType.Delete(); employee.Delete(); manager.Delete(); managerRole.Delete(); role.Delete(); }
private void btnGenerateTestData_Click(object sender, EventArgs e) { #region Delete Data First DeleteData(); #endregion int countEmployee = 0; int countLeave = 0; List <Guid> managerIDs = new List <Guid>(); #region Check Input if (!Int32.TryParse(txtCountEmployee.Text, out countEmployee)) { MessageBox.Show("Count of Employees must be a number."); return; } if (!Int32.TryParse(txtCountLeave.Text, out countLeave)) { MessageBox.Show("Count of level records for each employee must be a number."); return; } // we don't have more than 200 employees in BJ office. if (countEmployee > 200 || countEmployee < 1) { MessageBox.Show("We don't have more than 200 employees in BJ office.\r\nCount of Employees must >=1 and <201."); return; } // each employee can ask 150 leaves for a year? don't believe so if (countLeave > 150 || countLeave < 0) { MessageBox.Show("Each employee can ask 150 leaves for a year? Don't believe so.\r\nCount of level records for each employee must >=0 and <151."); return; } #endregion #region Add Role - Manager/Admin/Employee WriteLog("<< TEST DATA >>\r\n"); WriteLog("\r\n==Roles==\r\n"); // Stanley add: Our Real data is "Admin"/"Manager" and "Employee" string strManagerRole = "Manager"; Role roleManager = Role.CreateRole(strManagerRole); roleManager.Save(); //List<EmployeeRoleRL> employeeRoleList_Manager = new List<EmployeeRoleRL>(); //employeeRoleList_Manager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID)); WriteLog("Role: Manager\r\n"); // Stanley add: Our Real data is "Admin"/"Manager" and "Employee" string strAdminRole = "Admin"; Role roleAdmin = Role.CreateRole(strAdminRole); roleAdmin.Save(); //List<EmployeeRoleRL> employeeRoleList_Admin = new List<EmployeeRoleRL>(); //employeeRoleList_Admin.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID)); WriteLog("Role: Admin\r\n"); // Stanley add: Our Real data is "Admin"/"Manager" and "Employee" string strEmployeeRole = "Employee"; Role roleEmployee = Role.CreateRole(strEmployeeRole); roleEmployee.Save(); //List<EmployeeRoleRL> employeeRoleList_Employee = new List<EmployeeRoleRL>(); //employeeRoleList_Employee.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID)); WriteLog("Role: Employee\r\n"); #endregion #region Add Leave Type, 7 types actually /** * Annual Leave * Bereavement Leave * Marriage Leave * Maternity Leave * Paternity Leave * Regular Check * Sick Leave */ WriteLog("\r\n==Leave Types==\r\n"); string leave_Annual = "Annual Leave"; LeaveType leaveType_Annual = LeaveType.CreateLeaveType(leave_Annual, 120, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType_Annual.Save(); WriteLog("\r\nLeave Type: Annual Leave\r\n"); string leave_Sick = "Sick Leave"; LeaveType leaveType_Sick = LeaveType.CreateLeaveType(leave_Sick, 80, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType_Sick.Save(); WriteLog("Leave Type: Sick Leave\r\n"); string leave_Marriage = "Marriage Leave"; LeaveType leaveType_Marriage = LeaveType.CreateLeaveType(leave_Marriage, 80, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType_Marriage.Save(); WriteLog("Leave Type: Marriage Leave\r\n"); // only for female string leave_Maternity = "Maternity Leave"; LeaveType leaveType_Maternity = LeaveType.CreateLeaveType(leave_Maternity, 960, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType_Maternity.Save(); WriteLog("Leave Type: Maternity Leave\r\n"); // only for male string leave_Paternity = "Paternity Leave"; LeaveType leaveType_Paternity = LeaveType.CreateLeaveType(leave_Paternity, 40, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType_Paternity.Save(); WriteLog("Leave Type: Paternity Leave\r\n"); // only for female string leave_RegularCheck = "Regular Check Leave"; LeaveType leaveType_RegularCheck = LeaveType.CreateLeaveType(leave_RegularCheck, 80, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType_RegularCheck.Save(); WriteLog("Leave Type: Regular Check Leave\r\n"); string leave_Bereavement = "Bereavement Leave"; LeaveType leaveType_Bereavement = LeaveType.CreateLeaveType(leave_Bereavement, 80, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType_Bereavement.Save(); WriteLog("Leave Type: Bereavement Leave\r\n"); #endregion #region Add a default (root) manager, it's rchou or hniu actually, here using rchou as example. Employee rootManager = Employee.CreateEmployee("*****@*****.**", CryptographyStuff.AES_EncryptString("1234"), Sex.Male, "Richard", Convert.ToDateTime("1/1/2001"), "Chou"); List <EmployeeRoleRL> employeeRoleList_RootManager = new List <EmployeeRoleRL>(); employeeRoleList_RootManager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID)); employeeRoleList_RootManager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID)); employeeRoleList_RootManager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID)); rootManager.SetRoleList(employeeRoleList_RootManager); // manager & admin & employee rootManager.IsActive = true; rootManager.Save(); rootManager.IsAdmin = rootManager.IsManager = true; managerIDs.Add(rootManager.PKEmployeeID); // managerIDs[0] is rchou's GUID WriteLog("\r\n==Test data of Users==\r\n"); WriteLog("=====================================================================\r\n"); WriteLog("Name\t\tIsManager\tIsAdmin\tBelong to\tLeave Counts\r\n"); WriteLog("=====================================================================\r\n"); WriteLog(rootManager.Email.Replace("@Advent.com", "") + "\t\t" + rootManager.IsManager.ToString() + "\t\t" + rootManager.IsAdmin.ToString() + "\t \t\t0\r\n"); WriteLog("---------------------------------------------------------------------\r\n"); #endregion #region As Shan said, create two test accounts, Admin(super-user) and Manager. // test account [email protected] (admin and manager) Employee adminAccount = Employee.CreateEmployee("*****@*****.**", CryptographyStuff.AES_EncryptString("1234"), Sex.Female, "Admin", Convert.ToDateTime("1/1/2001"), "Test"); List <EmployeeRoleRL> adminRoleList_EmployeeAccount = new List <EmployeeRoleRL>(); adminRoleList_EmployeeAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID)); adminRoleList_EmployeeAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID)); adminRoleList_EmployeeAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID)); adminAccount.SetRoleList(adminRoleList_EmployeeAccount); // admin, manager and employee adminAccount.IsActive = true; adminAccount.FKReportManagerID = rootManager.PKEmployeeID; // report to Richard adminAccount.Save(); adminAccount.IsAdmin = adminAccount.IsManager = true; managerIDs.Add(adminAccount.PKEmployeeID); // managerIDs[1] is testAdmin's GUID WriteLog(adminAccount.Email.Replace("@Advent.com", "") + "\t\t" + adminAccount.IsManager.ToString() + "\t\t" + adminAccount.IsAdmin.ToString() + "\t" + rootManager.Email.Replace("@Advent.com", "") + "\t\t"); WriteLog("0\r\n"); WriteLog("---------------------------------------------------------------------\r\n"); // test account [email protected] Employee managerAccount = Employee.CreateEmployee("*****@*****.**", CryptographyStuff.AES_EncryptString("1234"), Sex.Male, "Manager", Convert.ToDateTime("1/1/2001"), "Test"); List <EmployeeRoleRL> employeeRoleList_ManagerAccount = new List <EmployeeRoleRL>(); employeeRoleList_ManagerAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID)); employeeRoleList_ManagerAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID)); managerAccount.SetRoleList(employeeRoleList_ManagerAccount); // manager & employee managerAccount.IsActive = true; managerAccount.FKReportManagerID = adminAccount.PKEmployeeID; // report to admin managerAccount.Save(); managerAccount.IsManager = true; managerIDs.Add(managerAccount.PKEmployeeID); // managerIDs[2] is testManager's GUID WriteLog(managerAccount.Email.Replace("@Advent.com", "") + "\t\t" + managerAccount.IsManager.ToString() + "\t\t" + managerAccount.IsAdmin.ToString() + "\t" + adminAccount.Email.Replace("@Advent.com", "") + "\t\t"); WriteLog("0\r\n"); WriteLog("---------------------------------------------------------------------\r\n"); #endregion #region Create an employee randomlly int index = 0; string employeeName = ""; Sex sex = Sex.Male; // create employees (admins and managers) while (countEmployee > 0) { bool isAdmin = false; bool isManager = false; Random random = new Random((int)DateTime.Now.Ticks); index++; List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); switch ((index - 1) % 6) // many employees, few admins and managers { case 0: employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID)); employeeName = "m" + index.ToString("000") + "@Advent.com"; isManager = true; break; case 1: employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID)); employeeName = "a" + index.ToString("000") + "@Advent.com"; isAdmin = true; break; case 2: employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID)); employeeName = "e" + index.ToString("000") + "@Advent.com"; break; default: employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID)); employeeName = "e" + index.ToString("000") + "@Advent.com"; break; } if (random.Next(100) % 3 == 0) { sex = Sex.Female; // 1/3 people are female } int tempDay = -random.Next(30, 720); Employee employee = Employee.CreateEmployee(employeeName, CryptographyStuff.AES_EncryptString("1234"), sex, //Sex.Male, string.Format(newFirstName, index.ToString("000")) + employeeName[0], DateTime.Now.AddDays(tempDay), string.Format(newLastName, index.ToString("000")) + employeeName[0]); employee.SetRoleList(employeeRoleList); employee.IsActive = true; if (employeeName.StartsWith("m")) // a manager { employee.FKReportManagerID = managerIDs[0]; // manager reports to root manager } else if (employeeName.StartsWith("a")) // a admin { employee.FKReportManagerID = managerIDs[0]; // admin reports to root manager } else { Random randomTemp = new Random((int)DateTime.Now.Ticks); if (managerIDs.Count == 1) { employee.FKReportManagerID = managerIDs[0]; // only have one manager } else if (managerIDs.Count == 2) { employee.FKReportManagerID = managerIDs[1]; // normally, others employees belong to a normal manager, not root manager } else { int tempIndex = randomTemp.Next(1, managerIDs.Count - 1); employee.FKReportManagerID = managerIDs[tempIndex]; } } employee.Save(); employee.IsManager = isManager; employee.IsAdmin = isAdmin; Employee tempManager = EmployeeBLL.GetEmployeeByID(employee.FKReportManagerID.ToString()); WriteLog(employee.Email.Replace("@Advent.com", "") + "\t\t" + employee.IsManager.ToString() + "\t\t" + employee.IsAdmin.ToString() + "\t" + tempManager.Email.Replace("@Advent.com", "") + "\t\t"); // add manager to management team if (employeeName.StartsWith("m")) { managerIDs.Add(employee.PKEmployeeID); } int count = countLeave; int leaves = 0; while (count > 0) { string name = string.Empty; switch (random.Next(100) % 7) { case 0: name = leave_Annual; break; case 1: name = leave_Sick; break; case 2: name = leave_Marriage; break; case 3: name = leave_Bereavement; break; case 4: name = leave_Maternity; break; case 5: name = leave_Paternity; break; case 6: name = leave_RegularCheck; break; default: name = leave_Annual; break; } #region Create Random TimeDurationInfo Random randomForTimeDurationInfo = new Random((int)DateTime.Now.Ticks); List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>(); for (int i = 0; i < randomForTimeDurationInfo.Next(5); i++) { DateTime durationStartTime = DateTime.Now; DateTime durationEndTime = DateTime.Now; GenerateStartEndTime(ref durationStartTime, ref durationEndTime); TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime); timeDurationList.Add(timeDurationInfo); } #endregion if (timeDurationList.Count > 0) { LeaveBLL.ApplyLeave(employee.PKEmployeeID.ToString(), "generated automatically", name, "generated automatically", timeDurationList); leaves++; } count--; } WriteLog(leaves.ToString() + "\r\n"); WriteLog("---------------------------------------------------------------------\r\n"); countEmployee--; } #endregion if (MessageBox.Show("Finished!") == System.Windows.Forms.DialogResult.OK) { Process.Start(logFile); } }
private void btnGenerateData_Click(object sender, EventArgs e) { int countEmployee = Int32.Parse(txtCountEmployee.Text); int countLeave = Int32.Parse(txtCountLeave.Text); string roleName1 = RoleRank.Admin.ToString(); Role role1 = Role.GetRoleByName(roleName1); if (null == role1) { role1 = Role.CreateRole(roleName1); role1.Save(); } string roleName2 = RoleRank.Manager.ToString(); Role role2 = Role.GetRoleByName(roleName2); if (null == role2) { role2 = Role.CreateRole(roleName2); role2.Save(); } string roleName3 = RoleRank.Employee.ToString(); Role role3 = Role.GetRoleByName(roleName3); if (null == role3) { role3 = Role.CreateRole(roleName3); role3.Save(); } // Add a default manager. Employee manager = Employee.CreateEmployee(string.Format(emplyeeName, Guid.NewGuid().ToString().Substring(0, 5)), CryptographyStuff.AES_EncryptString("1234"), Sex.Male, string.Format(firstName, Guid.NewGuid().ToString().Substring(0, 5)), Convert.ToDateTime("1/1/2011"), string.Format(lastName, Guid.NewGuid().ToString().Substring(0, 5))); List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role2.PKRoleID)); manager.SetRoleList(employeeRoleList); manager.IsActive = true; manager.Save(); Guid managerID = manager.PKEmployeeID; string leaveTypeName1 = string.Format(leaveTypeName, Guid.NewGuid().ToString().Substring(0, 5)); LeaveType leaveType1 = LeaveType.CreateLeaveType(leaveTypeName1, 100, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType1.Save(); string leaveTypeName2 = string.Format(leaveTypeName, Guid.NewGuid().ToString().Substring(0, 5)); LeaveType leaveType2 = LeaveType.CreateLeaveType(leaveTypeName2, 100, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType2.Save(); string leaveTypeName3 = string.Format(leaveTypeName, Guid.NewGuid().ToString().Substring(0, 5)); LeaveType leaveType3 = LeaveType.CreateLeaveType(leaveTypeName3, 100, Convert.ToDateTime("1/1/2010"), Convert.ToDateTime("1/1/2011")); leaveType3.Save(); DateTime durationStartTime = Convert.ToDateTime("02/02/2001"); DateTime durationEndTime = Convert.ToDateTime("02/05/2001"); DateTime durationStartTime2 = Convert.ToDateTime("02/02/2011"); DateTime durationEndTime2 = Convert.ToDateTime("02/05/2011"); while (countEmployee > 0) { employeeRoleList = new List <EmployeeRoleRL>(); switch (countEmployee % 3) { case 0: // Admin employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role1.PKRoleID)); break; case 1: // Manager employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role2.PKRoleID)); break; case 2: // Employee employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role3.PKRoleID)); break; default: // Employee employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role3.PKRoleID)); break; } Employee employee = Employee.CreateEmployee(string.Format(emplyeeName, Guid.NewGuid().ToString().Substring(0, 5)), CryptographyStuff.AES_EncryptString("1234"), Sex.Male, string.Format(firstName, Guid.NewGuid().ToString().Substring(0, 5)), Convert.ToDateTime("1/1/2011"), string.Format(lastName, Guid.NewGuid().ToString().Substring(0, 5))); employee.SetRoleList(employeeRoleList); employee.IsActive = true; employee.FKReportManagerID = managerID; employee.Save(); // Set the manager id as the employee who is manager. if (countEmployee % 3 == 1) { managerID = employee.PKEmployeeID; } int count = countLeave; while (count > 0) { string name = string.Empty; switch (countLeave % 3) { case 0: name = leaveTypeName1; break; case 1: name = leaveTypeName2; break; case 2: name = leaveTypeName3; break; default: name = leaveTypeName1; break; } List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>(); TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime); TimeDurationInfo timeDurationInfo2 = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2); timeDurationList.Add(timeDurationInfo); timeDurationList.Add(timeDurationInfo2); LeaveBLL.ApplyLeave(employee.PKEmployeeID.ToString(), "generated automatically", name, "generated automatically", timeDurationList); count--; } countEmployee--; } MessageBox.Show("Finished!"); }