} //end inventory click /// <summary> /// gets the inventory data from the database. /// I am also creating a dictionary to refer back to. I use this in the Add/Update click event. /// This prevents additional reads to the database to retrieve the ItemCode. /// </summary> public void populateInventory() { ///try catch block to handle exceptions try { //gets data from database and load into dgInventoryItems //Method should be run in initialize method ///sQuery for inventory items String sQuery = mydb.SelectInventoryItems(); ///database query dtInventory = db.FillSqlDataTable(sQuery); ///inventory items set to default view dgInventoryItems.ItemsSource = dtInventory.DefaultView; ///foreach loop to populate the grid foreach (DataRow row in dtInventory.Rows) { inventoryDictionary.Add(row[1].ToString(), row[0].ToString()); } } catch (Exception)///catch exceptions { MessageBox.Show(MethodInfo.GetCurrentMethod().DeclaringType.Name); } //end catch } //end populateInventory()
/// <summary> /// Populates datagrid with all items. /// </summary> private void populateDatagridInv() { try { // Gets all items from the database sSQL = mydb.SelectInventoryItems(); dt = db.FillSqlDataTable(sSQL); dataGrid.ItemsSource = dt.DefaultView; // Inserts items into the datagrid. foreach (DataRow row in dt.Rows) { inventoryDictionary.Add(row[1].ToString(), row[0].ToString()); } } catch (Exception) { MessageBox.Show(MethodInfo.GetCurrentMethod().DeclaringType.Name); } }