示例#1
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaChucVu.Text == "")
            {
                MessageBox.Show("Bạn 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;
            }
            else
            {
                sql = "Update ChucVu set TenChucVu = N'" + txtTenChucVu.Text.Trim() + "' where MaChucVu = '" + txtMaChucVu.Text.Trim() + "'";

                DAO.openconnection();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sql;
                cmd.Connection  = DAO.con;
                cmd.ExecuteNonQuery();//thực thi câu lệnh
                DAO.closeconnection();
                LoadDataToGrivew();
            }
        }
示例#2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaQue.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenQue.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên quê", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenQue.Focus();
                return;
            }

            else
            {
                sql = "Update Que set TenQue = N'" + txtTenQue.Text.ToString() + "' + where MaQue = '" + txtMaQue.Text.ToString() + "'";
                MessageBox.Show("oke");

                DAO.openconnection();
                SqlCommand cmd = new SqlCommand(sql, DAO.con);
                cmd.CommandText = sql;
                cmd.Connection  = DAO.con;
                cmd.ExecuteNonQuery();    //thực thi câu lệnh
                DAO.closeconnection();
                LoadDataToGrivew();
                btnHuy.Enabled   = false;
                btnLuu.Enabled   = true;
                btnThem.Enabled  = true;
                btnXoa.Enabled   = true;
                btnThoat.Enabled = true;
            }
        }
示例#3
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;
     }
     if (MessageBox.Show("bạn có muốn xóa không?", "thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         string sql = " delete from SinhVien where MaSV='" + txtMaSV.Text + "'";
         DAO.openconnection();
         SqlCommand cmd = new SqlCommand();
         cmd.CommandText = sql;
         cmd.Connection  = DAO.con;
         cmd.ExecuteNonQuery();
         DAO.closeconnection();
         ResetValues();
         LoadDatatogriview();
         //LoadDatatogriview();
     }
 }
示例#4
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            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("Bạn 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 chất liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenKhoa.Focus();
                return;
            }
            else
            {
                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() + "'";
                MessageBox.Show("oke");
                DAO.openconnection();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sql;
                cmd.Connection  = DAO.con;
                cmd.ExecuteNonQuery();//thực thi câu lệnh
                DAO.closeconnection();
                LoadDataToGrivew();
            }
        }
示例#5
0
文件: DAO.cs 项目: nthanhtra32/QLDiem
        public static string getfieldvalues(string sql)
        {
            DAO.openconnection();
            string ma = "";

            SqlCommand    cmd = new SqlCommand(sql, DAO.con);
            SqlDataReader reader;

            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                ma = reader.GetValue(0).ToString();
                //ten = reader.GetValue(0).ToString();
            }
            reader.Close();
            return(ma);
        }
示例#6
0
 private void LoadDatatogriview()// LẤY DỮ LIỆU ĐỔ VÀO DATAGRIDVIEW
 {
     try
     {
         DAO.openconnection();
         string sql = " select * from SinhVien";
         tblSinhVien = DAO.GetDataToTable(sql);
         GridViewSinhVien.DataSource = tblSinhVien;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         DAO.closeconnection();
     }
 }
示例#7
0
 public void LoadDataToGrivew()
 {
     try
     {
         DAO.openconnection();
         string         sql     = "select * from Que";
         SqlDataAdapter adapter = new SqlDataAdapter(sql, DAO.con);
         DataTable      tblQue  = new DataTable();
         adapter.Fill(tblQue);
         GridViewQue.DataSource = tblQue;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         DAO.closeconnection();
     }
 }
示例#8
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            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.check_key(sqlCheckKey))
            {
                MessageBox.Show("Mã quê đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DAO.closeconnection();
                txtMaQue.Focus();
                return;
            }
            else
            {
                string     sql = "insert into Que values ('" + txtMaQue.Text.Trim() + "' , N'" + txtTenQue.Text.Trim() + "')";
                SqlCommand cmd = new SqlCommand(sql, DAO.con);
                cmd.ExecuteNonQuery();
                DAO.closeconnection();
                LoadDataToGrivew();
                DAO.closeconnection();
                btnLuu.Enabled   = false;
                txtMaQue.Enabled = false;
            }
        }
示例#9
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaKhoa.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 Khoa WHERE MaKhoa='" + txtMaKhoa.Text.ToString() + "'";
                DAO.openconnection();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sql;
                cmd.Connection  = DAO.con;
                cmd.ExecuteNonQuery();
                DAO.closeconnection();
                ResetValues();
                LoadDataToGrivew();
            }
        }
示例#10
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;
            }
            string sql, GioiTinh;

            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 (checkGioiTinh.Checked == true)
            {
                GioiTinh = "Nam";
            }
            else
            {
                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 + "'";
            MessageBox.Show(sql);
            DAO.openconnection();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = sql;
            cmd.Connection  = DAO.con;
            cmd.ExecuteNonQuery();//thực thi câu lệnh
            DAO.closeconnection();
            LoadDatatogriview();
        }
示例#11
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string GioiTinh, 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  khoa");
                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 (!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 (checkGioiTinh.Checked == true)
            {
                MessageBox.Show("Giới tính sinh viên là nam", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                checkGioiTinh.Focus();
                return;
            }
            if (checkGioiTinh.Checked == true)
            {
                GioiTinh = "Nam";
            }
            else
            {
                GioiTinh = "Nữ";
            }

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

            DAO.openconnection();
            if (DAO.check_key(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);
                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();
                MessageBox.Show(" bạn đã thêm mới thành công", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadDatatogriview();

                DAO.closeconnection();
                btnLuu.Enabled  = false;
                txtMaSV.Enabled = false;
            }
        }
示例#12
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            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() + "'";

            DAO.openconnection();


            if (DAO.check_key(sqlCheckKey))
            {
                MessageBox.Show("Mã khoa đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DAO.closeconnection();
                txtMaKhoa.Focus();
                return;
            }
            else
            {
                string sql = "insert into Khoa values ('" +
                             txtMaKhoa.Text.ToString() + "' , N'" +
                             txtTenKhoa.Text.Trim() + "','" + txtDienThoai.Text.Trim() + "','" + txtDiaChi.Text.Trim() + "','" + txtWebsite.Text.Trim() + "')";
                MessageBox.Show("oke");
                SqlCommand cmd = new SqlCommand(sql, DAO.con);
                cmd.ExecuteNonQuery();
                DAO.closeconnection();
                LoadDataToGrivew();
                DAO.closeconnection();
                btnLuu.Enabled = false;
                //cmbMaKhoa.Enabled = false;
            }
        }