Пример #1
0
 //Генерация расчетных параметров для одного модуля
 public void GenerateParams(string moduleDir) //Каталог модуля
 {
     using (StartLog("Генерация параметров", moduleDir))
     {
         try
         {
             var dir       = moduleDir.EndDir();
             var table     = new GenTemplateTable("GenParams", "GenRule", "ErrMess", "CalcOn", "ParamId");
             var subTable  = new GenTemplateTable("GenSubParams", table, "GenRule", "ErrMess", "CalcOn", "SubParamId", "ParamId");
             var dataTabls = new TablsList();
             AddEvent("Загрузка структуры исходных таблиц", dir + "Tables.accdb");
             using (var db = new DaoDb(dir + "Tables.accdb"))
             {
                 dataTabls.AddDbStructs(db);
                 AddEvent("Загрузка значений из исходных таблиц");
                 dataTabls.LoadValues(db, true);
             }
             AddEvent("Загрузка и проверка генерирующих параметров");
             var generator = new ModuleGenerator(Logger, dataTabls, dir + "CalcParams.accdb", table, subTable);
             generator.Generate(dir + "Compiled.accdb", "GeneratedParams", "GeneratedSubParams");
             AddEvent("Генерация завершена", generator.GenErrorsCount + " ошибок");
             if (generator.GenErrorsCount != 0)
             {
                 SetLogResults(generator.GenErrorsCount + " ошибок");
                 AddCollectResult("Шаблон генерации содержит " + generator.GenErrorsCount + " ошибок");
             }
         }
         catch (Exception ex)
         {
             AddError("Ошибка при генерации параметров", ex);
         }
     }
 }
Пример #2
0
 //Загрузка таблиц
 private void LoadTables()
 {
     AddEvent("Загрузка данных исходных таблиц");
     using (var db = new DaoDb(_tablsFile))
     {
         db.ConnectDao();
         TablsList = new TablsList(db);
         TablsList.LoadValues();
     }
 }
Пример #3
0
        public void LoadValues()
        {
            var tdir = Different.GetTestInfoTaskDir() + @"CommonTypes\Tabls\LoadValues\";
            var tdb  = new DaoDb(tdir + "Project2GenData.accdb");
            {
                var tlist = new TablsList(tdb);
                tlist.LoadValues();

                var t      = tlist.Tabls["T1"];
                var rnums  = t.TablValues.SubNums;
                var rcodes = t.TablValues.SubCodes;
                Assert.IsTrue(rnums.ContainsKey(1));
                Assert.AreEqual("aa", rnums[1].Code);
                Assert.AreEqual("sssa", rnums[1]["stringfield"].String);
                Assert.AreEqual(10, rnums[1]["intfield"].Integer);
                Assert.AreEqual(2, rnums[1].SubCodes.Count);
                Assert.AreEqual(2, rnums[1].SubNums.Count);
                Assert.AreEqual("a1", rnums[1].SubNums[1].Code);
                Assert.AreEqual(2, rnums[1].SubCodes["a2"].Num);
                Assert.AreEqual("sa1", rnums[1].SubNums[1]["StringSub"].String);
                Assert.AreEqual("sa2", rnums[1].SubNums[2]["StringSub"].String);
                Assert.AreEqual("sa1", rnums[1].SubNums[1][0].String);
                Assert.AreEqual("sa2", rnums[1].SubNums[2][0].String);
                Assert.AreEqual(11, rnums[1].SubNums[1][1].Integer);
                Assert.AreEqual(12, rnums[1].SubNums[2][1].Integer);

                Assert.IsTrue(rcodes.ContainsKey("aa"));
                Assert.AreEqual(1, rcodes["aa"].Num);
                Assert.AreEqual("sssa", rcodes["aa"]["stringfield"].String);
                Assert.AreEqual("sa2", rcodes["aa"].SubNums[2]["StringSub"].String);

                Assert.IsTrue(rnums.ContainsKey(2));
                Assert.AreEqual("bb", rnums[2].Code);
                Assert.AreEqual("Sssb", rnums[2]["StringField"].String);
                Assert.AreEqual(20, rnums[2]["IntField"].Integer);
                Assert.AreEqual(1, rnums[2].SubCodes.Count);
                Assert.AreEqual(1, rnums[2].SubNums.Count);
                Assert.AreEqual("b1", rnums[2].SubNums[1].Code);
                Assert.AreEqual("sb1", rnums[2].SubNums[1]["StringSub"].String);

                Assert.IsTrue(rnums.ContainsKey(3));
                Assert.AreEqual("cc", rnums[3].Code);
                Assert.AreEqual("SSSC", rnums[3]["StringField"].String);
                Assert.AreEqual(30, rnums[3]["IntField"].Integer);
                Assert.AreEqual(3, rnums[3].SubCodes.Count);
                Assert.AreEqual(3, rnums[3].SubNums.Count);
                Assert.AreEqual("c2", rnums[3].SubNums[2].Code);
                Assert.AreEqual("sc3", rnums[3].SubNums[3]["StringSub"].String);
                Assert.AreEqual(33, rnums[3].SubNums[3]["IntSub"].Integer);

                t = tlist.Tabls["T2"];
                Assert.AreEqual(0, t.TablValues.SubNums.Count);
                Assert.AreEqual(0, t.TablValues.SubCodes.Count);
            }
        }
