Beispiel #1
0
        //Подготовка провайдера
        protected override void PrepareProvider()
        {
            var set = new SetS();

            using (var rec = new DaoRec(Db, "Signals"))
            {
                while (rec.Read())
                {
                    var code       = rec.GetString("FillCode");
                    var isContains = _outs.ContainsKey(code);
                    rec.Put("IsActive", isContains);
                    if (isContains)
                    {
                        set.Add(code);
                        _outs[code].Id = rec.GetInt("SignalId");
                    }
                }
                foreach (var k in _outs.Keys)
                {
                    if (!set.Contains(k))
                    {
                        rec.AddNew();
                        var o = _outs[k].ValueSignal;
                        rec.Put("FullCode", o.Code);
                        rec.Put("DataType", o.DataType.ToRussian());
                        rec.Put("SignalType", SignalType.List.ToRussian());
                        _outs[k].Id = rec.GetInt("SignalId");
                    }
                }
            }
            CloneRec    = new DaoRec(Db, "MomentValues");
            CloneStrRec = new DaoRec(Db, "MomentStrValues");
        }
Beispiel #2
0
        //Определение типов данных и формирование порожденных параметров
        public void DefineDataTypes()
        {
            foreach (var node in Expr1.Nodes)
            {
                node.DefineType();
            }

            var last = Expr1.Nodes.Last();

            if (last.Type.DataType != DataType.Void)
            {
                var resVar = Vars["calc"];
                resVar.Type = resVar.Type.Add(last.Type);
            }
            foreach (var node in Expr2.Nodes)
            {
                node.DefineType();
            }
            last = Expr2.Nodes.Last();
            Type = last.Type;
            if (Type is ObjectType || Type is BaseObjectType)
            {
                MetSignals = Keeper.GetMetSignals(last);
                MetProps   = Keeper.GetMetProps(last);
            }
        }
Beispiel #3
0
        //Сравнение двух таблиц на полное совпадение,
        public static bool CompareTables(DaoDb db1, DaoDb db2,                                           //Базы данных для сравнения
                                         string tableName,                                               //Имяы таблицы
                                         string idField, string idField2 = null, string idField3 = null, //Ключевые поля для сравнения
                                         string tableName2 = null,                                       //Имя таблицы во второй базе, если отличается
                                         params string[] exeptionFields)                                 //Поля, исключаемые из сравнения
        {
            var exFields = new SetS();

            foreach (var f in exeptionFields)
            {
                exFields.Add(f);
            }
            using (var rec1 = new DaoRec(db1, "SELECT * FROM " + tableName + " ORDER BY " + idField + (idField2 == null ? "" : ", " + idField2) + (idField3 == null ? "" : ", " + idField3)))
                using (var rec2 = new DaoRec(db2, "SELECT * FROM " + (tableName2 ?? tableName) + " ORDER BY " + idField + (idField2 == null ? "" : ", " + idField2) + (idField3 == null ? "" : ", " + idField3)))
                {
                    rec1.Read();
                    while (rec2.Read())
                    {
                        Assert.AreEqual(rec1.EOF, rec2.EOF);
                        foreach (var k in rec1.Fileds.Keys)
                        {
                            if (!exFields.Contains(k))
                            {
                                Assert.AreEqual(rec1.Recordset.Fields[k].Value, rec2.Recordset.Fields[k].Value);
                            }
                        }
                        rec1.Read();
                    }
                    Assert.AreEqual(rec1.EOF, rec2.EOF);
                }
            return(true);
        }
Beispiel #4
0
        public void Simple()
        {
            var set = new SetS();

            Assert.AreEqual(0, set.Count);
            set.Clear();
            Assert.AreEqual(0, set.Count);
            Assert.AreEqual(0, set.Keys.Count);
            Assert.AreEqual(0, set.Values.Count);
            set.Add("a");
            set.Add("Bb");
            Assert.AreEqual(2, set.Count);
            Assert.IsTrue(set.Contains("a"));
            Assert.IsTrue(set.Contains("bB"));
            Assert.IsFalse(set.Contains("ff"));
            Assert.AreEqual("aBb", set.Values.Aggregate("", (current, v) => current + v));
            set.Add("BB", true);
            Assert.IsTrue(set.Contains("a"));
            Assert.IsTrue(set.Contains("bb"));
            Assert.IsFalse(set.Contains("ff"));
            Assert.AreEqual("aBB", set.Values.Aggregate("", (current, v) => current + v));
            set.Add("bb");
            set.Add("CCC");
            Assert.AreEqual("aBBCCC", set.Values.Aggregate("", (current, v) => current + v));
            Assert.IsTrue(set.Contains("a"));
            Assert.IsTrue(set.Contains("bb"));
            Assert.IsTrue(set.Contains("cCc"));
            Assert.AreEqual(3, set.Count);
            set.Remove("bb");
            Assert.IsFalse(set.Contains("bb"));
            Assert.IsTrue(set.Contains("ccc"));
            Assert.AreEqual(2, set.Count);
            Assert.IsFalse(set.Remove("bb"));
        }
