//delete public bool Delete(Entities.NhomHang NhomHang) { bool kt = false; try { nhh = new Constants.NhomHangHoa(); Entities.NhomHang nhomhanghoa = new Entities.NhomHang(); Sql = new Constants.Sql(); string sql = Sql.DeleteNhomHangHoa; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(nhh.HanhDong, SqlDbType.NVarChar, 20).Value = NhomHang.HanhDong; cmd.Parameters.Add(nhh.NhomHangID, SqlDbType.Int).Value = NhomHang.NhomHangID; int i = cmd.ExecuteNonQuery(); if (i == 1) kt = true; else kt = false; cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; return kt; } catch { return kt; } }
public NhomHang() { nhh = null; Sql = null; conn = null; cmd = null; arr = null; dr = null; nhomhanghoa = null; cn = null; }
//Entities public Entities.NhomHang[] sp_SelectNhomHangsAll() { SelectLH(); Entities.NhomHang[] arrC = null; try { nhh = new Constants.NhomHangHoa(); Sql = new Constants.Sql(); string sql = Sql.SelectAllNhomHangHoa; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { nhomhanghoa = new Entities.NhomHang(); nhomhanghoa.NhomHangID = Convert.ToInt32(dr[nhh.NhomHangID].ToString()); nhomhanghoa.MaNhomHang = dr[nhh.MaNhomHang].ToString(); nhomhanghoa.MaLoaiHang = dr[nhh.MaLoaiHang].ToString(); nhomhanghoa.TenLoaiHang = TimTenLoaiHH(nhomhanghoa.MaLoaiHang); nhomhanghoa.TenNhomHang = dr[nhh.TenNhomHang].ToString(); nhomhanghoa.GhiChu = dr[nhh.GhiChu].ToString(); nhomhanghoa.Deleted = (Boolean)dr[nhh.Deleted]; arr.Add(nhomhanghoa); } int n = arr.Count; if (n == 0) { return(null); } arrC = new Entities.NhomHang[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.NhomHang)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return(arrC); }
//insert update public bool InsertUpdate(Entities.NhomHang nh) { bool kt = false; try { nhh = new Constants.NhomHangHoa(); Sql = new Constants.Sql(); string sql = Sql.InsertUpdateNhomHangHoa; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(nhh.HanhDong, SqlDbType.NVarChar, 20).Value = nh.HanhDong; cmd.Parameters.Add(nhh.NhomHangID, SqlDbType.Int).Value = nh.NhomHangID; cmd.Parameters.Add(nhh.MaNhomHang, SqlDbType.VarChar, 20).Value = nh.MaNhomHang; cmd.Parameters.Add(nhh.MaLoaiHang, SqlDbType.VarChar, 20).Value = nh.MaLoaiHang; cmd.Parameters.Add(nhh.TenNhomHang, SqlDbType.NVarChar, 200).Value = nh.TenNhomHang; cmd.Parameters.Add(nhh.GhiChu, SqlDbType.NVarChar, 100).Value = nh.GhiChu; cmd.Parameters.Add(nhh.Deleted, SqlDbType.Bit).Value = nh.Deleted; int i = cmd.ExecuteNonQuery(); if (i == 1) { kt = true; } else { kt = false; } cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; return(kt); } catch { return(kt); } }
//delete public bool Delete(Entities.NhomHang NhomHang) { bool kt = false; try { nhh = new Constants.NhomHangHoa(); Entities.NhomHang nhomhanghoa = new Entities.NhomHang(); Sql = new Constants.Sql(); string sql = Sql.DeleteNhomHangHoa; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(nhh.HanhDong, SqlDbType.NVarChar, 20).Value = NhomHang.HanhDong; cmd.Parameters.Add(nhh.NhomHangID, SqlDbType.Int).Value = NhomHang.NhomHangID; int i = cmd.ExecuteNonQuery(); if (i == 1) { kt = true; } else { kt = false; } cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; return(kt); } catch { return(kt); } }
public void LayNhomHang() { try { cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); Entities.NhomHang ctxh = new Entities.NhomHang("Select"); clientstrem = cl.SerializeObj(this.client1, "NhomHang", ctxh); NhomHang = (Entities.NhomHang[])cl.DeserializeHepper1(clientstrem, NhomHang); if (NhomHang == null) { NhomHang = new Entities.NhomHang[0]; return; } } catch { } }
//Entities public Entities.NhomHang[] sp_SelectNhomHangsAll() { SelectLH(); Entities.NhomHang[] arrC = null; try { nhh = new Constants.NhomHangHoa(); Sql = new Constants.Sql(); string sql = Sql.SelectAllNhomHangHoa; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { nhomhanghoa = new Entities.NhomHang(); nhomhanghoa.NhomHangID = Convert.ToInt32(dr[nhh.NhomHangID].ToString()); nhomhanghoa.MaNhomHang = dr[nhh.MaNhomHang].ToString(); nhomhanghoa.MaLoaiHang = dr[nhh.MaLoaiHang].ToString(); nhomhanghoa.TenLoaiHang = TimTenLoaiHH(nhomhanghoa.MaLoaiHang); nhomhanghoa.TenNhomHang = dr[nhh.TenNhomHang].ToString(); nhomhanghoa.GhiChu = dr[nhh.GhiChu].ToString(); nhomhanghoa.Deleted = (Boolean)dr[nhh.Deleted]; arr.Add(nhomhanghoa); } int n = arr.Count; if (n == 0) { return null; } arrC = new Entities.NhomHang[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.NhomHang)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return arrC; }
public int cbbLoaiHangHoa_sua(string maNH) { client = new Server_Client.Client(); this.tcpClient = client.Connect(Luu.IP, Luu.Ports); Entities.NhomHang nh1 = new Entities.NhomHang(); nh1 = new Entities.NhomHang("Select"); networkStream = client.SerializeObj(this.tcpClient, "NhomHang", nh1); Entities.NhomHang[] nh = new Entities.NhomHang[1]; nh = (Entities.NhomHang[])client.DeserializeHepper1(networkStream, nh); string maloaihang = ""; if (nh != null) { for (int i = 0; i < nh.Length; i++) { if (nh[i].MaNhomHang == maNH) { maloaihang = nh[i].MaLoaiHang; break; } } Entities.LoaiHangHoa[] pb = (Entities.LoaiHangHoa[])cbbLoaiHangHoa.DataSource; if (pb == null) return -1; for (int i = 0; i < pb.Length; i++) { if (pb[i].MaLoaiHang == maloaihang) { return i; } } return -1; } return -1; }
//Lấy Mã Nhóm Hàng Hóa public void LayMaNhomHangHoa(string maLH) { try { cmbMaNhomHangHoa.DataSource = null; client = new Server_Client.Client(); this.tcpClient = client.Connect(Luu.IP, Luu.Ports); Entities.NhomHang nh = new Entities.NhomHang(); nh = new Entities.NhomHang("Select"); networkStream = client.SerializeObj(this.tcpClient, "NhomHang", nh); Entities.NhomHang[] nh1 = new Entities.NhomHang[1]; nh1 = (Entities.NhomHang[])client.DeserializeHepper1(networkStream, nh1); if (nh1 != null) { int count = 0; for (int i = 0; i < nh1.Length; i++) { if (nh1[i].MaLoaiHang == maLH) { count++; } } Entities.NhomHang[] nhomhang = new Entities.NhomHang[count]; count = 0; for (int i = 0; i < nh1.Length; i++) { if (nh1[i].MaLoaiHang == maLH) { nhomhang[count] = nh1[i]; count++; } } cmbMaNhomHangHoa.DataSource = nhomhang; cmbMaNhomHangHoa.DisplayMember = "TenNhomHang"; } } catch { } }