Ejemplo n.º 1
0
        protected override List <DeviceType> GetConfiguredDeviceTypeWithController(ControllerModel controller)
        {
            List <DeviceType> lstDeviceType = new List <DeviceType>();

            List <short> lstDeviceCode = new List <short>();

            foreach (var l in controller.Loops)
            {
                foreach (var dev in l.GetDevices <DeviceInfo8021>())
                {
                    if (!lstDeviceCode.Contains(dev.TypeCode))
                    {
                        lstDeviceCode.Add(dev.TypeCode);
                    }
                }
            }
            ControllerConfig8021 config         = new ControllerConfig8021();
            List <DeviceType>    lstAllTypeInfo = config.GetALLDeviceTypeInfo(null);

            //var result =from c in lstAllTypeInfo where c.Code=

            foreach (var v in lstDeviceCode)
            {
                var result = lstAllTypeInfo.Where((s) => s.Code == v);
                if (result.Count() > 0)
                {
                    lstDeviceType.Add(result.FirstOrDefault());
                }
            }
            return(lstDeviceType);
        }
Ejemplo n.º 2
0
        public List <DeviceType> GetAllDeviceTypeOfController(ControllerModel controller)
        {
            List <DeviceType>    lstDeviceType = new List <DeviceType>();
            ControllerConfig8021 config        = new ControllerConfig8021();

            if (controller != null)
            {
                if (controller.Loops != null)
                {
                    foreach (var loop in controller.Loops)
                    {
                        IEnumerable <DeviceInfo8021> lstDistinceInfo = loop.GetDevices <DeviceInfo8021>().Distinct(new CollectionEqualityComparer <DeviceInfo8021>((x, y) => x.TypeCode == y.TypeCode)).ToList();
                        foreach (var device in lstDistinceInfo)
                        {
                            DeviceType dType = config.GetDeviceTypeViaDeviceCode(device.TypeCode);
                            lstDeviceType.Add(dType);
                        }
                    }
                }
            }
            return(lstDeviceType);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取控制器内不同器件类型的数量
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        public override Dictionary <string, int> GetAmountOfDifferentDeviceType(ControllerModel controller)
        {
            Dictionary <string, int> dictDeviceTypeStatistic = new Dictionary <string, int>();
            ControllerConfig8021     config = new ControllerConfig8021();

            if (controller != null)
            {
                if (controller.Loops != null)
                {
                    foreach (var loop in controller.Loops)
                    {
                        IEnumerable <DeviceInfo8021> lstDistinceInfo = loop.GetDevices <DeviceInfo8021>().Distinct(new CollectionEqualityComparer <DeviceInfo8021>((x, y) => x.TypeCode == y.TypeCode)).ToList();

                        int deviceCountInLoop = loop.GetDevices <DeviceInfo8021>().Count;
                        //int deviceCountInStatistic = 0;
                        foreach (var device in lstDistinceInfo)
                        {
                            DeviceType dType     = config.GetDeviceTypeViaDeviceCode(device.TypeCode);
                            int        typeCount = loop.GetDevices <DeviceInfo8021>().Count((d) => d.TypeCode == dType.Code); //记录器件类型的数量
                            if (!dictDeviceTypeStatistic.ContainsKey(dType.Name))
                            {
                                dictDeviceTypeStatistic.Add(dType.Name, typeCount);
                            }
                            else
                            {
                                dictDeviceTypeStatistic[dType.Name] += typeCount;
                            }
                            //deviceCountInStatistic += typeCount;
                            //if (deviceCountInStatistic == deviceCountInLoop)
                            //{
                            //    break;
                            //}
                        }
                    }
                }
            }
            return(dictDeviceTypeStatistic);
        }
Ejemplo n.º 4
0
        protected override List <LoopModel> ConvertToLoopModelFromDataTable(System.Data.DataTable dt, ControllerModel controller, out string loopDetailErrorInfo)
        {
            loopDetailErrorInfo = "";//Initialize
            //取得当前控制器最大器件ID
            int maxDeviceID             = this.GetMaxDeviceID();
            ControllerConfig8021 config = new ControllerConfig8021();
            //暂停对具体信息进行验证
            //Dictionary<string, RuleAndErrorMessage> dictDeviceDataRule = config.GetDeviceInfoRegularExpression(controller.DeviceAddressLength);
            List <LoopModel> lstLoops = new List <LoopModel>();


            string    loopCode = "";
            LoopModel loop     = null;

            int[] loopIndexRange = ParseLoopSheetName(dt.TableName);//取得工作表内回路的起始编号
            int   loopsAmount    = loopIndexRange[1] - loopIndexRange[0] + 1;

            int[] loopIndex = new int[loopsAmount];
            for (int i = 0; i < loopsAmount; i++)
            {
                loopIndex[i] = loopIndexRange[0] + i;
            }
            int loopCount = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (loopCode != dt.Rows[i]["编码"].ToString().Substring(0, controller.DeviceAddressLength - 3))//器件编码为3位
                {
                    //新建回路
                    loopCode  = dt.Rows[i]["编码"].ToString().Substring(0, controller.DeviceAddressLength - 3);
                    loop      = new LoopModel();
                    loop.Code = loopCode;
                    loop.Name = loopCode;
                    lstLoops.Add(loop);
                    string machineNumberOfDevice = loop.Code.Substring(0, controller.DeviceAddressLength - 5);
                    bool   blnErrorFlag          = false;
                    if (controller.MachineNumber != machineNumberOfDevice)  //控制器机号验证
                    {
                        loopDetailErrorInfo += ";" + dt.TableName + "-器件(" + dt.Rows[i]["编码"].ToString() + ")机号(" + machineNumberOfDevice + ")与模板机号(" + controller.MachineNumber + ")不符";
                        blnErrorFlag         = true;
                    }
                    if (!blnErrorFlag)
                    {
                        if (loopIndex[loopCount].ToString().PadLeft(controller.LoopAddressLength, '0') != loop.Code.Substring(machineNumberOfDevice.Length)) //回路号验证
                        {
                            loopDetailErrorInfo += ";器件(" + dt.Rows[i]["编码"].ToString() + ")回路号(" + loop.Code.Substring(machineNumberOfDevice.Length) + ")与模板回路号(" + loopIndex[loopCount].ToString().PadLeft(controller.LoopAddressLength, '0') + ")不符";
                            blnErrorFlag         = true;
                        }
                    }
                    if (blnErrorFlag)  //机号或回路号不正确,停止处理,返回调用
                    {
                        return(null);
                    }
                    loopCount++;
                }
                DeviceInfo8021 device = new DeviceInfo8021();
                maxDeviceID++;
                device.ID       = maxDeviceID;
                device.Code     = dt.Rows[i]["编码"].ToString();
                device.TypeCode = config.GetDeviceCodeViaDeviceTypeName(dt.Rows[i]["器件类型"].ToString());
                device.Disable  = new Nullable <bool>(Convert.ToBoolean(dt.Rows[i]["屏蔽"].ToString() == "0" ? false : true));
                if (dt.Rows[i]["电流报警值"].ToString() == "")
                {
                    device.CurrentThreshold = null;
                }
                else
                {
                    device.CurrentThreshold = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["电流报警值"].ToString()));
                }
                if (dt.Rows[i]["温度报警值"].ToString() == "")
                {
                    device.TemperatureThreshold = null;
                }
                else
                {
                    device.TemperatureThreshold = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["温度报警值"].ToString()));
                }


                if (dt.Rows[i]["楼号"].ToString() == "")
                {
                    device.BuildingNo = null;
                }
                else
                {
                    device.BuildingNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["楼号"].ToString()));
                }
                if (dt.Rows[i]["区号"].ToString() == "")
                {
                    device.ZoneNo = null;
                }
                else
                {
                    device.ZoneNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["区号"].ToString()));
                }
                if (dt.Rows[i]["层号"].ToString() == "")
                {
                    device.FloorNo = null;
                }
                else
                {
                    device.FloorNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["层号"].ToString()));
                }
                if (dt.Rows[i]["房间号"].ToString() == "")
                {
                    device.RoomNo = null;
                }
                else
                {
                    device.RoomNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["房间号"].ToString()));
                }
                device.Location = dt.Rows[i]["安装地点"].ToString();
                if (loop != null)
                {
                    device.Loop = loop;
                    //在合适位置设置
                    //device.LoopID
                    loop.SetDevice <DeviceInfo8021>(device);
                    loop.DeviceAmount++;
                }
            }
            //更新最大器件ID
            ProjectManager.GetInstance.MaxDeviceIDInController8021 = maxDeviceID;
            return(lstLoops);
        }