Beispiel #1
0
        private void btn_Click(object sender, EventArgs e)
        {
            string btnName = ((MaterialFlatButton)sender).Name;

            if (btnName == "LichSuHoaDon")
            {
                FrmLichSuHoaDon frmLichSuHoaDon = FrmLichSuHoaDon.Instance;
                frmLichSuHoaDon.MinimizeBox = false;

                FrmMain.Instance.TopMost = false;
                frmLichSuHoaDon.ShowDialog();
                return;
            }

            FrmHienThiBaoCao frm = new FrmHienThiBaoCao();

            if (btnName == "TatCaMon")
            {
                frm.HienTatCaMon();
            }
            else if (btnName == "MonGomNhom")
            {
                frm.HienThiMonTheoNhom();
            }
            else if (btnName == "TatCaHoaDon")
            {
                frm.HienThiTatCacHoaDon();
            }
            else if (btnName == "TatCaPhieuNhap")
            {
                frm.HienTatCaPhieuNhap();
            }
            else if (btnName == "TatCaNguyenLieu")
            {
                frm.HienTatCaNguyenLieu();
            }
            else if (btnName == "HoaDonMoiNhat")
            {
                frm.HienThiHoaDonMoiNhat();
            }
            else if (btnName == "HoaDonTrongNgay")
            {
                frm.HienThiTatHoaDonLapTrongNgay();
            }
            else if (btnName == "PhieuNhapMoiNhat")
            {
                frm.HienThiPhieuNhapMoiNhat();
            }
            else if (btnName == "PhieuNhapTrongNgay")
            {
                frm.TatCaPhieuNhapLapTrongNgay();
            }
            this.TopMost = false;
            frm.Show();
        }
        private void btnNhapHang_Click(object sender, EventArgs e)
        {
            PhieuNhapDTO phieuNhap = new PhieuNhapDTO();

            phieuNhap.NhaCungCap = (int)cmbNhaCungCap.SelectedValue;
            phieuNhap.NgayLap    = DateTime.Now;
            phieuNhap.TongTien   = Convert.ToDouble(lblTongTien.Text.Remove(lblTongTien.Text.Length - 1));
            phieuNhap.TrangThai  = true;

            List <CTPhieuNhapDTO> lsCTPhieuNhap = new List <CTPhieuNhapDTO>();

            foreach (DataGridViewRow row in dgvCTPhieuNhap.Rows)
            {
                string donGia = row.Cells["colDonGia"].Value.ToString();

                CTPhieuNhapDTO ctPhieuNhap = new CTPhieuNhapDTO();
                ctPhieuNhap.MaPhieuNhap  = Convert.ToInt32(lblMaPhieu.Text);
                ctPhieuNhap.MaNguyenLieu = Convert.ToInt32(row.Cells["colMaNguyenLieu"].Value);
                ctPhieuNhap.SoLuong      = Convert.ToDouble(row.Cells["colSoLuong"].Value);
                ctPhieuNhap.DonViTinh    = row.Cells["colDonViTinh"].Value.ToString();
                ctPhieuNhap.DonGia       = Convert.ToDouble(donGia.Remove(donGia.Length - 1));
                if (row.Cells["colGhiChu"].Value != null)
                {
                    ctPhieuNhap.GhiChu = row.Cells["colGhiChu"].Value.ToString();
                }
                else
                {
                    ctPhieuNhap.GhiChu = string.Empty;
                }

                lsCTPhieuNhap.Add(ctPhieuNhap);
            }

            if (PhieuNhapBUS.LuuPhieuNhap(phieuNhap, lsCTPhieuNhap))
            {
                if (DialogResult.Yes == MessageBox.Show("Bạn có muốn in phiếu nhập?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    FrmHienThiBaoCao frm = new FrmHienThiBaoCao();
                    frm.HienThiPhieuNhapMoiNhat();
                    FrmMain.Instance.TopMost = false;
                    frm.Show();
                }
                LamMoi();
                dgvCTPhieuNhap.Rows.Clear();
            }
            else
            {
                MessageBox.Show("Lưu phiếu nhập thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnXuatHoaDon_Click(object sender, EventArgs e)
        {
            HoaDonDTO hoaDon = new HoaDonDTO();

            hoaDon.NhanVienLap = TaiKhoanBUS.LayTaiKhoanDangNhap();
            hoaDon.NgayLap     = DateTime.Now;
            hoaDon.TongTien    = ((FrmBanHang)this.FindForm()).TinhThanhTien();
            hoaDon.TienMat     = Convert.ToDouble(txtTienMat.Text.Remove(txtTienMat.Text.Length - 1));
            hoaDon.TienThua    = Convert.ToDouble(txtTienThua.Text.Remove(txtTienThua.Text.Length - 1));
            hoaDon.TrangThai   = true;

            List <CTHoaDonDTO>         lsCTHD         = new List <CTHoaDonDTO>();
            List <CTHoaDon_ToppingDTO> lsCTHD_Topping = new List <CTHoaDon_ToppingDTO>();
            int idCTHDMark = 0; // Đánh dấu topping thuộc CTHĐ nào

            foreach (DataGridViewRow row in dgvHoaDon.Rows)
            {
                if (row.Tag.GetType() == typeof(MonDTO))
                {
                    CTHoaDonDTO cthd = new CTHoaDonDTO();
                    cthd.MaHoaDon = HoaDonBUS.LayMaHoaDonMoiNhat() + 1;
                    cthd.MaMon    = ((MonDTO)row.Tag).MaMon;
                    cthd.SoLuong  = Convert.ToInt32(row.Cells["colSoLuong"].Value);
                    cthd.DonGia   = Convert.ToDouble(((MonDTO)row.Tag).GiaTien);
                    if (row.Cells["colGhiChu"].Value != null)
                    {
                        cthd.GhiChu = row.Cells["colGhiChu"].Value.ToString();
                    }
                    else
                    {
                        cthd.GhiChu = string.Empty;
                    }
                    lsCTHD.Add(cthd);
                    idCTHDMark++;
                }
                else
                {
                    CTHoaDon_ToppingDTO cthd_topping = new CTHoaDon_ToppingDTO();
                    cthd_topping.MaCTHD    = CTHoaDonBUS.LayMaCTHoaDonMoiNhat() + idCTHDMark;
                    cthd_topping.MaTopping = ((ToppingDTO)row.Tag).MaTopping;
                    cthd_topping.SoLuong   = Convert.ToInt32(row.Cells["colSoLuong"].Value);
                    cthd_topping.DonGia    = Convert.ToDouble(((ToppingDTO)row.Tag).GiaTien);
                    if (row.Cells["colGhiChu"].Value != null)
                    {
                        cthd_topping.GhiChu = row.Cells["colGhiChu"].Value.ToString();
                    }
                    else
                    {
                        cthd_topping.GhiChu = string.Empty;
                    }
                    lsCTHD_Topping.Add(cthd_topping);
                }
            }

            if (HoaDonBUS.LuuHoaDon(hoaDon, lsCTHD, lsCTHD_Topping))
            {
                if (DialogResult.Yes == MessageBox.Show("Bạn có muốn in hoá đơn?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    FrmHienThiBaoCao frm = new FrmHienThiBaoCao();
                    frm.HienThiHoaDonMoiNhat();
                    FrmMain.Instance.TopMost = false;
                    frm.Show();
                }
                ((FrmBanHang)this.FindForm()).QuayLaiManHinhChonMon(true);
            }
            else
            {
                MessageBox.Show("Có lỗi xảy ra khi tạo hoá đơn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnBaoCao_Click(object sender, EventArgs e)
        {
            FrmMain.Instance.TopMost = false;
            FrmHienThiBaoCao frm = new FrmHienThiBaoCao();

            if (radTatCaMon.Checked)
            {
                frm.HienTatCaMon();
            }
            else if (radTheoLoaiMon.Checked)
            {
                frm.HienMonTheoLoai((int)cmbLoaiMon.SelectedValue);
            }
            else if (radGomNhomMon.Checked)
            {
                frm.HienThiMonTheoNhom();
            }
            else if (radTatCaHoaDon.Checked)
            {
                frm.HienThiTatCacHoaDon();
            }
            else if (radHoaDonLapTrongNgay.Checked)
            {
                frm.HienThiTatHoaDonLapTrongNgay();
            }
            else if (radHoaDonChonNgay.Checked)
            {
                frm.HienThiHoaDonTheoNgay((DateTime)dtpHoaDonChonNgay.Value);
            }
            else if (radHoaDonTheoThang.Checked)
            {
                frm.HienThiTatCacHoaDonTheoThang((DateTime)dtpTimeStart.Value, (DateTime)dtpTimeEnd.Value);
            }
            else if (radTatCaNguyenLieu.Checked)
            {
                frm.HienTatCaNguyenLieu();
            }
            else if (radTatCaPhieuNhap.Checked)
            {
                frm.HienTatCaPhieuNhap();
            }
            else if (radPhieuNhapTrongNgay.Checked)
            {
                frm.TatCaPhieuNhapLapTrongNgay();
            }
            else if (radPhieuNhapTheoThang.Checked)
            {
                frm.HienThiTatCacPhieuNhapTheoMoc((DateTime)dtpPhieuNhapStart.Value, (DateTime)dtpPhieuNhapEnd.Value);
            }
            else if (radPhieuNhapChonNgay.Checked)
            {
                frm.HienThiPhieuNhapTheoNgay((DateTime)dtpPhieuNhapChonNgay.Value);
            }
            else if (radHoaDonMoiNhat.Checked)
            {
                frm.HienThiHoaDonMoiNhat();
            }
            else if (radPhieuNhapNew.Checked)
            {
                frm.HienThiPhieuNhapMoiNhat();
            }
            else if (radDoanhThuTheoNgay.Checked)
            {
                frm.DoanhThuTheoNgay((DateTime)dtpDoanhThuTheoNgay.Value);
            }
            else if (radDoanhThuTheoMoc.Checked)
            {
                frm.DoanhThuTheoMoc((DateTime)dtpDoanhThuStart.Value, (DateTime)dtpDoanhThuEnd.Value);
            }
            frm.Show();
        }