public static void ReadAndWrite(string iAFN, string iFN, string iValues) { string pN = InputPN.GetPN(iAFN, iFN); Program.gList.Clear(); DataGridView gridV = MainForm.gMainForm.gAddressList.GridV; checked { for (int i = 0; i < gridV.Rows.Count; i++) { Program.AddList item = default(Program.AddList); if (!gridV.Rows[i].IsNewRow) { item.Checked = Convert.ToBoolean(gridV.Rows[i].Cells[0].Value); item.A1 = Convert.ToString(gridV.Rows[i].Cells[2].Value); item.A2 = Convert.ToString(gridV.Rows[i].Cells[3].Value); item.Mode = Program.GetLeiXing(Convert.ToString(gridV.Rows[i].Cells[4].Value)); Program.gList.Add(item); } } if (Program.gList.Count == 0) { MessageBox.Show("请先初始化终端列表 !", "失败", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { OtherOpera.dlt.AFN = iAFN; OtherOpera.dlt.FN = iFN; OtherOpera.dlt.PN = pN; OtherOpera.dlt.SendMSG = iValues; OtherOpera.dlt.ListenPort = Program.gPort; OtherOpera.dlt.CID = Program.CID; OtherOpera.dlt.Tp = Program.Tp; OtherOpera.dlt.PW = Program.PW; OtherOpera.dlt.Flag = Program.Flag; OtherOpera.dlt.ReadTimeout = Program.ReadTimeout; new Thread(new ThreadStart(OtherOpera.Run)) { IsBackground = true }.Start(); } } }
private void ToolStripButton1Click(object sender, EventArgs e) { checked { if (string.IsNullOrEmpty(this.toolStripTextBox2.Text)) { MessageBox.Show("请选择抄读规约"); } else { this.toolStripButton1.Enabled = false; string text = string.Empty; text += this.OperaSend(this.toolStripComboBox1.Text, 1, "BIN"); string str = string.Empty; try { str = this.toolStripButton2.Text.Split(new char[] { '-' })[1]; } catch { goto IL_7CE; } text += str; int num = 0; text += (num | 30).ToString("X2"); text += this.OperaSend("30", 1, "BIN"); string text2 = this.Get645Frame(); text += DataConvert.ReverseStr((text2.Trim().Length / 2).ToString("X4")); text += text2.Trim(); if (text2.Trim().Length != 0) { this.dlt.AFN = "10"; this.dlt.FN = "0001"; this.dlt.PN = InputPN.GetPN("10", "0001"); this.dlt.SendMSG = text; this.dlt.ListenPort = Program.gPort; this.dlt.CID = Program.CID; this.dlt.Tp = Program.Tp; this.dlt.PW = Program.PW; this.dlt.Flag = Program.Flag; this.dlt.ReadTimeout = Program.ReadTimeout; Program.gList.Clear(); DataGridView gridV = MainForm.gMainForm.gAddressList.GridV; for (int i = 0; i < gridV.Rows.Count; i++) { Program.AddList item = default(Program.AddList); if (!gridV.Rows[i].IsNewRow) { item.Checked = Convert.ToBoolean(gridV.Rows[i].Cells[0].Value); item.A1 = Convert.ToString(gridV.Rows[i].Cells[2].Value); item.A2 = Convert.ToString(gridV.Rows[i].Cells[3].Value); item.Mode = Program.GetLeiXing(Convert.ToString(gridV.Rows[i].Cells[4].Value)); Program.gList.Add(item); } } if (Program.gList.Count == 0) { MessageBox.Show("请先初始化终端列表 !", "失败", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { int port = 0; string temp = ""; Application.DoEvents(); for (int i = 0; i < Program.gList.Count; i++) { Application.DoEvents(); if (Program.gList[i].Checked) { if (Program.gList[i].Mode == ComunicationType.Serial) { this.dlt.FrameDelay = 5; this.dlt.Delay = Program.gDelay; port = Program.gComPort; temp = Program.gCommSetting; } else { if (Program.gList[i].Mode == ComunicationType.TCPMyisServer) { this.dlt.FrameDelay = Program.gDelay; this.dlt.Delay = Program.gDelay; this.dlt.m_Port = Program.GetSocket(Program.gList[i].Mode, Program.gList[i].A1, Program.gList[i].A2); } else { if (Program.gList[i].Mode == ComunicationType.TCPMyisClient) { this.dlt.FrameDelay = Program.gDelay; this.dlt.Delay = Program.gDelay; port = Program.RemotePort; temp = Program.RemoteIP; this.dlt.m_Port = Program.GetSocket(Program.gList[i].Mode, Program.gList[i].A1, Program.gList[i].A2); } else { if (Program.gList[i].Mode == ComunicationType.UDP) { this.dlt.FrameDelay = 5; this.dlt.Delay = Program.gDelay; } } } } this.dlt.OperType = Program.gList[i].Mode; bool flag = (this.dlt.OperType == ComunicationType.UDP) ? this.dlt.Open(Program.UdpOpera, Program.UDP_Port_Send, Program.UDP_Port_Recieve, Program.UDP_RemoteAddress) : this.dlt.Open(port, temp); if (flag) { this.dlt.A1 = Program.gList[i].A1; this.dlt.A2 = Program.gList[i].A2; this.dlt.MSA = Program.MSA; bool flag2 = this.dlt.SendData(); string receiveMSG = this.dlt.ReceiveMSG; string caption = "A1=" + this.dlt.A1 + ",A2=" + this.dlt.A2; if (string.IsNullOrEmpty(receiveMSG)) { MessageBox.Show("无数据返回"); break; } if (receiveMSG.ToUpper().IndexOf("ERROR") >= 0 | receiveMSG.ToUpper().IndexOf("确认") >= 0 | receiveMSG.ToUpper().IndexOf("否认") >= 0) { MessageBox.Show(receiveMSG.ToString(), caption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); break; } this.gAS.DoInfo("10", "0001", receiveMSG, false, "", this.toolStripLabel3.Text); this.grid3.Rows.Clear(); for (int j = 0; j < this.gAS.ItemData.Count; j++) { if (!string.IsNullOrEmpty(this.gAS.ItemData[j].Items)) { this.grid3.Rows.Add(); this.grid3.Rows[j].Cells[0].Value = this.gAS.ItemData[j].Items; this.grid3.Rows[j].Cells[1].Value = this.gAS.ItemData[j].Values; } } } Application.DoEvents(); } } } } IL_7CE: this.dlt.Close(); this.toolStripButton1.Enabled = true; } } }
private void 数据点抄ToolStripMenuItemClick(object sender, EventArgs e) { this.grid1.EndEdit(); Program.gList.Clear(); DataGridView gridV = MainForm.gMainForm.gAddressList.GridV; checked { for (int i = 0; i < gridV.Rows.Count; i++) { Program.AddList item = default(Program.AddList); if (!gridV.Rows[i].IsNewRow) { item.Checked = Convert.ToBoolean(gridV.Rows[i].Cells[0].Value); item.A1 = Convert.ToString(gridV.Rows[i].Cells[2].Value); item.A2 = Convert.ToString(gridV.Rows[i].Cells[3].Value); item.Mode = Program.GetLeiXing(Convert.ToString(gridV.Rows[i].Cells[4].Value)); Program.gList.Add(item); } } if (Program.gList.Count == 0) { MessageBox.Show("请先初始化终端列表 !", "失败", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { int port = 0; string temp = ""; Application.DoEvents(); for (int i = 0; i < Program.gList.Count; i++) { Application.DoEvents(); if (Program.gList[i].Checked) { if (Program.gList[i].Mode == 0) { this.dlt.FrameDelay = 5; this.dlt.Delay = Program.gDelay; port = Program.gComPort; temp = Program.gCommSetting; } else { if (Program.gList[i].Mode == ComunicationType.TCPMyisServer) { this.dlt.FrameDelay = Program.gDelay; this.dlt.Delay = Program.gDelay; this.dlt.m_Port = Program.GetSocket(Program.gList[i].Mode, Program.gList[i].A1, Program.gList[i].A2); } else { if (Program.gList[i].Mode == ComunicationType.TCPMyisClient) { this.dlt.FrameDelay = Program.gDelay; this.dlt.Delay = Program.gDelay; port = Program.RemotePort; temp = Program.RemoteIP; this.dlt.m_Port = Program.GetSocket(Program.gList[i].Mode, Program.gList[i].A1, Program.gList[i].A2); } } } this.dlt.OperType = Program.gList[i].Mode; bool flag = this.dlt.Open(port, temp); if (flag) { DataGridViewRow currentRow = this.grid1.CurrentRow; if (currentRow is CollapseDataGridViewRow) { this.dlt.AFN = "10"; this.dlt.FN = "0009"; this.dlt.PN = InputPN.GetPN("10", "0009"); this.dlt.SendMSG = this.GetSendText(currentRow); this.dlt.ListenPort = Program.gPort; this.dlt.CID = Program.CID; this.dlt.Tp = Program.Tp; this.dlt.PW = Program.PW; this.dlt.Flag = Program.Flag; this.dlt.A1 = Program.gList[i].A1; this.dlt.A2 = Program.gList[i].A2; this.dlt.MSA = Program.MSA; bool flag2 = this.dlt.SendData(); string text = this.dlt.ReceiveMSG; if (flag2) { text = this.dlt.ReceiveMSG; } else { text = "Error"; } if (!string.IsNullOrEmpty(text)) { if (string.IsNullOrEmpty(text) | text.ToUpper().IndexOf("ERROR") >= 0 | text.ToUpper().IndexOf("确认") >= 0 | text.ToUpper().IndexOf("否认") >= 0) { this.AddData(currentRow as CollapseDataGridViewRow, text, ""); } else { DLT698_Recv dLT698_Recv = new DLT698_Recv(); dLT698_Recv.DoInfo("10", "0009", text, false, "", Convert.ToString(currentRow.Cells[4].Value)); this.AddData(currentRow as CollapseDataGridViewRow, text, dLT698_Recv.AF10_F9_Val); } } } Application.DoEvents(); } } } } this.dlt.Close(); } }
private void ToolStripButton1Click(object sender, EventArgs e) { this.toolStripButton1.Enabled = false; this.toolStripButton4.Enabled = true; this.RunCB = true; this.grid1.EndEdit(); Program.gList.Clear(); DataGridView gridV = MainForm.gMainForm.gAddressList.GridV; checked { for (int i = 0; i < gridV.Rows.Count; i++) { Program.AddList item = default(Program.AddList); if (!gridV.Rows[i].IsNewRow) { item.Checked = Convert.ToBoolean(gridV.Rows[i].Cells[0].Value); item.A1 = Convert.ToString(gridV.Rows[i].Cells[2].Value); item.A2 = Convert.ToString(gridV.Rows[i].Cells[3].Value); item.Mode = Program.GetLeiXing(Convert.ToString(gridV.Rows[i].Cells[4].Value)); Program.gList.Add(item); } } if (Program.gList.Count == 0) { MessageBox.Show("请先初始化终端列表 !", "失败", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { int port = 0; string temp = ""; Application.DoEvents(); for (int i = 0; i < Program.gList.Count; i++) { Application.DoEvents(); if (Program.gList[i].Checked) { if (Program.gList[i].Mode == 0) { this.dlt.FrameDelay = 5; this.dlt.Delay = Program.gDelay; this.dlt.ReadTimeout = Program.ReadTimeout; port = Program.gComPort; temp = Program.gCommSetting; } else { if (Program.gList[i].Mode == ComunicationType.TCPMyisServer) { this.dlt.FrameDelay = Program.gDelay; this.dlt.Delay = Program.gDelay; this.dlt.m_Port = Program.GetSocket(Program.gList[i].Mode, Program.gList[i].A1, Program.gList[i].A2); } else { if (Program.gList[i].Mode == ComunicationType.TCPMyisClient) { this.dlt.FrameDelay = Program.gDelay; this.dlt.Delay = Program.gDelay; port = Program.RemotePort; temp = Program.RemoteIP; this.dlt.m_Port = Program.GetSocket(Program.gList[i].Mode, Program.gList[i].A1, Program.gList[i].A2); } else { if (Program.gList[i].Mode == ComunicationType.UDP) { this.dlt.FrameDelay = 5; this.dlt.Delay = Program.gDelay; } } } } this.dlt.OperType = Program.gList[i].Mode; bool flag = (this.dlt.OperType == ComunicationType.UDP) ? this.dlt.Open(Program.UdpOpera, Program.UDP_Port_Send, Program.UDP_Port_Recieve, Program.UDP_RemoteAddress) : this.dlt.Open(port, temp); if (flag) { for (int j = 0; j < int.Parse(this.toolStripTextBox1.Text); j++) { foreach (DataGridViewRow dataGridViewRow in (IEnumerable)this.grid1.Rows) { if (dataGridViewRow is CollapseDataGridViewRow) { if (!this.RunCB) { goto IL_7B3; } if (Convert.ToBoolean(dataGridViewRow.Cells[0].Value)) { this.dlt.AFN = "10"; this.dlt.FN = "0009"; this.dlt.PN = InputPN.GetPN("10", "0009"); this.dlt.SendMSG = this.GetSendText(dataGridViewRow); this.dlt.ListenPort = Program.gPort; this.dlt.CID = Program.CID; this.dlt.Tp = Program.Tp; this.dlt.PW = Program.PW; this.dlt.Flag = Program.Flag; this.dlt.A1 = Program.gList[i].A1; this.dlt.A2 = Program.gList[i].A2; this.dlt.MSA = Program.MSA; bool flag2 = this.dlt.SendData(); string text = this.dlt.ReceiveMSG; if (flag2) { text = this.dlt.ReceiveMSG; } else { text = "Error"; } if (!string.IsNullOrEmpty(text)) { if (string.IsNullOrEmpty(text) | text.ToUpper().IndexOf("ERROR") >= 0 | text.ToUpper().IndexOf("确认") >= 0 | text.ToUpper().IndexOf("否认") >= 0) { this.AddData(dataGridViewRow as CollapseDataGridViewRow, text, ""); Program.gDBDataBase.InsertDataAF10F9(this.dlt.A1, this.dlt.A2, Convert.ToString(dataGridViewRow.Cells[2].Value), "数据转发", "F9 数据直抄", "00", "0009", "0000", text, text); if (text.ToUpper().IndexOf("ERROR") >= 0) { Thread.Sleep(Program.LC_ERR * 1000); } } else { DLT698_Recv dLT698_Recv = new DLT698_Recv(); dLT698_Recv.DoInfo("10", "0009", text, false, "", Convert.ToString(dataGridViewRow.Cells[4].Value)); this.AddData(dataGridViewRow as CollapseDataGridViewRow, text, dLT698_Recv.AF10_F9_Val); Program.gDBDataBase.InsertDataAF10F9(this.dlt.A1, this.dlt.A2, Convert.ToString(dataGridViewRow.Cells[2].Value), "数据转发", "F9 数据直抄", "00", "0009", "0000", text, dLT698_Recv.AF10_F9_Val); } } } Application.DoEvents(); } } Thread.Sleep(Program.LC_JG * 1000); } } } } } IL_7B3: this.dlt.Close(); this.toolStripButton1.Enabled = true; this.toolStripButton4.Enabled = false; this.RunCB = false; } }