Ejemplo n.º 1
0
        private void themMonTile_Click(object sender, EventArgs e)
        {
            using (frmChonMon form = new frmChonMon(selectedIndex + 1))
            {
                if (form.ShowDialog() == DialogResult.OK)
                {
                    selected[selectedIndex] = form.Selected;
                    int tongTien = 0;

                    foreach (DataRow row in selected[selectedIndex].Rows)
                    {
                        string tenMon    = row["Tên món"].ToString();
                        int    donGia    = (int)row["Đơn giá"];
                        int    soLuong   = (int)row["Số lượng"];
                        int    thanhTien = donGia * soLuong;
                        tongTien += thanhTien;

                        ChiTietHoaDon detail        = new ChiTietHoaDon(currentBill.MaHoaDon, tenMon, soLuong, thanhTien);
                        ChiTietHoaDon existedDetail = BillDetailBUS.GetBillDetail(detail);

                        if (existedDetail != null)
                        {
                            detail.SoLuong   += existedDetail.SoLuong;
                            detail.ThanhTien += existedDetail.ThanhTien;
                            BillDetailBUS.Update(detail);
                        }
                        else
                        {
                            BillDetailBUS.Insert(detail);
                        }
                    }

                    currentBill.TongTien += tongTien + tongTien / 10;
                    BillBUS.UpdateTotalPrice(currentBill);
                    metroTileList[selectedIndex].PerformClick();
                }
            }
        }
Ejemplo n.º 2
0
        private void Tile_Click(object sender, EventArgs e)
        {
            int index = metroTileList.IndexOf((MetroTile)sender);

            if (tableList[index].TinhTrang == "Còn trống")
            {
                using (frmChonMon form = new frmChonMon(index + 1))
                {
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        selected[index]            = form.Selected;
                        metroTileList[index].Style = MetroColorStyle.Red;
                        tableList[index].TinhTrang = "Đã được đặt";
                        TableBUS.UpdateStatus(tableList[index]);
                        int tongTien = 0;

                        currentBill = new HoaDon
                        {
                            MaBan      = tableList[index].MaBan,
                            MaNhanVien = login.MaNhanVien,
                        };

                        BillBUS.Insert(currentBill);
                        currentBill = BillBUS.GetLastBill(tableList[index].MaBan);

                        foreach (DataRow row in selected[index].Rows)
                        {
                            string tenMon    = row["Tên món"].ToString();
                            int    donGia    = (int)row["Đơn giá"];
                            int    soLuong   = (int)row["Số lượng"];
                            int    thanhTien = donGia * soLuong;
                            tongTien += thanhTien;

                            ChiTietHoaDon detail        = new ChiTietHoaDon(currentBill.MaHoaDon, tenMon, soLuong, thanhTien);
                            ChiTietHoaDon existedDetail = BillDetailBUS.GetBillDetail(detail);

                            if (existedDetail != null)
                            {
                                detail.SoLuong   += existedDetail.SoLuong;
                                detail.ThanhTien += existedDetail.ThanhTien;
                                BillDetailBUS.Update(detail);
                            }
                            else
                            {
                                BillDetailBUS.Insert(detail);
                            }
                        }

                        currentBill.TongTien = tongTien + tongTien / 10;
                        BillBUS.UpdateTotalPrice(currentBill);
                    }
                }
            }
            else
            {
                currentBill           = BillBUS.GetLastBill(tableList[index].MaBan);
                dgv.DataSource        = BillDetailBUS.LoadAll(currentBill.MaHoaDon);
                selectedIndex         = index;
                thanhToanTile.Visible = true;
                themMonTile.Visible   = true;
                tongTienLabel.Visible = true;
                tongTienLabel.Text    = currentBill.TongTien.ToString("N0");
                label.Visible         = true;
            }
        }