Example #1
0
        public void QueryBase()
        {
            QueryBase qb     = new QueryBase();
            Query     query1 = new Query("get spending",
                                         new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("spending",
                                                                                               new Variable("customer"),
                                                                                               new Individual("min(5000,EUR)"),
                                                                                               new Individual("previous year"))));

            qb.Add(query1);
            Assert.AreEqual(1, qb.Count, "(1) QueriesCount");

            Query getQ1 = qb.Get("get spending");

            Assert.AreEqual(query1, getQ1, "Get Query Is Equal");
            Assert.IsTrue(((Atom)query1.AtomGroup.Members[0]).IsIntersecting((Atom)getQ1.AtomGroup.Members[0]), "Get Query Is Similar");

            Assert.IsNull(qb.Get("find me if you can"), "Missing query");

            Query query2 = new Query("get earning",
                                     new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("earning",
                                                                                           new Variable("customer"),
                                                                                           new Individual("min(99999,EUR)"),
                                                                                           new Individual("previous year"))));

            qb.Add(query2);
            Assert.AreEqual(2, qb.Count, "(2) QueriesCount");

            qb.Remove(qb.Get(0));
            Assert.AreEqual(1, qb.Count, "(3) QueriesCount");
            Query getQ2 = qb.Get(0);

            Assert.AreEqual(query2, getQ2, "(3) Get Query Is Equal");
            Assert.IsTrue(((Atom)query2.AtomGroup.Members[0]).IsIntersecting((Atom)getQ2.AtomGroup.Members[0]), "(3) Get Query Is Similar");

            qb.Add(new Query("to be killed",
                             new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("victim",
                                                                                   new Variable("test"),
                                                                                   new Individual("whatsoever")))));
            Assert.AreEqual(2, qb.Count, "(4) QueriesCount");

            qb.Remove(qb.Get("to be killed"));
            Assert.AreEqual(1, qb.Count, "(5) QueriesCount");

            qb.Remove(query2);
            Assert.AreEqual(0, qb.Count, "(6) QueriesCount");
        }
Example #2
0
        public void QueryBaseIndexTooHigh()
        {
            QueryBase qb = new QueryBase();

            qb.Add(new Query("get spending",
                             new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("spending",
                                                                                   new Variable("customer"),
                                                                                   new Individual("min(5000,EUR)"),
                                                                                   new Individual("previous year")))));
            qb.Get(2);
            Assert.Fail("Should never reach me!");
        }
Example #3
0
        /// <summary>
        /// Инициализация
        /// </summary>
        /// <param name="file">Файл</param>
        public void Init(
            [FileName(FileNameMode.Open, Filter = "Файлы DBF (*.dbf)|*.dbf|Все файлы (*.*)|*.*")]
            FileName file)
        {
            // Существующие записи КЛАДР
            IEnumerable <Kladr>        kladr = QueryBase.Get("Query.View(cmn.vw_kladr)").Select <Kladr>();
            Dictionary <string, Kladr> codes = new Dictionary <string, Kladr>(kladr.Count());

            foreach (Kladr k in kladr)
            {
                codes[k.Code] = k;
            }

            // Обработка записей
            DbfImporter import = new DbfImporter(new DbfImportParameters(file));

            Files.Add(import);
            import.ProcessRecordFunc = delegate(DbfRecord r)
            {
                string code = (string)r.Record["CODE"];
                if (!codes.ContainsKey(code))
                {
                    // Родительская запись
                    int   level  = Convert.ToInt32((decimal)r.Record["LEVEL"]);
                    Kladr parent = null;
                    if (level > 1)
                    {
                        int l = level;
                        while (l > 1 && parent == null)
                        {
                            int    count      = l == 5 ? 11 : l == 4 ? 8 : l == 3 ? 5 : 2;
                            string parentCode = code.Substring(0, count) +
                                                "0000000000000".Substring(0, code.Length - count - 2) + code.Substring(code.Length - 2, 2);
                            codes.TryGetValue(parentCode, out parent);
                            l--;
                        }
                        if (parent == null)
                        {
                            throw new KeyNotFoundException("Не найдена родительская запись: " + code);
                        }
                    }

                    // Импорт записи
                    KladrType type      = KladrType.GetType((decimal)r.Record["TYPE"]);
                    string    name      = (string)r.Record["NAME"];
                    string    codePost  = (string)r.Record["CODE_POST"];
                    string    codeIfns  = (string)r.Record["CODE_IFNS"];
                    string    codeIfnsT = (string)r.Record["CODE_IFNST"];
                    string    codeOkato = (string)r.Record["CODE_OKATO"];
                    codes[code] = new Kladr(type, parent, name, code, codePost, codeIfns, codeIfnsT, codeOkato);
                }
            };
        }
Example #4
0
 public void QueryBaseIndexSubZero()
 {
     Assert.Throws <IndexOutOfRangeException>(() => {
         QueryBase qb = new QueryBase();
         qb.Add(new Query(
                    "get spending",
                    new AtomGroup(
                        AtomGroup.LogicalOperator.And,
                        new Atom("spending",
                                 new Variable("customer"),
                                 new Individual("min(5000,EUR)"),
                                 new Individual("previous year")))));
         qb.Get(-1);
         Assert.Fail("Should never reach me!");
     });
 }
Example #5
0
 public void QueryBaseIndexTooHigh()
 {
     QueryBase qb = new QueryBase();
     qb.Add(new Query("get spending",
                           new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("spending",
                                               new Variable("customer"),
                                               new Individual("min(5000,EUR)"),
                                               new Individual("previous year")))));
     qb.Get(2);
     Assert.Fail("Should never reach me!");
 }
Example #6
0
        public void QueryBase()
        {
            QueryBase qb = new QueryBase();
            Query query1 = new Query("get spending",
                                          new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("spending",
                                                              new Variable("customer"),
                                                              new Individual("min(5000,EUR)"),
                                                              new Individual("previous year"))));
            qb.Add(query1);
            Assert.AreEqual(1, qb.Count, "(1) QueriesCount");

            Query getQ1 = qb.Get("get spending");
            Assert.AreEqual(query1, getQ1, "Get Query Is Equal");
            Assert.IsTrue(((Atom)query1.AtomGroup.Members[0]).IsIntersecting((Atom)getQ1.AtomGroup.Members[0]), "Get Query Is Similar");

            Assert.IsNull(qb.Get("find me if you can"), "Missing query");

            Query query2 = new Query("get earning",
                                          new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("earning",
                                                              new Variable("customer"),
                                                              new Individual("min(99999,EUR)"),
                                                              new Individual("previous year"))));
            qb.Add(query2);
            Assert.AreEqual(2, qb.Count, "(2) QueriesCount");

            qb.Remove(qb.Get(0));
            Assert.AreEqual(1, qb.Count, "(3) QueriesCount");
            Query getQ2 = qb.Get(0);
            Assert.AreEqual(query2, getQ2, "(3) Get Query Is Equal");
            Assert.IsTrue(((Atom)query2.AtomGroup.Members[0]).IsIntersecting((Atom)getQ2.AtomGroup.Members[0]), "(3) Get Query Is Similar");

            qb.Add(new Query("to be killed",
                                  new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("victim",
                                                      new Variable("test"),
                                                      new Individual("whatsoever")))));
            Assert.AreEqual(2, qb.Count, "(4) QueriesCount");

            qb.Remove(qb.Get("to be killed"));
            Assert.AreEqual(1, qb.Count, "(5) QueriesCount");

            qb.Remove(query2);
            Assert.AreEqual(0, qb.Count, "(6) QueriesCount");
        }