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