private void frmLop_Load(object sender, EventArgs e) { string strSelect = "Select * From LopHoc"; MyPublic.OpenData(strSelect, lop, "LopHoc"); strSelect = "Select MaTT, TenTT From TrungTam"; MyPublic.OpenData(strSelect, trungtam, "TrungTam"); cbTrungtam.DataSource = trungtam.Tables["TrungTam"]; cbTrungtam.DisplayMember = "TenTT"; cbTrungtam.ValueMember = "MaTT"; txtMalop.MaxLength = 8; txtTenlop.MaxLength = 40; dgvLophoc.DataSource = lop; dgvLophoc.DataMember = "LopHoc"; dgvLophoc.Width = 525; dgvLophoc.AllowUserToAddRows = false; dgvLophoc.AllowUserToDeleteRows = false; dgvLophoc.Columns[0].Width = 100; dgvLophoc.Columns[0].HeaderText = "Mã lớp"; dgvLophoc.Columns[1].Width = 265; dgvLophoc.Columns[1].HeaderText = "Tên lớp"; dgvLophoc.Columns[2].Width = 100; dgvLophoc.Columns[2].HeaderText = "Mã trung tâm"; dgvLophoc.EditMode = DataGridViewEditMode.EditProgrammatically; GanDuLieu(); DieuKhienKhiBinhThuong(); }
private void xoaBtn_Click(object sender, EventArgs e) { int currentRow = dsMHGridView.CurrentRow.Index; DialogResult dialog = MessageBox.Show("Bạn có thực sự muốn xóa môn học này không?", "Thông báo", MessageBoxButtons.YesNo); if (dialog == DialogResult.No) { return; } if (MyPublic.connection.State == ConnectionState.Closed) { MyPublic.connection.Open(); } if (MyPublic.tonTaiKhoaChinh("MaMon", mamonTextBox.Text, "TheoDoiBaiThi")) { MessageBox.Show("Bạn phải xóa các bài thi có liên quan tới môn học này trước!", "Thông báo", MessageBoxButtons.OK); return; } string query = "DELETE FROM MonHoc WHERE MaMon=@MAMON"; SqlCommand command = new SqlCommand(query, MyPublic.connection); command.Parameters.AddWithValue("@MAMON", dsMonHoc.Rows[currentRow]["MaMon"]); command.ExecuteNonQuery(); dsMonHoc.Rows.RemoveAt(currentRow); }
private void btnXoa_Click(object sender, EventArgs e) { if (MyPublic.tonTaiKhoaChinh("MaLop", txtMalop.Text, "TheoDoiBaiThi")) { MessageBox.Show("Phải xóa dữ liệu bài thi của lớp trước !"); } else { DialogResult dongY; dongY = MessageBox.Show("Bạn thật sự muốn xóa ?", "Xác Nhận", MessageBoxButtons.YesNo); if (dongY == DialogResult.Yes) { string delete = "Delete LopHoc Where MaLop = @MaLop"; if (MyPublic.connection.State == ConnectionState.Closed) { MyPublic.connection.Open(); } SqlCommand cmdCommand = new SqlCommand(delete, MyPublic.connection); cmdCommand.Parameters.AddWithValue("@MaLop", txtMalop.Text); cmdCommand.ExecuteNonQuery(); MyPublic.connection.Close(); int curRow = dgvLophoc.CurrentRow.Index; lop.Tables["LopHoc"].Rows.RemoveAt(curRow); GanDuLieu(); } } DieuKhienKhiBinhThuong(); }
private void btnXoa_Click(object sender, EventArgs e) { if (MyPublic.tonTaiKhoaChinh("MaMon", cbMonhoc.SelectedValue.ToString(), "MonHoc")) { MessageBox.Show("Phải xóa dữ liệu môn học này trước !"); } else { DialogResult dongY; dongY = MessageBox.Show("Bạn thật sự muốn xóa ?", "Xác Nhận", MessageBoxButtons.YesNo); if (dongY == DialogResult.Yes) { string delete = "Delete TheoDoiBaiThi Where MaMon = @MaMon And MaLop = @MaLop"; if (MyPublic.connection.State == ConnectionState.Closed) { MyPublic.connection.Open(); } SqlCommand command = new SqlCommand(delete, MyPublic.connection); command.Parameters.AddWithValue("@MaMon", cbMonhoc.SelectedValue); command.Parameters.AddWithValue("@MaLop", cbLophoc.SelectedValue); command.ExecuteNonQuery(); MyPublic.connection.Close(); int curRow = dgvBaithitheolop.CurrentRow.Index; dsbaithi.Tables["TheoDoiBaiThi"].Rows.RemoveAt(curRow); GanDuLieu(); } } DieuKhienKhiBinhThuong(); }
private void luuBtn_Click(object sender, EventArgs e) { if (mamonTextBox.Text == "" || tenmonTextBox.Text == "" || tinchiTextBox.Text == "") { MessageBox.Show("Không được để trống thông tin!", "Thông báo", MessageBoxButtons.OK); return; } int sotinchi; if (!int.TryParse(tinchiTextBox.Text, out sotinchi)) { MessageBox.Show("Thông tin không hợp lệ!", "Thông báo", MessageBoxButtons.OK); return; } if (MyPublic.connection.State == ConnectionState.Closed) { MyPublic.connection.Open(); } string query; SqlCommand command; int currentRow = dsMHGridView.CurrentRow.Index; if (MyPublic.tonTaiKhoaChinh("MaMon", mamonTextBox.Text, "MonHoc") && action == "them") { MessageBox.Show("Môn học đã tồn tại!", "Thông báo", MessageBoxButtons.OK); return; } if (action == "them") { query = "INSERT INTO MonHoc VALUES(@MAMON, @TENMON, @SOTINCHI)"; command = new SqlCommand(query, MyPublic.connection); command.Parameters.AddWithValue("@MAMON", mamonTextBox.Text); command.Parameters.AddWithValue("@TENMON", tenmonTextBox.Text); command.Parameters.AddWithValue("@SOTINCHI", sotinchi); dsMonHoc.Rows.Add(mamonTextBox.Text, tenmonTextBox.Text, sotinchi); } else { query = "UPDATE MonHoc SET TenMon=@TENMON, SoTinChi=@SOTINCHI WHERE MaMon=@MAMON"; command = new SqlCommand(query, MyPublic.connection); command.Parameters.AddWithValue("@TENMON", tenmonTextBox.Text); command.Parameters.AddWithValue("@SOTINCHI", sotinchi); command.Parameters.AddWithValue("@MAMON", mamonTextBox.Text); dsMonHoc.Rows[currentRow]["MaMon"] = mamonTextBox.Text; dsMonHoc.Rows[currentRow]["TenMon"] = tenmonTextBox.Text; dsMonHoc.Rows[currentRow]["SoTinChi"] = sotinchi; } command.ExecuteNonQuery(); toggleEdit(false); }
private void frmMain_Load(object sender, EventArgs e) { MyPublic.createConnection(); mnuDulieu.Enabled = false; mnuTienich.Enabled = false; mnuDoimatkhau.Enabled = false; mnuThoatdangnhap.Enabled = false; }
private void luuBtn_Click(object sender, EventArgs e) { if (tenTKTextBox.Text == "" || quyenSDCBBox.SelectedIndex == -1 || maTTCBBox.SelectedIndex == -1) { MessageBox.Show("Không được để trống thông tin!", "Thông báo", MessageBoxButtons.OK); return; } if (MyPublic.connection.State == ConnectionState.Closed) { MyPublic.connection.Open(); } string query; SqlCommand command; int currentRow = dsTKGridView.CurrentRow.Index; if (MyPublic.tonTaiKhoaChinh("TenTaiKhoan", tenTKTextBox.Text, "NguoiSuDung") && action == "them") { MessageBox.Show("Tài khoản đã tồn tại!", "Thông báo", MessageBoxButtons.OK); return; } if (action == "them") { query = "INSERT INTO NguoiSuDung VALUES(@TAIKHOAN, @MATKHAU, @QUYENSD, @MATT)"; command = new SqlCommand(query, MyPublic.connection); command.Parameters.AddWithValue("@TAIKHOAN", tenTKTextBox.Text); command.Parameters.AddWithValue("@QUYENSD", quyenSDCBBox.SelectedValue); command.Parameters.AddWithValue("@MATT", maTTCBBox.SelectedValue); command.Parameters.AddWithValue("@MATKHAU", showRequirePasswordPrompt());; dsNguoiSD.Rows.Add(tenTKTextBox.Text, quyenSDCBBox.SelectedValue, maTTCBBox.SelectedValue); } else { query = "UPDATE NguoiSuDung SET QuyenSD=@QUYENSD, MaTT=@MATT WHERE TenTaiKhoan=@TAIKHOAN"; command = new SqlCommand(query, MyPublic.connection); command.Parameters.AddWithValue("@QUYENSD", quyenSDCBBox.SelectedValue); command.Parameters.AddWithValue("@MATT", maTTCBBox.SelectedValue); command.Parameters.AddWithValue("@TAIKHOAN", tenTKTextBox.Text); dsNguoiSD.Rows[currentRow]["TenTaiKhoan"] = tenTKTextBox.Text; dsNguoiSD.Rows[currentRow]["QuyenSD"] = quyenSDCBBox.SelectedValue; dsNguoiSD.Rows[currentRow]["MaTT"] = maTTCBBox.SelectedValue; } command.ExecuteNonQuery(); toggleEdit(false); }
private void frmBaithitheolophoc_Load(object sender, EventArgs e) { string select = "Select MaLop, MaMon, LanThi, HocKy, NamHoc, NgayThi, SoBai, NgayNhan, HanNop From TheoDoiBaiThi"; MyPublic.OpenData(select, dsbaithi, "TheoDoiBaiThi"); select = "Select TenLop, MaLop From LopHoc"; MyPublic.OpenData(select, lop, "LopHoc"); select = "Select MaMon, TenMon From MonHoc"; MyPublic.OpenData(select, mon, "MonHoc"); cbLophoc.DataSource = lop.Tables["LopHoc"]; cbLophoc.DisplayMember = "TenLop"; cbLophoc.ValueMember = "MaLop"; cbMonhoc.DataSource = mon.Tables["MonHoc"]; cbMonhoc.DisplayMember = "TenMon"; cbMonhoc.ValueMember = "MaMon"; dvbaithi.Table = dsbaithi.Tables["TheoDoiBaiThi"]; dvbaithi.RowFilter = "MaLop like '" + cbLophoc.SelectedValue + "'"; dgvBaithitheolop.DataSource = dvbaithi; dgvBaithitheolop.Width = 723; dgvBaithitheolop.AllowUserToAddRows = false; dgvBaithitheolop.AllowUserToDeleteRows = false; dgvBaithitheolop.Columns[0].Width = 70; dgvBaithitheolop.Columns[0].HeaderText = "Mã lớp"; dgvBaithitheolop.Columns[1].Width = 70; dgvBaithitheolop.Columns[1].HeaderText = "Mã môn"; dgvBaithitheolop.Columns[2].Width = 65; dgvBaithitheolop.Columns[2].HeaderText = "Lần thi"; dgvBaithitheolop.Columns[3].Width = 70; dgvBaithitheolop.Columns[3].HeaderText = "Học Kỳ"; dgvBaithitheolop.Columns[4].Width = 80; dgvBaithitheolop.Columns[4].HeaderText = "Năm học"; dgvBaithitheolop.Columns[5].Width = 80; dgvBaithitheolop.Columns[5].HeaderText = "Ngày thi"; dgvBaithitheolop.Columns[5].DefaultCellStyle.Format = "dd/MM/yyyy"; dgvBaithitheolop.Columns[6].Width = 80; dgvBaithitheolop.Columns[6].HeaderText = "Số bài thi"; dgvBaithitheolop.Columns[7].Width = 85; dgvBaithitheolop.Columns[7].HeaderText = "Ngày nhận"; dgvBaithitheolop.Columns[7].DefaultCellStyle.Format = "dd/MM/yyyy"; dgvBaithitheolop.Columns[8].Width = 80; dgvBaithitheolop.Columns[8].HeaderText = "Hạn nộp"; dgvBaithitheolop.Columns[8].DefaultCellStyle.Format = "dd/MM/yyyy"; dgvBaithitheolop.EditMode = DataGridViewEditMode.EditProgrammatically; GanDuLieu(); DieuKhienKhiBinhThuong(); }
private void btnLuu_Click(object sender, EventArgs e) { if ((txtMalop.Text == "") || (txtTenlop.Text == "") || (cbTrungtam.SelectedIndex == -1)) { MessageBox.Show("Lỗi nhập dữ liệu !"); } else if ((blnThem) && (MyPublic.tonTaiKhoaChinh(txtMalop.Text, "MaLop", "LopHoc"))) { MessageBox.Show("Mã số lớp này đã có rồi !"); txtMalop.Focus(); } else { Luu(); } }
private void frmMon_Load(object sender, EventArgs e) { dsMHGridView.AllowUserToAddRows = false; dsMHGridView.AllowUserToDeleteRows = false; mamonTextBox.MaxLength = 6; tenmonTextBox.MaxLength = 60; tinchiTextBox.MaxLength = 10; string query = "SELECT MaMon, TenMon, SoTinChi FROM MonHoc"; DataSet dataSet = new DataSet(); MyPublic.OpenData(query, dataSet, "MonHoc"); dsMonHoc = dataSet.Tables["MonHoc"]; dsMHGridView.DataSource = dataSet.Tables["MonHoc"]; dsMHGridView.Columns[0].Width = 95; dsMHGridView.Columns[0].HeaderText = "Mã Môn"; dsMHGridView.Columns[1].Width = 250; dsMHGridView.Columns[1].HeaderText = "Tên Môn"; dsMHGridView.Columns[2].Width = 100; dsMHGridView.Columns[2].HeaderText = "Số Tín Chỉ"; if (MyPublic.quyenSD == "AdTinh" || MyPublic.quyenSD == "AdTruong") { themBtn.Enabled = true; suaBtn.Enabled = true; xoaBtn.Enabled = true; } else { themBtn.Enabled = false; suaBtn.Enabled = false; xoaBtn.Enabled = false; } dsMHGridView.Enabled = true; mamonTextBox.Enabled = false; tenmonTextBox.Enabled = false; tinchiTextBox.Enabled = false; luuBtn.Enabled = false; khongluuBtn.Enabled = false; displayRowAt(0); }
private void frmTaikhoan_Load(object sender, EventArgs e) { dsTKGridView.AllowUserToAddRows = false; dsTKGridView.AllowUserToDeleteRows = false; tenTKTextBox.MaxLength = 20; // set data cho combobox DataTable table = new DataTable(); table.Columns.Add("QuyenSD"); table.Rows.Add("User"); table.Rows.Add("AdTruong"); table.Rows.Add("AdTinh"); quyenSDCBBox.DataSource = table; quyenSDCBBox.DisplayMember = "QuyenSD"; quyenSDCBBox.ValueMember = "QuyenSD"; // set data cho data ma tt combobox if (MyPublic.connection.State == ConnectionState.Closed) { MyPublic.connection.Open(); } string query = "SELECT MaTT, TenTT FROM TrungTam"; DataSet dataSet = new DataSet(); MyPublic.OpenData(query, dataSet, "TrungTam"); maTTCBBox.DataSource = dataSet.Tables["TrungTam"]; maTTCBBox.DisplayMember = "TenTT"; maTTCBBox.ValueMember = "MaTT"; // set data cho data grid view query = "SELECT TenTaiKhoan, QuyenSD, MaTT FROM NguoiSuDung"; dataSet = new DataSet(); MyPublic.OpenData(query, dataSet, "NguoiSuDung"); dsNguoiSD = dataSet.Tables["NguoiSuDung"]; dsTKGridView.DataSource = dataSet.Tables["NguoiSuDung"]; dsTKGridView.Columns[0].Width = 125; dsTKGridView.Columns[0].HeaderText = "Tên tài khoản"; dsTKGridView.Columns[1].Width = 125; dsTKGridView.Columns[1].HeaderText = "Quyền sử dụng"; dsTKGridView.Columns[2].Width = 125; dsTKGridView.Columns[2].HeaderText = "Mã trung tâm"; // highlight cac button if (MyPublic.quyenSD == "AdTinh") { themBtn.Enabled = true; suaBtn.Enabled = true; xoaBtn.Enabled = true; } else { themBtn.Enabled = false; suaBtn.Enabled = false; xoaBtn.Enabled = false; } dsTKGridView.Enabled = true; tenTKTextBox.Enabled = false; maTTCBBox.Enabled = false; quyenSDCBBox.Enabled = false; luuBtn.Enabled = false; khongluuBtn.Enabled = false; // select tai khoan dau tien displayRowAt(0); }
private void frmBaithi_Load(object sender, EventArgs e) { dtpNgaythi.Format = DateTimePickerFormat.Custom; dtpNgaythi.CustomFormat = "dd-MM-yyyy"; dtpNgaynhan.Format = DateTimePickerFormat.Custom; dtpNgaynhan.CustomFormat = "dd-MM-yyyy"; dtpHannop.Format = DateTimePickerFormat.Custom; dtpHannop.CustomFormat = "dd-MM-yyyy"; dgvBaithi.AllowUserToAddRows = false; dgvBaithi.AllowUserToDeleteRows = false; txtNamhoc.MaxLength = 10; txtLanthi.MaxLength = 10; txtSobaithi.MaxLength = 10; string select = "Select MaLop, TenLop From LopHoc"; DataSet dataset = new DataSet(); MyPublic.OpenData(select, dataset, "LopHoc"); cbLophoc.DataSource = dataset.Tables["LopHoc"]; cbLophoc.DisplayMember = "TenLop"; cbLophoc.ValueMember = "MaLop"; select = "Select MaMon, TenMon From MonHoc"; dataset = new DataSet(); MyPublic.OpenData(select, dataset, "MonHoc"); cbMonhoc.DataSource = dataset.Tables["MonHoc"]; cbMonhoc.DisplayMember = "TenMon"; cbMonhoc.ValueMember = "MaMon"; select = "Select * From TheoDoiBaiThi"; dataset = new DataSet(); MyPublic.OpenData(select, dataset, "TheoDoiBaiThi"); dtBaithi = dataset.Tables["TheoDoiBaiThi"]; dgvBaithi.DataSource = dataset.Tables["TheoDoiBaiThi"]; dgvBaithi.Width = 723; dgvBaithi.Columns[0].Width = 70; dgvBaithi.Columns[0].HeaderText = "Mã Môn"; dgvBaithi.Columns[1].Width = 70; dgvBaithi.Columns[1].HeaderText = "Mã Lớp"; dgvBaithi.Columns[2].Width = 65; dgvBaithi.Columns[2].HeaderText = "Lần thi"; dgvBaithi.Columns[3].Width = 70; dgvBaithi.Columns[3].HeaderText = "Học Kỳ"; dgvBaithi.Columns[4].Width = 80; dgvBaithi.Columns[4].HeaderText = "Năm học"; dgvBaithi.Columns[5].Width = 80; dgvBaithi.Columns[5].HeaderText = "Ngày thi"; dgvBaithi.Columns[5].DefaultCellStyle.Format = "dd/MM/yyyy"; dgvBaithi.Columns[6].Width = 80; dgvBaithi.Columns[6].HeaderText = "Số bài thi"; dgvBaithi.Columns[7].Width = 85; dgvBaithi.Columns[7].HeaderText = "Ngày nhận"; dgvBaithi.Columns[7].DefaultCellStyle.Format = "dd/MM/yyyy"; dgvBaithi.Columns[8].Width = 80; dgvBaithi.Columns[8].HeaderText = "Hạn nộp"; dgvBaithi.Columns[8].DefaultCellStyle.Format = "dd/MM/yyyy"; if (MyPublic.quyenSD == "AdTinh" || MyPublic.quyenSD == "AdTruong") { btnThem.Enabled = true; btnSua.Enabled = true; btnXoa.Enabled = true; } else { btnThem.Enabled = false; btnSua.Enabled = false; btnXoa.Enabled = false; } dgvBaithi.Enabled = true; cbMonhoc.Enabled = false; cbLophoc.Enabled = false; txtLanthi.Enabled = false; rbtnHocky1.Enabled = false; rbtnHocky2.Enabled = false; txtNamhoc.Enabled = false; dtpNgaythi.Enabled = false; txtSobaithi.Enabled = false; dtpNgaynhan.Enabled = false; dtpHannop.Enabled = false; btnLuu.Enabled = false; btnKhongluu.Enabled = false; displayRowAt(0); }