// Created with MonoDevelop
//
//    Copyright (C) 2017 Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.



using System;
using Hiperscan.PdfLib;
using System.Reflection;
using System.Collections.Generic; 
using System.Drawing;
using System.IO;

using Hiperscan.Unix;


namespace Hiperscan.Pdf.SubstanceOverview
{
	
	public enum OverviewErrorType
	{
		None,
		NoAvailablePdf,
		NotMeasurablePdf,
		NoNewPdf,
	}

	public static class OverviewPdfCreator
	{
		public static void Create(PdfModelStructure list, string file_name, OverviewErrorType error_type)
		{
			
			OverviewPdfCreator.Document = new Layout(PdfPageSizes.A4_LANDSCAPE, file_name);
			OverviewPdfCreator.Document.PDF.SetTitle(Catalog.GetString("Substance overview"));
			OverviewPdfCreator.Document.PDF.SetSubject(Catalog.GetString("This document contains a list of substances."));

			OverviewPdfCreator.Document.LowerMargin = 50;

			Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("SubstanceOverview.Resources.Apo_Ident_Logo.png");
			OverviewPdfCreator.HiperscanLogo = new Bitmap(s);

			
			if (list == null || list.IsEmpty == true)
			{
				if (error_type != OverviewErrorType.None)
					OverviewPdfCreator.CreateSorryPage(error_type);
			}
			else
			{
				OverviewPdfCreator.Version = list.Version;

				OverviewPdfCreator.ModelStructure = list;		

				OverviewPdfCreator.Document.SimulateDrawing = true;
				{
					OverviewPdfCreator.CurrentPageNumber = 1;
					OverviewPdfCreator.CreateListOfContents();
					OverviewPdfCreator.CreateContents();
					OverviewPdfCreator.TotalPageNumber = OverviewPdfCreator.CurrentPageNumber;
				}
			
				OverviewPdfCreator.Document.SimulateDrawing = false;
				{
					OverviewPdfCreator.CurrentPageNumber = 1;
					OverviewPdfCreator.CreateListOfContents();
					OverviewPdfCreator.CreateContents();
				}
			
			}
			//OverviewPdfCreator.CreatePageNumbers();
			//OverviewPdfCreator.CreateChapterNumbers();
			
			OverviewPdfCreator.Document.Save();
		}
		
		private static int CurrentPageNumber  		{get; set;}
		private static int TotalPageNumber  		{get; set;}
		
		private static Layout Document 				{get; set;}
		private static string Version				{get; set;}
		private static Bitmap HiperscanLogo 		{get; set;}
		
		private static PdfModelStructure ModelStructure	{get; set;}
		//private static Dictionary<string, int> ModelClasses	{get; set;}
		
		
		#region List of contents
		private static double LOC_PageEntryWidth 	{get;set;}
		private static double LOC_PageEntryFeed		{get;set;}
		private static double LOC_PageEntryX		{get;set;}
		private static double LOC_PageEntryY		{get;set;} 
		private static List<int> LOC_EntriesPerPage	{get;set;}
		
		
		
		private static void CreateListOfContents()
		{
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 12, PdfColors.Black);
			OverviewPdfCreator.LOC_PageEntryWidth 	= OverviewPdfCreator.Document.MeasureString(" " + Catalog.GetString("Page") + " ");
			OverviewPdfCreator.LOC_PageEntryFeed 	= 50;
			OverviewPdfCreator.LOC_PageEntryX		= 620;
			OverviewPdfCreator.LOC_PageEntryY		= 150;
			OverviewPdfCreator.LOC_EntriesPerPage 	= new List<int>();
			int start_index = 0;
			int old_index = 0;

			for(;;)
			{
				start_index = OverviewPdfCreator.CreateOnePageForListOfContents(start_index);
				
				if (start_index == -1)
				{
					OverviewPdfCreator.LOC_EntriesPerPage.Add(OverviewPdfCreator.ModelStructure.ModelClasses.Count - old_index);
					break;
				}
				else
				{
					OverviewPdfCreator.LOC_EntriesPerPage.Add(start_index - old_index);
					OverviewPdfCreator.Document.AddNewPage();
					OverviewPdfCreator.CurrentPageNumber++;
				}
				old_index = start_index;
			}
			

