コード例 #1
0
ファイル: IoConfig.xaml.cs プロジェクト: rcw0125/-
        /// <summary>
        /// 读取设备集合(Type数值:设备类型:1;设备:2)
        /// </summary>
        private void GetEquTypeAndEquTree()
        {
            string         equJsonStr     = JesonOperateHelper.ReadJesonFile("EquList.json");
            string         equTypeJsonStr = JesonOperateHelper.ReadJesonFile("EquTypeList.json");
            List <Equ>     equList        = JsonConvert.DeserializeObject(equJsonStr, typeof(List <Equ>)) as List <Equ>;
            List <EquType> equTypeList    = JsonConvert.DeserializeObject(equTypeJsonStr, typeof(List <EquType>)) as List <EquType>;
            var            rootTypes      = (from r in equTypeList where string.IsNullOrEmpty(r.ParentId) select r).ToList();

            if (rootTypes.Count > 0)
            {
                EquType         rootType = rootTypes.First();//获取根节点
                ComBoxTreeModel rootNode = new ComBoxTreeModel()
                {
                    Id = rootType.Id, Code = rootType.Code, Type = IoConfigParam.Type_EquType, Name = rootType.Name
                };
                #region 加载设备信息
                var             equs = equList.Where(p => p.EquTypeId == rootType.Id).ToList();
                ComBoxTreeModel etemp;
                foreach (var equ in equs)
                {
                    etemp = new ComBoxTreeModel()
                    {
                        Id     = equ.Id,
                        Code   = equ.Code,
                        Name   = equ.Name,
                        Type   = IoConfigParam.Type_Equ,
                        Parent = rootNode
                    };
                    rootNode.Child.Add(etemp);
                }
                #endregion
                InitTreeObjects(rootNode, rootType.Child, equList);
                var             list      = from r in rootNode.Child select new TreeNode().Parse(r, () => r.Name, () => r.Child);
                List <TreeNode> final     = new List <TreeNode>();
                TreeNode        rootNode1 = new TreeNode(rootNode.Name, list)
                {
                    Target = new ComBoxTreeModel()
                    {
                        Child = rootNode.Child, Id = rootNode.Id, Code = rootNode.Code, Name = rootNode.Name, Type = rootNode.Type, Parent = rootNode.Parent
                    }
                };
                final.Add(rootNode1);
                comboBoxItemSource = CovertToTree.CovertObjToTree(final, ref comboBoxTreeList);
            }
        }
コード例 #2
0
        /// <summary>
        /// 生成设备json文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateEquJesonFile_Click(object sender, RoutedEventArgs e)
        {
            IList <EquType> equTypes = new List <EquType>();
            EquType         rootType = new EquType()
            {
                Id = "01", Code = "EquType", Name = "设备类型"
            };
            EquType dType = new EquType()
            {
                Id = "0101", Code = "Led", Name = "灯", ParentId = "01"
            };
            //EquType hdType = new EquType() { Id = "010101", Code = "RedLed", Name = "红灯", ParentId = "0101" };
            //EquType ldType = new EquType() { Id = "010102", Code = "GreenLed", Name = "绿灯", ParentId = "0101" };
            EquType hwType = new EquType()
            {
                Id = "0102", Code = "InfraredCorrelation", Name = "红外对射", ParentId = "01"
            };

            //dType.Child.Add(hdType);
            //dType.Child.Add(ldType);
            rootType.Child.Add(dType);
            rootType.Child.Add(hwType);
            equTypes.Add(rootType);
            string equTypeJsonStr = JsonConvert.SerializeObject(equTypes);

            IList <Equ> equs = new List <Equ>();
            Equ         zhd  = new Equ()
            {
                EquTypeId = "0101", Name = "左红绿灯", Id = "1", Code = "LeftLed"
            };
            Equ yhd = new Equ()
            {
                EquTypeId = "0101", Name = "右红绿灯", Id = "2", Code = "RightLed"
            };
            //Equ zhd = new Equ() { EquTypeId = "010101", Name = "左红灯", Id = "1", Code = "LeftRedLed" };
            //Equ yhd = new Equ() { EquTypeId = "010101", Name = "右红灯", Id = "2", Code = "RightRedLed" };
            //Equ zld = new Equ() { EquTypeId = "010102", Name = "左绿灯", Id = "3", Code = "LeftGreenLed" };
            //Equ yld = new Equ() { EquTypeId = "010102", Name = "右绿灯", Id = "4", Code = "RightGreenLed" };
            Equ zhw = new Equ()
            {
                EquTypeId = "0102", Name = "左红外", Id = "3", Code = "LeftInfraredCorrelation"
            };
            Equ yhw = new Equ()
            {
                EquTypeId = "0102", Name = "右红外", Id = "4", Code = "RightInfraredCorrelation"
            };
            Equ qhw = new Equ()
            {
                EquTypeId = "0102", Name = "前红外", Id = "5", Code = "AheadInfraredCorrelation"
            };
            Equ hhw = new Equ()
            {
                EquTypeId = "0102", Name = "后红外", Id = "6", Code = "BehindInfraredCorrelation"
            };

            equs.Add(zhd);
            equs.Add(yhd);
            //equs.Add(zld);
            //equs.Add(yld);
            equs.Add(zhw);
            equs.Add(yhw);
            equs.Add(qhw);
            equs.Add(hhw);
            string equJsonStr = JsonConvert.SerializeObject(equs);

            JesonOperateHelper.WriteJesonFile("EquTypeList.json", equTypeJsonStr);
            JesonOperateHelper.WriteJesonFile("EquList.json", equJsonStr);
        }