private void tsslbl_Click(object sender, EventArgs e) { string maKH = dgvkhachhang.Rows[i].Cells["MaKH"].Value.ToString(); if (!frmDangNhap.User.Administrator && !CheckQuyen(this.Name, 3)) { MessageBox.Show("Bạn Không có quyền vào chức năng này."); return; } if (new Check().CheckReference("KhachHang", maKH)) { DialogResult dlgResult = MessageBox.Show("Bạn Có Chắc Chắn muốn Xóa Khách Hàng này không?", "Đồng ý?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { try { //bool ktdelete = false; //int idcurent = int.Parse(dgvkhachhang.Rows[i].Cells["KhachHangID"].Value.ToString()); //SelectData(); //for (int j = 0; j < kh1.Length; j++) //{ // if (kh1[j].Deleted == false) // if (kh1[j].KhachHangID == idcurent) // { // ktdelete = true; // break; // } //} //if (ktdelete == true) //{ cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); Entities.KhachHang kh = new Entities.KhachHang(); kh = new Entities.KhachHang("Delete", int.Parse(dgvkhachhang.Rows[i].Cells["KhachHangID"].Value.ToString()), Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstrem = cl.SerializeObj(this.client1, "KhachHang", kh); bool kt = false; kt = (bool)cl.DeserializeHepper(clientstrem, kt); if (kt == true) { } //} else { MessageBox.Show("Khách Hàng này đã bị xóa"); } SelectData(); } catch (Exception ex) { } } } else { MessageBox.Show("khách hàng này không thể xóa! Hiện tại đang có giao dịch"); } }
public Entities.KhachHang[] KhachHang() { Entities.KhachHang[] khachhang = new BizLogic.KhachHang().Select(); if (khachhang == null) { khachhang = new Entities.KhachHang[0]; } return(khachhang); }
public Entities.KhachHangTraLai[] Select() { Entities.KhachHangTraLai[] arrC = null; try { Entities.KhachHang[] kh = new BizLogic.KhachHang().Select(); khtl = new Constants.KhachHangTraLai(); Sql = new Constants.Sql(); string sql = "Select * from KhachHangTraLai where Deleted = 0"; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { khachhangtralai = new Entities.KhachHangTraLai(); khachhangtralai.KhachHangTraLaiID = int.Parse(dr[0].ToString()); khachhangtralai.MaKhachHangTraLai = dr[1].ToString(); khachhangtralai.NgayNhap = Convert.ToDateTime(dr[2].ToString()); khachhangtralai.MaKhachHang = dr[3].ToString(); khachhangtralai.TenKhachHang = ""; foreach (Entities.KhachHang item in kh) { if (item.MaKH == khachhangtralai.MaKhachHang) { khachhangtralai.TenKhachHang = item.Ten; break; } } khachhangtralai.NoHienThoi = dr[4].ToString(); khachhangtralai.NguoiTra = dr[5].ToString(); khachhangtralai.HinhThucThanhToan = dr[6].ToString(); khachhangtralai.HanThanhToan = Convert.ToDateTime(dr[7].ToString()); khachhangtralai.MaHoaDonMuaHang = dr[8].ToString(); khachhangtralai.MaKho = dr[9].ToString(); khachhangtralai.MaTienTe = dr[10].ToString(); khachhangtralai.TienBoiThuong = dr[11].ToString(); khachhangtralai.ThanhToanNgay = dr[12].ToString(); khachhangtralai.ThueGTGT = dr[13].ToString(); khachhangtralai.GhiChu = dr[14].ToString(); khachhangtralai.Deleted = Convert.ToBoolean(dr[15].ToString()); arr.Add(khachhangtralai); } int n = arr.Count; if (n == 0) { arrC = null; } arrC = new Entities.KhachHangTraLai[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.KhachHangTraLai)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); arrC = null; } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return arrC; }
public Entities.KhachHangTraLai[] Select() { Entities.KhachHangTraLai[] arrC = null; try { Entities.KhachHang[] kh = new BizLogic.KhachHang().Select(); khtl = new Constants.KhachHangTraLai(); Sql = new Constants.Sql(); string sql = "Select * from KhachHangTraLai where Deleted = 0"; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { khachhangtralai = new Entities.KhachHangTraLai(); khachhangtralai.KhachHangTraLaiID = int.Parse(dr[0].ToString()); khachhangtralai.MaKhachHangTraLai = dr[1].ToString(); khachhangtralai.NgayNhap = Convert.ToDateTime(dr[2].ToString()); khachhangtralai.MaKhachHang = dr[3].ToString(); khachhangtralai.TenKhachHang = ""; foreach (Entities.KhachHang item in kh) { if (item.MaKH == khachhangtralai.MaKhachHang) { khachhangtralai.TenKhachHang = item.Ten; break; } } khachhangtralai.NoHienThoi = dr[4].ToString(); khachhangtralai.NguoiTra = dr[5].ToString(); khachhangtralai.HinhThucThanhToan = dr[6].ToString(); khachhangtralai.HanThanhToan = Convert.ToDateTime(dr[7].ToString()); khachhangtralai.MaHoaDonMuaHang = dr[8].ToString(); khachhangtralai.MaKho = dr[9].ToString(); khachhangtralai.MaTienTe = dr[10].ToString(); khachhangtralai.TienBoiThuong = dr[11].ToString(); khachhangtralai.ThanhToanNgay = dr[12].ToString(); khachhangtralai.ThueGTGT = dr[13].ToString(); khachhangtralai.GhiChu = dr[14].ToString(); khachhangtralai.Deleted = Convert.ToBoolean(dr[15].ToString()); arr.Add(khachhangtralai); } int n = arr.Count; if (n == 0) { arrC = null; } arrC = new Entities.KhachHangTraLai[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.KhachHangTraLai)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); arrC = null; } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return(arrC); }
/// <summary> /// Khách Hàng /// </summary> /// <param name="clientStream"></param> public void XuLy_KhachHang(NetworkStream clientStream) { Entities.KhachHang kh = (Entities.KhachHang)formatter.Deserialize(clientStream); switch (kh.HanhDong) { case "Insert": { int msg = new BizLogic.KhachHang().InsertUpdate(kh); if (msg == 1) { new BizLogic.LogFile().GhiFile(new Entities.LogFile(kh.MaNhanVien, kh.TenDangNhap, kh.HanhDong, DateTime.Now.ToString(), "Thêm khách hàng: " + kh.MaKH)); } formatter.Serialize(clientStream, msg); break; } case "Update": { int msg = new BizLogic.KhachHang().InsertUpdate(kh); if (msg == 1) { new BizLogic.LogFile().GhiFile(new Entities.LogFile(kh.MaNhanVien, kh.TenDangNhap, kh.HanhDong, DateTime.Now.ToString(), "Sửa khách hàng: " + kh.MaKH)); } formatter.Serialize(clientStream, msg); break; } case "UpdateDuNo": { bool msg = new BizLogic.KhachHang().Update(kh); formatter.Serialize(clientStream, msg); break; } case "UpdateDuNoKH": { bool msg = new BizLogic.KhachHang().UpdateKH(kh); formatter.Serialize(clientStream, msg); break; } case "Delete": { new BizLogic.KhachHang().Delete(kh); bool kt = true; formatter.Serialize(clientStream, kt); break; } case "Select": { Entities.KhachHang[] kh1 = new BizLogic.KhachHang().Select(); formatter.Serialize(clientStream, kh1); break; } case "Search": { Entities.KhachHang[] kh1 = new BizLogic.KhachHang().Select(kh.Cot, kh.Kieu, kh.GiaTri); formatter.Serialize(clientStream, kh1); break; } default: break; } }
/// <summary> /// select dữ liệu từ server /// </summary> public void SelectData() { try { i = 0; dgvkhachhang.RowHeadersVisible = false; 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.KhachHang kh = new Entities.KhachHang(); // truyền HanhDong kh = new Entities.KhachHang("Select"); // khởi tạo mảng đối tượng để hứng giá trị kh1 = new Entities.KhachHang[1]; clientstrem = cl.SerializeObj(this.client1, "KhachHang", kh); // đổ mảng đối tượng vào datagripview kh1 = (Entities.KhachHang[])cl.DeserializeHepper1(clientstrem, kh1); // lbltongs.Text = kh1.Length.ToString(); if (kh1 == null) { tsslbl.Enabled = false; hienthi = new Entities.KhachHang[0]; dgvkhachhang.DataSource = new Entities.KhachHang[0]; return; } tsslbl.Enabled = true; Entities.KhachHang[] pt2 = new Entities.KhachHang[kh1.Length]; int sotang = 0; for (int j = 0; j < kh1.Length; j++) { if (kh1[j].Deleted == false) { pt2[sotang] = kh1[j]; sotang++; } } hienthi = new Entities.KhachHang[sotang]; if (sotang != 0) { for (int j = 0; j < sotang; j++) { hienthi[j] = pt2[j]; } } else { dgvkhachhang.DataSource = new Entities.KhachHang[0]; return; } dgvkhachhang.DataSource = hienthi; new Common.Utilities().CountDatagridview(dgvkhachhang); dgvkhachhang.Rows[0].Selected = true; } finally { try { for (int j = 1; j < dgvkhachhang.ColumnCount; j++) { dgvkhachhang.Columns[j].Visible = false; } //dgvkhachhang.Columns[0].Visible = false; //dgvkhachhang.Columns[1].Visible = false; //dgvkhachhang.Columns[2].Visible = false; //dgvkhachhang.Columns[3].Visible = false; //dgvkhachhang.Columns[4].Visible = false; //dgvkhachhang.Columns[5].Visible = false; //dgvkhachhang.Columns[6].Visible = false; //dgvkhachhang.Columns["NgungTheoDoi"].Visible = false; //dgvkhachhang.Columns["CongTy"].Visible = false; //dgvkhachhang.Columns["DuNo"].Visible = false; //dgvkhachhang.Columns["MST"].Visible = false; //dgvkhachhang.Columns["Fax"].Visible = false; //dgvkhachhang.Columns["Email"].Visible = false; //dgvkhachhang.Columns["HanMucTT"].Visible = false; //dgvkhachhang.Columns["MaVung"].Visible = false; //dgvkhachhang.Columns["Mobi"].Visible = false; //dgvkhachhang.Columns["NgayThamGia"].Visible = false; //dgvkhachhang.Columns["GiaoDichCuoi"].Visible = false; //dgvkhachhang.Columns["NgungTheoDoi"].Visible = false; //dgvkhachhang.Columns["Website"].Visible = false; dgvkhachhang.Columns[0].Visible = true; dgvkhachhang.Columns[0].HeaderText = "STT"; dgvkhachhang.Columns["MaKH"].HeaderText = "Mã Khách Hàng"; dgvkhachhang.Columns["Ten"].HeaderText = "Tên Khách Hàng"; dgvkhachhang.Columns["DiaChi"].HeaderText = "Địa Chỉ"; dgvkhachhang.Columns["DienThoai"].HeaderText = "Điện Thoại"; dgvkhachhang.Columns["MaKH"].Visible = true; dgvkhachhang.Columns["Ten"].Visible = true; dgvkhachhang.Columns["DiaChi"].Visible = true; dgvkhachhang.Columns["DienThoai"].Visible = true; dgvkhachhang.Columns["NgaySinh"].HeaderText = "Ngày Sinh"; dgvkhachhang.Columns["NgaySua"].HeaderText = "Ngày Sửa"; dgvkhachhang.Columns["GhiChu"].HeaderText = "Ghi Chú"; dgvkhachhang.Columns["NgaySinh"].Visible = true; dgvkhachhang.Columns["NgaySua"].Visible = true; dgvkhachhang.Columns["GhiChu"].Visible = true; //dgvkhachhang.Columns["Deleted"].Visible=true; //dgvkhachhang.Columns["Deleted"].HeaderText = "Deleted"; dgvkhachhang.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgvkhachhang.AllowUserToAddRows = false; dgvkhachhang.AllowUserToDeleteRows = false; dgvkhachhang.AllowUserToResizeRows = false; } catch { } } }
private void tsslbl_Click(object sender, EventArgs e) { string maKH = dgvkhachhang.Rows[i].Cells["MaKH"].Value.ToString(); if (!frmDangNhap.User.Administrator && !CheckQuyen(this.Name, 3)) { MessageBox.Show("Bạn Không có quyền vào chức năng này."); return; } if (new Check().CheckReference("KhachHang",maKH)) { DialogResult dlgResult = MessageBox.Show("Bạn Có Chắc Chắn muốn Xóa Khách Hàng này không?", "Đồng ý?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { try { //bool ktdelete = false; //int idcurent = int.Parse(dgvkhachhang.Rows[i].Cells["KhachHangID"].Value.ToString()); //SelectData(); //for (int j = 0; j < kh1.Length; j++) //{ // if (kh1[j].Deleted == false) // if (kh1[j].KhachHangID == idcurent) // { // ktdelete = true; // break; // } //} //if (ktdelete == true) //{ cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); Entities.KhachHang kh = new Entities.KhachHang(); kh = new Entities.KhachHang("Delete", int.Parse(dgvkhachhang.Rows[i].Cells["KhachHangID"].Value.ToString()), Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstrem = cl.SerializeObj(this.client1, "KhachHang", kh); bool kt = false; kt = (bool)cl.DeserializeHepper(clientstrem, kt); if (kt == true) { } //} else { MessageBox.Show("Khách Hàng này đã bị xóa"); } SelectData(); } catch (Exception ex) { } } } else { MessageBox.Show("khách hàng này không thể xóa! Hiện tại đang có giao dịch"); } }
/// <summary> /// select dữ liệu từ server /// </summary> public void SelectData() { try { i = 0; dgvkhachhang.RowHeadersVisible = false; 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.KhachHang kh = new Entities.KhachHang(); // truyền HanhDong kh = new Entities.KhachHang("Select"); // khởi tạo mảng đối tượng để hứng giá trị kh1 = new Entities.KhachHang[1]; clientstrem = cl.SerializeObj(this.client1, "KhachHang", kh); // đổ mảng đối tượng vào datagripview kh1 = (Entities.KhachHang[])cl.DeserializeHepper1(clientstrem, kh1); // lbltongs.Text = kh1.Length.ToString(); if (kh1 == null) { tsslbl.Enabled = false; hienthi = new Entities.KhachHang[0]; dgvkhachhang.DataSource = new Entities.KhachHang[0]; return; } tsslbl.Enabled = true; Entities.KhachHang[] pt2 = new Entities.KhachHang[kh1.Length]; int sotang = 0; for (int j = 0; j < kh1.Length; j++) { if (kh1[j].Deleted == false) { pt2[sotang] = kh1[j]; sotang++; } } hienthi = new Entities.KhachHang[sotang]; if (sotang != 0) { for (int j = 0; j < sotang; j++) { hienthi[j] = pt2[j]; } } else { dgvkhachhang.DataSource = new Entities.KhachHang[0]; return; } dgvkhachhang.DataSource = hienthi; new Common.Utilities().CountDatagridview(dgvkhachhang); dgvkhachhang.Rows[0].Selected = true; } finally { try { for (int j = 1; j < dgvkhachhang.ColumnCount; j++) { dgvkhachhang.Columns[j].Visible = false; } //dgvkhachhang.Columns[0].Visible = false; //dgvkhachhang.Columns[1].Visible = false; //dgvkhachhang.Columns[2].Visible = false; //dgvkhachhang.Columns[3].Visible = false; //dgvkhachhang.Columns[4].Visible = false; //dgvkhachhang.Columns[5].Visible = false; //dgvkhachhang.Columns[6].Visible = false; //dgvkhachhang.Columns["NgungTheoDoi"].Visible = false; //dgvkhachhang.Columns["CongTy"].Visible = false; //dgvkhachhang.Columns["DuNo"].Visible = false; //dgvkhachhang.Columns["MST"].Visible = false; //dgvkhachhang.Columns["Fax"].Visible = false; //dgvkhachhang.Columns["Email"].Visible = false; //dgvkhachhang.Columns["HanMucTT"].Visible = false; //dgvkhachhang.Columns["MaVung"].Visible = false; //dgvkhachhang.Columns["Mobi"].Visible = false; //dgvkhachhang.Columns["NgayThamGia"].Visible = false; //dgvkhachhang.Columns["GiaoDichCuoi"].Visible = false; //dgvkhachhang.Columns["NgungTheoDoi"].Visible = false; //dgvkhachhang.Columns["Website"].Visible = false; dgvkhachhang.Columns[0].Visible = true; dgvkhachhang.Columns[0].HeaderText = "STT"; dgvkhachhang.Columns["MaKH"].HeaderText = "Mã Khách Hàng"; dgvkhachhang.Columns["Ten"].HeaderText = "Tên Khách Hàng"; dgvkhachhang.Columns["DiaChi"].HeaderText = "Địa Chỉ"; dgvkhachhang.Columns["DienThoai"].HeaderText = "Điện Thoại"; dgvkhachhang.Columns["MaKH"].Visible = true; dgvkhachhang.Columns["Ten"].Visible = true; dgvkhachhang.Columns["DiaChi"].Visible = true; dgvkhachhang.Columns["DienThoai"].Visible = true; dgvkhachhang.Columns["NgaySinh"].HeaderText = "Ngày Sinh"; dgvkhachhang.Columns["NgaySua"].HeaderText = "Ngày Sửa"; dgvkhachhang.Columns["GhiChu"].HeaderText = "Ghi Chú"; dgvkhachhang.Columns["NgaySinh"].Visible = true; dgvkhachhang.Columns["NgaySua"].Visible = true; dgvkhachhang.Columns["GhiChu"].Visible = true; //dgvkhachhang.Columns["Deleted"].Visible=true; //dgvkhachhang.Columns["Deleted"].HeaderText = "Deleted"; dgvkhachhang.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgvkhachhang.AllowUserToAddRows = false; dgvkhachhang.AllowUserToDeleteRows = false; dgvkhachhang.AllowUserToResizeRows = false; } catch { } } }
public Entities.KhachHang[] KhachHang() { Entities.KhachHang[] khachhang = new BizLogic.KhachHang().Select(); if (khachhang == null) khachhang = new Entities.KhachHang[0]; return khachhang; }