/// <summary> /// 确定是否有履行当前选定订单的 /// 足够产品库存。 /// </summary> /// <returns></returns> private bool CanFulfillOrder() { Excel.Range listRange = this.ProductList.DataBodyRange; for (int i = 1; i <= listRange.Rows.Count; i++) { // 获取 ListRow 中的值。 object[,] values = (object[, ])((Excel.Range)listRange.Rows[i, missing]).Value2; // 确定该行表示哪种产品。 if (values[1, productNameColumn] == null) { continue; } string product = values[1, productNameColumn].ToString(); // 如果该行中有一种产品,请确定该产品的可用数量。 if (!String.IsNullOrEmpty(product)) { int quantity = Convert.ToInt32(values[1, quantityOrderedColumn]); CompanyData.ProductsRow productRow = Globals.ThisWorkbook.CurrentCompanyData.Products.FindByName(product); // 检查是否有足够的库存满足订购的数量。 if ((productRow.Inventory - quantity) < 0) { return(false); } } } return(true); }
/// <summary> /// Determines if there is enough inventory of the products /// for the currently selected order. /// </summary> /// <returns></returns> private bool CanFulfillOrder() { Excel.Range listRange = this.ProductList.DataBodyRange; for (int i = 1; i <= listRange.Rows.Count; i++) { // Get the values within the ListRow. object[,] values = (object[, ])((Excel.Range)listRange.Rows[i, missing]).Value2; // Determine what product the row is representing. if (values[1, productNameColumn] == null) { continue; } string product = values[1, productNameColumn].ToString(); // If there is a product in this row, determine the available quantity of that product. if (!String.IsNullOrEmpty(product)) { int quantity = Convert.ToInt32(values[1, quantityOrderedColumn]); CompanyData.ProductsRow productRow = Globals.ThisWorkbook.CurrentCompanyData.Products.FindByName(product); // Check to see if there is enough inventory for the quantity being ordered. if ((productRow.Inventory - quantity) < 0) { return(false); } } } return(true); }
/// <summary> /// 根据履行的当前订单,更新产品的可用库存。 /// </summary> private void UpdateInventory() { Excel.Range listRange = this.ProductList.DataBodyRange; for (int i = 1; i <= listRange.Rows.Count; i++) { // 获取 ListRow 中的值。 object[,] values = (object[, ])((Excel.Range)listRange.Rows[i, missing]).Value2; if (values[1, productNameColumn] == null) { continue; } // 确定该行表示哪种产品。 string product = values[1, productNameColumn].ToString(); // 如果该行中有一种产品,请确定该产品的可用数量。 if (!String.IsNullOrEmpty(product)) { int quantity = Convert.ToInt32(values[1, quantityOrderedColumn]); CompanyData.ProductsRow productRow = Globals.ThisWorkbook.CurrentCompanyData.Products.FindByName(product); // 更新 ProductRow 以反映新的库存水平。 productRow.Inventory = productRow.Inventory - quantity; } } // 保存对数据集的更改。 Globals.ThisWorkbook.CurrentCompanyData.AcceptChanges(); }
/// <summary> /// Updates the available inventory of products based on the current order being fulfilled. /// </summary> private void UpdateInventory() { Excel.Range listRange = this.ProductList.DataBodyRange; for (int i = 1; i <= listRange.Rows.Count; i++) { // Get the values within the ListRow. object[,] values = (object[, ])((Excel.Range)listRange.Rows[i, missing]).Value2; if (values[1, productNameColumn] == null) { continue; } // Determine what product the row is representing. string product = values[1, productNameColumn].ToString(); // If there is a product in this row, determine the available quantity of that product. if (!String.IsNullOrEmpty(product)) { int quantity = Convert.ToInt32(values[1, quantityOrderedColumn]); CompanyData.ProductsRow productRow = Globals.ThisWorkbook.CurrentCompanyData.Products.FindByName(product); // Update the ProductRow to reflect the new inventory level. productRow.Inventory = productRow.Inventory - quantity; } } // Save changes to the DataSet. Globals.ThisWorkbook.CurrentCompanyData.AcceptChanges(); }