private void Raspisaniedata_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int id = Convert.ToInt32(Raspisaniedata.Rows[e.RowIndex].Cells[0].Value); Urok p = DBobjects.Entities.Urok.FirstOrDefault(u => u.ID_Urok == id); redaktirovatGlavnajaforma redakt = new redaktirovatGlavnajaforma(p); redakt.ShowDialog(); Fill1(); }
public redaktirovatGlavnajaforma(Urok urok) { InitializeComponent(); UROK = urok; comboBoxKabinet.DataSource = DBobjects.Entities.Kabinet.ToList(); comboBoxKabinet.SelectedItem = UROK.Kabinet; comboBoxNomer.SelectedItem = UROK.Nomer_uroka.ToString(); comboBoxWeekday.SelectedItem = zamena(UROK.Weekday); comboBoxPredmet.DataSource = DBobjects.Entities.Predmet.ToList(); comboBoxPredmet.SelectedItem = UROK.Predmet; comboBoxKlass.DataSource = DBobjects.Entities.Klass.ToList(); comboBoxKlass.SelectedItem = UROK.Klass; comboBoxUschitel.DataSource = DBobjects.Entities.Uchitel.ToList(); comboBoxUschitel.SelectedItem = UROK.Uchitel; }
private void GenerateSchedule() { DBobjects.Entities.Clear(); int maxIdKabinet = DBobjects.Entities.Kabinet.OrderByDescending(p => p.ID_Kabinet).FirstOrDefault().ID_Kabinet + 1; int maxIdKlass = DBobjects.Entities.Klass.OrderByDescending(p => p.ID_Klass).FirstOrDefault().ID_Klass + 1; int maxIdUchitel = DBobjects.Entities.Uchitel.OrderByDescending(p => p.ID_Uchitel).FirstOrDefault().ID_Uchitel + 1; int[,,] ZanKabinet = new int [maxIdKabinet, 6, 7]; int[,,] ZanKlass = new int[maxIdKlass, 6, 7]; int[,,] ZanUchitel = new int[maxIdUchitel, 6, 7]; int[,] FreeKabs = new int[30, 2]; Klass [] klasses = DBobjects.Entities.Klass.ToArray(); Random RANDMASS = new Random(); for (int i = klasses.Length - 1; i >= 1; i--) { int j = RANDMASS.Next(i + 1); Klass tmpM = klasses[j]; klasses[j] = klasses[i]; klasses[i] = tmpM; } int Lk = klasses.Count(); int ik = 0; List <Predmet> predmets = new List <Predmet>(); while ((ik < Lk)) { var tmp = klasses[ik]; List <KlassPredmet> klassPr = DBobjects.Entities.KlassPredmet.Where(p => p.ID_Klass == tmp.ID_Klass).ToList(); foreach (KlassPredmet klPr in klassPr) { predmets.Add(klPr.Predmet); } predmets = predmets.Distinct().ToList();//список предметов для класса int Lp = predmets.Count(); for (int ip = 0; ip < Lp; ip++) { var tmpP = predmets[ip]; if (DBobjects.Entities.UchitelKlassPredmet.Where(p => p.KlassPredmet.ID_Predmet == tmpP.ID_Predmet && p.KlassPredmet.Klass.ID_Klass == tmp.ID_Klass).Count() > 0) { UchitelKlassPredmet klascPrUch = DBobjects.Entities.UchitelKlassPredmet.FirstOrDefault(p => p.KlassPredmet.ID_Predmet == tmpP.ID_Predmet && p.KlassPredmet.Klass.ID_Klass == tmp.ID_Klass); int uc = klascPrUch.ID_Uchitel; int N = klascPrUch.KlassPredmet.UrokovVNedelyu; List <Kabinet> kabinets = new List <Kabinet>(); for (int i = 1; i <= N; i++) { List <KabinetPredmet> kabPredm = DBobjects.Entities.KabinetPredmet.Where(p => p.ID_Predmet == tmpP.ID_Predmet).ToList(); foreach (KabinetPredmet kabPr in kabPredm) { kabinets.Add(kabPr.Kabinet); } int Lkab = kabinets.Count(); for (int ikab = 0; ikab < Lkab;) { var tmpKab = kabinets[ikab]; int fk = -1; for (int iwd = 1; iwd <= 5; iwd++) { for (int iur = 1; iur <= 6; iur++) { if (ZanKabinet[tmpKab.ID_Kabinet, iwd, iur] == 0 && ZanKlass[tmp.ID_Klass, iwd, iur] == 0 && ZanUchitel[uc, iwd, iur] == 0) { fk = fk + 1; FreeKabs[fk, 0] = iwd; FreeKabs[fk, 1] = iur; } } } if (fk >= 0) { Random rand = new Random(); var rndwu = rand.Next(fk); var wd = FreeKabs[rndwu, 0]; var ur = FreeKabs[rndwu, 1]; ZanKabinet[tmpKab.ID_Kabinet, wd, ur] = 1; ZanKlass[tmp.ID_Klass, wd, ur] = 1; ZanUchitel[uc, wd, ur] = 1; Urok urok = new Urok(); urok.ID_Kabinet = tmpKab.ID_Kabinet; urok.ID_Klass = tmp.ID_Klass; urok.ID_Predmet = tmpP.ID_Predmet; urok.ID_Uchitel = uc; urok.Weekday = wd; urok.Nomer_uroka = ur; DBobjects.Entities.Urok.Add(urok); DBobjects.Entities.SaveChanges(); } break; } } } } ik++; } }