Пример #4
0
        //Загрузка таблиц
        private TablsList Load(string prefix)
        {
            var tabls = new TablsList();

            using (var db = new DaoDb(TestLib.CopyFile("Generator", "GenData.accdb", "Rows" + prefix + ".accdb")))
            {
                tabls.AddStruct(db, "Tabl", "SubTabl", "SubSubTabl");
                tabls.AddDbStructs(db);
                tabls.LoadValues(db, true);
            }
            return(tabls);
        }
Пример #5
0
        private void LoadTabls()
        {
            AddEvent("Загрузка графиков");
            using (var db = new DaoDb(Dir + "Grafics.accdb"))
            {
                using (var rec = new DaoRec(db, "GraficsList"))
                    while (rec.Read())
                    {
                    }
            }

            AddEvent("Загрузка таблиц");
            using (var db = new DaoDb(Dir + "Tables.accdb"))
            {
                TablsList.AddDbStructs(db);
                TablsList.LoadValues(db, false);
            }
        }
Пример #6
0
        private void Generate(string tablName, string subTablName = null, bool copyRes = true)
        {
            var tabls = new TablsList();

            using (var db = new DaoDb(TestLib.CopyFile("Generator", "GenData.accdb", "Gen" + tablName + "Data.accdb")))
            {
                tabls.AddStruct(db, "Tabl", "SubTabl", "SubSubTabl");
                tabls.AddDbStructs(db);
                tabls.LoadValues(db, true);
            }

            TestLib.CopyFile("Generator", "GenTemplate.accdb", "Gen" + tablName + "Template.accdb");
            if (copyRes)
            {
                TestLib.CopyFile("Generator", "GenRes.accdb", "Gen" + tablName + "Res.accdb");
            }
            TestLib.CopyFile("Generator", "CorrectGen" + tablName + ".accdb", "Gen" + tablName + "Correct.accdb");

            var templatesFile = TestLib.TestRunDir + @"Generator\Gen" + tablName + "Template.accdb";
            var table         = new GenTemplateTable(tablName, "GenRule", "ErrMess", "CalcOn", "Id");
            var subTable      = subTablName == null ? null : new GenTemplateTable(subTablName, table, "GenRule", "ErrMess", "CalcOn", "Id", "ParentId");
            var logger        = new Logger(new AppIndicator());

            logger.History = new TestHistory(logger);
            var generator = new ModuleGenerator(logger, tabls, templatesFile, table, subTable);

            var s = TestLib.TestRunDir + @"Generator\Gen" + tablName;

            if (copyRes)
            {
                generator.Generate(s + "Res.accdb", tablName, subTablName);
            }

            using (var db1 = new DaoDb(s + (copyRes ? "Res" : "Template") + ".accdb"))
                using (var db2 = new DaoDb(s + "Correct" + ".accdb"))
                {
                    TestLib.CompareTables(db1, db2, tablName, "Id");
                    if (subTablName != null)
                    {
                        TestLib.CompareTables(db1, db2, subTablName, "Id");
                    }
                }
        }
