Esempio n. 1
0
 //Создание провайдера архива
 protected void LoadArchive(IRecordRead rec, Logger logger)
 {
     try
     {
         if (!rec.GetString("CodeArchive").IsEmpty() && !rec.GetString("InfArchive").IsEmpty())
         {
             Archive = (IArchive)General.RunProvider(rec.GetString("CodeArchive"), CodeFinal + "_Archive", rec.GetString("InfArchive"), logger, ProviderSetupType.ReporterArchive);
         }
         if (Archive == null || !Archive.Check())
         {
             if (this is ReportProject)
             {
                 Book.AddError("Не удалось соединиться с архивом. Следует проверить настройки", null, CodeFinal + "_Archive");
             }
             Archive.Dispose();
             Archive = null;
         }
     }
     catch (Exception ex)
     {
         if (this is ReportProject)
         {
             Book.AddError("Не удалось соединиться с архивом. Следует проверить настройки", ex, CodeFinal + "_Archive");
         }
         Archive = null;
     }
 }
Esempio n. 2
0
 //Подготовка архивного отчета для чтения значений
 public void PrepareArchiveReport()
 {
     if (_archiveReport == null)
     {
         Book.AddEvent("Подготовка архивного отчета", CodeFinal);
         try
         {
             _archiveReport = new ArchiveReport(CodeFinal + "_" + Book.FullThreadName, Name, ReportType.Excel, Book.LastChangeLinks);
             if (!IsSave && !IsSystem)
             {
                 foreach (var param in Params.Values)
                 {
                     if (param.IntervalTypes.Count > 0)
                     {
                         var ap  = param.ArchiveParam;
                         var arp = new ArchiveReportParam(param.FullCode, Code, ap.DataType, ap.SuperProcess, ap.FirstParam.CalcParamType, param.IntervalTypes);
                         _archiveReport.AddParam(arp);
                         foreach (var cell in param.Cells)
                         {
                             if (arp.Queries.ContainsKey(cell.IntervalType))
                             {
                                 cell.ArchiveQueryValues = arp.Queries[cell.IntervalType];
                             }
                         }
                         foreach (var shape in param.Shapes)
                         {
                             if (arp.Queries.ContainsKey(shape.IntervalType))
                             {
                                 shape.ArchiveQueryValues = arp.Queries[shape.IntervalType];
                             }
                         }
                         foreach (var t in param.IntervalTypes)
                         {
                             if (t != IntervalType.Empty && !_intervalTypes.Contains(t))
                             {
                                 _intervalTypes.Add(t);
                             }
                         }
                     }
                 }
             }
             using (Book.Start(30))
                 Archive.PrepareReport(_archiveReport);
         }
         catch (Exception ex)
         {
             Book.AddError("Ошибка подготовки архивного расчета", ex);
         }
     }
 }
Esempio n. 3
0
 //Чтение значений из архива
 public void ReadArchiveReport(DateTime begin, DateTime end, string calcName)
 {
     try
     {
         _archiveReport.IntervalsForRead.Clear();
         foreach (var t in _intervalTypes)
         {
             _archiveReport.IntervalsForRead.Add(new ArchiveInterval(t, begin, end, calcName));
         }
         Archive.ReadReport(_archiveReport);
     }
     catch (Exception ex)
     {
         Book.AddError("Ошибка при чтении из архива", ex, CodeFinal);
     }
 }
