コード例 #1
0
        public static IPriceFormalizer Formalize(Type formatType, DataTable parseRules, string file, int priceItemId)
        {
            var parser = PricesValidator.CreateFormalizer(file, parseRules.Rows[0], formatType);

            parser.Formalize();
            return(parser);
        }
コード例 #2
0
        public void FormalizeWithStrictTest()
        {
            var rules = PricesValidator.LoadFormRules(_testPrice.Costs[0].PriceItem.Id);
            var row   = rules.NewRow();

            row[FormRules.colFirmCode]      = 0;
            row[FormRules.colPriceCode]     = _testPrice.Id;
            row[FormRules.colFormByCode]    = 0;
            row[FormRules.colCostType]      = _testPrice.CostType;
            row[FormRules.colPriceType]     = _testPrice.PriceType;
            row[FormRules.colPriceItemId]   = _testPrice.Costs[0].PriceItem.Id;
            row[FormRules.colParentSynonym] = 0;
            row["BuyingMatrix"]             = 0;
            row["PriceEncode"] = _testPrice.Costs[0].PriceItem.Format.PriceEncode;
            rules.Rows.Add(row);
            var price = session.Query <Price>().FirstOrDefault(p => p.Id == _testPrice.Id);

            price.IsStrict = false;
            session.Save(price);
            Reopen();
            var info   = new PriceFormalizationInfo(row, price);
            var parser = new PriceDbfParser(@"..\..\Data\BadTestFile.dbf", info);

            parser.Formalize();
            Assert.AreEqual(info.CodePage, 1251);
        }
コード例 #3
0
        public IList <string> GetAllNames()
        {
            IList <string> names;
            var            tempPath = Path.GetTempPath() + (int)DateTime.Now.TimeOfDay.TotalMilliseconds + "_" +
                                      PriceItemId.ToString() + "\\";
            var tempFileName = tempPath + PriceItemId + Path.GetExtension(FilePath);

            if (Directory.Exists(tempPath))
            {
                global::Common.Tools.FileHelper.DeleteDir(tempPath);
            }
            Directory.CreateDirectory(tempPath);
            try {
                try {
                    var workPrice = PricesValidator.Validate(FilePath, tempFileName, (uint)PriceItemId);
                    workPrice.Downloaded = Downloaded;
                    names = workPrice.GetAllNames();
                }
                catch (WarningFormalizeException) {
                    return(null);
                }
            }
            finally {
                Directory.Delete(tempPath, true);
            }

            return(names);
        }
コード例 #4
0
        public static IPriceFormalizer Formalize(string file, int priceItemId)
        {
            var data       = PricesValidator.LoadFormRules((uint)priceItemId);
            var typeName   = String.Format("Inforoom.PriceProcessor.Formalizer.{0}, PriceProcessor", data.Rows[0]["ParserClassName"]);
            var parserType = Type.GetType(typeName);

            return(Formalize(parserType, data, file, priceItemId));
        }
コード例 #5
0
        private IPriceFormalizer CreateFormalizer()
        {
            var table      = PricesValidator.LoadFormRules(priceItem.Id);
            var row        = table.Rows[0];
            var localPrice = session.Load <Price>(price.Id);
            var info       = new PriceFormalizationInfo(row, localPrice);

            return(new BufferFormalizer(file, info));
        }
コード例 #6
0
        private void Formalize()
        {
            FlushAndCommit();
            var file = Path.GetTempFileName();

            Dbf.Save(data, file);
            var formalizer = PricesValidator.Validate(file, Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()),
                                                      priceItem.Id);

            formalizer.Formalize();
        }
コード例 #7
0
        private void AssertFormalization()
        {
            CreateDefaultSynonym();
            formalizer = PricesValidator.Validate(file, "test1" + Path.GetExtension(file), priceItem.Id);
            Formalize();

            var cores = session.Query <TestCore>().Where(c => c.Price == price).ToList();

            Assert.That(cores.Count, Is.EqualTo(3));
            Assert.That(cores[0].ProductSynonym.Name, Is.EqualTo("9 МЕСЯЦЕВ КРЕМ Д/ПРОФИЛАКТИКИ И КОРРЕКЦИИ РАСТЯЖЕК 150МЛ"));
            Assert.That(cores[0].OptimizationSkip, Is.True);
        }
コード例 #8
0
        private void Formalize()
        {
            FlushAndCommit();

            file = Path.GetTempFileName();
            File.WriteAllText(file, xml);
            var formalizer = PricesValidator.Validate(file, Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()),
                                                      priceItem.Id);

            formalizer.Downloaded = true;
            formalizer.Formalize();
        }
        public void FormalizeTest()
        {
            Reopen();
            var formalizer = PricesValidator.Validate(@"..\..\Data\FarmimpeksOKP.xml", Path.GetTempFileName(), _priceItem.Id);

            formalizer.Formalize();
            formalizer.Formalize();

            var cores = session.Query <TestCore>().Where(c => c.Price.Id == _price.Id).ToList();

            Assert.That(cores.Count, Is.EqualTo(4));
            Assert.That(cores.Any(c => c.CodeOKP == 931201));
        }
コード例 #10
0
        public static PriceProcessItem GetProcessItem(uint priceItemId)
        {
            var dtRules = PricesValidator.LoadFormRules(priceItemId);

            if (dtRules.Rows.Count == 0)
            {
                return(null);
            }
            var mask  = priceItemId + dtRules.Rows[0]["FileExtention"].ToString();
            var files = Directory.GetFiles(Settings.Default.BasePath, mask);

            return(TryToLoadPriceProcessItem(files.FirstOrDefault()));
        }
コード例 #11
0
        private void FakeParserSynonymTest(bool automatic, int automaticProducerSynonyms)
        {
            if (session.Transaction.IsActive)
            {
                session.Transaction.Commit();
            }

            var table  = PricesValidator.LoadFormRules(priceItem.Id);
            var row    = table.Rows[0];
            var info   = new PriceFormalizationInfo(row, session.Load <Price>(price.Id));
            var parser = new FakeParser(new FakeReader(), info);

            if (parser.Connection.State != ConnectionState.Open)
            {
                parser.Connection.Open();
            }
            FillDaSynonymFirmCr2(parser, (MySqlConnection)session.Connection, automatic);
            parser.Connection.Close();
            var counter = session.Connection.CreateCommand();

            counter.CommandText = "select count(*) from AutomaticProducerSynonyms";
            Assert.That(Convert.ToInt32(counter.ExecuteScalar()), Is.EqualTo(automaticProducerSynonyms));
        }
コード例 #12
0
 public static void Formalize(Type formatType, string file, int priceItemId)
 {
     Formalize(formatType, PricesValidator.LoadFormRules((uint)priceItemId), file, priceItemId);
 }
コード例 #13
0
        private void Formalize(string file)
        {
            var formalizer = PricesValidator.Validate(Path.Combine(@"..\..\Data\", file), Path.GetTempFileName(), priceItem.Id);

            formalizer.Formalize();
        }