private void FrmChuyenmon_Load(object sender, EventArgs e) { DAO.OpenConnection(); LoaddatatoGridview(); DAO.CloseConnection(); }
private void cboMaLop_DropDown_1(object sender, EventArgs e) { cboMaLop.DataSource = DAO.GetDataToTable("select MaLop from tblLophoc"); cboMaLop.ValueMember = "MaLop"; cboMaLop.SelectedIndex = -1; }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaGV.Text == "") { MessageBox.Show("Bạn chưa nhập mã giáo viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaGV.Focus(); return; } if (txtTenGV.Text == "") { MessageBox.Show("Bạn chưa nhập tên giáo viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTenGV.Focus(); return; } if (cboGioitinh.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn giới tính", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtSDT.Text == "") { MessageBox.Show("Bạn chưa nhập điểm", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtSDT.Focus(); return; } if (txtDiachi.Text == "") { MessageBox.Show("Bạn chưa nhập địa chỉ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtDiachi.Focus(); return; } if (cboMachucdanh.SelectedIndex == -1) { MessageBox.Show("mã chức danh chưa tồn tại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboNgay.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn ngày sinh", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboThang.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn tháng sinh", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboNam.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn Năm sinh", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboMachuyenmon.SelectedIndex == -1) { MessageBox.Show("mã chuyên môn chưa tồn tại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboMaCQ.SelectedIndex == -1) { MessageBox.Show("mã cơ quan chưa tồn tại ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cboMatrinhdo.SelectedIndex == -1) { MessageBox.Show("mã trình độ chưa tồn tại ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sqlCheckkey = "Select * from tblGiaovien where MaGV = '" + txtMaGV.Text.Trim() + "'"; DAO.OpenConnection(); if (DAO.checkKeyexit(sqlCheckkey)) { MessageBox.Show("Mã giáo viên đã tồn tại"); DAO.CloseConnection(); txtMaGV.Focus(); return; } else { string Ngaysinh; Ngaysinh = String.Format("{1}/{0}/{2}", cboNgay.Text, cboThang.Text, cboNam.Text); string sql = "insert into tblGiaovien values('" + txtMaGV.Text.Trim() + "',N'" + txtTenGV.Text.Trim() + "','" + Ngaysinh + "',N'" + cboGioitinh.Text.Trim() + "',N'" + txtDiachi.Text.Trim() + "','" + txtSDT.Text.Trim() + "','" + cboMachucdanh.SelectedValue.ToString() + "','" + cboMachuyenmon.SelectedValue.ToString() + "','" + cboMaCQ.Text.Trim() + "','" + cboMatrinhdo.Text.Trim() + "','" + txtAnh.Text.Trim() + "')"; SqlCommand cmd = new SqlCommand(sql, DAO.conn); cmd.ExecuteNonQuery(); LoaddatatoGridview(); filldatatocombo(); filldatatocombo1(); filldatatocombo2(); filldatatocombo3(); DAO.CloseConnection(); } }