private void button1_Click(object sender, EventArgs e) { if (txtMaLop.Text.Trim() == "") { MessageBox.Show("Chưa nhập mã lớp", "Thông báo"); } else { if (context.tblLOPs.Find(txtMaLop.Text.Trim()) != null) { MessageBox.Show("Mã lớp đã tồn tại", "Thông báo"); } else { tblLOP g = new tblLOP(); g.MaLop = txtMaLop.Text; g.MaKhoa = cboKhoa.Text; g.TenLop = txtTenlop.Text; var result = new LOPF().Insert(g); dgrLop.DataSource = context.tblLOPs.ToList(); txtMaLop.Clear(); txtTenlop.Clear(); cboKhoa.Text = ""; } } }
private void button2_Click(object sender, EventArgs e) { string id = txtMaLop.Text.Trim(); if (MessageBox.Show(string.Format("Sửa lớp có mã '{0}'?", id), "", MessageBoxButtons.OKCancel) == DialogResult.OK) { tblLOP g = new tblLOP(); g.MaLop = txtMaLop.Text; g.MaKhoa = cboKhoa.Text; g.TenLop = txtTenlop.Text; var result = new LOPF().Update(g); dgrLop.DataSource = context.tblLOPs.ToList(); } }
private void btnXoa_Click(object sender, EventArgs e) { try { DialogResult result = MessageBox.Show("Bạn có muốn xóa nhà cung cấp " + txtTenLop.Text + " không?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { var ans = new LOPF().Delete(new LOP { malop = int.Parse(txtMaLop.Text) }); Init_(); ClearBinding(); Bindingtxt(); } } catch { } }
private void btnLuu_Click(object sender, EventArgs e) { try { LOP model = new LOP() { tenlop = txtTenLop.Text, quanso = int.Parse(txtQuanSo.Text), namhoc = txtNamHoc.Text }; int ID_ = -1; if (txtMaLop.Text != "") { ID_ = int.Parse(txtMaLop.Text.ToString()); } model.malop = ID_; if (txtMaLop.Text == "") { var result = new LOPF().Insert(model); if (result) { MessageBox.Show("Done"); } else { MessageBox.Show("Lỗi"); } } else { var result = new LOPF().Update(model); if (result) { MessageBox.Show("Done"); } else { MessageBox.Show("Lỗi"); } } Init_(); ClearBinding(); Bindingtxt(); } catch (Exception exp) { MessageBox.Show(exp.Message); } }