public bool DeleteCongNo() { try { string maXoa = ""; cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; foreach (Entities.SoDuCongNo item in this.hienthi) { if (item.MaDoiTuong.Equals(maNCCDELETE0)) { maXoa = item.MaSoDuCongNo; } } if (maXoa.Equals("")) { pt[0] = new Entities.SoDuCongNo("Delete", ma); } else { pt[0] = new Entities.SoDuCongNo("Delete", maXoa); } // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); bool kt = false; kt = (bool)cl.DeserializeHepper(clientstrem, kt); if (kt == true) { SelectData(); } return kt; } catch { return false; } }
public void SelectData() { try { bool loaiDoiTuong = false; if (cbbdoituong.SelectedIndex == 0) loaiDoiTuong = false; else loaiDoiTuong = true; cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi1 = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi1); if (hienthi1 == null) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; tsslthuchien.Enabled = true; return; } year = cbbnam.Text; month = cbbthang.Text; int sotang = 0; bool ktsd = false; Entities.SoDuCongNo[] sq = new Entities.SoDuCongNo[hienthi1.Length]; for (int i = 0; i < sq.Length; i++) { string namkt = hienthi1[i].NgayKetChuyen.Year.ToString(); string thangkt = hienthi1[i].NgayKetChuyen.Month.ToString(); if (namkt == year && thangkt == month && hienthi1[i].LoaiDoiTuong == loaiDoiTuong) { if (hienthi1[i].TrangThai == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; tsslthuchien.Enabled = true; } else { lbtrangthai.Text = "Kỳ này đã khóa"; lbtrangthai.ForeColor = Color.Red; tsslthuchien.Enabled = false; } ma = hienthi1[i].MaSoDuCongNo; sq[sotang] = hienthi1[i]; sotang++; ktsd = true; } } if (ktsd == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; tsslthuchien.Enabled = true; } if (sotang != 0) { hienthi = new Entities.SoDuCongNo[sotang]; for (int i = 0; i < sotang; i++) { hienthi[i] = sq[i]; } } else hienthi = null; } catch { } finally { } }
private void dtgvcongno_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { i = e.RowIndex; this.maNCCDELETE0 = dtgvcongno[3, e.RowIndex].Value.ToString(); //string maNCCDELETE2 = dtgvcongno[2, e.RowIndex].Value.ToString(); if (i < 0) return; try { string month1 = datesv.Month.ToString(); // kiểm tra tháng hiên tại và tháng được chọn if (month1 != month) { MessageBox.Show("Không phải kỳ hiện tại", "Hệ thống cảnh báo"); return; } cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi); // nếu obj khác null if (hienthi != null) { for (int j = 0; j < hienthi.Length; j++) { string monthkytruoc = (Convert.ToInt32(month) - 1).ToString(); string mm = hienthi[j].NgayKetChuyen.Month.ToString(); // kiểm tra kỳ trước của tháng đang chọn if (mm == monthkytruoc) { MessageBox.Show("Số dư đầu kỳ là kết chuyển từ kỳ trước - không thể thay đổi", "Hệ thống cảnh báo"); SelectData(); return; } } } if (MessageBox.Show("Bạn chắc chắn muốn xóa không?", "Hệ thống cảnh báo", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { // nếu kỳ trc không tồn tại tsslma.Text = dtgvcongno["MaDoiTuong", i].Value.ToString(); tsslten.Text = dtgvcongno["TenDoiTuong", i].Value.ToString(); tssldiachi.Text = dtgvcongno["DiaChi", i].Value.ToString(); tsslsodudauky.Text = dtgvcongno["SoDuDauKy", i].Value.ToString(); sono = Convert.ToDouble(dtgvcongno["SoDuDauKy", i].Value.ToString()); if (dtgvcongno.RowCount >= 1) { if (DeleteCongNo()) { if (cbbdoituong.SelectedIndex == 0) { Entities.KhachHang kh = new Entities.KhachHang("UpdateDuNoKH", tsslma.Text, sono.ToString()); UpdateDuNo(kh); } else { Entities.NhaCungCap kh = new Entities.NhaCungCap("UpdateDuNo", tsslma.Text, sono.ToString()); UpdateDuNoNCC(kh); } } else { MessageBox.Show("Xóa thất bại - xin thử lại sau", "Hệ thống cảnh báo"); return; } } } } catch { } finally { fix(); } }
private void toolStripButton1_Click(object sender, EventArgs e) { try { double.Parse(tsslsodudauky.Text); } catch { MessageBox.Show("Số dư đầu kỳ không được nhập ký tự", "Hệ thống cảnh báo"); tsslsodudauky.Focus(); return; } try { // kiểm tra giá trị trong dtgv if (CheckDataGridViewInsert() == true) { string month1 = datesv.Month.ToString(); //nếu tháng hiện tại không = tháng đang xử lý if (month1 != month) { MessageBox.Show("Không phải kỳ hiện tại - xin kiểm tra lại", "Hệ thống cảnh báo"); return; } cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi); // nếu obj khác null if (hienthi != null) { for (int i = 0; i < hienthi.Length; i++) { string monthkytruoc = (Convert.ToInt32(month) - 1).ToString(); string mm = hienthi[i].NgayKetChuyen.Month.ToString(); // kiểm tra kỳ trước có tồn tại số dư hay không if (mm == monthkytruoc && hienthi[i].MaDoiTuong == tsslma.Text) { MessageBox.Show("Số dư đầu kỳ là kết chuyển từ kỳ trước - không thể thay đổi", "Hệ thống cảnh báo"); return; } } } //nếu không tồn tại số dư kỳ trước try { bool loaidt = false; if (cbbdoituong.SelectedIndex == 0) loaidt = false; else loaidt = true; string masd = ProID("SoDuCongNo"); cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt1 = new Entities.SoDuCongNo[1]; pt1[0] = new Entities.SoDuCongNo("Insert", 0, masd, tsslma.Text, tsslten.Text, tssldiachi.Text, tsslsodudauky.Text, datesv, "0", loaidt, false); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt1); // đổ mảng đối tượng vào datagripview bool kt = false; kt = (bool)cl.DeserializeHepper(clientstrem, kt); if (kt == true) { if (cbbdoituong.SelectedIndex == 0) { Entities.KhachHang kh = new Entities.KhachHang("UpdateDuNo", tsslma.Text, tsslsodudauky.Text); UpdateDuNo(kh); } else { Entities.NhaCungCap kh = new Entities.NhaCungCap("UpdateDuNoNCC", tsslma.Text, tsslsodudauky.Text); UpdateDuNoNCC(kh); } tsslsodudauky.Text = tsslten.Text = tssldiachi.Text = ""; tsslma.Text = "<F4>-Tra cứu"; SelectData(); tsslma.Focus(); } else { MessageBox.Show("Thêm số dư đầu kỳ thất bại - xin thử lại sau","Hệ thống cảnh báo"); return; } } catch { } } } catch { } }
public void SelectSoDuCongNo() { try { if (soducongno == null || soducongno.Length == 0) { soducongno = new Entities.SoDuCongNo[0]; return; } int sotang = 0; Entities.SoDuCongNo[] sq = new Entities.SoDuCongNo[soducongno.Length]; for (int i = 0; i < sq.Length; i++) { string namkt = soducongno[i].NgayKetChuyen.Year.ToString(); string thangkt = soducongno[i].NgayKetChuyen.Month.ToString(); if (soducongno[i].LoaiDoiTuong == false && namkt == datesv.Year.ToString() && thangkt == datesv.Month.ToString()) { sq[sotang] = soducongno[i]; sotang++; } } if (sotang != 0) { soducongno = new Entities.SoDuCongNo[sotang]; for (int i = 0; i < sotang; i++) { soducongno[i] = new Entities.SoDuCongNo("", sq[i].MaDoiTuong, sq[i].TenDoiTuong, sq[i].DiaChi, sq[i].SoDuDauKy); soducongno[i].NgayKetChuyen = sq[i].NgayKetChuyen; } } else soducongno = new Entities.SoDuCongNo[0]; } catch { } finally { } }
public void SelectData() { try { bool loaiDoiTuong = false; if (cbbdoituong.SelectedIndex == 0) loaiDoiTuong = false; else loaiDoiTuong = true; cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi); // nếu null if (hienthi == null) { hienthi = new Entities.SoDuCongNo[0]; lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; toolStrip1.Enabled = dtgvcongno.Enabled = true; return; } year = cbbnam.Text; month = cbbthang.Text; int sotang = 0; bool ktsd = false; Entities.SoDuCongNo[] sq = new Entities.SoDuCongNo[hienthi.Length]; for (int i = 0; i < sq.Length; i++) { string namkt = hienthi[i].NgayKetChuyen.Year.ToString(); string thangkt = hienthi[i].NgayKetChuyen.Month.ToString(); // nếu năm tháng trong bản ghi - năm tháng hiện tại và loại đối tượng if (namkt == year && thangkt == month && hienthi[i].LoaiDoiTuong == loaiDoiTuong) { // nếu trạng thái = false if (hienthi[i].TrangThai == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; toolStrip1.Enabled = dtgvcongno.Enabled = true; } else { lbtrangthai.Text = "Kỳ này đã khóa"; lbtrangthai.ForeColor = Color.Red; toolStrip1.Enabled = dtgvcongno.Enabled = false; } ma = hienthi[i].MaSoDuCongNo; sq[sotang] = hienthi[i]; sotang++; ktsd = true; } } // nếu không có đối tượng nào đúng if (ktsd == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; toolStrip1.Enabled = dtgvcongno.Enabled = true; } // nếu không có bản ghi nào tồn tại if (sotang != 0) { hienthi = new Entities.SoDuCongNo[sotang]; for (int i = 0; i < sotang; i++) { hienthi[i] = new Entities.SoDuCongNo("", sq[i].MaDoiTuong, sq[i].TenDoiTuong, sq[i].DiaChi, sq[i].SoDuDauKy); } } else { hienthi = new Entities.SoDuCongNo[0]; dtgvcongno.DataSource = hienthi; return; } dtgvcongno.DataSource = hienthi; new Common.Utilities().CountDatagridview(dtgvcongno); } catch { } finally { fix(); } }
public void SelectSoDuCongNo() { try { bool loaiDoiTuong = false; if (cbbdoituong.SelectedIndex == 0) loaiDoiTuong = false; else loaiDoiTuong = true; cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); Entities.CongNo[] hienthi = new Entities.CongNo[1]; // đổ mảng đối tượng vào datagripview hienthi1 = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi); if (hienthi1 == null) { hienthi1 = new Entities.SoDuCongNo[0]; return; } year = cbbnam.Text; month = cbbthang.Text; int sotang = 0; Entities.SoDuCongNo[] sq = new Entities.SoDuCongNo[hienthi1.Length]; for (int i = 0; i < sq.Length; i++) { string namkt = hienthi1[i].NgayKetChuyen.Year.ToString(); string thangkt = hienthi1[i].NgayKetChuyen.Month.ToString(); if (namkt == year && thangkt == month && hienthi1[i].LoaiDoiTuong == loaiDoiTuong) { sq[sotang] = hienthi1[i]; sotang++; } } if (sotang != 0) { hienthi1 = new Entities.SoDuCongNo[sotang]; for (int i = 0; i < sotang; i++) { hienthi1[i] = new Entities.SoDuCongNo("", sq[i].MaSoDuCongNo, sq[i].MaDoiTuong, sq[i].TenDoiTuong, sq[i].DiaChi, sq[i].SoDuDauKy); } } else hienthi1 = new Entities.SoDuCongNo[0]; } catch { } finally { } }
/// <summary> /// hiển thị tổng /// </summary> public void HienThiTong() { try { if (cbbdoituong.SelectedIndex == 0) { SelectDataKH(); } else { SelectDataNCC(); } SelectBanBuonLe(); hienthi = new List<Entities.CongNo>(); congnokh = new List<Entities.CongNo>(); congnoncc = new List<Entities.CongNo>(); int soluong = 0; int soluongkh = 0; int soluongncc = 0; sdck = sddk = 0; if (cbbdoituong.SelectedIndex == 0) { string maSoDuCongNo = ""; SelectSoDuCongNo(); // Khách Hàng for (int i = 0; i < kh.Length; i++) { phatsinhco = 0; phatsinhno = 0; sddk = 0; for (int j = 0; j < hienthi1.Length; j++) { if (hienthi1[j].MaDoiTuong == kh[i].MaKH) { maSoDuCongNo = hienthi1[j].MaSoDuCongNo; sddk = Double.Parse(hienthi1[j].SoDuDauKy); break; } } // bán buôn for (int j = 0; j < bb.Length; j++) { if (bb[j].MaKhachHang == kh[i].MaKH) { double a = Convert.ToDouble(bb[j].TongTienThanhToan); double b = Convert.ToDouble(bb[j].ThanhToanKhiLapPhieu); if (b > a) { b = a; } phatsinhno += a; phatsinhco += b; string ngaylap = new Common.Utilities().XuLy(2, bb[j].NgayBan.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, Format(a), Format(b), bb[j].GhiChu, "PhieuThu"); hienthi.Add(cn); } } // Phieu thu for (int j = 0; j < phieuThuChi.Length; j++) { try { string month1 = phieuThuChi[j].NgayLap.Month.ToString(); string year1 = phieuThuChi[j].NgayLap.Year.ToString(); if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year) { phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan); string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, "0", Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), phieuThuChi[j].GhiChu, "Thu"); hienthi.Add(cn); } } catch { } } // Phieu chi for (int j = 0; j < phieuThuChi.Length; j++) { try { string month1 = phieuThuChi[j].NgayLap.Month.ToString(); string year1 = phieuThuChi[j].NgayLap.Year.ToString(); if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year) { phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan); string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", phieuThuChi[j].GhiChu, "Chi"); hienthi.Add(cn); } } catch { } } // khách hàng trả lại for (int j = 0; j < khtl.Length; j++) { if (khtl[j].MaKhachHang == kh[i].MaKH) { double a = Convert.ToDouble(khtl[j].TienBoiThuong); double b = Convert.ToDouble(khtl[j].ThanhToanNgay); if (b > a) { b = a; } phatsinhco += a; phatsinhno += b; string ngaylap = new Common.Utilities().XuLy(2, khtl[j].NgayNhap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, Format(b), Format(a), khtl[j].GhiChu, "PhieuThu"); hienthi.Add(cn); } } // phiếu thanh toán của khách hàng for (int j = 0; j < phieuttcuakh.Length; j++) { if (phieuttcuakh[j].MaKhachHang == kh[i].MaKH) { double tienthanhtoan = 0; for (int k = 0; k < chitietphieuttcuakh.Length; k++) { if (phieuttcuakh[j].MaPhieuTTCuaKH == chitietphieuttcuakh[k].MaPhieuTTCuaKH) { phatsinhco += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString()); tienthanhtoan += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString()); } } string ngaylap = new Common.Utilities().XuLy(2, phieuttcuakh[j].NgayLap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, "0", Format(tienthanhtoan), phieuttcuakh[j].GhiChu, "PhieuTTCuaKH"); hienthi.Add(cn); } } sdck = sddk + phatsinhno - phatsinhco; Entities.SoDuCongNo sdcnKH = new Entities.SoDuCongNo("UpdateTrangThai", maSoDuCongNo, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, (sddk + phatsinhno - phatsinhco).ToString(), Convert.ToDateTime(cbbthang.Text + "/01/" + cbbnam.Text), false); Entities.CongNo cnkh = new Entities.CongNo(kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck)); mangchitiet.Add(sdcnKH); congnokh.Add(cnkh); } sddk = phatsinhno = phatsinhco = 0; // tính toán của mảng khách hàng Entities.CongNo cnkh1 = new Entities.CongNo(); int count = congnokh.ToArray().Length; if (count == 1) { for (int i = 0; i < count; i++) { sdck = sddk + phatsinhno - phatsinhco; cnkh1 = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty); } congnokh.Add(cnkh1); } else { for (int i = 0; i < count; i++) { phatsinhco += Convert.ToDouble(congnokh[i].PhatSinhCo); phatsinhno += Convert.ToDouble(congnokh[i].PhatSinhNo); sddk += double.Parse(congnokh[i].DuDauKy); sdck = sddk + phatsinhno - phatsinhco; cnkh1 = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty); } congnokh.Add(cnkh1); } Entities.TongHopCongNo thcn; congNoList = new List<Entities.TongHopCongNo>(); foreach (Entities.CongNo item in congnokh) { double psn = 0; double psc = 0; double ddk = 0; double dck = 0; if (!string.IsNullOrEmpty(item.PhatSinhNo)) psn = double.Parse(item.PhatSinhNo); if (!string.IsNullOrEmpty(item.PhatSinhCo)) psc = double.Parse(item.PhatSinhCo); if (!string.IsNullOrEmpty(item.DuDauKy)) ddk = double.Parse(item.DuDauKy); if (!string.IsNullOrEmpty(item.DuCuoiKy)) dck = double.Parse(item.DuCuoiKy); thcn = new Entities.TongHopCongNo(); thcn.MaDoiTuong = item.MaDoiTuong; thcn.TenDoiTuong = item.TenDoiTuong; thcn.DiaChi = item.DiaChi; thcn.PhatSinhNo = psn; thcn.PhatSinhCo = psc; thcn.DuDauKy = ddk; thcn.DuCuoiKy = dck; if (!string.IsNullOrEmpty(item.MaDoiTuong)) congNoList.Add(thcn); } } else { SelectSoDuCongNo(); // Nhà Cung Cấp for (int i = 0; i < ncc.Length; i++) { phatsinhco = 0; phatsinhno = 0; sddk = 0; string maSoDuCongNo = ""; for (int j = 0; j < hienthi1.Length; j++) { if (hienthi1[j].MaDoiTuong == ncc[i].MaNhaCungCap) { maSoDuCongNo = hienthi1[j].MaSoDuCongNo; sddk = Double.Parse(hienthi1[j].SoDuDauKy); break; } } // hóa đơn nhập for (int j = 0; j < hdn.Length; j++) { if (ncc[i].MaNhaCungCap == hdn[j].MaNhaCungCap) { double a = Convert.ToDouble(hdn[j].TongTien); double b = Convert.ToDouble(hdn[j].ThanhToanNgay); if (b > a) { b = a; } phatsinhco += a; phatsinhno += b; string ngaylap = new Common.Utilities().XuLy(2, hdn[j].NgayNhap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, Format(b), Format(a), hdn[j].GhiChu, "HoaDonNhap"); hienthi.Add(cn); } } // Phieu thu for (int j = 0; j < phieuThuChi.Length; j++) { try { string month1 = phieuThuChi[j].NgayLap.Month.ToString(); string year1 = phieuThuChi[j].NgayLap.Year.ToString(); if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year) { phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan); string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, "0", Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), phieuThuChi[j].GhiChu, "Thu"); hienthi.Add(cn); } } catch { } } // Phieu chi for (int j = 0; j < phieuThuChi.Length; j++) { try { string month1 = phieuThuChi[j].NgayLap.Month.ToString(); string year1 = phieuThuChi[j].NgayLap.Year.ToString(); if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year) { phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan); string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", phieuThuChi[j].GhiChu, "Chi"); hienthi.Add(cn); } } catch { } } // trả lại nhà cung cấp for (int j = 0; j < tl.Length; j++) { if (tl[j].MaNCC == ncc[i].MaNhaCungCap) { double tongTienThanhToan = Convert.ToDouble(tl[j].TienBoiThuong); double thanhToanNgay = Convert.ToDouble(tl[j].ThanhToanNgay); if (thanhToanNgay > tongTienThanhToan) thanhToanNgay = tongTienThanhToan; phatsinhno += tongTienThanhToan; phatsinhco += thanhToanNgay; string ngaylap = new Common.Utilities().XuLy(2, tl[j].Ngaytra.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, Format(double.Parse(tl[j].ThanhToanNgay)), Format(double.Parse(tl[j].TienBoiThuong)), tl[j].GhiChu, "KHTL"); hienthi.Add(cn); } } // phiếu thanh toán của nhà cung cấp for (int j = 0; j < phieuttncc.Length; j++) { if (phieuttncc[j].MaNCC == ncc[i].MaNhaCungCap) { double tienthanhtoan = 0; for (int k = 0; k < chitietphieuttncc.Length; k++) { if (phieuttncc[j].MaPhieuTTNCC == chitietphieuttncc[k].MaPhieuTTNCC) { phatsinhno += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString()); tienthanhtoan += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString()); } } string ngaylap = new Common.Utilities().XuLy(2, phieuttncc[j].NgayLap.ToShortDateString()); Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, "0", Format(tienthanhtoan), phieuttncc[j].GhiChu, "PhieuThu"); hienthi.Add(cn); } } sdck = sddk + phatsinhco - phatsinhno; Entities.SoDuCongNo sdcnNCC = new Entities.SoDuCongNo("UpdateTrangThai", maSoDuCongNo, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, sdck.ToString(), Convert.ToDateTime(cbbthang.Text + "/01/" + cbbnam.Text), true); Entities.CongNo cnncc = new Entities.CongNo(ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck)); mangchitiet.Add(sdcnNCC); congnoncc.Add(cnncc); soluongncc++; } sddk = phatsinhno = phatsinhco = 0; // tính toán của mảng nhà cung cấp int count = congnoncc.ToArray().Length; Entities.CongNo cnNCC = new Entities.CongNo(); if (count == 1) { for (int i = 0; i < count; i++) { sdck = sddk + phatsinhco - phatsinhno; cnNCC = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty); } congnoncc.Add(cnNCC); } else { for (int i = 0; i < count; i++) { phatsinhco += Convert.ToDouble(congnoncc[i].PhatSinhCo); phatsinhno += Convert.ToDouble(congnoncc[i].PhatSinhNo); sddk += double.Parse(congnoncc[i].DuDauKy); sdck = sddk + phatsinhco - phatsinhno; cnNCC = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty); } congnoncc.Add(cnNCC); } } if (cbbdoituong.SelectedIndex == 0) { soluong = 0; int sl = 0; Entities.CongNo[] sdcn = new Entities.CongNo[congnokh.ToArray().Length]; for (int i = 0; i < congnokh.ToArray().Length - 1; i++) { double dauky = Convert.ToDouble(congnokh[i].DuDauKy); double cuoiky = Convert.ToDouble(congnokh[i].DuCuoiKy); double psco = Convert.ToDouble(congnokh[i].PhatSinhCo); double psno = Convert.ToDouble(congnokh[i].PhatSinhNo); if (dauky == 0 && cuoiky == 0 && psco == 0 && psno == 0) { soluong++; } else { sdcn[sl] = congnokh[i]; sl++; } } Entities.CongNo[] sdcn1 = new Entities.CongNo[sl + 1]; for (int i = 0; i < sdcn1.Length; i++) { if (i < sdcn1.Length - 1) sdcn1[i] = sdcn[i]; else sdcn1[i] = congnokh[congnokh.ToArray().Length - 1]; } dtgvcongno.DataSource = sdcn1; fixKH(); } else { soluong = 0; int sl = 0; Entities.CongNo[] sdcn = new Entities.CongNo[congnoncc.ToArray().Length]; for (int i = 0; i < congnoncc.ToArray().Length - 1; i++) { double dauky = Convert.ToDouble(congnoncc[i].DuDauKy); double cuoiky = Convert.ToDouble(congnoncc[i].DuCuoiKy); double psco = Convert.ToDouble(congnoncc[i].PhatSinhCo); double psno = Convert.ToDouble(congnoncc[i].PhatSinhNo); if (dauky == 0 && cuoiky == 0 && psco == 0 && psno == 0) { soluong++; } else { sdcn[sl] = congnoncc[i]; sl++; } } Entities.CongNo[] sdcn1 = new Entities.CongNo[sl + 1]; for (int i = 0; i < sdcn1.Length; i++) { Entities.TongHopCongNo cn = new Entities.TongHopCongNo(); if (i < sdcn1.Length - 1) { sdcn1[i] = sdcn[i]; } else { sdcn1[i] = congnoncc[congnoncc.ToArray().Length - 1]; } } Entities.TongHopCongNo cn1; congNoList = new List<Entities.TongHopCongNo>(); foreach (Entities.CongNo item in sdcn1) { cn1 = new Entities.TongHopCongNo(); cn1.MaDoiTuong = item.MaDoiTuong; cn1.TenDoiTuong = item.TenDoiTuong; cn1.DiaChi = item.DiaChi; cn1.PhatSinhNo = double.Parse(item.PhatSinhNo); cn1.PhatSinhCo = double.Parse(item.PhatSinhCo); cn1.DuDauKy = double.Parse(item.DuDauKy); cn1.DuCuoiKy = double.Parse(item.DuCuoiKy); if (!string.IsNullOrEmpty(item.MaDoiTuong)) congNoList.Add(cn1); } dtgvcongno.DataSource = sdcn1; fixNCC(); } dtgvcongno.Rows[dtgvcongno.RowCount - 1].DefaultCellStyle.Font = new Font(dtgvcongno.DefaultCellStyle.Font, FontStyle.Bold); } catch { } finally { } }
public void SelectData() { try { bool loaiDoiTuong = false; if (cbbdoituong.SelectedIndex == 0) { loaiDoiTuong = false; } else { loaiDoiTuong = true; } cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi1 = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi1); if (hienthi1 == null) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; tsslthuchien.Enabled = true; return; } year = cbbnam.Text; month = cbbthang.Text; int sotang = 0; bool ktsd = false; Entities.SoDuCongNo[] sq = new Entities.SoDuCongNo[hienthi1.Length]; for (int i = 0; i < sq.Length; i++) { string namkt = hienthi1[i].NgayKetChuyen.Year.ToString(); string thangkt = hienthi1[i].NgayKetChuyen.Month.ToString(); if (namkt == year && thangkt == month && hienthi1[i].LoaiDoiTuong == loaiDoiTuong) { if (hienthi1[i].TrangThai == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; tsslthuchien.Enabled = true; } else { lbtrangthai.Text = "Kỳ này đã khóa"; lbtrangthai.ForeColor = Color.Red; tsslthuchien.Enabled = false; } ma = hienthi1[i].MaSoDuCongNo; sq[sotang] = hienthi1[i]; sotang++; ktsd = true; } } if (ktsd == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; tsslthuchien.Enabled = true; } if (sotang != 0) { hienthi = new Entities.SoDuCongNo[sotang]; for (int i = 0; i < sotang; i++) { hienthi[i] = sq[i]; } } else { hienthi = null; } } catch { } finally { } }
private void dtgvcongno_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { i = e.RowIndex; this.maNCCDELETE0 = dtgvcongno[3, e.RowIndex].Value.ToString(); //string maNCCDELETE2 = dtgvcongno[2, e.RowIndex].Value.ToString(); if (i < 0) { return; } try { string month1 = datesv.Month.ToString(); // kiểm tra tháng hiên tại và tháng được chọn if (month1 != month) { MessageBox.Show("Không phải kỳ hiện tại", "Hệ thống cảnh báo"); return; } cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi); // nếu obj khác null if (hienthi != null) { for (int j = 0; j < hienthi.Length; j++) { string monthkytruoc = (Convert.ToInt32(month) - 1).ToString(); string mm = hienthi[j].NgayKetChuyen.Month.ToString(); // kiểm tra kỳ trước của tháng đang chọn if (mm == monthkytruoc) { MessageBox.Show("Số dư đầu kỳ là kết chuyển từ kỳ trước - không thể thay đổi", "Hệ thống cảnh báo"); SelectData(); return; } } } if (MessageBox.Show("Bạn chắc chắn muốn xóa không?", "Hệ thống cảnh báo", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { // nếu kỳ trc không tồn tại tsslma.Text = dtgvcongno["MaDoiTuong", i].Value.ToString(); tsslten.Text = dtgvcongno["TenDoiTuong", i].Value.ToString(); tssldiachi.Text = dtgvcongno["DiaChi", i].Value.ToString(); tsslsodudauky.Text = dtgvcongno["SoDuDauKy", i].Value.ToString(); sono = Convert.ToDouble(dtgvcongno["SoDuDauKy", i].Value.ToString()); if (dtgvcongno.RowCount >= 1) { if (DeleteCongNo()) { if (cbbdoituong.SelectedIndex == 0) { Entities.KhachHang kh = new Entities.KhachHang("UpdateDuNoKH", tsslma.Text, sono.ToString()); UpdateDuNo(kh); } else { Entities.NhaCungCap kh = new Entities.NhaCungCap("UpdateDuNo", tsslma.Text, sono.ToString()); UpdateDuNoNCC(kh); } } else { MessageBox.Show("Xóa thất bại - xin thử lại sau", "Hệ thống cảnh báo"); return; } } } } catch { } finally { fix(); } }
public void SelectData() { try { bool loaiDoiTuong = false; if (cbbdoituong.SelectedIndex == 0) { loaiDoiTuong = false; } else { loaiDoiTuong = true; } cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi); // nếu null if (hienthi == null) { hienthi = new Entities.SoDuCongNo[0]; lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; toolStrip1.Enabled = dtgvcongno.Enabled = true; return; } year = cbbnam.Text; month = cbbthang.Text; int sotang = 0; bool ktsd = false; Entities.SoDuCongNo[] sq = new Entities.SoDuCongNo[hienthi.Length]; for (int i = 0; i < sq.Length; i++) { string namkt = hienthi[i].NgayKetChuyen.Year.ToString(); string thangkt = hienthi[i].NgayKetChuyen.Month.ToString(); // nếu năm tháng trong bản ghi - năm tháng hiện tại và loại đối tượng if (namkt == year && thangkt == month && hienthi[i].LoaiDoiTuong == loaiDoiTuong) { // nếu trạng thái = false if (hienthi[i].TrangThai == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; toolStrip1.Enabled = dtgvcongno.Enabled = true; } else { lbtrangthai.Text = "Kỳ này đã khóa"; lbtrangthai.ForeColor = Color.Red; toolStrip1.Enabled = dtgvcongno.Enabled = false; } ma = hienthi[i].MaSoDuCongNo; sq[sotang] = hienthi[i]; sotang++; ktsd = true; } } // nếu không có đối tượng nào đúng if (ktsd == false) { lbtrangthai.Text = "Kỳ này chưa đóng"; lbtrangthai.ForeColor = Color.Black; toolStrip1.Enabled = dtgvcongno.Enabled = true; } // nếu không có bản ghi nào tồn tại if (sotang != 0) { hienthi = new Entities.SoDuCongNo[sotang]; for (int i = 0; i < sotang; i++) { hienthi[i] = new Entities.SoDuCongNo("", sq[i].MaDoiTuong, sq[i].TenDoiTuong, sq[i].DiaChi, sq[i].SoDuDauKy); } } else { hienthi = new Entities.SoDuCongNo[0]; dtgvcongno.DataSource = hienthi; return; } dtgvcongno.DataSource = hienthi; new Common.Utilities().CountDatagridview(dtgvcongno); } catch { } finally { fix(); } }
private void toolStripButton1_Click(object sender, EventArgs e) { try { double.Parse(tsslsodudauky.Text); } catch { MessageBox.Show("Số dư đầu kỳ không được nhập ký tự", "Hệ thống cảnh báo"); tsslsodudauky.Focus(); return; } try { // kiểm tra giá trị trong dtgv if (CheckDataGridViewInsert() == true) { string month1 = datesv.Month.ToString(); //nếu tháng hiện tại không = tháng đang xử lý if (month1 != month) { MessageBox.Show("Không phải kỳ hiện tại - xin kiểm tra lại", "Hệ thống cảnh báo"); return; } cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1]; pt[0] = new Entities.SoDuCongNo("Select"); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt); // đổ mảng đối tượng vào datagripview hienthi = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi); // nếu obj khác null if (hienthi != null) { for (int i = 0; i < hienthi.Length; i++) { string monthkytruoc = (Convert.ToInt32(month) - 1).ToString(); string mm = hienthi[i].NgayKetChuyen.Month.ToString(); // kiểm tra kỳ trước có tồn tại số dư hay không if (mm == monthkytruoc && hienthi[i].MaDoiTuong == tsslma.Text) { MessageBox.Show("Số dư đầu kỳ là kết chuyển từ kỳ trước - không thể thay đổi", "Hệ thống cảnh báo"); return; } } } //nếu không tồn tại số dư kỳ trước try { bool loaidt = false; if (cbbdoituong.SelectedIndex == 0) { loaidt = false; } else { loaidt = true; } string masd = ProID("SoDuCongNo"); cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.SoDuCongNo[] pt1 = new Entities.SoDuCongNo[1]; pt1[0] = new Entities.SoDuCongNo("Insert", 0, masd, tsslma.Text, tsslten.Text, tssldiachi.Text, tsslsodudauky.Text, datesv, "0", loaidt, false); // khởi tạo mảng đối tượng để hứng giá trị clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt1); // đổ mảng đối tượng vào datagripview bool kt = false; kt = (bool)cl.DeserializeHepper(clientstrem, kt); if (kt == true) { if (cbbdoituong.SelectedIndex == 0) { Entities.KhachHang kh = new Entities.KhachHang("UpdateDuNo", tsslma.Text, tsslsodudauky.Text); UpdateDuNo(kh); } else { Entities.NhaCungCap kh = new Entities.NhaCungCap("UpdateDuNoNCC", tsslma.Text, tsslsodudauky.Text); UpdateDuNoNCC(kh); } tsslsodudauky.Text = tsslten.Text = tssldiachi.Text = ""; tsslma.Text = "<F4>-Tra cứu"; SelectData(); tsslma.Focus(); } else { MessageBox.Show("Thêm số dư đầu kỳ thất bại - xin thử lại sau", "Hệ thống cảnh báo"); return; } } catch { } } } catch { } }
public Entities.SoDuCongNo[] SoDuCongNo() { Entities.SoDuCongNo[] sodu = new BizLogic.CongNo().Select(); if (sodu == null) sodu = new Entities.SoDuCongNo[0]; return sodu; }