示例#1
0
		static FlowDocument CreateDocument(Project project, Lessee lessee, bool overview) {
			var doc = new FlowDocument();

			if ( lessee != null && !overview ) {// Print 1 page for a single lessee
				WritePage(doc, new Lessee[] { lessee }, project, false, true);
			} else if ( lessee == null && overview ) {// Partition lessees 8 at a time
				int i = 0;
				var list = new List<Lessee>();
				foreach ( Lessee l in project.Result.Lessees.Keys.OrderBy(l => l.Name) ) {
					list.Add(l);
					if ( ++i == 8 ) {
						WritePage(doc, list, project, true, false);
						i = 0;
						list = new List<Lessee>();
					}
				}
				if ( i > 6 ) {
					WritePage(doc, list.Take(6).ToList(), project, true, false);
					WritePage(doc, new Lessee[] { list[list.Count - 1] }, project, true, true);
				} else WritePage(doc, list, project, true, true);
			} else if ( lessee == null && !overview ) {// Print 1 page per lessee for all lessees
				foreach ( Lessee l in project.Result.Lessees.Keys ) {
					WritePage(doc, new Lessee[] { l }, project, false, false);
				}
			} else {
				throw new ArgumentException("Arguments invalid");
			}

			return doc;
		}
示例#2
0
 public void ApplyTemplate(Project other) {
     foreach (FlatAssignmentCollection assignmentcol in other.Assignments) {
         var fac = Assignments.First((c) => c.Flat == assignmentcol.Flat);
         foreach (FlatAssignment assignment in assignmentcol) {
             if (assignment.End == other.EndDate) {
                 var fa = new FlatAssignment(this);
                 fa.StartIntervalIndex = 0;
                 fa.EndIntervalIndex = 23;
                 fa.Lessee = assignment.Lessee;
                 fac.Add(fa);
             }
         }
     }
     foreach (Cost cost in other.Costs) {
         var c = CreateCost();
         c.AffectsVacancy = cost.AffectsVacancy;
         c.Mode = cost.Mode;
         c.Name = cost.Name;
         foreach (CostOptions options in cost.Options) {                    
             var co = c.Options.FirstOrDefault((o) => o.Lessee == options.Lessee);
             if (co != null) {
                 co.Affected = options.Affected;
                 co.Exempt = options.Exempt;
             }
         }                
     }
 }
示例#3
0
        // Print - brings up the print dialogue and starts printing
        public static bool Print(Project project, Lessee lessee = null, bool overview = false) {
			PrintDocumentImageableArea area = null;
			var writer = PrintQueue.CreateXpsDocumentWriter(ref area);
			var document = CreateDocument(project, lessee, overview);
			document.PageWidth = area.MediaSizeWidth;
			document.PageHeight = area.MediaSizeHeight;
			document.ColumnWidth = document.PageWidth;
			document.PagePadding = new Thickness(40);
			IDocumentPaginatorSource source = document;
			try {
				writer.WriteAsync(source.DocumentPaginator);
			} catch ( Exception ) {
				return false;
			}
            return true;
        }
示例#4
0
		public static void Read(string filepath, ProjectManager projects, ReferenceTable references, IdTable ids) {
			var xml = new XPathDocument(filepath).CreateNavigator();
			var project = new Project();
			var pnode = xml.SelectSingleNode("/Project");
			ids[project] = new Guid(pnode.GetAttribute("id", ""));
			AssignProperties(pnode, project, references);
			references.Update(ids);// force Project.Property assignment
			var aci = pnode.Select("Assignments/FlatAssignmentCollection");
			while ( aci.MoveNext() ) {
				var acnode = aci.Current;
				var flatid = acnode.SelectSingleNode("Flat").Value;
				var collection = project.Assignments.First(ac => ids[ac.Flat].ToString() == flatid);
				ids[collection] = new Guid(acnode.GetAttribute("id", ""));
				AssignProperties(acnode, collection, references);
				var ai = acnode.Select("FlatAssignment");
				while ( ai.MoveNext() ) {
					var anode = ai.Current;
					var a = new FlatAssignment(project);
					ids[a] = new Guid(anode.GetAttribute("id", ""));
					AssignProperties(anode, a, references);
					collection.Add(a);
				}
			}
			references.Update(ids);// force Assignments for CostOptions generation
			var ci = pnode.Select("Costs/Cost");
			while ( ci.MoveNext() ) {
				var cnode = ci.Current;
				var c = project.CreateCost();
				ids[c] = new Guid(cnode.GetAttribute("id", ""));
				AssignProperties(cnode, c, references);
				var oi = cnode.Select("Options/CostOptions");
				while ( oi.MoveNext() ) {
					var onode = oi.Current;
					var lesseeid = onode.SelectSingleNode("Lessee").Value;
					var option = c.Options.First(o => ids[o.Lessee].ToString() == lesseeid);
					ids[option] = new Guid(onode.GetAttribute("id", ""));
					AssignProperties(onode, option, references);
				}
			}
			projects.Add(project);
		}
