private void btncheckvoucher_Click(object sender, EventArgs e)
 {
     voucher = blvoucher.GetVoucher(tbxvoucher.Text.Trim());
     if (voucher == null)
     {
         MessageBox.Show("Voucher không chính xác!",
                         "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         tbxvoucher.ResetText();
         return;
     }
     lbgiamgia.Text = voucher.Value.ToString() + "%";
     MessageBox.Show("Voucher trị giá " + voucher.Value + "%", "Thông báo",
                     MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
        public cVoucher GetVoucher(string code)
        {
            string    query = "EXEC GetVoucher @code";
            DataSet   ds    = db.ExecuteQueryDS(query, CommandType.Text, new object[] { code });
            DataTable dt    = new DataTable();

            dt = ds.Tables[0];
            cVoucher vc = null;

            try
            {
                vc = new cVoucher(dt.Rows[0]);
            }
            catch { }
            return(vc);
        }
        private void btnthanhtoan_Click(object sender, EventArgs e)
        {
            int idbill = bill.GetUnCheckBillID(IDTABLE);

            try
            {
                GiamGia = voucher.Value;
            }
            catch { GiamGia = 0; }

            if (idbill != -1)
            {
                frmHoaDon f = new frmHoaDon();
                f.ShowDialog();
                if (XacNhan)
                {
                    XacNhan = false;
                    if (voucher == null)
                    {
                        if (!bill.Pay(idbill, IDTABLE, -1, 0, TotalPrice, ref error))
                        {
                            showErr();
                            return;
                        }
                    }
                    else
                    {
                        if (!bill.Pay(idbill, IDTABLE, voucher.ID, GiamGia, TotalPrice - (TotalPrice * GiamGia / 100), ref error))
                        {
                            showErr();
                            return;
                        }
                    }
                    ShowBill(IDTABLE);
                    LayBanaAn();
                    tbxvoucher.ResetText();
                    lbgiamgia.Text = "0%";
                    GiamGia        = 0;
                    voucher        = null;
                    MessageBox.Show("Thanh toán thành công!", "Sucess!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }