コード例 #1
0
        private void DataLineFormPro_Load(object sender, EventArgs e)
        {
            if (_para.StationGrade.Contains("台站"))
            {
                _para.StationProList = new List <Common.StationPara>();
                string conn =
                    $"Data Source={_para.SqlServerPara.SqlIp};Initial Catalog={_para.SqlServerPara.SqlDb};User ID={_para.SqlServerPara.SqlUser};Password={_para.SqlServerPara.SqlPwd};";
                RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(conn);
                var stations = (from s in radarDataContext.StationParaTable
                                select s).Distinct().ToList();
                foreach (Common.StationPara station in stations.Select(s => new Common.StationPara
                {
                    StationId = s.StationID,
                    StationName = s.StationName,
                    Slong = s.Slong,
                    Slat = s.Slat
                }))
                {
                    _para.StationProList.Add(station);
                }
            }
            DateTime dt      = DateTime.Now;
            DateTime dtvalue = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0);

            dtpEndTime.MaxDate   = dtvalue;
            dtpEndTime.Value     = dtvalue;
            dtpStartTime.MaxDate = dtvalue;
            dtpStartTime.Value   = dtvalue.AddHours(-1);
            stationchkListBox.Items.Add("全选");
            string[] ss = (from d in _para.StationProList
                           select d.StationId).ToArray();
            stationchkListBox.Items.AddRange(ss);
        }
コード例 #2
0
 private void cmbGrade_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cmbGrade.SelectedItem.ToString().Contains("省级"))
     {
         gbSerialPort.Enabled = false;
         dgvStationList.ReadOnly = true;
         string conn = $"Data Source={tbSqlIp.Text};Initial Catalog={tbDataBase.Text};User ID={tbUser.Text};Password={tbPassword.Text};";
         RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(conn);
         var stations = (from s in radarDataContext.StationParaTable
                         select s).Distinct().ToList();
         dgvStationList.RowCount = stations.Count;
         for (int i = 0; i < dgvStationList.RowCount; i++)
         {
             dgvStationList[0, i].Value = (i + 1).ToString(CultureInfo.InvariantCulture);
             dgvStationList[1, i].Value = stations[i].StationID;
             dgvStationList[2, i].Value = stations[i].StationName;
             dgvStationList[3, i].Value = stations[i].Slong;
             dgvStationList[4, i].Value = stations[i].Slat;
         }
     }
     else
     {
         gbSerialPort.Enabled = true;
         dgvStationList.ReadOnly = false;
         dgvStationList.RowCount = 1;
         dgvStationList[0, 0].Value = "1";
         dgvStationList[1, 0].Value = _para.StationInfo.StationId;
         dgvStationList[2, 0].Value = _para.StationInfo.StationName;
         dgvStationList[3, 0].Value = _para.StationInfo.Slong;
         dgvStationList[4, 0].Value = _para.StationInfo.Slat;
     }
 }
コード例 #3
0
 public DataBaseHelper(string connstr)
 {
     _radarDataContext = new RadarDataClassesDataContext(connstr);
 }
