private void BtnDelet_Click(object sender, EventArgs e) { btnAdd.Enabled = false; btnEdit.Enabled = false; btnDelet.Enabled = false; try { string classtabel = dataGridViewX1.CurrentRow.Cells[0].Value.ToString(); if (RtlMessageBox.Show($"آیا از حذف {classtabel } مطمئن هستید ؟", "توجه", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { NetCollegeEntities db = new NetCollegeEntities(); var coname = dataGridViewX1.CurrentRow.Cells[0].Value.ToString(); classTable classTable = db.classTables.Where(c => c.class_ID == coname).Single(); db.Entry(classTable).State = System.Data.Entity.EntityState.Deleted; db.classTables.Remove(classTable); db.SaveChanges(); BindGrid(); } } catch (Exception) { RtlMessageBox.Show("خطا در انجام حذف!"); } btnAdd.Enabled = true; btnEdit.Enabled = true; btnDelet.Enabled = true; }
private void BtnSave_Click(object sender, EventArgs e) { NetCollegeEntities db = new NetCollegeEntities(); if (IsEdit == false) { classTable classTable = new classTable() { class_ID = txtClassID.Text, capacity = Convert.ToInt32(txtCapacty.Text), description = txtDest.Text, cooler = txtCooler.Checked, video_projector = txtVideo.Checked }; try { db.classTables.Add(classTable); RtlMessageBox.Show(" کلاس جدیداضافه شد "); db.SaveChanges(); } catch (DbUpdateException) { RtlMessageBox.Show("شماره کلاس تکراری است"); } catch { RtlMessageBox.Show("خطا در انجام عملیات"); } } else { classTable classTable = new classTable(); classTable.class_ID = txtClassID.Text; classTable.capacity = Convert.ToInt32(txtCapacty.Text); classTable.description = txtDest.Text; classTable.cooler = txtCooler.Checked; classTable.video_projector = txtVideo.Checked; db.Entry(classTable).State = System.Data.Entity.EntityState.Modified; IsEdit = false; RtlMessageBox.Show("ویرایش کلاس انجام شد"); db.SaveChanges(); } btnAdd.Enabled = true; btnEdit.Enabled = true; btnDelet.Enabled = true; BindGrid(); }
private void DataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e) { try { NetCollegeEntities db = new NetCollegeEntities(); var coname = dataGridViewX1.CurrentRow.Cells[0].Value.ToString(); classTable classTable = db.classTables.Where(c => c.class_ID == coname).Single(); string classneme = dataGridViewX1.CurrentRow.Cells[0].Value.ToString(); txtClassID.Text = classTable.class_ID; txtCapacty.Text = Convert.ToString(classTable.capacity); txtDest.Text = classTable.description; txtVideo.Checked = Convert.ToBoolean(classTable.video_projector); txtCooler.Checked = Convert.ToBoolean(classTable.cooler); } catch (Exception) { RtlMessageBox.Show("رکوردی انتخاب نشده است"); } }
private void BtnEdit_Click(object sender, EventArgs e) { IsEdit = true; txtCapacty.Enabled = true; txtCooler.Enabled = true; txtDest.Enabled = true; txtVideo.Enabled = true; btnSave.Visible = true; btnSave.Image = amozeshgah.Properties.Resources.icons8_save_as; NetCollegeEntities db = new NetCollegeEntities(); var coname = dataGridViewX1.CurrentRow.Cells[0].Value.ToString(); classTable classTable = db.classTables.Where(c => c.class_ID == coname).Single(); txtCapacty.Text = classTable.capacity.ToString(); txtClassID.Text = classTable.class_ID; txtCooler.Checked = Convert.ToBoolean(classTable.cooler); txtDest.Text = classTable.description; txtVideo.Checked = Convert.ToBoolean(classTable.video_projector); btnAdd.Enabled = false; btnEdit.Enabled = false; btnDelet.Enabled = false; }