public Workbook Generate(ShopList shopList) { this._shopList = shopList; Workbook book = new Workbook(); // ----------------------------------------------- // Properties // ----------------------------------------------- book.Properties.Author = ""; book.Properties.LastAuthor = ""; book.Properties.Created = new System.DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, 0); book.Properties.Version = "12.00"; book.ExcelWorkbook.WindowHeight = 10035; book.ExcelWorkbook.WindowWidth = 23955; book.ExcelWorkbook.WindowTopX = 0; book.ExcelWorkbook.WindowTopY = 90; book.ExcelWorkbook.ProtectWindows = false; book.ExcelWorkbook.ProtectStructure = false; // ----------------------------------------------- // Generate Styles // ----------------------------------------------- this.GenerateStyles(book.Styles); // ----------------------------------------------- // Generate Sheet1 Worksheet // ----------------------------------------------- this.GenerateShopListWorksheet(book.Worksheets); return book; }
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); //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; } }
/// <summary> /// Exports the list to excel. /// </summary> /// <param name="shopList">The shop list.</param> private void ExportListToExcel(ShopList shopList) { FileExporter.ExcelExporter exporter = new FileExporter.ExcelExporter(); CarlosAg.ExcelXmlWriter.Workbook book = exporter.Generate(shopList); SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "ShopList.xls"; sfd.Filter = "Excel XML Documents (*.xls)|*.xls"; if (sfd.ShowDialog() == DialogResult.OK) { String filename = sfd.FileName; if (!filename.EndsWith("xls")) { filename += "xls"; } try { book.Save(filename); using (Process prc = new Process()) { Process.Start(filename); } } catch (Exception ex) { this.ShowMessage(ex.Message); } } }
/// <summary> /// Matches the GUI to shoplist. /// </summary> /// <param name="shopList">The shop list.</param> private void MatchGuiToShoplist(ShopList shopList) { List<KeyValuePair<int, int>> quantityByProductIds = shopList.ShoplistItems.Select(si => new KeyValuePair<int, int>(si.ProductId, si.Quantity)).ToList(); for (int i = 0; i < this.gvProducts.Rows.Count; i++) { DataGridViewRow row = this.gvProducts.Rows[i]; int productId = (int)row.Cells[DataTableConstans.COL_NAME_ID].Value; //get the quantiny and product Id of this row KeyValuePair<int, int> currPriceByProduct = quantityByProductIds.Where(pair => pair.Key == productId).FirstOrDefault(); bool isProductInList = currPriceByProduct.Key > 0; ; //set values in grid view gvProducts.Rows[i].Cells[DataTableConstans.COL_NAME_TO_BUY].Value = isProductInList; gvProducts.Rows[i].Cells[DataTableConstans.COL_NAME_QUANTITY].Value = isProductInList ? currPriceByProduct.Value.ToString() : String.Empty; } }
private void Confirm() { this._selectedList = this.GetSelectedList() ; this.DialogResult = DialogResult.OK; }
public ShopList GetSortedList(ShopList list) { BusinessLogics.SortShopList(list); return list; }
/// <summary> /// Sorts the specified shop list. /// </summary> /// <param name="shoppingList">The shopping list.</param> private void SortShopList(ShopList shoppingList) { Array items = shoppingList.ShoplistItems.ToArray<ShoplistItem>(); Array.Sort(items); shoppingList.ShoplistItems = (ICollection<ShoplistItem>)items; }
/// <summary> /// Saves the shoplist to db. /// </summary> /// <param name="list">The list.</param> public bool SaveShoplist(ShopList list, out string errorMsg) { errorMsg = String.Empty; bool isInDb = this._db.ShopLists.Any(sl => sl.Id == list.Id); if (isInDb) { ShopList inDb = this._db.ShopLists.Where(sl => sl.Id == list.Id).FirstOrDefault(); inDb.ShoplistItems = list.ShoplistItems; inDb.Supermarket = list.Supermarket; inDb.Customer = list.Customer; inDb.Date = list.Date; inDb.Title = list.Title ?? String.Empty; } else { list.Title = list.Title ?? String.Format("{0}: {1}", list.Supermarket.Name, DateTime.Now.ToShortDateString()); this._db.ShopLists.Add(list); } string saveErrors; bool success = this.SaveChanges(out saveErrors); errorMsg = saveErrors ; return success; }
/// <summary> /// Saves the shop listto DB. /// </summary> /// <param name="list">The list.</param> /// <param name="customer">The customer.</param> private bool SaveShopList(ShopList list, Customer customer) { list.Customer = customer; list.CustomerId = customer.Id; if (list.Date == DateTime.MinValue) { list.Date = DateTime.Now; } string errorMessage; return this._db.SaveShoplist(list, out errorMessage); }
public ShopList GetSortedList(ShopList list) { this.SortShopList(list); return list; }
public ShopList GetSortedList(ShopList list,Customer customer) { this.SortShopList(list); if (customer != null) { this.SaveShopList(list, customer); } return list; }
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); }
public IEnumerable<ShoplistItemCandidate> GetAllShoplistCandidates(ShopList shopListBase) { var allProducts = this.GetAllProducts(); var items = allProducts.Select(p => new ShoplistItemCandidate(p)); if (shopListBase != null) { foreach (var shopItem in shopListBase.ShoplistItems) { var matchingItem = items.Where(i => i.Id == shopItem.Id).FirstOrDefault(); if (matchingItem != null) { matchingItem.Quantity = shopItem.Quantity; matchingItem.ToBuy = true; } } } return items; }
/// <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; }
/// <summary> /// Exports the list to excel. /// </summary> /// <param name="shopList">The shop list.</param> private static void ExportListToExcel(ShopList shopList) { FileExporter.ExcelExporter exporter = new FileExporter.ExcelExporter(); CarlosAg.ExcelXmlWriter.Workbook book = exporter.Generate(shopList); SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "ShopList.xls"; sfd.Filter = "Excel XML Documents (*.xls)|*.xls"; if (sfd.ShowDialog() == DialogResult.OK) { String filename = sfd.FileName; if (!filename.EndsWith("xls")) { filename += "xls"; } try { book.Save(filename); //File.Open(filename, FileMode.OpenOrCreate); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }