Beispiel #1
0
        void load()
        {
            DateTime fromday = dtpfromday.Value;
            DateTime today   = dtptoday.Value;

            QuanLyQuanCafeDBContext db = new QuanLyQuanCafeDBContext();

            var ListCTB =
                (
                    from hd in db.HOADONBANs.Where(p => p.NGAY > fromday && p.NGAY < today).ToList()
                    from ctb in db.CHITIETBANs.Where(p => p.MAHDB == hd.MAHDB).ToList()
                    select new
            {
                MaMH = ctb.MAMH,
                SoLuong = ctb.SOLUONG
            }
                ).ToList();

            int i           = 0;
            var ListMatHang = (
                from mh in db.MATHANGs.ToList()
                select new
            {
                ID = mh.MAMH,
                TenMatHang = mh.TENMH,
                SoLuong = ListCTB.Where(p => p.MaMH == mh.MAMH).Sum(p => p.SoLuong),
                TongTien = ListCTB.Where(p => p.MaMH == mh.MAMH).Sum(p => p.SoLuong) * mh.DONGIA
            }
                )
                              .Where(p => p.SoLuong > 0)
                              .OrderByDescending(p => p.TongTien)
                              .Select(p => new
            {
                STT      = ++i,
                ID       = p.ID,
                MatHang  = p.TenMatHang,
                SoLuong  = p.SoLuong,
                TongTien = ((int)p.TongTien).ToString("N0"),
                gt       = p.TongTien
            })
                              .ToList();

            txtLoiNhuan.Text = "Tổng lợi nhuận : " + ((int)ListMatHang.Sum(p => p.gt).Value).ToString("N0");

            dgrThongKe.DataSource = ListMatHang;



            chartThongKe.DataSource              = ListMatHang;
            chartThongKe.Series[0].XValueMember  = "MatHang";
            chartThongKe.Series[0].XValueType    = ChartValueType.String;
            chartThongKe.Series[0].YValueMembers = "TongTien";
            chartThongKe.Series[0].YValueType    = ChartValueType.Int32;
        }
        private void btnTraMon_Click(object sender, EventArgs e)
        {
            int idtable = (int)dgvChiTietNhapMain.Tag;
            int mahdb   = (int)HoaDonBanDAO.LayHoaDonTheoBan(idtable);
            int mamh    = (int)cboDanhSachMatHang.SelectedValue;
            int soluong = (int)SpinEditSoLuong.Value;

            try
            {
                mamh = (int)dgvChiTietNhap.GetFocusedRowCellValue("MAMH");
            }
            catch
            {
                MessageBox.Show("Hóa đơn đang trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (mahdb == -1)
            {
                MessageBox.Show("Không có món, không thể trả món", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                ChiTietBan.TraMon(mahdb, mamh, soluong);
            }

            QuanLyQuanCafeDBContext db = new QuanLyQuanCafeDBContext();
            int cnt = (
                from hd in db.HOADONBANs.Where(p => p.MABA == idtable && p.STATUS == 0).ToList()
                from ctb in db.CHITIETBANs.Where(p => p.MAHDB == hd.MAHDB).ToList()
                from mh in db.MATHANGs.Where(p => p.MAMH == ctb.MAMH).ToList()
                select new
            {
                MatHang = mh.TENMH,
                SoLuong = ctb.SOLUONG,
                DonGia = mh.DONGIA,
                ThanhTien = ctb.THANHTIEN
            })
                      .ToList()
                      .Count;

            if (cnt == 0)
            {
                db.BANANs.Where(p => p.MABA == idtable).FirstOrDefault().TRANGTHAI = 0;
                db.SaveChanges();
                LoadDanhSachBanAn();
            }

            HienThiHoaDon(idtable);
            TongTien(mahdb);
        }