示例#1
0
 /// <summary>
 ///     构造函数
 /// </summary>
 /// <param name="StationPoint">电源箱地址号</param>
 /// <param name="fzh">分站号</param>
 //public CuCharge(string StationPoint, string fzh)
 //{
 //    _StationPoint = StationPoint;
 //    _fzh = fzh;
 //    InitializeComponent();
 //}
 public CuCharge(BatteryItem bi, BatteryPowerConsumption batteryPowerConsumption)
 {
     //_StationPoint = StationPoint;
     //_fzh = fzh;
     _batteryItem             = bi;
     _batteryPowerConsumption = batteryPowerConsumption;
     InitializeComponent();
 }
示例#2
0
        /// <summary>
        /// 分站电源箱label点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SubstationLabelClick(object sender, EventArgs e)
        {
            try
            {
                var tv = (Label)sender;
                var bi = (BatteryItem)tv.Tag;
                //label2.Text = bi.BatteryAddress;
                label2.Text = bi.Channel;

                _lisDef = ControlInterfaceFuction.GetAllSubstation();//重新加载
                string     selectStationPointId = "";
                Jc_DefInfo def = _lisDef.Find(a => a.Fzh == short.Parse(selectFzhNow));
                if (def != null)
                {
                    selectStationPointId = def.PointID;
                }
                //查找分站对应的电源箱5分钟统计信息
                BatteryPowerConsumption batteryPowerConsumption = new BatteryPowerConsumption();
                if (def.BatteryPowerConsumptions != null)
                {
                    batteryPowerConsumption = def.BatteryPowerConsumptions.Find(a => a.Channel == bi.Channel);
                }
                var tempCharge = new CuCharge(bi, batteryPowerConsumption);
                //CpanelPowerPac.Controls.Clear();
                //重写释放控件的方法,直接clear会导致句柄资源一直增加  20180422
                while (CpanelPowerPac.Controls.Count > 0)
                {
                    if (CpanelPowerPac.Controls[0] != null)
                    {
                        CpanelPowerPac.Controls[0].Dispose();
                    }
                }
                CpanelPowerPac.Controls.Add(tempCharge);
                tempCharge.Dock = DockStyle.Fill;

                //var node = treeViewSubstation.SelectedNode;
                //Dictionary<string, object> dic = new Dictionary<string, object>();
                //dic.Add("GetBatteryItem", ((Label)sender).Text);
                //dic.Add("SelNode", node);
                //_refStationBattery = new Thread(GetBatteryItem);

                //_refStationBattery.Start(dic);
            }
            catch (Exception exc)
            {
                XtraMessageBox.Show(exc.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#3
0
        //private void GetBatteryItem(object dic)
        //{
        //    Dictionary<string, object> tempdic = dic as Dictionary<string, object>;
        //    string batteryAddress = tempdic["GetBatteryItem"].ToString();
        //    var node = (TreeNode)tempdic["SelNode"];
        //    if (node == null)
        //    {
        //        return;
        //    }
        //    var gsa = ControlInterfaceFuction.GetSubstationPowerBoxInfo(node.Name);

        //    if (gsa.PowerDateTime > Convert.ToDateTime("1900-01-01"))
        //    {
        //        BatteryItem item = gsa.PowerBoxInfo.FirstOrDefault(a => a.Channel == batteryAddress.ToString());
        //        if (item != null)
        //        {
        //            //Action<object> act = RefStationBatteryInfo;
        //            //BeginInvoke(act, item);
        //            MethodInvoker In = new MethodInvoker(() => RefStationBatteryInfo(item));
        //            if (this.InvokeRequired)
        //            {
        //                this.BeginInvoke(In);
        //            }
        //            //_substationUpdatetime[node.Name] = gsa.PowerDateTime;
        //            //substationUpdatetime.Text = _substationUpdatetime[node.Name].ToString("yyyy-MM-dd HH:mm:ss");
        //        }
        //    }
        //}

        //private void RefStationBatteryInfo(object item)
        //{
        //    var tempCharge = new CuCharge((BatteryItem)item);
        //    CpanelPowerPac.Controls.Clear();
        //    CpanelPowerPac.Controls.Add(tempCharge);
        //    tempCharge.Dock = DockStyle.Fill;

        //    //substationUpdatetime.Text = PowerDateTime.ToString();
        //}

        /// <summary>
        /// 交换机电源箱label点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SwitchLabelClick(object sender, EventArgs e)
        {
            try
            {
                var tv = (Label)sender;
                var bi = (BatteryItem)tv.Tag;
                label3.Text = bi.Channel;

                //加载交换机
                _lisMac = ControlInterfaceFuction.GetAllSwitch();

                Jc_MacInfo mac = _lisMac.Find(a => a.MAC == selectMacNow);

                //查找分站对应的电源箱5分钟统计信息
                BatteryPowerConsumption batteryPowerConsumption = new BatteryPowerConsumption();
                if (mac.BatteryPowerConsumptions != null)
                {
                    batteryPowerConsumption = mac.BatteryPowerConsumptions.Find(a => a.Channel == bi.Channel);
                }

                var tempCharge = new CuCharge(bi, batteryPowerConsumption);
                //panelControl2.Controls.Clear();
                //重写释放控件的方法,直接clear会导致句柄资源一直增加  20180422
                while (panelControl2.Controls.Count > 0)
                {
                    if (panelControl2.Controls[0] != null)
                    {
                        panelControl2.Controls[0].Dispose();
                    }
                }
                panelControl2.Controls.Add(tempCharge);
                tempCharge.Dock = DockStyle.Fill;

                //var node = treeViewSubstation.SelectedNode;
                //Dictionary<string, object> dic = new Dictionary<string, object>();
                //dic.Add("GetBatteryItem", ((Label)sender).Text);
                //dic.Add("SelNode", node);
                //_refStationBattery = new Thread(GetBatteryItemForSwicth);

                //_refStationBattery.Start(dic);
            }
            catch (Exception exc)
            {
                XtraMessageBox.Show(exc.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#4
0
        private static void HandleThreadFun()
        {
            while (_isRun)
            {
                try
                {
                    #region 计算交换机电源箱信息
                    NetworkModuleCacheGetByConditonRequest networkModuleCacheRequest = new NetworkModuleCacheGetByConditonRequest();
                    networkModuleCacheRequest.Predicate = a => a.Bz4 == "1";
                    List <Jc_MacInfo> macList = networkModuleService.GetNetworkModuleCache(networkModuleCacheRequest).Data;//所有挂接了智能电源箱的设备
                    foreach (Jc_MacInfo mac in macList)
                    {
                        if (mac.State == (short)DeviceDataState.EquipmentDC)//交换机进入直流状态,表示电源箱已处于放电状态
                        {
                            List <PointElectricityInfo> pointElectricityInfo = pointElectricityInfoList.FindAll(a => a.PointId == mac.MAC);
                            if (pointElectricityInfo.Count < 1) //表示第一次放电,则记录放电的开始时间
                            {
                                sendD(16, mac.MAC);             //下发获取电源箱数据命令
                                Thread.Sleep(10000);

                                PointElectricityInfo tempPointElectricityInfo = new PointElectricityInfo();
                                tempPointElectricityInfo.StartTime = DateTime.Now;
                                tempPointElectricityInfo.EndTime   = DateTime.Parse("1900-01-01 00:00:00");
                                if (mac.BatteryItems != null)
                                {
                                    foreach (BatteryItem battery in mac.BatteryItems)
                                    {
                                        tempPointElectricityInfo.Channel          = battery.Channel;
                                        tempPointElectricityInfo.PowerConsumption = battery.PowerPackVOL;
                                        if (pointElectricityInfoList.FindAll(a => a.Channel == battery.Channel && a.PointId == mac.MAC).Count < 1)
                                        {
                                            pointElectricityInfoList.Add(tempPointElectricityInfo);
                                        }
                                    }
                                }
                            }
                            else//表示之前已经添加了第一次放电的时间,判断放电是否达到了5分钟
                            {
                                if (pointElectricityInfo[0].EndTime != DateTime.Parse("1900-01-01 00:00:00"))
                                {
                                    continue;//如果之前已经计算过,则不用重复计算
                                }
                                TimeSpan ts = DateTime.Now - pointElectricityInfo[0].StartTime;
                                if (ts.TotalMinutes >= 5) //到5分钟时,计算当前5分钟消耗的电量,并存储
                                {
                                    sendD(16, mac.MAC);   //下发获取电源箱数据命令
                                    Thread.Sleep(10000);

                                    Dictionary <string, object>    updateItems = new Dictionary <string, object>();
                                    List <BatteryPowerConsumption> batteryPowerConsumptions = new List <BatteryPowerConsumption>();
                                    for (int i = 0; i < mac.BatteryItems.Count; i++)
                                    {
                                        int powerConsumption = pointElectricityInfo[i].PowerConsumption - mac.BatteryItems[i].PowerPackVOL;//得到当前5分钟的电量衰减量
                                        //将5分钟电量衰减参数更新到实时缓存
                                        BatteryPowerConsumption batteryPowerConsumption = new BatteryPowerConsumption();
                                        batteryPowerConsumption.Channel          = pointElectricityInfo[i].Channel;
                                        batteryPowerConsumption.PowerConsumption = powerConsumption;
                                        batteryPowerConsumptions.Add(batteryPowerConsumption);
                                    }
                                    updateItems.Add("BatteryPowerConsumptions", batteryPowerConsumptions);
                                    UpdateNetWorkInfoByProperties(mac.MAC, updateItems);

                                    //更新临时缓存的结束时间,后续不用再重复计算
                                    foreach (PointElectricityInfo temp in pointElectricityInfo)
                                    {
                                        temp.EndTime = DateTime.Now;
                                    }
                                }
                            }
                        }
                        else//交换机状态改变,重新计算
                        {
                            //清除临时缓存,并重新计算
                            foreach (PointElectricityInfo temp in pointElectricityInfoList)
                            {
                                if (temp.PointId == mac.MAC)
                                {
                                    pointElectricityInfoList.Remove(temp);
                                }
                            }
                        }
                    }
                    #endregion

                    #region 计算分站电源箱信息
                    PointDefineCacheGetByConditonRequest pointDefineCacheRequest = new PointDefineCacheGetByConditonRequest();
                    pointDefineCacheRequest.Predicate = a => a.DevPropertyID == 0 && (a.Bz3 & 0x8) == 0x8;
                    List <Jc_DefInfo> stationList = PointDefineCacheService.GetPointDefineCache(pointDefineCacheRequest).Data;
                    foreach (Jc_DefInfo station in stationList)
                    {
                        if (station.DataState == (short)DeviceDataState.EquipmentDC)//分站进入直流状态,表示电源箱已处于放电状态
                        {
                            List <PointElectricityInfo> pointElectricityInfo = pointElectricityInfoList.FindAll(a => a.PointId == station.PointID);
                            if (pointElectricityInfo.Count < 1)   //表示第一次放电,则记录放电的开始时间
                            {
                                sendD(0, station.Fzh.ToString()); //下发获取电源箱命令
                                Thread.Sleep(10000);

                                PointElectricityInfo tempPointElectricityInfo = new PointElectricityInfo();
                                tempPointElectricityInfo.PointId   = station.PointID;
                                tempPointElectricityInfo.StartTime = DateTime.Now;
                                tempPointElectricityInfo.EndTime   = DateTime.Parse("1900-01-01 00:00:00");
                                if (station.BatteryItems != null)
                                {
                                    foreach (BatteryItem battery in station.BatteryItems)
                                    {
                                        tempPointElectricityInfo.Channel          = battery.Channel;
                                        tempPointElectricityInfo.PowerConsumption = battery.PowerPackVOL;
                                        if (pointElectricityInfoList.FindAll(a => a.Channel == battery.Channel && a.PointId == station.PointID).Count < 1)
                                        {
                                            pointElectricityInfoList.Add(tempPointElectricityInfo);
                                        }
                                    }
                                }
                                else
                                {
                                    sendD(0, station.Fzh.ToString());
                                }
                            }
                            else//表示之前已经添加了第一次放电的时间,判断放电是否达到了5分钟
                            {
                                if (pointElectricityInfo[0].EndTime != DateTime.Parse("1900-01-01 00:00:00"))
                                {
                                    continue;//如果之前已经计算过,则不用重复计算
                                }
                                TimeSpan ts = DateTime.Now - pointElectricityInfo[0].StartTime;
                                if (ts.TotalMinutes >= 5)             //到5分钟时,计算当前5分钟消耗的电量,并存储
                                {
                                    sendD(0, station.Fzh.ToString()); //下发获取电源箱命令
                                    Thread.Sleep(10000);

                                    Dictionary <string, object>    updateItems = new Dictionary <string, object>();
                                    List <BatteryPowerConsumption> batteryPowerConsumptions = new List <BatteryPowerConsumption>();
                                    for (int i = 0; i < station.BatteryItems.Count; i++)
                                    {
                                        int powerConsumption = pointElectricityInfo[i].PowerConsumption - station.BatteryItems[i].PowerPackVOL;//得到当前5分钟的电量衰减量
                                        //将5分钟电量衰减参数更新到实时缓存
                                        BatteryPowerConsumption batteryPowerConsumption = new BatteryPowerConsumption();
                                        batteryPowerConsumption.Channel          = pointElectricityInfo[i].Channel;
                                        batteryPowerConsumption.PowerConsumption = powerConsumption;
                                        batteryPowerConsumptions.Add(batteryPowerConsumption);
                                    }
                                    updateItems.Add("BatteryPowerConsumptions", batteryPowerConsumptions);
                                    UpdatePointDefineInfoByProperties(station.PointID, updateItems);

                                    //更新临时缓存的结束时间,后续不用再重复计算
                                    foreach (PointElectricityInfo temp in pointElectricityInfo)
                                    {
                                        temp.EndTime = DateTime.Now;
                                    }
                                }
                            }
                        }
                        else//分站状态改变,重新计算
                        {
                            //清除临时缓存,并重新计算
                            foreach (PointElectricityInfo temp in pointElectricityInfoList)
                            {
                                if (temp.PointId == station.PointID)
                                {
                                    pointElectricityInfoList.Remove(temp);
                                }
                            }
                        }
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }

                Thread.Sleep(5000);
            }
            _isRun = true;
            LogHelper.Info("【ElectricityStatistics】充放电电量统计线程结束成功。");
        }