private async Task BuildIndexesAsync()
        {
            nupProjID.Enabled = false;
            indexList.Clear();
            var(Results, _) = await APIHelper.TryBuildIndexList(mainForm.EntID, mainForm.SessionID, nupProjID.Value.ToString(), mainForm.Url);

            indexList = Results;
            if (indexList.Count == 0)
            {
                MessageBox.Show("Invalid Project ID", "Upload Error");
                nupProjID.Enabled = true;
                return;
            }

            indexTable.RowCount = indexList.Count;
            int i = 0;

            foreach (string field in indexList)
            {
                indexTable.Controls.Add(new Label()
                {
                    Text = $"{field}:", Anchor = AnchorStyles.Right, AutoSize = true
                }, 0, i);
                indexTable.Controls.Add(new TextBox()
                {
                    Dock = DockStyle.Fill
                }, 1, i);
                ++i;
            }

            nupProjID.Enabled = true;
        }
Exemple #2
0
        /// <summary>
        /// Set combobox properties to populate project fields.
        /// </summary>
        /// <param name="cBox"></param>
        /// <returns></returns>
        private async ValueTask <bool> TrySetCBox(ComboBox cBox)
        {
            if (cBox == null)
            {
                throw new ArgumentNullException();
            }
            var results = new List <string>();

            try
            {
                if (indexes.TryGetValue(Convert.ToInt32(nupProjID.Value), out var val))
                {
                    results = val;
                }
                else
                {
                    var(Results, _) = await APIHelper.TryBuildIndexList(mainForm.EntID, mainForm.SessionID, nupProjID.Value.ToString(), mainForm.Url);

                    if (Results.Count == 0)
                    {
                        MessageBox.Show("Invalid Project ID.", "Error");
                        return(false);
                    }
                    results = Results;
                    indexes.Add(Convert.ToInt32(nupProjID.Value), results);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            var projectFieldsArray = results.ToArray();
            var autocomp           = new AutoCompleteStringCollection();

            cBox.Items.Clear();
            cBox.Items.AddRange(projectFieldsArray);
            cBox.SelectedIndex = 0;
            autocomp.AddRange(projectFieldsArray);
            cBox.AutoCompleteCustomSource = autocomp;
            cBox.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
            cBox.AutoCompleteSource       = AutoCompleteSource.CustomSource;
            return(true);
        }