/// <summary> /// select dữ liệu từ server /// </summary> public void SelectData() { Entities.HangHoaHienThi[] hhht = new Entities.HangHoaHienThi[0]; try { i = 0; 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.ChiTietXuatHuy ctxh = new Entities.ChiTietXuatHuy("Select", sochungtu); // khởi tạo mảng đối tượng để hứng giá trị pt1 = new Entities.ChiTietXuatHuy[1]; clientstrem = cl.SerializeObj(this.client1, "ChiTietXuatHuy", ctxh); // đổ mảng đối tượng vào datagripview pt1 = (Entities.ChiTietXuatHuy[])cl.DeserializeHepper1(clientstrem, pt1); if (pt1 == null) { dtgvsanpham.DataSource = new Entities.HangHoaHienThi[0]; return; } Entities.ChiTietXuatHuy[] pt2 = new Entities.ChiTietXuatHuy[pt1.Length]; int sotang = 0; for (int j = 0; j < pt1.Length; j++) { if (pt1[j].Deleted == false) { if (pt1[j].MaPhieuXuatHuy == sochungtu) { pt2[sotang] = pt1[j]; sotang++; } } } hhht = new Entities.HangHoaHienThi[sotang]; if (sotang != 0) { SelectHangHoa(); for (int j = 0; j < sotang; j++) { string tongtien = (Convert.ToDouble(LayGiaSanPham(pt2[j].MaHangHoa)) * Convert.ToDouble(pt2[j].SoLuong.ToString())).ToString(); hhht[j] = new Entities.HangHoaHienThi(pt2[j].MaPhieuXuatHuy, pt2[j].MaHangHoa, LayTenSanPham(pt2[j].MaHangHoa), new TienIch().FormatMoney(LayGiaSanPham(pt2[j].MaHangHoa)), pt2[j].SoLuong.ToString(), new TienIch().FormatMoney(tongtien)); } } else { dtgvsanpham.DataSource = new Entities.HangHoaHienThi[0]; return; } dtgvsanpham.DataSource = hhht; dtgvsanpham.Rows[0].Selected = true; } catch { } finally { try { fix(); } catch { } } }
public void XuLyDGV() { if (i < 0) return; try { if (dtgvsanpham.RowCount > 1) { mahanghoa = toolStrip_txtTracuu.Text = dtgvsanpham["MaHangHoa", i].Value.ToString(); tssltenhang.Text = dtgvsanpham["TenHang", i].Value.ToString(); tsslgia.Text = dtgvsanpham["DonGia", i].Value.ToString(); tsslsoluong.Text = dtgvsanpham["SoLuong", i].Value.ToString(); tsslthanhtien.Text = dtgvsanpham["ChietKhau", i].Value.ToString(); hh = new Entities.HangHoaHienThi[dtgvsanpham.RowCount - 1]; int so = 0; for (int j = 0; j < dtgvsanpham.RowCount; j++) { if (dtgvsanpham[1, j].Value.ToString() != dtgvsanpham[1, i].Value.ToString()) { hh[so] = new Entities.HangHoaHienThi(txtsochungtu.Text, dtgvsanpham[1, j].Value.ToString(), dtgvsanpham[2, j].Value.ToString(), dtgvsanpham[3, j].Value.ToString(), dtgvsanpham[4, j].Value.ToString(), dtgvsanpham[5, j].Value.ToString()); so++; } } dtgvsanpham.DataSource = hh; } else { mahanghoa = toolStrip_txtTracuu.Text = dtgvsanpham["MaHangHoa", i].Value.ToString(); tssltenhang.Text = dtgvsanpham["TenHang", i].Value.ToString(); tsslgia.Text = dtgvsanpham["DonGia", i].Value.ToString(); tsslsoluong.Text = dtgvsanpham["SoLuong", i].Value.ToString(); tsslthanhtien.Text = dtgvsanpham["ChietKhau", i].Value.ToString(); txttongtien.Text = "0"; dtgvsanpham.DataSource = new Entities.HangHoaHienThi[0]; return; } txttongtien.Text = String.Format("{0:0,0}", Convert.ToDouble(TinhTien(dtgvsanpham))); } catch (Exception ex) { } finally { try { fix(); } catch { } } }
/// <summary> /// method xử lý thêm row /// </summary> public void NewRow() { try { int sohangtrongbang = dtgvsanpham.RowCount; if (dtgvsanpham.RowCount != 0) { for (int j = 0; j < dtgvsanpham.RowCount; j++) { if (mahanghoa == dtgvsanpham[1, j].Value.ToString()) { hh = new Entities.HangHoaHienThi[sohangtrongbang]; break; } else hh = new Entities.HangHoaHienThi[sohangtrongbang + 1]; } } else hh = new Entities.HangHoaHienThi[sohangtrongbang + 1]; if (hh.Length != 0) { try { QuyDoi(toolStrip_txtTracuu.Text.ToUpper()); } catch { } try { string kt1 = ""; if (hh.Length == dtgvsanpham.RowCount) { for (int j = 0; j < hh.Length; j++) { if (mahanghoa == dtgvsanpham[1, j].Value.ToString()) { int soluongcu = Convert.ToInt32(dtgvsanpham[4, j].Value.ToString()); string soluong = "0"; if (tsslsoluong.Text == "") soluong = "0"; else soluong = tsslsoluong.Text; int soluongmoi = Convert.ToInt32(soluong); int soluonghientai = soluongcu + soluongmoi; string tongtien = (Convert.ToDouble(soluonghientai.ToString()) * Convert.ToDouble(dtgvsanpham[3, j].Value.ToString())).ToString(); hh[j] = new Entities.HangHoaHienThi(txtsochungtu.Text, dtgvsanpham[1, j].Value.ToString(), dtgvsanpham[2, j].Value.ToString(), dtgvsanpham[3, j].Value.ToString(), soluonghientai.ToString(), tongtien); kt1 = "ok"; } else hh[j] = new Entities.HangHoaHienThi(txtsochungtu.Text, dtgvsanpham[1, j].Value.ToString(), dtgvsanpham[2, j].Value.ToString(), dtgvsanpham[3, j].Value.ToString(), dtgvsanpham[4, j].Value.ToString(), dtgvsanpham[5, j].Value.ToString()); } } else { for (int j = 0; j < hh.Length; j++) { if (j < hh.Length - 1) hh[j] = new Entities.HangHoaHienThi(txtsochungtu.Text, dtgvsanpham[1, j].Value.ToString(), dtgvsanpham[2, j].Value.ToString(), dtgvsanpham[3, j].Value.ToString(), dtgvsanpham[4, j].Value.ToString(), dtgvsanpham[5, j].Value.ToString()); else hh[hh.Length - 1] = new Entities.HangHoaHienThi(txtsochungtu.Text, mahanghoa, tssltenhang.Text, tsslgia.Text, tsslsoluong.Text, tsslthanhtien.Text); } } if (kt1 == "") hh[hh.Length - 1] = new Entities.HangHoaHienThi(txtsochungtu.Text, mahanghoa, tssltenhang.Text, tsslgia.Text, tsslsoluong.Text, tsslthanhtien.Text); } catch (Exception ex) { hh[0] = new Entities.HangHoaHienThi(txtsochungtu.Text, mahanghoa, tssltenhang.Text, tsslgia.Text, tsslsoluong.Text, tsslthanhtien.Text); } dtgvsanpham.DataSource = hh; } } catch (Exception ex) { } finally { try { for (int i = 0; i < dtgvsanpham.ColumnCount; i++) { dtgvsanpham.Columns[i].Visible = false; } dtgvsanpham.ReadOnly = true; dtgvsanpham.RowHeadersVisible = false; dtgvsanpham.Columns["MaHangHoa"].Visible = true; dtgvsanpham.Columns["TenHang"].Visible = true; dtgvsanpham.Columns["DonGia"].Visible = true; dtgvsanpham.Columns["SoLuong"].Visible = true; dtgvsanpham.Columns["ChietKhau"].Visible = true; dtgvsanpham.Columns["MaHangHoa"].HeaderText = "Mã Hàng Hóa"; dtgvsanpham.Columns["TenHang"].HeaderText = "Tên Hàng"; dtgvsanpham.Columns["DonGia"].HeaderText = "Đơn Giá"; dtgvsanpham.Columns["SoLuong"].HeaderText = "Số Lượng"; dtgvsanpham.Columns["ChietKhau"].HeaderText = "Tổng Tiền"; dtgvsanpham.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dtgvsanpham.AllowUserToAddRows = false; dtgvsanpham.AllowUserToDeleteRows = false; dtgvsanpham.AllowUserToResizeRows = false; toolStrip_txtTracuu.Text = "<F4 - Tra Cứu>"; tssltenhang.Text = ""; tsslgia.Text = "0"; tsslsoluong.Text = ""; tsslthanhtien.Text = "0"; txttongtien.Text = String.Format("{0:0,0}", Convert.ToDouble(TinhTien(dtgvsanpham))); } catch { } } }