/// <summary> /// Checks the checked cell state, if it's checked it adds it to the LLP List if not it removes it. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvLLP_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (dgvLLP.Columns[e.ColumnIndex].Name == "cSelect") { DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgvLLP.Rows[e.RowIndex].Cells["cSelect"]; bool cellChecked = (Boolean)checkCell.Value; string hex = dgvLLP.Rows[e.RowIndex].Cells[0].Value.ToString(); if (cellChecked) { LLPList.Add(LLP.LoadLLP(hex)); } else { LLPList.Remove(LLP.LoadLLP(hex)); } } } catch (Exception ex) { Log.LogException(ex).ShowDialog(); } }
/// <summary> /// Pulls the LLP Char Value based on the Hex code passed in /// </summary> /// <param name="s">The hex code to search for</param> /// <returns>The LLP Char Value</returns> public static string GetLLPString(string s) { StringBuilder sb = new StringBuilder(); Regex reg = new Regex("\\[0x[A-Za-z0-9]+\\]"); MatchCollection matches = reg.Matches(s); foreach (Match match in matches) { LLP l = LoadLLP(match.Value); sb.Append(l.CharValue); } return(sb.ToString()); }
/// <summary> /// Initialization Method: Loads the LLP List and sets the List View to the values returned. /// </summary> public frmLLP() { InitializeComponent(); try { foreach (LLP l in LLP.LoadLLPList()) { List <object> objs = new List <object>(); objs.Add((object)l.Hex); objs.Add((object)l.Description); dgvLLP.Rows.Add(objs.ToArray()); } } catch (Exception ex) { Log.LogException(ex).ShowDialog(); } }
/// <summary> /// Save Button Click Event: Saves the TCP/IP Options to File /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { try { if (!String.IsNullOrEmpty(txtName.Text)) { IPAddress ip = ParseHostAddress(txtHostAddress.Text); int port = ParsePort(txtPort.Text); if (ip != null) { if (port != 0) { OptionsName = txtName.Text; TCPIPOps.HostAddress = ip; TCPIPOps.Port = port; TCPIPOps.LLPHeader = LLP.GetLLPString(txtHeader.Text); TCPIPOps.LLPTrailer = LLP.GetLLPString(txtTrailer.Text); TCPIPOps.WaitForAck = cbWaitForAck.Checked; TCPIPOps.SendAck = cbSendAck.Checked; this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("Please Add Port."); } } else { MessageBox.Show("Please Add Host Address."); } } else { MessageBox.Show("Please Enter a Unique Name for this Connection."); } } catch (Exception ex) { Log.Instance.LogException(ex).Report(); } }
/// <summary> /// Pulls an LLP Object from the list of LLP objects /// </summary> /// <param name="_Hex">The Hex Value of the Char Code</param> /// <returns>Returns the LLP object</returns> public static LLP LoadLLP(string _Hex) { LLP llp = LoadLLPList().Find(delegate(LLP l) { return(l.Hex == _Hex); }); return(llp); }