private void Save() { PhieuNhap itemSave = new PhieuNhap(); //thong tin ban hang itemSave.PhieuNhapID = PhieuNhapController.TaoMaPhieuNhap("PN", 10); itemSave.NgayNhap = dateEditNgayBan.DateTime; if (lookUpEditNhaCungCap.EditValue != null) { itemSave.NhaCungCapID = lookUpEditNhaCungCap.EditValue.ToString(); itemSave.TenNhaCungCap = lookUpEditNhaCungCap.Text; } itemSave.MaPhieuNCC = txtPhieuNhaCC.Text; itemSave.GhiChu = txtGhiChu.Text; itemSave.NhanVienID = txtNhanVien.Text; itemSave.TenNhanVien = Utility.NguoiSuDung.TenNguoiDung; itemSave.LastUpdate = DateTime.Now; //thong tin thanh toan itemSave.TienHang = txtTienHang.Value; itemSave.ThanhToan = txtThanhToan.Value; itemSave.ConNo = txtConNo.Value; //lay thong tin chi tiet don hang List <PhieuNhapChiTiet> PhieuNhapItems = new List <PhieuNhapChiTiet>(); if (tblDonHangChiTiet != null) { foreach (DataRow item in tblDonHangChiTiet.Rows) { PhieuNhapChiTiet newitem = new PhieuNhapChiTiet(); newitem.PhieuNhapID = itemSave.PhieuNhapID; newitem.SanPhamID = item["SanPhamID"].ToString(); newitem.TenSanPham = item["TenSanPham"].ToString(); newitem.Size = item["Size"].ToString(); newitem.SoLuong = Convert.ToInt32(item["SoLuong"].ToString()); newitem.DonGia = Convert.ToDecimal(item["DonGia"].ToString()); newitem.CreateDate = DateTime.Now; //newitem.TonKho = SanPhamController.GetTonKho(newitem.SanPhamID); PhieuNhapItems.Add(newitem); } } PhieuNhapController.Add(itemSave, PhieuNhapItems); }
void ThemMoi() { DataRow row = ctrl.NewRow(); row["ID"] = txtMaPhieu.Text; row["NGAY_NHAP"] = dtNgayNhap.Value.Date; row["TONG_TIEN"] = numTongTien.Value; row["ID_NHA_CUNG_CAP"] = cmbNhaCungCap.SelectedValue; row["DA_TRA"] = numDaTra.Value; row["CON_NO"] = numConNo.Value; ctrl.Add(row); PhieuNhapController ctrlPN = new PhieuNhapController(); if (ctrlPN.LayPhieuNhap(txtMaPhieu.Text) != null) { MessageBox.Show("Mã Phiếu nhập này đã tồn tại !", "Phieu Nhap", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (ThamSo.LaSoNguyen(txtMaPhieu.Text)) { long so = Convert.ToInt64(txtMaPhieu.Text); if (so >= ThamSo.LayMaPhieuNhap()) { ThamSo.GanMaPhieuNhap(so + 1); } } ctrl.Save(); ctrlMaSP.Save(); SanPhamController ctrlSP = new SanPhamController(); foreach (DataGridViewRow view in dataGridView.Rows) { ctrlSP.CapNhatGiaNhap(Convert.ToString(view.Cells["colSanPham"].Value), Convert.ToInt64(view.Cells["colDonGiaNhap"].Value), Convert.ToInt64(view.Cells["colSoLuong"].Value)); } }