private void menuItemReportExport_Click(object sender, EventArgs e) { #if DEBUG && USE_TDISK var basePath = Path.Combine(@"T:\", Scenario.LastReportId.ToString()); #else var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Scenario.LastReportId.ToString()); #endif var reportFile = new FileInfo(basePath + ".doc"); //var calcFile = new FileInfo(basePath + ".c.html"); //var sourceDataFile = new FileInfo(basePath + ".s.html"); if (!reportFile.Exists) { MessageBox.Show(this, "Для того, чтобы выгрузить отчет, последний должен быть сперва сгенерирован", "Модуль выгрузки данных", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } var fullPath = ""; var ww = new WaitWindow(); try { ww.Show(this); Func<IBranch, ScenarioNodeType> nodeType = b => b.GetValue("nodeType") == null ? ScenarioNodeType.Default : (ScenarioNodeType) Enum.Parse(typeof (ScenarioNodeType), b.GetValue("nodeType").ContentString); var all = Scenario.Vault.GetBranchesRecursive().ToDictionary(b => b, nodeType); var forExport = all.Where(kvp => kvp.Value == ScenarioNodeType.ForExport).FirstOrDefault(); Application.DoEvents(); using (var repo = RepositoryEditor.Repository()) { var now = DateTime.Now; var name = String.Format("{0:00}.{1:00}.{2:0000} {3:00}{4:00}{5:00}", now.Day, now.Month, now.Year, now.Hour, now.Minute, now.Second); var root = repo.GetOrCreateBranch("Для выгрузки"); var receiver = root.GetOrCreateBranch(name); fullPath = receiver.VPath.Path; if (!TryCreateFileStreamForTempCopy(reportFile, x => receiver.CreateValue("Отчет.doc", x).SetTypeToken2("binary"))) return; if (forExport.Key != null) { var node = new ScenarioNode(forExport.Key); //#warning Review this: eval sessions now lock the vault for reading #if VAULT_EVAL_1 using (_evalSession1 = new Esath.Eval.Ver1.EvalSession(Scenario.Vault, repo)) { #endif #if VAULT_EVAL_2 using (_evalSession2 = new Esath.Eval.Ver2.EvalSession(Scenario.Vault, repo, null)) { #endif #if VAULT_EVAL_3 using (_evalSession3 = new Esath.Eval.Ver3.EvalSession(Scenario.VaultCompiler, repo)) { #endif var source = Regex.Replace(node.Template, StartUp.VFIELD_PATTERN, vpathEvaluator, RegexOptions.Compiled); source = "<html><head></head><body>" + source + "</body></html>"; receiver.CreateValue("Расчетные Данные.html", new TempHtmlFile(source).Content).SetTypeToken2("binary"); } } var buf = new StringBuilder(32*1024); buf.Append("<html><head></head><body>"); buf.Append("<table border=1>"); buf.Append("<tr><th>Имя</th><th>Значение</th><th>Ед Изм</th><th>Тип</th></tr>"); foreach (var sourceValueDeclaration in Scenario.AllSourceValueDeclarations) { buf.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", sourceValueDeclaration.Name, sourceValueDeclaration.Value, sourceValueDeclaration.MeasurementUnit == "" ? " " : sourceValueDeclaration.MeasurementUnit, sourceValueDeclaration.HumanType ); } buf.Append("</table>"); buf.Append("</body></html>"); receiver.CreateValue("Исходные Данные.html", new TempHtmlFile(buf.ToString()).Content).SetTypeToken2("binary"); repo.Save(); } } finally { ww.Hide(); ww = null; Application.DoEvents(); } MessageBox.Show(this, string.Format("Данные текущего отчета успешно выгружены в ветвь Репозитория '{0}'", fullPath), "Модуль выгрузки данных", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var levelage = new Levelage(); var nodes = from node in ExpandTree() let sn = new ScenarioNode(node.Tag as IBranch) where node.Checked && !(string.IsNullOrEmpty(sn.Template) && string.IsNullOrEmpty(sn.Title)) orderby sn.SortingWeight select sn; var max = nodes.Count(); if (max == 0) return; var mainBuffer = new StringBuilder(300*1024); var appendinxBuffer = new StringBuilder(200*1024); var counter = 0; using (var repo = RepositoryEditor.Repository()) using (_evalSession2 = new Esath.Eval.Ver2.EvalSession(Scenario.Vault, repo, null)) { foreach (var branch in nodes) { if (e.Cancel) return; var source = Regex.Replace(branch.Template ?? "", @"<SPAN[^>]+vpath\s*=\s*""([^""]+)""[^>]*>[^<]+</SPAN>", vpathEvaluator, RegexOptions.Compiled); var title = ""; if (branch.Title != "") { title = branch.Title; switch (branch.NodeType) { case ScenarioNodeType.Topic: levelage.Enter(1); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "1", levelage); break; case ScenarioNodeType.Subtopic2: levelage.Enter(2); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "2", levelage); break; case ScenarioNodeType.Subtopic3: levelage.Enter(3); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "3", levelage); break; case ScenarioNodeType.Subtopic4: levelage.Enter(4); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "4", levelage); break; case ScenarioNodeType.Subtopic5: levelage.Enter(5); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "5", levelage); break; default: break; } } source = Regex.Replace(source, @"<table\s", match => string.Format(@"<div style='text-align:right'>Таблица {0}</div><table ", levelage.AddTable()), RegexOptions.Compiled | RegexOptions.IgnoreCase); if (title != "") source = title + source; if (branch.IsAppendix) appendinxBuffer.Append(source); else mainBuffer.Append(source); backgroundWorker.ReportProgress((counter++)*100/max); } } e.Result = new[] {mainBuffer, appendinxBuffer}; }
private string GeneratePreview(IEnumerable<Guid> checkedNodes) { var levelage = new Levelage(); var source = ""; using (var repo = RepositoryEditor.Repository()) using (_evalSession2 = new Esath.Eval.Ver2.EvalSession(Model.Vault, repo, checkedNodes)) { source = Regex.Replace(Template ?? "", @"<SPAN[^>]+vpath\s*=\s*""([^""]+)""[^>]*>[^<]+</SPAN>", vpathEvaluator, RegexOptions.Compiled); //source = Regex.Replace(Template ?? "", StartUp.VFIELD_PATTERN, vpathEvaluator, RegexOptions.Compiled); var title = ""; if (Title != "") { title = Title; switch (NodeType) { case ScenarioNodeType.Topic: levelage.Enter(1); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "1", levelage); break; case ScenarioNodeType.Subtopic2: levelage.Enter(2); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "2", levelage); break; case ScenarioNodeType.Subtopic3: levelage.Enter(3); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "3", levelage); break; case ScenarioNodeType.Subtopic4: levelage.Enter(4); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "4", levelage); break; case ScenarioNodeType.Subtopic5: levelage.Enter(5); title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "5", levelage); break; default: break; } } _evalSession2 = null; source = Regex.Replace(source, @"<table\s", match => string.Format(@"<div style='text-align:right'>Таблица {0}</div><table ", levelage.AddTable()), RegexOptions.Compiled | RegexOptions.IgnoreCase); if (title != "") source = title + source; } return source; }