private void button1_Click(object sender, EventArgs e) { // them giang vien GiaoVien gv = new GiaoVien(); gv.MonHoc = cb_MonHoc.Text; gv.GT = cb_GT.Text; gv.MaGV = tb_MaGV.Text; gv.HoTen = tb_HoTen.Text; gv.DiaChi = tb_DiaChi.Text; gv.NgaySinh = dt_NgaySinh.Value; bool add = new GiaoVienDAO().Insert(gv); if (!add) { MessageBox.Show("Mã GV đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Đã thêm giáo viên", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information); dtg_GiaoVien.DataSource = new GiaoVienDAO().ListAll(); tb_MaGV.Text = ""; tb_HoTen.Text = ""; tb_DiaChi.Text = ""; } }
private void dgvGiaoVien_Click(object sender, EventArgs e) { try { DataGridViewRow dr = dgvGiaoVien.SelectedRows[0]; txtMaGV.Text = dr.Cells["IDGiaoVien"].Value.ToString(); txtHoTen.Text = dr.Cells["HoTen"].Value.ToString(); // txtNgaySinh.Text = dr.Cells["IDGiaoVien"].Value.ToString(); cboGioiTinh.Text = dr.Cells["GioiTinh"].Value.ToString(); // txtMaMonHoc.Text = dr.Cells["IDMon"].Value.ToString(); txtDiachi.Text = dr.Cells["DiaChi"].Value.ToString(); txtSDT.Text = "0" + dr.Cells["SDT"].Value.ToString(); DateTime dt; DateTime.TryParse(dr.Cells["NgaySinh"].Value.ToString(), out dt); if (dt.Year > 1995) { dtpNgaySinh.Value = DateTimePicker.MinimumDateTime; } else { dtpNgaySinh.Value = dt; } //txtMaMonHoc.DataBindings.Clear(); //txtMaMonHoc.DataBindings.Add("Text", GiaoVienDAO.Lay_ThongtinMonhoc((int)dr.Cells["IDMon"].Value), "TenMon"); // lay cot [tenmon cboIDMon.DataSource = GiaoVienDAO.Lay_ThongtinMonhoc((int)dr.Cells["IDMon"].Value); cboIDMon.ValueMember = "IDMon"; cboIDMon.DisplayMember = "TenMon"; //cboIDMon.SelectedValue = (int)dr.Cells[" } catch { } }
private void button3_Click(object sender, EventArgs e) { // xoa giao vien bool del = new GiaoVienDAO().Delete(tb_MaGV.Text); MessageBox.Show("Đã xóa", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information); dtg_GiaoVien.DataSource = new GiaoVienDAO().ListAll(); }
private void frmGiaoVien_Load(object sender, EventArgs e) { dgvGiaoVien.DataSource = GiaoVienDAO.LoadDataGiaoVien(); SetHeaderColumn(); txtHienthi.Enabled = false; btnLưu.Enabled = false; LoadComboBox(); }
public void LoadComboBox() { cboTenLopTruong.DataSource = HocSinhDAO.LoadDataHocSinh(); cboTenLopTruong.ValueMember = "IDHocSinh"; cboTenLopTruong.DisplayMember = "HoTen"; cboTenGiaoVien.DataSource = GiaoVienDAO.LoadDataGiaoVien(); cboTenGiaoVien.ValueMember = "IDGiaoVien"; cboTenGiaoVien.DisplayMember = "HoTen"; }
private void btnSua_Click(object sender, EventArgs e) { hien(); DataGridViewRow dr = dgvBoMon.SelectedRows[0]; btnLuu.Visible = true; cboTruongBM.DataSource = GiaoVienDAO.LayThongTinGiaoVienVien((int)dr.Cells["IDMon"].Value); cboTruongBM.ValueMember = "IDGiaoVien"; cboTruongBM.DisplayMember = "HoTen"; luu = 2; }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaGV.Text == "" || txtTen.Text == "" || txtSDT.Text == "" || txtLuong.Text == "" || txtDiaChi.Text == "") { MessageBox.Show("Xin mời nhập đầy đủ thông tin"); Khoa_btn(); return; } else { //Them GV #region var giaovien = new tblGiaovien(); giaovien.MaGV = Convert.ToInt16(txtMaGV.Text); if (rdbNam.Checked) { giaovien.GT = "Nam"; } else { giaovien.GT = "Nữ"; } giaovien.Luong = Convert.ToInt32(txtLuong.Text); giaovien.NgaySinh = dtpNgaySinh.Value; giaovien.SDT = txtSDT.Text; giaovien.TenGV = txtTen.Text; giaovien.DiaChi = txtDiaChi.Text; var monhoc = new MonHocDAO(); giaovien.MaMon = (int)cboMamon.SelectedValue; var db = new GiaoVienDAO(); QLHSContex context = new QLHSContex(); context.Entry(giaovien).State = giaovien.MaGV == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; context.SaveChanges(); MessageBox.Show("Lưu thành công"); // txtMaGV.Enabled = false; btnLuu.Enabled = false; btnSua.Enabled = true; btnXoa.Enabled = true; LoadGV(); SetNull(); #endregion } }
private void dtg_GiaoVien_CellClick(object sender, DataGridViewCellEventArgs e) { dtg_GiaoVien.CurrentRow.Selected = true; string MaGV = dtg_GiaoVien.CurrentRow.Cells["MaGV"].Value.ToString(); var chosen = new GiaoVienDAO().GetByID(MaGV); tb_MaGV.Text = chosen.MaGV; tb_HoTen.Text = chosen.HoTen; tb_DiaChi.Text = chosen.DiaChi; dt_NgaySinh.Value = Convert.ToDateTime(chosen.NgaySinh); cb_GT.Text = chosen.GT; cb_MonHoc.Text = chosen.MonHoc; }
private void usr_GV_Load(object sender, EventArgs e) { GiaoVienDAO dtgv = new GiaoVienDAO(); dtg_GiaoVien.DataSource = dtgv.ListAll(); dtg_GiaoVien.Columns["MaGV"].HeaderText = "Mã GV"; dtg_GiaoVien.Columns["HoTen"].HeaderText = "Họ và tên"; dtg_GiaoVien.Columns["NgaySinh"].HeaderText = "Ngày Sinh"; dtg_GiaoVien.Columns["GT"].HeaderText = "Giới tính"; dtg_GiaoVien.Columns["DiaChi"].HeaderText = "Địa chi"; dtg_GiaoVien.Columns["MonHoc"].HeaderText = "Môn học"; }
private void dgvBoMon_Click(object sender, EventArgs e) { luu = 0; DataGridViewRow dr = dgvBoMon.SelectedRows[0]; txtIdMon.Text = dr.Cells["IDMon"].Value.ToString(); txtSoluong.Text = dr.Cells["SoLuong"].Value.ToString(); txtTenMon.Text = dr.Cells["TenMon"].Value.ToString(); cboTruongBM.DataSource = GiaoVienDAO.LayThongTinGiaoVienVien((int)dr.Cells["IDMon"].Value); cboTruongBM.ValueMember = "IDGiaoVien"; cboTruongBM.DisplayMember = "HoTen"; //hiển thị ra combobox theo tên giáo viên chứ không phải id! cboTruongBM.SelectedValue = (int)dr.Cells["IDMon"].Value; }
private void btnXoa_Click(object sender, EventArgs e) { if (txtMaGV.Text == "") { MessageBox.Show("Bạn chưa chọn giáo viên"); } else { GiaoVienDTO gv = new GiaoVienDTO(); gv.IDGiaoVien = int.Parse(txtMaGV.Text); GiaoVienDAO.XoaGV(gv); MessageBox.Show("Bạn đã xóa giáo viên thành công"); dgvGiaoVien.DataSource = GiaoVienDAO.LoadDataGiaoVien(); } }
private void btnLưu_Click(object sender, EventArgs e) { GiaoVienDTO gv = new GiaoVienDTO(); antext(); gv.IDGiaoVien = int.Parse(txtMaGV.Text); gv.HoTen = txtHoTen.Text; gv.NgaySinh = dtpNgaySinh.Value.ToShortDateString(); gv.GioiTinh = cboGioiTinh.Text; gv.DiaChi = txtDiachi.Text; gv.SDT = txtSDT.Text; gv.IDMon = (int)(cboIDMon.SelectedValue); if (choice_save == 1) { try { GiaoVienDAO.ThemGV(gv); dgvGiaoVien.DataSource = GiaoVienDAO.HienThiYeuCau(gv); MessageBox.Show("Bạn đã lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Bạn lưu chưa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (choice_save == 2) { if (txtMaGV.Text == "") { MessageBox.Show("Bạn chưa chọn dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { GiaoVienDAO.SuaGiaoVien(gv); dgvGiaoVien.DataSource = GiaoVienDAO.HienThiYeuCau(gv); MessageBox.Show("Bạn đã sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Bạn sửa bị lỗi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } MoDieuKhien(); }
private void btnThem_Click(object sender, EventArgs e) { // lưu, thêm active hientext(); btnLưu.Enabled = true; btnSua.Enabled = false; btnXoa.Enabled = false; btnRefresh.Enabled = false; choice_save = 1; choice_return = 1; txtMaGV.Focus(); // //if((int)GiaoVienDAO.getIDmin().Rows[0]["IDMin"]+1 <0) // dong 0 cot IDMax; // dem so dong cua IDGiaovien // rows[0] -> row[n-2] // neu ma so dang truoc kem so dang sau !=1 donvi thi tao cai ma so do +1 // vong lap for chay tu 0-> n-2; if ((int)GiaoVienDAO.countID().Rows[0]["numID"] == (int)GiaoVienDAO.getIDmax().Rows[0]["IDMax"]) { txtMaGV.Text = ((int)GiaoVienDAO.getIDmax().Rows[0]["IDMax"] + 1).ToString(); } if ((int)GiaoVienDAO.countID().Rows[0]["numID"] != (int)GiaoVienDAO.getIDmax().Rows[0]["IDMax"]) { for (int i = 1; i < (int)GiaoVienDAO.countID().Rows[0]["numID"]; i++) { if ((int)GiaoVienDAO.getID().Rows[0]["ID"] > 1) { txtMaGV.Text = ((int)GiaoVienDAO.getID().Rows[0]["ID"] - 1).ToString(); break; } if (((int)GiaoVienDAO.getID().Rows[i]["ID"] - (int)GiaoVienDAO.getID().Rows[i - 1]["ID"]) != 1) { txtMaGV.Text = ((int)GiaoVienDAO.getID().Rows[i - 1]["ID"] + 1).ToString(); break; } } } txtMaGV.Enabled = false; // txtMaMonHoc.Enabled = false; LoadComboBox(); }
private void button2_Click(object sender, EventArgs e) { // sua giao vien GiaoVien gv = new GiaoVien(); gv.MaGV = tb_MaGV.Text; gv.HoTen = tb_HoTen.Text; gv.MonHoc = cb_MonHoc.Text; gv.GT = cb_GT.Text; gv.NgaySinh = dt_NgaySinh.Value; gv.DiaChi = tb_DiaChi.Text; bool edit = new GiaoVienDAO().Update(gv); if (!edit) { MessageBox.Show("Không tồn tại giáo viên", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Đã sửa", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information); dtg_GiaoVien.DataSource = new GiaoVienDAO().ListAll(); } }
private void btnRefresh_Click(object sender, EventArgs e) { dgvGiaoVien.DataSource = GiaoVienDAO.LoadDataGiaoVien(); ResetText(); }
public GiaoVienBUS() { _GiaoVienDAO = new GiaoVienDAO(); }
private void btnSearch_Click(object sender, EventArgs e) { dgvGiaoVien.DataSource = GiaoVienDAO.Search(txtTimkiem.Text); }