示例#5
0
		static void WritePage(FlowDocument doc, IList<Lessee> lessees, Project project, bool overview, bool lastpage) {
			var result = project.Result;
			double scale = overview ? 0.8 : 1;
			var llv = overview && lastpage;// print landlord and vacancy columns

			// create some useful fonts and brushes
			var heading = CreateStyle(20.0 * scale, FontWeights.Bold);
			var big = CreateStyle(16 * scale, FontWeights.Bold);
			var bold = CreateStyle(11 * scale, FontWeights.Bold);
			var normal = CreateStyle(11 * scale);
			var small = CreateStyle(9 * scale);
			var red = CreateStyle(11 * scale, FontWeights.Bold, Brushes.Red);

			// Nebenkostenabrechnung <jahr>/<jahr+1>
			// <name mietpartei/Übersicht>
			// Vom <abrechnungszeitraum anfang> bis zum <abrechnungszeitraum ende>
			var r = doc.Blocks;
			r.Add(Text("Nebenkostenabrechnung " + project.StartYear + " / " + project.EndDate.Year, heading));
			if ( r.Count != 1 ) r.LastBlock.BreakPageBefore = true;// unless this is the first page, insert a page break
			r.Add(Text(overview ? "Übersicht" : lessees[0].Name, big));
			var start = overview ? project.StartDate : result.Lessees[lessees[0]].StartDate;
			var end = overview ? project.EndDate : result.Lessees[lessees[0]].EndDate;
			r.Add(Text("Zeitraum: " + start.ToShortDateString() + " bis " + end.ToShortDateString(), bold));
			

			/* Kostenart            Schlüssel       Gesamtkosten                    _______
			 *                      Mieter                              Mieter i
			 *                      Personen/Firmen                     i.count
			 *                      Mietfläche                          i.room.size
			 *                      Mietdauer                           n Monate    _______
			 * Kostenpunkt j        j.type          j.value             k(i, j)     _______    
			 * Nebenkosten gesamt   in Euro         K(false)            K(i)
			 * Vorauszahlungen      in Euro         P()                 P(i)
			 * Nachzahlung/Erstattung in Euro       Z(false)            Z(i)
			 *\____________________|_______________|______________|_/ \_____________/
			 *       same for single leccee and overview                single first
			 */
			var t = new Table();
			t.CellSpacing = 0;
			for ( var i = 0; i < 3 + lessees.Count; ++i ) {
				t.Columns.Add(new TableColumn() { Width = i == 0 ? new GridLength(160 * scale) : new GridLength(110 * scale) });
			}
			if ( overview && lastpage ) {
				t.Columns.Add(new TableColumn() { Width = new GridLength(110 * scale) });
				t.Columns.Add(new TableColumn() { Width = new GridLength(110 * scale) });
			}

			var headgroup = new TableRowGroup();
			headgroup.Rows.Add(Row(
				Text("Kostenart", bold), 
				Text("Schlüssel", bold), 
				Text("Gesamtkosten", bold),
				lessees, l => Text(), 
				llv ? Text() : null, 
				llv ? Text() : null, true));
			headgroup.Rows.Add(Row(
				Text(), 
				Text("Mieter", normal), 
				Text(),
				lessees, l => Text(l.Name, normal),
				llv ? Text("Leerstand", normal) : null, 
				llv ? Text("Vermieter", normal) : null));
			headgroup.Rows.Add(Row(
				Text(), 
				Text("Personen", normal), 
				Text(),
				lessees, l => Text(l.Members.ToString(), normal),
				llv ? Text() : null, 
				llv ? Text() : null));
			headgroup.Rows.Add(Row(
				Text(), 
				Text("Mietfläche", normal), 
				Text(),
				lessees, l => Text(result.Lessees[l].AverageFlatSize.ToString("F") + " m²", normal),
				llv ? Text(result.Vacancy.AverageFlatSize.ToString("F") + "~ m²", normal) : null, 
				llv ? Text() : null));
			headgroup.Rows.Add(Row(
				Text(), 
				Text("Mietdauer", normal), 
				Text(),
				lessees, l => Text(result.Lessees[l].Months + " Monate", normal),
				llv ? Text(result.Vacancy.Months + " Monate", normal) : null, 
				llv ? Text() : null, true));
			t.RowGroups.Add(headgroup);

			var costgroup = new TableRowGroup();
			for ( var i = 0; i < project.Costs.Count; ++i ) {
				var cost = project.Costs[i];
				if ( !overview && !result.Lessees[lessees[0]].Costs.ContainsKey(cost) ) continue;
				costgroup.Rows.Add(Row(
									Text(cost.Name, normal), 
									Text(ResultView.CostModeToString(cost.Mode), normal),
					/* Total */		Text(cost.Amount.ToString("F"), normal), lessees,
					/* Lessee */	l => result.Lessees[l].Costs.ContainsKey(cost) ? Text(result.Lessees[l].Costs[cost].ToString("F"), normal) : Text(),
					/* Vacancy */	llv ? (result.Vacancy.Costs.ContainsKey(cost) ? Text(result.Vacancy.Costs[cost].ToString("F"), normal) : Text()) : null,
					/* Landlord */	llv && result.Landlord.Costs.ContainsKey(cost) ? Text(result.Landlord.Costs[cost].ToString("F"), normal) : null,
					/* HasBorder */	i == project.Costs.Count - 1));
			}
			t.RowGroups.Add(costgroup);

			var sumgroup = new TableRowGroup();
			double costssum = project.Costs.Sum(c => c.Amount);
			double paymentsum = result.Lessees.Sum(p => p.Value.AdvancePayment);
			double vacancysum = result.Vacancy.Costs.Sum(v => v.Value);
			double landlordsum = result.Landlord.Costs.Sum(l => l.Value);
			sumgroup.Rows.Add(Row(
				Text("Nebenkosten gesamt", bold), 
				Text("in Euro", normal),
				Text(costssum.ToString("F"), bold), 
				lessees, l => Text(result.Lessees[l].Costs.Sum(p => p.Value).ToString("F"), bold),
				llv ? Text(vacancysum.ToString("F"), bold) : null,
				llv ? Text(landlordsum.ToString("F"), bold) : null));
			sumgroup.Rows.Add(Row(
				Text("Vorrauszahlungen", bold), 
				Text("in Euro", normal),
				Text(paymentsum.ToString("F"), bold), 
				lessees, l => Text(result.Lessees[l].AdvancePayment.ToString("F"), bold),
				llv ? Text() : null, 
				llv ? Text() : null));
			sumgroup.Rows.Add(Row(
				Text("Nachzahlung/Erstattung", bold), 
				Text("in Euro", normal),
				Text((paymentsum - costssum).ToString("F"), bold), 
				lessees, l => {
					var sum = result.Lessees[l].AdvancePayment - result.Lessees[l].Costs.Sum(p => p.Value);
					return Text(sum.ToString("F"), sum < 0 ? red : bold);
				},
				llv ? Text((-vacancysum).ToString("F"), red) : null,
				llv ? Text((-landlordsum).ToString("F"), red) : null));
			t.RowGroups.Add(sumgroup);

			r.Add(t);			
		}
示例#6
0
		public ResultTable(Project project) {
			Project = project;
		}
示例#7
0
		public FlatAssignment(Project project) {
			Project = project;
			start = min = project.StartDate;
			end = max = project.EndDate;
		}