Example #1
0
        void AddProduct()
        {
            TableFood table = lsvBill.Tag as TableFood;

            if (table == null)
            {
                MessageBox.Show("Xin chọn bàn!!");
                return;
            }
            int idBill    = _serviceBill.GetUncheckBillByIdTable_S(table.id);
            int idProduct = (cmbProduct.SelectedItem as Product).id;
            int count     = (int)nmdCount.Value;

            if (count > _serviceProduct.GetProductById_S(idProduct).inventory)
            {
                MessageBox.Show("Số lượng sản phẩm hiện tại không đủ. Xin nhập thêm !");
                return;
            }
            if (count == 0)
            {
                return;
            }
            if (idBill == -1) // Bill not exist
            {
                if (_serviceBill.AddBill_S(new Bill()
                {
                    idTable = table.id, dateCheckIn = DateTime.Now, discount = 0, status = 0, totalPrice = 0
                }))
                {
                    if (_serviceBillInfo.AddBillInfo_S(new BillInfo()
                    {
                        idBill = _serviceBill.GetMaxIdBill_S().GetValueOrDefault(), idProduct = idProduct, count = count
                    }))
                    {
                        //Cập nhật status
                        _serviceTable.UpdateStatus_S(new TableFood()
                        {
                            id = table.id, status = "Có khách"
                        });
                    }
                }
            }
            else // Bill đã tồn tại
            {
                if (_serviceBillInfo.AddBillInfo_S(new BillInfo()
                {
                    idBill = idBill, idProduct = idProduct, count = count
                }))
                {
                    //Do something if you want
                }
            }
            ShowBill(table.id);
            LoadTable();
            nmdCount.Value = 1;
        }
 void CheckOut()
 {
     if (listIdBill.Count <= 0)
     {
         return;
     }
     if (MessageBox.Show("Bạn có chắc chắn muốn thanh toán các bàn đã chọn không?", "Thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         string note            = txtNote.Text;
         int    discount        = Convert.ToInt32(cmbDiscount.SelectedItem);
         double totalPrice      = double.Parse(txtTotalPrice.Text.Split(',')[0]);
         double costsIncurred   = double.Parse(txtCostsIncurred.Text);
         double finalTotalPrice = (totalPrice * (100 - discount) / 100) + costsIncurred;
         int    idBillChangeTo;
         if (listIdBill.Count > 1)
         {
             idBillChangeTo = listIdBill[0];
             foreach (int item in listIdBill)
             {
                 ChangeIdBill(item, idBillChangeTo);
                 DeleteBillNull(item);
             }
         }
         Bill b = _serviceBill.GetBillById_S(listIdBill[0]);
         if (_serviceBill.CheckOut_S(new Bill()
         {
             id = b.id, discount = discount, dateCheckIn = DateTime.Now, idTable = b.idTable, totalPrice = finalTotalPrice, status = 1, Note = note
         }))
         {
             MessageBox.Show(String.Format("Thanh toán thành công!\nTạm tính : {0}\nGiảm giá : {1}\nChi phí phát sinh: {2}\nGhi chú : {3}\nTổng tiền phải trả : {4}"
                                           , totalPrice, totalPrice + costsIncurred - finalTotalPrice, costsIncurred, note, finalTotalPrice));
             _serviceTableFood.UpdateStatus_S(new TableFood()
             {
                 id = b.idTable, status = "Trống"
             });
         }
     }
 }
Example #3
0
        void ChangeProductTable()
        {
            int idBillBeSwitch  = _serviceBill.GetUncheckBillByIdTable_S(_idTable);
            int idTableSwitchTo = (cmbListTable.SelectedItem as TableFood).id;

            if (idTableSwitchTo == _idTable)
            {
                MessageBox.Show("Đây là bàn hiện tại đang thao tác. Xin chọn lại bàn khác!");
                return;
            }
            int  idBillSwitchTo = _serviceBill.GetUncheckBillByIdTable_S(idTableSwitchTo);
            bool check          = false;

            if (idBillSwitchTo == -1)
            {
                if (MessageBox.Show(String.Format("Bạn có chắc chắn muốn tách những sản phẩm đã chọn của Bàn {0} sang {1} không?"
                                                  , _idTable, (cmbListTable.SelectedItem as TableFood).name), "Thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    if (_serviceBill.AddBill_S(new Bill()
                    {
                        idTable = idTableSwitchTo, dateCheckIn = DateTime.Now, discount = 0, status = 0, totalPrice = 0
                    }))
                    {//Tạo bill mới cho bàn đc chuyển tới
                        int idBillCurrent = _serviceBill.GetMaxIdBill_S().GetValueOrDefault();
                        foreach (BillInfo item in _listProductChoosed)
                        {     //Chuyển billinfo(checked) of bàn được chọn(đang thao tác) => bàn mới
                            if (CheckProCountChoosed(item))
                            { // Kiểm tra nếu số lượng được chọn bằng số lượng của billInfo ban đầu
                                if (_serviceBillInfo.UpdateBillInfo_S(new BillInfo()
                                {
                                    id = item.id, idBill = idBillCurrent, idProduct = item.idProduct, count = item.count
                                }))
                                { // idBill ở đây là của bill mới tạo nên lấy giá trị max của bill
                                    check = true;
                                }
                            }
                            else
                            {//Số lượng được chọn ít hơn số lượng ban đầu
                                if (_serviceBillInfo.AddBillInfo_S(new BillInfo()
                                {
                                    idBill = idBillCurrent, idProduct = item.idProduct, count = item.count
                                }))
                                { // idBill ở đây là của bill mới tạo nên lấy giá trị max của bill
                                    check = true;
                                }
                                UpdateProCount(item);
                            }
                        }
                    }
                }
            }
            else
            { //Trường hợp này là 2 bàn cùng có bill nên k cần tạo bill mới cho bàn chuyển tới
                if (MessageBox.Show(String.Format("Bạn có chắc chắn muốn tách những sản phẩm đã chọn Bàn {0} sang {1} không?"
                                                  , _idTable, (cmbListTable.SelectedItem as TableFood).name), "Thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    foreach (BillInfo item in _listProductChoosed)
                    {//Chuyển billinfo(checked) of bàn được chọn(đang thao tác) => bàn đc chuyển tới
                        if (CheckProCountChoosed(item))
                        {
                            if (_serviceBillInfo.UpdateBillInfo_S(new BillInfo()
                            {
                                id = item.id, idBill = idBillSwitchTo, idProduct = item.idProduct, count = item.count
                            }))
                            {
                                check = true;
                            }
                        }
                        else
                        {
                            if (_serviceBillInfo.AddBillInfo_S(new BillInfo()
                            {
                                idBill = idBillSwitchTo, idProduct = item.idProduct, count = item.count
                            }))
                            {
                                check = true;
                            }
                            UpdateProCount(item);
                        }
                    }
                }
            }
            if (CheckBillNull(idBillBeSwitch))
            {
                _serviceBill.DeleteBillById_S(idBillBeSwitch);
                //MessageBox.Show("Xóa bill null");
            }
            if (check)
            {
                int idBill = _serviceBill.GetUncheckBillByIdTable_S(_idTable);
                if (CheckBillNull(idBill))
                {
                    _serviceTableFood.UpdateStatus_S(new TableFood()
                    {
                        id = _idTable, status = "Trống"
                    });
                }
                if (idBillSwitchTo == -1)
                {
                    MessageBox.Show("Tách bàn thành công!");
                    _serviceTableFood.UpdateStatus_S(new TableFood()
                    {
                        id = idTableSwitchTo, status = "Có Khách"
                    });
                }
                else
                {
                    MessageBox.Show("Gọp bàn thành công!");
                }
            }
            //ShowBill(idTableSwitchTo);
            //LoadTable();
            //LoadListProductOfTableChoosed();
        }