Ejemplo n.º 1
0
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         int row = this.listView1.SelectedItems[0].Index;
         str = this.listView1.Items[row].SubItems[0].Text;
         SqlConnection con = new SqlConnection();
         con.ConnectionString = KetNoi.str;
         con.Open();
         SqlCommand cmd = new SqlCommand();
         cmd.Connection  = con;
         cmd.CommandText = "DELETE FROM LOP WHERE MaLop='" + txtMaLop.Text + "'";
         if (str == txtMaLop.Text)
         {
             DialogResult result;
             result = MessageBox.Show("BẠN CÓ MUỐN XOÁ LỚP NÀY KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (result == DialogResult.Yes)
             {
                 cmd.ExecuteNonQuery();
                 con.Close();
                 MessageBox.Show("XÓA THÀNH CÔNG", "THÔNG BÁO");
                 frmLop frm = new frmLop();
                 this.Close();
                 frm.Show();
             }
             con.Close();
         }
         else
         {
             MessageBox.Show("Mã Lớp Không Khớp. Vui lòng thử lại !", "THÔNG BÁO");
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Hãy chọn lớp muốn xóa", "THÔNG BÁO");
     }
 }
Ejemplo n.º 2
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         int row = this.listView1.SelectedItems[0].Index;
         str = this.listView1.Items[row].SubItems[0].Text;
         SqlConnection con = new SqlConnection();
         con.ConnectionString = KetNoi.str;
         con.Open();
         SqlCommand cmd = new SqlCommand();
         cmd.Connection = con;
         SqlCommand cmd2 = new SqlCommand();
         cmd2.Connection  = con;
         cmd2.CommandText = "select * from LOP where MaLop='" + txtMaLop.Text + "'";
         SqlDataReader rd2;
         rd2 = cmd2.ExecuteReader();
         DataTable td2 = new DataTable();
         td2.Load(rd2);
         if (txtMaLop.Text == str)
         {
             if (txtTenLop.Text != "" && txtDiaDiem.Text != "" && txtSLHS.Text != "")
             {
                 if (cbxTenLT.Text != "" && cbxTenGVCN.Text != "")
                 {
                     if (td2.Rows.Count == 1)
                     {
                         if (IsNumber(txtSLHS.Text))
                         {
                             string maLT, maGVCN;
                             cmd2.CommandText = "select MaHS from HOCSINH where TenHS=N'" + cbxTenLT.Text + "'";
                             rd2 = cmd2.ExecuteReader();
                             DataTable td3 = new DataTable();
                             td3.Load(rd2);
                             maLT             = td3.Rows[0][0].ToString();
                             cmd2.CommandText = "select MaGV from GIAOVIEN where TenGV=N'" + cbxTenGVCN.Text + "'";
                             rd2 = cmd2.ExecuteReader();
                             DataTable td4 = new DataTable();
                             td4.Load(rd2);
                             maGVCN          = td4.Rows[0][0].ToString();
                             cmd.CommandText = "UPDATE LOP SET TenLop=N'" + txtTenLop.Text + "',DiaDiem=N'" + txtDiaDiem.Text + "',SoLuongHS='" + txtSLHS.Text + "',MaLopTruong='" + maLT + "',MaGVCN='" + maGVCN + "' WHERE LOP.MaLop='" + str + "'";
                             DialogResult result;
                             result = MessageBox.Show("BẠN CÓ MUỐN THAY ĐỔI THÔNG TIN KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                             if (result == DialogResult.Yes)
                             {
                                 cmd.ExecuteNonQuery();
                                 MessageBox.Show("CẬP NHẬT THÀNH CÔNG", "THÔNG BÁO");
                                 frmLop frm = new frmLop();
                                 this.Close();
                                 frm.Show();
                             }
                         }
                         else
                         {
                             MessageBox.Show("SĐT nhập không đúng!");
                         }
                     }
                     else
                     {
                         MessageBox.Show("Mã Lớp Không Tồn Tại !", "Thông Báo");
                     }
                 }
                 else
                 {
                     if (td2.Rows.Count == 1)
                     {
                         if (IsNumber(txtSLHS.Text))
                         {
                             cmd.CommandText = "UPDATE LOP SET TenLop=N'" + txtTenLop.Text + "',DiaDiem=N'" + txtDiaDiem.Text + "',SoLuongHS='" + txtSLHS.Text + "' WHERE LOP.MaLop='" + str + "'";
                             DialogResult result;
                             result = MessageBox.Show("BẠN CÓ MUỐN THAY ĐỔI THÔNG TIN KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                             if (result == DialogResult.Yes)
                             {
                                 cmd.ExecuteNonQuery();
                                 MessageBox.Show("CẬP NHẬT THÀNH CÔNG", "THÔNG BÁO");
                                 frmLop frm = new frmLop();
                                 this.Close();
                                 frm.Show();
                             }
                         }
                         else
                         {
                             MessageBox.Show("SĐT nhập không đúng!");
                         }
                     }
                     else
                     {
                         MessageBox.Show("Mã Lớp Không Tồn Tại !", "Thông Báo");
                     }
                 }
             }
             else
             {
                 MessageBox.Show("Bạn phải nhập đủ các trường bắt buộc!", "Thông Báo");
             }
         }
         else
         {
             MessageBox.Show("Mã lớp Không Thể Sửa !", "Thông Báo");
         }
         con.Close();
     }
     catch (Exception)
     {
         MessageBox.Show("Hãy chọn lớp muốn sửa", "THÔNG BÁO");
     }
 }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = KetNoi.str;
            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;
            SqlCommand cmd2 = new SqlCommand();

            cmd2.Connection  = con;
            cmd2.CommandText = "select * from LOP where MaLop='" + txtMaLop.Text + "'";
            SqlDataReader rd2;

            rd2 = cmd2.ExecuteReader();
            DataTable td2 = new DataTable();

            td2.Load(rd2);
            if (txtMaLop.Text != "" && txtTenLop.Text != "" && txtDiaDiem.Text != "" && txtSLHS.Text != "" && cbxTenLT.Text != "" && cbxTenGVCN.Text != "")
            {
                if (td2.Rows.Count == 0)
                {
                    if (txtMaLop.Text.Length == 6)
                    {
                        if (IsNumber(txtSLHS.Text))
                        {
                            string maLT, maGVCN;
                            cmd2.CommandText = "select MaHS from HOCSINH where TenHS=N'" + cbxTenLT.Text + "'";
                            rd2 = cmd2.ExecuteReader();
                            DataTable td3 = new DataTable();
                            td3.Load(rd2);
                            maLT             = td3.Rows[0][0].ToString();
                            cmd2.CommandText = "select MaGV from GIAOVIEN where TenGV=N'" + cbxTenGVCN.Text + "'";
                            rd2 = cmd2.ExecuteReader();
                            DataTable td4 = new DataTable();
                            td4.Load(rd2);
                            maGVCN          = td4.Rows[0][0].ToString();
                            cmd.CommandText = "insert into LOP values ('" + txtMaLop.Text + "',N'" + txtTenLop.Text + "',N'" + txtDiaDiem.Text + "','" + txtSLHS.Text + "','" + maLT + "','" + maGVCN + "')";
                            DialogResult result;
                            result = MessageBox.Show("BẠN CÓ MUỐN THÊM MỚI LỚP NÀY KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (result == DialogResult.Yes)
                            {
                                cmd.ExecuteNonQuery();
                                MessageBox.Show("THÊM MỚI THÀNH CÔNG", "THÔNG BÁO");
                                frmLop frm = new frmLop();
                                this.Close();
                                frm.Show();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Số lượng học sinh nhập không đúng!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Mã Lớp Phải Đủ 6 Kí Tự !", "Thông Báo");
                    }
                }
                else
                {
                    MessageBox.Show("Mã Lớp Bị Trùng !", "Thông Báo");
                }
            }
            else
            {
                MessageBox.Show("Bạn phải nhập đủ các trường bắt buộc!", "Thông Báo");
            }
            con.Close();
        }
Ejemplo n.º 4
0
        private void lỚPToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmLop frm = new frmLop();

            frm.Show();
        }