/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.c_user_address DataRowToModel(DataRow row) { Cms.Model.c_user_address model = new Cms.Model.c_user_address(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["user_id"] != null && row["user_id"].ToString() != "") { model.user_id = int.Parse(row["user_id"].ToString()); } if (row["consignee"] != null) { model.consignee = row["consignee"].ToString(); } if (row["cellphone"] != null) { model.cellphone = row["cellphone"].ToString(); } if (row["code"] != null) { model.code = row["code"].ToString(); } if (row["location"] != null) { model.location = row["location"].ToString(); } if (row["city"] != null) { model.city = row["city"].ToString(); } if (row["county"] != null) { model.county = row["county"].ToString(); } if (row["street"] != null) { model.street = row["street"].ToString(); } if (row["address"] != null) { model.address = row["address"].ToString(); } if (row["is_default"] != null && row["is_default"].ToString() != "") { model.is_default = int.Parse(row["is_default"].ToString()); } if (row["updateTime"] != null && row["updateTime"].ToString() != "") { model.updateTime = DateTime.Parse(row["updateTime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Cms.Model.c_user_address model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update c_user_address set "); strSql.Append("user_id=@user_id,"); strSql.Append("consignee=@consignee,"); strSql.Append("cellphone=@cellphone,"); strSql.Append("code=@code,"); strSql.Append("location=@location,"); strSql.Append("city=@city,"); strSql.Append("county=@county,"); strSql.Append("street=@street,"); strSql.Append("address=@address,"); strSql.Append("is_default=@is_default,"); strSql.Append("updateTime=@updateTime"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@consignee", SqlDbType.VarChar, 150), new SqlParameter("@cellphone", SqlDbType.VarChar, 150), new SqlParameter("@code", SqlDbType.VarChar, 150), new SqlParameter("@location", SqlDbType.VarChar, 350), new SqlParameter("@city", SqlDbType.VarChar, 350), new SqlParameter("@county", SqlDbType.VarChar, 350), new SqlParameter("@street", SqlDbType.VarChar, 350), new SqlParameter("@address", SqlDbType.VarChar, 350), new SqlParameter("@is_default", SqlDbType.Int, 4), new SqlParameter("@updateTime", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.user_id; parameters[1].Value = model.consignee; parameters[2].Value = model.cellphone; parameters[3].Value = model.code; parameters[4].Value = model.location; parameters[5].Value = model.city; parameters[6].Value = model.county; parameters[7].Value = model.street; parameters[8].Value = model.address; parameters[9].Value = model.is_default; parameters[10].Value = model.updateTime; parameters[11].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Cms.Model.c_user_address model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into c_user_address("); strSql.Append("user_id,consignee,cellphone,code,location,city,county,street,address,is_default,updateTime)"); strSql.Append(" values ("); strSql.Append("@user_id,@consignee,@cellphone,@code,@location,@city,@county,@street,@address,@is_default,@updateTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@consignee", SqlDbType.VarChar, 150), new SqlParameter("@cellphone", SqlDbType.VarChar, 150), new SqlParameter("@code", SqlDbType.VarChar, 150), new SqlParameter("@location", SqlDbType.VarChar, 350), new SqlParameter("@city", SqlDbType.VarChar, 350), new SqlParameter("@county", SqlDbType.VarChar, 350), new SqlParameter("@street", SqlDbType.VarChar, 350), new SqlParameter("@address", SqlDbType.VarChar, 350), new SqlParameter("@is_default", SqlDbType.Int, 4), new SqlParameter("@updateTime", SqlDbType.DateTime) }; parameters[0].Value = model.user_id; parameters[1].Value = model.consignee; parameters[2].Value = model.cellphone; parameters[3].Value = model.code; parameters[4].Value = model.location; parameters[5].Value = model.city; parameters[6].Value = model.county; parameters[7].Value = model.street; parameters[8].Value = model.address; parameters[9].Value = model.is_default; parameters[10].Value = model.updateTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.c_user_address GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,user_id,consignee,cellphone,code,location,city,county,street,address,is_default,updateTime from c_user_address "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Cms.Model.c_user_address model = new Cms.Model.c_user_address(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }