Пример #1
0
        private void DeleteShift_Click(object sender, RoutedEventArgs e)
        {
            EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter sAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter();

            EmployeeScheduleDatabaseDataSet.ShiftTableDataTable shiftData = sAdapter.GetData();

            try
            {
                EmployeeScheduleDatabaseDataSet.ShiftTableRow delRow =
                    shiftData.FindByShiftId(selectedShift.ShiftId);

                delRow.Delete();

                sAdapter.Update(delRow);

                allShifts.Remove(selectedShift);
                ShiftList.ItemsSource = null;
                ShiftList.ItemsSource = allShifts;
                System.Windows.MessageBox.Show("Shift Deleted!");
                PopShiftList();
            }
            catch
            {
                System.Windows.MessageBox.Show("whoops");
            }
        }
Пример #2
0
        public void PullData()
        {
            if (allSShifts != null)
            {
                allSShifts.Clear();
            }

            EmployeeScheduleDatabaseDataSetTableAdapters.ScheduledShiftTableAdapter SSAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ScheduledShiftTableAdapter();

            EmployeeScheduleDatabaseDataSet.ScheduledShiftDataTable sshiftdata = SSAdapter.GetData();

            EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter SAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter();

            EmployeeScheduleDatabaseDataSet.ShiftTableDataTable shiftdata = SAdapter.GetData();

            EmployeeScheduleDatabaseDataSetTableAdapters.EmployeesTableAdapter empAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.EmployeesTableAdapter();

            EmployeeScheduleDatabaseDataSet.EmployeesDataTable empdata = empAdapter.GetData();

            foreach (EmployeeScheduleDatabaseDataSet.ScheduledShiftRow row in sshiftdata)
            {
                ScheduledShift tempSShift = new ScheduledShift();
                tempSShift.SShiftId      = row.SShiftId;
                tempSShift.ScheduledDate = row.Date;
                tempSShift.Starttime     = shiftdata.FindByShiftId(row.ShiftId).StartTime;
                tempSShift.Endtime       = shiftdata.FindByShiftId(row.ShiftId).EndTime;
                tempSShift.EmpName       = empdata.FindByempId(row.EmpId).firstName + " " + empdata.FindByempId(row.EmpId).lastName;


                allSShifts.Add(tempSShift);
            }
        }
Пример #3
0
        public void PopShiftList()
        {
            EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter sAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter();

            EmployeeScheduleDatabaseDataSet.ShiftTableDataTable shiftData = sAdapter.GetData();



            foreach (EmployeeScheduleDatabaseDataSet.ShiftTableRow row in shiftData)
            {
                Shift tempShift = new Shift();
                tempShift.ShiftId   = row.ShiftId;
                tempShift.ShiftName = row.ShiftName;
                tempShift.StartTime = row.StartTime.ToString();
                tempShift.EndTime   = row.EndTime.ToString();
                allShifts.Add(tempShift);
            }

            ShiftList.ItemsSource = allShifts;
            dv = new DataView(shiftData);
        }
