/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebApi_Model.T_Product_Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Product_Category set "); strSql.Append("Leave=@Leave,"); strSql.Append("ParentID=@ParentID,"); strSql.Append("CategoryName=@CategoryName,"); strSql.Append("CategoryICO=@CategoryICO"); strSql.Append(" where CategoryID=@CategoryID"); SqlParameter[] parameters = { new SqlParameter("@Leave", SqlDbType.Int, 4), new SqlParameter("@ParentID", SqlDbType.Int, 4), new SqlParameter("@CategoryName", SqlDbType.NVarChar, 50), new SqlParameter("@CategoryICO", SqlDbType.NVarChar, 50), new SqlParameter("@CategoryID", SqlDbType.Int, 4) }; parameters[0].Value = model.Leave; parameters[1].Value = model.ParentID; parameters[2].Value = model.CategoryName; parameters[3].Value = model.CategoryICO; parameters[4].Value = model.CategoryID; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Product_Category DataRowToModel(DataRow row) { WebApi_Model.T_Product_Category model = new WebApi_Model.T_Product_Category(); if (row != null) { if (row["CategoryID"] != null && row["CategoryID"].ToString() != "") { model.CategoryID = int.Parse(row["CategoryID"].ToString()); } if (row["Leave"] != null && row["Leave"].ToString() != "") { model.Leave = int.Parse(row["Leave"].ToString()); } if (row["ParentID"] != null && row["ParentID"].ToString() != "") { model.ParentID = int.Parse(row["ParentID"].ToString()); } if (row["CategoryName"] != null) { model.CategoryName = row["CategoryName"].ToString(); } if (row["CategoryICO"] != null) { model.CategoryICO = row["CategoryICO"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebApi_Model.T_Product_Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Product_Category("); strSql.Append("Leave,ParentID,CategoryName,CategoryICO)"); strSql.Append(" values ("); strSql.Append("@Leave,@ParentID,@CategoryName,@CategoryICO)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Leave", SqlDbType.Int, 4), new SqlParameter("@ParentID", SqlDbType.Int, 4), new SqlParameter("@CategoryName", SqlDbType.NVarChar, 50), new SqlParameter("@CategoryICO", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Leave; parameters[1].Value = model.ParentID; parameters[2].Value = model.CategoryName; parameters[3].Value = model.CategoryICO; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Product_Category GetModel(int CategoryID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CategoryID,Leave,ParentID,CategoryName,CategoryICO from T_Product_Category "); strSql.Append(" where CategoryID=@CategoryID"); SqlParameter[] parameters = { new SqlParameter("@CategoryID", SqlDbType.Int, 4) }; parameters[0].Value = CategoryID; WebApi_Model.T_Product_Category model = new WebApi_Model.T_Product_Category(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }