public void RemoveNetwork(Network n)
 {
     try
     {
         connection = new SQLiteConnection("Data Source=" + dbpath + ";Version=3; foreign keys=true;");
         connection.Open();
         command = new SQLiteCommand(connection);
         //Delete Network
         command.CommandText = "DELETE FROM network WHERE networkNumber=@nnr ;";
         command.Parameters.AddWithValue("@nnr", n.NetworkNumber);
         command.ExecuteNonQuery();
         //drop old ip addresses
         /*command.CommandText = "DELETE FROM networkipadress WHERE networkNumber=@nnr ;";
         command.Parameters.AddWithValue("@nnr", n.NetworkNumber);
         command.ExecuteNonQuery();*/
         Log.WriteLog(string.Format("Network {0} deleted in database.", n.Name));
     }
     catch (Exception e)
     {
         MessageBox.Show("Error SQL Write Network", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Log.WriteLog(e.Message);
     }
     connection.Close();
 }
 public void SaveNetwork(Network n, NetworkInventory ni)
 {
     try
     {
         //Create Progress Form
         FormProgress fp = new FormProgress();
         //Create Query
         connection = new SQLiteConnection("Data Source=" + dbpath + ";Version=3; foreign keys=true;");
         connection.Open();
         command = new SQLiteCommand(connection);
         command.CommandText = "INSERT INTO network (networkNumber, name, inputtype, networkInventoryNumber) VALUES(@networkNumber, @name, @inputtype, @networkInventoryNumber);";
         command.Parameters.AddWithValue("@networkNumber", n.NetworkNumber);
         command.Parameters.AddWithValue("@name", n.Name);
         command.Parameters.AddWithValue("@inputtype", n.InputType);
         command.Parameters.AddWithValue("@networkInventoryNumber", ni.NetworkInventoryNumber);
         command.ExecuteNonQuery();
         SQLiteTransaction transaction = connection.BeginTransaction();
         //Initialize Progress Form
         fp.SetMax(n.IpAddresses.Count);
         fp.Show();
         foreach (IPAddress ip in n.IpAddresses)
         {
             try
             {//Write IP to table, if it is already there, throw exception
                 command.CommandText = "INSERT INTO ipaddresses (ipaddress) VALUES(@ipaddress);";
                 command.Parameters.AddWithValue("@ipaddress", ip.ToString());
                 command.ExecuteNonQuery();
                 //Log.WriteLog("IPAddress {0} saved to database", ip.ToString());
             }
             catch (Exception e)
             {
                 Log.WriteLog("Error writing IP to DB: " + e.Message);
             }
             try
             {//Connect ip to netwok in database
                 command.CommandText = "INSERT INTO networkipadress (networkNumber, ipaddress) VALUES(@networkNumber, @ipaddress);";
                 command.Parameters.AddWithValue("@networkNumber", n.NetworkNumber);
                 command.Parameters.AddWithValue("@ipaddress", ip.ToString());
                 command.ExecuteNonQuery();
                 //Log.WriteLog("IPaddress {0} connected to network {1} in database.", ip.ToString(), n.Name);
             }
             catch (Exception e)
             {
                 Log.WriteLog("Error writing IP/NW to DB: " + e.Message);
             }
             fp.Progress();
         }
         transaction.Commit();
         Log.WriteLog(string.Format("Network {0} saved to database.", n.Name));
         fp.Close();
     }
     catch (Exception e)
     {
         MessageBox.Show("Error SQL Write Network", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Log.WriteLog(e.Message);
     }
     connection.Close();
 }
 public void UpdateNetwork(Network n)
 {
     try
     {
         //Create Progress Form
         FormProgress fp = new FormProgress();
         //Create Query
         connection = new SQLiteConnection("Data Source=" + dbpath + ";Version=3; foreign keys=true;");
         connection.Open();
         command = new SQLiteCommand(connection);
         command.CommandText = "UPDATE network SET name=@name, inputtype=@inputtype WHERE networkNumber=@nnr ;";
         command.Parameters.AddWithValue("@nnr", n.NetworkNumber);
         command.Parameters.AddWithValue("@name", n.Name);
         command.Parameters.AddWithValue("@inputtype", n.InputType);
         command.ExecuteNonQuery();
         //drop old ip address connection to this network
         command.CommandText = "DELETE FROM networkipadress WHERE networkNumber=@nnr ;";
         command.Parameters.AddWithValue("@nnr", n.NetworkNumber);
         //initialize Progress Form
         fp.SetMax(n.IpAddresses.Count);
         fp.Show();
         //Add new ip-Addresses
         SQLiteTransaction transaction = connection.BeginTransaction();
         foreach (IPAddress ip in n.IpAddresses)
         {
             try
             {//Write IP to table, if it is already there, throw exception
                 command.CommandText = "INSERT INTO ipaddresses (ipaddress) VALUES(@ipaddress);";
                 command.Parameters.AddWithValue("@ipaddress", ip.ToString());
                 command.ExecuteNonQuery();
             }
             catch (Exception e)
             {
                 Log.WriteLog("Error writing IP to DB: " + e.Message);
             }
             try
             {//Connect ip to netwok in database
                 command.CommandText = "INSERT INTO networkipadress (networkNumber, ipaddress) VALUES(@networkNumber, @ipaddress);";
                 command.Parameters.AddWithValue("@networkNumber", n.NetworkNumber);
                 command.Parameters.AddWithValue("@ipaddress", ip.ToString());
                 command.ExecuteNonQuery();
             }
             catch (Exception e)
             {
                 Log.WriteLog("Error writing IP/NW to DB: " + e.Message);
             }
             fp.Progress();
         }
         transaction.Commit();
         Log.WriteLog(string.Format("Network {0} changed in database.", n.Name));
         fp.Close();
     }
     catch (Exception e)
     {
         MessageBox.Show("Error SQL Write Network", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Log.WriteLog(e.Message);
     }
     connection.Close();
 }
        public void RemoveNetwork(Object selectedNetwork)
        {
            if (selectedNetwork == null)
            {
                MessageBox.Show("Kein Netzwerk ausgewählt. Bitte zuerst ein Netzwerk auswählen.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                this.selectedNetwork = (Network)selectedNetwork;
                DialogResult dr = MessageBox.Show(String.Format("Soll das Netzwerk {0} unwiderruflich gelöscht werden?", this.selectedNetwork.Name), "Netzwerk löschen", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    for (int i = 0; i < currentNetworkInventory.List_networks.Count; i++)
                    {
                        Network n = (Network)currentNetworkInventory.List_networks[i];
                        if (n.NetworkNumber == this.selectedNetwork.NetworkNumber)
                        {
                            currentNetworkInventory.List_networks.Remove(n);
                            i = currentNetworkInventory.List_networks.Count;
                        }
                    }
                    //update Clientsystem
                    foreach (ClientSystem c in list_systems)
                    {
                        if (c.Networknumber == this.selectedNetwork.NetworkNumber)
                        {
                            c.Networknumber = -1;
                        }
                    }
                    db.RemoveNetwork(this.selectedNetwork);
                    callingController.UpdateInformation();
                    UpdateView(false);
                    MessageBox.Show(String.Format("Das Netzwerk {0} wurde unwiderruflich gelöscht.", this.selectedNetwork.Name), "Netzwerk gelöscht", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

        }
 public void AddNetwork(Network network)
 {
     lstNetworks.Items.Add(network);
 }
        public void UpdateNetworkInventory(object selectedNetwork)
        {
            //bind to existing network
            if (selectedNetwork == null)
            {
                MessageBox.Show("Kein Netzwerk ausgewählt. Bitte zuerst ein Netzwerk auswählen.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Network help = (Network)selectedNetwork;
                foreach (Network n in list_networks)
                {
                    if (help.NetworkNumber == n.NetworkNumber)
                    {
                        this.selectedNetwork = n;
                    }
                }
                string newname = null;
                //Question if the network should be changed as selected
                switch (view.GetNetworkInputtype())
                {
                    case 1:
                        {
                            string[] str_s = view.GetStartAddress();
                            string[] str_e = view.GetEndAddress();
                            newname = String.Format("{0}.{1}.{2}.{3} - {4}.{5}.{6}.{7}", str_s[0], str_s[1], str_s[2], str_s[3], str_e[0], str_e[1], str_e[2], str_e[3]);
                            break;
                        }
                    case 2:
                        {
                            string[] str_h = view.GetHostAddress();
                            newname = String.Format("{0}.{1}.{2}.{3}", str_h[0], str_h[1], str_h[2], str_h[3]);
                            break;
                        }
                    case 3:
                        {
                            string[] str_cidr = view.GetCidrAddress();
                            string[] str_e = view.GetEndAddress();
                            newname = String.Format("{0}.{1}.{2}.{3} / {4}", str_cidr[0], str_cidr[1], str_cidr[2], str_cidr[3], str_cidr[4]);
                            break;
                        }
                    default:
                        newname = "";
                        break;
                }
                DialogResult dr = MessageBox.Show(String.Format("Soll das Netzwerk {0} in das Netzwerk {1} geändert werden?", this.selectedNetwork.Name, newname), "Netzwerk ändern", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    try
                    {
                        //Change the network
                        switch (view.GetNetworkInputtype())
                        {
                            case 1:
                                {
                                    //Get Address-Bytes as string
                                    string[] str_startaddress = new string[4];
                                    str_startaddress = view.GetStartAddress();
                                    string[] str_endaddress = new string[4];
                                    str_endaddress = view.GetEndAddress();
                                    //Convert into byte
                                    Byte[] b_startaddress = new Byte[4];
                                    Byte[] b_endaddress = new Byte[4];
                                    //Checks automaticaly for right value by its type and by converting
                                    b_startaddress[0] = Convert.ToByte(str_startaddress[0]);
                                    b_startaddress[1] = Convert.ToByte(str_startaddress[1]);
                                    b_startaddress[2] = Convert.ToByte(str_startaddress[2]);
                                    b_startaddress[3] = Convert.ToByte(str_startaddress[3]);
                                    b_endaddress[0] = Convert.ToByte(str_endaddress[0]);
                                    b_endaddress[1] = Convert.ToByte(str_endaddress[1]);
                                    b_endaddress[2] = Convert.ToByte(str_endaddress[2]);
                                    b_endaddress[3] = Convert.ToByte(str_endaddress[3]);
                                    IPAddress start = new IPAddress(b_startaddress);
                                    IPAddress end = new IPAddress(b_endaddress);
                                    //Check for right input: Start must be lower than end
                                    if (ControllerNetwork.convertIPtoUInt32(start) > ControllerNetwork.convertIPtoUInt32(end))
                                    {
                                        IPAddress helper = start;
                                        start = end;
                                        end = helper;
                                        MessageBox.Show("Addressen gedreht.", "Inputfehler korregiert", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }
                                    if ((int)(ControllerNetwork.convertIPtoUInt32(end) - ControllerNetwork.convertIPtoUInt32(start)) > 10000)
                                    {
                                        DialogResult dr_inner = MessageBox.Show("Achtung: Die Berechnung dieses Netzwerks kann unter Umständen länger dauern. Wollen Sie fortfahren?", "Warnung", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                        if (dr_inner == DialogResult.No)
                                        {
                                            return;
                                        }
                                    }
                                    this.selectedNetwork.Name = String.Format("{0} - {1}", start.ToString(), end.ToString());
                                    this.selectedNetwork.InputType = view.GetNetworkInputtype();
                                    this.selectedNetwork.IpAddresses = ControllerNetwork.calcAddressesSE(start, end, view.GetProgressBar());
                                    view.ClearStartEndInput();
                                    break;
                                }
                            case 2:
                                {
                                    //Get Address-Bytes as string
                                    string[] str_hostaddress = new string[4];
                                    str_hostaddress = view.GetHostAddress();
                                    //Convert into byte
                                    Byte[] b_hostaddress = new Byte[4];
                                    //Checks automaticaly for right value by its type and by converting
                                    b_hostaddress[0] = Convert.ToByte(str_hostaddress[0]);
                                    b_hostaddress[1] = Convert.ToByte(str_hostaddress[1]);
                                    b_hostaddress[2] = Convert.ToByte(str_hostaddress[2]);
                                    b_hostaddress[3] = Convert.ToByte(str_hostaddress[3]);
                                    IPAddress host = new IPAddress(b_hostaddress);
                                    ArrayList addresses = new ArrayList();
                                    addresses.Add(host);
                                    this.selectedNetwork.Name = host.ToString();
                                    this.selectedNetwork.InputType = view.GetNetworkInputtype();
                                    this.selectedNetwork.IpAddresses = addresses;
                                    view.ClearHostInput();
                                    break;
                                }
                            case 3:
                                {
                                    //Get Address-Bytes as string
                                    string[] str_cidraddress = new string[5];
                                    str_cidraddress = view.GetCidrAddress();
                                    //Convert into byte
                                    Byte[] b_cidraddress = new Byte[4];
                                    byte cidr = 0;
                                    //Checks automaticaly for right value by its type and by converting
                                    b_cidraddress[0] = Convert.ToByte(str_cidraddress[0]);
                                    b_cidraddress[1] = Convert.ToByte(str_cidraddress[1]);
                                    b_cidraddress[2] = Convert.ToByte(str_cidraddress[2]);
                                    b_cidraddress[3] = Convert.ToByte(str_cidraddress[3]);
                                    cidr = Convert.ToByte(str_cidraddress[4]);
                                    if (cidr > 32) throw new Exception("Cidr overflow");
                                    if (cidr < 19)
                                    {
                                        DialogResult dr_inner = MessageBox.Show("Achtung: Die Berechnung dieses Netzwerks kann unter Umständen länger dauern. Wollen Sie fortfahren?", "Warnung", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                        if (dr_inner == DialogResult.No)
                                        {
                                            return;
                                        }
                                    }
                                    //Creating and adding network
                                    IPAddress network = new IPAddress(b_cidraddress);
                                    this.selectedNetwork.Name = String.Format("{0} / {1}", network.ToString(), cidr.ToString());
                                    Log.WriteLog("NetworktabTest:" + view.GetNetworkInputtype());
                                    this.selectedNetwork.InputType = view.GetNetworkInputtype();

                                    this.selectedNetwork.IpAddresses = ControllerNetwork.calcAddressesCidr(network, cidr, view.GetProgressBar());
                                    view.ClearCidrInput();
                                    break;
                                }
                            default:
                                newname = "";
                                break;
                        }
                        db.UpdateNetwork(this.selectedNetwork);
                        callingController.UpdateInformation();
                        UpdateView(false);
                    }
                    catch (FormatException e)
                    {
                        Log.WriteLog("Error while parsing IPAddress String to Byte: " + e.Message);
                        MessageBox.Show("Fehler bei der Eingabe der Adressen", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    catch (OutOfMemoryException e)
                    {
                        MessageBox.Show("Maximal zulässige Anzahl an Adressen überschritten. Das Netzwerk wurde nicht hinzugefügt. Bitte Netzwerk korregieren.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Log.WriteLog("Speicherüberlauf: " + e.Message);
                        GC.Collect();
                        return;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Allgemeiner Fehler.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Log.WriteLog("Allgemeiner Fehler: " + e.Message);
                        return;
                    }
                }
            }
        }
        //Update the view with the selected network
        public void SelectedNetworkChanged(object selectedNetwork)
        {
            this.selectedNetwork = (Network)selectedNetwork;
            if (this.selectedNetwork != null)
            {
                //1=Start-/EndAddress
                //2=Host only
                //3=Cidr
                int type = this.selectedNetwork.InputType;
                switch (type)
                {
                    case 1:
                        {
                            //Get the start and endaddress, get their bytes, convert them to strings and pass them to the view
                            view.SetNetworkTab(type - 1);
                            view.ClearStartEndInput();
                            IPAddress start = (IPAddress)this.selectedNetwork.IpAddresses[0];
                            IPAddress end = (IPAddress)this.selectedNetwork.IpAddresses[this.selectedNetwork.IpAddresses.Count - 1];
                            Byte[] b_start = start.GetAddressBytes();
                            Byte[] b_end = end.GetAddressBytes();
                            string[] s_start = new string[4], s_end = new string[4];
                            for (int i = 0; i < 4; i++)
                            {
                                s_start[i] = b_start[i].ToString();
                                s_end[i] = b_end[i].ToString();
                            }
                            view.UpdateStartEndInput(s_start, s_end);
                            break;
                        }

                    case 2:
                        {
                            //Get Hostaddress and convert their bytes to string and pass them to the view
                            view.SetNetworkTab(type - 1);
                            view.ClearHostInput();
                            IPAddress host = (IPAddress)this.selectedNetwork.IpAddresses[0];
                            Byte[] b_host = host.GetAddressBytes();
                            string[] s_host = new string[4];
                            for (int i = 0; i < 4; i++)
                            {
                                s_host[i] = b_host[i].ToString();
                            }
                            view.UpdateHostInput(s_host);
                            break;
                        }

                    case 3:
                        {
                            //Get the name, split cidr and bytes from the name and pass to view
                            view.SetNetworkTab(type - 1);
                            view.ClearCidrInput();
                            string[] cidr = this.selectedNetwork.Name.Split('/', '.');
                            for (int i = 0; i < cidr.Length; i++)
                            {
                                cidr[i].Trim();
                            }
                            view.UpdateCidrInput(cidr);
                            break;
                        }
                    default:
                        {
                            Log.WriteLog("Error, wrong Inputtype");
                            break;
                        }

                }
            }
        }
 public void AddNetwork(Network network)
 {
     lstNetwork.Items.Add(network);
     lstNetwork.SelectedItems.Clear();
 }
 //functions
 public void AddNetwork(Network toAddingNetwork)
 {
     list_networks.Add(toAddingNetwork);
 }
        public void AddNetworkToInventory()
        {
            inputtype = view.GetInputtype();
            if (currentCustomer != null)
            {
                try
                {
                    switch (inputtype)
                    {
                        //Start- Endaddress
                        case 1:
                            {
                                //Get Address-Bytes as string
                                string[] str_startaddress = new string[4];
                                str_startaddress = view.GetStartAddress();
                                string[] str_endaddress = new string[4];
                                str_endaddress = view.GetEndAddress();
                                //Convert into byte
                                Byte[] b_startaddress = new Byte[4];
                                Byte[] b_endaddress = new Byte[4];
                                //Checks automaticaly for right value by its type and by converting
                                b_startaddress[0] = Convert.ToByte(str_startaddress[0]);
                                b_startaddress[1] = Convert.ToByte(str_startaddress[1]);
                                b_startaddress[2] = Convert.ToByte(str_startaddress[2]);
                                b_startaddress[3] = Convert.ToByte(str_startaddress[3]);
                                b_endaddress[0] = Convert.ToByte(str_endaddress[0]);
                                b_endaddress[1] = Convert.ToByte(str_endaddress[1]);
                                b_endaddress[2] = Convert.ToByte(str_endaddress[2]);
                                b_endaddress[3] = Convert.ToByte(str_endaddress[3]);
                                IPAddress start = new IPAddress(b_startaddress);
                                IPAddress end = new IPAddress(b_endaddress);
                                //Check for right input: Start must be lower than end
                                if (convertIPtoUInt32(start) > convertIPtoUInt32(end))
                                {
                                    IPAddress helper = start;
                                    start = end;
                                    end = helper;
                                    MessageBox.Show("Addressen gedreht.", "Inputfehler korregiert", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                if ((int)(convertIPtoUInt32(end) - convertIPtoUInt32(start)) > 10000)
                                {
                                    DialogResult dr = MessageBox.Show("Achtung: Die Berechnung dieses Netzwerks kann unter Umständen länger dauern. Wollen Sie fortfahren?", "Warnung", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                    if (dr == DialogResult.No)
                                    {
                                        return;
                                    }
                                }
                                //Creating and adding network
                                currentNetwork = new Network(list_networks.Count,
                                                                String.Format("{0} - {1}", start.ToString(), end.ToString()),
                                                                inputtype,
                                                                calcAddressesSE(start, end, view.GetProgressBar()));
                                view.ClearStartEndInput();
                                break;
                            }
                        //Host
                        case 2:
                            {
                                //Get Address-Bytes as string
                                string[] str_hostaddress = new string[4];
                                str_hostaddress = view.GetHostAddress();
                                //Convert into byte
                                Byte[] b_hostaddress = new Byte[4];
                                //Checks automaticaly for right value by its type and by converting
                                b_hostaddress[0] = Convert.ToByte(str_hostaddress[0]);
                                b_hostaddress[1] = Convert.ToByte(str_hostaddress[1]);
                                b_hostaddress[2] = Convert.ToByte(str_hostaddress[2]);
                                b_hostaddress[3] = Convert.ToByte(str_hostaddress[3]);
                                IPAddress host = new IPAddress(b_hostaddress);
                                ArrayList addresses = new ArrayList();
                                addresses.Add(host);
                                currentNetwork = new Network(list_networks.Count,
                                                                host.ToString(),
                                                                inputtype,
                                                                addresses);
                                view.ClearHostInput();
                                break;
                            }

                        //Cidr
                        case 3:
                            {
                                //Get Address-Bytes as string
                                string[] str_cidraddress = new string[5];
                                str_cidraddress = view.GetCidrAddress();
                                //Convert into byte
                                Byte[] b_cidraddress = new Byte[4];
                                byte cidr = 0;
                                //Checks automaticaly for right value by its type and by converting
                                b_cidraddress[0] = Convert.ToByte(str_cidraddress[0]);
                                b_cidraddress[1] = Convert.ToByte(str_cidraddress[1]);
                                b_cidraddress[2] = Convert.ToByte(str_cidraddress[2]);
                                b_cidraddress[3] = Convert.ToByte(str_cidraddress[3]);
                                cidr = Convert.ToByte(str_cidraddress[4]);
                                if (cidr > 32) throw new ArgumentException("Cidr>32");
                                if (cidr < 19)
                                {
                                    DialogResult dr = MessageBox.Show("Achtung: Die Berechnung dieses Netzwerks kann unter Umständen länger dauern. Wollen Sie fortfahren?", "Warnung", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                    if (dr == DialogResult.No)
                                    {
                                        return;
                                    }
                                }
                                //Creating and adding network
                                IPAddress network = new IPAddress(b_cidraddress);
                                currentNetwork = new Network(list_networks.Count,
                                                                String.Format("{0} / {1}", network.ToString(), cidr.ToString()),
                                                                inputtype,
                                                                calcAddressesCidr(network, cidr, view.GetProgressBar()));
                                view.ClearCidrInput();
                                break;
                            }
                        default:
                            Log.WriteLog("Unknown Inputtype");
                            break;
                    }


                    list_networks.Add(currentNetwork);
                    view.AddNetwork(currentNetwork);
                    currentNetworkInventory.AddNetwork(currentNetwork);
                    db.SaveNetwork(currentNetwork, currentNetworkInventory);
                    callingController.UpdateInformation();
                }
                catch (FormatException e)
                {
                    Log.WriteLog("Error while parsing IPAddress String to Byte: " + e.Message);
                    MessageBox.Show("Fehler bei der Eingabe der Adressen.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                catch (ArgumentException e)
                {
                    MessageBox.Show("Fehler bei der Eingabe des Suffixes.", "Suffix-Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Log.WriteLog("Suffix Fehler: " + e.Message);
                    return;
                }
                catch (OutOfMemoryException e)
                {
                    MessageBox.Show("Maximal zulässige Anzahl an Adressen überschritten. Das Netzwerk wurde nicht hinzugefügt. Bitte Netzwerk korregieren.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Log.WriteLog("Speicherüberlauf: " + e.Message);
                    GC.Collect();
                    return;
                }
                catch (Exception e)
                {
                    MessageBox.Show("Allgemeiner Fehler.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Log.WriteLog("Allgemeiner Fehler: " + e.Message);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Kein Kunde ausgewählt. Bitte Kunde auswählen.", "Kein Kunde ausgewählt", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            UpdateView(false);
        }