Esempio n. 1
0
        private void btnTaoPhieuNhapHang_Click(object sender, EventArgs e)
        {
            if (lvwChiTietPhieuNhap.Items.Count == 0)
            {
                MessageBox.Show(Instance.TBChuaThemHHVaoDDH, Instance.Loi, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                double tongTien = 0;
                foreach (ListViewItem item in lvwChiTietPhieuNhap.Items)
                {
                    if (item.SubItems[2].Text == "")
                    {
                        MessageBox.Show(Instance.TBChuaNhapDayDuGia, Instance.CanhBao, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        tongTien += Convert.ToDouble(item.SubItems[1].Text) * Convert.ToDouble(item.SubItems[2].Text);
                    }
                }
                PhieuNhapHangDTO pnhDTO = new PhieuNhapHangDTO();
                pnhDTO.Manvlap  = tkGlobal.Manv;
                pnhDTO.Maddh    = Convert.ToInt32(cboDonDatHang.SelectedValue);
                pnhDTO.Mancc    = Convert.ToInt32(cboNhaCungCap.SelectedValue);
                pnhDTO.Tongtien = tongTien;

                PhieuNhapHangBUS pnhBUS = new PhieuNhapHangBUS();
                int mapnh;
                if (pnhBUS.ThemPNH(pnhDTO, out mapnh))
                {
                    foreach (ListViewItem item in lvwChiTietPhieuNhap.Items)
                    {
                        ChiTietPhieuNhapHangBUS ctBUS = new ChiTietPhieuNhapHangBUS();
                        ChiTietPhieuNhapHangDTO ctDTO = new ChiTietPhieuNhapHangDTO();

                        ctDTO.Mapnh   = mapnh;
                        ctDTO.Mahh    = Convert.ToInt32(item.SubItems[4].Text);
                        ctDTO.Soluong = Convert.ToInt32(item.SubItems[1].Text);
                        ctDTO.Gia     = Convert.ToInt32(item.SubItems[2].Text);
                        ctBUS.ThemChiTietPNH(ctDTO);
                    }
                    MessageBox.Show(Instance.TBTaoPhieuNhapThanhCong, Instance.ThanhCong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadDsPNH();
                }
                else
                {
                    MessageBox.Show(Instance.TBTaoPhieuNhapThatBai, Instance.Loi, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btnTaoPhieuNhapHang_Click(object sender, EventArgs e)
        {
            if (lvwChiTietPhieuNhap.Items.Count == 0)
            {
                MessageBox.Show("Bạn chưa thêm hàng hóa vào đơn đặt hàng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                double tongTien = 0;
                foreach (ListViewItem item in lvwChiTietPhieuNhap.Items)
                {
                    if (item.SubItems[2].Text == "")
                    {
                        MessageBox.Show("Bạn chưa nhập đầy đủ giá, hãy nhập thêm giá!", "Nhập thiếu thông tin", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        tongTien += Convert.ToDouble(item.SubItems[1].Text) * Convert.ToDouble(item.SubItems[2].Text);
                    }
                }
                PhieuNhapHangDTO pnhDTO = new PhieuNhapHangDTO();
                pnhDTO.Manvlap  = tkGlobal.Manv;
                pnhDTO.Maddh    = Convert.ToInt32(cboDonDatHang.SelectedValue);
                pnhDTO.Mancc    = Convert.ToInt32(cboNhaCungCap.SelectedValue);
                pnhDTO.Tongtien = tongTien;

                PhieuNhapHangBUS pnhBUS = new PhieuNhapHangBUS();
                int mapnh;
                if (pnhBUS.ThemPNH(pnhDTO, out mapnh))
                {
                    foreach (ListViewItem item in lvwChiTietPhieuNhap.Items)
                    {
                        ChiTietPhieuNhapHangBUS ctBUS = new ChiTietPhieuNhapHangBUS();
                        ChiTietPhieuNhapHangDTO ctDTO = new ChiTietPhieuNhapHangDTO();

                        ctDTO.Mapnh   = mapnh;
                        ctDTO.Mahh    = Convert.ToInt32(item.SubItems[4].Text);
                        ctDTO.Soluong = Convert.ToInt32(item.SubItems[2].Text);
                        ctDTO.Gia     = Convert.ToInt32(item.SubItems[1].Text);
                        ctBUS.ThemChiTietPNH(ctDTO);
                    }
                    MessageBox.Show("Tạo phiếu nhập thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadDsPNH();
                }
                else
                {
                    MessageBox.Show("Tạo phiếu nhập thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }