Exemplo n.º 1
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            if (tblHeDaoTao.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaHDT.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenHDT.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên hệ đào tạo", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenHDT.Focus();
                return;
            }
            sql = "UPDATE HeDaoTao SET TenHDT=N'" + txtTenHDT.Text.ToString() + "' WHERE MaHDT=N'" + txtMaHDT.Text + "'";
            DAO.RunSql(sql);
            Load_DataGridView();
            ResetValues();
            btnHuy.Enabled = false;
            DAO.CloseConnection();
        }
Exemplo n.º 2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            if (tblKhoa.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaKhoa.Text == "")
            {
                MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenKhoa.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên khoa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenKhoa.Focus();
                return;
            }
            sql = "Update Khoa set TenKhoa = N'" + txtTenKhoa.Text.Trim() + "', DienThoai = N'" + txtDienThoai.Text.Trim()
                  + "',DiaChi = N'" + txtDiaChi.Text.Trim() + "', Website = N'" + txtWebsite.Text.Trim() + "' where MaKhoa = '"
                  + txtMaKhoa.Text.ToString() + "'";
            DAO.RunSql(sql);
            LoadDataToGrivew();
            ResetValues();
            btnHuy.Enabled = false;
            DAO.CloseConnection();
        }
Exemplo n.º 3
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            string sql;

            if (tblDanToc.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaDanToc.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            sql = "select MaDanToc from SinhVien where MaDanToc='" + txtMaDanToc.Text.Trim() + "'";
            if (DAO.CheckKeyExist(sql))
            {
                MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    sql = "DELETE DanToc WHERE MaDanToc=N'" + txtMaDanToc.Text + "'";
                    DAO.RunSql(sql);
                    Load_DataGridView();
                    ResetValues();
                }
            }
        }
Exemplo n.º 4
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql;

            if (tblDanToc.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaDanToc.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenDanToc.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên dân tộc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenDanToc.Focus();
                return;
            }
            sql = "UPDATE DanToc SET TenDanToc=N'" + txtTenDanToc.Text.ToString() + "' WHERE MaDanToc=N'" + txtMaDanToc.Text + "'";
            DAO.RunSql(sql);
            Load_DataGridView();
            ResetValues();
            btnHuy.Enabled = false;
        }
Exemplo n.º 5
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            if (tblChucVu.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaChucVu.Text == "")
            {
                MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenChucVu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên chức vụ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenChucVu.Focus();
                return;
            }
            sql = "Update ChucVu set TenChucVu = N'" + txtTenChucVu.Text.Trim() + "' where MaChucVu = '" + txtMaChucVu.Text.Trim() + "'";
            DAO.RunSql(sql);
            LoadDataToGrivew();
            ResetValues();
            btnHuy.Enabled = false;
            DAO.CloseConnection();
        }
Exemplo n.º 6
0
        private void FrmDiem_Load(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            //Load_DataGridView();
            string str;

            str = "INSERT INTO Diem(MaSV,MaLop,MaMon,HocKy,LanThi,Diem) SELECT MaSV, Thoi_Khoa_Bieu.MaLop, MaMon, HocKy,1, null FROM SinhVien inner join Thoi_Khoa_Bieu on SinhVien.MaLop = Thoi_Khoa_Bieu.MaLop WHERE MaSV NOT IN(SELECT MaSV FROM Diem)";
            DAO.RunSql(str);
            string sql = "select MaLop from Lop";

            DAO.FillDataToCombo(sql, cmbMaLop, "MaLop", "MaLop");
            sql = "select MaMon, TenMon from MonHoc";
            DAO.FillDataToCombo(sql, cmbMonHoc, "MaMon", "TenMon");
            btnLuu.Enabled     = false;
            btnHuy.Enabled     = false;
            btnQuayLai.Enabled = false;
            btnSua.Enabled     = false;
            txtMaSV.Enabled    = false;
            txtTenSV.Enabled   = false;
            txtDiem.Enabled    = false;
            ResetValues();
            cmbMaLop.DropDownStyle  = System.Windows.Forms.ComboBoxStyle.DropDownList;
            cmbHocKy.DropDownStyle  = System.Windows.Forms.ComboBoxStyle.DropDownList;
            cmbMonHoc.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            //txtLanThi.MaxLength = 1;
            GridViewDiem.AllowUserToAddRows = false;
        }
Exemplo n.º 7
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            //DAO.OpenConnection();
            string sql;

            if (tblKhoa.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaKhoa.Text == "")
            {
                MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            sql = "select MaKhoa from ChuyenNganh where MaKhoa='" + txtMaKhoa.Text.Trim() + "'";
            string sql1 = "select MaKhoa from SinhVien where MaKhoa='" + txtMaKhoa.Text.Trim() + "'";
            string sql2 = "select MaKhoa from Lop where MaKhoa='" + txtMaKhoa.Text.Trim() + "'";

            if (DAO.CheckKeyExist(sql) || DAO.CheckKeyExist(sql1) || DAO.CheckKeyExist(sql2))
            {
                MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    sql = "DELETE Khoa WHERE MaKhoa='" + txtMaKhoa.Text.ToString() + "'";
                    DAO.RunSql(sql);
                    LoadDataToGrivew();
                    ResetValues();
                }
            }
            //DAO.CloseConnection();
        }
Exemplo n.º 8
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            if (tblDiem.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaSV.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                sql = "DELETE Diem WHERE MaSV=N'" + txtMaSV.Text.Trim() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
                DAO.OpenConnection();
                DAO.RunSql(sql);
                DAO.OpenConnection();
                if (btnQuayLai.Enabled == false)
                {
                    Load_DataGridView();
                }
                else
                {
                    Load_DataGridView1();
                }
                txtMaSV.Text = "";
                txtDiem.Text = "";
                //txtDiem.Enabled = false;
            }
        }
Exemplo n.º 9
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            if (txtMaKhoa.Text == "")
            {
                MessageBox.Show("bạn chưa nhập mã khoa ");
                txtMaKhoa.Focus();
                return;
            }
            if (txtTenKhoa.Text == "")
            {
                MessageBox.Show("bạn chưa nhập tên khoa");
                txtTenKhoa.Focus();
                return;
            }
            if (txtDienThoai.Text == "")
            {
                MessageBox.Show("bạn chưa nhập số điện thoại ");
                txtDienThoai.Focus();
                return;
            }
            if (txtDiaChi.Text == "")
            {
                MessageBox.Show("bạn chưa nhập địa chỉ ");
                txtDiaChi.Focus();
                return;
            }
            if (txtWebsite.Text == "")
            {
                MessageBox.Show("bạn chưa nhập website ");
                txtWebsite.Focus();
                return;
            }

            string sqlCheckKey = "Select * from Khoa Where MaKhoa = '"
                                 + txtMaKhoa.Text.ToString() + "'";

            if (DAO.CheckKeyExist(sqlCheckKey))
            {
                MessageBox.Show("Mã khoa đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DAO.CloseConnection();
                txtMaKhoa.Focus();
                return;
            }
            string sql = "insert into Khoa values ('" +
                         txtMaKhoa.Text.ToString() + "' , N'" +
                         txtTenKhoa.Text.Trim() + "','" + txtDienThoai.Text.Trim() + "','" + txtDiaChi.Text.Trim() + "','" + txtWebsite.Text.Trim() + "')";

            DAO.RunSql(sql);
            LoadDataToGrivew();
            GridViewKhoa.Enabled = true;
            ResetValues();
            btnXoa.Enabled    = true;
            btnThem.Enabled   = true;
            btnSua.Enabled    = true;
            btnHuy.Enabled    = true;
            btnLuu.Enabled    = false;
            txtMaKhoa.Enabled = false;
            DAO.CloseConnection();
        }
