srvfunction.asmx.cs

来自「人物传记/成功经验人物传记/成功经验人物传记/成功经验人物传记/成功经验人物传记」· CS 代码 · 共 130 行

CS
130
字号
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;

namespace SkyiSite.WebServices
{
    /// <summary>
    /// SrvFunction 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class SrvFunction : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        SkyiSite.DB.AdoHelper ado = SkyiSite.DB.AdoHelper.Instance;

        [WebMethod]
        public string GetMzTVForUser(string UserID)
        {
            string sql = "Select RoleID from dbo.aspnet_UsersInRoles where UserID='" + UserID + "'";
            string RoleID = ado.ExecuteScalar(sql).ToString();
            return GetMzTVForUser(UserID, RoleID);
        }
        [WebMethod]
        public string GetMzTVForUserName(string UserName)
        {
            string sql = "Select UserID from aspnet_Users where UserName='"+UserName+"'";
            string obj = ado.ExecuteScalar(sql).ToString();
            return GetMzTVForUser(obj);
        }
        [WebMethod]
        public string GetMzTVForUser(string UserID, string RoleID)
        {
            DataTable table = GetUserFun(UserID, GetRoleFun(RoleID));
            string node = "";
            foreach (DataRow row in table.Rows)
            {
                node += "\r\n     tree.nodes[" + "\"" + row["parentID"].ToString() + "_" + row["funID"].ToString() + "\"" + "] = ";
                node +=  "\"" + "text:" + row["funName"].ToString() + ";" + "\"";
            }
            if (table != null) table.Dispose();
            return node;
        }
        [WebMethod]
        public string GetMzTVForRoleName(string RoleName)
        {
            string sql = "Select RoleID from aspnet_Roles where RoleName='"+RoleName+"'";
            string RoleID = ado.ExecuteScalar(sql).ToString();
            return GetMzTVForRole(RoleID);
        }
        [WebMethod]
        public string GetMzTVForRole(string RoleID)
        {
            string node = "";
            DataTable table = GetRoleFun(RoleID);
            foreach (DataRow row in table.Rows)
            {
                node += "\r\n     tree.nodes[" + "\"" + row["parentID"].ToString() + "_" + row["funID"].ToString() + "\"" + "] = ";
                node +=  "\"" + "text:" + row["funName"].ToString() + ";" + "\"";
            }
            if (table != null) table.Dispose();
            return node;
        }

        #region SQL语句
        /*
         SELECT SY_Function.funID, SY_Function.funName, SY_Function.parentID
FROM SY_Function INNER JOIN
      SY_FunctionInRole ON SY_Function.funID = SY_FunctionInRole.funID
WHERE (SY_FunctionInRole.RoleID = '1567460d-50f6-4cb9-ba9c-78012747e201')
ORDER BY SY_Function.parentID, SY_Function.sequence
         */

        /*
         SELECT SY_Function.funID, SY_Function.funName, SY_Function.parentID, 
      SY_FunctionInUser.IsOwn
FROM SY_Function INNER JOIN
      SY_FunctionInUser ON SY_Function.funID = SY_FunctionInUser.funID
WHERE (SY_FunctionInUser.UserID = '730d19c8-1ce0-4737-ad26-89747b042f87')
ORDER BY SY_Function.parentID, SY_Function.sequence
         */
        #endregion

        private DataTable GetRoleFun(string RoleID)
        {
            string sql = "SELECT SY_Function.funID, SY_Function.funName, SY_Function.parentID FROM SY_Function INNER JOIN SY_FunctionInRole ON SY_Function.funID = SY_FunctionInRole.funID WHERE (SY_FunctionInRole.RoleID = '" + RoleID + "') ORDER BY SY_Function.parentID, SY_Function.sequence";
            return ado.ExecuteDataset(sql).Tables[0];
        }
        private DataTable GetUserFun(string UserID, DataTable table)
        {
            string sql = "SELECT SY_Function.funID, SY_Function.funName, SY_Function.parentID,SY_FunctionInUser.IsOwn FROM SY_Function INNER JOIN SY_FunctionInUser ON SY_Function.funID = SY_FunctionInUser.funID WHERE (SY_FunctionInUser.UserID = '" + UserID + "') ORDER BY SY_Function.parentID, SY_Function.sequence";
            DataTable newtable = ado.ExecuteDataset(sql).Tables[0];
            if (newtable == null) return table;
            if (newtable.Rows.Count > 0)
            {
                foreach (DataRow row in newtable.Rows)
                {
                    if (Convert.ToBoolean(row["IsOwn"].ToString()))
                    {
                        if (table.Select("funID=" + row["funID"].ToString()).Length == 0)
                        {
                            DataRow r = table.NewRow();
                            r["funID"] = row["funID"];
                            r["funName"] = row["funName"];
                            r["parentID"] = row["parentID"];
                            table.Rows.Add(r);
                        }
                    }
                    else
                    {
                        table.Select("funID=" + row["funID"].ToString())[0].Delete();
                    }
                }
            }
            newtable.Dispose();
            return table;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?