private void FormChiTietThanhVien_Load(object sender, EventArgs e) { ThanhVienDTO thanhVienDTO = ThanhVienBUS.SelectThanhVienById(maThanhVien); labelMaThanhVien.Text = "Mã thành viên: " + maThanhVien; labelTenThanhVien.Text = "Tên thành viên: " + thanhVienDTO.TenThanhVien; labelDiaChi.Text = "Địa chỉ: " + thanhVienDTO.DiaChi; labelTongCV.Text = "Tổng CV: " + thanhVienDTO.CV.ToString(); List <PhieuXuatDTO> listPhieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatByMaThanhVien(maThanhVien); if (listPhieuXuatDTO != null) { dataGridViewChiTiet.Rows.Clear(); List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>(); foreach (PhieuXuatDTO itemPhieuXuat in listPhieuXuatDTO) { listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(itemPhieuXuat.MaPhieuXuat); if (listChiTietPhieuXuatDTO != null) { foreach (ChiTietPhieuXuatDTO itemCTPX in listChiTietPhieuXuatDTO) { dataGridViewChiTiet.Rows.Add( itemPhieuXuat.MaPhieuXuat, itemPhieuXuat.NgayBan.ToString("dd/MM/yyyy"), NhanVienBUS.SelectNhanVienById(itemPhieuXuat.MaNhanVien).TenNhanVien, SanPhamBUS.SelectSanPhamById(itemCTPX.MaSanPham).TenSanPham, itemCTPX.SoLuong.ToString(), string.Format("{0:#,0.##}", itemCTPX.ThanhTien) ); } } } } }
private void btnCapNhat_Click(object sender, EventArgs e) { if (KiemTraDong_KhongTonTai() == false) { FormXuatHang fQLXuatHang = new FormXuatHang(); fQLXuatHang.Status = 2; fQLXuatHang.MaPhieuXuat = dataGridView_TraCuuXuatHang.CurrentRow.Cells[clMaPhieuXuat.Index].Value.ToString(); fQLXuatHang.ShowDialog(); PhieuXuatDTO phieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatById(fQLXuatHang.MaPhieuXuat); int soLuong = 0; float thanhTien = 0; List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>(); listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(phieuXuatDTO.MaPhieuXuat); if (listChiTietPhieuXuatDTO != null) { for (int j = 0; j < listChiTietPhieuXuatDTO.Count; j++) { soLuong += listChiTietPhieuXuatDTO[j].SoLuong; thanhTien += listChiTietPhieuXuatDTO[j].ThanhTien; } } dataGridView_TraCuuXuatHang.CurrentRow.Cells[clSoLuong.Index].Value = soLuong; dataGridView_TraCuuXuatHang.CurrentRow.Cells[clSoTien.Index].Value = string.Format("{0:#,0.##}", thanhTien); } else { MessageBox.Show("Không có dữ liệu để cập nhật", "Quản lý xuất hàng"); } }
private void frmPhieuSuaChua_Load(object sender, EventArgs e) { vtptBus = new VatTuPhuTungBUS(); tcBus = new TienCongBUS(); ctpxBus = new ChiTietPhieuXuatBUS(); loadVatTuPhuTung_combobox(); loadTienCong_combobox(); this.loadData_Vao_GridView(); tb_machitiet.Clear(); tb_noidung.Clear(); tb_soluong.Clear(); bt_sua.Enabled = false; bt_xoa.Enabled = false; tb_giatiencong.Clear(); tb_dongia.Clear(); cb_tiencong.Text = null; cb_vattu.Text = null; int mactpx = data_suachua.RowCount + 1; tb_machitiet.Text = mactpx.ToString(); if (this.hsDTO != null) { lb_mahs.Text = hsDTO.Mahs.ToString(); tb_bienso.Text = hsDTO.Bienso; time_ngaysuachua.Text = hsDTO.Ngaytiepnhan.ToString(); } }
//Load khi status =1 //Chuyen sang trang thai cho XemChiTiet phieuxuat private void Load_Update() { //Load_Default(); //Load Thong tin PhieuXuat PhieuXuatDTO phieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatById(MaPhieuXuat); txtMaPhieuXuat.Text = phieuXuatDTO.MaPhieuXuat; if (phieuXuatDTO.MaThanhVien != "") { txtMaThanhVien.Text = phieuXuatDTO.MaThanhVien; txtMaThanhVien.ReadOnly = true; } else { txtTenKhachHang.Text = phieuXuatDTO.TenKhachHang; txtDiaChi.Text = phieuXuatDTO.DiaChi; } txtNgayBan.Text = phieuXuatDTO.NgayBan.ToString("dd/MM/yyyy"); txtMaNhanVien.Text = phieuXuatDTO.MaNhanVien; txtNhanVienBanHang.Text = NhanVienBUS.SelectNhanVienById(phieuXuatDTO.MaNhanVien).TenNhanVien; //Kiểm tra Khách hàng có là Thành viên không if (txtMaThanhVien.Text == "") { IsThanhVien = false; } //Thay đổi button Tạo thành Cập nhật btnTao.Text = "Cập nhật"; btnTao.Enabled = true; btnTaoMoi.Visible = false; btnLamLai.Visible = false; btnTimPhieuXuat.Visible = false; //Truy vấn lấy ChiTietPhieuXuat theo MaDonHang List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>(); listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(MaPhieuXuat); //Lấy tên sản phẩm SanPhamDTO sanphamDTO = new SanPhamDTO(); for (int i = 0; i < listChiTietPhieuXuatDTO.Count; i++) { sanphamDTO = SanPhamBUS.SelectSanPhamById(listChiTietPhieuXuatDTO[i].MaSanPham); dataGridView_XuatHang.Rows.Add(i + 1, listChiTietPhieuXuatDTO[i].MaSanPham, sanphamDTO.TenSanPham, listChiTietPhieuXuatDTO[i].CV, listChiTietPhieuXuatDTO[i].DonGia, (sanphamDTO.SoLuongTon + listChiTietPhieuXuatDTO[i].SoLuong), listChiTietPhieuXuatDTO[i].SoLuong, string.Format("{0:#,0.##}", listChiTietPhieuXuatDTO[i].ThanhTien)); dataGridView_XuatHang.Rows[i].ReadOnly = true; } dataGridView_XuatHang.SelectionMode = DataGridViewSelectionMode.FullRowSelect; }
//Cập nhật lại phiếu xuất private void btnYes_Click(object sender, EventArgs e) { if (CheckOut_clSoLuong(dataGridView_XuatHang)) { List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>(); listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(MaPhieuXuat); int cv = 0; int cv2 = 0; int SoLuongTon = 0; SanPhamDTO sanPhamDTO = new SanPhamDTO(); for (int i = 0; i < listChiTietPhieuXuatDTO.Count; i++) { //Tính lại SoLuongTon của sản phẩm SoLuongTon = listChiTietPhieuXuatDTO[i].SoLuong - int.Parse(dataGridView_XuatHang.Rows[i].Cells["clSoLuong"].Value.ToString()); sanPhamDTO = SanPhamBUS.SelectSanPhamById(listChiTietPhieuXuatDTO[i].MaSanPham); sanPhamDTO.SoLuongTon += SoLuongTon; SanPhamBUS.UpdateSanPhamById(sanPhamDTO); //cv cv2 += int.Parse(dataGridView_XuatHang.Rows[i].Cells["clSoLuong"].Value.ToString()) * int.Parse(dataGridView_XuatHang.Rows[i].Cells[clCV.Index].Value.ToString()); cv += listChiTietPhieuXuatDTO[i].CV * listChiTietPhieuXuatDTO[i].SoLuong; listChiTietPhieuXuatDTO[i].SoLuong = int.Parse(dataGridView_XuatHang.Rows[i].Cells["clSoLuong"].Value.ToString()); listChiTietPhieuXuatDTO[i].ThanhTien = float.Parse(dataGridView_XuatHang.Rows[i].Cells["clThanhTien"].Value.ToString()); ChiTietPhieuXuatBUS.UpdateChiTietPhieuXuatById(listChiTietPhieuXuatDTO[i]); } //Tinh lai TongCV if (IsThanhVien == true) { this.thanhVienDTO.CV = this.thanhVienDTO.CV - cv + cv2; ThanhVienBUS.UpdateThanhVienById(this.thanhVienDTO); } MessageBox.Show("Cập nhật thành công", "Cập nhật đơn hàng"); this.Dispose(); } else { MessageBox.Show("Phiếu xuất không hợp lệ, tất cả số lượng sản phẩm đều bằng không", "Phiếu xuất"); dataGridView_XuatHang.CurrentCell = dataGridView_XuatHang.Rows[0].Cells[clSoLuong.Index]; dataGridView_XuatHang.CurrentCell.Selected = true; dataGridView_XuatHang.BeginEdit(true); } }
private void KhoiTao() { List <PhieuXuatDTO> listPhieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatAll(); List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>(); int soLuong = 0; float thanhTien = 0; if (listPhieuXuatDTO != null) { dataGridView_TraCuuXuatHang.Rows.Clear(); PhieuXuatDTO phieuXuatDTO = new PhieuXuatDTO(); for (int i = 0; i < listPhieuXuatDTO.Count; i++) { phieuXuatDTO = listPhieuXuatDTO[i]; listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(phieuXuatDTO.MaPhieuXuat); if (listChiTietPhieuXuatDTO != null) { soLuong = 0; thanhTien = 0; for (int j = 0; j < listChiTietPhieuXuatDTO.Count; j++) { soLuong += listChiTietPhieuXuatDTO[j].SoLuong; thanhTien += listChiTietPhieuXuatDTO[j].ThanhTien; } } dataGridView_TraCuuXuatHang.Rows.Add( (i + 1).ToString(), phieuXuatDTO.MaPhieuXuat, phieuXuatDTO.NgayBan.ToString("dd/MM/yyyy"), phieuXuatDTO.TenKhachHang, NhanVienBUS.SelectNhanVienById(phieuXuatDTO.MaNhanVien).TenNhanVien, soLuong.ToString(), string.Format("{0:#,0.##}", thanhTien)); } btnLamLai.Enabled = true; } else { buttonDisabled(); btnLamLai.Enabled = false; } }
private void btnXoa_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Xóa phiếu xuất", "Phiếu xuất", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); //Lấy vị trí cần xóa if (result == DialogResult.Yes) { int Index = dataGridView_TraCuuXuatHang.CurrentRow.Index; int stt = int.Parse(dataGridView_TraCuuXuatHang.CurrentRow.Cells[clSTT.Index].Value.ToString()); string id = dataGridView_TraCuuXuatHang.CurrentRow.Cells["clMaPhieuXuat"].Value.ToString(); List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(id); PhieuXuatDTO phieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatById(id); if (PhieuXuatBUS.DeletePhieuXuatById(id)) { dataGridView_TraCuuXuatHang.Rows.RemoveAt(Index); if (dataGridView_TraCuuXuatHang.RowCount > 0) { bool f = false; for (int i = 0; i < Index; i++) { if (dataGridView_TraCuuXuatHang.Rows[i].Visible == true) { f = true; break; } } for (int i = Index; i < dataGridView_TraCuuXuatHang.RowCount; i++) { if (dataGridView_TraCuuXuatHang.Rows[i].Visible == true) { dataGridView_TraCuuXuatHang.Rows[i].Cells["clSTT"].Value = stt.ToString(); stt++; f = true; } } if (f == false) { buttonDisabled(); } else { buttonEnabled(); } } else { buttonDisabled(); } int cv = 0; SanPhamDTO sanPhamDTO = new SanPhamDTO(); for (int i = 0; i < listChiTietPhieuXuatDTO.Count; i++) { //Tính lại SoLuongTon của sản phẩm sanPhamDTO = SanPhamBUS.SelectSanPhamById(listChiTietPhieuXuatDTO[i].MaSanPham); sanPhamDTO.SoLuongTon = sanPhamDTO.SoLuongTon + listChiTietPhieuXuatDTO[i].SoLuong; SanPhamBUS.UpdateSanPhamById(sanPhamDTO); //cv cv += listChiTietPhieuXuatDTO[i].CV * listChiTietPhieuXuatDTO[i].SoLuong; } //Tinh lai TongCV if (phieuXuatDTO.MaThanhVien != "") { ThanhVienDTO thanhVien = ThanhVienBUS.SelectThanhVienById(phieuXuatDTO.MaThanhVien); thanhVien.CV = thanhVien.CV - cv; ThanhVienBUS.UpdateThanhVienById(thanhVien); } MessageBox.Show("Xóa thành công"); } } }
private void FormChiTietNhanVien_Load(object sender, EventArgs e) { NhanVienDTO nhanVienDTO = NhanVienBUS.SelectNhanVienById(maNhanVien); labelMaNhanVien.Text = "Mã nhân viên: " + nhanVienDTO.MaNhanVien; labelTenNhanVien.Text = "Tên nhân viên: " + nhanVienDTO.TenNhanVien; dataGridViewXuatHang.Dock = DockStyle.Fill; dataGridViewNhapHang.Dock = DockStyle.Fill; List <PhieuXuatDTO> listPhieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatByMaNhanVien(maNhanVien); if (listPhieuXuatDTO != null) { dataGridViewXuatHang.Rows.Clear(); List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>(); foreach (PhieuXuatDTO itemPhieuXuat in listPhieuXuatDTO) { listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(itemPhieuXuat.MaPhieuXuat); foreach (ChiTietPhieuXuatDTO itemCTPX in listChiTietPhieuXuatDTO) { dataGridViewXuatHang.Rows.Add( itemPhieuXuat.MaPhieuXuat, itemPhieuXuat.NgayBan.ToString("dd/MM/yyyy"), NhanVienBUS.SelectNhanVienById(itemPhieuXuat.MaNhanVien).TenNhanVien, SanPhamBUS.SelectSanPhamById(itemCTPX.MaSanPham).TenSanPham, itemCTPX.SoLuong.ToString(), string.Format("{0:#,0.##}", itemCTPX.ThanhTien) ); } } } List <PhieuNhapDTO> listPhieuNhapDTO = PhieuNhapBUS.SelectPhieuNhapByMaNhanVien(maNhanVien); if (listPhieuNhapDTO != null) { dataGridViewNhapHang.Rows.Clear(); List <ChiTietPhieuNhapDTO> listChiTietPhieuNhapDTO = new List <ChiTietPhieuNhapDTO>(); foreach (PhieuNhapDTO itemPhieuNhap in listPhieuNhapDTO) { listChiTietPhieuNhapDTO = ChiTietPhieuNhapBUS.SelectChiTietPhieuNhapByMaPhieuNhap(itemPhieuNhap.MaPhieuNhap); foreach (ChiTietPhieuNhapDTO itemCTPN in listChiTietPhieuNhapDTO) { dataGridViewNhapHang.Rows.Add( itemPhieuNhap.MaPhieuNhap, itemPhieuNhap.NgayNhan.ToString("dd/MM/yyyy"), itemPhieuNhap.MaDonHang, DonHangBUS.SelectDonHangById(itemPhieuNhap.MaDonHang).NgayLap.ToString("dd/MM/yyyy"), NhanVienBUS.SelectNhanVienById(itemPhieuNhap.MaNhanVien).TenNhanVien, SanPhamBUS.SelectSanPhamById(itemCTPN.MaSanPham).TenSanPham, itemCTPN.SLNhan.ToString() ); } } } comboBoxNhapXuat.Items.Add("Nhâp hàng"); comboBoxNhapXuat.Items.Add("Xuất hàng"); comboBoxNhapXuat.SelectedIndex = 0; }
private bool Process_Button() { //Lấy các trường để insert vào bảng PhieuXuat PhieuXuatDTO phieuXuatDTO = new PhieuXuatDTO(); phieuXuatDTO.MaPhieuXuat = txtMaPhieuXuat.Text; phieuXuatDTO.NgayBan = DateTimeSystem; phieuXuatDTO.MaNhanVien = ThongTin.NhanVienDTO.MaNhanVien; if (txtMaThanhVien.Text == "") { //MaThanhVien Thamchieu bang ThanhVien => notnull=>sua storeproc phieuXuatDTO.MaThanhVien = null; if (txtTenKhachHang.Text == "") { MessageBox.Show("Tên khách hàng không hợp lệ"); return(false); } else { phieuXuatDTO.TenKhachHang = txtTenKhachHang.Text; } if (txtDiaChi.Text == "") { MessageBox.Show("Địa chỉ không hợp lệ"); return(false); } else { phieuXuatDTO.DiaChi = txtDiaChi.Text; } phieuXuatDTO.MaLoaiPhieuXuat = "LPX02"; } else { phieuXuatDTO.MaThanhVien = txtMaThanhVien.Text; phieuXuatDTO.TenKhachHang = txtTenKhachHang.Text; phieuXuatDTO.DiaChi = txtDiaChi.Text; phieuXuatDTO.MaLoaiPhieuXuat = "LPX01"; } //Lấy các trường để insert vào bảng ChiTietPhieuXuat List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>(); SanPhamDTO sanPhamDTO = new SanPhamDTO(); for (int i = 0; i < dataGridView_XuatHang.Rows.Count; i++) { ChiTietPhieuXuatDTO chiTietPhieuXuatDTO = new ChiTietPhieuXuatDTO(); DataGridViewRow Row = dataGridView_XuatHang.Rows[i]; int check; int.TryParse(Row.Cells["clSoLuong"].Value.ToString(), out check); if (check > 0) { chiTietPhieuXuatDTO.MaChiTietPhieuXuat = txtMaPhieuXuat.Text; if (i > 100) { chiTietPhieuXuatDTO.MaChiTietPhieuXuat += (i + 1).ToString(); } else if (i > 100) { chiTietPhieuXuatDTO.MaChiTietPhieuXuat += "0" + (i + 1).ToString(); } else { chiTietPhieuXuatDTO.MaChiTietPhieuXuat += "00" + (i + 1).ToString(); } chiTietPhieuXuatDTO.MaPhieuXuat = txtMaPhieuXuat.Text; chiTietPhieuXuatDTO.MaSanPham = Row.Cells["clMaSanPham"].Value.ToString(); chiTietPhieuXuatDTO.CV = int.Parse(Row.Cells["clCV"].Value.ToString()); chiTietPhieuXuatDTO.SoLuong = int.Parse(Row.Cells["clSoLuong"].Value.ToString()); chiTietPhieuXuatDTO.DonGia = float.Parse(Row.Cells["clDonGia"].Value.ToString()); chiTietPhieuXuatDTO.ThanhTien = float.Parse(Row.Cells["clThanhTien"].Value.ToString()); listChiTietPhieuXuatDTO.Add(chiTietPhieuXuatDTO); //Tinh SoLuongTon của sản phẩm int SoLuongTon = int.Parse(Row.Cells["clSoLuongTon"].Value.ToString()) - int.Parse(Row.Cells["clSoLuong"].Value.ToString()); sanPhamDTO = SanPhamBUS.SelectSanPhamById(chiTietPhieuXuatDTO.MaSanPham); sanPhamDTO.SoLuongTon = SoLuongTon; SanPhamBUS.UpdateSanPhamById(sanPhamDTO); //Tinh TongCV TongCV += int.Parse(Row.Cells["clCV"].Value.ToString()) * int.Parse(Row.Cells["clSoLuong"].Value.ToString()); } } //insert dữ liệu if (PhieuXuatBUS.InsertPhieuXuat(phieuXuatDTO)) { foreach (ChiTietPhieuXuatDTO chiTietPhieuXuatDTO in listChiTietPhieuXuatDTO) { ChiTietPhieuXuatBUS.InsertChiTietPhieuXuat(chiTietPhieuXuatDTO); } if (IsThanhVien == true) { thanhVienDTO.CV += TongCV; ThanhVienBUS.UpdateThanhVienById(thanhVienDTO); } MessageBox.Show("Nhập dữ liệu thành công"); return(true); } else { MessageBox.Show("Nhập dữ liệu thất bại"); } return(false); }