public TemplateShift FindTemplateShiftById(int templateShiftId)
        {
            TemplateShift templateShift = _templateShiftRepository.FindTemplateShiftById(templateShiftId);

            templateShift.Employee = _employeeController.GetEmployeeById(templateShift.Employee.Id);
            return(templateShift);
        }
Exemplo n.º 2
0
 public ScheduleShiftElement(TemplateShift shift, string text, Color color)
 {
     InitializeComponent();
     DataContext        = shift;
     IsLastElement      = false;
     TextBox.Background = new SolidColorBrush(color);
     TextBox.Text       = text;
     SetCursor();
 }
Exemplo n.º 3
0
 public ScheduleShiftElement(TemplateShift shift, Color color, bool isLastElement)
 {
     InitializeComponent();
     DataContext        = shift;
     IsLastElement      = isLastElement;
     TextBox.Background = new SolidColorBrush(color);
     SetCursor();
     Button.Visibility = Visibility.Hidden;
 }
Exemplo n.º 4
0
        public int OverlapsWithShiftsInList(Shift shift, List <Shift> shifts)
        {
            int res = 0;

            if (shift.GetType() == typeof(TemplateShift))
            {
                TemplateShift templateShift = (TemplateShift)shift;
                foreach (Shift s in shifts)
                {
                    TemplateShift currShift = (TemplateShift)s;
                    if (templateShift.Employee != currShift.Employee)
                    {
                        if (templateShift.StartTime < currShift.StartTime &&
                            (templateShift.StartTime.Add(new TimeSpan((int)templateShift.Hours, 0, 0))) > currShift.StartTime)
                        {
                            res++;
                        }
                        else if (templateShift.StartTime > currShift.StartTime &&
                                 (currShift.StartTime.Add(new TimeSpan((int)currShift.Hours, 0, 0))) > templateShift.StartTime)
                        {
                            res++;
                        }
                        else if (templateShift.StartTime == currShift.StartTime)
                        {
                            res++;
                        }
                    }
                }
            }
            else if (shift.GetType() == typeof(ScheduleShift))
            {
                ScheduleShift scheduleShift = (ScheduleShift)shift;
                foreach (Shift s in shifts)
                {
                    ScheduleShift currShift = (ScheduleShift)s;
                    if (scheduleShift.Employee != currShift.Employee)
                    {
                        if (scheduleShift.StartTime < currShift.StartTime &&
                            (scheduleShift.StartTime.AddHours(scheduleShift.Hours) > currShift.StartTime))
                        {
                            res++;
                        }
                        else if (scheduleShift.StartTime > currShift.StartTime &&
                                 (currShift.StartTime.AddHours(currShift.Hours) > scheduleShift.StartTime))
                        {
                            res++;
                        }
                        else if (scheduleShift.StartTime == currShift.StartTime)
                        {
                            res++;
                        }
                    }
                }
            }
            return(res);
        }
        public void AddTemplaceShiftServiceTest()
        {
            TemplateShift templateShift = _templateShiftService.CreateTemplateShift(TemplateShiftService.DayOfWeek.Friday, 10.0, new TimeSpan(10, 0, 0), 1, new Employee()
            {
                Id = 3
            });

            Assert.AreEqual(TemplateShiftService.DayOfWeek.Friday.ToString(), templateShift.WeekDay.ToString());
            Assert.AreNotEqual(TimeSpan.FromHours(5), templateShift.StartTime);
        }
Exemplo n.º 6
0
 public void DeleteTemplateShift(TemplateShift templateShift)
 {
     using (SqlConnection connection = new DbConnection().GetConnection())
     {
         using (SqlCommand deleteTemplateShift = new SqlCommand(
                    "DELETE FROM TemplateShift WHERE id = @param1;", connection))
         {
             deleteTemplateShift.Parameters.AddWithValue(@"param1", templateShift.Id);
             deleteTemplateShift.ExecuteNonQuery();
         }
     }
 }
