/// <summary> /// 添加一项菜单 /// </summary> /// <param name="menu">菜单实体</param> /// <returns>1:添加成功;0:添加失败</returns> public int Add(SYS_MenuEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Sys_Menu("); strSql.Append("MenuID,MenuName,MenuUrl,FunctionID,IsLeaf,MenuLevel,RootID,ParentsID,DisplayOrder,IcValue,IsPop,MenuSeq)"); strSql.Append(" values ("); strSql.Append("@MenuID,@MenuName,@MenuUrl,@FunctionID,@IsLeaf,@MenuLevel,@RootID,@ParentsID,@DisplayOrder,@IcValue,@IsPop,@MenuSeq)"); SqlParameter[] parameters = { new SqlParameter("@MenuID", SqlDbType.NVarChar, 20), new SqlParameter("@MenuName", SqlDbType.NVarChar, 50), new SqlParameter("@MenuUrl", SqlDbType.VarChar, 300), new SqlParameter("@FunctionID", SqlDbType.NVarChar, 100), new SqlParameter("@IsLeaf", SqlDbType.VarChar, 1), new SqlParameter("@MenuLevel", SqlDbType.VarChar, 1), new SqlParameter("@RootID", SqlDbType.VarChar, 32), new SqlParameter("@ParentsID", SqlDbType.VarChar, 32), new SqlParameter("@DisplayOrder", SqlDbType.Decimal, 5), new SqlParameter("@IcValue", SqlDbType.VarChar, 200), new SqlParameter("@IsPop", SqlDbType.VarChar, 1), new SqlParameter("@MenuSeq", SqlDbType.VarChar, 300) }; parameters[0].Value = model.MenuID; parameters[1].Value = model.MenuName; parameters[2].Value = model.MenuUrl; parameters[3].Value = model.FunctionID; parameters[4].Value = model.IsLeaf; parameters[5].Value = model.MenuLevel; parameters[6].Value = model.RootID; parameters[7].Value = model.ParentsID; parameters[8].Value = model.DisplayOrder; parameters[9].Value = model.IcValue; parameters[10].Value = model.IsPop; parameters[11].Value = model.MenuSeq; return(DbHelperSQL.ExecuteSql(strSql.ToString(), parameters)); }
/// <summary> /// 更新一项菜单 /// </summary> /// <param name="menu">菜单实体</param> /// <returns>1:添加成功;0:添加失败</returns> public int Update(SYS_MenuEntity menu) { return(dal.Update(menu)); }
/// <summary> /// 添加一项菜单 /// </summary> /// <param name="menu">菜单实体</param> /// <returns>1:添加成功;0:添加失败</returns> public int Add(SYS_MenuEntity menu) { return(dal.Add(menu)); }
/// <summary> /// 更新一项菜单 /// </summary> /// <param name="menu">菜单实体</param> /// <returns>1:添加成功;0:添加失败</returns> public int Update(SYS_MenuEntity menu) { try { string originalMenuSEQ = GetParentSEQ(menu.MenuID).TrimEnd(menu.MenuID.ToCharArray()); #region Update the menuSEQ StringBuilder sb = new StringBuilder(); sb.AppendFormat("update SYS_MENU set menuSEQ='{0}'", menu.MenuID.TrimEnd(menu.MenuID.ToCharArray())); sb.AppendFormat("+replace(menuSEQ,'{0}','')", originalMenuSEQ); sb.AppendFormat(" where menuSEQ like '{0}%'", originalMenuSEQ + menu.MenuID); DbHelperSQL.ExecuteSql(sb.ToString()); #endregion Update the menuSEQ StringBuilder sbLevel = new StringBuilder(); sbLevel.Append("update SYS_MENU set menuLevel = len(menuSEQ)-len(replace(menuSEQ,'.' , ''))"); sbLevel.AppendFormat(" where menuSEQ like '{0}%'", originalMenuSEQ + menu.MenuID); DbHelperSQL.ExecuteSql(sbLevel.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("update Sys_Menu set "); strSql.Append("MenuName=@MenuName,"); strSql.Append("MenuUrl=@MenuUrl,"); strSql.Append("FunctionID=@FunctionID,"); strSql.Append("IsLeaf=@IsLeaf,"); strSql.Append("MenuLevel=@MenuLevel,"); strSql.Append("RootID=@RootID,"); strSql.Append("ParentsID=@ParentsID,"); strSql.Append("DisplayOrder=@DisplayOrder,"); strSql.Append("IcValue=@IcValue,"); strSql.Append("IsPop=@IsPop,"); strSql.Append("MenuSeq=@MenuSeq"); strSql.Append(" where MenuID=@MenuID "); SqlParameter[] parameters = { new SqlParameter("@MenuID", SqlDbType.NVarChar, 20), new SqlParameter("@MenuName", SqlDbType.NVarChar, 50), new SqlParameter("@MenuUrl", SqlDbType.VarChar, 300), new SqlParameter("@FunctionID", SqlDbType.NVarChar, 100), new SqlParameter("@IsLeaf", SqlDbType.VarChar, 1), new SqlParameter("@MenuLevel", SqlDbType.VarChar, 1), new SqlParameter("@RootID", SqlDbType.VarChar, 32), new SqlParameter("@ParentsID", SqlDbType.VarChar, 32), new SqlParameter("@DisplayOrder", SqlDbType.Decimal, 5), new SqlParameter("@IcValue", SqlDbType.VarChar, 200), new SqlParameter("@IsPop", SqlDbType.VarChar, 1), new SqlParameter("@MenuSeq", SqlDbType.VarChar, 300) }; parameters[0].Value = menu.MenuID; parameters[1].Value = menu.MenuName; parameters[2].Value = menu.MenuUrl; parameters[3].Value = menu.FunctionID; parameters[4].Value = menu.IsLeaf; parameters[5].Value = menu.MenuLevel; parameters[6].Value = menu.RootID; parameters[7].Value = menu.ParentsID; parameters[8].Value = menu.DisplayOrder; parameters[9].Value = menu.IcValue; parameters[10].Value = menu.IsPop; parameters[11].Value = menu.MenuSeq; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); return(1); } catch { return(0); } }