Beispiel #1
0
        protected void btnXoa_Click(object sender, EventArgs e)
        {
            TheLoaiDAO theloaiDAO = new TheLoaiDAO();
            string     maloai     = txtMaLoai.Text;

            if (txtMaLoai.Text != "" && txtTenLoai.Text != "")
            {
                // Kiểm tra mã loại này đã tồn tại trong CSDL chưa
                bool exist = theloaiDAO.CheckMaLoai(maloai);
                if (exist)
                {
                    // Thực hiện xóa từ CSDL
                    bool result = theloaiDAO.DeleteTheLoai(maloai);
                    if (result)
                    {
                        lblMessage.Text = "Xóa thể loại thành công!";
                        LayDuLieuVaoGridView();
                    }
                    else
                    {
                        lblMessage.Text = "Có lỗi. Vui lòng thử lại sau";
                    }
                }
                else
                {
                    lblMessage.Text = "Thể loại không tồn tại";
                }
            }
            else
            {
                lblMessage.Text = "Vui lòng điền đầy đủ thông tin";
            }
        }
Beispiel #2
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            if (txtMaLoai.Text != "" && txtTenLoai.Text != "")
            {
                // Lấy các giá trị từ giao diện
                TheLoai    theLoai    = LayDuLieuTuForm();
                TheLoaiDAO theloaiDAO = new TheLoaiDAO();
                // Kiểm tra mã loại này đã tồn tại trong CSDL chưa
                bool exist = theloaiDAO.CheckMaLoai(theLoai.MaLoai);
                if (exist)
                {
                    lblMessage.Text = "Thể loại đã tồn tại";
                }
                else
                {
                    // Thực hiện ghi xuống CSDL
                    bool result = theloaiDAO.Insert(theLoai);

                    if (result)
                    {
                        lblMessage.Text = "Thêm thành công!";
                        LayDuLieuVaoGridView();
                    }
                    else
                    {
                        lblMessage.Text = "Có lỗi. Vui lòng thử lại sau";
                    }
                }
            }
            else
            {
                lblMessage.Text = "Vui lòng điền đầy đủ thông tin";
            }
        }
Beispiel #3
0
        private void LayDuLieuVaoGridView()
        {
            TheLoaiDAO theloaiDAO = new TheLoaiDAO();

            GridView1.DataSource = theloaiDAO.GetAllTheLoai();
            GridView1.DataBind();
        }
Beispiel #4
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string     maloai     = GridView1.SelectedRow.Cells[0].Text;
            TheLoaiDAO theloaiDAO = new TheLoaiDAO();
            TheLoai    theLoai    = theloaiDAO.GetTheLoaiByMaLoai(maloai);

            if (theLoai != null)
            {
                // Đổ dữ liệu từ đối tượng TheLoai vào các trường trên Form
                DoDuLieuLenForm(theLoai);
            }
        }
Beispiel #5
0
 protected void btnSua_Click(object sender, EventArgs e)
 {
     if (txtMaLoai.Text != "" && txtTenLoai.Text != "")
     {
         TheLoai    theLoai    = LayDuLieuTuForm();
         TheLoaiDAO theloaiDAO = new TheLoaiDAO();
         bool       result     = theloaiDAO.UpdateTheLoai(theLoai);
         if (result)
         {
             lblMessage.Text = "Cập nhật thành công";
             LayDuLieuVaoGridView();
         }
         else
         {
             lblMessage.Text = "Cập nhật không thành công, vui lòng kiểm tra lại";
         }
     }
     else
     {
         lblMessage.Text = "Vui lòng điền đầy đủ thông tin";
     }
 }