Пример #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter sAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter();

            EmployeeScheduleDatabaseDataSet.ShiftTableDataTable shiftData = sAdapter.GetData();
            if (StartTimePicker.Value > EndTimePicker.Value)
            {
                System.Windows.MessageBox.Show("Start time must be before end time.");
                return;
            }

            if (updateShift != null)
            {
                EmployeeScheduleDatabaseDataSet.ShiftTableRow editRow =
                    shiftData.FindByShiftId(updateShift.ShiftId);


                editRow.ShiftName = ShiftNameTextBox.Text;
                editRow.StartTime = DateTime.Parse(StartTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");
                editRow.EndTime   = DateTime.Parse(EndTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");



                try
                {
                    sAdapter.Update(editRow);

                    Shifts shiftWindow = new Shifts();
                    shiftWindow.Show();
                    this.Close();
                }
                catch
                {
                    System.Windows.MessageBox.Show("whoops");
                }
            }
            else
            {
                EmployeeScheduleDatabaseDataSet.ShiftTableRow newRow =
                    shiftData.NewShiftTableRow();

                newRow.ShiftId   = shiftData.Last().ShiftId + 1;
                newRow.ShiftName = ShiftNameTextBox.Text;
                newRow.StartTime = DateTime.Parse(StartTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");
                newRow.EndTime   = DateTime.Parse(EndTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");


                try
                {
                    sAdapter.Insert(newRow.ShiftId, newRow.ShiftName, newRow.StartTime, newRow.EndTime);

                    Shifts shiftWindow = new Shifts();
                    shiftWindow.Show();
                    this.Close();
                }
                catch
                {
                    System.Windows.MessageBox.Show("whoops");
                }
            }
        }
        public override void Build_Schedule()
        {
            if (CheckForCurrentSched())
            {
                DeleteCurrent();
            }

            EmployeeScheduleDatabaseDataSetTableAdapters.ScheduledShiftTableAdapter SSAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ScheduledShiftTableAdapter();

            EmployeeScheduleDatabaseDataSet.ScheduledShiftDataTable sshiftdata = SSAdapter.GetData();

            //EmployeeScheduleDatabaseDataSet.ScheduledShiftDataTable newsched = SSAdapter.

            EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter SAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter();

            EmployeeScheduleDatabaseDataSet.ShiftTableDataTable shiftdata = SAdapter.GetData();

            EmployeeScheduleDatabaseDataSetTableAdapters.EmployeesTableAdapter empAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.EmployeesTableAdapter();

            EmployeeScheduleDatabaseDataSet.EmployeesDataTable empdata = empAdapter.GetData();

            int    EmpsperShift               = 3;
            int    ShiftsperDay               = shiftdata.Count;
            int    daysleftinWeek             = GetEndofWeek().DayOfWeek - DateTime.Today.AddDays(1).DayOfWeek;
            int    neededShifts               = (EmpsperShift * ShiftsperDay) * daysleftinWeek;
            double neededemps                 = Math.Ceiling((double)neededShifts / (double)empdata.Count);
            List <ScheduledShift> tempList    = new List <ScheduledShift>();
            List <Shift>          shiftIdList = new List <Shift>();
            List <Employee>       empIdList   = new List <Employee>();
            //int tryEmp = empdata.First().empId;
            //int empCount = empdata.Count;
            int newSID       = sshiftdata.Last().SShiftId + 1;
            int empsAssigned = 0;

            foreach (EmployeeScheduleDatabaseDataSet.ShiftTableRow row in shiftdata)
            {
                Shift tempShift = new Shift();
                tempShift.ShiftId   = row.ShiftId;
                tempShift.ShiftName = row.ShiftName;
                tempShift.StartTime = row.StartTime.ToString();
                tempShift.EndTime   = row.EndTime.ToString();

                shiftIdList.Add(tempShift);
            }

            foreach (EmployeeScheduleDatabaseDataSet.EmployeesRow row in empdata)
            {
                Employee tempEmp = new Employee();
                tempEmp.EmpId = row.empId;
                tempEmp.FName = row.firstName;
                tempEmp.LName = row.lastName;

                empIdList.Add(tempEmp);
            }



            for (int i = 0; i <= daysleftinWeek; i++)
            {
                //get the date for each day left in week
                DateTime adate = DateTime.Now.AddDays(i + 1).Date;

                for (int j = 0; j < ShiftsperDay; j++)
                {
                    //for each date assign 3 shifts

                    int shiftID = shiftIdList.ElementAt(j).ShiftId;
                    empsAssigned = 0;
                    var shuffled = empIdList.OrderBy(x => Guid.NewGuid()).ToList();
                    foreach (Employee emp in shuffled)
                    {
                        // List<ScheduledShift> matchedDate = tempList.Where(x => x.ScheduledDate == adate).ToList();
                        List <ScheduledShift> matchedEmp   = tempList.Where(x => x.EmpId == emp.EmpId).ToList();
                        List <ScheduledShift> matchedShift = tempList.Where(x => ((x.ScheduledDate == adate) && (x.EmpId == emp.EmpId))).ToList();

                        if (matchedShift.Count != 0)//((matchedDate.Count != 0) && (matchedEmp.Count != 0))
                        {
                            //Emp has been assigned a shift for this date, need to move to next emp in list
                            if (matchedShift.ElementAt(0).EmpId == emp.EmpId) //((emp.EmpId == matchedEmp.ElementAt(0).EmpId) && (emp.EmpId == matchedDate.ElementAt(0).EmpId))
                            {
                            }
                        }
                        else
                        {
                            if (matchedEmp.Count > neededemps)
                            {
                            }

                            else if (empsAssigned < EmpsperShift)
                            {
                                // Emp is good to go, add it to the List
                                ScheduledShift tempSShift = new ScheduledShift();
                                tempSShift.ScheduledDate = adate;
                                tempSShift.SShiftId      = newSID;
                                tempSShift.ShiftId       = shiftID;
                                tempSShift.EmpId         = emp.EmpId;

                                //Console.WriteLine(tempSShift.SShiftId + " " + tempSShift.ScheduledDate + " " + tempSShift.ShiftId + " " + tempSShift.EmpId);
                                tempList.Add(tempSShift);
                                newSID++;
                                empsAssigned++;
                            }
                            else
                            {
                            }
                        }
                    }
                }
            }

            foreach (ScheduledShift s in tempList)
            {
                try
                {
                    SSAdapter.Insert(s.SShiftId, s.EmpId, s.ShiftId, s.ScheduledDate);
                }
                catch
                {
                    System.Windows.MessageBox.Show("Whoops");
                }
            }
        }