/// <summary> /// 更新一条数据 /// </summary> public bool Update(GoodsTypeModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Info_Category set "); strSql.Append("CategoryName=@CategoryName,"); strSql.Append("CategoryLevel=@CategoryLevel,"); strSql.Append("PCategoryId=@PCategoryId,"); strSql.Append("CategoryPath=@CategoryPath,"); strSql.Append("RootId=@RootId,"); strSql.Append("CategoryToTypeId=@CategoryToTypeId,"); strSql.Append("CategoryFlag=@CategoryFlag,"); strSql.Append("Orderby=@Orderby,"); strSql.Append("Remarks=@Remarks,"); strSql.Append("Url=@Url,"); strSql.Append("icon=@icon"); strSql.Append(" where CategoryId=@CategoryId "); SqlParameter[] parameters = { new SqlParameter("@CategoryName", SqlDbType.VarChar, 50), new SqlParameter("@CategoryLevel", SqlDbType.Int, 4), new SqlParameter("@PCategoryId", SqlDbType.VarChar, 50), new SqlParameter("@CategoryPath", SqlDbType.VarChar, 50), new SqlParameter("@RootId", SqlDbType.VarChar, 50), new SqlParameter("@CategoryToTypeId", SqlDbType.VarChar, 50), new SqlParameter("@CategoryFlag", SqlDbType.VarChar, 50), new SqlParameter("@Orderby", SqlDbType.Int, 4), new SqlParameter("@Remarks", SqlDbType.VarChar, 500), new SqlParameter("@Url", SqlDbType.VarChar, 500), new SqlParameter("@icon", SqlDbType.VarChar, 500), new SqlParameter("@CategoryId", SqlDbType.VarChar, 50) }; parameters[0].Value = model.CategoryName; parameters[1].Value = model.CategoryLevel; parameters[2].Value = model.PCategoryId; parameters[3].Value = model.CategoryPath; parameters[4].Value = model.RootId; parameters[5].Value = model.CategoryToTypeId; parameters[6].Value = model.CategoryFlag; parameters[7].Value = model.Orderby; parameters[8].Value = model.Remarks; parameters[9].Value = model.Url; parameters[10].Value = model.icon; parameters[11].Value = model.CategoryId; int rows = adoHelper.ExecuteSqlNonQuery(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(GoodsTypeModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Info_Category("); strSql.Append("CategoryId,CategoryName,CategoryLevel,PCategoryId,CategoryPath,RootId,CategoryToTypeId,CategoryFlag,Orderby,Remarks,Url,icon)"); strSql.Append(" values ("); strSql.Append("@CategoryId,@CategoryName,@CategoryLevel,@PCategoryId,@CategoryPath,@RootId,@CategoryToTypeId,@CategoryFlag,@Orderby,@Remarks,@Url,@icon)"); SqlParameter[] parameters = { new SqlParameter("@CategoryId", SqlDbType.VarChar, 50), new SqlParameter("@CategoryName", SqlDbType.VarChar, 50), new SqlParameter("@CategoryLevel", SqlDbType.Int, 4), new SqlParameter("@PCategoryId", SqlDbType.VarChar, 50), new SqlParameter("@CategoryPath", SqlDbType.VarChar, 50), new SqlParameter("@RootId", SqlDbType.VarChar, 50), new SqlParameter("@CategoryToTypeId", SqlDbType.VarChar, 50), new SqlParameter("@CategoryFlag", SqlDbType.VarChar, 50), new SqlParameter("@Orderby", SqlDbType.Int, 4), new SqlParameter("@Remarks", SqlDbType.VarChar, 500), new SqlParameter("@Url", SqlDbType.VarChar, 500), new SqlParameter("@icon", SqlDbType.VarChar, 500) }; parameters[0].Value = model.CategoryId; parameters[1].Value = model.CategoryName; parameters[2].Value = model.CategoryLevel; parameters[3].Value = model.PCategoryId; parameters[4].Value = model.CategoryPath; parameters[5].Value = model.RootId; parameters[6].Value = model.CategoryToTypeId; parameters[7].Value = model.CategoryFlag; parameters[8].Value = model.Orderby; parameters[9].Value = model.Remarks; parameters[10].Value = model.Url; parameters[11].Value = model.icon; adoHelper.ExecuteSqlNonQuery(strSql.ToString(), parameters); }
/// <summary> /// 获得数据列表 /// </summary> public List <GoodsTypeModel> DataTableToList(DataTable dt) { List <GoodsTypeModel> modelList = new List <GoodsTypeModel>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { GoodsTypeModel model; for (int n = 0; n < rowsCount; n++) { model = new GoodsTypeModel(); if (dt.Rows[n]["CategoryId"] != null && dt.Rows[n]["CategoryId"].ToString() != "") { model.CategoryId = dt.Rows[n]["CategoryId"].ToString(); } if (dt.Rows[n]["CategoryName"] != null && dt.Rows[n]["CategoryName"].ToString() != "") { model.CategoryName = dt.Rows[n]["CategoryName"].ToString(); } if (dt.Rows[n]["CategoryLevel"] != null && dt.Rows[n]["CategoryLevel"].ToString() != "") { model.CategoryLevel = int.Parse(dt.Rows[n]["CategoryLevel"].ToString()); } if (dt.Rows[n]["PCategoryId"] != null && dt.Rows[n]["PCategoryId"].ToString() != "") { model.PCategoryId = dt.Rows[n]["PCategoryId"].ToString(); } if (dt.Rows[n]["CategoryPath"] != null && dt.Rows[n]["CategoryPath"].ToString() != "") { model.CategoryPath = dt.Rows[n]["CategoryPath"].ToString(); } if (dt.Rows[n]["RootId"] != null && dt.Rows[n]["RootId"].ToString() != "") { model.RootId = dt.Rows[n]["RootId"].ToString(); } if (dt.Rows[n]["CategoryToTypeId"] != null && dt.Rows[n]["CategoryToTypeId"].ToString() != "") { model.CategoryToTypeId = dt.Rows[n]["CategoryToTypeId"].ToString(); } if (dt.Rows[n]["CategoryFlag"] != null && dt.Rows[n]["CategoryFlag"].ToString() != "") { model.CategoryFlag = dt.Rows[n]["CategoryFlag"].ToString(); } if (dt.Rows[n]["Orderby"] != null && dt.Rows[n]["Orderby"].ToString() != "") { model.Orderby = int.Parse(dt.Rows[n]["Orderby"].ToString()); } if (dt.Rows[n]["Remarks"] != null && dt.Rows[n]["Remarks"].ToString() != "") { model.Remarks = dt.Rows[n]["Remarks"].ToString(); } if (dt.Rows[n]["Url"] != null && dt.Rows[n]["Url"].ToString() != "") { model.Url = dt.Rows[n]["Url"].ToString(); } if (dt.Rows[n]["icon"] != null && dt.Rows[n]["icon"].ToString() != "") { model.icon = dt.Rows[n]["icon"].ToString(); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(GoodsTypeModel model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public void Add(GoodsTypeModel model) { dal.Add(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public GoodsTypeModel GetModel(string CategoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CategoryId,CategoryName,CategoryLevel,PCategoryId,CategoryPath,RootId,CategoryToTypeId,CategoryFlag,Orderby,Remarks,Url,icon from T_Info_Category "); strSql.Append(" where CategoryId=@CategoryId "); SqlParameter[] parameters = { new SqlParameter("@CategoryId", SqlDbType.VarChar, 50) }; parameters[0].Value = CategoryId; GoodsTypeModel model = new GoodsTypeModel(); DataSet ds = adoHelper.ExecuteSqlDataset(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CategoryId"] != null && ds.Tables[0].Rows[0]["CategoryId"].ToString() != "") { model.CategoryId = ds.Tables[0].Rows[0]["CategoryId"].ToString(); } if (ds.Tables[0].Rows[0]["CategoryName"] != null && ds.Tables[0].Rows[0]["CategoryName"].ToString() != "") { model.CategoryName = ds.Tables[0].Rows[0]["CategoryName"].ToString(); } if (ds.Tables[0].Rows[0]["CategoryLevel"] != null && ds.Tables[0].Rows[0]["CategoryLevel"].ToString() != "") { model.CategoryLevel = int.Parse(ds.Tables[0].Rows[0]["CategoryLevel"].ToString()); } if (ds.Tables[0].Rows[0]["PCategoryId"] != null && ds.Tables[0].Rows[0]["PCategoryId"].ToString() != "") { model.PCategoryId = ds.Tables[0].Rows[0]["PCategoryId"].ToString(); } if (ds.Tables[0].Rows[0]["CategoryPath"] != null && ds.Tables[0].Rows[0]["CategoryPath"].ToString() != "") { model.CategoryPath = ds.Tables[0].Rows[0]["CategoryPath"].ToString(); } if (ds.Tables[0].Rows[0]["RootId"] != null && ds.Tables[0].Rows[0]["RootId"].ToString() != "") { model.RootId = ds.Tables[0].Rows[0]["RootId"].ToString(); } if (ds.Tables[0].Rows[0]["CategoryToTypeId"] != null && ds.Tables[0].Rows[0]["CategoryToTypeId"].ToString() != "") { model.CategoryToTypeId = ds.Tables[0].Rows[0]["CategoryToTypeId"].ToString(); } if (ds.Tables[0].Rows[0]["CategoryFlag"] != null && ds.Tables[0].Rows[0]["CategoryFlag"].ToString() != "") { model.CategoryFlag = ds.Tables[0].Rows[0]["CategoryFlag"].ToString(); } if (ds.Tables[0].Rows[0]["Orderby"] != null && ds.Tables[0].Rows[0]["Orderby"].ToString() != "") { model.Orderby = int.Parse(ds.Tables[0].Rows[0]["Orderby"].ToString()); } if (ds.Tables[0].Rows[0]["Remarks"] != null && ds.Tables[0].Rows[0]["Remarks"].ToString() != "") { model.Remarks = ds.Tables[0].Rows[0]["Remarks"].ToString(); } if (ds.Tables[0].Rows[0]["Url"] != null && ds.Tables[0].Rows[0]["Url"].ToString() != "") { model.Url = ds.Tables[0].Rows[0]["Url"].ToString(); } if (ds.Tables[0].Rows[0]["icon"] != null && ds.Tables[0].Rows[0]["icon"].ToString() != "") { model.icon = ds.Tables[0].Rows[0]["icon"].ToString(); } return(model); } else { return(null); } }