private void view_Click(object sender, RoutedEventArgs e)
 {
     //Method to display schedule when picked in the table
     //If there are multiple schedules selected, open up all of them
     foreach (DataRowView item in GeneratedSchedules.SelectedItems)
     {
         DataRowView        drv  = GeneratedSchedules.Items.GetItemAt(GeneratedSchedules.SelectedIndex) as DataRowView;
         DateTime           date = Convert.ToDateTime(drv["Date"]);
         ScheduleController sc   = new ScheduleController();
         //Get the correct date of the schedule to be deleted
         Schedule s = sc.getScheduleByDate(date);
         //If there is no schedule on that date, throw an error
         if (s.Id == null)
         {
             System.Windows.MessageBox.Show("No Schedule Generated", "Error");
         }
         ScheduleWindow ss = new ScheduleWindow(date);
         ss.Show();
     }
 }
示例#2
0
        public void GenerateButton_Click(object sender, RoutedEventArgs e)
        {
            if (App.ISADMIN == false)
            {
                //If the user is not an admin, they are not allowed to create a schedule
                PermissionController pc = new PermissionController();
                Permission           p  = pc.getPermissions();
                if (p.GenerateSchedule == false)
                {
                    MessageBoxButton button = MessageBoxButton.OK;
                    MessageBoxImage  icon   = MessageBoxImage.Error;
                    System.Windows.MessageBox.Show("Sorry! You do not have permission to generate a schedule", "Error", button, icon);
                }
            }
            else
            {
                //Create a progress bar to track the progress of the schedule building
                System.Windows.Controls.ProgressBar pBar = new System.Windows.Controls.ProgressBar();
                pBar.Visibility = Visibility.Visible;

                ScheduleController sc = new ScheduleController();
                Schedule           t  = sc.getScheduleByDate(DateTime.Today);
                //Update the progress bar
                this.pBar.Value = 20;
                if (t.Id != null)
                {
                    MessageBoxImage  icon   = MessageBoxImage.Warning;
                    MessageBoxButton button = MessageBoxButton.YesNo;
                    MessageBoxResult result = System.Windows.MessageBox.Show("There was already a schedule made today. Would you like to overwrite it?", "Capstone Employee Scheduler", button, icon);
                    if (result == MessageBoxResult.No)
                    {
                        return;
                    }
                    else if (result == MessageBoxResult.Yes)
                    {
                        //If they choose to overwrite the schedule, delete the old one
                        this.pBar.Value = 30;
                        sc.deleteSchedule(t.Id);
                    }
                }
                //Update the progress bar
                this.pBar.Value = 40;

                //Create a new schedule with all the users and roles in the database
                Schedule       s     = new Schedule();
                MakeSchedule   ms    = new MakeSchedule();
                List <User>    users = new List <User>();
                UserController uc    = new UserController();
                this.pBar.Value = 50;
                //Get all the users without roles beforehand to speed up scheduling process
                users           = uc.getAllUsersWithRoleId();
                this.pBar.Value = 60;
                List <int> rolecounts = new List <int>();
                int        q;
                foreach (User u in users)
                {
                    q = u.Roles.Count();
                    rolecounts.Add(q);
                }
                this.pBar.Value = 70;

                /*  if (rolecounts.Contains(1))
                 * {
                 *    MessageBoxImage icon = MessageBoxImage.Warning;
                 *    MessageBoxButton button = MessageBoxButton.OK;
                 *    System.Windows.MessageBox.Show("One or more employees are only trained in one role. This may cause scheudling problems", "Capstone Employee Scheduler", button, icon);
                 * }
                 */
                this.pBar.Value = 80;
                ms.Generate(users, DateTime.Today);
                this.pBar.Value = 100;
                //Display the schedule once it is generated
                ScheduleWindow x = new ScheduleWindow(DateTime.Today);
                x.ShowDialog();
                //Reset the progress bar
                this.pBar.Value = 0;
            }
        }