예제 #1
0
        /// <summary>
        /// Gets a shopping based on data in GUI.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        private ShopList GetShoppingListFromGui()
        {
            Logger.Log("Getting shopping list from gui");
            ShopList list = new ShopList();


            foreach (DataGridViewRow currRow in this.gvProducts.Rows)
            {
                bool             toBuy    = Convert.ToBoolean(currRow.Cells[this.clmToBuy.Index].Value);
                DataGridViewCell cllQuant = currRow.Cells[this.clmQuantity.Index];
                int quantity;
                if (toBuy && cllQuant.Value != null && int.TryParse(cllQuant.Value.ToString(), out quantity))
                {
                    ShoplistItem item = new ShoplistItem();
                    item.Product  = (Product)currRow.DataBoundItem;
                    item.Quantity = quantity;
                    item.ShopList = list;
                    list.ShoplistItems.Add(item);
                }
            }


            Supermarket market = this.cmbSuperMarkets.SelectedItem as Supermarket;

            list.Supermarket   = market;
            list.SuperMarketId = market.Id;
            Logger.Log(String.Format("got shopping list from gui: {0}", list.ToString()));
            return(list);
        }
예제 #2
0
        public ShopList GetShoppingList(Dictionary <Product, int> quantityByProduct, Supermarket market, Customer customer)
        {
            ShopList list = new ShopList();

            foreach (var pair in quantityByProduct)
            {
                var          product  = pair.Key;
                var          quantity = pair.Value;
                ShoplistItem item     = new ShoplistItem();
                item.Product   = product;
                item.ProductId = product.Id;
                item.Quantity  = quantity;
                item.ShopList  = list;
                list.ShoplistItems.Add(item);
            }


            if (market == null)
            {
                var markets = this.GetAllSuperMarkets();
                market = markets[0];
            }
            list.Supermarket   = market;
            list.SuperMarketId = market.Id;


            return(this.GetSortedList(list, customer));
        }
예제 #3
0
        public void SortedGivenShopListTest()
        {
            //Assign
            Supermarket     sm;
            List <Category> categories;
            List <Product>  products;

            SmartShopLogicsTests.CreateDataBaseObjects(out sm, out categories, out products);

            ShopList list = new ShopList();

            #region Populating shopping list
            list.Supermarket   = sm;
            list.SuperMarketId = sm.Id;
            for (int i = 0; i < products.Count; i++)
            {
                Product      currProduct = products[i];
                ShoplistItem newItem     = new ShoplistItem()
                {
                    Product = currProduct, Quantity = i, ShopList = list
                };
                list.ShoplistItems.Add(newItem);
            }
            #endregion


            //act
            DataBase        dataBase = Substitute.For <DataBase>();
            SmartShopLogics bs       = new SmartShopLogics(dataBase);
            ShopList        sorted   = bs.GetSortedList(list, null);

            //assert
            int lastCategoryId = -1;
            for (int i = 0; i < sorted.ShoplistItems.Count; i++)
            {
                List <ShoplistItem> items = sorted.ShoplistItems.ToList();
                int currCategory          = items[i].Product.Category.CategorySorts.Where(cat => cat.Supermarket == sm).SingleOrDefault().SortValue;
                //If list is sorted, the sort value should always increase
                Assert.IsTrue(currCategory >= lastCategoryId, "Shopping list was not sorted properly ({0} sort value came before {1})", lastCategoryId, currCategory);
                lastCategoryId = currCategory;
            }
        }
예제 #4
0
        private void GenerateDataRows(Worksheet sheet)
        {
            String lastCategoryName = String.Empty;

            for (int i = 0; i < this.Items.Count; i++)
            {
                ShoplistItem currItem = this.Items[i];

                bool addCategoryRow = lastCategoryName != currItem.Product.Category.Name;

                if (addCategoryRow)
                {
                    WorksheetRow workSHeetCategoryRow = sheet.Table.Rows.Add();
                    workSHeetCategoryRow.Height        = 15;
                    workSHeetCategoryRow.AutoFitHeight = false;
                    WorksheetCell cell = workSHeetCategoryRow.Cells.Add();
                    cell.StyleID   = "s65";
                    cell.Data.Type = DataType.String;
                    cell.Data.Text = currItem.Product.Category.Name;
                    cell.NamedCell.Add("Print_Area");
                    cell         = workSHeetCategoryRow.Cells.Add();
                    cell.StyleID = "s66";
                    cell.NamedCell.Add("Print_Area");
                    cell         = workSHeetCategoryRow.Cells.Add();
                    cell.StyleID = "s66";
                    cell.NamedCell.Add("Print_Area");
                    cell         = workSHeetCategoryRow.Cells.Add();
                    cell.StyleID = "s66";
                    cell.NamedCell.Add("Print_Area");
                    cell         = workSHeetCategoryRow.Cells.Add();
                    cell.StyleID = "s66";
                    cell.NamedCell.Add("Print_Area");
                    cell         = workSHeetCategoryRow.Cells.Add();
                    cell.StyleID = "s66";
                    cell.NamedCell.Add("Print_Area");
                }


                WorksheetRow workSHeetDataRow = sheet.Table.Rows.Add();
                workSHeetDataRow.Height        = 15;
                workSHeetDataRow.AutoFitHeight = false;
                WorksheetCell workSHeetDatacell = workSHeetDataRow.Cells.Add();
                workSHeetDatacell.StyleID = "s67";
                workSHeetDatacell.NamedCell.Add("Print_Area");
                workSHeetDatacell.StyleID   = "s68";
                workSHeetDatacell           = workSHeetDataRow.Cells.Add();
                workSHeetDatacell.Data.Type = DataType.String;
                workSHeetDatacell.Data.Text = currItem.Product.ProductName;
                workSHeetDatacell.NamedCell.Add("Print_Area");
                workSHeetDatacell           = workSHeetDataRow.Cells.Add();
                workSHeetDatacell.StyleID   = "s68";
                workSHeetDatacell.Data.Type = DataType.Number;
                workSHeetDatacell.Data.Text = currItem.Quantity.ToString("N0");
                workSHeetDatacell.NamedCell.Add("Print_Area");
                workSHeetDatacell           = workSHeetDataRow.Cells.Add();
                workSHeetDatacell.StyleID   = "s69";
                workSHeetDatacell.Data.Type = DataType.Number;
                workSHeetDatacell.Data.Text = currItem.Product.Price.ToString();
                workSHeetDatacell.NamedCell.Add("Print_Area");
                workSHeetDatacell           = workSHeetDataRow.Cells.Add();
                workSHeetDatacell.StyleID   = "s68";
                workSHeetDatacell.Data.Type = DataType.String;
                workSHeetDatacell.Data.Text = currItem.Product.Notes;
                workSHeetDatacell.NamedCell.Add("Print_Area");
                workSHeetDatacell           = workSHeetDataRow.Cells.Add();
                workSHeetDatacell.StyleID   = "s70";
                workSHeetDatacell.Data.Type = DataType.Number;
                workSHeetDatacell.Data.Text = "11.58";
                workSHeetDatacell.Formula   = "=RC[-3]*RC[-2]";
                workSHeetDatacell.NamedCell.Add("Print_Area");

                lastCategoryName = currItem.Product.Category.Name;
            }
        }