Exemplo n.º 1
0
    protected void btnAction_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(lblError.Text))
        {
            return;
        }

        divAction.Visible = false;
        choseDiv.Visible  = false;
        if (File.Exists(_fullPath))
        {
            try
            {
                if (!ImportStatistic.IsRun)
                {
                    _hasHeadrs = Request["hasheadrs"] == "true";
                    ImportStatistic.Init();
                    ImportStatistic.IsRun = true;
                    linkCancel.Visible    = true;
                    MsgErr(true);
                    lblRes.Text = string.Empty;
                    var tr = new Thread(ProcessCsv);
                    ImportStatistic.ThreadImport = tr;
                    tr.Start();
                    OutDiv.Visible = true;
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
        }
    }
Exemplo n.º 2
0
    //public static void SubParseAndCreateCategory(string strCategory, string artNo)
    //{
    //    //
    //    // strCategory "[Техника >> Игровые приставки >> PlayStation 3];[....]"
    //    //
    //    foreach (string strT in strCategory.Split(new[] { ';' }))
    //    {
    //        var st = strT;
    //        st = st.Replace("[", "");
    //        st = st.Replace("]", "");
    //        int parentId = 0;
    //        string[] temp = st.Split(new[] { ">>" }, StringSplitOptions.RemoveEmptyEntries);

    //        for (int i = 0; i <= temp.Length - 1; i++)
    //        {
    //            string str = temp[i].Trim();
    //            if (!string.IsNullOrEmpty(str))
    //            {
    //                var cat = CategoryService.GetChildCategoryIDByName(parentId, str);
    //                if (cat != 0)
    //                    parentId = cat;
    //                else
    //                {
    //                    parentId = CategoryService.AddCategory(new Category
    //                    {
    //                        Name = str,
    //                        ParentCategoryId = parentId,
    //                        Picture = string.Empty,
    //                        SortOrder = 0,
    //                        Enabled = true
    //                    }, false);
    //                }
    //            }
    //            if (i == temp.Length - 1)
    //            {
    //                var tempProductId = ProductService.GetProductIdByArtNo(artNo);
    //                if (tempProductId != -1)
    //                    ProductService.AddProductLink(tempProductId, parentId);
    //            }
    //        }
    //    }
    //}

    protected void linkCancel_Click(object sender, EventArgs e)
    {
        if (ImportStatistic.ThreadImport.IsAlive)
        {
            //ImportStatistic.ThreadImport.Abort();
            ImportStatistic.IsRun = false;
            ImportStatistic.Init();
            hlDownloadImportLog.Attributes.CssStyle["display"] = "inline";
        }
    }
Exemplo n.º 3
0
    protected void btnLoad_Click(object sender, EventArgs e)
    {
        try
        {
            if (!FileUpload1.HasFile)
            {
                MsgErr(Resource.Admin_ImportXLS_ChooseFile);
                return;
            }

            if (!ImportStatistic.IsRun)
            {
                ImportStatistic.Init();
                ImportStatistic.IsRun = true;
                linkCancel.Visible    = true;
                MsgErr(true);
                lblRes.Text = string.Empty;

                bool boolSuccess = true;

                // Files

                try
                {
                    FileHelpers.CreateDirectory(_filePath);
                    FileHelpers.DeleteFile(_fullPath);
                }
                catch (Exception ex)
                {
                    MsgErr(ex.Message + " at Files");
                    boolSuccess = false;
                }

                if (!boolSuccess)
                {
                    return;
                }
                pUploadExcel.Visible = false;
                // Save file

                FileUpload1.SaveAs(_fullPath);
                var tr = new Thread(ProcessExcel);
                ImportStatistic.ThreadImport = tr;
                tr.Start();

                pUploadExcel.Visible = false;

                OutDiv.Visible = true;
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }
Exemplo n.º 4
0
        public async Task <IActionResult> Check()
        {
            DateTime startDate = new DateTime(2021, 1, 1);
            DateTime endDate   = new DateTime(2021, 6, DateTime.DaysInMonth(2021, 6));

            DateTime        iterator         = startDate;
            List <DateTime> monthsToConsider = new List <DateTime>();

            while (true)
            {
                if (iterator > endDate)
                {
                    break;
                }
                monthsToConsider.Add(iterator);
                iterator = iterator.AddMonths(1);
            }

            List <MonthYear_SumSaleImportRevenue> stats = new List <MonthYear_SumSaleImportRevenue>();

            foreach (DateTime month in monthsToConsider)
            {
                double sumSale    = new SaleStatistic(_iProductRepository, _cartRepository, _shoppingCartRepository).GetTotalSaleValueCertainMonth(month.Month, month.Year);
                double sumImport  = new ImportStatistic(_iProductRepository, _importRepository, _importDetailRepository).GetTotalImportValueCertainMonth(month.Month, month.Year);
                double difference = sumSale - sumImport;
                stats.Add(new MonthYear_SumSaleImportRevenue()
                {
                    Month        = month.Month,
                    Year         = month.Year,
                    TotalSale    = sumSale,
                    TotalImport  = sumImport,
                    TotalRevenue = difference,
                });
            }

            return(Json(stats));
        }
 private static void LogInvalidData(string message)
 {
     ImportStatistic.WriteLog(message);
     ImportStatistic.TotalErrorRow++;
     ImportStatistic.RowPosition++;
 }
Exemplo n.º 6
0
        //Added by Evgeni
        public static void SaveProductsToCsvAutospace(string path, Encodings.EncodingsEnum encodeType, Separators.SeparatorsEnum delimetr)
        {
            ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace. DateTime: " + DateTime.Now);

            using (var writer = new CsvHelper.CsvWriter(new StreamWriter(path, false, Encodings.GetEncoding(encodeType))))
            {
                ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace 2.Encoding: " + Encodings.GetEncoding(encodeType) + " DateTime: " + DateTime.Now);

                writer.Configuration.Delimiter = Separators.GetCharSeparator(delimetr);

                //var items = new List<Product>();

                //using (var db = new SQLDataAccess())
                //{
                //    db.cnOpen();
                //    items = (List<Product>)ProductService.GetProductsWhere(db, "ArtNo like '2.607.001.733'");
                //    db.cnClose();
                //}
                var items = ProductService.GetProducts();// .Where(t => t.ArtNo.Contains("2.607.001.733")).ToList();

                List <string> loadedProducts = new List <string>();

                ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace 3. DateTime: " + DateTime.Now + "Number of products to proceed: " + items.Count);
                //select only relevants offers
                //  items = items.Where(t => t.Brand.Name.ToLower() == "bosch" || t.Brand.Name.ToLower() == "skil").Where(t => t.Offers.FirstOrDefault().Amount > 0 && t.Offers.FirstOrDefault().Price > 0).ToList();

                if (items == null)
                {
                    return;
                }
                var    regex = new Regex("^[0-9]+$");
                string pcs   = "шт.";
                for (int j = 0; j < items.Count; j++)
                {
                    try
                    {
                        if (j % 1000 == 0)
                        {
                            ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace 4. DateTime: " + DateTime.Now
                                                     + " File No " + j);
                        }

                        //check that product was not inserted yet
                        if (loadedProducts.Where(t => t.Contains(items[j].ArtNo)).ToList().Count > 0)
                        {
                            continue;
                        }
                        else
                        {
                            loadedProducts.Add(items[j].ArtNo);
                        }

                        var product = items[j];
                        var offer   = product.Offers.Where(t => t.OfferListId == 15).FirstOrDefault() ?? new Offer {
                            Amount = 0, Price = 0, SupplyPrice = 0, Unit = "", ShippingPrice = 0
                        };                                                                                                                                                                //get only spec price
                        if (offer.OfferListId != 15 || offer.Amount <= 0 || offer.Price <= 0)
                        {
                            continue;
                        }

                        if (product.Brand == null)
                        {
                            if (product.ArtNo.ToLower().StartsWith("f"))
                            {
                                writer.WriteField("Skil");
                            }
                            else
                            {
                                writer.WriteField("Bosch");
                            }
                        }
                        else
                        {
                            writer.WriteField(product.Brand.Name);
                        }

                        writer.WriteField(product.ArtNo);
                        writer.WriteField(product.BriefDescription.Replace(";", "").Replace("&nbsp;", " ").Replace(",", "").Replace("<p>", "").Replace("<p/>", ""));

                        if (product.ProductCategories.Count == 0)
                        {
                            writer.WriteField("Прочее");
                        }
                        else
                        {
                            writer.WriteField(product.ProductCategories.FirstOrDefault().Name.Replace(";", "").Replace("&nbsp;", "").Replace(",", ""));
                        }

                        writer.WriteField(offer.Amount);
                        writer.WriteField(offer.Price.ToString("F2"));
                        writer.WriteField(pcs);
                        writer.WriteField("1");

                        writer.NextRecord();
                    }
                    catch (Exception ex)
                    {
                        ImportStatistic.WriteLog("Error while adding product:" + ex.Message);
                    }
                }

                ImportStatistic.WriteLog("End working on SaveProductsToCsvAutospace 5. DateTime: " + DateTime.Now);
            }
            ImportStatistic.WriteLog("End working on SaveProductsToCsvAutospace 6. DateTime: " + DateTime.Now);
        }
Exemplo n.º 7
0
    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);
    }
Exemplo n.º 8
0
 private static void Log(string message)
 {
     ImportStatistic.WriteLog(message);
 }