Auto populate from sqlite database

Booney 166 Reputation points
2021-05-02T23:13:14.503+00:00

I am auto populating a textbox and returning a combo box with time. If the textbox has multi entry the combo box will list the times of each entry. Now I need it to give me the rest of the data in the database per time. I’m using dictionary and item list to pull information from SQLite database.
Populating number and time is no issue the rest of the data is I have a class for the data.
Any tips or direction appreciated.

I guess I need to set the properties when I do the GetSTring and then set the textboxes to the properties in the SelectedIndexCHanged event.
That's where I get lost

93205-copy.png

 public partial class Search_Inventory_Part : Form  
    {  
          
  
        public Search_Inventory_Part()  
        {  
            InitializeComponent();  
            AutoCompleteText(); // Used to Populate fromDataBase  
        }  
  
        #region Dictionary to Auto Populate From2  
  
        public static List<Item2> Items = new List<Item2>();  
        public static Dictionary<string, List<Item2>> ItemLists = new Dictionary<string, List<Item2>>(); // Dictionary to get Data from DataBase  
        void AutoCompleteText()  
        {  
            txt_PN.AutoCompleteMode = AutoCompleteMode.SuggestAppend;  
            txt_PN.AutoCompleteSource = AutoCompleteSource.CustomSource;  
              
            string constring = "Data Source = Document.db";  
            string Query = "select PartNumber, Part_Name, AC, Checker, Unit_Cost, Time_Counted from InventoryDoc ORDER BY PartNumber";  
            SqliteConnection conDataBase = new SqliteConnection(constring);  
            SqliteCommand cmdDataBase = new SqliteCommand(Query, conDataBase);  
            SqliteDataReader myReader;  
            Items.Clear();  
            try  
            {  
                conDataBase.Open();  
                myReader = cmdDataBase.ExecuteReader();  
  
                var coll = new AutoCompleteStringCollection();  
  
                while (myReader.Read())  
                {  
                    var item2 = new Item2()  
                    {  
                        PartNumber = myReader.GetString(0).Trim(),  
                        Part_Name = myReader.GetString(1).Trim(),  
                        AC = myReader.GetString(2),  
                        Checker = myReader.GetString(3),  
                        Unit_Cost = myReader.GetString(4),  
                        PartTime = DateTime.Parse(myReader.GetString(5))  
                    };  
  
                    coll.Add(item2.PartNumber);  
                     
  
                    Items.Add(item2);  
                }  
                txt_PN.AutoCompleteCustomSource = coll;  
                 
                ItemLists =  
                Items.GroupBy(x => x.PartNumber).ToDictionary(x => x.Key, x => x.OrderBy(y => y.PartTime).ToList());  
            }  
  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.Message);  
            }  
  
        }  
  
        #endregion  
  
  
        #region Send to Search Inventory Part  
        private void Search_Inventory_Part_Load(object sender, EventArgs e)  
        {  
  
        }  
  
        #endregion  
  
        private void txt_PN_TextChanged(object sender, EventArgs e)  
        {  
            if (ItemLists.ContainsKey(txt_PN.Text.Trim().ToUpper()))  
            {  
                var items = ItemLists[txt_PN.Text.Trim().ToUpper()];  
                PartTime.DisplayMember = "PartTime";  
                PartTime.DataSource = items;  
                // Fill Dropdown with items. set DataTextField = key field is (datetime)  
            }  
        }  
  
  
        private void ddb_SelectedIndexChanged()  // Select Time from Drop Down  
        {  
            var item = PartTime.SelectedItem as Item2;  
                       
            if (item == null)  
                return;  
        }  
  
        private void Search_Inventory_Part_FormClosing(object sender, FormClosingEventArgs e)  
        {  
            Application.Exit();  
        }  
    }  
  
}  
SQL Server | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.