protected bool HandleChangeQuantity(int index, int quantity) { try { if (index >= m_listItem.Count) { return(false); } ProductGridEntity item = m_listItem[index]; if (quantity < 0) { MessageBox.Show("Số lượng không được nhỏ hơn 0", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else { item.Quantity = quantity; item.Total = quantity * (item.Price - item.Discount); //updateGridData(); //avoid error "...result is a reentrant...." //update total m_gridView.Rows[index].Cells["m_colTotal"].Value = item.Total; return(true); } } catch (Exception exc) { AppLogger.logError(this.GetType().Name, exc); return(false); } }
public void HandleAddProductItem(ProductGridEntity item) { try { if (item != null) { bool isExist = false; foreach (ProductGridEntity product in m_listItem) { if (product.Id == item.Id) { product.Quantity++; product.Total = product.Quantity * product.Price; isExist = true; } } if (!isExist) { m_listItem.Add(item); } updateGridData(); } } catch (Exception exc) { AppLogger.logError(this.GetType().Name, exc); } }
private void m_gridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { DataGridViewCell cell = m_gridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (cell == null) { return; } bool result = false; //change quantity if (e.ColumnIndex == 4) { result = HandleChangeQuantity(e.RowIndex, int.Parse(StringUtil.ToEmpty(cell.Value))); } //apply discount else if (e.ColumnIndex == 5) { result = HandleDiscount(e.RowIndex, int.Parse(StringUtil.ToEmpty(cell.Value))); } else { ProductGridEntity item = null; //search product by barcode if (e.ColumnIndex == 1) { item = SearchProductByBarcode(StringUtil.ToEmpty(cell.Value)); } //search product by Name else if (e.ColumnIndex == 2) { item = SearchProductByName(StringUtil.ToEmpty(cell.Value)); } if (item != null) { HandleAddProductItem(item); result = true; } else { result = false; } } if (result == false && m_gridView.Rows.Count > 1 && e.RowIndex < m_gridView.Rows.Count - 1) { m_gridView.Rows.RemoveAt(e.RowIndex); } } catch (Exception exc) { AppLogger.logError(this.GetType().Name, exc); } }
private void m_gridView_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { ProductGridEntity item = SearchProductByBarcode(m_cacheBarcodeKey); if (item != null) { HandleAddProductItem(item); } m_cacheBarcodeKey = ""; } }
protected ProductGridEntity SearchProductByBarcode(string barcode) { try { AppLogger.logInfo(this.GetType().Name, " ENTER SearchProductByBarcode"); BindingProductEntity searchResult; SearchProductView searchComp = new SearchProductView(barcode, "", true); if (searchComp.getUniqueItem() != null) { searchResult = searchComp.getUniqueItem(); } else { searchComp.ShowDialog(); searchResult = searchComp.SelectedProduct; } if (searchResult != null) { ProductGridEntity product = new ProductGridEntity(); product.Id = searchResult.Id; product.Barcode = searchResult.Barcode; product.Name = searchResult.Name; product.Price = searchResult.Price; product.Quantity = 1; product.Discount = 0; product.Total = product.Quantity * product.Price; return(product); } return(null); } catch (Exception exc) { AppLogger.logError(this.GetType().Name, exc); return(null); } }
protected ProductGridEntity SearchProductByName(string name) { try { AppLogger.logInfo(this.GetType().Name, " ENTER SearchProductByName"); ProductFinderView searchComp = isBarcode ? new ProductFinderView(barcode: _model.Barcode, isSearchBarcode: true) : new ProductFinderView(name: _model.Name, isSearchBarcode: false); Product searchResult = null; if (searchComp.getUniqueItem() != null) { searchResult = searchComp.getUniqueItem(); } else { searchComp.ShowDialog(); searchResult = searchComp.SelectedProduct; } if (searchResult != null) { ProductGridEntity product = new ProductGridEntity(); product.Id = searchResult.Id; product.Barcode = searchResult.Barcode; product.Name = searchResult.Name; product.Price = searchResult.Price; product.Quantity = 1; product.Discount = 0; product.Total = product.Quantity * product.Price; return(product); } return(null); } catch (Exception exc) { AppLogger.logError(this.GetType().Name, exc); return(null); } }
private bool HandleDiscount(int index, double discount) { try { ProductGridEntity item = m_listItem[index]; if (index >= m_listItem.Count) { return(false); } if (discount < 0) { MessageBox.Show("Giá giảm không được nhỏ hơn 0", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else if (discount > item.Price) { MessageBox.Show("Giá giảm không được nhiều hơn giá bán", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else { item.Discount = discount; item.Total = item.Quantity * (item.Price - discount); //updateGridData(); // update total m_gridView.Rows[index].Cells["m_colTotal"].Value = item.Total; return(true); } } catch (Exception exc) { AppLogger.logError(this.GetType().Name, exc); return(false); } }