Example #1
0
    private static void CopyNode(XmlNode srcNode, XmlNode tgtNode)
    {
        string DefaultWebServer = MyConfig.GetWebConfig("webipaddr", "localhost");

        foreach (XmlNode subNode in srcNode.ChildNodes)
        {
            if (subNode.Name != "siteMapNode")
            {
                continue;                                //只处理siteMapNode结点
            }
            XmlNode newNode = MyXml.AddXmlNode(tgtNode, subNode.Name);
            foreach (XmlAttribute attr in subNode.Attributes)
            {
                switch (attr.Name.ToLower())
                {
                case "url":
                case "title":
                case "right":
                case "icon":
                case "style":     //菜单样式 1,2,3
                    //以上结点可以被传向客户端,可以扩充

                    //url内容可以进行字符串替换
                    string value = attr.Value;
                    if (attr.Name.ToLower().Equals("url"))
                    {
                        value = value.Replace("[webipaddr]", DefaultWebServer);
                    }
                    MyXml.AddAttribute(newNode, attr.Name, value);
                    break;
                }
            }
            CopyNode(subNode, newNode);
        }
    }
Example #2
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    protected override XmlDocument CreateInitInfo()
    {
        //删除过期设备
        //ReturnValue retVal = uegLogic.DeleteExpire(new UserEquipmentGrantInfo() { EndDate = DateTime.Now });
        //if (retVal.IsSuccess == false) { return MyXml.CreateResultXml(-1, "删除过期授权设备时异常", string.Empty); }

        XmlDocument xmlDoc   = MyXml.CreateResultXml(1, string.Empty, string.Empty);
        XmlNode     rootNode = xmlDoc.SelectSingleNode("xml");

        XmlNode userNode               = MyXml.AddXmlNode(rootNode, "users");
        XmlNode equipmentsNode         = MyXml.AddXmlNode(rootNode, "equipments");
        XmlNode grantequipmentsNode    = MyXml.AddXmlNode(rootNode, "grantequipments");
        XmlNode notgrantequipmentsNode = MyXml.AddXmlNode(rootNode, "notgrantequipments");
        //用户对象
        ReturnValue retVal = userLogic.GetUser(new UserInfo()
        {
            UserID = -1
        });

        if (retVal.IsSuccess == false)
        {
            return(MyXml.CreateResultXml(-1, "加载用户时异常", string.Empty));
        }
        {//排序
            DataView dv = retVal.RetDt.DefaultView;
            dv.Sort      = "username";
            retVal.RetDt = dv.ToTable();
        }
        foreach (DataRow dr in retVal.RetDt.Rows)
        {
            XmlNode itemNode = MyXml.AddXmlNode(userNode, "item");
            MyXml.AddAttribute(itemNode, "key", dr["userid"]);
            MyXml.AddAttribute(itemNode, "name", string.Format("{0}【{1}】", dr["username"], dr["usernick"]));
        }

        //设备对象
        retVal = equLogic.GetEquipment(new EquipmentInfo()
        {
            EIID = -1
        });
        if (retVal.IsSuccess == false)
        {
            return(MyXml.CreateResultXml(-1, "加载设备时异常", string.Empty));
        }
        {//排序
            DataView dv = retVal.RetDt.DefaultView;
            dv.Sort      = "einame";
            retVal.RetDt = dv.ToTable();
        }
        foreach (DataRow dr in retVal.RetDt.Rows)
        {
            XmlNode itemNode = MyXml.AddXmlNode(equipmentsNode, "item");
            MyXml.AddAttribute(itemNode, "key", dr["eiid"]);
            MyXml.AddAttribute(itemNode, "name", dr["einame"]);
        }

        //未授权设备对象
        retVal = equLogic.GetNotGrantEquipment(new EquipmentInfo()
        {
            EIID = -1
        });
        if (retVal.IsSuccess == false)
        {
            return(MyXml.CreateResultXml(-1, "加载未授权设备时异常", string.Empty));
        }
        {//排序
            DataView dv = retVal.RetDt.DefaultView;
            dv.Sort      = "einame";
            retVal.RetDt = dv.ToTable();
        }
        foreach (DataRow dr in retVal.RetDt.Rows)
        {
            XmlNode itemNode = MyXml.AddXmlNode(notgrantequipmentsNode, "item");
            MyXml.AddAttribute(itemNode, "key", dr["eiid"]);
            MyXml.AddAttribute(itemNode, "name", dr["einame"]);
        }

        //昂前登录用户授权设备对象
        retVal = uegLogic.GetUserEquGrant(new UserEquipmentGrantInfo()
        {
            UserID = Tools.GetInt32(IPApi.UserID, int.MaxValue)
        });
        if (retVal.IsSuccess == false)
        {
            return(MyXml.CreateResultXml(-1, "加载未授权设备时异常", string.Empty));
        }
        {//排序
            DataView dv = retVal.RetDt.DefaultView;
            dv.Sort      = "einame";
            retVal.RetDt = dv.ToTable();
        }
        foreach (DataRow dr in retVal.RetDt.Rows)
        {
            XmlNode itemNode = MyXml.AddXmlNode(grantequipmentsNode, "item");
            MyXml.AddAttribute(itemNode, "key", dr["eiid"]);
            MyXml.AddAttribute(itemNode, "name", dr["einame"]);
        }

        return(xmlDoc);
    }