Exemplo n.º 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";
            }
        }
Exemplo n.º 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";
            }
        }