private List <ProductCell> GetMassiveProducts(MySqlCommand commandSQL) { List <ProductCell> products = new List <ProductCell>(); lock (locker) { using (MySqlDataReader readerMassive = commandSQL.ExecuteReader()) { while (readerMassive.Read()) { ProductCell product = new ProductCell(); product.product_id = (readerMassive.IsDBNull(0)) ? -1 : readerMassive.GetInt32(0); product.category = (readerMassive.IsDBNull(1)) ? -1 : readerMassive.GetInt32(1); product.subcat = (readerMassive.IsDBNull(2)) ? -1 : readerMassive.GetInt32(2); product.second_subcat = (readerMassive.IsDBNull(3)) ? -1 : readerMassive.GetInt32(3); product.product_code = readerMassive.GetInt32(4); product.product_vendore_code = (readerMassive.IsDBNull(5)) ? "" : readerMassive.GetString(5); product.product_name = (readerMassive.IsDBNull(6)) ? "" : readerMassive.GetString(6); product.product_price = (readerMassive.IsDBNull(7)) ? -1 : readerMassive.GetDouble(7); product.product_order = (readerMassive.IsDBNull(8)) ? "" : readerMassive.GetString(8); product.product_link_1 = (readerMassive.IsDBNull(9)) ? "" : readerMassive.GetString(9); product.product_link_2 = (readerMassive.IsDBNull(10)) ? "" : readerMassive.GetString(10); product.product_comment = (readerMassive.IsDBNull(11)) ? "" : readerMassive.GetString(11); product.created_at = readerMassive.GetString(12); product.product_url_image = (readerMassive.IsDBNull(13)) ? "" : readerMassive.GetString(13); products.Add(product); } commandSQL.Dispose(); return(products); } } }
//public override UITableViewCell GetCell( // UITableView _tableView, // NSIndexPath _indexPath) //{ // var cell = _tableView.DequeueReusableCell(cellIdentifier) as UITableViewCell; // if (cell == null) // { // cell = new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier); // } // #region Old Code // //var product = products[_indexPath.Row]; // //cell.TextLabel.Text = product.Name; // //cell.ImageView.Image = UIImage.FromFile(product.ImageFullPath); // //return cell; // #endregion Old Code // var product = products[_indexPath.Row]; // cell.TextLabel.Text = product.Name; // var imageData = this.GetImageData(product.ImageFullPath); // cell.ImageView.Image = UIImage.LoadFromData(imageData); // return cell; //} #endregion Old Code public override UITableViewCell GetCell( UITableView _tableView, NSIndexPath _indexPath) { var cell = _tableView.DequeueReusableCell(cellIdentifier) as ProductCell; if (cell == null) { cell = new ProductCell(cellIdentifier); } #region Old Code //var product = products[_indexPath.Row]; //cell.UpdateCell( // product.Name, // $"{product.Price:C2}", // UIImage.FromFile(product.ImageUrl)); #endregion Old Code var product = products[_indexPath.Row]; var imageData = this.GetImageData(product.ImageFullPath); cell.UpdateCell( product.Name, $"{product.Price:C2}", UIImage.LoadFromData(imageData)); return(cell); }
private void UpdateListProducts() { if (_listProducts != null) { _listProducts.RemoveFromSuperview(); } _listProducts = new GridView((RectangleF)View.Bounds) { AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth, Delegate = this, BackgroundColor = Consts.ColorMainBg }; Add(_listProducts); foreach (var product in ((ProductsGridViewModel)ViewModel).Products) { var cell = new ProductCell(CartAdd); cell.Bind(product); _listProducts.AddTile(cell); } if (_showFilters) { View.BringSubviewToFront(_overlayView); View.BringSubviewToFront(_filterView); } }
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item) { var cell = tableView.DequeueReusableCell(ProductCell.Key) as ProductCell; if (cell == null) { cell = ProductCell.Create(); } //cell.Type.Text = item as string; cell.ViewModel = item as Tuple <string, string, string, string, double>; return(cell); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { var cell = tableView.DequeueReusableCell(cellIdentifier) as ProductCell; if (cell == null) { cell = new ProductCell(cellIdentifier); } var product = products[indexPath.Row]; cell.UpdateCell(product.Name, $"{product.Price:C2}", UIImage.FromFile(product.ImageUrl)); return(cell); }
public void AddPriceProduct(ref ProductCell product, ref DateTime created_at_D) { lock (locker) { using (MySqlCommand commandSQL = new MySqlCommand(InsertPrice, connection)) { commandSQL.Parameters.AddWithValue("@product_code", product.product_code); commandSQL.Parameters.AddWithValue("@price", product.product_price); commandSQL.Parameters.AddWithValue("@ordering", product.product_order); commandSQL.Parameters.AddWithValue("@created_at", product.created_at); commandSQL.Parameters.AddWithValue("@created_at_D", created_at_D); commandSQL.ExecuteNonQuery(); commandSQL.Dispose(); } } }
private ProductCell CreateProductCell(ProductInformation product, int currentYPosition) { ProductCell cell = new ProductCell( product: product, yPosition: currentYPosition, groupWidth: productsPanel.Width - 20, labelFont: labelFont, textBoxFont: textBoxFont, barcodeLabelFont: barcodeLabelFont ); cell.EditButton.Click += (o, arg) => { int oldPositionNumber = product.PositionNumber; editProduct( product, cell.ProductPositionNumberTextBox.Text, cell.ProductNameTextBox.Text, cell.ProductPriceTextBox.Text, cell.ProductBarcodeTextBox.Text ); if (oldPositionNumber != product.PositionNumber) { EditCell(product); } MessageBox.Show($"Товар {product.Name} изменен"); }; cell.DeleteButton.Click += (o, arg) => { bool successfullyDeleted = deleteProduct(product); if (successfullyDeleted) { DeleteCell(product); } MessageBox.Show($"Товар {product.Name} удален"); }; return(cell); }
public ProductsPanelManager(LinkedList <ProductInformation> products, Panel productsPanel, int maxDisplayedCells, Action <ProductInformation, string, string, string, string> editProduct, Func <ProductInformation, bool> deleteProduct) // string в параметре-типе: 1 - позиция; 2 - название; 3 - цена; 4 - штрих-код { if (products == null) { throw new ArgumentNullException("База товаров равна null"); } this.maxDisplayedCells = maxDisplayedCells; this.productsPanel = productsPanel; this.editProduct = editProduct; this.deleteProduct = deleteProduct; pages = new LinkedList <ProductCells>(); int currentYPosition = startedYPos; int count = 1; // Распределяем товары по страницам foreach (var product in products) { if (count > maxDisplayedCells) { currentYPosition = startedYPos; count = 1; } if (count == 1) { pages.AddLast(new ProductCells()); } ProductCell cell = CreateProductCell(product, currentYPosition); pages.Last.Value.AddLast(cell); currentYPosition = GetNextYPos(currentYPosition); ++count; } currentPage = pages.First; CurrentPageNum = 1; }
public void AddProduct(ref ProductCell product) { lock (locker) { using (MySqlCommand commandSQL = new MySqlCommand(InsertProduct, connection)) { commandSQL.Parameters.AddWithValue("@category_id", product.category); commandSQL.Parameters.AddWithValue("@subcat_id", product.subcat); commandSQL.Parameters.AddWithValue("@second_subcat_id", product.second_subcat); commandSQL.Parameters.AddWithValue("@product_code", product.product_code); commandSQL.Parameters.AddWithValue("@product_vendore_code", product.product_vendore_code); commandSQL.Parameters.AddWithValue("@product_name", product.product_name); commandSQL.Parameters.AddWithValue("@product_price", product.product_price); commandSQL.Parameters.AddWithValue("@product_ordering", product.product_order); commandSQL.Parameters.AddWithValue("@product_link_1", product.product_link_1); commandSQL.Parameters.AddWithValue("@product_link_2", product.product_link_2); commandSQL.Parameters.AddWithValue("@product_comment", product.product_comment); commandSQL.Parameters.AddWithValue("@created_at", product.created_at); commandSQL.Parameters.AddWithValue("@product_url_image", product.product_url_image); commandSQL.ExecuteNonQuery(); commandSQL.Dispose(); } } }
public void AddCell(ProductInformation product) { bool currentPageChanged = false; ProductCell cell = CreateProductCell(product, startedYPos); if (pages.Count == 0) { pages.AddLast(new LinkedList <ProductCell>()); pages.First.Value.AddLast(cell); currentPage = pages.First; DisplayCurrentPage(); currentPageChanged = true; } // Если у нас уже отображены товары, тогда необходимо найти место для текущего товара // и сдвинуть все последующие на NextYPos(от текущей позиции). Если после вставки // количество товаров на странице стало больше, чем maxDisplayedCells, тогда переносим последний // товар на странице на следующую страницу (тоже самое проделываем и с последующими страницами) // Если для товара не нашлось места, значит его номер больше, чем у остальных товаров, поэтому вставляем // его на последнюю страницу, в конец (не забывая про maxDisplayedCells) // Так же нужно отобразить вставленные или перенесенные товары, если они находятся на текущей странице. // Если же отображаемый ранее товар был перенесен на другую страницу, тогда его следует сделать невидимым // и удалить из коллекции панели продуктов. else { bool found = false; // Ищем позицию для добавленного товара и смещаем все последующие позиции for (Page pageNode = pages.First; pageNode != null; pageNode = pageNode.Next) { for (Cell cellNode = pageNode.Value.First; cellNode != null; cellNode = cellNode.Next) { // Если это перенесенная позиция с прошлой страницы, то пропускаем if (found && cellNode == pageNode.Value.First) { continue; } if (!found && product.PositionNumber < cellNode.Value.Product.PositionNumber) { cell.Cell.Location = cellNode.Value.Cell.Location; pageNode.Value.AddBefore(cellNode, cell); // Если вставленная позиция на текущей странице, то делаем её видимой if (currentPage == pageNode) { cell.Cell.Visible = true; productsPanel.Controls.Add(cell.Cell); currentPageChanged = true; } found = true; } // Сдвигаем все последующие позиции if (found) { int currentYPos = cellNode.Value.Cell.Location.Y; cellNode.Value.SetNewGroupYPosition(GetNextYPos(currentYPos)); } } // Если количество товаров на странице больше максимально возможного, // то делаем перенос последнего товара на следующую страницу if (pageNode.Value.Count > maxDisplayedCells) { pageNode.Value.Last.Value.SetNewGroupYPosition(startedYPos); productsPanel.Controls.Remove(pageNode.Value.Last.Value.Cell); pageNode.Value.Last.Value.Cell.Visible = false; if (pageNode.Next != null) { pageNode.Next.Value.AddFirst(pageNode.Value.Last.Value); // Если перенесенная позиция на текущей странице, то делаем её видимой if (pageNode.Next == currentPage) { pageNode.Next.Value.First.Value.Cell.Visible = true; productsPanel.Controls.Add(pageNode.Next.Value.First.Value.Cell); } } else { pageNode.List.AddLast(new LinkedList <ProductCell>()); pageNode.List.Last.Value.AddLast(pageNode.Value.Last.Value); if (pageNode == currentPage) { currentPageChanged = true; } } pageNode.Value.Remove(pageNode.Value.Last); } } // Если место не найдено, значит добавляем в конец последней страницы if (!found) { // Если количество товаров на последней странице - максимальное, то // создаем новую и переносим туда наш товар if (pages.Last.Value.Count + 1 > maxDisplayedCells) { pages.AddLast(new LinkedList <ProductCell>()); pages.Last.Value.AddLast(cell); if (currentPage == pages.Last.Previous) { currentPageChanged = true; } } else { int lastCellYPos = pages.Last.Value.Last.Value.Cell.Location.Y; cell.SetNewGroupYPosition(GetNextYPos(lastCellYPos)); pages.Last.Value.AddLast(cell); // Если вставленная на последнюю страницу позиция - на текущей странице, то делаем её видимой if (pages.Last == currentPage) { productsPanel.Controls.Add(cell.Cell); cell.Cell.Visible = true; } } } } if (currentPageChanged && CurrentPageChanged != null) { CurrentPageChanged(); } }