private void ProcessOptPrices(string optPricesFilePath) { using (var csv = new CsvHelper.CsvReader(new StreamReader(optPricesFilePath, Encoding.UTF8)))// Encodings.GetEncoding()))) { LogInvalidData(string.Format("ProcessOptPrices Start 1: Encoding: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now)); csv.Configuration.Delimiter = Separators.GetCharSeparator(); csv.Configuration.HasHeaderRecord = true; Product product; bool firstRead = true; // LogInvalidData(string.Format("ProcessOptPrices Start 2: Encoding: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now)); while (csv.Read()) { try { // LogInvalidData(string.Format("ProcessOptPrices Start 3: csv: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now)); if (firstRead) { for (int i = 0; i < csv.FieldHeaders.Length; i++) { FieldMapping.Add(csv.FieldHeaders[i], i); } firstRead = false; } // LogInvalidData(string.Format("ProcessOptPrices Start 4: csv: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now)); var productInStrings = new Dictionary <ProductFields.Fields, string>(); string artNo = ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku); if (FieldMapping.ContainsKey(artNo)) { productInStrings.Add(ProductFields.Fields.Sku, Convert.ToString(csv[FieldMapping[artNo]])); } //sku;amount;priceOpt1;priceOpt2;priceAkc1;priceAkc2;priceSpec;priceEur product = ProductService.GetProduct(Convert.ToString(csv[FieldMapping[artNo]])); decimal priceOpt1; decimal priceOpt2; decimal priceAkc1; decimal priceAkc2; decimal priceSpec; decimal priceEur; decimal.TryParse(csv["priceOpt1"].ToString().Replace(" ", ""), out priceOpt1); decimal.TryParse(csv["priceOpt2"].ToString().Replace(" ", ""), out priceOpt2); decimal.TryParse(csv["priceAkc1"].ToString().Replace(" ", ""), out priceAkc1); decimal.TryParse(csv["priceAkc2"].ToString().Replace(" ", ""), out priceAkc2); decimal.TryParse(csv["priceSpec"].ToString().Replace(" ", ""), out priceSpec); decimal.TryParse(csv["priceEur"].ToString().Replace(" ", ""), out priceEur); if (priceEur == 0 && csv["priceEur"].ToString().Contains(".")) { decimal.TryParse(csv["priceEur"].ToString().Replace(" ", "").Replace(".", ","), out priceEur); } string briefDescription = csv["BriefDescription"].ToString(); product.BriefDescription = briefDescription; product.Offers.Add(new Offer { Amount = product.Offers[0].Amount, OfferListId = 9, Price = priceOpt1, ShippingPrice = 0, SupplyPrice = 0, Unit = product.Offers[0].Unit, Multiplicity = product.Offers[0].Multiplicity }); product.Offers.Add(new Offer { Amount = product.Offers[0].Amount, OfferListId = 12, Price = priceOpt2, ShippingPrice = 0, SupplyPrice = 0, Unit = product.Offers[0].Unit, Multiplicity = product.Offers[0].Multiplicity }); product.Offers.Add(new Offer { Amount = product.Offers[0].Amount, OfferListId = 13, Price = priceAkc1, ShippingPrice = 0, SupplyPrice = 0, Unit = product.Offers[0].Unit, Multiplicity = product.Offers[0].Multiplicity }); product.Offers.Add(new Offer { Amount = product.Offers[0].Amount, OfferListId = 14, Price = priceAkc2, ShippingPrice = 0, SupplyPrice = 0, Unit = product.Offers[0].Unit, Multiplicity = product.Offers[0].Multiplicity }); product.Offers.Add(new Offer { Amount = product.Offers[0].Amount, OfferListId = 15, Price = priceSpec, ShippingPrice = 0, SupplyPrice = 0, Unit = product.Offers[0].Unit, Multiplicity = product.Offers[0].Multiplicity }); product.Offers.Add(new Offer { Amount = product.Offers[0].Amount, OfferListId = 16, Price = priceEur, ShippingPrice = 0, SupplyPrice = 0, Unit = product.Offers[0].Unit, Multiplicity = product.Offers[0].Multiplicity }); // LogInvalidData(string.Format("ProcessOptPrices Start 5: csv: {0}, File: {1}, Time: {2}", product.ArtNo, optPricesFilePath, DateTime.Now)); ProductService.UpdateProduct(product, false); // LogInvalidData(string.Format("ProcessOptPrices Start 6: csv: {0}, File: {1}, Time: {2}", product.ArtNo, optPricesFilePath, DateTime.Now)); } catch (Exception ex) { LogInvalidData("Ex " + ex.Message + DateTime.Now.ToString()); } } } try { File.Copy(optPricesFilePath, optPricesFilePath.Replace("OstatkiWseCeny.csv", string.Format("OstatkiWseCeny_done{0}.csv", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")))); FileHelpers.DeleteFile(optPricesFilePath); } catch (Exception ex) { LogInvalidData("Ex File.Copy(... " + ex.Message + DateTime.Now.ToString()); } }
private void ProcessCsv() { string _filePath = FoldersHelper.GetPathAbsolut(FolderType.PriceTemp); string _fullPath = string.Format("{0}{1}", _filePath, "ostatki.csv"); LogInvalidData("Start working on Update (1C). File " + _fullPath + DateTime.Now.ToString()); if (!File.Exists(_fullPath)) { return; } long count = 0; using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding()))) { csv.Configuration.Delimiter = Separators.GetCharSeparator(); csv.Configuration.HasHeaderRecord = true; while (csv.Read()) { count++; } } ImportStatistic.TotalRow = count; LogInvalidData("ImportStatistic.TotalRow = " + count.ToString() + DateTime.Now.ToString()); using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding()))) { csv.Configuration.Delimiter = Separators.GetCharSeparator(); csv.Configuration.HasHeaderRecord = true; bool firstRead = true; while (csv.Read()) { try { if (firstRead) { for (int i = 0; i < csv.FieldHeaders.Length; i++) { FieldMapping.Add(csv.FieldHeaders[i], i); } firstRead = false; } var productInStrings = new Dictionary <ProductFields.Fields, string>(); string nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Sku, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Name).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { var name = Convert.ToString(csv[FieldMapping[nameField]]); if (!string.IsNullOrEmpty(name)) { productInStrings.Add(ProductFields.Fields.Name, name); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_CanNotEmpty, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Name), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Enabled).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { string enabled = Convert.ToString(csv[FieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.Enabled, enabled); //product.Enabled = !string.IsNullOrEmpty(enabled) && enabled.Trim().Equals("+"); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Discount); if (FieldMapping.ContainsKey(nameField)) { var discount = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(discount)) { discount = "0"; } decimal tmp; if (decimal.TryParse(discount, out tmp)) { productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString()); } else if (decimal.TryParse(discount, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Discount), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Weight); if (FieldMapping.ContainsKey(nameField)) { var weight = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(weight)) { weight = "0"; } decimal tmp; if (decimal.TryParse(weight, out tmp)) { productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString()); } else if (decimal.TryParse(weight, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Weight), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Size); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Size, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.BriefDescription); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.BriefDescription, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Description); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Description, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Price).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { var price = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(price)) { price = "0"; } decimal tmp; if (decimal.TryParse(price, out tmp)) { productInStrings.Add(ProductFields.Fields.Price, tmp.ToString()); } else if (decimal.TryParse(price, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Price, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Price), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.PurchasePrice); if (FieldMapping.ContainsKey(nameField)) { var sypplyprice = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(sypplyprice)) { sypplyprice = "0"; } decimal tmp; if (decimal.TryParse(sypplyprice, out tmp)) { productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString()); } else if (decimal.TryParse(sypplyprice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.PurchasePrice), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ShippingPrice); if (FieldMapping.ContainsKey(nameField)) { var shippingPrice = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(shippingPrice)) { shippingPrice = "0"; } decimal tmp; if (decimal.TryParse(shippingPrice, out tmp)) { productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString()); } else if (decimal.TryParse(shippingPrice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ShippingPrice), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Amount); if (FieldMapping.ContainsKey(nameField)) { var amount = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(amount)) { amount = "0"; } int tmp; if (int.TryParse(amount, out tmp)) { productInStrings.Add(ProductFields.Fields.Amount, amount); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Amount), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Unit); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Unit, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ParamSynonym); if (FieldMapping.ContainsKey(nameField)) { string rewurl = Convert.ToString(csv[FieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.ParamSynonym, rewurl); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Title); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Title, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaKeywords); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.MetaKeywords, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaDescription); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.MetaDescription, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Photos); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Photos, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Markers); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Markers, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Properties); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Properties, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Producer); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Producer, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.OrderByRequest); if (FieldMapping.ContainsKey(nameField)) { string orderbyrequest = Convert.ToString(csv[FieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.OrderByRequest, orderbyrequest); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Category).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { var parentCategory = Convert.ToString(csv[FieldMapping[nameField]]); if (!string.IsNullOrEmpty(parentCategory)) { productInStrings.Add(ProductFields.Fields.Category, parentCategory); } } ImportProduct.UpdateInsertProduct(productInStrings, false); } catch (Exception ex) { LogInvalidData("Ex " + ex.Message + DateTime.Now.ToString()); } } //All amounts to zero. except that was updated 0.02 = 30 minutes before and SubBrandID != -2 (tools.by) string script = "UPDATE Catalog.Offer SET Amount = 0 FROM Catalog.Product INNER JOIN Catalog.Offer ON Catalog.Product.ProductId = Catalog.Offer.ProductID WHERE (Catalog.Product.DateModified < GETDATE() - 0.02) AND Amount < 9000 "; ExecuteScript(script); LogInvalidData("Amounts of products that was not updated to zero" + DateTime.Now.ToString()); LogInvalidData(" CategoryService.RecalculateProductsCountManual() before " + DateTime.Now.ToString()); CategoryService.RecalculateProductsCountManual(); LogInvalidData(" CategoryService.RecalculateProductsCountManual() after " + DateTime.Now.ToString()); } try { LogInvalidData(" LuceneSearch.CreateAllIndexInBackground(); " + DateTime.Now.ToString()); LuceneSearch.CreateAllIndexInBackground(); CacheManager.Clean(); LogInvalidData(" File.Cop file:" + _fullPath + DateTime.Now.ToString()); // File.Copy(_fullPath, _fullPath.Replace("ostatki.csv", "ostatki_done_" + DateTime.Now.ToString("M-d-yyyy-HH-mm") + ".csv")); FileHelpers.DeleteFile(_fullPath.Replace("ostatki.csv", "Instrument_opt_by__ostatki.csv")); File.Copy(_fullPath, _fullPath.Replace("ostatki.csv", "Instrument_opt_by__ostatki.csv")); FileHelpers.DeleteFile(_fullPath); //UPdate Sorting LogInvalidData(" //UPdate Sorting " + DateTime.Now.ToString()); AdvantShop.Core.SQLDataAccess.ExecuteNonQuery("[Catalog].[sp_UpdateSortingInCategories]", CommandType.StoredProcedure); LogInvalidData(" All Done: " + DateTime.Now.ToString()); } catch (Exception ex) { LogInvalidData("Ex 2 " + ex.Message + DateTime.Now.ToString()); } }
private void ProcessCsv() { if (chboxDisableProducts.Checked) { ProductService.DisableAllProducts(); } long count = 0; using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding()))) { csv.Configuration.Delimiter = Separators.GetCharSeparator(); csv.Configuration.HasHeaderRecord = _hasHeadrs; while (csv.Read()) { count++; } } ImportStatistic.TotalRow = count; using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding()))) { csv.Configuration.Delimiter = Separators.GetCharSeparator(); csv.Configuration.HasHeaderRecord = _hasHeadrs; while (csv.Read()) { if (!ImportStatistic.IsRun) { csv.Dispose(); FileHelpers.DeleteFile(_fullPath); return; } try { //Added by Evgeni to Remove dots // csv.CurrentRecord[0] = csv.CurrentRecord[0].Replace(".", "").Replace(" ", ""); // Step by rows var productInStrings = new Dictionary <ProductFields.Fields, string>(); string nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Sku, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Name).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { var name = Convert.ToString(csv[FieldMapping[nameField]]); if (!string.IsNullOrEmpty(name)) { productInStrings.Add(ProductFields.Fields.Name, name); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_CanNotEmpty, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Name), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Enabled).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { string enabled = Convert.ToString(csv[FieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.Enabled, enabled); //product.Enabled = !string.IsNullOrEmpty(enabled) && enabled.Trim().Equals("+"); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Discount); if (FieldMapping.ContainsKey(nameField)) { var discount = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(discount)) { discount = "0"; } decimal tmp; if (decimal.TryParse(discount, out tmp)) { productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString()); } else if (decimal.TryParse(discount, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Discount), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Weight); if (FieldMapping.ContainsKey(nameField)) { var weight = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(weight)) { weight = "0"; } decimal tmp; if (decimal.TryParse(weight, out tmp)) { productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString()); } else if (decimal.TryParse(weight, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Weight), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Size); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Size, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.BriefDescription); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.BriefDescription, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Description); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Description, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Price).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { var price = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(price)) { price = "0"; } decimal tmp; if (decimal.TryParse(price, out tmp)) { productInStrings.Add(ProductFields.Fields.Price, tmp.ToString()); } else if (decimal.TryParse(price, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Price, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Price), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.PurchasePrice); if (FieldMapping.ContainsKey(nameField)) { var sypplyprice = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(sypplyprice)) { sypplyprice = "0"; } decimal tmp; if (decimal.TryParse(sypplyprice, out tmp)) { productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString()); } else if (decimal.TryParse(sypplyprice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.PurchasePrice), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ShippingPrice); if (FieldMapping.ContainsKey(nameField)) { var shippingPrice = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(shippingPrice)) { shippingPrice = "0"; } decimal tmp; if (decimal.TryParse(shippingPrice, out tmp)) { productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString()); } else if (decimal.TryParse(shippingPrice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString()); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ShippingPrice), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Amount); if (FieldMapping.ContainsKey(nameField)) { var amount = Convert.ToString(csv[FieldMapping[nameField]]); if (string.IsNullOrEmpty(amount)) { amount = "0"; } int tmp; if (int.TryParse(amount, out tmp)) { productInStrings.Add(ProductFields.Fields.Amount, amount); } else { LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Amount), ImportStatistic.RowPosition + 2)); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Unit); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Unit, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ParamSynonym); if (FieldMapping.ContainsKey(nameField)) { string rewurl = Convert.ToString(csv[FieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.ParamSynonym, rewurl); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Title); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Title, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaKeywords); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.MetaKeywords, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaDescription); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.MetaDescription, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Photos); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Photos, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Markers); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Markers, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Properties); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Properties, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Producer); if (FieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Producer, Convert.ToString(csv[FieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.OrderByRequest); if (FieldMapping.ContainsKey(nameField)) { string orderbyrequest = Convert.ToString(csv[FieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.OrderByRequest, orderbyrequest); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Category).Trim('*'); if (FieldMapping.ContainsKey(nameField)) { var parentCategory = Convert.ToString(csv[FieldMapping[nameField]]); if (!string.IsNullOrEmpty(parentCategory)) { productInStrings.Add(ProductFields.Fields.Category, parentCategory); } } ImportProduct.UpdateInsertProduct(productInStrings); } catch (Exception ex) { MsgErr(ex.Message + " at csv"); Debug.LogError(ex); } } CategoryService.RecalculateProductsCountManual(); } ImportStatistic.IsRun = false; LuceneSearch.CreateAllIndexInBackground(); CacheManager.Clean(); FileHelpers.DeleteFilesFromImageTempInBackground(); FileHelpers.DeleteFile(_fullPath); }
protected void Page_Load(object sender, EventArgs e) { if ((SaasDataService.IsSaasEnabled) && (!SaasDataService.CurrentSaasData.HaveExcel)) { mainDiv.Visible = false; notInTariff.Visible = true; } Page.Title = string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Admin_ImportXLS_Title); if (!IsPostBack) { if (divStart.Visible) { ddlEncoding.Items.Clear(); ddlEncoding.Items.Add(new ListItem { Text = Encodings.EncodingsEnum.Windows1251.ToString(), Value = ((int)Encodings.EncodingsEnum.Windows1251).ToString(), Selected = true }); ddlEncoding.Items.Add(new ListItem { Text = Encodings.EncodingsEnum.Utf8.ToString(), Value = ((int)Encodings.EncodingsEnum.Utf8).ToString() }); ddlEncoding.Items.Add(new ListItem { Text = Encodings.EncodingsEnum.Utf16.ToString(), Value = ((int)Encodings.EncodingsEnum.Utf16).ToString() }); ddlEncoding.Items.Add(new ListItem { Text = Encodings.EncodingsEnum.Koi8R.ToString(), Value = ((int)Encodings.EncodingsEnum.Koi8R).ToString() }); ddlEncoding.SelectedValue = ((int)Encodings.CsvEnconing).ToString(); ddlSeparetors.Items.Clear(); ddlSeparetors.Items.Add(new ListItem { Text = Resource.Admin_ImportCsv_Semicolon, Value = ((int)Separators.SeparatorsEnum.SemicolonSeparated).ToString(), Selected = true }); ddlSeparetors.Items.Add(new ListItem { Text = Resource.Admin_ImportCsv_Comma, Value = ((int)Separators.SeparatorsEnum.CommaSeparated).ToString() }); ddlSeparetors.Items.Add(new ListItem { Text = Resource.Admin_ImportCsv_Tab, Value = ((int)Separators.SeparatorsEnum.TabSeparated).ToString() }); ddlSeparetors.SelectedValue = ((int)Separators.CsvSeparator).ToString(); } } if (choseDiv.FindControl("tblValues") != null && IsPostBack) { short index = 0; var cells = ((TableRow)choseDiv.FindControl("ddlRow")).Cells; foreach (TableCell item in cells) { var element = item.Controls.OfType <DropDownList>().FirstOrDefault(); if (element == null) { continue; } if (element.SelectedValue != ProductFields.GetStringNameByEnum(ProductFields.Fields.None)) { if (!FieldMapping.ContainsKey(element.SelectedValue)) { FieldMapping.Add(element.SelectedValue, index); } else { MsgErr(string.Format(Resource.Admin_ImportCsv_DuplicateMessage, element.SelectedItem.Text));// "Duplicate field"); return; } } index++; } } if (btnAction.Visible && IsPostBack) { foreach (var item in _mustRequiredFfield) { if (!FieldMapping.ContainsKey(ProductFields.GetStringNameByEnum(item).Trim('*'))) { MsgErr(string.Format(Resource.Admin_ImportCsv_NotChoice, ProductFields.GetDisplayNameByEnum(item))); return; } } } //MsgErr(true); }
protected void Page_Init(object sender, EventArgs e) { MsgErr(true); divStart.Visible = !ImportStatistic.IsRun && (string.IsNullOrEmpty(Request["action"])); divAction.Visible = !ImportStatistic.IsRun && (Request["action"] == "start"); choseDiv.Visible = !ImportStatistic.IsRun; OutDiv.Visible = ImportStatistic.IsRun; linkCancel.Visible = ImportStatistic.IsRun; if (ImportStatistic.IsRun || (Request["action"] != "start")) { return; } if (!File.Exists(_fullPath)) { return; } var tbl = new Table() { ID = "tblValues" }; var namesRow = new TableRow { ID = "namesRow", BackColor = System.Drawing.ColorTranslator.FromHtml("#0D76B8") }; var firstValRow = new TableRow { ID = "firstValsRow" }; var ddlRow = new TableRow { ID = "ddlRow" }; var firstCell = new TableCell { Width = 200, BackColor = System.Drawing.Color.White, }; firstCell.Controls.Add(new Label { Text = Resources.Resource.Admin_ImportCsv_Column, CssClass = "firstColumn" }); var div1 = new Panel { CssClass = "arrow_left_bg" }; div1.Controls.Add(new Panel { CssClass = "arrow_right_bg" }); firstCell.Controls.Add(div1); var secondCell = new TableCell { Width = 200 }; secondCell.Controls.Add(new Label { Text = Resources.Resource.Admin_ImportCsv_FistLineInTheFile, CssClass = "firstColumn" }); var div2 = new Panel { CssClass = "arrow_left_bg_two" }; div2.Controls.Add(new Panel { CssClass = "arrow_right_bg" }); secondCell.Controls.Add(div2); var firdCell = new TableCell { Width = 200 }; firdCell.Controls.Add(new Label { Text = Resources.Resource.Admin_ImportCsv_DataType, CssClass = "firstColumn" }); var div3 = new Panel { CssClass = "arrow_left_bg_free" }; div3.Controls.Add(new Panel { CssClass = "arrow_right_bg" }); firdCell.Controls.Add(div3); var div4 = new Panel { Width = 200 }; firdCell.Controls.Add(div4); namesRow.Cells.Add(firstCell); firstValRow.Cells.Add(secondCell); ddlRow.Cells.Add(firdCell); _hasHeadrs = chbHasHeadrs.Checked; using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding()))) { csv.Configuration.Delimiter = Separators.GetCharSeparator(); csv.Configuration.BufferSize = 0x1000; csv.Configuration.HasHeaderRecord = false; csv.Read(); if (_hasHeadrs && csv.CurrentRecord.HasDuplicates()) { var strFileds = string.Empty; foreach (var item in csv.CurrentRecord.Duplicates()) { strFileds += "\"" + item + "\","; } MsgErr(Resource.Admin_ImportCsv_DuplicateHeader + strFileds.Trim(',')); btnAction.Visible = false; } for (int i = 0; i < csv.CurrentRecord.Length; i++) { //Added by Evgeni to Import csv with dotes // csv.CurrentRecord[0] = csv.CurrentRecord[0].Replace(".", "").Replace(" ", ""); var cell = new TableCell { ID = "cell" + i.ToString() }; var lb = new Label(); bool flagMustReqField = false; if (Request["hasheadrs"].ToLower() == "true") { var tempCsv = (csv[i].Length > 50 ? csv[i].Substring(0, 49) : csv[i]).Replace("*", ""); if (_mustRequiredFfield.Any(item => ProductFields.GetStringNameByEnum(item).Replace("*", "") == tempCsv.ToLower())) { flagMustReqField = true; } lb.Text = tempCsv; } else { lb.Text = Resource.Admin_ImportCsv_Empty; } lb.ForeColor = System.Drawing.Color.White; cell.Controls.Add(lb); if (flagMustReqField) { var lbl = new Label { Text = @"*", ForeColor = System.Drawing.Color.Red }; cell.Controls.Add(lbl); } namesRow.Cells.Add(cell); cell = new TableCell() { Width = 150 }; var ddl = new DropDownList { ID = "ddlType" + i.ToString(), Width = 150 }; ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.None), ProductFields.GetStringNameByEnum(ProductFields.Fields.None))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Sku), ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Name), ProductFields.GetStringNameByEnum(ProductFields.Fields.Name).Trim('*'))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ParamSynonym), ProductFields.GetStringNameByEnum(ProductFields.Fields.ParamSynonym))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Category), ProductFields.GetStringNameByEnum(ProductFields.Fields.Category).Trim('*'))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Enabled), ProductFields.GetStringNameByEnum(ProductFields.Fields.Enabled).Trim('*'))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Price), ProductFields.GetStringNameByEnum(ProductFields.Fields.Price).Trim('*'))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.PurchasePrice), ProductFields.GetStringNameByEnum(ProductFields.Fields.PurchasePrice))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Amount), ProductFields.GetStringNameByEnum(ProductFields.Fields.Amount))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Unit), ProductFields.GetStringNameByEnum(ProductFields.Fields.Unit))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Discount), ProductFields.GetStringNameByEnum(ProductFields.Fields.Discount))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ShippingPrice), ProductFields.GetStringNameByEnum(ProductFields.Fields.ShippingPrice))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Weight), ProductFields.GetStringNameByEnum(ProductFields.Fields.Weight))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Size), ProductFields.GetStringNameByEnum(ProductFields.Fields.Size))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.BriefDescription), ProductFields.GetStringNameByEnum(ProductFields.Fields.BriefDescription))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Description), ProductFields.GetStringNameByEnum(ProductFields.Fields.Description))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Title), ProductFields.GetStringNameByEnum(ProductFields.Fields.Title))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.MetaKeywords), ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaKeywords))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.MetaDescription), ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaDescription))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Photos), ProductFields.GetStringNameByEnum(ProductFields.Fields.Photos))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Markers), ProductFields.GetStringNameByEnum(ProductFields.Fields.Markers))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Properties), ProductFields.GetStringNameByEnum(ProductFields.Fields.Properties))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Producer), ProductFields.GetStringNameByEnum(ProductFields.Fields.Producer))); ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.OrderByRequest), ProductFields.GetStringNameByEnum(ProductFields.Fields.OrderByRequest))); ddl.SelectedValue = lb.Text.Replace("*", "").Trim().ToLower(); cell.Controls.Add(ddl); ddlRow.Cells.Add(cell); } csv.Read(); if (csv.CurrentRecord != null) { for (int i = 0; i < csv.CurrentRecord.Length; i++) { //Added by Evgeni to remove dots //csv.CurrentRecord[0] = csv.CurrentRecord[0].Replace(".", "").Replace(" ", ""); var cell = new TableCell(); if (csv[i] == null) { cell.Controls.Add(new Label { Text = string.Empty }); } else { cell.Controls.Add(new Label { Text = csv[i].Length > 50 ? csv[i].Substring(0, 49).HtmlEncode() : csv[i].HtmlEncode() }); } firstValRow.Cells.Add(cell); } } } tbl.Rows.Add(namesRow); tbl.Rows.Add(firstValRow); tbl.Rows.Add(ddlRow); choseDiv.Controls.Add(tbl); }
private void ProcessCsv(string fullPath) { ImportStatistic.Init(); ImportStatistic.IsRun = true; var fieldMapping = new Dictionary <string, int>(); using (var csv = new CsvHelper.CsvReader(new StreamReader(fullPath, Encoding.UTF8))) { csv.Configuration.Delimiter = ';'; csv.Configuration.HasHeaderRecord = false; csv.Read(); for (int i = 0; i < csv.CurrentRecord.Length; i++) { if (csv.CurrentRecord[i] == ProductFields.GetStringNameByEnum(ProductFields.Fields.None)) { continue; } if (!fieldMapping.ContainsKey(csv.CurrentRecord[i])) { fieldMapping.Add(csv.CurrentRecord[i], i); } } } using (var csv = new CsvHelper.CsvReader(new StreamReader(fullPath, Encoding.UTF8))) { csv.Configuration.Delimiter = ';'; csv.Configuration.HasHeaderRecord = true; while (csv.Read()) { if (!ImportStatistic.IsRun) { csv.Dispose(); FileHelpers.DeleteFile(fullPath); return; } ImportStatistic.RowPosition++; try { // Step by rows var productInStrings = new Dictionary <ProductFields.Fields, string>(); string nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Sku, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Name).Trim('*'); if (fieldMapping.ContainsKey(nameField)) { var name = Convert.ToString(csv[fieldMapping[nameField]]); if (!string.IsNullOrEmpty(name)) { productInStrings.Add(ProductFields.Fields.Name, name); } else { Log(string.Format(Resource.Admin_ImportCsv_CanNotEmpty, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Name), ImportStatistic.RowPosition + 2), "InvalidData"); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Enabled).Trim('*'); if (fieldMapping.ContainsKey(nameField)) { string enabled = Convert.ToString(csv[fieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.Enabled, enabled); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Discount); if (fieldMapping.ContainsKey(nameField)) { string discount = Convert.ToString(csv[fieldMapping[nameField]]); if (string.IsNullOrEmpty(discount)) { discount = "0"; } decimal tmp; if (decimal.TryParse(discount, out tmp)) { productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString()); } else if (decimal.TryParse(discount, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString()); } else { Log(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Discount), ImportStatistic.RowPosition + 2), "InvalidData"); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Weight); if (fieldMapping.ContainsKey(nameField)) { string weight = Convert.ToString(csv[fieldMapping[nameField]]); if (string.IsNullOrEmpty(weight)) { weight = "0"; } decimal tmp; if (decimal.TryParse(weight, out tmp)) { productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString()); } else if (decimal.TryParse(weight, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString()); } else { Log(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Weight), ImportStatistic.RowPosition + 2), "InvalidData"); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Size); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Size, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.BriefDescription); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.BriefDescription, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Description); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Description, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Price).Trim('*'); if (fieldMapping.ContainsKey(nameField)) { string price = Convert.ToString(csv[fieldMapping[nameField]]); if (string.IsNullOrEmpty(price)) { price = "0"; } decimal tmp; if (decimal.TryParse(price, out tmp)) { productInStrings.Add(ProductFields.Fields.Price, tmp.ToString()); } else if (decimal.TryParse(price, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.Price, tmp.ToString()); } else { Log(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Price), ImportStatistic.RowPosition + 2), "InvalidData"); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.PurchasePrice); if (fieldMapping.ContainsKey(nameField)) { string sypplyprice = Convert.ToString(csv[fieldMapping[nameField]]); if (string.IsNullOrEmpty(sypplyprice)) { sypplyprice = "0"; } decimal tmp; if (decimal.TryParse(sypplyprice, out tmp)) { productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString()); } else if (decimal.TryParse(sypplyprice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString()); } else { Log(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.PurchasePrice), ImportStatistic.RowPosition + 2), "InvalidData"); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ShippingPrice); if (fieldMapping.ContainsKey(nameField)) { string shippingPrice = Convert.ToString(csv[fieldMapping[nameField]]); if (string.IsNullOrEmpty(shippingPrice)) { shippingPrice = "0"; } decimal tmp; if (decimal.TryParse(shippingPrice, out tmp)) { productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString()); } else if (decimal.TryParse(shippingPrice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) { productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString()); } else { Log(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ShippingPrice), ImportStatistic.RowPosition + 2), "InvalidData"); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Amount); if (fieldMapping.ContainsKey(nameField)) { string amount = Convert.ToString(csv[fieldMapping[nameField]]); if (string.IsNullOrEmpty(amount)) { amount = "0"; } int tmp; if (int.TryParse(amount, out tmp)) { productInStrings.Add(ProductFields.Fields.Amount, amount); } else { Log(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Amount), ImportStatistic.RowPosition + 2), "InvalidData"); continue; } } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Unit); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Unit, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ParamSynonym); if (fieldMapping.ContainsKey(nameField)) { string rewurl = Convert.ToString(csv[fieldMapping[nameField]]); productInStrings.Add(ProductFields.Fields.ParamSynonym, rewurl); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Title); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Title, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaKeywords); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.MetaKeywords, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaDescription); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.MetaDescription, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Photos); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Photos, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Markers); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Markers, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Properties); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Properties, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Producer); if (fieldMapping.ContainsKey(nameField)) { productInStrings.Add(ProductFields.Fields.Producer, Convert.ToString(csv[fieldMapping[nameField]])); } nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Category).Trim('*'); if (fieldMapping.ContainsKey(nameField)) { var parentCategory = Convert.ToString(csv[fieldMapping[nameField]]); if (!string.IsNullOrEmpty(parentCategory)) { productInStrings.Add(ProductFields.Fields.Category, parentCategory); } } ImportProduct.UpdateInsertProduct(productInStrings); } catch (Exception ex) { Log(ex.Message, "InvalidData"); } } CategoryService.RecalculateProductsCountManual(); } ImportStatistic.IsRun = false; FileHelpers.DeleteFile(fullPath); }