Ejemplo n.º 1
0
        public override void AddLogic(ICoatingScheduleLogic newController = null)
        {
            CoatingScheduleLine newLogic;

            if (newController != null)
            {
                newLogic = (CoatingScheduleLine)newController;
                newLogic.Connect(this);
                if (Control != null)
                {
                    Control.AddControlToBottom(newLogic);
                }
            }
            else
            {
                newLogic       = new CoatingScheduleLine();
                newLogic.Shift = GetNextShift();
                newLogic.Connect(this);
                if (Control != null)
                {
                    Control.AddControlToBottom(newLogic);
                }
                newLogic.AddLogic();
            }
            ChildrenLogic.Add(newLogic);
        }
Ejemplo n.º 2
0
        public override void AddControlToTop(ICoatingScheduleLogic newController)
        {
            CoatingScheduleLine newLogic;

            if (newController != null)
            {
                if (newController.GetType() == typeof(CoatingScheduleLine))
                {
                    newLogic = (CoatingScheduleLine)newController;

                    newLogic.Shift = GetNextShift();
                    ChildrenLogic.Add(newLogic);
                    newLogic.Connect(this);
                    Control.AddControlToTop(newLogic);
                    newLogic.AddLogic();
                }
                else if (ChildrenLogic.Count > 0)
                {
                    ChildrenLogic[0].AddControlToTop(newController);
                }
                else
                {
                    newLogic = new CoatingScheduleLine();

                    newLogic.Date  = Date;
                    newLogic.Shift = GetNextShift();
                    ChildrenLogic.Add(newLogic);
                    newLogic.Connect(this);
                    Control.AddControlToTop(newLogic);
                    newLogic.AddLogic();

                    newLogic.AddControlToTop(newController);
                }
            }
            else
            {
                newLogic = new CoatingScheduleLine();

                newLogic.Date  = Date;
                newLogic.Shift = GetNextShift();
                ChildrenLogic.Add(newLogic);
                newLogic.Connect(this);
                Control.AddControlToTop(newLogic);
                newLogic.AddLogic();
            }
        }
Ejemplo n.º 3
0
        private Shift GetNextShift()
        {
            Shift nextShift = null;

            if (ChildrenLogic.Count == 0)
            {
                if (ShiftHandler.CoatingInstance.Shifts.Count == 0)
                {
                    var result = MessageBox.Show("No shift schedule loaded. Try loading now?", "",
                                                 MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        bool loaded = ShiftHandler.CoatingInstance.LoadShifts();
                        if (loaded)
                        {
                            MessageBox.Show("Shifts loaded successfully.");
                            nextShift = ShiftHandler.CoatingInstance.Shifts.FirstOrDefault(x => x.StartDate <= Date && x.EndDate >= Date && x.DaysList.Contains(Date.DayOfWeek));
                        }
                        else
                        {
                            MessageBox.Show("Shifts could not be loaded.");
                        }
                    }
                }
                else
                {
                    nextShift = ShiftHandler.CoatingInstance.Shifts[0];
                }
            }
            else
            {
                foreach (var shift in ShiftHandler.CoatingInstance.Shifts)
                {
                    bool hasShift = false;
                    for (Int32 index = 0; !hasShift && index < ChildrenLogic.Count; index++)
                    {
                        CoatingScheduleLine line = ChildrenLogic[index] as CoatingScheduleLine;
                        if (line != null && line.ShiftName == shift.Name)
                        {
                            hasShift = true;
                        }
                    }
                    if (!hasShift && (shift.StartDate <= Date && shift.EndDate >= Date &&
                                      shift.DaysList.Contains(Date.DayOfWeek)))
                    {
                        nextShift = shift;
                        break;
                    }
                }
            }

            //if (ChildrenLogic.Count == 0)
            //    nextTitle = StaticFactoryValuesManager.Shifts.FirstOrDefault();
            //else
            //{
            //    try
            //    {
            //        foreach (string shift in StaticFactoryValuesManager.Shifts.Reverse())
            //        {
            //            bool hasShift = false;
            //            for (Int32 index = 0; !hasShift && index < ChildrenLogic.Count; index++)
            //            {
            //                CoatingScheduleLine line = ChildrenLogic[index] as CoatingScheduleLine;
            //                if (line.ShiftName == shift)
            //                    hasShift = true;
            //            }
            //            if (hasShift) continue;
            //            nextTitle = shift;
            //            break;
            //        }
            //    }
            //    catch (Exception)
            //    {

            //    }
            //}
            return(nextShift);
        }