private void ShowNewProductData(NewProductData newProd) { ListViewItem item = new ListViewItem(new string[] { mAllowedSubcategories.Find(subcat => newProd.Product.ProductSubCategoryId == subcat.Id).SubCategoryName, newProd.BrandName, newProd.Product.ProductName, newProd.Product.Size, newProd.Product.ManufacturerPartNum, newProd.VendorProduct.VendorPartNum, newProd.Product.RetailPrice.ToString("C2"), newProd.VendorProduct.EachCost.ToString("C2"), newProd.VendorProduct.CaseCost.ToString("C2"), newProd.VendorProduct.CountInCase.ToString(), newProd.Product.IsActive.ToString(), newProd.Product.ManufacturerBarcode }); lvwNewProducts.Items.Add(item); }
private bool TryProcessFields(string[] fields, int lineNumber) { if (fields.Length < 10) { MessageBox.Show(string.Format("Not enough fields on line {0}", lineNumber)); return(false); } string productName = GetInputColumn(fields, mColProductName).Trim(); if (ValidateString("Product name", productName, 4, 100, lineNumber)) { return(false); } string productSize = GetInputColumn(fields, mColProductSize).Trim(); if (ValidateString("Product size", productSize, 0, 30, lineNumber)) { return(false); } string vendorCode = GetInputColumn(fields, mColVendorCode).Trim(); if (vendorCode.StartsWith("#")) { vendorCode = vendorCode.Substring(1); } if (ValidateString("Vendor code", vendorCode, 1, 30, lineNumber)) { return(false); } decimal retailPrice; if (ValidateDecimal("Retail price", GetInputColumn(fields, mColRetail), out retailPrice, lineNumber)) { return(false); } decimal caseCost; if (ValidateDecimal("Case cost", GetInputColumn(fields, mColCsCost), out caseCost, lineNumber)) { return(false); } int countInCase; if (ValidateInt("Count in case", GetInputColumn(fields, mColCsSize), out countInCase, lineNumber)) { return(false); } decimal eachCost; if (ValidateDecimal("Each cost", GetInputColumn(fields, mColEaCost), out eachCost, lineNumber)) { return(false); } // Brand string brandName = GetInputColumn(fields, mColBrand).Trim(); if (ValidateString("Brand name", brandName, 3, 80, lineNumber)) { return(false); } ProductBrand brandToUse = null; foreach (ProductBrand existingBrand in mBrands) { if (NormalizeBrandName(existingBrand.BrandName).Equals( NormalizeBrandName(brandName), StringComparison.OrdinalIgnoreCase)) { brandToUse = existingBrand; break; } } if (brandToUse == null) { DialogResult newBrandAnswer = MessageBox.Show(string.Format( "Brand name \"{0}\" not found. Do you want to create it?", brandName), "New Brand Name", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (newBrandAnswer != DialogResult.Yes) { return(false); } brandToUse = new ProductBrand(new ProductBrandId(), brandName, string.Empty, true, string.Empty, DateTime.Now, DateTime.Now); mBrands.Add(brandToUse); } // Subcategory ProductSubCategory subCatToUse = null; string subCatName = GetInputColumn(fields, mColSubcategory); foreach (ProductSubCategory subCat in mAllowedSubcategories) { if (subCat.SubCategoryName.Equals(subCatName, StringComparison.OrdinalIgnoreCase)) { subCatToUse = subCat; break; } } if (subCatToUse == null) { MessageBox.Show(string.Format("Subcategory \"{0}\" not found.", subCatName), "No such subcategory", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // IsActive string isActiveText = GetInputColumn(fields, mColIsActive).ToUpper(); bool isActive; if (isActiveText == "Y") { isActive = true; } else if (isActiveText == "N") { isActive = false; } else { MessageBox.Show(string.Format("Invalid active flag on line {0}", lineNumber)); return(false); } // Barcode string barcode = GetInputColumn(fields, mColBarcode); if (ValidateString("Barcode", barcode, 0, 30, lineNumber)) { return(false); } // Model string model = GetInputColumn(fields, mColModel); if (ValidateString("Model", model, 0, 30, lineNumber)) { return(false); } NewProductData rec = new NewProductData(); rec.Product = new Product(new ProductId(), productName, subCatToUse.Id, productSize, retailPrice, brandToUse.Id, barcode, model, isActive, false, false, false, false, 0, 0, 0, 0, string.Empty, 0.0m, 0.0m, DateTime.Now, DateTime.Now); rec.VendorProduct = new VendorProduct(new VendorProductId(), mVendor.Id, new ProductId(), 0m, vendorCode, caseCost, countInCase, eachCost, isActive, isActive, false, false, new DateTime(1980, 1, 1), string.Empty, false, false, string.Empty, DateTime.Now, DateTime.Now); rec.BrandName = brandName; mProductDataToSave.Add(rec); ShowNewProductData(rec); return(true); }