Exemplo n.º 10
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            int s1 = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + cmbMaLop.SelectedValue + "'"));

            if (tblSinhVien.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaSV.Text == "")
            {
                MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string s11 = "select MaSV from Diem where MaSV='" + txtMaSV.Text.Trim() + "'";

            if (DAO.CheckKeyExist(s11) == true)
            {
                MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (s1 > 0)
                {
                    if (MessageBox.Show("bạn có muốn xóa không?", "thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        sql = " delete from SinhVien where MaSV='" + txtMaSV.Text + "'";
                        String sql1 = " update Lop set SiSo = SiSo -1 WHERE MaLop = '" + cmbMaLop.SelectedValue + "'";
                        DAO.RunSql(sql1);
                        s1 = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + cmbMaLop.SelectedValue + "'"));
                        MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + cmbMaLop.Text + "' là " + s1, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        DAO.OpenConnection();
                        DAO.RunSql(sql);
                        ResetValues();
                        LoadDatatogriview();
                    }
                    if (s1 == 0)
                    {
                        string sql = DAO.GetFieldValues(" select MaLop from Lop where SiSo = " + s1 + "");
                        if (MessageBox.Show("sĩ số lớp bằng 0, Bạn có muốn xóa lớp không", "thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            string ss = " select MaSV from SinhVien where MaLop ='" + sql + "'";
                            if (DAO.CheckKeyExist(ss) == false)
                            {
                                string s = "delete from Lop where MaLop='" + sql + "'";
                                MessageBox.Show(s);
                                DAO.OpenConnection();
                                DAO.RunSql(s);
                                DAO.CloseConnection();
                                ResetValues();
                                LoadDatatogriview();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            if (tblDiem.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaSV.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) > 10))
            {
                MessageBox.Show("Bạn nhập sai điểm.Nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiem.Focus();
                return;
            }
            if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) >= 5)
            {
                MessageBox.Show("Sinh viên này không phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                sql = "DELETE Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'";
                //MessageBox.Show(ql);
                DAO.RunSql(sql);
            }
            if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) < 5)
            {
                MessageBox.Show("Sinh viên này phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.Text + "','" + cmbMonHoc.SelectedValue + "',"
                      + cmbHocKy.Text + "," + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + ",null)";
                //MessageBox.Show(sql);
                DAO.RunSql(sql);
            }
            sql = "UPDATE Diem SET Diem = ROUND(" + GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString() + ",1) WHERE MaSV=N'" + txtMaSV.Text.Trim() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
            //MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() +"',
            DAO.RunSql(sql);
            DAO.CloseConnection();
            if (btnQuayLai.Enabled == false)
            {
                Load_DataGridView();
            }
            else
            {
                Load_DataGridView1();
            }
        }
Exemplo n.º 12
0
        private void checkupdate()
        {
            string d1 = "delete from Diem where MaSV =(SELECT distinct Diem.MaSV FROM SinhVien inner join Diem on SinhVien.MaSV=Diem.MaSV where SinhVien.MaLop != Diem.MaLop)";

            // MessageBox.Show(d1);
            DAO.RunSql(d1);
            string d = "INSERT INTO Diem(MaSV,MaLop,MaMon,HocKy,LanThi,Diem) SELECT distinct MaSV, Thoi_Khoa_Bieu.MaLop, MaMon, HocKy,1, null FROM SinhVien inner join Thoi_Khoa_Bieu on SinhVien.MaLop = Thoi_Khoa_Bieu.MaLop WHERE MaSV=(SELECT distinct Diem.MaSV FROM SinhVien inner join Diem on SinhVien.MaSV=Diem.MaSV where SinhVien.MaLop != Diem.MaLop)";

            DAO.RunSql(d);
            //MessageBox.Show(d);
            string str;

            str = "INSERT INTO Diem(MaSV,MaLop,MaMon,HocKy,LanThi,Diem) SELECT distinct MaSV, Thoi_Khoa_Bieu.MaLop, MaMon, HocKy,1, null FROM SinhVien inner join Thoi_Khoa_Bieu on SinhVien.MaLop = Thoi_Khoa_Bieu.MaLop WHERE MaSV NOT IN(SELECT MaSV FROM Diem)";
            DAO.RunSql(str);
        }
Exemplo n.º 13
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            if (txtMaQue.Text == "")
            {
                MessageBox.Show("bạn chưa nhập mã quê ");
                txtMaQue.Focus();
                return;
            }
            if (txtTenQue.Text == "")
            {
                MessageBox.Show("bạn chưa nhập tên quê");
                txtTenQue.Focus();
                return;
            }
            string sqlCheckKey = "Select * from Que Where MaQue = '"
                                 + txtMaQue.Text.Trim() + "'";

            DAO.OpenConnection();


            if (DAO.CheckKeyExist(sqlCheckKey))
            {
                MessageBox.Show("Mã quê đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DAO.CloseConnection();
                txtMaQue.Focus();
                return;
            }
            string sql = "insert into Que values ('" + txtMaQue.Text.Trim() + "' , N'" + txtTenQue.Text.Trim() + "')";

            DAO.RunSql(sql);
            LoadDataToGrivew();
            GridViewQue.Enabled = true;
            ResetValues();
            btnXoa.Enabled   = true;
            btnThem.Enabled  = true;
            btnSua.Enabled   = true;
            btnHuy.Enabled   = false;
            btnLuu.Enabled   = false;
            txtMaQue.Enabled = false;
            DAO.CloseConnection();
        }
Exemplo n.º 14
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (tblSinhVien.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaSV.Text == "")
            {
                MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string sql = "select MaSV from Diem where MaSV='" + txtMaSV.Text.Trim() + "'";

            if (DAO.CheckKeyExist(sql) == true)
            {
                MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    sql = " delete from SinhVien where MaSV='" + txtMaSV.Text + "'";
                    //cập nhật sĩ số khi xóa sinh viên
                    String sql1 = " update Lop set SiSo = SiSo -1 WHERE MaLop = '" + cmbMaLop.SelectedValue + "'";
                    DAO.RunSql(sql1);
                    int s2 = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + cmbMaLop.SelectedValue + "'"));
                    MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + cmbMaLop.Text + "' là " + s2, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DAO.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = sql;
                    cmd.Connection  = DAO.con;
                    cmd.ExecuteNonQuery();
                    DAO.CloseConnection();
                    ResetValues();
                    LoadDatatogriview();
                    //LoadDatatogriview();
                    // update sinh viên giảm xuống
                }
            }
        }
Exemplo n.º 15
0
        private void btnDanhSach_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();

            /*string s0 = "INSERT INTO Diem(MaSV) select MaSV from SinhVien";
             * DAO.RunSql(s0);
             * Load_DataGridView();*/
            string s1 = DAO.GetFieldValues("SELECT MaSV FROM SinhVien");

            MessageBox.Show(s1);
            string s2 = "select MaSV from Diem where MaSV='" + s1 + "'";

            MessageBox.Show(s2);
            if (DAO.CheckKeyExist(s2) == false)
            {
                string s3 = "INSERT INTO Diem VALUES('" + s1 + "', null,null, null,null,null)";
                MessageBox.Show(s3);
                DAO.RunSql(s3);
                Load_DataGridView();
            }
        }
Exemplo n.º 16
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            if (txtMaHDT.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã hệ đào tạo", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaHDT.Focus();
                return;
            }
            if (txtTenHDT.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên hệ đào tạo", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenHDT.Focus();
                return;
            }

            sql = "SELECT MaHDT FROM HeDaoTao WHERE MaHDT=N'" + txtMaHDT.Text.Trim() + "'";
            if (DAO.CheckKeyExist(sql))
            {
                MessageBox.Show("Mã hệ đào tạo này đã có, bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaHDT.Focus();
                txtMaHDT.Text = "";
                return;
            }
            sql = "INSERT INTO HeDaoTao(MaHDT,TenHDT) VALUES('" + txtMaHDT.Text.Trim() + "',N'" + txtTenHDT.Text.Trim() + "')";
            DAO.RunSql(sql);
            Load_DataGridView();
            GridViewHeDaoTao.Enabled = true;
            ResetValues();
            btnXoa.Enabled   = true;
            btnThem.Enabled  = true;
            btnSua.Enabled   = true;
            btnHuy.Enabled   = true;
            btnLuu.Enabled   = false;
            txtMaHDT.Enabled = false;
            DAO.CloseConnection();
        }
Exemplo n.º 17
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            string sql;

            if (tblHeDaoTao.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaHDT.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                sql = "DELETE HeDaoTao WHERE MaHDT=N'" + txtMaHDT.Text + "'";
                DAO.RunSql(sql);
                Load_DataGridView();
                ResetValues();
            }
        }
Exemplo n.º 18
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            if (cmbMaLop.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn phải chọn mã lớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cmbHocKy.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn phải chọn học kỳ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cmbMonHoc.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn phải chọn môn học", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtLanThi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập lần thi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtLanThi.Focus();
                return;
            }
            if (GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString().Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập mã sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            /*if (Convert.ToInt32(txtLanThi.Text.Trim()) > 1)
             * {
             *  sql = "UPDATE Diem SET Diem = " + GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim() + " WHERE MaSV=N'" + txtMaSV.Text.Trim() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
             *  //MessageBox.Show(sql);
             *  DAO.RunSql(sql);
             * }*/

            /*string s1 = DAO.GetFieldValues("Select MaSV from Diem where MaSV = '"+ GridViewDiem.Rows[(tblDiem.Rows.Count-1)].Cells["clmMaSV"].Value + "'");
             * string s2 = DAO.GetFieldValues("Select MaSV from Diem where MaSV = '" + GridViewDiem.Rows[tblDiem.Rows.Count].Cells["clmMaSV"].Value + "'");
             * string s3 = DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.Rows[tblDiem.Rows.Count].Cells["clmMaSV"].Value + "'");
             * string s4 = "SELECT MaSV, MaLop, MaMon,HocKy,LanThi FROM Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
             * ////MessageBox.Show(1);
             * //MessageBox.Show(s2);
             * if (Convert.ToInt32(txtLanThi.Text.Trim()) == 1&&s1 !=""&&s2==""&&s3==""&& DAO.CheckKeyExist(s4) == true)
             * {
             *  MessageBox.Show("Bạn phải nhập mã sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *  return;
             * }*/
            /*if(GridViewDiem.Rows[tblDiem.Rows.Count].ToString() == "")
             * {
             *  MessageBox.Show("Bạn phải nhập mã sinh viên.....", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *  return;
             * }*/
            if (Convert.ToInt32(txtLanThi.Text.Trim()) == 1)
            {
                sql = "SELECT MaSV, MaLop, MaMon,HocKy,LanThi FROM Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
                //MessageBox.Show(sql);
                if (DAO.CheckKeyExist(sql) == true)
                {
                    MessageBox.Show("Bạn đã nhập điểm cho sinh viên học lớp và môn này , bạn hãy nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtMaSV.Focus();
                    return;
                }
            }

            sql = "SELECT MaSV FROM SinhVien WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'";
            if (DAO.CheckKeyExist(sql) == false)
            {
                MessageBox.Show("Mã sinh viên không tồn tại , bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            /*if (GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString().Trim()=="")
             * {
             *  MessageBox.Show("Bạn phải nhập mã sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *  return;
             * }*/

            if (GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập điểm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) > 10))
            {
                MessageBox.Show("Bạn nhập sai điểm.Nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiem.Focus();
                return;
            }
            if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) < 5)
            {
                MessageBox.Show("Sinh viên này phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.Text + "','" + cmbMonHoc.SelectedValue + "',"
                      + cmbHocKy.Text + "," + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + ",null)";
                //MessageBox.Show(sql);
                DAO.RunSql(sql);
            }
            string str = DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) - 1) + "'");

            //MessageBox.Show(str);
            if (Convert.ToInt32(txtLanThi.Text.Trim()) > 1 && Convert.ToInt32(str) < 5)
            {
                sql = "UPDATE Diem SET Diem = ROUND(" + GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString() + ",1) WHERE MaSV=N'" + txtMaSV.Text.Trim() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
                //MessageBox.Show(sql);
                DAO.RunSql(sql);
                MessageBox.Show("Bạn đã thêm mới thành công ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Load_DataGridView1();
                txtMaSV.Text = "";
                txtDiem.Text = "";
            }
            else
            //sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.Rows[i].Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.Text + "','" + cmbMonHoc.SelectedValue + "',"
            //+ cmbHocKy.Text + "," + txtLanThi.Text.Trim() + "," + GridViewDiem.Rows[i].Cells["clmDiem"].Value.ToString() + ")";

            {
                sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.Text + "','" + cmbMonHoc.SelectedValue + "',"
                      + cmbHocKy.Text + "," + txtLanThi.Text.Trim() + ",ROUND(" + GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString() + ",1))";
                //MessageBox.Show(sql);
                DAO.RunSql(sql);

                MessageBox.Show("Bạn đã thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                GridViewDiem.CurrentRow.Cells["clmDiem"].Value = Math.Round(Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value), 1);
                Load_DataGridView1();
                txtMaSV.Text = "";
                txtDiem.Text = "";
            }

            //txtDiem.Enabled = false;
            DAO.CloseConnection();
        }
Exemplo n.º 19
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (tblSinhVien.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaSV.Text == "")
            {
                MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (txtTenSV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenSV.Focus();
                return;
            }
            if (cmbMaKhoa.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập khoa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaKhoa.Focus();
                return;
            }
            if (cmbMaLop.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập lớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaLop.Focus();
                return;
            }
            if (cmbMaQue.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập quê", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaQue.Focus();
                return;
            }
            if (cmbMaDanToc.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập dân tôc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaDanToc.Focus();
                return;
            }
            if (cmbMaChucVu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập chức vụ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaChucVu.Focus();
                return;
            }
            if (cmbMaChuyenNganh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập chuyên ngành", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaChuyenNganh.Focus();
                return;
            }
            if (mtbNgaySinh.Text == "  /  /")

            {
                MessageBox.Show("Bạn không để trống ngày sinh");
                mtbNgaySinh.Focus();
                return;
            }
            if (!DAO.IsDate(mtbNgaySinh.Text))
            {
                MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                mtbNgaySinh.Text = "";
                mtbNgaySinh.Focus();
                return;
            }
            if (rdNam.Checked == true)
            {
                GioiTinh = "Nam";
            }
            if (rdNu.Checked == true)
            {
                GioiTinh = "Nữ";
            }

            sql = "UPDATE SinhVien SET  TenSV=N'" + txtTenSV.Text.ToString() +
                  "',MaKhoa='" + cmbMaKhoa.SelectedValue.ToString() + "',MaLop='" + cmbMaLop.SelectedValue.ToString() +
                  "',NgaySinh='" + DAO.ConvertDateTime(mtbNgaySinh.Text) + "',GioiTinh=N'" + GioiTinh
                  + "',MaQue='" + cmbMaQue.SelectedValue.ToString() +
                  "',MaDanToc='" + cmbMaDanToc.SelectedValue.ToString() + "',MaChuyenNganh='" + cmbMaChuyenNganh.SelectedValue.ToString() + "',MaHDT='" + cmbMaHDT.SelectedValue.ToString() + "',MaChucVu='" + cmbMaChucVu.SelectedValue.ToString() +
                  "' WHERE MaSV='" + txtMaSV.Text + "'";
            DAO.OpenConnection();
            DAO.RunSql(sql);
            DAO.CloseConnection();
            LoadDatatogriview();
        }
Exemplo n.º 20
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            for (int i = 0; i < tblDiem.Rows.Count; i++)
            {
                if ((GridViewDiem.Rows[i].Cells["clmDiem"].Value.ToString().Trim() != "") && (Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) > 10))
                {
                    MessageBox.Show("Bạn nhập sai điểm.Nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    GridViewDiem.CurrentCell = GridViewDiem.Rows[i].Cells["clmDiem"];
                    return;
                }
            }

            for (int i = 0; i < tblDiem.Rows.Count; i++)
            {
                string ss = (DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.Rows[i].Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'"));
                if (Convert.ToString(GridViewDiem.Rows[i].Cells["clmDiem"].Value) != ss && ss == "")
                {
                    int t = 0;
                    if (Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) < Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value))
                    {
                        t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value);
                    }
                    else if ((Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value)) == 0.5)
                    {
                        t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value) + 1;
                    }
                    else if ((Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value)) < 0.5)
                    {
                        t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value);
                    }
                    else if (Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) == Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value))
                    {
                        t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value);
                    }
                    sql = "UPDATE Diem SET Diem = " + t + " WHERE MaSV=N'" + GridViewDiem.Rows[i].Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
                    DAO.RunSql(sql);

                    if (t < 5)
                    {
                        sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.Rows[i].Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.SelectedValue + "','" + cmbMonHoc.SelectedValue + "',"
                              + cmbHocKy.Text + "," + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + ",null)";
                        DAO.RunSql(sql);
                    }
                }
            }
            string a1 = (DAO.GetFieldValues("Select count(*) from Diem where MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "' and diem<5"));

            if (Convert.ToInt32(a1) > 0)
            {
                MessageBox.Show("Lớp có " + Convert.ToInt32(a1) + " sinh viên phải thi lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Load_DataGridView();
            btnDanhSach.Enabled = true;
            cmbMaLop.Enabled    = true;
            txtLanThi.Enabled   = true;
            cmbHocKy.Enabled    = true;
            cmbMonHoc.Enabled   = true;
            btnLuu.Enabled      = false;
            btnHuy.Enabled      = false;
            btnSua.Enabled      = false;
            btnDanhSach.Enabled = true;
            btnQuayLai.Enabled  = true;
            txtMaSV.Text        = "";
            txtDiem.Text        = "";
            DAO.CloseConnection();
        }
Exemplo n.º 21
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;

            string s4 = "SELECT MaSV, MaLop, MaMon,HocKy,LanThi FROM Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'";

            if (GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập điểm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) > 10))
            {
                MessageBox.Show("Bạn nhập sai điểm.Nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiem.Focus();
                return;
            }
            string str = DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'");

            if (str != "")
            {
                MessageBox.Show("Bạn không thể sửa vì sinh viên này đã thi lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                int x = 0;
                if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) < Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value))
                {
                    x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value);
                }
                else if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value)) == 0.5)
                {
                    x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) + 1;
                }
                else if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value)) < 0.5)
                {
                    x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value);
                }
                else if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) == Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value))
                {
                    x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value);
                }
                sql = "UPDATE Diem SET Diem = " + x + " WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'";
                DAO.RunSql(sql);
                txtDiem.Text = Convert.ToString(x);
                string str1 = "Select MaSV from Diem where MaSV = '" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'";
                if (x >= 5 && DAO.CheckKeyExist(str1) == true)
                {
                    MessageBox.Show("Sinh viên này không phải thi lại lần sau", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    string s0 = "DELETE Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'";
                    DAO.RunSql(s0);
                }
                else if (x < 5 && DAO.CheckKeyExist(s4) == true)
                {
                    MessageBox.Show("Sinh viên này phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (x < 5 && DAO.CheckKeyExist(s4) == false)
                {
                    MessageBox.Show("Sinh viên này phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.SelectedValue + "','" + cmbMonHoc.SelectedValue + "',"
                          + cmbHocKy.Text + "," + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + ",null)";
                    DAO.RunSql(sql);
                }
                btnDanhSach.Enabled = true;
                cmbMaLop.Enabled    = true;
                txtLanThi.Enabled   = true;
                cmbHocKy.Enabled    = true;
                cmbMonHoc.Enabled   = true;
            }
            DAO.CloseConnection();
            Load_DataGridView();
            btnLuu.Enabled      = false;
            btnHuy.Enabled      = false;
            btnSua.Enabled      = false;
            btnDanhSach.Enabled = true;
            btnQuayLai.Enabled  = true;
        }
Exemplo n.º 22
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            btnXoa.Enabled = false;
            string sql;

            if (txtMaSV.Text == "")
            {
                MessageBox.Show("Bạn không được để trống mã sinh viên");
                txtMaSV.Focus();
                return;
            }
            if (txtTenSV.Text == "")

            {
                MessageBox.Show("Bạn không được để trống tên sinh viên");
                txtTenSV.Focus();
                return;
            }
            if (cmbMaKhoa.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn khoa");
                cmbMaKhoa.Focus();
                return;
            }
            if (cmbMaLop.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn  lớp");
                cmbMaLop.Focus();
                return;
            }
            if (cmbMaQue.SelectedIndex == -1)

            {
                MessageBox.Show("Bạn chưa chọn quê");
                cmbMaQue.Focus();
                return;
            }
            if (cmbMaDanToc.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn  dân tộc");
                cmbMaDanToc.Focus();
                return;
            }
            if (cmbMaHDT.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn hệ đào tạo");
                cmbMaHDT.Focus();
                return;
            }
            if (cmbMaChuyenNganh.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn chuyên ngành");
                cmbMaChuyenNganh.Focus();
                return;
            }
            if (cmbMaChucVu.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn chức vụ");
                cmbMaChucVu.Focus();
                return;
            }

            if (mtbNgaySinh.Text == "  /  /")
            {
                MessageBox.Show("Bạn không để trống ngày sinh");
                mtbNgaySinh.Focus();
                return;
            }
            if (rdNam.Checked == false && rdNu.Checked == false)
            {
                MessageBox.Show("Bạn chưa chọn giới tính", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!DAO.IsDate(mtbNgaySinh.Text))
            {
                MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                mtbNgaySinh.Text = "";
                mtbNgaySinh.Focus();
                return;
            }

            if (rdNam.Checked == true)
            {
                GioiTinh = "Nam";
            }
            if (rdNu.Checked == true)
            {
                GioiTinh = "Nữ";
            }

            string s1 = " select MaSV from SinhVien where MaSV =N'" + txtMaSV.Text.Trim() + "'";

            DAO.OpenConnection();
            if (DAO.CheckKeyExist(s1))
            {
                MessageBox.Show(" Mã sinh viên đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DAO.CloseConnection();
                txtMaSV.Focus();
                return;
            }
            else
            {
                sql = " insert into SinhVien  values('" + txtMaSV.Text.Trim() + "',N'" + txtTenSV.Text.Trim() + "','" + cmbMaKhoa.SelectedValue.ToString() + "','" + cmbMaLop.SelectedValue.ToString() + "','"
                      + DAO.ConvertDateTime(mtbNgaySinh.Text) + "',N'" + GioiTinh + "','" + cmbMaQue.SelectedValue.ToString() + "','" + cmbMaDanToc.SelectedValue.ToString() + "','" + cmbMaChuyenNganh.SelectedValue.ToString()
                      + "','" + cmbMaHDT.SelectedValue.ToString() + "','" + cmbMaChucVu.SelectedValue.ToString() + "')";
                //MessageBox.Show(sql);
                //cập nhật  sĩ số
                string sql1 = " update Lop set SiSo = SiSo +1 WHERE MaLop = '" + cmbMaLop.SelectedValue + "'";
                DAO.RunSql(sql1);
                int sl = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + cmbMaLop.SelectedValue + "'"));
                //MessageBox.Show(" Bạn đã thêm mới thành công, sĩ số sau khi cập nhật của phòng '" + cmbMaLop.Text + "' là " + sl, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);

                SqlCommand cmd = new SqlCommand(sql, DAO.con); // khai báo đổi tượng command
                cmd.CommandText = sql;                         // gán câu truy vấn
                cmd.Connection  = DAO.con;
                cmd.ExecuteNonQuery();
                DAO.CloseConnection();

                LoadDatatogriview();

                DAO.CloseConnection();
                btnLuu.Enabled  = false;
                txtMaSV.Enabled = false;
            }
        }
Exemplo n.º 23
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (tblSinhVien.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaSV.Text == "")
            {
                MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (txtTenSV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenSV.Focus();
                return;
            }
            if (cmbMaKhoa.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập khoa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaKhoa.Focus();
                return;
            }
            if (cmbMaLop.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập lớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaLop.Focus();
                return;
            }
            if (cmbMaQue.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập quê", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaQue.Focus();
                return;
            }
            if (cmbMaDanToc.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập dân tôc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaDanToc.Focus();
                return;
            }
            if (cmbMaChucVu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập chức vụ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaChucVu.Focus();
                return;
            }
            if (cmbMaChuyenNganh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập chuyên ngành", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMaChuyenNganh.Focus();
                return;
            }
            if (mtbNgaySinh.Text == "  /  /")

            {
                MessageBox.Show("Bạn không để trống ngày sinh");
                mtbNgaySinh.Focus();
                return;
            }
            if (!DAO.IsDate(mtbNgaySinh.Text))
            {
                MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                mtbNgaySinh.Text = "";
                mtbNgaySinh.Focus();
                return;
            }
            if (rdNam.Checked == true)
            {
                GioiTinh = "Nam";
            }
            if (rdNu.Checked == true)
            {
                GioiTinh = "Nữ";
            }

            sql = "UPDATE SinhVien SET  TenSV=N'" + txtTenSV.Text.ToString() +
                  "',MaKhoa='" + cmbMaKhoa.SelectedValue.ToString() + "',MaLop='" + cmbMaLop.SelectedValue.ToString() +
                  "',NgaySinh='" + DAO.ConvertDateTime(mtbNgaySinh.Text) + "',GioiTinh=N'" + GioiTinh
                  + "',MaQue='" + cmbMaQue.SelectedValue.ToString() +
                  "',MaDanToc='" + cmbMaDanToc.SelectedValue.ToString() + "',MaChuyenNganh='" + cmbMaChuyenNganh.SelectedValue.ToString() + "',MaHDT='" + cmbMaHDT.SelectedValue.ToString() + "',MaChucVu='" + cmbMaChucVu.SelectedValue.ToString() +
                  "' WHERE MaSV='" + txtMaSV.Text + "'";
            string A = cmbMaLop.SelectedValue.ToString();
            string B = Convert.ToString(DAO.GetFieldValues("select MaLop from SinhVien where MaSV='" + txtMaSV.Text + "'"));

            if (A != B)
            {
                int    s1   = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + A + "'"));
                String sql1 = " update Lop set SiSo = SiSo +1 WHERE MaLop = '" + A + "'";
                DAO.RunSql(sql1);
                s1 = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + A + "'"));
                MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + A + "' là " + s1, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                int    s2   = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + B + "'"));
                String sql2 = " update Lop set SiSo = SiSo -1 WHERE MaLop = '" + B + "'";
                DAO.RunSql(sql2);
                s2 = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + B + "'"));
                MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + B + "' là " + s2, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            DAO.OpenConnection();
            DAO.RunSql(sql);
            LoadDatatogriview1();
            DAO.CloseConnection();
            cmbMaLop.Enabled  = true;
            cmbMaKhoa.Enabled = true;
        }