//Проверка соответствия строки prop, фильтру filter, с отношением relation private bool CheckParamProperty(ReportParam param, LinkField field, Control relation, Control filter) { string prop = param.GetField(field); if (relation.Text == "Не пустое") { return(!prop.IsEmpty()); } if (relation.Text == "Пустое") { return(prop.IsEmpty()); } if (filter.Text.IsEmpty()) { return(true); } string p = (prop ?? "").ToLower(); string f = filter.Text.ToLower(); switch (relation.Text) { case "Равно": return(p == f); case "Не равно": return(p != f); case "Содержит": return(p.IndexOf(f) != -1); case "Не содержит": return(p.IndexOf(f) == -1); case "Начинается с": return(p.IndexOf(f) == 0); case "Кончается на": return(f.Length <= p.Length && p.LastIndexOf(f) == p.Length - f.Length); case "По шаблону": return(p.CheckFilter(f)); } return(true); }
//Загрузка параметров из файла данных в память (Projects) private void ParamsFileToMemory() { AddEvent("Загрузка параметров из файла данных в память"); try { Projects.Clear(); using (var db = new DaoDb(DataFile)) { using (var rec = new ReaderAdo(db, "SELECT * FROM Projects")) while (rec.Read()) { var proj = new ReportProjectForLinks(this, rec); Projects.Add(proj.CodeFinal, proj); } foreach (var pr in SysPage.GetProjects().Values) { if (Projects.ContainsKey(pr.CodeFinal)) { Projects[pr.CodeFinal].CalcMode = pr.CalcMode; } } using (var rec = new ReaderAdo(db, "SELECT * FROM CalcParams")) while (rec.Read()) { var par = new ReportParam(rec); if (Projects.ContainsKey(par.Project)) { Projects[par.Project].Params.Add(par.FullCode, par); } } } foreach (var proj in Projects.Values) { proj.MakeFilters(); } } catch (Exception ex) { AddError("Ошибка при загрузке параметров", ex); } }
//Проверяет, можно ли устанавливать ссылку типа ltype на параметр par private bool CanAddLinkType(ReportParam par, LinkType ltype) { if (CurProject.CalcMode == CalcModeType.Internal) { return(ltype == LinkType.MomentsList || ltype == LinkType.Result); } var sp = par.ArchiveParam.SuperProcess; if (sp.IsAbsolute()) { if (!sp.IsPeriodic()) { return(ltype == LinkType.Absolute || ltype == LinkType.AbsoluteEdit); } return(ltype == LinkType.Absolute || ltype == LinkType.AbsoluteEdit || ltype == LinkType.AbsoluteList || ltype == LinkType.AbsoluteCombined || ltype == LinkType.Combined || ltype == LinkType.CombinedList); } if (!sp.IsPeriodic()) { return(ltype == LinkType.MomentsList); } return(ltype == LinkType.Combined || ltype == LinkType.CombinedList); }
//Проверяет сответствие параметра papam фильтрам, forFind - используется для поиска, otm - параметр отмечен в списке public bool CheckParam(ReportParam param, bool forFind = false) { if (!IsFiltered && !forFind) { return(true); } bool b = CheckParamProperty(param, LinkField.Code, RelationFullCode, FilterFullCode); b &= CheckParamProperty(param, LinkField.CodeParam, RelationCode, FilterCode); b &= CheckParamProperty(param, LinkField.CodeSubParam, RelationSubCode, FilterSubCode); b &= CheckParamProperty(param, LinkField.Name, RelationName, FilterName); b &= CheckParamProperty(param, LinkField.Comment, RelationComment, FilterComment); b &= CheckParamProperty(param, LinkField.Task, RelationTask, FilterTask); b &= CheckParamProperty(param, LinkField.DataType, RelationDataType, FilterDataType); b &= CheckParamProperty(param, LinkField.Units, RelationUnits, FilterUnits); b &= CheckParamProperty(param, LinkField.SuperProcessType, RelationSuperProcess, FilterSuperProcess); b &= CheckParamProperty(param, LinkField.CalcParamType, RelationCalcParamType, FilterCalcParamType); if (RelationOtm.Text == "Равно" && (FilterOtm.Text == "Вкл" || FilterOtm.Text == "Откл")) { b &= (FilterOtm.Text == "Вкл" && param.Otm) || (FilterOtm.Text == "Откл" && !param.Otm); } return(b); }
//Добавляет ссылки по шаблону, rp - параметр по которому устанавливать ссылки, tlist - текущая транзакция public void AddLinksTemplate(ReportParam rp = null, Transaction tlist = null) { var trans = tlist ?? new Transaction(); try { if (!GeneralRep.CheckOneSheet(true)) { return; } var param = rp ?? CurParam; if (CurProject == null || param == null) { return; } if (tlist == null) { _book.BeforeTransaction(); } var page = (Worksheet)_book.Workbook.ActiveSheet; var acell = GeneralRep.Application.ActiveCell; foreach (var dic in _book.CurLinkTemplate) { var action = dic["CellAction"].ToCellAction(); string code = dic["CodeForming"];//Способ формирования кода или текст для записи, если action=Записать текст if (action != CellActionType.Text) { code = code.Replace("<Код параметра>", param.ArchiveParam.FirstParam.Code).Replace("<Полный код>", param.FullCode); int n1 = param.FullCode.IndexOf("."); if (n1 > 0) { int n2 = param.FullCode.IndexOf(".", n1 + 1); if (n2 > 0) { code = code.Replace("<Код 2 параметра>", param.FullCode.Substring(0, n2)); } } } int x = acell.Column, y = acell.Row; x += dic.GetInt("X"); y += dic.GetInt("Y"); var field = dic["Field"].ToLinkField(); var cell = (Range)page.Cells[y, x]; var dicl = dic.Keys.Where(prop => prop != "X" && prop != "Y" && prop != "CellAction" && prop != "CodeForming").ToDictionary(prop => prop, prop => dic[prop]); if (action == CellActionType.Save) { AddLinkSave(trans, cell); } if (action == CellActionType.Text) { trans.AddCell(new TransactionCell(page, x, y) { NewValue = code }); page.PutCellValue(y, x, code); } else if (!CurProject.Params.ContainsKey(code)) { trans.NotFound.Add(code); } else { var par = CurProject.Params[code]; if (action == CellActionType.Value) { string s = par.GetField(field); if (s != null) { trans.AddCell(new TransactionCell(page, x, y) { NewValue = s }); page.PutCellValue(y, x, s); } } else { dicl.Add("Project", CurProject.CodeFinal); dicl.Add("Code", par.FullCode); dicl.Add("CellComment", CellComment.Text ?? ""); dicl.Add("SaveCode", GetSaveCode()); if (field == LinkField.CodeSubParam || field == LinkField.SubName || field == LinkField.SubComment) { if (par.ArchiveParam.LastParam != null) { AddCellLink(dicl.ToPropertyString(), trans, cell); } } else if (field == LinkField.Min || field == LinkField.Max) { if (par.ArchiveParam.DataType == BaseLibrary.DataType.Real || par.ArchiveParam.DataType == BaseLibrary.DataType.Integer) { AddCellLink(dicl.ToPropertyString(), trans, cell); } } else if (!field.IsValueField() || CanAddLinkType(par, dicl["LinkType"].ToLinkType())) { AddCellLink(dicl.ToPropertyString(), trans, cell); } else { trans.NotFound.Add(code); } } } } ((Range)page.Cells[acell.Row + _book.CurTemplateShiftY, acell.Column + _book.CurTemplateShiftX]).Activate(); } catch (Exception ex) { GeneralRep.ShowError("Ошибка при установке ссылки по шаблону", ex); } if (tlist == null) { _book.AddTransaction(trans); } }
//Сохранение одной ссылки private void SaveLink(Comment c, Shape sh, RecDao rp, RecDao rc, RecDao rs, Worksheet sheet) { var dic = (sh == null ? c.Text() : sh.Title).ToPropertyDicS(); if (dic != null && dic.ContainsKey("Field") && dic.ContainsKey("Project") && dic.ContainsKey("Code")) { LinkType linkType = dic["LinkType"].ToLinkType(); var projcode = dic["Project"]; string parcode = dic["Code"]; if (Projects.ContainsKey(projcode)) { ReportProjectForLinks proj = Projects[projcode]; ReportParam param = null; if (proj.IsSave) { //Сохранение if (proj.Params.ContainsKey(parcode)) { param = proj.Params[parcode]; } else { rp.AddNew(); param = new ReportParam(projcode, new ArchiveParam(parcode, DataType.String, null, new CalcParamBase(parcode, dic["CellComment"]), new CalcParamBase(dic["Field"]))) { Id = rp.GetInt("ParamId") }; rp.Put("Project", projcode); rp.Put("Code", parcode); rp.Put("CodeParam", parcode); rp.Put("DataType", DataType.String.ToRussian()); rp.Put("IsUsed", true); rp.Put("IsHandInput", false); proj.Params.Add(parcode, param); rp.Update(); } } else if (proj.Params.ContainsKey(parcode)) { param = proj.Params[parcode]; if (linkType == LinkType.HandInput) { //Ручной ввод param.IsHandInput = true; proj.IsHandInput = true; } else { //Обычное получние данных param.IsUsed = true; proj.IsUsed = true; } } if (param != null) { var itype = IntervalType.Empty; if (proj.CalcMode == CalcModeType.Internal) { if (linkType == LinkType.Result || linkType == LinkType.MomentsList) { itype = IntervalType.Single; } } else { switch (linkType) { case LinkType.Combined: case LinkType.CombinedList: if (dic.ContainsKey("LengthMinute") || dic.ContainsKey("PartBeginMinute") || dic.ContainsKey("PartEndMinute")) { itype = IntervalType.Base; } else if (dic.ContainsKey("LengthHour") || dic.ContainsKey("PartBeginHour") || dic.ContainsKey("PartEndHour")) { itype = IntervalType.Hour; } else if (dic.ContainsKey("LengthDay") || dic.ContainsKey("PartByTime")) { itype = IntervalType.Day; } else { itype = IntervalType.Combined; } break; case LinkType.Absolute: case LinkType.AbsoluteEdit: itype = IntervalType.Absolute; break; case LinkType.AbsoluteCombined: itype = IntervalType.AbsoluteCombined; break; case LinkType.AbsoluteList: if (dic.ContainsKey("LengthMinute") && dic["LengthMinute"].ToInt() != 0) { itype = IntervalType.AbsoluteListBase; } else if (dic.ContainsKey("LengthHour") && dic["LengthHour"].ToInt() != 0) { itype = IntervalType.AbsoluteListHour; } else { itype = IntervalType.AbsoluteListDay; } break; case LinkType.MomentsList: case LinkType.Result: itype = IntervalType.Moments; break; } } if (!param.IntervalTypes.Contains(itype)) { param.IntervalTypes.Add(itype); } if (sh == null) { //Добавление в таблицу Cells rc.AddNew(); rc.Put("Page", sheet.Name); rc.Put("Y", ((Range)c.Parent).Row); rc.Put("X", ((Range)c.Parent).Column); rc.Put("LinkType", linkType.ToEnglish()); rc.Put("LinkField", dic["Field"]); if (dic.ContainsKey("AllowEdit")) { rc.Put("AllowEdit", dic["AllowEdit"] == "True"); } string prop = ""; foreach (var k in dic.Keys) { if (k != "LinkType" && k != "Field" && k != "Project" && k != "Code") { prop += k + "=" + dic[k] + ";"; } } rc.Put("Properties", prop); rc.Put("ParamId", param.Id); rc.Put("IntervalType", itype.ToRussian()); rc.Put("SaveCode", dic["SaveCode"]); rc.Update(); } else { //Добавление в таблицу Shapes rs.AddNew(); rs.Put("Page", sheet.Name); rs.Put("ShapeId", sh.ID); rs.Put("ShapeType", sh.Type.ToEnglish()); if (sh.Type == MsoShapeType.msoGroup) { rs.Put("Formula", sh.AlternativeText); } rs.Put("LinkType", linkType.ToEnglish()); rs.Put("LinkField", dic["Field"]); string prop = ""; foreach (var k in dic.Keys) { if (k != "LinkType" && k != "Field" && k != "Project" && k != "Code") { prop += k + "=" + dic[k] + ";"; } } rs.Put("Properties", prop); rs.Put("ParamId", param.Id); rs.Put("IntervalType", itype.ToRussian()); rs.Update(); } } } } }