Exemple #1
0
        private void GetDeviceTreeJsonByListNew(int pId, int level)
        {
            var deepth = 0;
            // var objectlist = dal.GetBaseLayerObjectList("", " order by LayerObjectDeepth desc,LayerObjectID");
            var objectlist = dal.GetBaseLayerObjectList("", " order by   LayerObjectID");

            if (objectlist.Count > 0)
            {
                //deepth = objectlist[0].LayerObjectDeepth;
                deepth = level;
            }
            Dictionary <int, string> cacheLayer = NTS.WEB.Common.CacheHelper.GetCache("object-Layer") as Dictionary <int, string>;

            if (cacheLayer == null)
            {
                var res = new NTS.WEB.BLL.LayerObjects().GetObjectLayers();
                NTS.WEB.Common.CacheHelper.SetCache("object-Layer", res);
                cacheLayer = res;
            }
            deviceresult.Append(devicesb.ToString());
            devicesb.Clear();
            if (tabel.Count > 0)
            {
                devicesb.Append("[");

                var rows = (from l in tabel where l.pid.Equals(pId) select l).ToList <NTS.WEB.Model.Tree>();
                if (rows.Count > 0)
                {
                    foreach (var row in rows)
                    {
                        devicesb.Append("{\"id\":" + row.id + ",\"text\":\"" + row.name + "\",\"state\":\"open\",\"iconCls\":\"\"");
                        var childrows = (from l in tabel where l.pid.Equals(row.id) select l).ToList <NTS.WEB.Model.Tree>();
                        if (childrows.Count > 0)
                        {
                            var deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and areaid=" + row.id, " order by deviceid");
                            // if (deviceList.Count > 0 && 4 == level) //&& row.deepth==4
                            //if (deviceList.Count > 0 && cacheLayer.Count == level)
                            //{
                            //    devicesb.Append(",\"hasChildren\":true");
                            //}
                            //else
                            //{
                            //    devicesb.Append(",\"hasChildren\":false");
                            //}
                            devicesb.Append(",\"children\":");
                            GetDeviceTreeJsonByListNew(row.id, level + 1);
                            deviceresult.Append(devicesb.ToString());
                            devicesb.Clear();
                        }
                        else
                        {
                            var deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and areaid=" + row.id, " order by deviceid");
                            //if (deviceList.Count > 0 && 4 == level)
                            //if (deviceList.Count > 0 && cacheLayer.Count == level)
                            //{
                            //    devicesb.Append(",\"hasChildren\":true");
                            //}
                            //else
                            //{
                            //    devicesb.Append(",\"hasChildren\":false");
                            //}
                            devicesb.Append(",\"children\":");
                            GetDeviceTreeJsonByList(row.id, level + 1);
                            deviceresult.Append(devicesb.ToString());
                            devicesb.Clear();
                        }
                        deviceresult.Append(devicesb.ToString());
                        devicesb.Clear();
                        devicesb.Append("},");
                    }
                    devicesb = devicesb.Remove(devicesb.Length - 1, 1);
                }
                devicesb.Append("]");
                deviceresult.Append(devicesb.ToString());
                devicesb.Clear();
            }
        }
Exemple #2
0
        private void GetDeviceTreeJsonByListNew(int pId, int level)
        {
            var deepth = 0;
            // var objectlist = dal.GetBaseLayerObjectList("", " order by LayerObjectDeepth desc,LayerObjectID");
            var objectlist = dal.GetBaseLayerObjectList("", " order by   LayerObjectID");
            if (objectlist.Count > 0)
            {
                //deepth = objectlist[0].LayerObjectDeepth;
                deepth = level;
            }
            Dictionary<int, string> cacheLayer = NTS.WEB.Common.CacheHelper.GetCache("object-Layer") as Dictionary<int, string>;
            if (cacheLayer == null)
            {
                var res = new NTS.WEB.BLL.LayerObjects().GetObjectLayers();
                NTS.WEB.Common.CacheHelper.SetCache("object-Layer", res);
                cacheLayer = res;
            }
            deviceresult.Append(devicesb.ToString());
            devicesb.Clear();
            if (tabel.Count > 0)
            {
                devicesb.Append("[");

                var rows = (from l in tabel where l.pid.Equals(pId) select l).ToList<Tree>();
                if (rows.Count > 0)
                {
                    foreach (var row in rows)
                    {
                        devicesb.Append("{\"id\":" + row.id + ",\"text\":\"" + row.name + "\",\"state\":\"open\",\"iconCls\":\"\"");
                        var childrows = (from l in tabel where l.pid.Equals(row.id) select l).ToList<Tree>();
                        if (childrows.Count > 0)
                        {
                            var deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and areaid=" + row.id, " order by deviceid");
                            // if (deviceList.Count > 0 && 4 == level) //&& row.deepth==4
                            //if (deviceList.Count > 0 && cacheLayer.Count == level)
                            //{
                            //    devicesb.Append(",\"hasChildren\":true");
                            //}
                            //else
                            //{
                            //    devicesb.Append(",\"hasChildren\":false");
                            //}
                            devicesb.Append(",\"children\":");
                            GetDeviceTreeJsonByListNew(row.id, level + 1);
                            deviceresult.Append(devicesb.ToString());
                            devicesb.Clear();
                        }
                        else
                        {
                            var deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and areaid=" + row.id, " order by deviceid");
                            //if (deviceList.Count > 0 && 4 == level)
                            //if (deviceList.Count > 0 && cacheLayer.Count == level)
                            //{
                            //    devicesb.Append(",\"hasChildren\":true");
                            //}
                            //else
                            //{
                            //    devicesb.Append(",\"hasChildren\":false");
                            //}
                            devicesb.Append(",\"children\":");
                            GetDeviceTreeJsonByList(row.id, level + 1);
                            deviceresult.Append(devicesb.ToString());
                            devicesb.Clear();
                        }
                        deviceresult.Append(devicesb.ToString());
                        devicesb.Clear();
                        devicesb.Append("},");
                    }
                    devicesb = devicesb.Remove(devicesb.Length - 1, 1);
                }
                devicesb.Append("]");
                deviceresult.Append(devicesb.ToString());
                devicesb.Clear();
            }
        }