Ejemplo n.º 1
0
        private bool IPv4_calculateBits()
        {
            byte[] tmp;
            if (IsValidInput_IpV4() && isValidInput_IpV4SubnetMask())
            {
                switch (IpCalculator.getFieldStatus(writeStruct(Textbox_FieldType.SUBNETMASK_LONG), writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)))
                {
                case IpV4_FieldStatus.SHORTFILLED:
                    tmp = IpCalculator.calcEmptySubnetMaskFields(Subnet_textBox_ShortWritten);
                    int a = tmp[0];
                    int b = tmp[1];
                    int c = tmp[2];
                    int d = tmp[3];
                    Subnet_textBox1.Text = a.ToString();
                    Subnet_textBox2.Text = b.ToString();
                    Subnet_textBox3.Text = c.ToString();
                    Subnet_textBox4.Text = d.ToString();
                    break;

                case IpV4_FieldStatus.LONGFILLED:
                    tmp = IpCalculator.calcEmptySubnetMaskFields(Subnet_textBox1, Subnet_textBox2, Subnet_textBox3, Subnet_textBox4);
                    int x = tmp[0];
                    Subnet_textBox_ShortWritten.Text = x.ToString();
                    break;

                default:
                    throw new NotImplementedException();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 private void Textboxes_LeftBottom_Brush(string brush_string)
 {
     readStruct(IpCalculator.brushTextboxes(brush_string, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
     readStruct(IpCalculator.brushTextboxes(brush_string, writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)));
     readStruct(IpCalculator.brushTextboxes(brush_string, writeStruct(Textbox_FieldType.DESIRED_HOSTNO)));
     readStruct(IpCalculator.brushTextboxes(brush_string, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)));
 }
Ejemplo n.º 3
0
 public Main()
 {
     control               = new Control.Control();
     ipCalculator          = new IpCalculator(control);
     WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
     InitializeComponent();
 }
Ejemplo n.º 4
0
 private void Textboxes_LeftTop_Disabled()
 {
     readStruct(IpCalculator.Textboxes_Disabled(writeStruct(Textbox_FieldType.IP_ADDRESSBLOCK)));
     readStruct(IpCalculator.Textboxes_Disabled(writeStruct(Textbox_FieldType.SUBNETMASK_LONG)));
     readStruct(IpCalculator.Textboxes_Disabled(writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)));
     Textboxes_LeftTop_Brush(ColourCodes.GRAY);
     Subnet_ipv4_Left_Top.Background.Opacity = 0.3;
 }
Ejemplo n.º 5
0
 private void Textboxes_LeftBottom_Disabled()
 {
     readStruct(IpCalculator.Textboxes_Disabled(writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
     readStruct(IpCalculator.Textboxes_Disabled(writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)));
     readStruct(IpCalculator.Textboxes_Disabled(writeStruct(Textbox_FieldType.DESIRED_HOSTNO)));
     readStruct(IpCalculator.Textboxes_Disabled(writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)));
     Textboxes_LeftBottom_Brush(ColourCodes.GRAY);
     Subnet_ipv4_Left_Bottom.Background.Opacity = 0.3;
 }
Ejemplo n.º 6
0
 private bool IsValidInput_IpV4()
 {
     if (IpCalculator.isIpV4Digit(Ip4_textBox1, false) && IpCalculator.isIpV4Digit(Ip4_textBox2, false) &&
         IpCalculator.isIpV4Digit(Ip4_textBox3, false) && IpCalculator.isIpV4Digit(Ip4_textBox4, false))
     {
         return(true);
     }
     else
     {
         // Ist falsche IPv4 Adresse
         createErrorLabel(ErrorCodeNo.WRONGIPV4);
         return(false);
     }
 }
Ejemplo n.º 7
0
        private bool isValidInput_IpV4SubnetMask()
        {
            switch (IpCalculator.getFieldStatus(writeStruct(Textbox_FieldType.SUBNETMASK_LONG), writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)))
            {
            case IpV4_FieldStatus.SHORTFILLED:
                if (IpCalculator.isLegitIpV4SubnetMask(Subnet_textBox_ShortWritten))
                {
                    createErrorLabel(ErrorCodeNo.NOERROR);
                    return(true);
                }
                else
                {
                    createErrorLabel(ErrorCodeNo.WRONGSUBNETCODE);
                    return(false);
                }

            case IpV4_FieldStatus.LONGFILLED:
                if (IpCalculator.isIpV4Digit(Subnet_textBox1, true) && IpCalculator.isIpV4Digit(Subnet_textBox2, true) &&
                    IpCalculator.isIpV4Digit(Subnet_textBox3, true) && IpCalculator.isIpV4Digit(Subnet_textBox4, true))
                {
                    if (IpCalculator.isLegitIpV4SubnetMask(writeStruct(Textbox_FieldType.SUBNETMASK_LONG)))
                    {
                        createErrorLabel(ErrorCodeNo.NOERROR);
                        return(true);
                    }
                    else
                    {
                        createErrorLabel(ErrorCodeNo.WRONGSUBNETCODE);
                        return(false);
                    }
                }
                else
                {
                    createErrorLabel(ErrorCodeNo.WRONGSUBNETCODE);
                    return(false);
                }

            case IpV4_FieldStatus.BOTHFILLED:
                createErrorLabel(ErrorCodeNo.MULTIPLEFIELDSFILLED);
                return(false);

            case IpV4_FieldStatus.NOFIELDSFILLED:
                createErrorLabel(ErrorCodeNo.WRONGSUBNETCODE);
                return(false);

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 8
0
        private void FillRightContent()
        {
            Int64 netmask;
            Int64 subnetmask;

            try     { netmask = Convert.ToInt64(Subnet_textBox_ShortWritten.Text); }
            catch   { netmask = 0; };
            try     { subnetmask = Convert.ToInt64(Subnet_textBox_ShortWritten_new.Text); }
            catch   { subnetmask = 0; }

            string ipv4 = IpCalculator.InputToBinary(Ip4_textBox1.Text);

            ipv4 = ipv4 + IpCalculator.InputToBinary(Ip4_textBox2.Text);
            ipv4 = ipv4 + IpCalculator.InputToBinary(Ip4_textBox3.Text);
            ipv4 = ipv4 + IpCalculator.InputToBinary(Ip4_textBox4.Text);
            string subnetmask_string = IpCalculator.InputToBinary(Subnet_textBox1_new.Text);

            subnetmask_string = subnetmask_string + IpCalculator.InputToBinary(Subnet_textBox2_new.Text);
            subnetmask_string = subnetmask_string + IpCalculator.InputToBinary(Subnet_textBox3_new.Text);
            subnetmask_string = subnetmask_string + IpCalculator.InputToBinary(Subnet_textBox4_new.Text);

            txblock_ip_binaer.Text     = IpCalculator.FormatIPv4String(netmask, subnetmask, ipv4);
            txblock_subnet_binaer.Text = IpCalculator.FormatIPv4String(netmask, subnetmask, subnetmask_string);
            try { txblock_subnet_max_hosts.Text = Convert.ToString((IpCalculator.MaxBinaryBase(Convert.ToDecimal(Hosts_desired.Text) + 2)) - 2); }
            catch { txblock_subnet_max_hosts.Text = "-"; }
            try { txblock_subnet_number.Text = Convert.ToString(IpCalculator.MaxBinaryBase(Convert.ToDecimal(Subnet_desired.Text))); }
            catch { txblock_subnet_number.Text = "-"; }

            txblock_first_adress.Text        = IpCalculator.FormatIPv4String(netmask, subnetmask, (IpCalculator.FirstSubnetIPAdress(ipv4, netmask)));
            txblock_first_adress_dez.Text    = IpCalculator.IP_BinaryToDottedDecimal(IpCalculator.FirstSubnetIPAdress(ipv4, netmask));
            txblock_first_bc_adress.Text     = IpCalculator.FormatIPv4String(netmask, subnetmask, (IpCalculator.FirstBroadcastIPAdress(ipv4, netmask, subnetmask)));
            txblock_first_bc_adress_dez.Text = IpCalculator.IP_BinaryToDottedDecimal(IpCalculator.FirstBroadcastIPAdress(ipv4, netmask, subnetmask));

            txblock_last_adress.Text        = IpCalculator.FormatIPv4String(netmask, subnetmask, (IpCalculator.LastSubnetIPAdress(ipv4, netmask, subnetmask)));
            txblock_last_adress_dez.Text    = IpCalculator.IP_BinaryToDottedDecimal(IpCalculator.LastSubnetIPAdress(ipv4, netmask, subnetmask));
            txblock_last_bc_adress.Text     = IpCalculator.FormatIPv4String(netmask, subnetmask, (IpCalculator.LastBroadcastIPAdress(ipv4, netmask, subnetmask)));
            txblock_last_bc_adress_dez.Text = IpCalculator.IP_BinaryToDottedDecimal(IpCalculator.LastBroadcastIPAdress(ipv4, netmask, subnetmask));
        }
Ejemplo n.º 9
0
 private void Textboxes_LeftTop_Brush(string brush_string)
 {
     readStruct(IpCalculator.brushTextboxes(brush_string, writeStruct(Textbox_FieldType.IP_ADDRESSBLOCK)));
     readStruct(IpCalculator.brushTextboxes(brush_string, writeStruct(Textbox_FieldType.SUBNETMASK_LONG)));
     readStruct(IpCalculator.brushTextboxes(brush_string, writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)));
 }
Ejemplo n.º 10
0
        //
        //  Funktion wird jedesmal ausgeführt, wenn sich eine Eingabe in den Textfeldern ändert
        //  Dabei wird zunächst geprüft, ob die jeweilige Eingabe stimmt. Fehler werden rot markiert
        //  und ein Label weist den Nutzer darauf hin, dass die Eingabe so nicht übernommen werden kann.
        //  Stimmt die Eingabe, so wird auf die fehlenden Felder umgerechnet.
        //
        //  Als Letztes wird dann eine Berechnung der Ausgabe ausgelöst. Insgesamt ist somit das
        //  Auslesen der Ergebnisse in Echtzeit möglich.
        //
        private void TextBox_BottomLeft_onTextChanged(Textbox_FieldType fieldType, TextBox txbox)
        {
            //
            //  Das Berechnen der Fehlenden Felder würde eine Endlosschleife auslösen
            //  (Jedes Eintragen in eine Textbox führt wieder rekursiv in diese Fuktion)
            //
            //  Daher muss geprüft werden, ob bereits eine Berechnung der Felder erfolgt, was
            //  durch die Flag TextChanged_Event_isLocked erfolgt.
            //
            if (!TextChanged_Event_isLocked)
            {
                TextChanged_Event_isLocked = true;
                switch (fieldType)
                {
                case Textbox_FieldType.DESIRED_SUBNETNO:
                    // Validation + Calc restliche Felder, eine FKT in CONTROL welche von hier mehrmals aufgerufen wird.
                    if (IpCalculator.isLegitSubnetNo(Subnet_desired, Subnet_textBox_ShortWritten) && control.CheckTextboxIfNumeric(txbox) && IpCalculator.IsTextboxFilled(txbox))
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_HOSTNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
                        //Falsche Nummer ?
                        string st = IpCalculator.calcSubnetShort(writeStruct(Textbox_FieldType.DESIRED_SUBNETNO),
                                                                 writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)).ToString();
                        Subnet_textBox_ShortWritten_new.Text = st;
                        Hosts_desired.Text = IpCalculator.calcHostNo(writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)).ToString();
                        //
                        //UMBAU IN READSTRUCT AUSSTEHEND
                        //
                        byte[] tmp;
                        tmp = IpCalculator.calcEmptySubnetMaskFields(Subnet_textBox_ShortWritten_new);
                        readStruct(IpCalculator.fillAddressBoxByByte(tmp, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
                        FillRightContent();
                    }
                    else
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.RED, writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)));
                    }
                    TextChanged_Event_isLocked = false;
                    break;

                case Textbox_FieldType.DESIRED_HOSTNO:
                    if (IpCalculator.isLegitHostNo(writeStruct(Textbox_FieldType.DESIRED_HOSTNO),
                                                   writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)) && control.CheckTextboxIfNumeric(txbox) && IpCalculator.IsTextboxFilled(txbox))
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_HOSTNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
                        string st = IpCalculator.calcSubnetShort(writeStruct(Textbox_FieldType.DESIRED_HOSTNO)).ToString();
                        Subnet_textBox_ShortWritten_new.Text = st;
                        readStruct(IpCalculator.calcSubnetNo(writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)
                                                             , writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT),
                                                             writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)));
                        byte[] tmp;
                        tmp = IpCalculator.calcEmptySubnetMaskFields(Subnet_textBox_ShortWritten_new);
                        readStruct(IpCalculator.fillAddressBoxByByte(tmp, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
                        FillRightContent();
                    }
                    else
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.RED, writeStruct(Textbox_FieldType.DESIRED_HOSTNO)));
                    }
                    TextChanged_Event_isLocked = false;
                    break;

                case Textbox_FieldType.NEW_SUBNETMASK_LONG:
                    if (IpCalculator.isIpV4Digit(Subnet_textBox1_new, true) &&
                        IpCalculator.isIpV4Digit(Subnet_textBox2_new, true) &&
                        IpCalculator.isIpV4Digit(Subnet_textBox3_new, true) &&
                        IpCalculator.isIpV4Digit(Subnet_textBox4_new, true) &&
                        IpCalculator.tryParseTextboxToInt(Subnet_textBox4_new) != 255 &&
                        IpCalculator.isLegitIpV4SubnetMask(writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)) && IpCalculator.IsTextboxFilled(txbox))
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_HOSTNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
                        byte[] tmp = IpCalculator.calcEmptySubnetMaskFields(Subnet_textBox1_new, Subnet_textBox2_new, Subnet_textBox3_new, Subnet_textBox4_new);
                        Subnet_textBox_ShortWritten_new.Text = tmp[0].ToString();
                        readStruct(IpCalculator.calcSubnetNo(writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)
                                                             , writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT),
                                                             writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)));
                        Hosts_desired.Text = IpCalculator.calcHostNo(writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)).ToString();
                        FillRightContent();
                    }
                    else
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.RED, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
                    }
                    TextChanged_Event_isLocked = false;
                    break;

                case Textbox_FieldType.NEW_SUBNETMASK_SHORT:
                    //
                    //SubnetNo wird eins zu Hoch gesetzt!
                    //
                    if (IpCalculator.isLegitIpV4SubnetMask(writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)
                                                           , writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)) && IpCalculator.IsTextboxFilled(txbox))
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.DESIRED_HOSTNO)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)));
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.WHITE, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));
                        readStruct(IpCalculator.calcSubnetNo(writeStruct(Textbox_FieldType.DESIRED_SUBNETNO)
                                                             , writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT),
                                                             writeStruct(Textbox_FieldType.SUBNETMASK_SHORT)));
                        Hosts_desired.Text = IpCalculator.calcHostNo(writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)).ToString();
                        byte[] tmp;
                        tmp = IpCalculator.calcEmptySubnetMaskFields(Subnet_textBox_ShortWritten_new);
                        readStruct(IpCalculator.fillAddressBoxByByte(tmp, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_LONG)));

                        FillRightContent();
                    }
                    else
                    {
                        readStruct(IpCalculator.brushTextboxes(ColourCodes.RED, writeStruct(Textbox_FieldType.NEW_SUBNETMASK_SHORT)));
                    }

                    TextChanged_Event_isLocked = false;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                //
                //  Berechnung wurde bereits durch ein Textchanged Event ausgelöst.
                //
            }
        }