private void btnDelete_Click(object sender, EventArgs e) { if (!cu.is_dataGridView_colored(dataGridViewLevels)) { MessageBox.Show("Nothing is picked on table!"); return; } Lessons les = new Lessons(); string field = "kod_level"; string code = cu.GetID(dataGridViewLevels); DataTable lessonsID = les.GetLessonsByString(field, code); foreach (DataRow dr in lessonsID.Rows) { if (dr[field].ToString().Equals(code) && cu.is_date_in_future(dr["due_date"].ToString())) { MessageBox.Show("Cannot delete level with scheduled lessons!"); return; } } levels mkk = new levels(); mkk.Delete(cu.GetID(dataGridViewLevels)); cu.charge_data_grid_view(mkk.GetLevels(), dataGridViewLevels); dataGridViewLevels.ClearSelection(); }
private void btnDelete_Click(object sender, EventArgs e) { if (!cu.is_dataGridView_colored(dataGridViewMikP)) { MessageBox.Show("Nothing is picked on teachers!"); return; } Lessons les = new Lessons(); string field = "kod_mik"; DataTable lessonsID = les.GetLessonsByString(field, cu.GetID(dataGridViewMikP)); string mik_id = cu.GetID(dataGridViewMikP); foreach (DataRow dr in lessonsID.Rows) { if (dr[field].ToString() == mik_id && cu.is_date_in_future(dr["due_date"].ToString())) { MessageBox.Show("Cannot delete mik with scheduled lessons!"); return; } } MikP mkk = new MikP(); mkk.Delete(cu.GetID(dataGridViewMikP)); cu.charge_data_grid_view(mkk.GetMikzoot(), dataGridViewMikP); this.dataGridViewMikP.ClearSelection(); }
private void dataGridViewInfo_CellClick(object sender, DataGridViewCellEventArgs e) { if (cu.is_out_of_dataGridView_range(e.RowIndex, e.ColumnIndex, cu.get_dgv_last_row(dataGridViewInfo)) || e.ColumnIndex == 0) { dataGridViewInfo.ClearSelection(); return; } if (!cu.is_dataGridView_colored(dataGridViewMorimProject)) { dataGridViewInfo.ClearSelection(); MessageBox.Show("Please Choose Teacher"); return; } string mik = tabControlMik.SelectedTab.Text; string level = dataGridViewInfo.Rows[e.RowIndex].Cells[0].Value.ToString(); string kita = dataGridViewInfo.Columns[e.ColumnIndex].HeaderText; int MikCode = 0; int kitaCode = 0; int LevelCode = 0; string TeacherCode = ""; foreach (DataRow dr in mikzoot.Rows) { if (dr["mikName"].ToString().Equals(mik)) { MikCode = int.Parse(dr["mikCode"].ToString()); } } foreach (DataRow dr in ramot.Rows) { if (dr["rama"].ToString().Equals(level)) { LevelCode = int.Parse(dr["code"].ToString()); } } foreach (DataRow dr in kitot.Rows) { if (dr["class"].ToString().Equals(kita)) { kitaCode = int.Parse(dr["Code"].ToString()); } } for (int d = 0; d < dataGridViewMorimProject.RowCount; d++) { if (dataGridViewMorimProject.Rows[d].Cells[0].Style.BackColor == Color.MediumPurple) { TeacherCode = dataGridViewMorimProject.Rows[d].Cells[0].Value.ToString(); } } if (TeacherCode == "") { dataGridViewInfo.ClearSelection(); return; } if (dataGridViewInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor == Color.MediumPurple) { Lessons les = new Lessons(); DataTable lessons = les.GetLessonsByString("teacher_id", "'" + TeacherCode + "'"); foreach (DataRow lesson in lessons.Rows) { if (cu.is_date_in_future(lesson["due_date"].ToString()) && lesson["kod_mik"].ToString().Equals(MikCode.ToString()) && lesson["kod_kita"].ToString().Equals(kitaCode.ToString()) && lesson["kod_level"].ToString().Equals(LevelCode.ToString())) { dataGridViewInfo.ClearSelection(); MessageBox.Show("Cannot delete, Future lesson is scheduled"); return; } } dataGridViewInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.White; CanTeachProject x = new CanTeachProject(); x.DeleteCanTeach(kitaCode, LevelCode, MikCode, TeacherCode); } else if (dataGridViewInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor == Color.Empty) { dataGridViewInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.MediumPurple; CanTeachProject x = new CanTeachProject(); x.AddCanTeachProject(kitaCode, LevelCode, MikCode, TeacherCode); } dataGridViewInfo.ClearSelection(); }