private void btnThem_Click(object sender, EventArgs e) { if (txtMaGiaoVien.Text != "" && txtTenGiaoVien.Text != "" && txtNgaySinh.Text != "" && txtChucVu.Text != "" && txtChuyenNganh.Text != "" && txtSoTiet.Text != "" && cboTinhTrang.Text != "" && cboLop.Text != "") { if (KiemTraMa(txtMaGiaoVien.Text) == false) { tbGiaoVien gv = new tbGiaoVien(); gv.MaGiaoVien = txtMaGiaoVien.Text; gv.TenGiaoVien = txtTenGiaoVien.Text; gv.NgaySinh = DateTime.Parse(txtNgaySinh.Text); gv.ChucVu = txtChucVu.Text; gv.ChuyenNganh = txtChuyenNganh.Text; gv.SoTietDay = int.Parse(txtSoTiet.Text); gv.TinhTrangCongTac = cboTinhTrang.Text; gv.XepLoaiGiaoVien = cboXepLoai.Text; gv.DangDayLop = cboLop.Text; gv.TrinhDo = cboTrinhDo.Text; gv.DanToc = cboDanToc.Text; if (rdoNam.Checked == true) { gv.GioiTinh = "Nam"; } if (rdoNu.Checked == true) { gv.GioiTinh = "Nữ"; } db.tbGiaoViens.InsertOnSubmit(gv); db.SubmitChanges(); LoadDGVGiaoVien(); } else { MessageBox.Show("Hãy nhập mã khác!"); } } else { MessageBox.Show("Hãy điền đầy đủ thông tin cần thiết?"); } }
private void btnXoa_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có chắc muốn xóa thông tin này!?", "AptechFinanceManage", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK) { tbGiaoVien giaovien = db.tbGiaoViens.SingleOrDefault(gv => gv.TenGiaoVien == txtTenGiaoVien.Text); if (giaovien != null) { db.tbGiaoViens.DeleteOnSubmit(giaovien); dgvGiaoVien.Rows.RemoveAt(dgvGiaoVien.CurrentRow.Index); db.SubmitChanges(); LoadDGVGiaoVien(); } MessageBox.Show("Xóa thành công"); } else { MessageBox.Show(" "); } }
//Add click nam nữ radio button - xong //grv click //update delete private void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text == "" || txtMail.Text == "" || txtUser.Text == "" || txtPass.Text == "" || txtAddress.Text == "" || txtPhone.Text == "" || rdFemale.Checked == false && rdMale.Checked == false) { MessageBox.Show("Vui lòng nhập đầy đủ thông tin !"); } else { var checkdata = from l in db.tbGiaoViens where l.giaoVien_User == txtUser.Text select l; if (checkdata.Count() > 0) { MessageBox.Show("Tai Khoan Da Ton Tai !"); setnull(); } else { tbGiaoVien insert = new tbGiaoVien(); insert.giaoVien_Name = txtName.Text; insert.giaoVien_Email = txtMail.Text; insert.giaoVien_User = txtUser.Text; insert.giaoVien_Pass = txtPass.Text; insert.giaoVien_Address = txtAddress.Text; insert.giaoVien_Phone = txtPhone.Text; insert.giaoVien_NgaySinh = Convert.ToDateTime(dtDate.Text); if (rdMale.Checked) { insert.giaoVien_Gender = true; } else { insert.giaoVien_Gender = false; } db.tbGiaoViens.InsertOnSubmit(insert); db.SubmitChanges(); MessageBox.Show("Da Them Thanh Cong !"); getdata(); setnull(); // setrue(); } } }
private void btnSua_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có muốn sửa thông tin này!?", "AptechFinanceManage", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK) { hangchon = dgvGiaoVien.CurrentRow.Index; tbGiaoVien gv = db.tbGiaoViens.SingleOrDefault(g1 => g1.MaGiaoVien == txtMaGiaoVien.Text); //gv.MaGiaoVien = txtMaGiaoVien.Text; gv.TenGiaoVien = txtTenGiaoVien.Text; gv.NgaySinh = DateTime.Parse(txtNgaySinh.Text); if (dgvGiaoVien.Rows[hangchon].Cells[3].Value.ToString() == "Nam") { rdoNam.Checked = true; } if (dgvGiaoVien.Rows[hangchon].Cells[3].Value.ToString() == "Nữ") { rdoNu.Checked = true; } gv.ChucVu = txtChucVu.Text; gv.ChuyenNganh = txtChuyenNganh.Text; gv.SoTietDay = int.Parse(txtSoTiet.Text); cboTinhTrang.Text = ""; cboTinhTrang.Text = dgvGiaoVien.Rows[hangchon].Cells[7].Value.ToString(); cboXepLoai.Text = ""; cboXepLoai.Text = dgvGiaoVien.Rows[hangchon].Cells[8].Value.ToString(); cboLop.Text = ""; cboLop.Text = dgvGiaoVien.Rows[hangchon].Cells[9].Value.ToString(); cboTrinhDo.Text = ""; cboTrinhDo.SelectedText = dgvGiaoVien.Rows[hangchon].Cells[10].Value.ToString(); cboDanToc.Text = ""; cboDanToc.Text = dgvGiaoVien.Rows[hangchon].Cells[11].Value.ToString(); // db.SubmitChanges(); LoadDGVGiaoVien(); } else { MessageBox.Show("Sửa thành công!"); } }