Esempio n. 4
0
        //Получает в память список актуальный список параметров из файла данных, проекта и архива и обновляет список параметров в файле данных
        //Возвращает true, если параметры были обновлены
        public bool UpdateParams()
        {
            if (DataChangeTime >= ProjectChangeTime && DataChangeTime >= ArchiveChangeTime)
            {
                return(false);
            }
            var dataParams    = new DicS <ArchiveParam>();
            var projectParams = new DicS <ArchiveParam>();
            var archiveParams = new DicS <ArchiveParam>();

            try
            {
                if (!File.IsEmpty())
                {
                    Book.AddEvent("Получение списка параметров из проекта", CodeFinal);
                    const string stSql = "SELECT CalcParamsArchive.FullCode As Code, CalcParams.Code AS CodeParam, CalcSubParams.Code AS CodeSubParam, CalcParams.Name, CalcSubParams.Name AS SubName, " +
                                         "CalcParamsArchive.DataType, CalcParams.CalcParamType, CalcParamsArchive.SuperProcessType, CalcParams.Comment, CalcSubParams.Comment AS SubComment, " +
                                         "CalcParamsArchive.Units, CalcParams.Task, CalcParamsArchive.Min, CalcParamsArchive.Max, CalcParamsArchive.DecPlaces, CalcParams.Tag " +
                                         "FROM CalcParams INNER JOIN (CalcSubParams RIGHT JOIN CalcParamsArchive ON CalcSubParams.CalcParamId = CalcParamsArchive.CalcSubParamId) ON CalcParams.CalcParamId = CalcParamsArchive.CalcParamId;";
                    using (var rec = new ReaderAdo(File, stSql))
                        while (rec.Read())
                        {
                            var ap = new ArchiveParam(rec);
                            projectParams.Add(ap.FullCode, ap);
                        }

                    if (CalcMode == CalcModeType.Internal)
                    {
                        Book.AddEvent("Получение параметров ручного ввода из проекта", CodeFinal);
                        using (var rec = new ReaderAdo(File, "SELECT CalcParams.Code, CalcParams.Code AS CodeParam, CalcParams.Name, CalcParams.ResultType AS DataType, CalcParams.Units, CalcParams.Task, CalcParams.CalcParamType, CalcParams.Comment, CalcParams.SuperProcessType, CalcParams.Min, CalcParams.Max, CalcParams.DecPlaces, CalcParams.Tag " +
                                                       "FROM CalcParams WHERE CalcParamType Is Not Null"))
                            while (rec.Read())
                            {
                                var ap = new ArchiveParam(rec);
                                projectParams.Add(ap.FullCode, ap);
                            }
                    }
                }
                if (Archive != null && CalcMode != CalcModeType.Internal)
                {
                    Book.AddEvent("Получение списка параметров из архива", CodeFinal);
                    foreach (var ap in Archive.ReadParams(Code, ReportType.Calc))
                    {
                        archiveParams.Add(ap.FullCode, ap);
                    }
                }

                var dic1 = ProjectChangeTime >= ArchiveChangeTime ? projectParams : archiveParams;
                var dic2 = ProjectChangeTime < ArchiveChangeTime ? projectParams : archiveParams;

                Book.AddEvent("Обновление параметров в файле данных", CodeFinal);
                using (var rec = new RecDao(Book.DataFile, "SELECT * FROM CalcParams WHERE Project='" + CodeFinal + "'"))
                {
                    while (rec.Read())
                    {
                        var ap = new ArchiveParam(rec);
                        dataParams.Add(ap.FullCode, ap);
                        if (!dic1.ContainsKey(ap.FullCode) && !dic2.ContainsKey(ap.FullCode))
                        {
                            rec.Put("SysField", "Del");
                        }
                        else
                        {
                            rec.Put("SysField", "");
                            if (dic1.ContainsKey(ap.FullCode))
                            {
                                dic1[ap.FullCode].ToRecordset(rec, CodeFinal);
                            }
                            else
                            {
                                dic2[ap.FullCode].ToRecordset(rec, CodeFinal);
                            }
                            rec.Put("FromProject", projectParams.ContainsKey(ap.FullCode));
                            rec.Put("FromArchive", archiveParams.ContainsKey(ap.FullCode));
                        }
                    }

                    Book.AddEvent("Добавление недостающих параметров в файл данных", CodeFinal);
                    foreach (var ap in dic1.Values)
                    {
                        if (!dataParams.ContainsKey(ap.FullCode))
                        {
                            dataParams.Add(ap.FullCode, ap);
                            ap.ToRecordset(rec, CodeFinal, true);
                            rec.Put("FromProject", projectParams.ContainsKey(ap.FullCode));
                            rec.Put("FromArchive", archiveParams.ContainsKey(ap.FullCode));
                        }
                    }
                    foreach (var ap in dic2.Values)
                    {
                        if (!dataParams.ContainsKey(ap.FullCode))
                        {
                            ap.ToRecordset(rec, CodeFinal, true);
                            rec.Put("FromProject", projectParams.ContainsKey(ap.FullCode));
                            rec.Put("FromArchive", archiveParams.ContainsKey(ap.FullCode));
                        }
                    }

                    using (var rep = new RecDao(rec.DaoDb, "SELECT LastChange FROM Projects WHERE (ProjectCode2='" + CodeFinal + "') OR (ProjectCode2 Is Null AND Project = '" + CodeFinal + "')"))
                        rep.Put("LastChange", ProjectChangeTime >= ArchiveChangeTime ? ProjectChangeTime : ArchiveChangeTime);
                }
            }
            catch (Exception ex)
            {
                Book.AddError("Ошибка при обновлении спиcка параметров", ex, CodeFinal);
            }
            return(true);
        }
