cancel should also cancel auto-filled lastIP values

The problem is seen in the first puzzle if you ping
       pc0, and then edit the 0.0.0.0 gateway.   It auto-fills in
       the last-used pc0 IP address, and canceling saves that change
       instead of leaving the gateway at 0.0.0.0.

       lastIP nicely saves some typing (although it has also confused
       my student quite a bit I think), but since it updates WhatToEdit,
       that becomes the "saved" value even during a cancel.

       Instead, save the original value as a copy, and set back to
       the original value when cancellng.

       Perhaps it would be worth creating a reparse( NB_IPAddress)
       function, but this was easy to just hack together.

       Tested by pinging pc0, then editing the gateway and cancellng,
       editing the IP address and canceling.

       Next: don't add a canceled route
This commit is contained in:
Tim Young 2019-02-23 12:11:20 -06:00
parent ddebafeec9
commit 06eb896558
1 changed files with 5 additions and 0 deletions

View File

@ -21,6 +21,8 @@ namespace EduNetworkBuilder
NetworkDevice ParentDevice = null;
Point StartLocation = new Point (50,50);
NB_IPAddress SavedIPAddress = null;
public IPAddressEntry(NB_IPAddress toEdit, NetworkDevice ToEdit, Form ParentForm, bool JustPinging=false)
{
@ -34,6 +36,7 @@ namespace EduNetworkBuilder
ParentDevice = ToEdit;
Network myNet = NB.GetNetwork();
NB_IPAddress lastIP = myNet.RetrieveLastIP();
SavedIPAddress = new NB_IPAddress(toEdit);
WhatToEdit = toEdit;
string hostname = "";
if (ToEdit != null)
@ -182,6 +185,8 @@ namespace EduNetworkBuilder
private void btnCancel_Click(object sender, EventArgs e)
{
if(SavedIPAddress != null)
WhatToEdit.Reparse(SavedIPAddress.GetIPString, SavedIPAddress.GetMaskString, SavedIPAddress.GetGateway.ToIpString());
UpdateFieldsFromAddress();
WellDone = false;
Close();