예제 #1
0
        private void numUpDownIndex_ValueChanged(object sender, EventArgs e)
        {
            //
            //refresh listview, groupbox, lblVal, and txtTweak
            //use numIndex and fieldObjs
            //
            if (mH)
            {
                return;
            }
            _n = Convert.ToInt32(numUpDownIndex.Value) - 1;
            _fObj f = fobjs[_n];

            lblFieldVal.Text = $"{f.mainMetric} value: {f.value}";
            int x = 0;

            foreach (_diskEntry d in diskEntries)
            {
                if (d.fIndex == _n)
                {
                    x++;
                }
            }
            btnBegin.Text = $"List {x} Pairs";
            txtTweak.Text = f.foodName;
        }
예제 #2
0
        private void txtTweak_TextChanged(object sender, EventArgs e)
        {
            //
            //refresh listview
            //search over fieldObjs
            //

            if (mH)
            {
                return;
            }
            _fObj f = fobjs[_n];

            chkLstBoxUSDAresults.Items.Clear();
            usdaDB.wMatch        = new int[usdaDB.names.Length];
            usdaDB.joinedMatches = new string[usdaDB.names.Length];
            string[] words;

            if (txtTweak.TextLength < 4)
            {
                return;
            }
            else if (txtTweak.Text.Split(' ').Length < 2)
            {
                words = new string[] { txtTweak.Text }
            }
            ;
            else
            {
                words = txtTweak.Text.Split(' '); //(_delims);
            }
            foreach (string s in words)
            {
                for (int i = 0; i < usdaDB.names.Length; i++)
                {
                    if (s.Length > 2 && usdaDB.names[i].ToUpper() /*.Split(_delims)*/.Contains(s.ToUpper()))
                    {
                        usdaDB.wMatch[i]++; //usdaDB.joinedMatches[i] += s + ", ";
                    }
                }
            }
            int m = usdaDB.wMatch.Max();
            int q = 0;
            List <string> itms = new List <string>();
            for (int i = m; i > 0; i--)
            {
                for (int j = 0; j < usdaDB.names.Length; j++)
                {
                    if (usdaDB.wMatch[j] == i && ++q > 0)
                    {
                        itms.Add($"{usdaDB.ndbs[j]} -- {usdaDB.names[j]}"); // -- {usdaDB.wMatch[j]}"); //-({usdaDB.joinedMatches[j]})");
                    }
                }
            }
            n = fobjs.Count();
            groupBox1.Text   = $"{q} Possible Matches ({_n + 1} of {n}) — {f.foodName}";
            lblFieldVal.Text = $"{f.mainMetric} value: {f.value}";

            chkLstBoxUSDAresults.BeginUpdate();
            for (int i = 0; i < itms.Count; i++)
            {
                chkLstBoxUSDAresults.Items.Add(itms[i]);
                foreach (_diskEntry d in diskEntries)
                {
                    if (d.ndb == itms[i].Split(new string[] { " -- " }, StringSplitOptions.None)[0])
                    {
                        chkLstBoxUSDAresults.SetItemChecked(i, true);
                    }
                }
            }
            chkLstBoxUSDAresults.EndUpdate();
        }
예제 #3
0
        private void comboFields_SelectedIndexChanged(object sender, EventArgs e)
        {
            //
            //changes the field objects
            //loads other things behind the scenes
            //

            _db       = this.Text;
            this.Text = $"Pair {_db} with USDA";
            string fieldRoot = $"{Application.StartupPath}{slash}usr{slash}profile{frmMain.currentUser.index}{slash}lib{slash}{_db}{slash}";

            storLoc      = $"{Application.StartupPath}{slash}usr{slash}profile{frmMain.currentUser.index}{slash}lib{slash}_pairings{slash}{_db}.TXT";
            dbInitKeys   = new List <dbi>();
            dbConfigKeys = new List <dbc>();
            string[] dbInitLines   = File.ReadAllLines($"{fieldRoot}_dbInit.TXT");
            string[] dbConfigLines = File.ReadAllLines($"{fieldRoot}_dbConfig.TXT");
            string[] fieldInfo;
            try { fieldInfo = File.ReadAllLines($"{Application.StartupPath}{slash}usr{slash}profile{frmMain.currentUser.index}{slash}lib{slash}_pairings{slash}{comboFields.Text}.TXT"); }
            catch { }

            foreach (string s in dbInitLines)
            {
                if (s.StartsWith("#") || string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }
                string[] _params = s.Split(':');
                dbInitKeys.Add(new dbi {
                    file = _params[0], header = _params[1], unit = _params[2]
                });
            }
            foreach (string s in dbConfigLines)
            {
                if (s.StartsWith("#") || string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }
                string[] _params = s.Split(':');
                dbConfigKeys.Add(new dbc {
                    file = _params[0], field = _params[1], metric = _params[2]
                });
            }

            //
            //loads in data for all field entries
            //
            fobjs = new List <_fObj>();
            foreach (dbc d in dbConfigKeys)
            {
                string[] names;
                string[] vals;
                if (d.field == "FoodName")
                {
                    names = File.ReadAllLines(fieldRoot + d.file);
                    n     = names.Length;
                    foreach (dbc d2 in dbConfigKeys)
                    {
                        if (d2.field == "Value1")
                        {
                            vals = File.ReadAllLines(fieldRoot + d2.file);
                            for (int i = 0; i < names.Length; i++)
                            {
                                _fObj f = new _fObj {
                                    index = i, foodName = names[i], value = vals[i]
                                };
                                //if (!string.IsNullOrEmpty(d.metric) && !f.metricsToTrack.Contains(d.metric))
                                //f.metricsToTrack.Add(d.metric);
                                if (!string.IsNullOrEmpty(d.metric) && d.field == "Value1")
                                {
                                    f.mainMetric = d.metric;
                                }
                                fobjs.Add(f);
                            }
                        }
                    }
                }
            }

            _n = 0;
            try
            {
                diskContents = File.ReadAllLines(storLoc).ToList();

                foreach (string s in diskContents)
                {
                    if (s.StartsWith("[Progress]"))
                    {
                        _n = Convert.ToInt32(s.Replace("[Progress]", ""));
                        break;
                    }
                }

                diskEntries = new List <_diskEntry>();
                foreach (string s in diskContents)
                {
                    if (!s.StartsWith("["))
                    {
                        diskEntries.Add(new _diskEntry {
                            ndb = s.Split('|')[0], value = s.Split('|')[1], fIndex = Convert.ToInt32(s.Split('|')[2])
                        });
                    }
                }
            }
            catch { }

            mH = true;
            numUpDownIndex.Minimum = 1;
            numUpDownIndex.Maximum = n;
            numUpDownIndex.Value   = _n + 1;
            mH             = false;
            groupBox1.Text = $"Possible Matches ({_n + 1} of {n}) — {fobjs[_n].foodName}";
            this.Text      = $"Pair {n} items for {comboFields.Text} with USDA";
            foreach (_fObj f in fobjs)
            {
                if (f.foodName == fobjs[_n].foodName)
                {
                    lblFieldVal.Text = $"{f.mainMetric} value: {f.value}";
                }
            }
            mH = true;
            numUpDownIndex.Value = _n + 1;
            mH = false;
        }