/// <summary> /// 更新一条数据 /// </summary> public bool Update(Leadin.Model.PublicVersion model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_PublicVersion set "); strSql.Append("NumId=@NumId,"); strSql.Append("NameInfo=@NameInfo,"); strSql.Append("Num=@Num,"); strSql.Append("ImgUrl=@ImgUrl,"); strSql.Append("SortNum=@SortNum,"); strSql.Append("StateInfo=@StateInfo,"); strSql.Append("Remark=@Remark,CustomerId=@CustomerId"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@NumId", SqlDbType.NVarChar, 100), new SqlParameter("@NameInfo", SqlDbType.NVarChar, 100), new SqlParameter("@Num", SqlDbType.Int, 4), new SqlParameter("@ImgUrl", SqlDbType.NVarChar, 200), new SqlParameter("@SortNum", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.NText), new SqlParameter("@CustomerId", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.NumId; parameters[1].Value = model.NameInfo; parameters[2].Value = model.Num; parameters[3].Value = model.ImgUrl; parameters[4].Value = model.SortNum; parameters[5].Value = model.StateInfo; parameters[6].Value = model.Remark; parameters[7].Value = model.CustomerId; parameters[8].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.PublicVersion DataRowToModel(DataRow row) { Leadin.Model.PublicVersion model = new Leadin.Model.PublicVersion(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["NumId"] != null) { model.NumId = row["NumId"].ToString(); } if (row["NameInfo"] != null) { model.NameInfo = row["NameInfo"].ToString(); } if (row["Num"] != null && row["Num"].ToString() != "") { model.Num = int.Parse(row["Num"].ToString()); } if (row["ImgUrl"] != null) { model.ImgUrl = row["ImgUrl"].ToString(); } if (row["SortNum"] != null && row["SortNum"].ToString() != "") { model.SortNum = int.Parse(row["SortNum"].ToString()); } if (row["StateInfo"] != null && row["StateInfo"].ToString() != "") { model.StateInfo = int.Parse(row["StateInfo"].ToString()); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } if (row["CustomerId"] != null && row["CustomerId"].ToString() != "") { model.CustomerId = int.Parse(row["CustomerId"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Leadin.Model.PublicVersion model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_PublicVersion("); strSql.Append("NumId,NameInfo,Num,ImgUrl,SortNum,StateInfo,Remark,CustomerId)"); strSql.Append(" values ("); strSql.Append("@NumId,@NameInfo,@Num,@ImgUrl,@SortNum,@StateInfo,@Remark,@CustomerId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@NumId", SqlDbType.NVarChar, 100), new SqlParameter("@NameInfo", SqlDbType.NVarChar, 100), new SqlParameter("@Num", SqlDbType.Int, 4), new SqlParameter("@ImgUrl", SqlDbType.NVarChar, 200), new SqlParameter("@SortNum", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.NText), new SqlParameter("@CustomerId",SqlDbType.Int, 4) }; parameters[0].Value = model.NumId; parameters[1].Value = model.NameInfo; parameters[2].Value = model.Num; parameters[3].Value = model.ImgUrl; parameters[4].Value = model.SortNum; parameters[5].Value = model.StateInfo; parameters[6].Value = model.Remark; parameters[7].Value = model.CustomerId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.PublicVersion GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,NumId,NameInfo,Num,ImgUrl,SortNum,StateInfo,Remark,CustomerId from tb_PublicVersion "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Leadin.Model.PublicVersion model = new Leadin.Model.PublicVersion(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }