Beispiel #1
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.
                //
            }
        }