			if (OverviewPdfCreator.CurrentPageNumber % 2 == 1)
			{
				OverviewPdfCreator.Document.AddNewPage();
				OverviewPdfCreator.CurrentPageNumber++;
			}
		}
		
		
		private static int CreateOnePageForListOfContents(int start_index)
		{
			double tmp;
			PdfRect rect = new PdfRect(0, 0, 0, 0);
			double left = 60;
			double right = OverviewPdfCreator.Document.InnerPageWidth - 80;

			//Create firm address
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA_BOLD, 10, PdfColors.Black);
			OverviewPdfCreator.Document.YPosition = 0;
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.AddHeader("HiperScan GmbH");
			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 9, PdfColors.Black);
			OverviewPdfCreator.Document.YPosition = 11;
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.AddHeader(Catalog.GetString("Weißeritzstr. 3, 01067 Dresden\nTel. 0351-212 496 33"));

			//Content header
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA_BOLD, 14, PdfColors.White);
			tmp = OverviewPdfCreator.Document.MeasureString(OverviewPdfCreator.ModelStructure.ListOfContentsHeader);
			tmp += 20;
			rect.X 		= left;
			rect.Y 		= 70;
			rect.Width 	= tmp;
			rect.Height = 24;
			OverviewPdfCreator.Document.AddRectangle(rect, PdfColors.HiperscanRed);
			OverviewPdfCreator.Document.YPosition = 73;
			OverviewPdfCreator.Document.XPosition = left;
			OverviewPdfCreator.Document.AddParagraph(OverviewPdfCreator.ModelStructure.ListOfContentsHeader, 
			                                         tmp, PdfTextAlignments.Center);
			//Logo
			OverviewPdfCreator.Document.AddBitmap(OverviewPdfCreator.HiperscanLogo, new PdfPoint(right - 105, 55), PdfBitmapScales.X, 105);			
			OverviewPdfCreator.Document.AddHorizontalLine(left, 94.5, right - left, 1);
				
			
			//Page entry
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 10, PdfColors.Black);
			OverviewPdfCreator.Document.XPosition = OverviewPdfCreator.LOC_PageEntryX;
			OverviewPdfCreator.Document.YPosition = 110;
			OverviewPdfCreator.Document.AddParagraph(" " +Catalog.GetString("Page") + " ", OverviewPdfCreator.LOC_PageEntryWidth, PdfTextAlignments.Center);
			
			//footer
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.YPosition = OverviewPdfCreator.Document.InnerPageHeight + 5;
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 8, PdfColors.Black);
			OverviewPdfCreator.Document.AddFooter("\u00A9 Hiperscan GmbH");


			//page entry
			if (OverviewPdfCreator.Document.SimulateDrawing == false)
			{
				OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 8, PdfColors.Black);
				OverviewPdfCreator.Document.XPosition = 0;
				OverviewPdfCreator.Document.YPosition = OverviewPdfCreator.Document.InnerPageHeight + 20;
				string text = String.Format(Catalog.GetString("Page {0} of {1}"), OverviewPdfCreator.CurrentPageNumber, OverviewPdfCreator.TotalPageNumber);
				OverviewPdfCreator.Document.AddFooter(text, PdfTextAlignments.Right);
			}


			//model class entries
			tmp = OverviewPdfCreator.LOC_PageEntryY;

			for (int i = start_index; i < OverviewPdfCreator.ModelStructure.ModelClasses.Count; i++) 
			{
				if (OverviewPdfCreator.Document.AddHorizontalLine(left, tmp + 20, right - left, 0.5) == false)
					return i;
				
				//single model class entry
				OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA_BOLD, 11, PdfColors.HiperscanRed);
				OverviewPdfCreator.Document.YPosition = tmp;
				OverviewPdfCreator.Document.XPosition = left;

				OverviewPdfCreator.Document.AddParagraph(OverviewPdfCreator.ModelStructure.ModelClasses[i].ModelClassName);

				//single model class entry page number
				if (OverviewPdfCreator.Document.SimulateDrawing == false)
				{
					OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 11, PdfColors.Black);
					OverviewPdfCreator.Document.XPosition = OverviewPdfCreator.LOC_PageEntryX;
					string page_number = OverviewPdfCreator.ModelStructure.ModelClasses[i].PageNumber.ToString();
					OverviewPdfCreator.Document.AddParagraph(page_number, 
					                                         OverviewPdfCreator.LOC_PageEntryWidth, PdfTextAlignments.Center);
				}
				
				tmp += OverviewPdfCreator.LOC_PageEntryFeed;
			}
			return -1;
		}
		#endregion List of contents
		
		
		
		#region table pages
		//TODO bad solution, better mark substance classes as pin yin
		private static List<string> PinYinGroups = new List<string>(new string[]
		                                                     	{   
				"herbasinica",
				"phytocomm",
				"chinamedica",
																});
		
		private static double SubstanceGroupNameWidth 				{get;set;}
		private static double VersionWidth 							{get;set;}
		private static List<PdfSubstanceEntry> CurrentSubstances 	{get;set;}
		private static int TableHeaderColor 						{get;set;}
		private static int TableRowColor							{get;set;}
		private static int TableLineColor 							{get;set;}
		//private static List<int> ChapterIndices 					{get;set;}

		private static double NamesSummaryColumnWidth				{get;set;}	
		private static double NamesEntryColumnWidth 				{get;set;}	
		private static double CellSpace								{get;set;}
		private static double LineWidth								{get;set;}
		
		
		private static void CreateContents()
		{
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 12, PdfColors.Black);
			OverviewPdfCreator.SubstanceGroupNameWidth = OverviewPdfCreator.Document.MeasureString(Catalog.GetString("Classifier:") + " ") + 5;
			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 10, PdfColors.Black);
			OverviewPdfCreator.VersionWidth = OverviewPdfCreator.Document.MeasureString(OverviewPdfCreator.Version) + 30;
			
			OverviewPdfCreator.TableHeaderColor 	= 0x00B33333;
			OverviewPdfCreator.TableRowColor 		= 0x00FFCCCC;
			OverviewPdfCreator.TableLineColor 		= 0X00E68080;

			OverviewPdfCreator.LineWidth = 1;
			OverviewPdfCreator.CellSpace = OverviewPdfCreator.LineWidth * 3;
			
			
			OverviewPdfCreator.NamesSummaryColumnWidth = 0;
			if (OverviewPdfCreator.ModelStructure.ShowClassificationColumn == true)
				OverviewPdfCreator.NamesSummaryColumnWidth = 150 + 2 * OverviewPdfCreator.CellSpace;
				
			if (OverviewPdfCreator.ModelStructure.ShowClassificationColumn == true)
			{
				OverviewPdfCreator.NamesEntryColumnWidth = (OverviewPdfCreator.Document.InnerPageWidth - 
				                                            OverviewPdfCreator.NamesSummaryColumnWidth +
				                                            2 * OverviewPdfCreator.LineWidth) / 2;
			}
			else
			{
				OverviewPdfCreator.NamesEntryColumnWidth = (OverviewPdfCreator.Document.InnerPageWidth +
				                                            OverviewPdfCreator.LineWidth) / 2;
			}


			foreach(PdfModelClassEntry model_class in OverviewPdfCreator.ModelStructure.ModelClasses)
			{
				OverviewPdfCreator.CurrentSubstances = model_class.Substances;
				if (OverviewPdfCreator.Document.SimulateDrawing == true)
					model_class.PageNumber = OverviewPdfCreator.CurrentPageNumber + 1;

				int start_index = 0;
				for(;;)
				{
				
					OverviewPdfCreator.Document.AddNewPage();
					OverviewPdfCreator.CurrentPageNumber++;
					start_index = OverviewPdfCreator.CreateOnePageForEnumerations(start_index, model_class.ModelClassName);
					if (start_index == -1)
						break;
				}
			}
		}


		private static int CreateOnePageForEnumerations(int start_index, string class_name)
		{
			double tmp1, tmp2, tmp3;
			double top;
			PdfRect rect;
			string text;
			int row = 1;

			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 10, PdfColors.Black);
			OverviewPdfCreator.Document.YPosition = 0;
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.AddHeader("HiperScan GmbH");
			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 12, PdfColors.Black);
			OverviewPdfCreator.Document.YPosition = 50;
			OverviewPdfCreator.Document.AddParagraph(Catalog.GetString("Classifier:") + " ");
			OverviewPdfCreator.Document.XPosition = OverviewPdfCreator.SubstanceGroupNameWidth;
			OverviewPdfCreator.Document.AddParagraph(class_name);
			
			top = OverviewPdfCreator.Document.ParagraphBoundingBox.Height + OverviewPdfCreator.Document.YPosition;
			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 8, PdfColors.Black);
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.YPosition = OverviewPdfCreator.Document.InnerPageHeight + 20;
			OverviewPdfCreator.Document.AddFooter(OverviewPdfCreator.Version);
			
			tmp1 = OverviewPdfCreator.Document.InnerPageWidth - 2 * OverviewPdfCreator.VersionWidth;
			OverviewPdfCreator.Document.XPosition = OverviewPdfCreator.VersionWidth;
			OverviewPdfCreator.Document.AddFooter(class_name, tmp1, PdfTextAlignments.Center);
						
			OverviewPdfCreator.Document.AddHeaderBitmap(OverviewPdfCreator.HiperscanLogo, new PdfPoint(OverviewPdfCreator.Document.InnerPageWidth - 105, -15), PdfBitmapScales.X, 105);
			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA_BOLD, 10, PdfColors.White);
			top += 10;
		
			//German column
			rect = new PdfRect(0, top, OverviewPdfCreator.NamesEntryColumnWidth, 15);
			OverviewPdfCreator.Document.AddRectangle(rect, OverviewPdfCreator.LineWidth, 
			                                         OverviewPdfCreator.TableLineColor, OverviewPdfCreator.TableHeaderColor);


			text = Catalog.GetString("Substance name");
			foreach (string producer in OverviewPdfCreator.PinYinGroups)
			{
				string lower_group_name = class_name.ToLower();
				if (lower_group_name.Contains(producer) == true)
				{
					text = Catalog.GetString("Pin Yin");
					break;
				}
			}
				
			OverviewPdfCreator.Document.YPosition = top + 1;
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.AddParagraph(text, rect.Width, PdfTextAlignments.Center);	
			
			
			//Latin Column
			rect = new PdfRect(OverviewPdfCreator.NamesEntryColumnWidth - OverviewPdfCreator.LineWidth, 
			                   top, OverviewPdfCreator.NamesEntryColumnWidth, 15);
			OverviewPdfCreator.Document.AddRectangle(rect, OverviewPdfCreator.LineWidth, 
			                                         OverviewPdfCreator.TableLineColor, OverviewPdfCreator.TableHeaderColor);
			OverviewPdfCreator.Document.XPosition = rect.X;
			OverviewPdfCreator.Document.YPosition = top + 1;
			OverviewPdfCreator.Document.AddParagraph(Catalog.GetString("Latin name"), rect.Width, PdfTextAlignments.Center);
			
			//Summary Column
			if (OverviewPdfCreator.ModelStructure.ShowClassificationColumn == true)
			{
				rect = new PdfRect((OverviewPdfCreator.NamesEntryColumnWidth - OverviewPdfCreator.LineWidth) * 2, 
				                   top, OverviewPdfCreator.NamesSummaryColumnWidth, 15);
				OverviewPdfCreator.Document.AddRectangle(rect, OverviewPdfCreator.LineWidth, 
				                                         OverviewPdfCreator.TableLineColor, OverviewPdfCreator.TableHeaderColor);
				OverviewPdfCreator.Document.XPosition = rect.X;
				OverviewPdfCreator.Document.YPosition = top + 1;
				OverviewPdfCreator.Document.AddParagraph(Catalog.GetString("Classification"), rect.Width, PdfTextAlignments.Center);
			}

			//page entry
			if (OverviewPdfCreator.Document.SimulateDrawing == false)
			{
				OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 8, PdfColors.Black);
				OverviewPdfCreator.Document.XPosition = 0;
				OverviewPdfCreator.Document.YPosition = OverviewPdfCreator.Document.InnerPageHeight + 20;
				string page_number = String.Format(Catalog.GetString("Page {0} of {1}"), OverviewPdfCreator.CurrentPageNumber, OverviewPdfCreator.TotalPageNumber);
				OverviewPdfCreator.Document.AddFooter(page_number, PdfTextAlignments.Right);
			}
			
			
			
			top += 14;
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 10, PdfColors.Black);
			
			
			for(int i = start_index; i < OverviewPdfCreator.CurrentSubstances.Count; i++)
			{
				string default_entry   = String.Join("\n", OverviewPdfCreator.CurrentSubstances[i].DefaultNames.ToArray());
				string latin_entry = String.Join("\n",OverviewPdfCreator.CurrentSubstances[i].LatinNames.ToArray());
				string summary_entry = String.Empty;
				if (OverviewPdfCreator.ModelStructure.ShowClassificationColumn == true)
				{
					if (OverviewPdfCreator.CurrentSubstances[i].IsSingleClassiification == false)
					{
						summary_entry = OverviewPdfCreator.CurrentSubstances[i].ClassificationName;
						summary_entry += String.Format(" " +Catalog.GetString("({0} substances)"), OverviewPdfCreator.CurrentSubstances[i].NumberOfClassificationMembers);
					}
				}
				
				int color		 = row % 2 == 1 ? OverviewPdfCreator.TableRowColor : PdfColors.White;
				
				//cell widths
				double substance_paragraph_width = OverviewPdfCreator.NamesEntryColumnWidth - 2 * OverviewPdfCreator.CellSpace;
				double summary_paragraph_width  = OverviewPdfCreator.NamesSummaryColumnWidth - 2 * OverviewPdfCreator.CellSpace;
				//cell heights
				tmp1 = OverviewPdfCreator.Document.MeasureParagraph(default_entry, substance_paragraph_width).Height;
				tmp2 = OverviewPdfCreator.Document.MeasureParagraph(latin_entry, substance_paragraph_width).Height;	
				tmp3 = 0;
				if (OverviewPdfCreator.ModelStructure.ShowClassificationColumn == true)
					tmp3 = OverviewPdfCreator.Document.MeasureParagraph(summary_entry, summary_paragraph_width).Height;	
				
				double paragraph_height = tmp1 > tmp2 ? tmp1 : tmp2;
				paragraph_height = paragraph_height > tmp3 ? paragraph_height : tmp3;
				paragraph_height += 5;
				
				//create first column
				rect = new PdfRect(0, top, OverviewPdfCreator.NamesEntryColumnWidth, paragraph_height);
				if (OverviewPdfCreator.Document.AddRectangle(rect, OverviewPdfCreator.LineWidth, 
				                                             OverviewPdfCreator.TableLineColor, color) == false)
					return i;
				
				OverviewPdfCreator.Document.XPosition = OverviewPdfCreator.CellSpace;
				OverviewPdfCreator.Document.YPosition = top + 0.5;
				OverviewPdfCreator.Document.AddParagraph(default_entry, substance_paragraph_width);
				
				
				//create second column
				rect = new PdfRect(OverviewPdfCreator.NamesEntryColumnWidth - OverviewPdfCreator.LineWidth, 
				                   top, 
				                   OverviewPdfCreator.NamesEntryColumnWidth, paragraph_height);
				OverviewPdfCreator.Document.AddRectangle(rect, OverviewPdfCreator.LineWidth, 
				                                         OverviewPdfCreator.TableLineColor, color);
				
				OverviewPdfCreator.Document.XPosition = OverviewPdfCreator.CellSpace + 
														OverviewPdfCreator.NamesEntryColumnWidth - OverviewPdfCreator.LineWidth;
				OverviewPdfCreator.Document.AddParagraph(latin_entry, substance_paragraph_width);
				
				//create third column
				if (OverviewPdfCreator.ModelStructure.ShowClassificationColumn == true)
				{
					rect = new PdfRect((OverviewPdfCreator.NamesEntryColumnWidth - OverviewPdfCreator.LineWidth) * 2, 
				                   top, 
				                   OverviewPdfCreator.NamesSummaryColumnWidth, paragraph_height);
					
					OverviewPdfCreator.Document.AddRectangle(rect, OverviewPdfCreator.LineWidth, 
				                                         OverviewPdfCreator.TableLineColor, color);
					
					OverviewPdfCreator.Document.XPosition = OverviewPdfCreator.CellSpace + 
															(OverviewPdfCreator.NamesEntryColumnWidth - OverviewPdfCreator.LineWidth) * 2;
					OverviewPdfCreator.Document.AddParagraph(summary_entry, summary_paragraph_width);
				}
				
				top += paragraph_height - OverviewPdfCreator.LineWidth;
				row++;
			}
			
			
			return -1;
		}
		#endregion table pages

		#region sorry page
		private static void CreateSorryPage(OverviewErrorType error_type)
		{
			string text = String.Empty;

			//Create firm address
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA_BOLD, 10, PdfColors.Black);
			OverviewPdfCreator.Document.YPosition = 55;
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.AddHeader("HiperScan GmbH");
			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 9, PdfColors.Black);
			OverviewPdfCreator.Document.YPosition = 66;
			OverviewPdfCreator.Document.XPosition = 0;
			OverviewPdfCreator.Document.AddHeader("Weißeritzstr. 3, 01067 Dresden\nTel. 0351-212 496 0");
			

			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA_BOLD, 20, PdfColors.Black);
			switch (error_type)
			{
			case OverviewErrorType.NoAvailablePdf:
				text = Catalog.GetString("List of available substances cannot be shown.");
				break;
				
			case OverviewErrorType.NoNewPdf:
				text = Catalog.GetString("List of added substances cannot be shown.");
				break;
				
			case OverviewErrorType.NotMeasurablePdf:
				text = Catalog.GetString("List of not measurable substances cannot be shown.");
				break;

			default:
				break;
			}
				
			OverviewPdfCreator.Document.YPosition = 150;
			OverviewPdfCreator.Document.AddParagraph(text, PdfTextAlignments.Center);
			
			OverviewPdfCreator.Document.AddBitmap(OverviewPdfCreator.HiperscanLogo, new PdfPoint(OverviewPdfCreator.Document.InnerPageWidth - 105, 55), PdfBitmapScales.X, 105);
			
			Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("SubstanceOverview.Resources.sorry.bmp");
			Bitmap bitmap = new Bitmap(s);
			OverviewPdfCreator.Document.AddBitmap(bitmap, new PdfPoint(0.3 * OverviewPdfCreator.Document.InnerPageWidth, 
			                                                        0.4 * OverviewPdfCreator.Document.InnerPageHeight),
			                        PdfBitmapScales.X, 
			                                      0.3 * OverviewPdfCreator.Document.InnerPageWidth);
			
			
			OverviewPdfCreator.Document.SetFont(PdfFontTypes.HELVETICA, 12, PdfColors.Black);
			OverviewPdfCreator.Document.YPosition = 0.875 * OverviewPdfCreator.Document.InnerPageHeight;
			OverviewPdfCreator.Document.XPosition = 150;
			text = Catalog.GetString("Possible reasons for this error are:");
			OverviewPdfCreator.Document.AddParagraph(text);
			
			OverviewPdfCreator.Document.XPosition = 170;
			OverviewPdfCreator.Document.YPosition += 16;

			switch (error_type)
			{
			case OverviewErrorType.NoAvailablePdf:
				text = Catalog.GetString("- No substance groups are defined for this device.");
				OverviewPdfCreator.Document.AddParagraph(text);
				break;
				
			case OverviewErrorType.NoNewPdf:
				text = Catalog.GetString("- No substances have been added since last Ident Module update.");
				OverviewPdfCreator.Document.AddParagraph(text);
				break;
				
			case OverviewErrorType.NotMeasurablePdf:
				text = Catalog.GetString("- There aren't any not measurable substances.");
				OverviewPdfCreator.Document.AddParagraph(text);
				break;
			}

		}
		#endregion sorry page
	}
	
	
}

