Ejemplo n.º 1
0
 private void ReadSchedule(IWorkbook _iWordbook)
 {
     for (int i = 0; i < _iWorkbook.NumberOfSheets; i++)
     {
         ISheet sheet = _iWorkbook.GetSheetAt(i);
         if (CheckSchedule(sheet))
         {
             var listTime = GetTimeList(sheet);
             var startDay = listTime.FirstOrDefault();
             var lastDay = listTime.LastOrDefault();
             var startPoint = StartPoint(sheet);
             while (startDay <= lastDay)
             {
                 if (checkBox2.Checked)
                 {
                     //delete old data
                     if (_iScheduleService.CheckExistDate(startDay))
                     {
                         _iScheduleService.DeleteOldDate(startDay);
                     }
                     // add update data
                     for (int j = startPoint.First() + 1; j <= sheet.LastRowNum; j++)
                     {
                         var row = sheet.GetRow(j);
                         Schedule schedule = new Schedule();
                         if (row.GetCell(startPoint.Last()) == null || row.GetCell(startPoint.Last()).NumericCellValue == 0)
                             break;
                         schedule.Code = row.GetCell(startPoint.Last() + 4).StringCellValue.ToString();
                         var mytime = row.GetCell(startPoint.Last() + 1).DateCellValue;
                         schedule.Date = new DateTime(startDay.Year, startDay.Month, startDay.Day, mytime.Hour, mytime.Minute, mytime.Second);
                         _iScheduleService.Create(schedule);
                     }
                 }
                 else
                 {
                     if (_iScheduleService.CheckExistDate(startDay))
                     {
                         //do nothing
                     }
                     else
                     {
                         for (int j = startPoint.First() + 1; j <= sheet.LastRowNum; j++)
                         {
                             var row = sheet.GetRow(j);
                             Schedule schedule = new Schedule();
                             if (row.GetCell(startPoint.Last()) == null || row.GetCell(startPoint.Last()).NumericCellValue == 0)
                                 break;
                             schedule.Code = row.GetCell(startPoint.Last() + 4).StringCellValue.ToString();
                             var mytime = row.GetCell(startPoint.Last() + 1).DateCellValue;
                             schedule.Date = new DateTime(startDay.Year, startDay.Month, startDay.Day, mytime.Hour, mytime.Minute, mytime.Second);
                             _iScheduleService.Create(schedule);
                         }
                     }
                 }
                 startDay = startDay.AddDays(1);
             }
             _iScheduleService.Save();
         }
     }
 }
Ejemplo n.º 2
0
 private List<ScheduleViewModel> addItemToScheduleList(Schedule item, List<ScheduleViewModel> result)
 {
     var item_temp = totalResult.Where(x => x.Code == item.Code).FirstOrDefault();
     DateTime time = Convert.ToDateTime(item_temp.Duration);
     if (time.Minute > 4)
     {
         DateTime endTime = item.Date;
         endTime = endTime.AddMinutes(time.Minute).AddSeconds(time.Second);
         DateTime seprateTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, endTime.Hour, 0, 0);
         DateTime choosenTime = new DateTime();
         if (item.Date <= seprateTime)
         {
             if ((seprateTime - item.Date) >= (endTime - seprateTime))
             {
                 choosenTime = item.Date;
             }
             else
             {
                 choosenTime = endTime;
             }
         }
         else
             choosenTime = endTime;
         var choosenItem = result.Where(x => x.Hour == choosenTime.Hour).FirstOrDefault();
         if (choosenItem != null)
         {
             choosenItem.programs.Add(item);
             choosenItem.programs = choosenItem.programs.OrderBy(x => x.Date).ToList();
         }
         else
         {
             choosenItem = new ScheduleViewModel();
             choosenItem.Hour = choosenTime.Hour;
             choosenItem.programs = new List<Schedule>();
             choosenItem.programs.Add(item);
             result.Add(choosenItem);
         }
     }
     return result;
 }