示例#1
0
		private void buttonGenerate_Click(object sender, EventArgs e)
		{
			if (Scenario == null) return;
			if (CheckedIds == null) return;

			buttonGenerate.Visible = false;
			buttonExport.Visible = false;


			var levelage = new Levelage();
			var mainBuffer = new StringBuilder(300*1024);
			var appendinxBuffer = new StringBuilder(200*1024);

			var cwd = new CancellableWorkerDialog
			          	{
			          		Information = "Производится генерация документа, представляющего собой типовой отчет об оценке недвижимости. \n\nВ генерируемый документ попадут только выбранные ветви дерева сценария. Продолжительность данной процедуры зависит от количества выбранных ветвей дерева сценария.",
			          	};

			cwd.Worker = x =>
				{
					x.UpdateProgress(0, "Обработка выбранных узлов сценария");

					var nodes = from node in Scenario.Vault.GetBranchesRecursive()
					            let sn = new ScenarioNode(node)
					            where CheckedIds.Contains(node.Id) && !string.IsNullOrEmpty(sn.Template)
					            orderby sn.SortingWeight
					            select new {branch = sn, sn.Name};

					var total = 0;
					if ((total = nodes.Count()) == 0) return;
					var marker = 0;

					//#warning Review this: eval sessions now lock the vault for reading
					using (var repo = RepositoryEditor.Repository())
					using (_evalSession2 = new Esath.Eval.Ver2.EvalSession(Scenario.Vault, repo, CheckedIds))
					{
						foreach (var n in nodes)
						{
							x.UpdateProgress(++marker*99/total, n.Name);
							if (x.CancelPending) return;

							var source = Regex.Replace(n.branch.Template ?? "", @"<SPAN[^>]+vpath\s*=\s*""([^""]+)""[^>]*>[^<]+</SPAN>", vpathEvaluator, RegexOptions.Compiled);
							//var source = Regex.Replace(n.branch.Template ?? "", StartUp.VFIELD_PATTERN, vpathEvaluator, RegexOptions.Compiled);

							var title = "";

							if (n.branch.Title != "")
							{
								title = n.branch.Title;
								switch (n.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 (n.branch.IsAppendix)
								appendinxBuffer.Append(source);
							else
								mainBuffer.Append(source);
						}

						x.UpdateProgress(100, "Почти все готово");

						var main = mainBuffer.ToString().Replace("<hr>", "$$$newline$$$");
						main = main.Replace("<HR>", "$$$newline$$$");
						if (main.StartsWith("$$$newline$$$")) main = main.Substring(13);

						var appendix = appendinxBuffer.ToString().Replace("<hr>", "$$$newline$$$");
						appendix = appendix.Replace("<HR>", "$$$newline$$$");
						if (appendix.StartsWith("$$$newline$$$")) appendix = appendix.Substring(13);

						MainSource = "<html><head>" + Styles + "</head><body>" + main + "</body></html>";
						AppendixSource = "<html><head>" + Styles + "</head><body>" + appendix + "</body></html>";
					}
				};

			if (cwd.ShowDialog(this) != DialogResult.OK)
			{
				buttonGenerate.Visible = true;
				buttonExport.Visible = false;
				return;
			}

			webBrowser.DocumentText = "<html><head>" + Styles + "</head><body>" + mainBuffer + appendinxBuffer + "</body></html>";
			Application.DoEvents();

			buttonGenerate.Visible = false;
			buttonExport.Visible = true;
		}
		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};
		}
示例#3
0
		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;
		}