Exemple #1
0
        private void SetCalendarTimeRowLane(ref CalendarTimeRow ctr, int laneIndex, int?laneValue)
        {
            switch (laneIndex)
            {
            case 1:
                ctr.Lane1 = laneValue;
                break;

            case 2:
                ctr.Lane2 = laneValue;
                break;

            case 3:
                ctr.Lane3 = laneValue;
                break;

            case 4:
                ctr.Lane4 = laneValue;
                break;

            case 5:
                ctr.Lane5 = laneValue;
                break;

            case 6:
                ctr.Lane6 = laneValue;
                break;
            }
        }
Exemple #2
0
 //trash
 public void SaveCalendarTimeRows(DataGridView dgv, DateTime currDate)
 {
     using (poolDBEntities ent = new poolDBEntities())
     {
         bool isColumnNotEmpty = false;
         for (int i = 0; i < dgv.RowCount; i++)
         {
             isColumnNotEmpty = false;
             for (int j = 1; j < dgv.ColumnCount; j++)
             {
                 if ((dgv[j, i] as DataGridViewComboBoxCell).Value != null)
                 {
                     isColumnNotEmpty = true;
                     break;
                 }
             }
             if (isColumnNotEmpty)
             {
                 CalendarTimeRow      ctr = new CalendarTimeRow();
                 List <TrainingGroup> tgs;
                 tgs = GetTrainingGroupByName(dgv[1, i].Value as string);
                 if (tgs.Count != 0)
                 {
                     ctr.Lane1 = tgs[0].Id;
                 }
                 tgs = GetTrainingGroupByName(dgv[2, i].Value as string);
                 if (tgs.Count != 0)
                 {
                     ctr.Lane2 = tgs[0].Id;
                 }
                 tgs = GetTrainingGroupByName(dgv[3, i].Value as string);
                 if (tgs.Count != 0)
                 {
                     ctr.Lane3 = tgs[0].Id;
                 }
                 tgs = GetTrainingGroupByName(dgv[4, i].Value as string);
                 if (tgs.Count != 0)
                 {
                     ctr.Lane4 = tgs[0].Id;
                 }
                 tgs = GetTrainingGroupByName(dgv[5, i].Value as string);
                 if (tgs.Count != 0)
                 {
                     ctr.Lane5 = tgs[0].Id;
                 }
                 tgs = GetTrainingGroupByName(dgv[6, i].Value as string);
                 if (tgs.Count != 0)
                 {
                     ctr.Lane6 = tgs[0].Id;
                 }
                 ctr.TimeId = DayTimeSetIndexToId(i);
                 ctr.Date   = currDate;
                 ent.CalendarTimeRows.Add(ctr);
                 ent.SaveChanges();
             }
         }
     }
 }
Exemple #3
0
        public void SaveCalendarDataGridViewCmbCellChanges(DateTime currDate, DataGridViewComboBoxCell cmbCell)
        {
            int rowInd       = cmbCell.RowIndex;
            int dayTimeSetId = DayTimeSetIndexToId(rowInd);

            using (poolDBEntities ent = new poolDBEntities())
            {
                List <CalendarTimeRow> currDateCtrs = ent.CalendarTimeRows.Where(c => System.Data.Entity.DbFunctions.TruncateTime(c.Date) == currDate.Date).ToList();
                CalendarTimeRow        ctr          = currDateCtrs?.Find(c => c.TimeId == dayTimeSetId);
                if (ctr == null)
                {
                    if (cmbCell.Value == null)
                    {
                        return;
                    }
                    CalendarTimeRow newCtr = new CalendarTimeRow();
                    newCtr.TimeId = dayTimeSetId;
                    newCtr.Date   = currDate;
                    SetCalendarTimeRowLane(ref newCtr, cmbCell.ColumnIndex, GetTrainingGroupIdByName(cmbCell.Value as string));
                    ent.CalendarTimeRows.Add(newCtr);
                    //ent.Entry(newCtr).State = System.Data.Entity.EntityState.Added;
                }
                else
                {
                    SetCalendarTimeRowLane(ref ctr, cmbCell.ColumnIndex, GetTrainingGroupIdByName(cmbCell.Value as string));
                    if (ctr.Lane1 == null &&
                        ctr.Lane2 == null &&
                        ctr.Lane3 == null &&
                        ctr.Lane4 == null &&
                        ctr.Lane5 == null &&
                        ctr.Lane6 == null)
                    {
                        ent.CalendarTimeRows.Remove(ctr);
                    }
                    //ent.Entry(ctr).State = System.Data.Entity.EntityState.Modified;
                }
                ent.SaveChanges();
            }
        }