//insert update public Entities.KhoHang InsertUpdate(Entities.KhoHang kh1) { Entities.KhoHang k = new Entities.KhoHang(); try { kh = new Constants.KhoHang(); Sql = new Constants.Sql(); string sql = Sql.InsertUpdateKhoHang; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(kh.HanhDong, SqlDbType.NVarChar, 20).Value = kh1.HanhDong; cmd.Parameters.Add(kh.KhoHangID, SqlDbType.Int).Value = kh1.KhoHangID; cmd.Parameters.Add(kh.MaKho, SqlDbType.VarChar, 20).Value = kh1.MaKho; cmd.Parameters.Add(kh.TenKho, SqlDbType.NVarChar, 200).Value = kh1.TenKho; cmd.Parameters.Add(kh.DiaChi, SqlDbType.NVarChar, 200).Value = kh1.DiaChi; cmd.Parameters.Add(kh.DienThoai, SqlDbType.NVarChar, 200).Value = kh1.DienThoai; cmd.Parameters.Add(kh.MaNhanVien, SqlDbType.NVarChar, 200).Value = kh1.MaNhanVien; cmd.Parameters.Add(kh.GhiChu, SqlDbType.NVarChar, 100).Value = kh1.GhiChu; cmd.Parameters.Add(kh.Deleted, SqlDbType.Bit).Value = kh1.Deleted; dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { k.GhiChu = dr[0].ToString(); } } catch (Exception ex) { string s = ex.Message.ToString(); k.GhiChu = null; } return(k); }
/// <summary> /// lay thong tin cac kho hang /// </summary> /// <returns></returns> public Entities.KhoHang[] sp_SelectKhoHangsAll() { List <Entities.KhoHang> L = new List <Entities.KhoHang>(); try { kh = new Constants.KhoHang(); cn = new Connection().openConnection(); cmd = new SqlCommand("exec sp_SelectKhoHangsAll", cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { khohang = new Entities.KhoHang(); khohang.MaKho = dr[kh.MaKho].ToString(); khohang.TenKho = dr[kh.TenKho].ToString(); khohang.DiaChi = dr[kh.DiaChi].ToString(); khohang.DienThoai = dr[kh.DienThoai].ToString(); khohang.MaNhanVien = dr[kh.MaNhanVien].ToString(); khohang.GhiChu = dr[kh.GhiChu].ToString(); L.Add(khohang); } } catch { return(null); } finally { cmd.Connection.Dispose(); cn.Close(); } return(L.ToArray()); }
//delete public int Delete(Entities.KhoHang kh1) { int tra = 0; try { kh = new Constants.KhoHang(); Entities.KhoHang khohang = new Entities.KhoHang(); Sql = new Constants.Sql(); string sql = Sql.DeleteKhoHang; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(kh.HanhDong, SqlDbType.NVarChar, 20).Value = kh1.HanhDong; cmd.Parameters.Add(kh.KhoHangID, SqlDbType.Int).Value = kh1.KhoHangID; tra = cmd.ExecuteNonQuery(); cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; } catch (Exception ex) { string s = ex.Message; tra = 0; } return(tra); }
public KhoHang() { kh = null; Sql = null; conn = null; cmd = null; arr = null; dr = null; khohang = null; cn = null; }