Exemple #1
0
        }     //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()
        private void invoiceIDComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ///Disable other drop down menu's if this is selected
            if (invoiceIDComboBox.IsEnabled)
            {
                invoiceDateComboBox.IsEnabled   = false;
                invoiceAmountComboBox.IsEnabled = false;
            }

            ///The two other drop down menu's will be disbled when this is being used

            ///When selected this combo box will show a drop down list with invoice ID's
            ///The user will be able to highlight/select an ID and it will be recieved
            ///by the dataGrid1 to show that specific invoice only
            Console.Write("textbox Value: " + invoiceIDComboBox.SelectedItem);

            //get query needed find invoice
            String sQuery = mydb.SelectInvoiceID(invoiceIDComboBox.SelectedItem.ToString());

            //datatable used to fget table data.
            dt = db.FillSqlDataTable(sQuery);

            //fill the datagrid
            invoiceGrid1.ItemsSource = dt.DefaultView;
        }
        /// <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);
            }
        }