Ejemplo n.º 1
0
		internal bool PreviewTabSelected(ScenarioNode node)
		{
			if (templateEditor.InnerHtml == null)
			{
				previewBrowser.DocumentText = "";
				return true;
			}
			var topicNumber = "";
			var title = "";

			var tableCounter = 1;

#warning Review this: eval sessions now lock the vault for reading

#if VAULT_EVAL_1
            using (_evalSession1 = new Esath.Eval.Ver1.EvalSession(Scenario.Vault))
            {
#endif

#if VAULT_EVAL_2
			using (var repo = RepositoryEditor.Repository())
			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))
            {
#endif

				var preview = Regex.Replace(templateEditor.InnerHtml, StartUp.VFIELD_PATTERN, vpathEvaluator, RegexOptions.Compiled);
				if (node.Title != "")
				{
					title = node.Title;
					switch (node.NodeType)
					{
						case ScenarioNodeType.Topic:
							topicNumber = "1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "1", topicNumber);
							break;
						case ScenarioNodeType.Subtopic2:
							topicNumber = "1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "2", topicNumber);
							break;
						case ScenarioNodeType.Subtopic3:
							topicNumber = "1.1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "3", topicNumber);
							break;
						case ScenarioNodeType.Subtopic4:
							topicNumber = "1.1.1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "4", topicNumber);
							break;
						case ScenarioNodeType.Subtopic5:
							topicNumber = "1.1.1.1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "5", topicNumber);
							break;
						default:
							break;
					}
					topicNumber += "."; // for tables only
				}

				preview = Regex.Replace(preview, @"<table\s", match => string.Format(@"<div style='text-align:right'>Таблица {1}{0}</div><table ", tableCounter++, topicNumber), RegexOptions.Compiled | RegexOptions.IgnoreCase);
				if (title != "") preview = title + preview;
				previewBrowser.DocumentText = preview;

#if VAULT_EVAL_1
            }
#endif

#if VAULT_EVAL_2
			}
#endif

#if VAULT_EVAL_3
            }
#endif

			return true;
		}
Ejemplo n.º 2
0
		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 == "" ? "&nbsp;" : 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);
		}