private void SettingForm_FormClosing(object sender, FormClosingEventArgs e) { if (lockstate) { MyLog.Info("载入各项配置参数"); mform.SetConfigValue("LocalIP1", textBox_LocalIP1.Text); mform.SetConfigValue("LocalPort1_ZK", textBox_LocalPort1_YK.Text); mform.SetConfigValue("LocalIP2", textBox_LocalIP2.Text); mform.SetConfigValue("Client_USRP_Ip", textBox_USRP_IP.Text); mform.SetConfigValue("Server_CRTa_Ip", textBox_CRTa_IP.Text); mform.SetConfigValue("Server_CRTa_Port", textBox_CRTa_Port.Text); mform.SetConfigValue("Server_CRTa_Port2", textBox_CRTa_Port2.Text); } else { DialogResult dr = MessageBox.Show("参数未保存,是否确定关闭此窗体?", "关闭提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.No) { e.Cancel = true; } else { e.Cancel = false; } } }
private void pictureBox1_Click(object sender, EventArgs e) { if (lockstate) { MyLog.Info("系统设置--解锁"); lockstate = false; this.pictureBox1.Image = Properties.Resources.unlocked2; foreach (Control ctr in this.Controls) { ctr.Enabled = true; } } else { MyLog.Info("系统设置--锁定"); lockstate = true; this.pictureBox1.Image = Properties.Resources.locked; foreach (Control ctr in this.Controls) { ctr.Enabled = false; } this.pictureBox1.Enabled = true; } }
private void 系统设置ToolStripMenuItem_Click(object sender, EventArgs e) { MyLog.Info("进行系统设置"); if (mySettingForm != null) { mySettingForm.Activate(); } else { mySettingForm = new SettingForm(this); } mySettingForm.ShowDialog(); }
public void FileClose() { MyLog.Info("关闭所有存盘线程"); SaveOn = false; Trace.WriteLine("Start FileClose!\n"); Thread.Sleep(500); foreach (var item in myFileList_dat) { item.Close(); } foreach (var item in myFileList_txt) { item.Close(); } }
//在主页面初始化时,调用FileInit()和FileSaveStart(),分别初始化文件夹和开始存储 /// <summary> /// 存储线程初始化 /// </summary> public void FileInit() { MyLog.Info("初始化运行日志存盘路径"); Trace.WriteLine("Start FileInit!\n"); // FileCreateTxt(Program.GetStartupPath() + @"接收\总控设备(遥控)\", out file_in1); //FileCreateTxt(Program.GetStartupPath() + @"接收\总控设备(遥测)\", out file_in2); // FileCreateTxt(Program.GetStartupPath() + @"接收\瑞信丰\", out file_in3); DataQueue_inList.Add(DataQueue_in1); DataQueue_inList.Add(DataQueue_in2); DataQueue_inList.Add(DataQueue_in3); myLockforTxt.Add(Lock_Txt1); myLockforTxt.Add(Lock_Txt2); myLockforTxt.Add(Lock_Txt3); FileCreateDat(Program.GetStartupPath() + @"接收\USRP\Telemetry\", out file_out1); FileCreateDat(Program.GetStartupPath() + @"发送\USRP\Telecmd", out file_out2); FileCreateDat(Program.GetStartupPath() + @"接收\瑞信丰\原始数据\", out file_out3); FileCreateDat(Program.GetStartupPath() + @"接收\瑞信丰\遥测数据\", out file_out4); FileCreateDat(Program.GetStartupPath() + @"发送\总控设备(遥测)\", out file_out5); //FileCreateDat(Program.GetStartupPath() + @"发送\空空\", out file_out6); //FileCreateDat(Program.GetStartupPath() + @"发送\其它舱(总控)\", out file_out7); DataQueue_outList.Add(DataQueue_out1); DataQueue_outList.Add(DataQueue_out2); DataQueue_outList.Add(DataQueue_out3); DataQueue_outList.Add(DataQueue_out4); DataQueue_outList.Add(DataQueue_out5); DataQueue_outList.Add(DataQueue_out6); DataQueue_outList.Add(DataQueue_out7); myLockforDat.Add(Lock_Dat1); myLockforDat.Add(Lock_Dat2); myLockforDat.Add(Lock_Dat3); myLockforDat.Add(Lock_Dat4); myLockforDat.Add(Lock_Dat5); myLockforDat.Add(Lock_Dat6); myLockforDat.Add(Lock_Dat7); }
private void buttonCRT_Click(object sender, EventArgs e) { Button btn = (Button)sender; switch (btn.Name) { case "btn_CRTa_Open": MyLog.Info("尝试连接--瑞信丰..."); ClientAPP.Server_CRTa_Return.ServerIP = ConfigurationManager.AppSettings["Server_CRTa_Ip"]; ClientAPP.Server_CRTa_Return.ServerPORT = ConfigurationManager.AppSettings["Server_CRTa_Port2"]; ClientAPP.Connect(ref ClientAPP.Server_CRTa_Return); if (ClientAPP.Server_CRTa_Return.IsConnected) { DealCRT_On(ref Data.DealCRTa); MyLog.Info("连接成功--" + Data.DealCRTa.CRTName + "--3070端口"); new Thread(() => { Fun_RecvFromCRT_Return(ref Data.DealCRTa, ref ClientAPP.Server_CRTa_Return); }).Start(); } else { DealCRT_Off(ref Data.DealCRTa); return; } btn_CRTa_Open.Enabled = false; btn_CRTa_Close.Enabled = true; break; case "btn_CRTa_Close": ClientAPP.Disconnect(ref ClientAPP.Server_CRTa); ClientAPP.Disconnect(ref ClientAPP.Server_CRTa_Return); btn_CRTa_Open.Enabled = true; btn_CRTa_Close.Enabled = false; Data.DealCRTa.LedOff(); MyLog.Info("关闭连接--瑞信丰"); break; default: break; } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { try { if (btn_ZK1_Close.Enabled) { btn_ZK1_Close_Click(sender, e); } if (btn_ZK1_YC_Close.Enabled) { btn_ZK1_YC_Close_Click(sender, e); } if (btn_CRTa_Open.Enabled == false) { ClientAPP.Disconnect(ref ClientAPP.Server_CRTa); ClientAPP.Disconnect(ref ClientAPP.Server_CRTa_Return); btn_CRTa_Open.Enabled = true; btn_CRTa_Close.Enabled = false; Data.DealCRTa.LedOff(); MyLog.Info("关闭连接--USB应答机A"); } Thread.Sleep(100); mySaveFileThread.FileClose(); ServerLedThreadTag = false; ServerLedThreadTag2 = false; Data.ServerConnectEvent.Set(); Data.ServerConnectEvent2.Set(); Data.AllThreadTag = false; } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
private void button5_Click(object sender, EventArgs e) { openFileDialog1.InitialDirectory = Program.GetStartupPath() + @"配置文件\chartform配置文件\"; string openpath = ""; if (openFileDialog1.ShowDialog() == DialogResult.OK) { // openFileDialog1.InitialDirectory = Program.GetStartupPath() + @"LogData\"; try { openpath = openFileDialog1.FileName; } catch { MyLog.Info("配置文件打开失败"); return; } } string str = Application.StartupPath; TextReader reader = new StreamReader(openpath); string line; line = reader.ReadLine(); while (line != "" && line != null) { string[] gettablename = line.Split(':'); String TableName = "table_" + gettablename[0] + "_解析值"; //要查询的数据库的名称 String SelectColum = gettablename[1]; //对应数据库中的列(就是选中的项的名称) String TableparentName = gettablename[0] + "_解析值"; //数据库名字 //查询数据库时的限定语句(时间限定) string Str_Condition_time = "CreateTime >= '" + dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'" + "and CreateTime <= '" + dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'"; //最终查询数据库的cmd语句 string cmd = "Select CreateTime,[" + SelectColum + "] From " + TableName + " where " + Str_Condition_time; SQLiteDataAdapter mAdapter = new SQLiteDataAdapter(cmd, dbConnection); DataTable mTable = new DataTable(); // Don't forget initialize!新建1个DataTable类型 mAdapter.Fill(mTable); //将数据库中取出内容填到DataTable中 DataTable showtable = new DataTable(); DataView dv = mTable.DefaultView; dv.Sort = "CreateTime desc"; showtable = dv.ToTable(); dataGridView1.DataSource = showtable; //将DataTable数据与dataGridview绑定 double[] x = new double[mTable.Rows.Count]; //x轴 double[] y = new double[mTable.Rows.Count]; try { //循环将DataTable中的时间和数值赋予x和y数组 for (int j = 0; j < mTable.Rows.Count; j++) { // Trace.WriteLine(mTable.Rows[j]["CreateTime"] + ":" + mTable.Rows[j][SelectColum]); DateTime time = Convert.ToDateTime(mTable.Rows[j]["CreateTime"]); x[j] = (double)new XDate(time); string value = (string)mTable.Rows[j][SelectColum]; y[j] = double.Parse(value); } } catch { TableparentName = gettablename[0] + "_源码"; //数据库名字 TableName = "table_" + gettablename[0] + "_源码"; //要查询的数据库的名称 SelectColum = gettablename[1]; //对应数据库中的列(就是选中的项的名称) //根据此处的APID-内容,进行下一步解析和处理 //查询数据库时的限定语句(时间限定) Str_Condition_time = "CreateTime >= '" + dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'" + "and CreateTime <= '" + dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'"; //最终查询数据库的cmd语句 cmd = "Select CreateTime,[" + SelectColum + "] From " + TableName + " where " + Str_Condition_time; mAdapter = new SQLiteDataAdapter(cmd, dbConnection); DataTable yuanmamTable = new DataTable(); // Don't forget initialize!新建1个DataTable类型 mAdapter.Fill(yuanmamTable); //将数据库中取出内容填到DataTable中 x = new double[yuanmamTable.Rows.Count];//x轴 y = new double[yuanmamTable.Rows.Count]; for (int j = 0; j < yuanmamTable.Rows.Count; j++) { // Trace.WriteLine(mTable.Rows[j]["CreateTime"] + ":" + mTable.Rows[j][SelectColum]); DateTime time = Convert.ToDateTime(yuanmamTable.Rows[j]["CreateTime"]); x[j] = (double)new XDate(time); string value = (string)yuanmamTable.Rows[j][SelectColum]; y[j] = Convert.ToInt64(value.Substring(2, value.Length - 2), 16); } } string showSelectColum = gettablename[0] + ":" + SelectColum; bool samecurveflag = false; for (int m = 0; m < z1.GraphPane.CurveList.Count; m++) { CurveItem mycurve = z1.GraphPane.CurveList[m]; if (mycurve.Label.Text == showSelectColum) { PointPairList list = mycurve.Points as PointPairList; #region 除曲线中时间以前的点 if (x.Length == 0) { list.Clear(); } else { double fisttime = x[0]; for (int j = 0; j < list.Count; j++) { if (list[j].X < fisttime) { list.Clear(); break; } } } #endregion double lasttime = list[list.Count - 1].X; for (int j = 0; j < x.Length; j++) { if (x[j] > lasttime) { list.Add(x[j], y[j]); } } samecurveflag = true; break; } } if (!samecurveflag) { z1.GraphPane.AddCurve(showSelectColum, x, y, ChooseColor(), ZedGraph.SymbolType.None);//显示曲线 } samecurveflag = false; int t = z1.GraphPane.CurveList.Count; for (int m = 0; m < t; m++) { CurveItem mycurve = z1.GraphPane.CurveList[m]; Trace.WriteLine(mycurve.Label); } z1.AxisChange(); z1.Invalidate(); comboBox1.Items.Add(showSelectColum); line = reader.ReadLine(); } }
/// <summary> /// 接受USRP的遥测数据 /// </summary> /// <param name="ClientSocket"></param> private void RecvFromClientUSRP(object ClientSocket) { Trace.WriteLine("RecvFromUSRP_telemetry!!"); Socket myClientSocket = (Socket)ClientSocket; while (ServerOn_YC && myClientSocket.Connected) { try { byte[] RecvBufZK1 = new byte[2048]; int RecvNum = myClientSocket.Receive(RecvBufZK1); if (RecvNum > 0) { String tempstr = ""; byte[] RecvBufToFile = new byte[RecvNum]; for (int i = 0; i < RecvNum; i++) { RecvBufToFile[i] = RecvBufZK1[i]; tempstr += RecvBufZK1[i].ToString("x2"); } Trace.WriteLine(tempstr); string timestr = string.Format("{0}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); Data.TelemetryRealShowBox.BeginInvoke( new Action(() => { Data.TelemetryRealShowBox.AppendText(timestr + "\n" + tempstr + "\n"); })); //存储从USRP发来的遥测数据 SaveFile.DataQueue_out1.Enqueue(RecvBufToFile); //数据库存储 IPEndPoint tmppoint = (IPEndPoint)myClientSocket.RemoteEndPoint; String RemoteIpStr = tmppoint.Address.ToString(); if (RecvNum > 22) { MyLog.Info("收到遥测数据量:" + RecvNum.ToString()); try { deal_zk_data(RecvBufZK1, RecvNum, timestr, RemoteIpStr); } catch (Exception e) { Trace.WriteLine("RecvFromClientZK_YC--deal_zk_data Exception:" + e.Message); } Data.dtUSRP.Rows[0][1] = (int)Data.dtUSRP.Rows[0][1] + 1; } else { MyLog.Error("收到遥测数据帧长度异常:" + RecvNum.ToString()); } } else { Trace.WriteLine("收到数据少于等于0!"); break; } } catch (Exception e) { Trace.WriteLine("RecvFromClientZK_YC Exception:" + e.Message); if (myClientSocket.Connected) { myClientSocket.Shutdown(SocketShutdown.Both); myClientSocket.Close(); } ClientAPP.ClientUSRP_Telemetry.IsConnected = false; break; } } if (myClientSocket.Connected) { Trace.WriteLine("服务器主动关闭socket!"); myClientSocket.Shutdown(SocketShutdown.Both); myClientSocket.Close(); } ClientAPP.ClientUSRP_Telemetry.IsConnected = false; Trace.WriteLine("leave Server YC!!"); Data.ServerConnectEvent2.Set(); }
void DealCRT_On(ref Data.CRT_STRUCT myCRT) { myCRT.LedOn(); MyLog.Info("连接成功--" + myCRT.CRTName); }
private void button2_Click(object sender, EventArgs e) { string fileName = ""; string saveFileName = ""; SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.DefaultExt = "xlsx"; saveDialog.Filter = "Excel文件|*.xlsx"; saveDialog.FileName = fileName; String Path = Program.GetStartupPath() + @"数据库导出\"; if (!Directory.Exists(Path)) { Directory.CreateDirectory(Path); } saveDialog.InitialDirectory = Path; saveDialog.ShowDialog(); saveFileName = saveDialog.FileName; if (saveFileName.IndexOf(":") < 0) { return; //被点了取消 } Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); if (xlApp == null) { //MessageBox.Show("无法创建Excel对象,您的电脑可能未安装Excel"); MyLog.Error("无法创建Excel对象,您的电脑可能未安装Excel"); return; } Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks; Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet); Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1]; //取得sheet1 //写入标题 for (int i = 0; i < dataGridView1.ColumnCount; i++) { worksheet.Cells[1, i + 1] = dataGridView1.Columns[i].HeaderText; } //写入数值 for (int r = 0; r < dataGridView1.Rows.Count; r++) { for (int i = 0; i < dataGridView1.ColumnCount; i++) { worksheet.Cells[r + 2, i + 1] = dataGridView1.Rows[r].Cells[i].Value; } System.Windows.Forms.Application.DoEvents(); } worksheet.Columns.EntireColumn.AutoFit();//列宽自适应 //MessageBox.Show(fileName + "资料保存成功", "提示", MessageBoxButtons.OK); MyLog.Info(fileName + "资料保存成功"); if (saveFileName != "") { try { workbook.Saved = true; workbook.SaveCopyAs(saveFileName); //fileSaved = true; } catch (Exception ex) {//fileSaved = false; //MessageBox.Show("导出文件时出错,文件可能正被打开!\n" + ex.Message); MyLog.Error("导出文件时出错,文件可能正被打开!\n" + ex.Message); } } xlApp.Quit(); GC.Collect();//强行销毁 }