Esempio n. 5
0
 //Запись значений ручного ввода, beg - начало периода расчета
 public void WriteHandInput(DateTime beg, DateTime en)
 {
     if (IsHandInput)
     {
         try
         {
             Book.AddEvent("Сохрание значений ручного ввода из ячеек", CodeFinal);
             var pars = new DicS <ReportHandParam>();
             foreach (var param in Params.Values)
             {
                 if (param.HandInputCell != null)
                 {
                     pars.Add(param.FullCode,
                              new ReportHandParam(param, GeneralRep.ActiveBook.ValueFromCell(param.HandInputCell)));
                 }
             }
             using (var db = new DaoDb(_handInputFile))
             {
                 using (
                     var rec = new RecDao(db,
                                          "SELECT Objects.CodeObject, MomentsValues.Time FROM (Objects INNER JOIN Signals ON Objects.ObjectId = Signals.ObjectId) INNER JOIN MomentsValues ON Signals.SignalId = MomentsValues.SignalId " +
                                          "WHERE (Time >= " + beg.ToAccessString() + ") AND (Time < " + en.ToAccessString() + ")"))
                     while (rec.Read())
                     {
                         if (pars.ContainsKey(rec.GetString("CodeObject")))
                         {
                             rec.Put("Time", Different.MaxDate);
                         }
                     }
                 using (
                     var rec = new RecDao(db,
                                          "SELECT Objects.CodeObject, MomentsStrValues.Time FROM (Objects INNER JOIN Signals ON Objects.ObjectId = Signals.ObjectId) INNER JOIN MomentsStrValues ON Signals.SignalId = MomentsStrValues.SignalId " +
                                          "WHERE (Time >= " + beg.ToAccessString() + ") AND (Time < " + en.ToAccessString() + ")"))
                     while (rec.Read())
                     {
                         if (pars.ContainsKey(rec.GetString("CodeObject")))
                         {
                             rec.Put("Time", Different.MaxDate);
                         }
                     }
                 db.Execute("DELETE * FROM MomentsValues WHERE Time=" + Different.MaxDate.ToAccessString());
                 db.Execute("DELETE * FROM MomentsStrValues WHERE Time=" + Different.MaxDate.ToAccessString());
                 using (
                     var rec = new RecDao(db,
                                          "SELECT Objects.CodeObject, Objects.ObjectId, Signals.CodeSignal, Signals.SignalId FROM Objects INNER JOIN Signals ON Objects.ObjectId = Signals.SignalId")
                     )
                     while (rec.Read())
                     {
                         var code = rec.GetString("CodeObject");
                         if (pars.ContainsKey(code))
                         {
                             pars[code].ObjectId = rec.GetInt("ObjectId");
                             pars[code].SignalId = rec.GetInt("SignalId");
                         }
                     }
                 using (var reco = new RecDao(db, "Objects"))
                     using (var recs = new RecDao(db, "Signals"))
                         foreach (var param in pars.Values)
                         {
                             if (param.ObjectId == 0)
                             {
                                 var ap  = param.ReportParam.ArchiveParam;
                                 var par = ap.FirstParam;
                                 reco.AddNew();
                                 reco.Put("CodeObject", par.Code);
                                 reco.Put("NameObject", par.Name);
                                 param.ObjectId = reco.GetInt("ObjectId");
                                 reco.Update();
                                 recs.AddNew();
                                 recs.Put("ObjectId", param.ObjectId);
                                 recs.Put("CodeSignal", "Руч");
                                 recs.Put("NameSignal", "Ручной ввод");
                                 recs.Put("FullCode", par.Code + ".Руч");
                                 recs.Put("Default", true);
                                 recs.Put("DataType", ap.DataType.ToRussian());
                                 recs.Put("Units", ap.Units);
                                 recs.Put("Min", ap.Min);
                                 recs.Put("Max", ap.Max);
                                 recs.Put("Active", true);
                                 param.SignalId = recs.GetInt("SignalId");
                                 recs.Update();
                             }
                         }
                 using (var rec = new RecDao(db, "MomentsValues"))
                     using (var recs = new RecDao(db, "MomentsStrValues"))
                         foreach (var param in pars.Values)
                         {
                             if (!param.StringValue.IsEmpty())
                             {
                                 var dt = param.ReportParam.ArchiveParam.DataType;
                                 var r  = dt.LessOrEquals(DataType.Real) ? rec : recs;
                                 r.AddNew();
                                 r.Put("SignalId", param.SignalId);
                                 r.Put("Time", beg);
                                 if (dt.LessOrEquals(DataType.Real))
                                 {
                                     var d = param.StringValue.ToDouble();
                                     if (!double.IsNaN(d))
                                     {
                                         r.Put("Value", d);
                                     }
                                     else
                                     {
                                         r.Put("Value", 0);
                                         r.Put("Nd", 1);
                                     }
                                 }
                                 else if (dt == DataType.String)
                                 {
                                     r.Put("StrValue", param.StringValue);
                                 }
                                 else if (dt == DataType.Time)
                                 {
                                     var t = param.StringValue.ToDateTime();
                                     r.Put("TimeValue", t);
                                     if (t == Different.MinDate)
                                     {
                                         r.Put("Nd", 1);
                                     }
                                 }
                             }
                         }
                 using (var sys = new SysTabl(db, false))
                 {
                     var d = sys.Value("BeginInterval").ToDateTime();
                     if (d == Different.MinDate || d > beg)
                     {
                         sys.PutValue("BeginInterval", beg.ToString());
                     }
                     d = sys.Value("EndInterval").ToDateTime();
                     if (d < beg)
                     {
                         sys.PutValue("EndInterval", beg.ToString());
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Book.AddError("Ошибка при записи ручного ввода", ex);
         }
     }
 }