Ejemplo n.º 1
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"));
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
        }