示例#1
0
        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;
        }
示例#2
0
 private void DeleteSB_Click(object sender, EventArgs e)
 {
     StaffShedulersLogic shedulers = new StaffShedulersLogic(manager);
     shedulers.Delete(Convert.ToInt32(DataGV.SelectedRows[0].Cells["ID"].Value));
     manager.Save();
     Fill();
 }
示例#3
0
        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;
        }
示例#4
0
        private void DeleteSB_Click(object sender, EventArgs e)
        {
            StaffShedulersLogic shedulers = new StaffShedulersLogic(manager);

            shedulers.Delete(Convert.ToInt32(DataGV.SelectedRows[0].Cells["ID"].Value));
            manager.Save();
            Fill();
        }
示例#5
0
        private void Fill()
        {
            //int enterpriseId = Convert.ToInt32(
            StaffShedulersLogic shedulers = new StaffShedulersLogic(manager);

            DataGV.AutoGenerateColumns = false;
            DataGV.DataSource          = shedulers.GetAll(
                enterpriseStructureUC1.StructureObjectID,
                enterpriseStructureUC1.ShiftID,
                enterpriseStructureUC1.TeamID,
                enterpriseStructureUC1.StartDate).Select(a => new { a.ID,

                                                                    StructureObjectName = a.StaffStructureObject != null ? a.StaffStructureObject.Name : "",
                                                                    ShiftName           = a.StaffShift != null ? a.StaffShift.Name : "",
                                                                    TeamName            = a.StaffTeam != null ? a.StaffTeam.Name : "",
                                                                    a.StartDate,
                                                                    a.EndDate,
                                                                    a.Description }).ToList();
            DataGV.Update();
        }
示例#6
0
        private void Fill()
        {
            //int enterpriseId = Convert.ToInt32(
            StaffShedulersLogic shedulers = new StaffShedulersLogic(manager);
            DataGV.AutoGenerateColumns = false;
            DataGV.DataSource = shedulers.GetAll(
                enterpriseStructureUC1.StructureObjectID,
                enterpriseStructureUC1.ShiftID,
                enterpriseStructureUC1.TeamID,
                enterpriseStructureUC1.StartDate).Select(a => new {a.ID,

                    StructureObjectName = a.StaffStructureObject != null ? a.StaffStructureObject.Name : "",
                    ShiftName = a.StaffShift != null ? a.StaffShift.Name : "",
                    TeamName = a.StaffTeam != null ? a.StaffTeam.Name : "",
                    a.StartDate,
                    a.EndDate,
                    a.Description
                }).ToList();
            DataGV.Update();
        }
示例#7
0
        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();
        }
示例#8
0
        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();
        }