Ejemplo n.º 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (key == 1)
            {
                if (txtmatl.Text != "" && txttentl.Text != "")
                {
                    TheLoai tl = new TheLoai(txtmatl.Text.ToString().Trim(), txttentl.Text.ToString().Trim());
                    if (bal_theloai.Them(tl) == true)
                    {
                        ClearText();
                        ShowData();
                        MessageBox.Show("Thêm thành công");
                        TheLoai_Load(sender, e);
                        key = 0;
                    }
                    else
                    {
                        Exception ex = bal_theloai.GetEx();
                        MessageBox.Show(ex.Message);
                        MessageBox.Show("Mã thể loại đã tồn tại");
                    }
                }
                else
                {
                    MessageBox.Show("Bạn cần nhập đủ thông tin ");
                }
            }

            if (key == 2)
            {
                if (txtmatl.Text != "" && txttentl.Text != "")
                {
                    TheLoai tl = new TheLoai(txtmatl.Text.ToString().Trim(), txttentl.Text.ToString().Trim());
                    if (bal_theloai.Sua(tl) == true)
                    {
                        ClearText();
                        ShowData();
                        MessageBox.Show("Sửa thành công");
                        TheLoai_Load(sender, e);
                        key = 0;
                    }
                    else
                    {
                        Exception ex = bal_theloai.GetEx();
                        MessageBox.Show(ex.Message);
                        MessageBox.Show("Có lỗi xảy ra");
                    }
                }
                else
                {
                    MessageBox.Show("Chọn dòng bạn muốn sửa và hãy nhập đầy đủ thông tin");
                }
            }
            if (key == 3)
            {
                if (txtmatl.Text.Length != 0)
                {
                    string query = @"DELETE FROM THELOAI Where matheloai='" + txtmatl.Text + "'";

                    if (bal_theloai.Xoa(txtmatl.Text.Trim()))
                    {
                        ClearText();
                        ShowData();
                        MessageBox.Show("Xóa thành công");
                        TheLoai_Load(sender, e);
                        key = 0;
                    }
                    else
                    {
                        Exception ex = bal_theloai.GetEx();
                        MessageBox.Show(ex.Message);
                        MessageBox.Show("Lỗi");
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng chọn");
                }
            }
        }