コード例 #4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                var updater = Updater.Instance;
                updater.Error                 += updater_Error;
                updater.UpdatesFound          += updater_UpdatesFound;
                updater.NoUpdatesFound        += updater_NoUpdatesFound;
                updater.MinmumVersionRequired += updater_OnUpdaterOnMinmumVersionRequired;
                updater.BeginCheckUpdateInProcess();
            }
            catch (Exception exception)
            {
                CommonLogHelper.GetInstance("LogError").Error(@"自动更新过程出错", exception);
            }
            try
            {
                _para = Parameter.ReadCfg();
            }
            catch (Exception exception)
            {
                CommonLogHelper.GetInstance("LogError").Error(@"读取系统参数过程出错", exception);
                MessageBox.Show(@"读取系统参数过程出错", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (_para.StationGrade.Contains("省级"))
            {
                //采集器设置ToolStripMenuItem.Visible = false;
                台站选择ToolStripMenuItem.Visible = true;

                try
                {
                    _para.StationProList = new List <StationPara>();
                    string conn =
                        $"Data Source={_para.SqlServerPara.SqlIp};Initial Catalog={_para.SqlServerPara.SqlDb};User ID={_para.SqlServerPara.SqlUser};Password={_para.SqlServerPara.SqlPwd};";
                    RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(conn);
                    var stations = (from s in radarDataContext.StationParaTable
                                    select s).Distinct().ToList();
                    foreach (StationPara station in stations.Select(s => new StationPara
                    {
                        StationId = s.StationID,
                        StationName = s.StationName,
                        Slong = s.Slong,
                        Slat = s.Slat
                    }))
                    {
                        _para.StationProList.Add(station);
                    }
                    foreach (ToolStripMenuItem stationToolStripMenuItem in stations.Select(station => new ToolStripMenuItem
                    {
                        Name = "stationToolStripMenuItem",
                        Text = station.StationName,
                        Tag = station.StationID
                    }))
                    {
                        stationToolStripMenuItem.Click += StationToolStripMenuItem_Click;
                        台站选择ToolStripMenuItem.DropDownItems.Add(stationToolStripMenuItem);
                        StationToolStripMenuItem_Click(stationToolStripMenuItem, e);
                    }
                }
                catch (Exception exception)
                {
                    CommonLogHelper.GetInstance("LogError").Error(@"加载站点信息出错", exception);
                    MessageBox.Show(@"加载站点信息出错", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                //采集器设置ToolStripMenuItem.Visible = true;
                台站选择ToolStripMenuItem.Visible = false;
                _smcForm = new StatusMonitorControlForm
                {
                    MdiParent   = this,
                    WindowState = FormWindowState.Maximized,
                    Para        = _para,
                    StationId   = _para.StationInfo.StationId,
                };
                _smcForm.Show();
            }
            _tmr.Start();
        }
コード例 #5
0
        private void 系统设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string staitongrad = _para.StationGrade;

            using (SettingForm setForm = new SettingForm())
            {
                var result = setForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    _para = Parameter.ReadCfg();
                    if (!_para.StationGrade.Equals(staitongrad))
                    {
                        foreach (Form mdiChild in MdiChildren)
                        {
                            ((StatusMonitorControlForm)mdiChild).CanClose = true;
                            mdiChild.Close();
                        }
                        if (_para.StationGrade.Contains("省级"))
                        {
                            //采集器设置ToolStripMenuItem.Visible = false;
                            台站选择ToolStripMenuItem.Visible = true;
                            台站选择ToolStripMenuItem.DropDownItems.Clear();

                            try
                            {
                                _para.StationProList = new List <StationPara>();
                                string conn =
                                    $"Data Source={_para.SqlServerPara.SqlIp};Initial Catalog={_para.SqlServerPara.SqlDb};User ID={_para.SqlServerPara.SqlUser};Password={_para.SqlServerPara.SqlPwd};";
                                RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(conn);
                                var stations = (from s in radarDataContext.StationParaTable
                                                select s).Distinct().ToList();
                                foreach (StationPara station in stations.Select(s => new StationPara
                                {
                                    StationId = s.StationID,
                                    StationName = s.StationName,
                                    Slong = s.Slong,
                                    Slat = s.Slat
                                }))
                                {
                                    _para.StationProList.Add(station);
                                }
                                foreach (ToolStripMenuItem stationToolStripMenuItem in stations.Select(station => new ToolStripMenuItem
                                {
                                    Name = "stationToolStripMenuItem",
                                    Text = station.StationName,
                                    Tag = station.StationID
                                }))
                                {
                                    stationToolStripMenuItem.Click += StationToolStripMenuItem_Click;
                                    台站选择ToolStripMenuItem.DropDownItems.Add(stationToolStripMenuItem);
                                    StationToolStripMenuItem_Click(stationToolStripMenuItem, e);
                                }
                            }
                            catch (Exception exception)
                            {
                                CommonLogHelper.GetInstance("LogError").Error(@"加载站点信息出错", exception);
                                MessageBox.Show(@"加载站点信息出错", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            //采集器设置ToolStripMenuItem.Visible = true;
                            台站选择ToolStripMenuItem.Visible = false;
                            _smcForm = new StatusMonitorControlForm
                            {
                                MdiParent   = this,
                                WindowState = FormWindowState.Maximized,
                                Para        = _para,
                                StationId   = _para.StationInfo.StationId
                            };
                            _smcForm.Show();
                        }
                    }
                }
            }
        }
コード例 #6
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            Thread drawDataLineProThread = new Thread((ThreadStart) delegate
            {
                try
                {
                    _synchContext.Post(a =>
                    {
                        gbControl.Enabled          = false;
                        stationchkListBox.Enabled  = false;
                        powerchkListBox.Enabled    = false;
                        circularProgress.IsRunning = true;
                        circularProgress.Visible   = true;
                    }, null);
                    _powerDataDics.Clear();
                    _sheetNameList.Clear();
                    List <string> stationsList = new List <string>();
                    for (int i = 1; i < stationchkListBox.Items.Count; i++)
                    {
                        if (stationchkListBox.GetItemChecked(i))
                        {
                            stationsList.Add(stationchkListBox.GetItemText(stationchkListBox.Items[i]));
                        }
                    }
                    string conn =
                        $"Data Source={_para.SqlServerPara.SqlIp};Initial Catalog={_para.SqlServerPara.SqlDb};User ID={_para.SqlServerPara.SqlUser};Password={_para.SqlServerPara.SqlPwd};";
                    DateTime sdt = dtpStartTime.Value;
                    DateTime edt = dtpEndTime.Value;
                    RadarDataClassesDataContext radarDataClasses = new RadarDataClassesDataContext(conn);
                    List <string> powerList = new List <string>();
                    for (int i = 1; i < powerchkListBox.Items.Count; i++)
                    {
                        if (powerchkListBox.GetItemChecked(i))
                        {
                            powerList.Add(powerchkListBox.GetItemText(powerchkListBox.Items[i]));
                        }
                    }

                    for (int i = 0; i < powerList.Count; i++)
                    {
                        powerList[i] = DataEnum2Titles.ToProperties(powerList[i]);
                    }

                    _synchContext.Post(a =>
                    {
                        chartVolCur.Titles.Clear();
                        chartVolCur.Titles.Add("电源数据曲线图");
                        chartVolCur.Titles.Add(
                            $"({sdt.ToString(CultureInfo.InvariantCulture)}——{edt.ToString(CultureInfo.InvariantCulture)})");
                        chartVolCur.ChartAreas.Clear();
                        chartVolCur.Series.Clear();
                        chartVolCur.Legends.Clear();
                        ChartArea ca = new ChartArea("Default");
                        chartVolCur.ChartAreas.Add(ca);
                        chartVolCur.ChartAreas[0].AxisX.IsMarginVisible    = true;
                        chartVolCur.ChartAreas[0].AxisX.Interval           = 1;
                        chartVolCur.ChartAreas[0].AxisX.MajorGrid.Interval = 1;

                        //chartVolCur.Legends["Legend2"].DockedToChartArea = "Default";

                        foreach (var stationid in stationsList)
                        {
                            Dictionary <string, List <string> > powerDataDic = new Dictionary <string, List <string> >();

                            List <string> columnName = new List <string>();

                            chartVolCur.Legends.Add(new Legend(stationid)
                            {
                                Title = stationid, Docking = Docking.Bottom
                            });
                            foreach (var powerName in powerList)
                            {
                                //chartVolCur.Legends["Legend2"].CellColumns.Add(new LegendCellColumn("Name", LegendCellColumnType.Text, stationid));
                                // Assign the legend to Series1.

                                Series s = new Series(stationid + "_" + powerName)
                                {
                                    MarkerSize          = 10,
                                    MarkerStyle         = MarkerStyle.Star10,
                                    ChartType           = SeriesChartType.Line,
                                    IsValueShownAsLabel = true,
                                    BorderWidth         = 3,
                                    ShadowOffset        = 1,
                                    Legend            = stationid,
                                    LegendText        = DataEnum2Titles.ToTitles(powerName),
                                    IsVisibleInLegend = true,
                                    Font = new Font("Microsoft Sans Serif", 8F, FontStyle.Bold),
                                };
                                var allpowerdata = (from vol in radarDataClasses.PowerDataTable
                                                    where stationsList.Contains(vol.StationID) &&
                                                    vol.DateTime >= sdt && vol.DateTime <= edt
                                                    orderby vol.DateTime ascending
                                                    select vol).ToList();
                                for (int i = 0; i <= (edt - sdt).TotalMinutes; i++)
                                {
                                    DateTime dt             = sdt.AddMinutes(i);
                                    List <string> powerdata = new List <string>();
                                    if (!powerDataDic.ContainsKey(dt.ToString(CultureInfo.InvariantCulture)))
                                    {
                                        powerDataDic.Add(dt.ToString(CultureInfo.InvariantCulture), powerdata);
                                    }
                                    var pd = (from v in allpowerdata
                                              where v.DateTime == dt && v.StationID == stationid
                                              select v).Distinct().ToList();
                                    if (pd.Count > 0)
                                    {
                                        object obj = (typeof(PowerDataTable)).GetProperty(powerName).GetValue(pd[0], null);
                                        s.Points.AddXY(dt.ToString("HH:mm"), obj);
                                        powerDataDic[dt.ToString(CultureInfo.InvariantCulture)].Add(obj.ToString());
                                    }
                                    else
                                    {
                                        s.Points.AddXY(dt.ToString("HH:mm"), DBNull.Value);
                                        powerDataDic[dt.ToString(CultureInfo.InvariantCulture)].Add(string.Empty);
                                    }
                                }
                                chartVolCur.Series.Add(s);

                                columnName.Add(DataEnum2Titles.ToTitles(powerName));
                            }

                            _powerDataDics.Add(stationid, powerDataDic);
                            _sheetNameList.Add(stationid, columnName);
                        }
                    }, null);
                }
                catch (Exception exception)
                {
                    CommonLogHelper.GetInstance("LogError").Error(@"数据查询并绘制曲线过程出错", exception);
                    _synchContext.Post(a =>
                                       MessageBox.Show(this, @"绘制复杂曲线过程错误," + exception.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
                                       , null);
                }
                finally
                {
                    _synchContext.Post(a =>
                    {
                        gbControl.Enabled          = true;
                        stationchkListBox.Enabled  = true;
                        powerchkListBox.Enabled    = true;
                        circularProgress.IsRunning = false;
                        circularProgress.Visible   = false;
                    }, null);
                }
            })
            {
                IsBackground = true
            };

            drawDataLineProThread.Start();
        }
コード例 #7
0
        private void 实时采集ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DateTime dt   = DateTime.Now;
            DateTime obdt = dt.AddSeconds(-dt.Second).AddMilliseconds(-dt.Millisecond);

            #region 台站级别发送指令

            if (Para.StationGrade.Contains("台站"))
            {
                Thread collectThread = new Thread((ThreadStart) delegate
                {
                    try
                    {
                        SerialPortOperate tempSerialPortOperate = _serialPort;
                        //_tempSerialPortOperate.ReturnCollectorRecData += ManualRecDataProcessing;
                        byte[] cmd = SerialPortCmdCombine.SetBaseCommand("FF", "03");
                        CommonLogHelper.GetInstance("LogInfo")
                        .Info($@"实时采集:发送采集命令:{string.Join(" ", cmd.Select(x => x.ToString("X2")).ToArray())}");
                        tempSerialPortOperate.SendCommand(cmd);
                    }
                    catch (Exception ex)
                    {
                        CommonLogHelper.GetInstance("LogInfo").Info(@"实时采集:发送串口命令获取数据过程出错");
                        CommonLogHelper.GetInstance("LogError").Error(@"实时采集:发送串口命令获取数据过程出错", ex);
                        _synchContext.Post(a =>
                                           MessageBox.Show(this, @"实时采集:发送串口命令获取数据过程出错," + ex.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
                                           , null);
                    }
                })
                {
                    IsBackground = true
                };
                collectThread.Start();
            }

            #endregion 台站级别发送指令

            #region 省级级别操作数据库

            try
            {
                if (Para.StationGrade.Contains("省级"))
                {
                    Thread collectProThread = new Thread((ThreadStart) delegate
                    {
                        tSSLSystemStatus.Text = @"获取最新数据";
                        RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(_conn);
                        DataAdapter dataadp = new DataAdapter(StationId, obdt);
                        dataadp.DataResolve(radarDataContext);
                        _synchContext.Post(a =>
                        {
                            try
                            {
                                if (dataadp.AlarmStatusData != null)
                                {
                                    radarStatusUI.SetAlarmStatus(dataadp.AlarmStatusData);
                                }
                                if (dataadp.ControlStatusData != null)
                                {
                                    radarControlUI.SetControlStatus(dataadp.ControlStatusData);
                                }
                                if (dataadp.RadarPowerData != null)
                                {
                                    powerIndicationUI.SetPowerDataValue(dataadp.RadarPowerData);
                                }
                                if (dataadp.AlarmStatusData != null || dataadp.ControlStatusData != null ||
                                    dataadp.RadarPowerData != null)
                                {
                                    tSSLDataUpdateTime.Text = $"数据更新时间:{obdt.ToString("yyyy-MM-dd HH:mm")}";
                                }
                                else
                                {
                                    MessageBox.Show(@"无当前实时数据");
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(@"数据显示到界面上出错" + ex);
                            }
                        }, null);
                        CommonLogHelper.GetInstance("LogInfo").Info(@"获取数据库数据成功");

                        try
                        {
                            RadarFailureAlarm(dataadp.AlarmStatusData);
                        }
                        catch (Exception ex)
                        {
                            CommonLogHelper.GetInstance("LogError").Error(@"雷达故障报警过程出错", ex);
                        }
                    })
                    {
                        IsBackground = true
                    };
                    collectProThread.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, @"提取数据库数据处理过程出错" + ex, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            #endregion 省级级别操作数据库
        }
コード例 #8
0
        private void tmr_Elapsed(object sender, EventArgs e)
        {
            DateTime dt   = DateTime.Now;
            DateTime obdt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0);

            if (dt.Minute % Para.UpdateDataIntl == 0 && dt.Second == 30)
            {
                #region 台站级别发送指令

                if (Para.StationGrade.Contains("台站"))
                {
                    Thread collectTimeThread = new Thread((ThreadStart) delegate
                    {
                        try
                        {
                            _synchContext.Post(a =>
                            {
                                toolSslNextUpdateTime.Text =
                                    $"下次采集时间:{obdt.AddSeconds(30).AddMinutes(Para.UpdateDataIntl).ToString("yyyy-MM-dd HH:mm:ss")}";
                                tSSLSystemStatus.Text = @"正在获取最新数据";
                            }, null);
                            byte[] cmd = SerialPortCmdCombine.SetBaseCommand("FF", "03");
                            CommonLogHelper.GetInstance("LogInfo")
                            .Info($@"发送定时采集命令:{string.Join(" ", cmd.Select(x => x.ToString("X2")).ToArray())}");
                            _isCollect = true;
                            _serialPort.SendCommand(cmd);
                        }
                        catch (Exception ex)
                        {
                            CommonLogHelper.GetInstance("LogInfo").Info(@"发送串口命令获取数据过程出错");
                            CommonLogHelper.GetInstance("LogError").Error(@"发送串口命令获取数据过程出错", ex);
                        }
                    })
                    {
                        IsBackground = true
                    };
                    collectTimeThread.Start();
                }

                #endregion 台站级别发送指令
            }
            if (dt.Second == 40)
            {
                #region 停止声音报警

                _soundAlarm.StopAlarm();

                #endregion 停止声音报警
            }
            if (dt.Minute % Para.UpdateDataIntl == 0 && dt.Second == 45)
            {
                #region 省级级别操作数据库

                if (Para.StationGrade.Contains("省级"))
                {
                    Thread collectProThread = new Thread((ThreadStart) delegate
                    {
                        try
                        {
                            bool havePowerData    = false;
                            tSSLSystemStatus.Text = @"获取最新数据";
                            RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(_conn);
                            DataAdapter dataadp = new DataAdapter(StationId, obdt);
                            dataadp.DataResolve(radarDataContext);
                            _synchContext.Post(a =>
                            {
                                toolSslNextUpdateTime.Text =
                                    $"下次采集时间:{obdt.AddSeconds(45).AddMinutes(Para.UpdateDataIntl).ToString("yyyy-MM-dd HH:mm:ss")}";
                                try
                                {
                                    if (dataadp.AlarmStatusData != null)
                                    {
                                        radarStatusUI.SetAlarmStatus(dataadp.AlarmStatusData);
                                    }
                                    else
                                    {
                                        CommonLogHelper.GetInstance("LogInfo").Error(@"无当前报警数据");
                                    }
                                    if (dataadp.ControlStatusData != null)
                                    {
                                        radarControlUI.SetControlStatus(dataadp.ControlStatusData);
                                    }
                                    else
                                    {
                                        CommonLogHelper.GetInstance("LogInfo").Error(@"无当前状态数据");
                                    }
                                    if (dataadp.RadarPowerData != null)
                                    {
                                        powerIndicationUI.SetPowerDataValue(dataadp.RadarPowerData);
                                        havePowerData = true;
                                    }
                                    else
                                    {
                                        CommonLogHelper.GetInstance("LogInfo").Error(@"无当前电源数据");
                                    }
                                    if (dataadp.AlarmStatusData != null || dataadp.ControlStatusData != null || dataadp.RadarPowerData != null)
                                    {
                                        tSSLDataUpdateTime.Text = $"数据更新时间:{obdt.ToString("yyyy-MM-dd HH:mm")}";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    CommonLogHelper.GetInstance("LogError").Error(@"数据显示到界面上出错", ex);
                                }
                            }, null);
                            CommonLogHelper.GetInstance("LogInfo").Info(@"获取数据库数据成功");

                            try
                            {
                                RadarFailureAlarm(dataadp.AlarmStatusData);
                            }
                            catch (Exception ex)
                            {
                                CommonLogHelper.GetInstance("LogError").Error(@"雷达故障报警过程出错", ex);
                            }

                            try
                            {
                                if (havePowerData)
                                {
                                    PowerDataTable nowpowerData =
                                        radarDataContext.PowerDataTable.First(x => x.DateTime == dt && x.StationID == StationId);
                                    PowerDataTable prepowerData =
                                        radarDataContext.PowerDataTable.First(
                                            x =>
                                            x.DateTime == dt.AddMinutes(-Para.UpdateDataIntl) &&
                                            x.StationID == StationId);
                                    PowerAlarm(obdt, nowpowerData, prepowerData);
                                }
                            }
                            catch (Exception ex)
                            {
                                CommonLogHelper.GetInstance("LogError").Error(@"电源跳变检查过程出错", ex);
                            }
                        }
                        catch (Exception ex)
                        {
                            CommonLogHelper.GetInstance("LogError").Error(@"提取数据库数据处理过程出错", ex);
                        }
                    })
                    {
                        IsBackground = true
                    };
                    collectProThread.Start();
                }

                #endregion 省级级别操作数据库
            }
            if (dt.Minute % 5 == 0 && dt.Second == 50)
            {
                #region 正常入库失败后批量数据补入

                Thread batchDataProcessThread = new Thread((ThreadStart) delegate
                {
                    bool dbisAvaliable = true;
                    try
                    {
                        RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(_conn);
                        radarDataContext.Connection.Open();
                        radarDataContext.Connection.Close();
                    }
                    catch (Exception)
                    {
                        dbisAvaliable = false;
                    }
                    if (dbisAvaliable)
                    {
                        DataBaseHelper dbHelper = new DataBaseHelper(_conn);
                        try
                        {
                            DataAdapter dataAdapter = new DataAdapter();
                            CommonLogHelper.GetInstance("LogInfo").Info(@"开始批量数据入库");
                            dbHelper.AlarmStatusInsert(dataAdapter.DataResolve(new DataBaseHelper().AlarmStatusSelect()));
                            dbHelper.ControlStatusInsert(
                                dataAdapter.DataResolve(new DataBaseHelper().ControlStatusSelect()));
                            dbHelper.PowerDataInsert(dataAdapter.DataResolve(new DataBaseHelper().PowerDataSelect()));
                            dbHelper.SaveChanges();
                            CommonLogHelper.GetInstance("LogInfo").Info(@"批量数据入库成功");
                            new DataBaseHelper().DeleteAllSqLiteData();
                            CommonLogHelper.GetInstance("LogInfo").Info(@"本地数据删除成功");
                        }
                        catch (Exception ex)
                        {
                            CommonLogHelper.GetInstance("LogInfo").Info(@"批量数据入库失败");
                            CommonLogHelper.GetInstance("LogError").Error(@"批量数据入库失败", ex);
                        }
                        finally
                        {
                            dbHelper.Dispose();
                        }
                    }
                })
                {
                    IsBackground = true
                };
                batchDataProcessThread.Start();

                #endregion 正常入库失败后批量数据补入
            }
        }
コード例 #9
0
        private void RecDataProcessing(byte[] message)
        {
            Thread newThread = new Thread((ThreadStart) delegate
            {
                try
                {
                    if (message.Length <= 4)
                    {
                        CommonLogHelper.GetInstance("LogInfo").Info(@"未接收到采集数据"); return;
                    }
                    if (message[0] != Convert.ToByte("7E", 16))
                    {
                        return;
                    }
                    if (message[1] != Convert.ToByte("D1", 16))
                    {
                        return;
                    }
                    string m = message[4].ToString("X2");
                    switch (m)
                    {
                    case "03":

                        #region 获取到的状态、报警、电压数据处理

                        _synchContext.Post(a => { tSSLSystemStatus.Text = @"获取最新数据成功"; }, null);
                        DateTime dt         = DateTime.Now;
                        DateTime obdt       = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0);
                        DataAdapter dataadp = new DataAdapter(StationId, obdt);
                        try
                        {
                            string msg = string.Join(" ", message.Select(x => x.ToString("X2")).ToArray());
                            CommonLogHelper.GetInstance("LogInfo").Info($@"接收到采集数据:{msg}");
                            dataadp.DataResolve(message);
                            _synchContext.Post(a =>
                            {
                                try
                                {
                                    radarStatusUI.SetAlarmStatus(dataadp.AlarmStatusData);
                                    radarControlUI.SetControlStatus(dataadp.ControlStatusData);
                                    powerIndicationUI.SetPowerDataValue(dataadp.RadarPowerData);
                                    tSSLDataUpdateTime.Text = $"数据更新时间:{obdt.ToString("yyyy-MM-dd HH:mm")}";
                                }
                                catch (Exception ex)
                                {
                                    CommonLogHelper.GetInstance("LogError").Error(@"数据显示到界面上出错", ex);
                                }
                            }, null);

                            RadarFailureAlarm(dataadp.AlarmStatusData);
                        }
                        catch (Exception e)
                        {
                            CommonLogHelper.GetInstance("LogError").Error(@"接收处理数据并显示过程出错", e);
                        }

                        if (_isCollect)
                        {
                            AlarmStatusTable alarmStatus     = dataadp.DataResolve(dataadp.AlarmStatusData);
                            ControlStatusTable controlStatus = dataadp.DataResolve(dataadp.ControlStatusData);
                            PowerDataTable powerData         = dataadp.DataResolve(dataadp.RadarPowerData);

                            try
                            {
                                DataBaseHelper dbHelper = new DataBaseHelper(_conn);
                                dbHelper.AlarmStatusInsert(alarmStatus);
                                dbHelper.ControlStatusInsert(controlStatus);
                                dbHelper.PowerDataInsert(powerData);
                                dbHelper.SaveChanges();
                                CommonLogHelper.GetInstance("LogInfo").Info(@"数据入库成功");
                            }
                            catch (Exception e)
                            {
                                CommonLogHelper.GetInstance("LogError").Error(@"数据入库过程出错", e);
                                try
                                {
                                    Lrdm.AlarmStatusModels localalarmStatus     = dataadp.LocalDataResolve(dataadp.AlarmStatusData);
                                    Lrdm.ControlStatusModels localcontrolStatus = dataadp.LocalDataResolve(dataadp.ControlStatusData);
                                    Lrdm.PowerDataModels localpowerData         = dataadp.LocalDataResolve(dataadp.RadarPowerData);

                                    DataBaseHelper dbHelper = new DataBaseHelper();
                                    dbHelper.AlarmStatusInsert(localalarmStatus);
                                    dbHelper.ControlStatusInsert(localcontrolStatus);
                                    dbHelper.PowerDataInsert(localpowerData);
                                    CommonLogHelper.GetInstance("LogInfo").Info(@"数据入本地库成功");
                                }
                                catch (Exception exception)
                                {
                                    CommonLogHelper.GetInstance("LogError").Error(@"数据入本地库过程出错", exception);
                                }
                            }

                            try
                            {
                                RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(_conn);
                                PowerDataTable prepowerData =
                                    radarDataContext.PowerDataTable.First(
                                        x =>
                                        x.DateTime == dt.AddMinutes(-Para.UpdateDataIntl) &&
                                        x.StationID == StationId);
                                PowerAlarm(obdt, powerData, prepowerData);
                            }
                            catch (Exception ex)
                            {
                                CommonLogHelper.GetInstance("LogError").Error(@"电源跳变检查报警过程出错", ex);
                            }
                        }

                        #endregion 获取到的状态、报警、电压数据处理

                        break;

                    case "81":
                        string controlmsg = string.Join(" ", message.Select(x => x.ToString("X2")).ToArray());
                        CommonLogHelper.GetInstance("LogInfo").Info($@"接收到控制数据:{controlmsg}");
                        //isContinueKeyUp = isfirsControlcmd;
                        break;
                    }
                }
                catch (Exception e)
                {
                    CommonLogHelper.GetInstance("LogError").Error(_isCollect ? @"接收处理数据并入库过程出错" : @"接收处理数据并显示过程出错", e);
                }
                finally
                {
                    _isCollect = false;
                    _synchContext.Post(a => { tSSLSystemStatus.Text = radarControlUI.Enabled ? @"正在使用控制功能" : @"等待采集数据"; }, null);
                }
            })
            {
                IsBackground = true
            };

            newThread.Start();
        }
コード例 #10
0
        private void DrawNowDataLine()
        {
            Thread drawDataLineThread = new Thread((ThreadStart) delegate
            {
                try
                {
                    _synchContext.Post(a =>
                    {
                        gbControl.Enabled          = false;
                        circularProgress.IsRunning = true;
                        circularProgress.Visible   = true;
                    }, null);
                    _powerData.Clear();
                    DateTime sdt = dtpStartTime.Value;
                    DateTime edt = dtpEndTime.Value;
                    RadarDataClassesDataContext radarDataClasses = new RadarDataClassesDataContext(ConnectionString);
                    _synchContext.Post(a =>
                    {
                        chartVolCur.Titles.Clear();
                        chartVolCur.Titles.Add(DataEnum2Titles.ToTitles(DataName));
                        chartVolCur.Titles.Add(
                            $"({sdt.ToString(CultureInfo.InvariantCulture)}——{edt.ToString(CultureInfo.InvariantCulture)})");
                        chartVolCur.ChartAreas.Clear();
                        chartVolCur.Series.Clear();
                        ChartArea ca = new ChartArea("CA1");
                        chartVolCur.ChartAreas.Add(ca);
                        Series s = new Series("S1")
                        {
                            ChartType           = SeriesChartType.Line,
                            IsValueShownAsLabel = true,
                            BorderWidth         = 3,
                            ShadowOffset        = 1
                        };
                        chartVolCur.ChartAreas[0].AxisX.IsMarginVisible    = true;
                        chartVolCur.ChartAreas[0].AxisX.Interval           = 1;
                        chartVolCur.ChartAreas[0].AxisX.MajorGrid.Interval = 1;
                        try
                        {
                            var powerdata = (from p in radarDataClasses.PowerDataTable
                                             where p.StationID == StationId &&
                                             p.DateTime >= sdt && p.DateTime <= edt
                                             orderby p.DateTime ascending
                                             select p).ToList();
                            for (int i = 0; i <= (edt - sdt).TotalMinutes; i++)
                            {
                                DateTime dt = sdt.AddMinutes(i);
                                var pd      = (from v in powerdata
                                               where v.DateTime == dt
                                               select v).Distinct().ToList();
                                if (pd.Count > 0)
                                {
                                    object obj = typeof(PowerDataTable).GetProperty(DataName).GetValue(pd[0], null);
                                    s.Points.AddXY(dt.ToString("HH:mm"), obj);
                                    _powerData.Add(dt.ToString(CultureInfo.InvariantCulture), obj.ToString());
                                }
                                else
                                {
                                    s.Points.AddXY(dt.ToString("HH:mm"), DBNull.Value);
                                    _powerData.Add(dt.ToString(CultureInfo.InvariantCulture), string.Empty);
                                }
                            }
                            chartVolCur.Series.Add(s);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }, null);
                }
                catch (Exception exception)
                {
                    CommonLogHelper.GetInstance("LogError").Error(@"实时数据查询并绘制曲线过程出错", exception);
                    _synchContext.Post(a =>
                                       MessageBox.Show(this, @"绘制当前曲线过程错误," + exception.Message, @"错误", MessageBoxButtons.OK,
                                                       MessageBoxIcon.Error)
                                       , null);
                }
                finally
                {
                    _synchContext.Post(a =>
                    {
                        gbControl.Enabled          = true;
                        circularProgress.IsRunning = false;
                        circularProgress.Visible   = false;
                    }, null);
                }
            })
            {
                IsBackground = true
            };

            drawDataLineThread.Start();
        }