Ejemplo n.º 1
0
        /// <summary>
        ///  Создание календаря GanttCalendar по данным календаря PLM
        /// </summary>
        /// <param name="calendPLM">Импортируемый календарь PLM</param>
        public void ImportCalendarPLM(InfoObject calendarPLM)
        {
            CalendarExceptionCollection GanttExceptionsColl;
            CalendarException GanttCalendarException;
            WorkingHourCollection WorkHourColl;
            WorkingHour WorkHour;

            // Наименование нового календаря
            this.intCalendar.Text = calendarPLM.GetValue<String>("ScheduleName");
            SetWorkingDays(calendarPLM);
            // Инициализация коллекции исключений для нового календаря
            GanttExceptionsColl = new KS.Gantt.Calendars.CalendarExceptionCollection();
            // Выборка коллекции дней исключений из PLM
            var ExceptionsPLM = calendarPLM.GetAttribute("Exceptions").CollectionElements.ToArray();
            foreach (var cePLM in ExceptionsPLM)
            {
                GanttCalendarException = new KS.Gantt.Calendars.CalendarException();
                // Дата исключения
                var TheDay = cePLM.GetValue<DateTime>("TheDay");
                GanttCalendarException.Date = TheDay;
                // Признак по календарю рабочего дня isWorking - true,
                // выходного дня(суббота, воскресение) isWorking - false
                bool isWorking = calendarPLM.GetAttribute("Schedule" + ((int)TheDay.DayOfWeek)).CollectionElements.Count > 0;
                GanttCalendarException.IsWorkingDay = cePLM.GetAttribute("Hours").CollectionElements.Count != 0;
                // Инициализация коллекции рабочих часов дней исключений
                WorkHourColl = new KS.Gantt.Calendars.WorkingHourCollection();
                // Выборка коллекции рабочих часов текущего исключения из PLM
                var hoursCollPLM = cePLM.GetAttribute("Hours").CollectionElements.
                    OrderBy(e => e.GetValue<TimeSpan>("TimeSpanFrom").Hours).ToArray();
                foreach (var hrPLM in hoursCollPLM)
                {
                    WorkHour = new KS.Gantt.Calendars.WorkingHour();
                    var b1 = hrPLM.GetValue<String>("HourFrom");
                    double hourFrom = 0;
                    double.TryParse(b1.Substring(0, 2), out hourFrom);
                    double minuteFrom = 0;
                    double.TryParse(b1.Substring(2, 2), out minuteFrom);
                    double hour = hourFrom + minuteFrom / 100;
                    WorkHour.StartHour = hour;

                    var b2 = hrPLM.GetValue<String>("HourTo");
                    hourFrom = 0;
                    double.TryParse(b2.Substring(0, 2), out hourFrom);
                    minuteFrom = 0;
                    double.TryParse(b2.Substring(2, 2), out minuteFrom);
                    hour = hourFrom + minuteFrom / 100;
                    WorkHour.EndHour = hour;

                    WorkHourColl.Add(WorkHour);
                }
                GanttCalendarException.WorkingHours = WorkHourColl;
                GanttExceptionsColl.Add(GanttCalendarException);
            }

            this.intCalendar.Exceptions = GanttExceptionsColl;
         }
Ejemplo n.º 2
0
 private void SetOneDay(int day, ICollection<CollectionElement> ceSchedule)
 {
     XMLWorkingDayAdapter WorkingDay = this.intCalendar.WorkingDays.WorkingDaySunday;
     switch (day)
     {
         case 1: WorkingDay = this.intCalendar.WorkingDays.WorkingDayMonday; break;
         case 2: WorkingDay = this.intCalendar.WorkingDays.WorkingDayTuesday; break;
         case 3: WorkingDay = this.intCalendar.WorkingDays.WorkingDayWednesday; break;
         case 4: WorkingDay = this.intCalendar.WorkingDays.WorkingDayThursday; break;
         case 5: WorkingDay = this.intCalendar.WorkingDays.WorkingDayFriday; break;
         case 6: WorkingDay = this.intCalendar.WorkingDays.WorkingDaySaturday; break;
     }
     if (ceSchedule.Count == 0)
     {
         // Нерабочий день
         this.intCalendar.WorkingDays.SetWorkingDay((DayOfWeek)day, false);
     }
     else
     {
         this.intCalendar.WorkingDays.SetWorkingDay((DayOfWeek)day, true);
         for (int i = 0; i < ceSchedule.Count; i++)
         {
             TimeSpan begTime = ceSchedule.ElementAt(i).GetValue<TimeSpan>("TimeSpanFrom");
             TimeSpan endTime = ceSchedule.ElementAt(i).GetValue<TimeSpan>("TimeSpanTo");
             var start = begTime.Hours;
             var finit = endTime.Hours;
             if (begTime.Hours == 0 && begTime.Days > 0) start = 24;
             if (endTime.Hours == 0 && endTime.Days > 0) finit = 24;
             var ccc = new KS.Gantt.Calendars.WorkingHour(start, finit);
             WorkingDay.WorkingHours.Add(ccc);
         }
     }
 }