Example #1
0
        // Optional: sort (default is category_no)
        public List<CategoryItem> GetCategoryItemList(CategorySort sort = CategorySort.Default)
        {
            // Case statment for sort column
            string sortString;
            switch (sort)
            {
                case CategorySort.Name: sortString = "category_name"; break;
                case CategorySort.Timed: sortString = "timed"; break;
                default: sortString = "category_no"; break;
            }

            // Construct and execute the query
            string query = "SELECT category_no, category_name, timed FROM [" + Year +
                "_category] ORDER BY " + sortString + ";";
            SQLiteDataReader reader = DoTheReader(ClubConn, query);
            List<CategoryItem> catItemList = new List<CategoryItem>();
            CategoryItem item;

            // Read the results
            while (reader.Read())
            {
                item = new CategoryItem();
                item.No = reader.GetInt32(0);
                item.Name = reader.GetString(1);
                item.Timed = (bool)IntToBool(reader.GetInt32(2));
                catItemList.Add(item);
            }
            reader.Close();
            ClubConn.Close();
            return catItemList;
        }
Example #2
0
 /// <summary>
 /// Sets the category fileds to match argument <see cref="Category"/>.
 /// </summary>
 /// <param name="category">The category.</param>
 private void SetCategoryFileds(Category category)
 {
     if (category != null)
     {
         this.txbCategoryName.Text = category.Name;
         CategorySort sort = category.GetSortBySuperMarket(this._superMarket);
         this.nupSortValue.Value = sort.SortValue;
     }
     else
     {
         this.txbCategoryName.Text = String.Empty;
         this.nupSortValue.Value   = 0;
     }
 }
Example #3
0
        /// <summary>
        /// Creates a category.
        /// </summary>
        /// <param name="supermarket">The Supermarket that the category sort will be for.</param>
        /// <param name="catName">Name of the category.</param>
        /// <param name="sortValue">The sort value for category.</param>
        /// <returns>the category with a sort value for specified supermarket</returns>
        private static Category CreateCategory(Supermarket supermarket, string catName, int sortValue)
        {
            //creating the category
            Category cat = new Category()
            {
                Name = catName
            };
            //creating the sort
            CategorySort catSort = new CategorySort()
            {
                Category = cat, Supermarket = supermarket, SortValue = sortValue, SupermarketId = supermarket.Id
            };

            //assigning the sort
            cat.CategorySorts.Add(catSort);
            return(cat);
        }
Example #4
0
        /// <summary>
        /// Populates the formatted table.
        /// </summary>
        /// <param name="dt">The structured table.</param>
        /// <param name="list">The list.</param>
        private void PopulateFormattedTable(DataTable dt, IEnumerable <Product> list)
        {
            foreach (Product product in list)
            {
                DataRow currRow = dt.NewRow();
                currRow[DataTableConstans.COL_NAME_ID]             = product.Id;
                currRow[DataTableConstans.COL_NAME_PRODUCTNAME]    = product.ProductName;
                currRow[DataTableConstans.COL_NAME_NOTES]          = "";//this is not product notes, but notes for shopping item
                currRow[DataTableConstans.COL_NAME_PRICE]          = product.Price;
                currRow[DataTableConstans.COL_NAME_CATEGORY]       = product.Category.Name;
                currRow[DataTableConstans.COL_NAME_CATEGORYID]     = product.CategoryID;
                currRow[DataTableConstans.COL_NAME_CATEGORYOBJECT] = product.Category;
                currRow[DataTableConstans.COL_NAME_PRODUCT]        = product;

                CategorySort catSort = product.Category.CategorySorts.FirstOrDefault(cs => this._selectedSuperMarket != null &&
                                                                                     cs.SupermarketId == this._selectedSuperMarket.Id);
                currRow[DataTableConstans.COL_NAME_CATEGORY_SORT_VALUE] = catSort != null? catSort.SortValue : 0;


                dt.Rows.Add(currRow);
            }
        }
Example #5
0
 public void SortCategories(CategorySort sort)
 {
     CatList = Database.GetCategoryItemList(sort);
 }