private void button1_Click(object sender, EventArgs e) { if (txtMaMon.Text.Trim() == "") { MessageBox.Show("Mã lớp chưa nhập", "Thông báo"); } else { if (context.tblMONs.Find(txtMaMon.Text) != null) { MessageBox.Show("Mã môn đã tồn tại", "Thông báo"); } else { tblMON m = new tblMON(); m.TenMon = txtTenMon.Text; m.SoDVHT = Convert.ToInt32(numsdvht.Text); m.MaMon = txtMaMon.Text; m.MaKhoa = cboKhoa.Text; m.HocKi = txtHocKy.Text; MONHOCF mh = new MONHOCF(); mh.Insert(m); dgrMON.DataSource = context.tblMONs.ToList(); txtHocKy.Clear(); txtMaMon.Clear(); numsdvht.Value = 0; txtTenMon.Clear(); cboKhoa.Text = ""; } } }
private void btnXoa_Click(object sender, EventArgs e) { try { DialogResult result = MessageBox.Show("Bạn có muốn xóa nhà cung cấp " + txtName.Text + " không?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { var ans = new MONHOCF().Delete(new MONHOC { ID = int.Parse(txtID.Text) }); Init_(); ClearBinding(); Bindingtxt(); } } catch { } }
private void btnLuu_Click(object sender, EventArgs e) { try { MONHOC model = new MONHOC() { tenmon = txtName.Text, note = txtNote.Text, }; int ID_ = -1; if (txtID.Text != "") { ID_ = int.Parse(txtID.Text.ToString()); } model.ID = ID_; if (txtID.Text == "") { var result = new MONHOCF().Insert(model); if (result) { MessageBox.Show("Done"); } else { MessageBox.Show("Lỗi"); } } else { var result = new MONHOCF().Update(model); if (result) { MessageBox.Show("Done"); } else { MessageBox.Show("Lỗi"); } } Init_(); ClearBinding(); Bindingtxt(); } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private void button2_Click(object sender, EventArgs e) { string id = txtMaMon.Text.Trim(); if (MessageBox.Show(string.Format("Sửa môn học có mã '{0}'?", id), "", MessageBoxButtons.OKCancel) == DialogResult.OK) { tblMON m = new tblMON(); m.TenMon = txtTenMon.Text; m.SoDVHT = Convert.ToInt32(numsdvht.Text); m.MaMon = txtMaMon.Text; m.MaKhoa = cboKhoa.Text; m.HocKi = txtHocKy.Text; MONHOCF mh = new MONHOCF(); mh.Update(m); dgrMON.DataSource = context.tblMONs.ToList(); } }