Exemple #1
0
        /// <summary>
        /// method to get a List of Items from the database
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        public List <clsItem> GetItems(clsDataAccess db)
        {
            try
            {
                ItemsList = new List <clsItem>();
                sSQL      = "select ItemCode, ItemDesc, Cost from ItemDesc";
                ds        = db.ExecuteSQLStatement(sSQL, ref iRetVal);

                for (int i = 0; i < iRetVal; i++)
                {
                    clsItem Item = new clsItem();

                    Item.Code        = (string)ds.Tables[0].Rows[i][0];
                    Item.Description = (string)ds.Tables[0].Rows[i][1];
                    Item.Cost        = float.Parse(ds.Tables[0].Rows[i][2].ToString());

                    ItemsList.Add(Item);
                }

                return(ItemsList);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
        /// <summary>
        /// method for when Add item button is clicked, opens new window for more information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _8GroupAssignment.Items.wndNewItem wndNewItem = new wndNewItem(clsData);

                wndNewItem.ShowDialog();

                if (!wndNewItem.bItemAdded)
                {
                    return;
                }
                clsItem             = new clsItem();
                clsItem.Code        = wndNewItem.sCode;
                clsItem.Cost        = wndNewItem.fCost;
                clsItem.Description = wndNewItem.sDescription;

                clsItemsSQL.InsertItem(clsData, clsItem.Code, clsItem.Cost, clsItem.Description);
                LoadItemGrid();
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }