//constructor public ControllerMain(FormMain view) : base(null, null) { //connect controller to its view this.view = view; list_customers = new ArrayList(); list_networks = new ArrayList(); list_networkInventories = new ArrayList(); list_allAvailableLicenses = new ArrayList(); list_licenseInventories = new ArrayList(); list_systems = new ArrayList(); list_systemInventories = new ArrayList(); list_Audits = new ArrayList(); //initialising by database list_customers = db.GetCustomers(); list_allAvailableLicenses = db.GetLicenses(); list_networks = db.GetNetworks(); list_networkInventories = db.GetNetworkInventories(); list_licenseInventories = db.GetLicenseInventories(); list_systems = db.GetClientSystems(); list_systemInventories = db.GetSystemInventories(); list_Audits = db.GetAudits(); //Creating Forms fAudit = new FormAudit(); fChanges = new FormChange(); fCustomer = new FormCustomer(); fLicense = new FormLicense(); fNetwork = new FormNetwork(); fSystemInventory = new FormSystemInventory(); fAudit.Visible = false; fChanges.Visible = false; fCustomer.Visible = false; fLicense.Visible = false; fNetwork.Visible = false; fSystemInventory.Visible = false; //Creating Controllers and connect data cAudit = new ControllerAudit(this, fAudit, list_customers, list_licenseInventories, list_systemInventories, list_Audits, list_allAvailableLicenses); cChanges = new ControllerChanges(this, fChanges, list_customers, list_networks, list_networkInventories, list_licenseInventories, list_allAvailableLicenses, list_systems); cCustomer = new ControllerCustomer(this, fCustomer, list_customers); cLicense = new ControllerLicense(this, fLicense, list_customers, list_allAvailableLicenses, list_licenseInventories); cNetwork = new ControllerNetwork(this, fNetwork, list_customers, list_networks, list_networkInventories); cSystemInventory = new ControllerSystemInventory(this, fSystemInventory, list_customers, list_networks, list_networkInventories, list_systems, list_systemInventories, list_allAvailableLicenses); //Connect Controller to View fAudit.Currentcontroller = cAudit; fChanges.Currentcontroller = cChanges; fCustomer.Currentcontroller = cCustomer; fLicense.Currentcontroller = cLicense; fNetwork.Currentcontroller = cNetwork; fSystemInventory.Currentcontroller = cSystemInventory; //Update View with Information initialised by Database UpdateView(true); }
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; } } } }