//Add new detail bill
        public bool addDetailBill(model.DetailBill detail_bill)
        {
            String sql = "insert into DETAILBILL values(@id, @idProduct, @amount, @price)";

            DbParameter param1 = df.createParam("@id", detail_bill.id_bill);
            DbParameter param2 = df.createParam("@idProduct", detail_bill.id_product);
            DbParameter param3 = df.createParam("@amount", detail_bill.amount);
            DbParameter param4 = df.createParam("@price", detail_bill.price);

            DbParameter[] parameters = { param1, param2, param3, param4 };

            int rows = detail_helper.insertUpdateDelete(sql, parameters);

            return(rows == 1);
        }
Exemple #2
0
        /*
         * - Duyệt từng phần tử ở trong lv_hoaDon và lấy dữ liệu từng dòng thêm vào chi tiết hóa đơn qua class DetailBillDao và sau khi thêm mỗi dòng
         * thì đồng thời thực hiện việc xóa dòng đó ở lv_hoaDon.
         * - Nếu việc thêm chi tiết hóa đơn không thành công thì sẽ xuất ra MessageBox
         */
        private void addDetailBill()
        {
            foreach (ListViewItem items in lv_hoaDon_banHangControl.Items)
            {
                model.DetailBill detailBill = new model.DetailBill();
                detailBill.id_bill    = max;
                detailBill.id_product = items.Name;
                detailBill.amount     = int.Parse(items.SubItems[4].Text);
                detailBill.price      = int.Parse(items.SubItems[5].Text);

                if (!detail_bill.addDetailBill(detailBill))
                {
                    MessageBox.Show("Thêm chi tiết hóa đơn không thành công");
                }

                updateAmountProduct(items.Name, detailBill.amount);

                lv_hoaDon_banHangControl.Items.Remove(items);
            }
            bt_refresh_banHangControl_Click(null, null);
        }