Exemplo n.º 1
0
        private async void btnKhachHang_Click(object sender, EventArgs e)
        {
            frmKhachHang f      = new frmKhachHang(hd);
            DialogResult result = f.ShowDialog();

            switch (result)
            {
            case DialogResult.OK:
                Program.dtKhachHang  = await new KhachHangBAL().LayDT();
                Program.lstKhachHang = await new KhachHangBAL().LayLst(Program.dtKhachHang);
                hd = new HoaDon((await balHD.LayDT(hd.ID)).Rows[0]);
                kh = Program.lstKhachHang.FirstOrDefault(p => p.ID == hd.IDKhachHang);
                lblKhachHang.Text += "\n" + kh.TenKH;
                break;

            case DialogResult.Yes:
                hd = new HoaDon((await balHD.LayDT(hd.ID)).Rows[0]);
                kh = Program.lstKhachHang.FirstOrDefault(p => p.ID == hd.IDKhachHang);
                lblKhachHang.Text += "\n" + kh.TenKH;
                break;

            default:
                lblKhachHang.Text = "Tên Khách Hàng: ";
                break;
            }
        }
Exemplo n.º 2
0
        private async void frmChon_Load(object sender, EventArgs e)
        {
            dtpNgayBD.Value      = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            dtpNgayKetThuc.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
            bsHoanThanh.SuspendBinding();

            bsHoanThanh.DataSource = await balHD.LayDT(dtpNgayBD.Value, dtpNgayKetThuc.Value, Convert.ToByte(0));

            bsHoanThanh.ResumeBinding();
        }
Exemplo n.º 3
0
        private async void btnViewReport_Click(object sender, EventArgs e)
        {
            int ValTong = 0;
            int ValChi  = 0;

            lstDoanhThu.Clear();
            lvDanhSach.Items.Clear();

            if (radNam.Checked)
            {
                TuNgay  = new DateTime(Convert.ToInt32(cbxNam.Text), 1, 1, 0, 0, 0);
                DenNgay = new DateTime(Convert.ToInt32(cbxNam.Text), 12, 31, 23, 59, 59);
            }
            if (radThang.Checked)
            {
                TuNgay  = new DateTime(Convert.ToInt32(cbxNam.Text), int.Parse(cbxThang.Text), 1, 0, 0, 0);
                DenNgay = new DateTime(Convert.ToInt32(cbxNam.Text), int.Parse(cbxThang.Text), TinhNgay(int.Parse(cbxThang.Text), int.Parse(cbxNam.Text)), 23, 59, 59);
            }
            if (radTuan.Checked)
            {
                DateTime d = DateTime.Now;
                d = new DateTime(dtpNgayBD.Value.Year, dtpNgayBD.Value.Month, dtpNgayBD.Value.Day, 0, 0, 0);

                TuNgay  = d.AddDays(-(Convert.ToInt32(d.DayOfWeek) == 0 ? 6 : Convert.ToInt32(d.DayOfWeek) - 1));
                d       = TuNgay.AddDays(6);
                DenNgay = new DateTime(d.Year, d.Month, d.Day, 23, 59, 59);//TuNgay.AddDays(6);
            }
            if (radThoiGian.Checked)
            {
                TuNgay  = new DateTime(dtpNgayBD.Value.Year, dtpNgayBD.Value.Month, dtpNgayBD.Value.Day, 0, 0, 0);
                DenNgay = new DateTime(dtpNgayKetThuc.Value.Year, dtpNgayKetThuc.Value.Month, dtpNgayKetThuc.Value.Day, 23, 59, 59);
            }
            try
            {
                foreach (DataRow dr in (await balHoaDon.LayDT(TuNgay, DenNgay)).Rows)
                {
                    lstDoanhThu.Add(new DoanhThu()
                    {
                        ID      = Convert.ToInt32(dr["ID"]),
                        NVien   = Convert.IsDBNull(dr["IDNhanVien"]) ? "Không có NV" : Program.lstNhanVien.FirstOrDefault(p => p.ID == Convert.ToInt32(dr["IDNhanVien"])).Ten,
                        KHang   = Convert.IsDBNull(dr["IDKhacHang"]) ? "Khách Vãn lai" : Program.lstKhachHang.FirstOrDefault(p => p.ID == Convert.ToInt32(dr["IDKhacHang"])).TenKH,
                        Ngay    = Convert.ToDateTime(dr["Ngay"]),
                        TongChi = await TongChi(Convert.ToInt32(dr["ID"])),
                        Tong    = await Tong(Convert.ToInt32(dr["ID"]))
                    });
                }

                var lstGroups = lstDoanhThu.GroupBy(p => p.Ngay.Date);

                foreach (var gr in lstGroups)
                {
                    ListViewGroup lvg = new ListViewGroup("lgv_" + gr.Key.Date.ToString("ddMMyyyy"), "Ngày: " + gr.Key.Date.ToString("dd/MMyyyy"))
                    {
                        HeaderAlignment = HorizontalAlignment.Center
                    };

                    foreach (var item in gr)
                    {
                        lvg.Items.Add(new ListViewItem(new string[] { item.ID.ToString(), item.NVien, item.KHang, Program.FormatNumber(item.TongChi.ToString()), Program.FormatNumber(item.Tong.ToString()) }));
                        ValTong += item.Tong;
                        ValChi  += item.TongChi;
                    }
                    lvDanhSach.Items.AddRange(lvg.Items);
                    lvDanhSach.Groups.Add(lvg);

                    lblTong.Text     = Program.FormatNumber(ValTong.ToString());
                    lblLoiNhuan.Text = Program.FormatNumber(ValChi.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }