示例#1
0
 private void btXoa_Click(object sender, EventArgs e)
 {
     try
     {
         LinkLabel tam    = new LinkLabel();
         string    delete = "delete from Lop where Malop=N'" + txtMaLop.Text + "'";
         if (txtMaLop.Text.Trim() == "")
         {
             MessageBox.Show("Bạn chưa chọn lớp để xóa!", "Thông báo!");
         }
         else
         {
             cls.loadlinklabel(tam, "select Malop from Lop where Malop=N'" + txtMaLop.Text + "'");
             if (tam.Text == "")
             {
                 MessageBox.Show("Lớp này chưa tồn tại!", "Chú ý!");
             }
             else
             if (MessageBox.Show("Bạn chắc chắn muốn xóa Lớp này??", "Xóa dữ liệu", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
             {
                 cls.thucthiketnoi(delete);
                 DgvLop.Refresh();
                 cls.loaddatagridview(DgvLop, "select * from Lop");
                 MessageBox.Show("Lớp bạn chọn đã được xóa!");
             }
         }
     }
     catch
     {
     }
 }
示例#2
0
 private void bttMoi_Click(object sender, EventArgs e)
 {
     kiemtra = !kiemtra;
     if (kiemtra)
     {
         //cls.Data2DataGridView(DgvLop, "select * from Lop");
         string sql = "select Malop from Lop";
         // Lấy DataTable từ câu truy vấn truyền vào (Apdapter Fill DataTable)
         DataTable tb      = cls.getDataTable(sql);
         double[]  arrCode = new double[tb.Rows.Count];
         int       code;
         for (int i = 0; i < tb.Rows.Count; i++)
         {
             code       = int.Parse(tb.Rows[i]["Malop"].ToString().Remove(0, 1));
             arrCode[i] = code;
         }
         code = int.Parse((arrCode.Max() + 1).ToString());
         string nextID = "L" + code.ToString();
         txtMaLop.Text   = nextID;
         txtTenLop.Text  = "";
         bttMoi.Text     = "Lưu";
         btSua.Enabled   = false;
         btXoa.Enabled   = false;
         cbGiaoVien.Text = "";
         cbNienKhoa.Text = "";
         txtTenLop.Focus();
     }
     else
     {
         try
         {
             string insert = "insert into Lop values(N'" + txtMaLop.Text + "','" + txtTenLop.Text + "',N'" + cbNienKhoa.Text + "','" + cbGiaoVien.Text + "')";
             if (txtTenLop.Text.Trim() == "" || cbGiaoVien.Text.Trim() == "" || cbNienKhoa.Text.Trim() == "")
             {
                 MessageBox.Show("bạn chưa nhập đầy đủ thông tin.", "Thông báo");
                 return;
             }
             else
             {
                 cls.thucthiketnoi(insert);
                 DgvLop.Refresh();
                 cls.loaddatagridview(DgvLop, "select * from Lop");
                 MessageBox.Show("Lớp mới đã được thêm!", "Thông báo!");
             }
         }
         catch
         {
             MessageBox.Show("Dữ liệu đầu vào không đúng!", "Thông báo");
         }
         bttMoi.Text   = "Thêm";
         btSua.Enabled = true;
         btXoa.Enabled = true;
     }
 }
示例#3
0
 private void btSua_Click(object sender, EventArgs e)
 {
     try
     {
         string update = "update Lop set Tenlop=N'" + txtTenLop.Text + "',Nienkhoa='" + cbNienKhoa.Text + "',MaGV='" + cbGiaoVien.Text + "' where(Malop=N'" + txtMaLop.Text + "')";
         if (txtTenLop.Text.Trim() == "" || cbGiaoVien.Text.Trim() == "" || cbNienKhoa.Text.Trim() == "")
         {
             MessageBox.Show("bạn chưa nhập đầy đủ thông tin.", "Thông báo");
             return;
         }
         else
         {
             cls.thucthiketnoi(update);
             DgvLop.Refresh();
             cls.loaddatagridview(DgvLop, "select * from Lop");
             MessageBox.Show("Sửa thông tin lớp thành công!", "Thông báo!");
         }
     }
     catch (SqlException ex)
     {
         MessageBox.Show(ex.Message);
     }
 }