Ejemplo n.º 1
0
 /// <summary>
 /// Enter-Taste, wenn ein neuer Widerstandwert hinzugefügt werden soll
 /// </summary>
 void textBox1_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == '\r')
     {
         var p = Resistor.Parse(textBoxValue.Text);
         if (p != null)
         {
             p.ident           = textBoxIdent.Text;
             textBoxIdent.Text = Increment(textBoxIdent.Text);
             int insertPos = 0;
             while (insertPos < listBoxResistors.Items.Count && ((Resistor)listBoxResistors.Items[insertPos]).valueMilliOhm < p.valueMilliOhm)
             {
                 insertPos++;
             }
             listBoxResistors.Items.Insert(insertPos, p);
             AutoSave(listBoxResistors.Items.Cast <Resistor>().ToArray());
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Änderung der Sucheingabe
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void textBoxSearch_TextChanged(object sender, EventArgs e)
        {
            var val = Resistor.Parse(textBoxSearch.Text);

            if (val == null)
            {
                return;
            }

            int searchType = radioButtonSearchType1.Checked ? 1 : radioButtonSearchType2.Checked ? 2 : radioButtonSearchType3.Checked ? 3 : radioButtonSearchType4.Checked ? 4 : radioButtonSearchType5.Checked ? 5 : radioButtonSearchType6.Checked ? 6 : 0;

            if (searchType == 0)
            {
                throw new ArgumentException("searchType");
            }

            const int TargetLimit = 1000;

            var time = Stopwatch.StartNew();

            ResistorResult[] results = null;
            foreach (double searchLevel in new[] { 1.0001, 1.0002, 1.0005, 1.001, 1.002, 1.005, 1.01, 1.02, 1.05, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 9999999.9 })
            {
                results = Resistor.Search(listBoxResistors.Items.Cast <Resistor>().ToArray(), val, searchType, searchLevel).Take(TargetLimit).ToArray();
                if (results.Length >= TargetLimit / 2)
                {
                    break;                            // mindestens die Hälfte an Ergebnissen erreicht?
                }
            }

            Array.Sort(results, (x, y) => x.errorMilliOhm.CompareTo(y.errorMilliOhm));

            time.Stop();
            Text = "Search-Time: " + time.ElapsedMilliseconds.ToString("N0", CultureInfo.InvariantCulture) + " ms";

            listBoxSearchResults.BeginUpdate();
            listBoxSearchResults.Items.Clear();
            listBoxSearchResults.Items.AddRange(results);
            listBoxSearchResults.EndUpdate();
        }