Exemplo n.º 7
0
        private void OnHandleDrop(object sender, DragEventArgs e)
        {
            object droppedItem = e.Data.GetData("Object");

            if (droppedItem.GetType().IsSubclassOf(typeof(Shift)))
            {
                Shift droppedShift = (Shift)e.Data.GetData("Object");

                bool isLastElement = (bool)e.Data.GetData("IsLastShiftElement");
                if (isLastElement)
                {
                    if (droppedShift.GetType() == typeof(TemplateShift))
                    {
                        TemplateShift ts    = (TemplateShift)droppedShift;
                        double        hours = (Time.Subtract(ts.StartTime).Add(new TimeSpan(0, TemplateScheduleCalendar.INCREMENT, 0)).TotalHours);
                        ts.Hours = hours > 0 ? hours : 1;
                    }
                    else if (droppedShift.GetType() == typeof(ScheduleShift))
                    {
                        ScheduleShift ss    = (ScheduleShift)droppedShift;
                        double        hours = (Time.Hours - (ss.StartTime.Hour)); //+ TemplateScheduleCalendar.INCREMENT);
                        droppedShift.Hours = hours > 0 ? hours : 1;
                    }
                }
                else
                {
                    if (droppedShift.GetType() == typeof(TemplateShift))
                    {
                        TemplateShift ts = (TemplateShift)droppedShift;
                        ts.StartTime = Time;
                        ts.WeekDay   = WeekDay;
                        droppedShift = ts;
                    }
                    else if (droppedShift.GetType() == typeof(ScheduleShift))
                    {
                        ScheduleShift ss = (ScheduleShift)droppedShift;
                        DateTime      dt = new DateTime(ss.StartTime.Year, ss.StartTime.Month, (int)WeekDay, Time.Hours, Time.Minutes, 0);
                        ss.StartTime = dt;
                        droppedShift = ss;
                    }
                }
                Mediator.GetInstance().OnShiftDropped(sender, droppedShift, isLastElement);
            }
            else if (droppedItem.GetType() == typeof(Employee))
            {
                Employee employee = (Employee)droppedItem;
                Mediator.GetInstance().OnEmployeeDropped(employee, Time, WeekDay);
            }
        }
 public void SetCloseShiftClicked()
 {
     Mediator.GetInstance().ShiftCloseClicked += (s, e) =>
     {
         if (e.Shift.GetType() == typeof(TemplateShift))
         {
             TemplateShift ts = (TemplateShift)e.Shift;
             Shifts.Remove(ts);
             DeletedShifts.Add((TemplateShift)e.Shift);
         }
         DayColumnList.ForEach(x => x.ResetTimeCells());
         Clear();
         LoadShiftsIntoCalendar();
     };
 }
Exemplo n.º 9
0
        private TemplateShift BuildTemplateShiftObject(SqlDataReader reader)
        {
            TemplateShift templateShiftObject = new TemplateShift();

            templateShiftObject.Id                 = reader.GetInt32(0);
            templateShiftObject.WeekDay            = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), reader.GetString(1));
            templateShiftObject.Hours              = reader.GetDouble(2);
            templateShiftObject.StartTime          = reader.GetTimeSpan(3);
            templateShiftObject.WeekNumber         = reader.GetInt32(4);
            templateShiftObject.TemplateScheduleId = reader.GetInt32(5);
            templateShiftObject.Employee           = new Employee()
            {
                Id = reader.GetInt32(6)
            };                                                                         //Creates dummy-employee-object, so it is possible to find the employee by id later
            return(templateShiftObject);
        }
        public void GetShiftsFromTemplateShiftTest()
        {
            _scheduleController = new ScheduleController(new ScheduleRepository());
            Employee         employee         = new Employee();
            TemplateSchedule templateSchedule = _templateScheduleController.CreateTemplateSchedule(10, "basicSchedule");
            TemplateShift    templateShift    = _templateShiftController.CreateTemplateShift(DayOfWeek.Friday, 10.0, new TimeSpan(10, 0, 0), 1, employee);
            TemplateShift    templateShift2   = _templateShiftController.CreateTemplateShift(DayOfWeek.Monday, 15.0, new TimeSpan(3, 1, 2), 2, employee);

            templateSchedule.TemplateShifts.Add(templateShift);
            templateSchedule.TemplateShifts.Add(templateShift2);

            Schedule schedule = _scheduleController.GenerateScheduleFromTemplateSchedule(templateSchedule, DateTime.Now);

            Assert.AreEqual(templateSchedule.TemplateShifts.Count, schedule.Shifts.Count);
            Assert.AreEqual(schedule.Shifts[1].Hours, templateSchedule.TemplateShifts[1].Hours);
        }
