//Добавить ошибку в список public void AddError(string errMess, string lexeme, int line, int pos, IToken token = null) { if (!Errors.ContainsKey(FieldName)) { Errors.Add(FieldName, new ParsingError(FieldName, errMess, lexeme, line, pos, token)); } }
public void Complex() { var dic = new DicS <int>(1000); dic.Clear(); Assert.AreEqual(0, dic.Count); dic.Add("First", 1); dic.Add("Second", 2); Assert.AreEqual(2, dic.Count); Assert.AreEqual(1, dic["first"]); Assert.AreEqual(1, dic.Get("FIRST")); Assert.AreEqual(2, dic["Second"]); var dicAdd = new DicS <int>(); dicAdd.Add("second", 22); dicAdd.Add("third", 33); dic.AddDic(dicAdd); Assert.AreEqual(3, dic.Count); Assert.IsTrue(dic.ContainsKey("THIRD")); Assert.IsTrue(dic.ContainsKey("Second")); Assert.AreEqual(56, dic.Values.Sum()); dic.AddDic(dicAdd); Assert.AreEqual(3, dic.Count); Assert.AreEqual(1, dic["first"]); Assert.AreEqual(22, dic["second"]); Assert.AreEqual(33, dic["third"]); dic.Remove((k, v) => v == 33 || k.ToLower() == "second"); Assert.AreEqual(1, dic.Count); Assert.IsTrue(dic.ContainsKey("First")); Assert.IsFalse(dic.ContainsKey("Second")); }
//Добавить выход в провайдер protected override ProviderOut AddOut(ProviderSignal sig) { string ocode = sig.Inf.Get("Name_Object") + "." + sig.Inf.Get("Name_Device") + "." + sig.Inf.Get("Name_Type"); return(!Outs.ContainsKey(ocode) ? Outs.Add(ocode, new MirOut(this)) : Outs[ocode]); }
//Запись значений по параметру и подпараметрам в линейную ведомость, columns - список колонок таблицы LinVed public void ToLinVed(RecDao rec, DicS <VedColumn> columns) { if (_param.RunParam.CalcValue == null || _param.RunParam.CalcValue.SingleValue == null) { return; } var par = _param.RunParam.CalcValue.SingleValue.ToMomList(); var subs = new List <VedMomList>(); foreach (var col in columns.Values) { if (SubParams.ContainsKey(col.Code)) { subs.Add(new VedMomList(col.Code, SubParams[col.Code])); } } foreach (var mom in par) { rec.AddNew(); rec.Put("IdParam", _id); rec.Put("TimeValue", mom.Time); rec.Put("TimeString", mom.Time.ToStringWithMs()); if (mom.DataType.LessOrEquals(DataType.Real)) { if (columns.ContainsKey("ValueReal")) { rec.Put("ValueReal", mom.Real); } } else if (columns.ContainsKey("ValueString")) { rec.Put("ValueString", mom.String); } if (rec.ContainsField("Nd")) { rec.Put("Nd", mom.Nd); } if (rec.ContainsField("ErrorString")) { rec.Put("ErrorString", mom.Error.Text); } foreach (var sub in subs) { WriteValue(sub.ChangeMoment(mom.Time), rec, sub.Code); } //foreach (var col in _vedSaver.ColumnsParams.Values) // if (col.LinVedView != VedView.None) // WriteProp(col, rec); rec.Update(); } }
//Подготовка провайдера 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"); }
//Добавить сигнал в источник public ProviderSignal AddSignal(string signalInf, string code, DataType dataType, int idInClone = 0) { var sig = new ProviderSignal(signalInf, code, dataType, this, idInClone); ProviderSignals.Add(code, sig); string tableName = sig.Inf["TableName"]; int nodeId = sig.Inf.GetInt("NodeId"); string prop = sig.Inf["Prop"]; if (prop.IsEmpty()) { if (!_objects.ContainsKey(tableName)) { _objects.Add(tableName, new DicI <ObjectProlog>()); } var ob = _objects[tableName].Add(nodeId, new ObjectProlog(tableName, nodeId, prop)); _objectsId.Add(nodeId, ob); return(ob.AddSignal(sig)); } if (!_totals.ContainsKey(tableName)) { _totals.Add(tableName, new DicI <ObjectProlog>()); } var obt = _totals[tableName].Add(nodeId, new ObjectProlog(tableName, nodeId, prop)); _totalsId.Add(nodeId, obt); return(obt.AddSignal(sig)); }
//Добавить модуль public void AddModule(string code) { if (!_modules.ContainsKey(code)) { var smod = Project.SchemeModules[code]; var mod = new TablikModule(this, code, smod.Name, smod.Description); _modules.Add(code, mod); foreach (var m in smod.LinkedModules.Values) { AddModule(m); mod.LinkedModules.Add(_modules[m]); } foreach (var c in smod.LinkedConnects.Values) { if (Project.SchemeSources.ContainsKey(c)) { mod.LinkedSources.Add(Sources[c]); } if (Project.SchemeReceivers.ContainsKey(c)) { mod.LinkedReceivers.Add(Receivers[c]); } } } }
public void Simple() { var dic = new DicS <string>(); Assert.AreEqual(0, dic.Count); dic.Add("a", "sa"); dic.Add("B", "sB"); Assert.IsTrue(dic.ContainsKey("a")); Assert.IsTrue(dic.ContainsKey("b")); Assert.AreEqual("sa", dic["a"]); Assert.AreEqual("sB", dic["B"]); Assert.AreEqual("sa", dic.Get("A")); Assert.AreEqual("sB", dic.Get("b", "h")); Assert.IsNull(dic["c"]); Assert.AreEqual("h", dic.Get("c", "h")); Assert.AreEqual(2, dic.Count); dic.Add("b", "gghsdauh"); Assert.AreEqual(2, dic.Count); Assert.AreEqual("sB", dic["B"]); dic["b"] = "gg"; Assert.AreEqual(2, dic.Count); Assert.AreEqual("gg", dic["B"]); dic.Add("c", "SC"); Assert.IsTrue(dic.ContainsKey("C")); Assert.AreEqual(3, dic.Count); dic.Add("b", "ssb", true); Assert.IsTrue(dic.ContainsKey("b")); Assert.IsTrue(dic.ContainsKey("c")); Assert.AreEqual("ssb", dic["b"]); Assert.IsTrue(dic.Keys.Contains("B")); Assert.IsTrue(dic.Values.Contains("ssb")); dic.Remove("C"); Assert.AreEqual(2, dic.Count); Assert.IsFalse(dic.ContainsKey("c")); Assert.IsNull(dic["c"]); Assert.AreEqual("def", dic.Get("C", "def")); Assert.IsFalse(dic.Remove("C")); Assert.IsFalse(dic.ContainsKey("c")); Assert.AreEqual("def", dic.Get("C", "def")); Assert.IsFalse(dic.ContainsKey(null)); dic.Clear(); Assert.AreEqual(0, dic.Count); Assert.IsNull(dic["a"]); Assert.IsFalse(dic.ContainsKey("c")); Assert.IsFalse(dic.ContainsKey("a")); }
//Проверка настроек protected override string CheckSettings(DicS <string> inf) { if (!inf.ContainsKey("SQLServer")) { return("Не указано имя архивного сервера"); } return(""); }
//Чтение значений из таблиц, usedSignals - набор кодов используемых сигналов public void PrepareSignals(DicS <DataType> usedSignals) { if (!IsConnected && !Check()) { return; } Logger.AddEvent("Чтение списка имитируемых сигналов"); _signals.Clear(); _signalsId.Clear(); try { using (var rec = new ReaderAdo(ImitDataFile, "SELECT * FROM SignalsBehavior WHERE ImitFlag=True ORDER BY ImitId")) while (rec.Read()) { var sig = new ImitSignal(rec, this); if (usedSignals.ContainsKey(sig.Code)) { sig.SetDataType(usedSignals[sig.Code]); _signals.Add(sig.Code, sig); _signalsId.Add(sig.ImitId, sig); } } } catch (Exception ex) { Logger.AddError("Ошибка чтения списков имитированных сигналов", ex); } Logger.AddEvent("Чтение списка имитируемых значений, " + _signalsId.Count + " сигналов"); try { using (var rec = new ReaderAdo(ImitDataFile, "SELECT SignalsValues.ImitId AS ImitId, SignalsValues.Time, SignalsValues.RelativeTime, SignalsValues.Value, SignalsValues.Nd FROM SignalsValues INNER JOIN SignalsBehavior ON SignalsBehavior.ImitId = SignalsValues.ImitId " + "WHERE SignalsBehavior.ImitFlag=True ORDER BY SignalsValues.ImitId, SignalsValues.RelativeTime")) { rec.Read(); while (!rec.EOF) { int id = rec.GetInt("ImitId"); if (_signalsId.ContainsKey(id)) { _signalsId[id].ReadMoments(rec); } else { while (!rec.EOF && rec.GetInt("ImitId") == id) { rec.Read(); } } } } } catch (Exception ex) { Logger.AddError("Ошибка чтения списков имитируемых значений", ex); } }
//Добавить сигнал public SourceSignal AddSignal(string fullCode, //Полный код сигнала DataType dataType, //Тип данных SignalType signalType, //Тип сигнала string infObject, //Свойства объекта string infOut = "", //Свойства выхода относительно объекта string infProp = "") //Свойства сигнала относительно выхода { if (_readingSignals.ContainsKey(fullCode)) { return(_readingSignals[fullCode]); } if (Provider != null) { Provider.IsPrepared = false; } var contextOut = infObject + (infOut.IsEmpty() ? "" : ";" + infOut); var inf = infObject.ToPropertyDicS().AddDic(infOut.ToPropertyDicS()).AddDic(infProp.ToPropertyDicS()); SourceSignal sig = null; switch (signalType) { case SignalType.Mom: sig = _initialSignals.Add(fullCode, new MomSignal(this, fullCode, dataType, contextOut, inf)); break; case SignalType.Uniform: sig = _initialSignals.Add(fullCode, new UniformSignal(this, fullCode, dataType, contextOut, inf)); break; case SignalType.List: sig = _initialSignals.Add(fullCode, new ListSignal(this, fullCode, dataType, contextOut, inf)); break; case SignalType.Clone: sig = _initialSignals.Add(fullCode, new CloneSignal((ClonerConnect)this, fullCode, dataType, contextOut, inf)); break; case SignalType.UniformClone: sig = _initialSignals.Add(fullCode, new UniformCloneSignal((ClonerConnect)this, fullCode, dataType, contextOut, inf)); break; } return(_readingSignals.Add(fullCode, sig)); }
//Удалить сигнал public void RemoveSignal(string fullCode) { if (Provider != null) { Provider.IsPrepared = false; } if (_receiverSignals.ContainsKey(fullCode)) { _receiverSignals.Remove(fullCode); } }
//Добавление объекта protected override ProviderOut AddOut(ProviderSignal sig) { var table = sig.Inf.Get("Table"); bool isErr = sig.Inf.Get("IsErrorObject") == "True"; var code = sig.Inf.Get("ObjectCode"); switch (table) { case "MomValues": return(Outs.ContainsKey(code) ? Outs[code] : Outs.Add(code, new FictiveOut(this, isErr))); case "MomValues2": return(Outs2.ContainsKey(code) ? Outs2[code] : Outs2.Add(code, new FictiveSmallOut(this))); case "MomOperator": return(OperatorOut ?? (OperatorOut = new FictiveOperatorOut(this))); } return(null); }
//Чтение списка параметров private void ReadParams() { try { foreach (var par in _project.ArchiveParams.Values) { if (_allTasks || par.FirstParam.Task == _task) { var fcode = par.ArchiveParam.FullCode; if (!fcode.Contains(".")) { if (!_params.ContainsKey(fcode)) { _params.Add(fcode, new VedParam(par, this)); } } else { string code = fcode.Substring(0, fcode.LastIndexOf('.')); if (!_params.ContainsKey(code) && _project.ArchiveParams.ContainsKey(code)) { _params.Add(code, new VedParam(_project.ArchiveParams[code], this)); } var cv = par.RunParam.CalcValue; if (cv != null && cv.SingleValue != null && _params.ContainsKey(code)) { _params[code].SubParams.Add(par.LastParam.Code, cv.SingleValue); } } } } } catch (Exception ex) { AddError("Ошибка загрузки списка параметров", ex, "", _project.Code); } }
//Добавляет объект в ErrorsObjects protected void AddErrorOut(string codeObject, //Код сигнала string errText, //Сообщение об ошибке Exception ex = null) //Исключение { if (!_errorOuts.ContainsKey(codeObject)) { var err = errText + (ex == null ? "" : ". " + ex.Message + ". " + ex.StackTrace); _errorOuts.Add(codeObject, err); if (ProviderConnect is ClonerConnect) { var rec = ((ClonerConnect)ProviderConnect).CloneErrorsRec; rec.AddNew(); rec.Put("OutContext", codeObject); rec.Put("ErrorDescription", err); rec.Update(); } } }
//Добавить выход в источник protected override ProviderOut AddOut(ProviderSignal sig) { int id = sig.Inf.GetInt("NodeId"); if (OutsId.ContainsKey(id)) { return(OutsId[id]); } string tableName = sig.Inf["TableName"]; if (!Outs.ContainsKey(tableName)) { Outs.Add(tableName, new DicI <LogikaOut>()); } var ob = new LogikaOut(this); Outs[tableName].Add(id, ob); return(OutsId.Add(id, ob)); }
//Добавить расчетный сигнал public CalcSignal AddCalcSignal(string fullCode, //Полный код сигнала string objectCode, //Код объекта string initialCode, //Код исходного сигнала без кода объекта string formula) //Формула { if (CalcSignals.ContainsKey(fullCode)) { return(CalcSignals[fullCode]); } string icode = objectCode + "." + initialCode; if (!_initialSignals.ContainsKey(icode)) { throw new InstanceNotFoundException("Не найден исходный сигнал " + icode); } Provider.IsPrepared = false; var calc = new CalcSignal(fullCode, _initialSignals[icode], formula); _readingSignals.Add(fullCode, calc); return(CalcSignals.Add(fullCode, calc)); }
//Отметка в клоне считывемых сигналов, получение Id сигналов protected override void PrepareProvider() { AddEvent("Отметка в клоне считывемых сигналов"); using (var rec = new DaoRec(CloneFile, "SELECT SignalId, FullCode, OtmReadClone FROM Signals")) while (rec.Read()) { string code = rec.GetString("FullCode"); var id = rec.GetInt("SignalId"); if (Objects.ContainsKey(code)) { rec.Put("OtmReadClone", true); var ob = Objects[code]; ObjectsId.Add(id, ob); ObjectsList.Add(ob); } else { rec.Put("OtmReadClone", false); } } }
//Добавить сигнал public ProviderSignal AddSignal(string signalInf, string code, DataType dataType, int idInClone = 0) { var dic = signalInf.ToPropertyDicS(); var proj = dic["Project"]; var ocode = dic["CodeObject"]; var itype = dic["IntervalType"].ToIntervalType(); var sp = dic["SuperProcessType"].ToSuperProcess(); if (!_intervalTypes.Contains(itype)) { _intervalTypes.Add(itype); } if (!_signalsDic.ContainsKey(proj)) { _signalsDic.Add(proj, new DicS <Dictionary <IntervalType, ProviderSignal> >()); _reportParams.Add(proj, new DicS <ArchiveReportParam>()); } var projdic = _signalsDic[proj]; var repdic = _reportParams[proj]; if (!projdic.ContainsKey(ocode)) { projdic.Add(ocode, new Dictionary <IntervalType, ProviderSignal>()); repdic.Add(ocode, new ArchiveReportParam(ocode, proj, dataType, sp, CalcParamType.Class, new List <IntervalType>())); } if (projdic[ocode].ContainsKey(itype)) { return(projdic[ocode][itype]); } var sig = new ProviderSignal(signalInf, code, dataType, this, idInClone) { Value = new SingleValue(SingleType.List) }; projdic[ocode].Add(itype, sig); ProviderSignals.Add(code, sig); repdic[ocode].Queries.Add(itype, new ArchiveQueryValues()); return(sig); }
public bool Contains(string name) { return(_fieldsDic.ContainsKey(name)); }
//Доступ к значению по имени поля public Mean this[string name] { get { return(_means.ContainsKey(name) ? _means[name] : null); } }
private void ParseSubExpr(DicS <TablikCalcParam> pars, string code, string subCode, string result) { Assert.IsTrue(pars.ContainsKey(code)); Assert.IsTrue(pars[code].Params.ContainsKey(subCode)); Assert.AreEqual("NodeList: (" + result + ")", pars[code].Params[subCode].Expr1.ToTestString()); }
//Запись значений ручного ввода, 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); } } }
//Проверка таблицы сигналов public string CheckSignals(bool onlyInUse = false) { StartAtom(Atom.CheckSignals); CountsToZero(); var objectsId = new DicI <ObjectSignal>(); var signals = new DicS <Signal>(); _objects.Clear(); try { if (State == State.Closed) { AddError("Копилятор уже был закрыт"); } else if (State == State.Empty) { AddError("Проект не загружен"); } else { //using (var reco = new RecDao(_projectFile, "SELECT CodeObject, NameObject, TagObject, ObjectId, CommName, ErrMess FROM Objects ORDER BY ObjectId")) using (var reco = new RecDao(_objectsFile, "SELECT CodeObject, NameObject, TagObject, ObjectId, CommName, ErrMess FROM Objects ORDER BY ObjectId")) //ab\ { Procent = 10; while (reco.Read()) { var ob = new ObjectSignal(reco, true); objectsId.Add(ob.Id, ob); if (!_objects.ContainsKey(ob.Code)) { _objects.Add(ob.Code, ob); } else { ob.ErrMess += "Повтор кода объекта (" + ob.Code + "); "; reco.Put("ErrMess", ob.ErrMess); _objects[ob.Code].ErrMess += "Повтор кода объекта (" + ob.Code + "); "; } } Procent = 25; using (var recs = new RecDao(reco.DaoDb, "SELECT ObjectId, Signals.Default, CodeSignal, NameSignal, Units, Signals.DataType, ConstValue, Signals.SourceName, Signals.ReceiverName, Signals.Inf, Signals.FullCode AS FullCode, Signals.ErrMess" + (!onlyInUse ? "" : ", SignalsInUse.FullCode AS FullCodeInUse") + " FROM Signals" + (!onlyInUse ? "" : " LEFT JOIN SignalsInUse ON Signals.FullCode=SignalsInUse.FullCode "))) { Procent = 35; while (recs.Read()) { var sig = new Signal(recs, objectsId, true); if (onlyInUse) { sig.InUse = !recs.GetString("FullCodeInUse").IsEmpty(); } objectsId[sig.ObjectId].InUse |= sig.InUse; if (signals.ContainsKey(sig.FullCode)) { sig.ErrMess += "Повтор полного кода сигнала (" + sig.FullCode + "); "; } else { signals.Add(sig.FullCode, sig); } if (sig.ErrMess != "") { recs.Put("ErrMess", sig.ErrMess, true); if (sig.InUse || !onlyInUse) { SignalsErrorsCount++; } objectsId[sig.ObjectId].ErrorInSignals = true; } } } Procent = 80; reco.MoveFirst(); while (!reco.EOF) { var ob = objectsId[reco.GetInt("ObjectId")]; if (ob.DefalutsCount == 0) { ob.ErrMess += "Объект не содержит сигналов по умолчанию; "; } if (ob.DefalutsCount >= 2) { ob.ErrMess += "Объект содержит более одного сигнала по умолчанию; "; } if (ob.ErrorInSignals) { ob.ErrMess += "Ошибки в сигналах; "; } if (ob.ErrMess != "") { reco.Put("ErrMess", ob.ErrMess); if (!onlyInUse || ob.InUse) { ObjectsErrorsCount++; } } reco.MoveNext(); } } } } catch (Exception ex) { return(ex.MessageError("Ошибка при проверке сигналов")); } return(FinishAtom(State.Project, State.Project, "Проект: " + _code + "; Объектов с ошибками: " + ObjectsErrorsCount + "; Сигналов с ошибками: " + SignalsErrorsCount)); }
//Загружает список провайдеров в соответствии со списком проектов, ControllerData и уже загруженным списком провайдеров private void UpdateProvidersList() { if (!_setupIsLoaded) { return; } foreach (DataGridViewRow row in Providers.Rows) { string name = row.Get("ProviderName"); _codes.Add(name, row.Get("ProviderCode"), true); _infs.Add(name, row.Get("ProviderInf"), true); } Providers.Rows.Clear(); ProjectCode2.Visible = AllowProjectsRepetitions.Checked; if (AllowProjectsRepetitions.Checked) { UseOneArchive.Checked = false; UseOneArchive.Visible = false; } else { UseOneArchive.Visible = true; } AddProviderToGrid("Архив", "Report_Archive", "Архив журнала отчетов", _codes.Get("Report_Archive", "AccessArchive"), _infs["Report_Archive"]); bool hasSingle = false; foreach (DataGridViewRow row in Projects.Rows) { hasSingle |= !row.IsNewRow && row.Get("ProjectCalcMode").ToCalcModeType() == CalcModeType.Internal; } labelThreadId.Visible = hasSingle; ThreadId.Visible = hasSingle; IsImit.Visible = hasSingle; ImitMode.Visible = hasSingle; ImitMode.Enabled = IsImit.Checked; var set = new HashSet <string>(); foreach (DataGridViewRow row in Projects.Rows) { if (!row.IsNewRow) { string proj = row.Get("Project"); if (AllowProjectsRepetitions.Checked && !row.Get("ProjectCode2").IsEmpty()) { proj = row.Get("ProjectCode2"); } string name = proj + "_Archive"; if (row.Get("ProjectCalcMode").ToCalcModeType() != CalcModeType.Internal) { if (!UseOneArchive.Checked) { AddProviderToGrid("Архив", name, "Архив проекта " + proj, _codes.Get(name, "AccessArchive"), _infs[name]); } } else { try { var projFile = row.Get("ProjectFile"); if (new FileInfo(projFile).Exists) { using (var rec = new ReaderAdo(projFile, "SELECT * FROM Providers")) while (rec.Read()) { string type = rec.GetString("ProviderType"); var sname = type == "Архив" ? "CalcArchive" : rec.GetString("ProviderName"); if (!set.Contains(sname) && (type == "Источник" || type == "Приемник" || (type == "Архив" && !UseOneArchive.Checked) || (type == "Имитатор" && IsImit.Checked))) { if (_codes.ContainsKey(sname)) { AddProviderToGrid(type, sname, type + " потока отчета", _codes[sname], _infs[sname]); } else { AddProviderToGrid(type, sname, type + " потока отчета", rec.GetString("ProviderCode"), ""); } set.Add(sname); } } } } catch { } } } } }
//Обновление списка проектов в файле данных отчета 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); }
//Получает в память список актуальный список параметров из файла данных, проекта и архива и обновляет список параметров в файле данных //Возвращает 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); }