Пример #7
0
        public void TablValues()
        {
            using (var db = CopyDb("Values"))
            {
                var tlist = new TablsList();
                Assert.AreEqual(0, tlist.Tabls.Count);
                tlist.AddStruct(db, "Tabl", "SubTabl", "SubSubTabl");
                Assert.AreEqual(1, tlist.Structs.Count);
                tlist.LoadValues(db, false);
                Assert.AreEqual(1, tlist.Tabls.Count);
                var tabl = tlist.Tabls["Tabl"];
                Assert.AreEqual(3, tabl.Rows[0].Count);
                Assert.AreEqual(4, tabl.Rows[1].Count);
                Assert.AreEqual(0, tabl.Rows[2].Count);
                Assert.AreEqual(3, tabl.SubCodes.Count);
                Assert.AreEqual(2, tabl.SubNums.Count);
                Assert.AreEqual(3, tabl.SubList.Count);

                Assert.IsTrue(tabl.SubCodes.ContainsKey("s1"));
                Assert.IsTrue(tabl.SubCodes.ContainsKey("s2"));
                Assert.IsTrue(tabl.SubCodes.ContainsKey("s3"));
                Assert.IsTrue(tabl.SubNums.ContainsKey(11));
                Assert.IsTrue(tabl.SubNums.ContainsKey(12));

                var row = tabl.SubCodes["s1"];
                Assert.AreEqual(3, row.SubCodes.Count);
                Assert.AreEqual(3, row.SubNums.Count);
                Assert.AreEqual(3, row.SubList.Count);
                Assert.AreEqual(1, row.Id);
                Assert.AreEqual(11, row.Num);
                Assert.AreEqual("s1", row.Code);

                Assert.AreEqual(DataType.Integer, row["Num"].DataType);
                Assert.AreEqual(11, row["Num"].Integer);
                Assert.IsNull(row["Num"].Error);
                Assert.AreEqual(DataType.String, row["StringField"].DataType);
                Assert.AreEqual("SSS", row["StringField"].String);
                Assert.AreEqual(DataType.Boolean, row["BoolField"].DataType);
                Assert.AreEqual(true, row["StringField"].Boolean);
                Assert.AreEqual(DataType.Time, row["TimeField"].DataType);
                Assert.AreEqual(new DateTime(2016, 9, 26), row["TimeField"].Date);

                row = row.SubNums[1];
                Assert.AreEqual(2, row.SubCodes.Count);
                Assert.AreEqual(2, row.SubNums.Count);
                Assert.AreEqual(2, row.SubList.Count);
                Assert.AreEqual(1, row.Id);
                Assert.AreEqual(1, row.ParentId);
                Assert.AreEqual(1, row.Num);
                Assert.AreEqual("a", row.Code);

                Assert.AreEqual(DataType.Integer, row["Num"].DataType);
                Assert.AreEqual(1, row["Num"].Integer);
                Assert.AreEqual(DataType.String, row["Code"].DataType);
                Assert.AreEqual("a", row["Code"].String);
                Assert.AreEqual(DataType.String, row["StringSub"].DataType);
                Assert.AreEqual("", row["StringSub"].String);
                Assert.AreEqual(DataType.Boolean, row["BoolSub"].DataType);
                Assert.AreEqual(true, row["StringSub"].Boolean);
                Assert.AreEqual(DataType.Real, row["RealSub"].DataType);
                Assert.AreEqual(1, row["RealSub"].Real);

                row = row.SubNums[2000];
                Assert.AreEqual(0, row.SubCodes.Count);
                Assert.AreEqual(0, row.SubNums.Count);
                Assert.AreEqual(0, row.SubList.Count);
                Assert.AreEqual(2, row.Id);
                Assert.AreEqual(1, row.ParentId);
                Assert.AreEqual(2000, row.Num);
                Assert.AreEqual("ppp", row.Code);

                Assert.AreEqual(DataType.String, row["Code"].DataType);
                Assert.AreEqual("ppp", row["Code"].String);
                Assert.AreEqual(DataType.String, row["StringString"].DataType);
                Assert.AreEqual("ppp", row["StringString"].String);
                Assert.AreEqual(DataType.Boolean, row["BoolBool"].DataType);
                Assert.AreEqual(true, row["BoolBool"].Boolean);

                row = tabl.SubNums[12];
                Assert.AreEqual(1, row.SubCodes.Count);
                Assert.AreEqual(1, row.SubNums.Count);
                Assert.AreEqual(1, row.SubList.Count);
                Assert.AreEqual(2, row.Id);
                Assert.AreEqual(12, row.Num);
                Assert.AreEqual("s2", row.Code);

                Assert.AreEqual(DataType.Integer, row["Num"].DataType);
                Assert.AreEqual(12, row["Num"].Integer);
                Assert.AreEqual(DataType.String, row["StringField"].DataType);
                Assert.AreEqual("SSS", row["StringField"].String);
                Assert.AreEqual(DataType.Boolean, row["BoolField"].DataType);
                Assert.AreEqual(true, row["StringField"].Boolean);
                Assert.AreEqual(DataType.Real, row["RealField"].DataType);
                Assert.AreEqual(123.5, row["RealField"].Real);

                tlist.AddDbStructs(db);
                tlist.LoadValues(db, true);
                Assert.AreEqual(2, tlist.Tabls.Count);
                Assert.AreEqual(2, tlist.Structs.Count);
                tabl = tlist.Tabls["VTZTZ"];
                Assert.AreEqual(6, tabl.SubCodes.Count);
                Assert.AreEqual(1, tabl.SubNums.Count);
                Assert.AreEqual(6, tabl.SubList.Count);

                row = tabl.SubCodes["ВТЗЗ00120101002"];
                Assert.AreEqual(1, row.SubCodes.Count);
                Assert.AreEqual(1, row.SubNums.Count);
                Assert.AreEqual(1, row.SubList.Count);
                Assert.AreEqual(386, row.Id);
                Assert.AreEqual(0, row.Num);
                Assert.AreEqual("ВТЗЗ00120101002", row.Code);

                Assert.AreEqual(DataType.String, row["Code"].DataType);
                Assert.AreEqual("ВТЗЗ00120101002", row["Code"].String);
                Assert.AreEqual(DataType.String, row["NameVTZ"].DataType);
                Assert.AreEqual("Выходные цепи отключения ДВ-А", row["NameVTZ"].String);
                Assert.AreEqual(DataType.Integer, row["SysNumVTZ"].DataType);
                Assert.AreEqual(43000, row["SysNumVTZ"].Integer);
                Assert.AreEqual(DataType.Integer, row["PriorVTZ"].DataType);
                Assert.AreEqual(1, row["PriorVTZ"].Integer);

                row = row.SubCodes["ТЗ_З00120101004"];
                Assert.IsNotNull(row.Parent);
                Assert.AreEqual(0, row.SubCodes.Count);
                Assert.AreEqual(0, row.SubNums.Count);
                Assert.AreEqual(0, row.SubList.Count);
                Assert.AreEqual(1, row.Id);
                Assert.AreEqual(386, row.ParentId);
                Assert.AreEqual(0, row.Num);
                Assert.AreEqual("ТЗ_З00120101004", row.Code);

                Assert.AreEqual(DataType.String, row["Code"].DataType);
                Assert.AreEqual("ТЗ_З00120101004", row["Code"].String);
                Assert.AreEqual(DataType.String, row["NameTZ"].DataType);
                Assert.AreEqual("Понижение Pм на смазку ДВ-А", row["NameTZ"].String);
                Assert.AreEqual(DataType.Integer, row["SysNumTZ"].DataType);
                Assert.AreEqual(41000, row["SysNumTZ"].Integer);
                Assert.AreEqual(DataType.Integer, row["IdUnitTZ"].DataType);
                Assert.AreEqual(10299, row["IdUnitTZ"].Integer);
            }
        }