Exemplo n.º 11
0
        private void UpdateTemplateScheduleShift(TemplateShift templateShift, SqlConnection connection)
        {
            using (SqlCommand updateTemplateShift = new SqlCommand(
                       "UPDATE TemplateShift SET " +
                       "weekday = @param1, hours = @param2, " +
                       "startTime = @param3 WHERE id = @param4",
                       connection))
            {
                updateTemplateShift.Parameters.AddWithValue("@param1", templateShift.WeekDay.ToString());
                updateTemplateShift.Parameters.AddWithValue("@param2", templateShift.Hours);
                updateTemplateShift.Parameters.AddWithValue("@param3", templateShift.StartTime);
                updateTemplateShift.Parameters.AddWithValue("@param4", templateShift.Id);

                updateTemplateShift.ExecuteNonQuery();
            }
        }
        private bool ValidateTemplateShift(TemplateShift templateShift)
        {
            bool isOkToInsert = true;

            if (templateShift.Hours < 0)
            {
                isOkToInsert = false;
            }
            else if (templateShift.Employee == null)
            {
                isOkToInsert = false;
            }
            else if (templateShift.TemplateScheduleId < 0)
            {
                isOkToInsert = false;
            }
            return(isOkToInsert);
        }
Exemplo n.º 13
0
        public List <TemplateShift> GetAllTemplateShifts()
        {
            List <TemplateShift> templateShifts = new List <TemplateShift>();

            using (SqlConnection connection = new DbConnection().GetConnection())
            {
                using (SqlCommand command = new SqlCommand("SELECT * FROM TemplateShift", connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            TemplateShift templateShift = BuildTemplateShiftObject(reader);
                            templateShifts.Add(templateShift);
                        }
                    }
                }
            }
            return(templateShifts);
        }
Exemplo n.º 14
0
        public TemplateShift FindTemplateShiftById(int templateShiftId)
        {
            TemplateShift templateShift = null;

            using (SqlConnection connection = new DbConnection().GetConnection())
            {
                using (SqlCommand command = new SqlCommand("SELECT * FROM TemplateShift WHERE ID = @param1", connection))
                {
                    command.Parameters.AddWithValue("@param1", templateShiftId);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            templateShift = BuildTemplateShiftObject(reader);
                        }
                    }
                }
            }
            return(templateShift);
        }
Exemplo n.º 15
0
        private void SetTextHeader(Shift shift)
        {
            ScheduleShift scheduleShift = null;
            TemplateShift templateShift = null;

            if (shift.GetType() == typeof(ScheduleShift))
            {
                scheduleShift = (ScheduleShift)shift;
                TextBox1.Text = scheduleShift.Employee.Name;
                TextBox2.Text = scheduleShift.StartTime.ToShortTimeString() + " - " + scheduleShift.StartTime.AddHours(scheduleShift.Hours).ToShortTimeString();
            }
            else
            {
                templateShift = (TemplateShift)shift;
                int      minutes   = (int)(60 * (templateShift.Hours - (int)templateShift.Hours));
                DateTime startTime = new DateTime(2017, 1, 1, templateShift.StartTime.Hours, templateShift.StartTime.Minutes, 0);
                DateTime endTime   = startTime.AddHours(templateShift.Hours);

                TextBox1.Text = templateShift.Employee.Name;
                TextBox2.Text = startTime.ToShortTimeString() + " - " + endTime.ToShortTimeString();
            }
        }
