Exemplo n.º 1
0
 private void btnAddAddress_Click(object sender, EventArgs e)
 {
     using (var addAddress = new FrmAddAddress())
     {
         if (addAddress.ShowDialog() == DialogResult.OK)
         {
             ManuallyAddAddress(addAddress);
         }
     }
 }
Exemplo n.º 2
0
        private void ManuallyAddAddress(FrmAddAddress frmAddAddress)
        {
            //Check if address exist
            //Get Stored Address Count
            //If more than 0
            var count = lvStoredAddresses.Items.Count;

            if (count > 0)
            {
                var found = false;
                //Loop thru the addresses
                for (var i = 0; i < count; i++)
                {
                    var address = lvStoredAddresses.Items[i].SubItems[GetColumnID(lvStoredAddresses, "cAddress")].Text;
                    address = address.Split(' ')[0];
                    //If address found
                    if (frmAddAddress.Address != address)
                    {
                        continue;
                    }
                    found = true;
                    //Edit Existing Address
                    lvStoredAddresses.Items[i].SubItems[GetColumnID(lvStoredAddresses, "cDescription")].Text = frmAddAddress.Description;
                    lvStoredAddresses.Items[i].SubItems[GetColumnID(lvStoredAddresses, "cValueType")].Text   = frmAddAddress.ValueType;
                    lvStoredAddresses.Items[i].SubItems[GetColumnID(lvStoredAddresses, "cValue")].Text       = frmAddAddress.AddressValue;
                    break;
                }

                if (!found)
                {
                    lvStoredAddresses.Items.Add(AddListViewItem(frmAddAddress.Address, frmAddAddress.Description,
                                                                frmAddAddress.ValueType,
                                                                frmAddAddress.AddressValue));
                }
            }
            else
            {
                //Else Add a new Address
                lvStoredAddresses.Items.Add(AddListViewItem(frmAddAddress.Address, frmAddAddress.Description,
                                                            frmAddAddress.ValueType,
                                                            frmAddAddress.AddressValue));
            }

            if (frmAddAddress.PokeAddress)
            {
                MySwitch.SendCommand(Commands.PokeAddress, "", frmAddAddress.Address,
                                     frmAddAddress.ValueType, frmAddAddress.AddressValue);
            }
        }