Beispiel #5
0
        //Формирование списка параметров для записи в архив и запись их в CalcParamsArchive
        private void SaveArchive()
        {
            try
            {
                using (var db = new DaoDb(_projectFile))
                {
                    foreach (var cp in CalcParamsId.Values)
                    {
                        if (cp.Inputs.Count == 0 && cp.CalcOn && cp.ErrMess == "")
                        {
                            new ParamArchive(cp);
                        }
                    }

                    var old = new SetS();
                    var add = new SetS();
                    using (var rec = new RecDao(db, "CalcParamsArchive", RecordsetTypeEnum.dbOpenTable))
                        while (rec.Read())
                        {
                            var code = rec.GetString("FullCode");
                            if (ArchiveParams.ContainsKey(code))
                            {
                                old.Add(code);
                            }
                            else
                            {
                                rec.Put("Del", true);
                            }
                        }
                    db.Execute("DELETE * FROM CalcParamsArchive WHERE Del=True");

                    foreach (var ap in ArchiveParams.Keys)
                    {
                        if (!old.Contains(ap))
                        {
                            add.Add(ap);
                        }
                    }
                    using (var rec = new RecDao(db, "CalcParamsArchive", RecordsetTypeEnum.dbOpenTable))
                    {
                        while (rec.Read())
                        {
                            ArchiveParams[rec.GetString("FullCode")].ToRecordset(rec, false);
                        }
                        foreach (var p in add.Keys)
                        {
                            ArchiveParams[p].ToRecordset(rec, true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AddError("Ошибка сохранения архивных параметров", ex);
            }
        }
Beispiel #6
0
        //Заполняет источник для выпадающего списка по HashSet
        private void MakeFilterItems(ComboBox field, SetS set)
        {
            field.Items.Clear();
            var arr = set.Values.ToArray();

            Array.Sort(arr);
            foreach (var it in arr)
            {
                field.Items.Add(it);
            }
        }
Beispiel #7
0
        //Запись используемых сигналов в SignalsInUse
        private void SaveInUse()
        {
            try
            {
                using (var db = new DaoDb(_projectFile))
                {
                    var old = new SetS();
                    using (var rec = new RecDao(db, "SignalsInUse"))
                    {
                        while (rec.Read())
                        {
                            var code = rec.GetString("FullCode");
                            if ((Signals.ContainsKey(code) && Signals[code].InUse) || HandSignals.ContainsKey(code))
                            {
                                old.Add(code);
                                rec.Put("Del", false);
                            }
                            else
                            {
                                rec.Put("Del", true);
                            }
                        }
                    }
                    db.Execute("DELETE * FROM SignalsInUse WHERE Del=True");
                    var add = new SetS();
                    var use = from s in SignalsList where s.InUse select s;
                    SignalsInUseCount = use.Count();
                    foreach (var s in use)
                    {
                        if (!old.Contains(s.FullCode))
                        {
                            add.Add(s.FullCode);
                        }
                        if (s.InUseSource)
                        {
                            UsedProviders.Add(s.SourceName);
                        }
                        if (s.InUseReceiver)
                        {
                            UsedProviders.Add(s.ReceiverName);
                        }
                    }
                    if (HandSignals.Count > 0 && HandInputSource != null)
                    {
                        UsedProviders.Add(HandInputSource);
                    }
                    foreach (var hand in HandSignals.Values)
                    {
                        if (!old.Contains(hand.FullCode))
                        {
                            add.Add(hand.FullCode);
                        }
                    }

                    using (var rec = new RecDao(db, "SignalsInUse"))
                    {
                        while (rec.Read())
                        {
                            var    s   = rec.GetString("FullCode");
                            Signal sig = Signals.ContainsKey(s) ? Signals[s] : HandSignals[s];
                            sig.ToRecordset(rec, false);
                        }
                        foreach (var s in add.Keys)
                        {
                            Signal sig = Signals.ContainsKey(s) ? Signals[s] : HandSignals[s];
                            sig.ToRecordset(rec, true);
                        }
                    }
                    using (var rec = new RecDao(db, "GraficsList"))
                        while (rec.Read())
                        {
                            rec.Put("UsedUnits", UsingParamsString(Grafics[rec.GetString("Code")].UsingParams));
                        }
                }
            }
            catch (Exception ex)
            {
                AddError("Ошибка сохранения сигналов или графиков", ex);
            }
        }
Beispiel #8
0
        //Запись в таблицу PrevParams
        private void SavePrevs()
        {
            try
            {
                using (var db = new DaoDb(_projectFile))
                {
                    var old = new SetS();
                    var add = new SetS();
                    using (var rec = new RecDao(db, "PrevParams"))
                        while (rec.Read())
                        {
                            var code = rec.GetString("FullCode");
                            if (Prevs.ContainsKey(code) && Prevs[code].Id != 0)
                            {
                                old.Add(code);
                                rec.Put("Del", false);
                            }
                            else
                            {
                                rec.Put("Del", true);
                            }
                        }
                    db.Execute("DELETE * FROM PrevParams WHERE Del=True");

                    foreach (var prev in Prevs.Keys)
                    {
                        if (!old.Contains(prev))
                        {
                            add.Add(prev);
                        }
                    }
                    if (Prevs.Count > 0)
                    {
                        using (var rec = new RecDao(db, "PrevParams"))
                        {
                            while (rec.Read())
                            {
                                Prevs[rec.GetString("FullCode")].ToRecordset(rec, false);
                            }
                            foreach (var p in add.Keys)
                            {
                                Prevs[p].ToRecordset(rec, true);
                            }
                        }
                    }

                    foreach (var p in Prevs.Values)
                    {
                        IsPrevAbs     |= p.PrevAbs;
                        IsLastBase    |= p.LastBase;
                        IsLastHour    |= p.LastHour;
                        IsLastDay     |= p.LastDay;
                        IsManyBase    |= p.ManyBase;
                        IsManyHour    |= p.ManyHour;
                        IsManyDay     |= p.ManyDay;
                        IsManyMoments |= p.ManyMoments;
                    }
                }
            }
            catch (Exception ex)
            {
                AddError("Ошибка сохранения параметров фунций Пред", ex);
            }
        }
Beispiel #9
0
        //Компиляция проекта, возвращает количество ошибок компиляции
        public string CompileProject()
        {
            //OnlyOn = true;
            CountsToZero();
            if (State == State.Project || State == State.Empty)//Если не загружены, то загружаем сигналы
            {
                string s = LoadSignals();
                if (s != "")
                {
                    return(s);
                }
            }
            else
            {
                foreach (var sig in SignalsList)
                {
                    sig.InUse         = false;
                    sig.InUseSource   = false;
                    sig.InUseReceiver = false;
                }
            }
            StartAtom(Atom.CompileProject);
            if (State == State.Closed)
            {
                AddError("Копилятор уже был закрыт");
            }
            else
            {
                try
                {
                    //Обнуления поля Expr и т.п.
                    using (var daodb = new DaoDb(_projectFile))
                    {
                        //daodb.Execute("UPDATE CalcParams SET CalcParams.Expr = Null, CalcParams.ErrMess = Null, CalcParams.UsedUnits = Null, CalcParams.CalcNumber = 0;");
                        foreach (string tab in new[] { "CalcParams", "CalcSubParams" })
                        {
                            using (var rec = new RecDao(daodb, tab))
                                while (rec.Read())
                                {
                                    rec.Put("Expr", (string)null);
                                    try { rec.Put("UsedUnits", (string)null); } catch { }
                                    rec.Put("CalcNumber", 0);
                                    rec.Put("ErrMess", (string)null);
                                    rec.Update();
                                }
                        }
                        CalcParams.Clear();
                        CalcParamsId.Clear();
                        CalcParamsAll.Clear();
                        Grafics.Clear();
                        ArchiveParams.Clear();
                        Prevs.Clear();
                        HandSignals.Clear();
                        CalcParamNumber = 0;

                        Procent = 10;
                        AddEvent("Загрузка графиков");
                        using (var rec = new RecDao(daodb, "SELECT GraficsList.Code, GraficsList.Dimension FROM GraficsList"))
                            while (rec.Read())
                            {
                                var gr = new Grafic(rec.GetString("Code"), rec.GetInt("Dimension"));
                                Grafics.Add(gr.Code, gr);
                            }

                        Procent = 15;
                        AddEvent("Загрузка параметров");
                        string spar = OnlyOn ? "WHERE (CalcOn = True) And (TaskOn = True)" : "";
                        using (var rec = new RecDao(daodb, "SELECT CalcParams.* FROM CalcParams " + spar + " ORDER BY CalcParamId"))
                            while (rec.Read())
                            {
                                new CalcParam(rec, this);
                            }

                        Procent = 25;
                        AddEvent("Загрузка подпараметров");
                        string ssub = OnlyOn ? "WHERE (CalcParams.CalcOn = True) And (CalcParams.TaskOn = True) And (CalcSubParams.CalcOn = True)" : "";
                        using (var rec = new RecDao(daodb, "SELECT CalcSubParams.* FROM CalcParams INNER JOIN CalcSubParams ON CalcParams.CalcParamId = CalcSubParams.OwnerId " + ssub))
                            while (rec.Read())
                            {
                                new CalcParam(rec, this, true);
                            }

                        Procent = 35;
                        AddEvent("Разбор выражений");
                        foreach (var cp in CalcParamsId.Values)
                        {
                            cp.Parse();
                        }

                        IsPrevAbs     = false;
                        IsLastBase    = false;
                        IsLastHour    = false;
                        IsLastDay     = false;
                        IsManyBase    = false;
                        IsManyHour    = false;
                        IsManyDay     = false;
                        IsManyMoments = false;

                        Procent = 45;
                        AddEvent("Компиляция выражений");
                        foreach (var cp in CalcParamsId.Values)
                        {
                            if (cp.Stage == CompileStage.NotStarted)
                            {
                                cp.Compile(null);
                            }

                            /*foreach (var d in cp.MethodsId.Values)
                             *  if (d.Stage == CompileStage.NotStarted)
                             *      d.Compile(null);*/
                        }

                        FindCycleLinks();

                        ErrorsCount   = 0;
                        UsedProviders = new SetS();
                        IsAbsolute    = false;
                        IsPeriodic    = false;
                        IsMoments     = false;

                        Procent = 60;
                        AddEvent("Сохранение результатов компиляции параметров");
                        using (var rec = new RecDao(daodb, "SELECT CalcParams.* FROM CalcParams " + spar + " ORDER BY CalcParamId"))
                            SaveCompile(rec, false);

                        Procent = 70;
                        AddEvent("Сохранение результатов компиляции подпараметров");
                        using (var rec = new RecDao(daodb, "SELECT CalcSubParams.* FROM CalcParams INNER JOIN CalcSubParams ON CalcParams.CalcParamId = CalcSubParams.OwnerId " + ssub + " ORDER BY CalcParams.CalcParamId;"))
                            SaveCompile(rec, true);
                    }

                    Procent = 80;
                    AddEvent("Сохранение списка используемых сигналов и графиков");
                    SaveInUse();

                    Procent = 90;
                    AddEvent("Сохранение архивных параметров");
                    SaveArchive();

                    Procent = 96;
                    AddEvent("Сохранение параметров функций Пред");
                    SavePrevs();

                    Procent = 99;
                    SaveUsedProviders();
                    using (var sys = new SysTabl(_projectFile))
                    {
                        sys.PutSubValue("CompileStatus", "LastTimeCompile", DateTime.Now.ToString());
                        sys.PutSubValue("CompileStatus", "ErrorsCount", ErrorsCount.ToString());
                    }
                }
                catch (Exception ex)
                {
                    AddError("Ошибка компилятора", ex);
                }
            }
            return(FinishAtom(State.Compiled, State.Signals, "Проект: " + _code + ";  Ошибок: " + ErrorsCount + ";" + Different.NewLine
                              + "Параметров: " + CalcParamsId.Count + "; Архивных параметров:" + ArchiveParams.Count + ";  Сигналов: " + SignalsInUseCount));
        }
Beispiel #10
0
        //Обновление списка проектов в файле данных отчета
        private IEnumerable <ReportProjectForData> MakeProjectsList()
        {
            AddEvent("Обновление списка проектов");
            var plist = new DicS <ReportProjectForData>();

            try
            {
                using (var rec = new RecDao(General.ReporterFile, "SELECT Reports.Report, Projects.* FROM Reports INNER JOIN Projects ON Reports.ReportId = Projects.ReportId WHERE Report='" + Code + "'"))
                    while (rec.Read())
                    {
                        var p = new ReportProjectForData(this, rec);
                        plist.Add(p.CodeFinal, p);
                    }

                foreach (var pr in SysPage.GetProjects().Values)
                {
                    if (plist.ContainsKey(pr.CodeFinal))
                    {
                        plist[pr.CodeFinal].CalcMode = pr.CalcMode;
                    }
                }
                foreach (var pr in plist.Values)
                {
                    pr.GetChangeTime();
                }
                using (var db = new DaoDb(DataFile))
                {
                    var dic = new SetS();
                    using (var rec = new RecDao(db, "SELECT * FROM Projects"))
                    {
                        while (rec.Read())
                        {
                            var code = rec.GetString("Project");
                            if (code != "Сохранение" && code != "Системные")
                            {
                                if (!plist.ContainsKey(code))
                                {
                                    rec.Put("SysField", "Del");
                                }
                                else
                                {
                                    dic.Add(code);
                                    rec.Put("SysField", "");
                                    plist[code].DataChangeTime = rec.GetTime("LastChange");
                                    plist[code].ToRecordset(rec, false);
                                }
                            }
                        }
                        foreach (var p in plist.Values)
                        {
                            if (!dic.Contains(p.Code))
                            {
                                p.ToRecordset(rec, true);
                            }
                        }
                    }
                    db.Execute("DELETE Cells.* FROM Projects INNER JOIN (CalcParams INNER JOIN Cells ON CalcParams.ParamId = Cells.ParamId) ON Projects.Project = CalcParams.Project WHERE Projects.SysField='Del';");
                    db.Execute("DELETE CalcParams.* FROM Projects INNER JOIN CalcParams ON Projects.Project = CalcParams.Project WHERE Projects.SysField='Del';");
                    db.Execute("DELETE * FROM Projects WHERE Projects.SysField='Del'");
                }
            }
            catch (Exception ex)
            {
                AddError("Ошибка при работе с ReporterData, архивом или файлом данных отчета", ex);
            }
            return(plist.Values);
        }