Esempio n. 1
0
 public void ProcessReport()
 {
     _dtStart = DateTime.Now;
     With.DeadlockWraper(() => {
         DataAdapter = new MySqlDataAdapter("", Connection);
         _dsReport.Clear();
         GenerateReport();
     });
 }
        public virtual void DeleteAssortment(uint assortmentId)
        {
            With.DeadlockWraper(() =>
                                Transaction(session => {
                var productAssortment = session.Load <Assortment>(assortmentId);
                session.Delete(productAssortment);

                var assortment = session.Load <Assortment>(assortmentId);
                session.CreateSQLQuery(@"
delete from farm.Core0
where CodeFirmCr = :ProducerId and ProductId in (
	select id from catalogs.Products where CatalogId = :CatalogId)"    )
                .SetParameter("CatalogId", assortment.CatalogProduct.Id)
                .SetParameter("ProducerId", assortment.Producer.Id)
                .ExecuteUpdate();
            }));
        }
        protected void LogDownloadedPrice(ulong sourceTypeId, string archFileName, string extrFileName)
        {
            With.DeadlockWraper((c, t) => {
                var downloadLogId = DownloadLogEntity.Log(sourceTypeId, (uint)CurrPriceItemId,
                                                          null, null,
                                                          DownPriceResultCode.SuccessDownload, archFileName,
                                                          (String.IsNullOrEmpty(extrFileName)) ? null : Path.GetFileName(extrFileName), c);

                var downloadedFileName = Path.Combine(Settings.Default.InboundPath, "d" + CurrPriceItemId + "_" + downloadLogId + GetExt());
                var item = CreatePriceProcessItem(downloadedFileName);
                item.CopyToInbound(extrFileName, c, t);
                CopyToHistory(downloadLogId);
            });

            using (NDC.Push(CurrPriceItemId.ToString()))
                _logger.InfoFormat("Price {0} - {1} скачан/распакован",
                                   drCurrent[SourcesTableColumns.colShortName],
                                   drCurrent[SourcesTableColumns.colPriceName]);
        }
        public List <uint> Query()
        {
            var parametrs = new List <MySqlParameter> {
                new MySqlParameter("?SupplierId", supplierId),
                new MySqlParameter("?SupplierDeliveryId", SupplierDeliveryId)
            };

            if (includeClientId)
            {
                parametrs.Add(new MySqlParameter("?SupplierClientId", SupplierClientId));
            }

            var sql = SqlGetClientAddressId(includeClientId, true);
            var ds  = With.DeadlockWraper(() => With.Connection(c => MySqlHelper.ExecuteDataset(
                                                                    c,
                                                                    sql,
                                                                    parametrs.ToArray())));

            return(ds.Tables[0].AsEnumerable().Select(r => Convert.ToUInt32(r["AddressId"])).ToList());
        }
Esempio n. 5
0
        public void ApplyChanges(MySqlConnection masterConnection, IProgressNotifier formProgress, List <DataRow> rows)
        {
            operatorName = Environment.UserName.ToLower();
            CalculateChanges(masterConnection, formProgress, rows);

            var updateSynonymProducerEtalonSQL = daSynonymFirmCr.UpdateCommand.CommandText;
            var insertSynonymProducerEtalonSQL = daSynonymFirmCr.InsertCommand.CommandText;

            var changes = dtSynonymFirmCr.GetChanges(DataRowState.Modified);

            if (changes != null)
            {
                stat.SynonymFirmCrCount += changes.Rows.Count;
            }

            formProgress.Status = "Применение изменений в базу данных...";
            DataRow lastUpdateSynonym = null;

            try {
                With.DeadlockWraper(c => {
                    var humanName = GetHumanName(c, operatorName);

                    var helper        = new Common.MySql.MySqlHelper(c, null);
                    var commandHelper = helper.Command("set @inHost = ?Host; set @inUser = ?UserName;");
                    commandHelper.AddParameter("?Host", Environment.MachineName);
                    commandHelper.AddParameter("?UserName", operatorName);
                    commandHelper.Execute();

                    //Заполнили таблицу логов для синонимов наименований
                    daSynonym.SelectCommand.Connection = c;
                    daSynonym.Update(dtSynonym);

                    formProgress.ApplyProgress += 10;

                    var insertExclude = new MySqlCommand(@"
insert into Farm.Excludes(CatalogId, PriceCode, ProducerSynonym, DoNotShow, Operator, OriginalSynonymId)
value (?CatalogId, ?PriceCode, ?ProducerSynonym, ?DoNotShow, ?Operator, ?OriginalSynonymId);", c);
                    insertExclude.Parameters.AddWithValue("?PriceCode", priceId);
                    insertExclude.Parameters.AddWithValue("?Operator", humanName);
                    insertExclude.Parameters.Add("?ProducerSynonym", MySqlDbType.VarChar);
                    insertExclude.Parameters.Add("?DoNotShow", MySqlDbType.Byte);
                    insertExclude.Parameters.Add("?CatalogId", MySqlDbType.UInt32);
                    insertExclude.Parameters.Add("?OriginalSynonymId", MySqlDbType.UInt32);

                    foreach (var exclude in excludes.Where(e => e.Id == 0))
                    {
                        if (!IsExcludeCorrect(c, exclude))
                        {
                            continue;
                        }
                        insertExclude.Parameters["?ProducerSynonym"].Value   = exclude.ProducerSynonym;
                        insertExclude.Parameters["?DoNotShow"].Value         = exclude.DoNotShow;
                        insertExclude.Parameters["?CatalogId"].Value         = exclude.CatalogId;
                        insertExclude.Parameters["?OriginalSynonymId"].Value = exclude.GetOriginalSynonymId();
                        insertExclude.ExecuteScalar();
                    }

                    //Заполнили таблицу логов для синонимов производителей
                    daSynonymFirmCr.SelectCommand.Connection = c;
                    daSynonymFirmCr.UpdateCommand.Connection = c;
                    daSynonymFirmCr.InsertCommand.Connection = c;
                    var dtSynonymFirmCrCopy = dtSynonymFirmCr.Copy();
                    foreach (DataRow drInsertProducerSynonym in dtSynonymFirmCrCopy.Rows)
                    {
                        lastUpdateSynonym = drInsertProducerSynonym;
                        daSynonymFirmCr.InsertCommand.CommandText = insertSynonymProducerEtalonSQL;
                        daSynonymFirmCr.UpdateCommand.CommandText = updateSynonymProducerEtalonSQL;

                        //обновляем по одному синониму производителя, т.к. может быть добавление в исключение
                        daSynonymFirmCr.Update(new[] { drInsertProducerSynonym });
                    }

                    MySqlHelper.ExecuteNonQuery(c,
                                                @"
update
usersettings.pricescosts,
usersettings.priceitems
set
priceitems.LastSynonymsCreation = now()
where
pricescosts.PriceCode = ?PriceCode
and priceitems.Id = pricescosts.PriceItemId",
                                                new MySqlParameter("?PriceCode", priceId));
                    formProgress.ApplyProgress += 10;

                    //Заполнили таблицу логов для запрещённых выражений
                    daForbidden.SelectCommand.Connection = c;
                    var dtForbiddenCopy = dtForbidden.Copy();
                    daForbidden.Update(dtForbiddenCopy);

                    formProgress.ApplyProgress += 10;
                    //Обновление таблицы нераспознанных выражений
                    daUnrecUpdate.SelectCommand.Connection = c;
                    var dtUnrecUpdateCopy = dtUnrecUpdate.Copy();
                    daUnrecUpdate.Update(dtUnrecUpdateCopy);
                    formProgress.ApplyProgress += 10;

                    // Сохраняем запрещенные имена производителей
                    var deleteUnrec = new MySqlCommand("delete from farm.UnrecExp where LOWER(FirmCr) = ?FirmName and Status = 1", c);

                    var insertForbiddenProducer = new MySqlCommand(@"
insert into Farm.Forbiddenproducers(Name)
value (?Name);", c);
                    insertForbiddenProducer.Parameters.Add("?Name", MySqlDbType.VarChar);
                    foreach (var producer in ForbiddenProducers.Where(e => e.Id == 0))
                    {
                        insertForbiddenProducer.Parameters["?Name"].Value = producer.Name;
                        insertForbiddenProducer.ExecuteScalar();

                        // удаляем нераспознанные выражения с таким же наименованием производителя
                        deleteUnrec.Parameters.Clear();
                        deleteUnrec.Parameters.AddWithValue("?FirmName", producer.Name.ToLower());
                        deleteUnrec.ExecuteNonQuery();
                    }
                });
            }
            catch (Exception e) {
                if (e.Message.Contains("Duplicate entry"))
                {
                    Mailer.SendDebugLog(dtSynonymFirmCr, e, lastUpdateSynonym);
                }
                throw;
            }

            formProgress.ApplyProgress = 80;

            formProgress.Status = String.Empty;
            formProgress.Error  = String.Empty;

            formProgress.Status        = "Перепроведение пpайса...";
            formProgress.ApplyProgress = 80;

            try {
#if !DEBUG
                _remotePriceProcessor.RetransPriceSmartMsMq(priceId);
#endif
            }
            catch (Exception e) {
                formProgress.Error = "При перепроведении файлов возникла ошибка, которая отправлена разработчику.";
                _logger.Error(String.Format("Ошибка при перепроведении прайс листа {0}", priceId), e);
            }

            _logger.DebugFormat("Перепроведение пpайса завершено.");
            formProgress.ApplyProgress = 100;
        }