private async void LoadChiTietPhieuNhap(int idPhieuNhap) { var result = await NhapKhoService.LayChiTietPhieuNhapKho(idPhieuNhap); if (result != null && result.Status == Config.CODE_OK) { listChiTietNhapKho = (List <ChiTietNhapKho>)result.Data; nhapKho = listChiTietNhapKho[0].NhapKho; txtMa.Text = nhapKho.Ma; txtGhiChu.Text = nhapKho.GhiChu; txtTongTien.Text = nhapKho.TongTien.ToString(); dtpNgayNhap.Value = nhapKho.NgayNhap; cboKho.Text = nhapKho.Kho.Ten; cboNhaCungCap.Text = nhapKho.NhaCungCap.Ten; cboNhanVien.Text = nhapKho.NhanVien.Ten; LoadDanhSachVatTu(nhapKho.NhaCungCap.Id); } }
private async void LoadListNhapKho() { var result = await NhapKhoService.LayTatCaPhieuNhapKho(); if (result != null && result.Status == Config.CODE_OK) { listNhapKho = (List <NhapKho>)result.Data; lvNhapKho.Items.Clear(); foreach (NhapKho nhapKho in listNhapKho) { ListViewItem listViewItem = new ListViewItem(nhapKho.Ma.ToString()); listViewItem.SubItems.Add(nhapKho.NgayNhap.ToShortDateString()); listViewItem.SubItems.Add(nhapKho.Kho.Ten); listViewItem.SubItems.Add(nhapKho.NhanVien.Ten); listViewItem.SubItems.Add(nhapKho.NhaCungCap.Ten); listViewItem.SubItems.Add(nhapKho.TongTien.ToString()); listViewItem.SubItems.Add(nhapKho.GhiChu); listViewItem.SubItems[0].Tag = nhapKho.Id; lvNhapKho.Items.Add(listViewItem); } } }
private async void btnLuu_Click(object sender, EventArgs e) { NhapKho nhapKho = new NhapKho() { Ma = txtMa.Text, NgayNhap = dtpNgayNhap.Value, GhiChu = txtGhiChu.Text, NhanVien = new NhanVien() { Id = (int)cboNhanVien.SelectedValue }, NhaCungCap = new NhaCungCap() { Id = (int)cboNhaCungCap.SelectedValue }, Kho = new Kho() { Id = (int)cboKho.SelectedValue }, Id = ucNhapKho.idPhieuNhap }; List <VatTuNhapXuat> listVatTu = new List <VatTuNhapXuat>(); for (int i = 0; i < dgvVatTu.Rows.Count; i++) { var dr = dgvVatTu.Rows[i]; VatTuNhapXuat vatTu = new VatTuNhapXuat() { Id = (int)dr.Cells["Id"].Value, GhiChu = (string)dr.Cells["GhiChu"].Value, SoLuong = (int)dr.Cells["SoLuong"].Value }; if (vatTu.SoLuong > 0) { listVatTu.Add(vatTu); } } if (nhapKho.Id != 0) { // Call update var result = await NhapKhoService.CapNhatPhieuNhapKho(nhapKho, listVatTu); if (result != null && result.Status == Config.CODE_OK) { MessageBoxEx.Show("Cập nhật phiếu nhập kho thành công", "Thông báo"); txtTongTien.Text = ((decimal)result.Data).ToString(); LoadChiTietPhieuNhap(ucNhapKho.idPhieuNhap); LoadDanhSachVatTu(nhapKho.NhaCungCap.Id); } else { MessageBoxEx.Show("Cập nhật phiếu nhập kho thất bại", "Thông báo"); ChiTietNhapKho chiTiet = listChiTietNhapKho.SingleOrDefault(x => x.NhapKho.Id == ucNhapKho.idPhieuNhap); if (chiTiet != null) { nhapKho = chiTiet.NhapKho; txtMa.Text = nhapKho.Ma; txtGhiChu.Text = nhapKho.GhiChu; txtTongTien.Text = nhapKho.TongTien.ToString(); dtpNgayNhap.Value = nhapKho.NgayNhap; cboKho.Text = nhapKho.Kho.Ten; cboNhaCungCap.Text = nhapKho.NhaCungCap.Ten; cboNhanVien.Text = nhapKho.NhanVien.Ten; LoadDanhSachVatTu(nhapKho.NhaCungCap.Id); } } } else { // Call add new var result = await NhapKhoService.ThemMoiPhieuNhapKho(nhapKho, listVatTu); if (result != null && result.Status == Config.CODE_OK) { MessageBoxEx.Show("Thêm mới phiếu nhập kho thành công", "Thông báo"); InforNhapKho infor = (InforNhapKho)result.Data; txtTongTien.Text = ((decimal)infor.totalPrice).ToString(); LoadChiTietPhieuNhap(infor.receiptId); LoadDanhSachVatTu(nhapKho.NhaCungCap.Id); ucNhapKho.idPhieuNhap = infor.receiptId; } else { MessageBoxEx.Show("Thêm mới phiếu nhập kho thất bại", "Thông báo"); LoadDanhSachVatTu(nhapKho.NhaCungCap.Id); } } }