private void btnLuu_Click(object sender, EventArgs e)
        {
            PhieuNhapDTO phieuNhap = new PhieuNhapDTO();

            phieuNhap.MaPN         = txtPhieu.Text;
            phieuNhap.NCC          = txtMaNCC.Text;
            phieuNhap.KhoXuat      = int.Parse(cbKhoXuat.SelectedValue.ToString());
            phieuNhap.Ngay         = txtNgay.Text;
            phieuNhap.NgayGiao     = txtNgayGiao.Text;
            phieuNhap.HanThanhToan = txtHanThanhToan.Text;
            phieuNhap.GhiChu       = txtGhiChu.Text;
            phieuNhap.TongTien     = tongTien;

            PhieuNhapBUS phieuNhapBUS = new PhieuNhapBUS();

            phieuNhapBUS.LuuPhieuNhap(phieuNhap);

            int i = 0;

            foreach (DataGridViewRow row in dgvNhapHang.Rows)
            {
                CT_PhieuNhap cT_PhieuNhap = new CT_PhieuNhap();
                cT_PhieuNhap.MaPN      = txtPhieu.Text;
                cT_PhieuNhap.STT       = i;
                cT_PhieuNhap.TenHang   = row.Cells["TenHang"].Value.ToString();
                cT_PhieuNhap.DonVi     = 1;
                cT_PhieuNhap.DonGia    = float.Parse(row.Cells["DonGia"].Value.ToString());
                cT_PhieuNhap.ThanhTien = float.Parse(row.Cells["ThanhTien"].Value.ToString());

                phieuNhapBUS = new PhieuNhapBUS();
                phieuNhapBUS.LuuCTPhieuNhap(cT_PhieuNhap);
            }

            MessageBox.Show("Lưu thành công");
        }
Ejemplo n.º 2
0
        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);
            }
        }