public ShedulerData(string _mode, int?_id) { InitializeComponent(); manager = new ContextManager(); mode = _mode; id = _id; if (mode == "new") { StartTimeDTP.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0); EndTimeDTP.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 17, 0, 0); } if (mode == "edit" || mode == "copy") { StaffShedulersLogic shedulers = new StaffShedulersLogic(manager); sheduler = shedulers.Get(Convert.ToInt32(id)); } FillStructureObjects(); FillShifts(); FillTeams(); FillPositions(); FillAvailableEmployees(); FillSelectedEmployees(); SelectedEmployeesLB.ValueMember = "ID"; SelectedEmployeesLB.DisplayMember = "Name"; RemoveBt.Enabled = false; }
public ShedulerData(string _mode, int? _id) { InitializeComponent(); manager = new ContextManager(); mode = _mode; id = _id; if (mode == "new") { StartTimeDTP.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0); EndTimeDTP.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 17, 0, 0); } if (mode == "edit" || mode =="copy") { StaffShedulersLogic shedulers = new StaffShedulersLogic(manager); sheduler = shedulers.Get(Convert.ToInt32(id)); } FillStructureObjects(); FillShifts(); FillTeams(); FillPositions(); FillAvailableEmployees(); FillSelectedEmployees(); SelectedEmployeesLB.ValueMember = "ID"; SelectedEmployeesLB.DisplayMember = "Name"; RemoveBt.Enabled = false; }
public int Create(StaffSheduler Sheduler, int EmployeeID) { int result = 1; StaffShedulerEmployee sr = new StaffShedulerEmployee(); sr.EmployeeID = EmployeeID; sr.StaffSheduler = Sheduler; context.AddToStaffShedulerEmployees(sr); return(result); }
private void SaveBt_Click(object sender, EventArgs e) { StaffShedulersLogic shedulers = new StaffShedulersLogic(manager); StaffShedulerEmployeesLogic shedulersEmployee = new StaffShedulerEmployeesLogic(manager); int? StructureObjectId = null; int? teamId = null; int? shiftId = null; int? workPlaceId = null; DateTime startDate = StartDateDTP.Value.Add(StartTimeDTP.Value.TimeOfDay); DateTime endDate = EndDateDTP.Value.Add(EndTimeDTP.Value.TimeOfDay); string description = DescriptionTB.Text; if (StructureObjectsCB.SelectedIndex > 0) { StructureObjectId = Convert.ToInt32(StructureObjectsCB.SelectedValue); } if (TeamsCB.SelectedIndex > 0) { teamId = Convert.ToInt32(TeamsCB.SelectedValue); } if (ShiftsCB.SelectedIndex > 0) { shiftId = Convert.ToInt32(ShiftsCB.SelectedValue); } if (mode == "new" || mode == "copy") { int userId = Compas.Logic.Security.CurrentSecurityContext.Identity.ID; // Define a transaction scope for the operations. using (TransactionScope transaction = new TransactionScope()) { try { StaffSheduler sheduler = shedulers.Create(StructureObjectId, shiftId, teamId, startDate, endDate, userId, DateTime.Now, description); //додаємо працівників foreach (object item in SelectedEmployeesLB.Items) { ItemIntValue i = (ItemIntValue)item; int employeeId = i.ID; shedulersEmployee.Create(sheduler, employeeId); } } catch (Exception ex) { // Handle errors and deadlocks here and retry if needed. // Allow an UpdateException to pass through and // retry, otherwise stop the execution. if (ex.GetType() != typeof(UpdateException)) { MessageBox.Show("An error occured. " + "The operation cannot be retried." + ex.Message); } // If we get to this point, the operation will be retried. } } } if (mode == "edit") { // Define a transaction scope for the operations. using (TransactionScope transaction = new TransactionScope()) { try { shedulers.Update(Convert.ToInt32(id), StructureObjectId, shiftId, teamId, startDate, endDate, description); //додаємо працівників shedulersEmployee.DeleteBySheduler(Convert.ToInt32(id)); foreach (object item in SelectedEmployeesLB.Items) { ItemIntValue i = (ItemIntValue)item; int employeeId = i.ID; shedulersEmployee.Create(sheduler, employeeId); } } catch (Exception ex) { // Handle errors and deadlocks here and retry if needed. // Allow an UpdateException to pass through and // retry, otherwise stop the execution. if (ex.GetType() != typeof(UpdateException)) { MessageBox.Show("An error occured. " + "The operation cannot be retried." + ex.Message); } // If we get to this point, the operation will be retried. } } } manager.Save(); this.Close(); }