Exemplo n.º 16
0
        public List <TemplateShift> GetTemplateShiftsByTemplateScheduleId(int templateScheduleId)
        {
            List <TemplateShift> templateShifts = new List <TemplateShift>();

            using (SqlConnection connection = new DbConnection().GetConnection())
            {
                using (SqlCommand command = new SqlCommand("SELECT * FROM TemplateShift WHERE templateScheduleId = @param1", connection))
                {
                    SqlParameter p1 = new SqlParameter(@"param1", SqlDbType.Int);
                    p1.Value = templateScheduleId;
                    command.Parameters.Add(p1);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            TemplateShift templateShift = BuildTemplateShiftObject(reader);
                            templateShifts.Add(templateShift);
                        }
                    }
                }
            }
            return(templateShifts);
        }
 public void DeleteTemplateShift(TemplateShift templateShift)
 {
     _templateShiftRepository.DeleteTemplateShift(templateShift);
 }
 public void AddShift(TemplateShift shift)
 {
     Shifts.Add(shift);
 }
Exemplo n.º 19
0
        public void RenderShifts()
        {
            loadedShifts.Clear();
            bool isTemplate = false;
            int  zIndex     = 600;

            foreach (Shift shift in Shifts)
            {
                //Find the corosponding timecell element
                TimeCell timeCell = new TimeCell();
                if (shift.GetType() == typeof(TemplateShift))
                {
                    TemplateShift ts = (TemplateShift)shift;
                    timeCell   = FindMatchingTimeCell(ts.StartTime);
                    isTemplate = true;
                }
                else if (shift.GetType() == typeof(ScheduleShift))
                {
                    ScheduleShift ss = (ScheduleShift)shift;
                    timeCell = FindMatchingTimeCell(new TimeSpan(ss.StartTime.Hour, ss.StartTime.Minute, ss.StartTime.Second));
                }

                //------------------Set rows and columns-----------------------
                //Find out how many columns the should be in the current timecell
                int columnAmount = OverlapsWithShiftsInList(shift, Shifts) > 0 ? OverlapsWithShiftsInList(shift, Shifts) + 1 : 1;
                //Find out which column nr the current shift shall insertes into
                int columnNr = OverlapsWithShiftsInList(shift, loadedShifts);

                //Find how many rows the timecell should have
                int rowCount = (int)(shift.Hours * (60 / TemplateScheduleCalendar.INCREMENT));
                //Set the max-rowcount for block of shifts
                timeCell.MaxRowCount = timeCell.MaxRowCount < rowCount ? rowCount : timeCell.MaxRowCount;

                //------------------Insert shiftelement-------------------------
                //Find the right color
                Color col = Colors.RoyalBlue;
                if (!isTemplate)
                {
                    ScheduleShift scheduleShift = (ScheduleShift)shift;
                    if (scheduleShift.IsForSale)
                    {
                        col = Colors.MistyRose;  // Mmmmmmm.... Misty Rose
                    }
                }
                //Instansiate the shiftelement
                ShiftElement shiftElement = new ShiftElement(shift, col);
                shiftElement.RootTimeCell = timeCell;
                shiftElement.AddButtom(new ShiftElement(shift, col, true));
                //shiftElement.SetMouseOver();
                //shiftElement.SetMouseLeave();
                //Add shiftelement to timecell
                timeCell.TimeCellGrid.Children.Add(shiftElement);
                //Add columns
                timeCell.TimeCellGrid.ColumnDefinitions.Clear();
                for (int i = 0; i < columnAmount; i++)
                {
                    timeCell.TimeCellGrid.ColumnDefinitions.Add(new ColumnDefinition());
                }
                //Add rows for the timeCell
                timeCell.TimeCellGrid.RowDefinitions.Clear();
                for (int i = 0; i < timeCell.MaxRowCount; i++)
                {
                    timeCell.TimeCellGrid.RowDefinitions.Add(new RowDefinition());
                }
                //Set rowspan for timecell
                Grid.SetRowSpan(timeCell, timeCell.MaxRowCount);
                //Set rowspan for shiftelement
                Grid.SetRowSpan(shiftElement, rowCount);
                //Set columnspan for timeCell
                Grid.SetColumnSpan(timeCell, columnAmount);
                //Set column for shiftelement
                Grid.SetColumn(shiftElement, columnNr);
                Panel.SetZIndex(timeCell, zIndex);
                //zIndex--;
                //Finally add shift to list of loaded shifts
                loadedShifts.Add(shift);
            }
        }