diff --git a/.vs/BuechermarktClient/v15/.suo b/.vs/BuechermarktClient/v15/.suo index 2b7e5ff..25e5019 100644 Binary files a/.vs/BuechermarktClient/v15/.suo and b/.vs/BuechermarktClient/v15/.suo differ diff --git a/BuechermarktClient/Bills.cs b/BuechermarktClient/Bills.cs new file mode 100644 index 0000000..ae91d5b --- /dev/null +++ b/BuechermarktClient/Bills.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MongoDB.Driver; +using MSOfficeUtils.Word; + +namespace BuechermarktClient +{ + class Bills + { + public static void GenerateBills() + { + var ds = new DataSet(); + var tableRechnung = new DataTable("Rechnung"); + tableRechnung.Columns.Add("ID", typeof(bool)); + ds.Tables.Add(tableRechnung); + + var tablePerson = new DataTable("Person"); + tablePerson.Columns.Add("ID", typeof(string)); + tablePerson.Columns.Add("Forname", typeof(string)); + tablePerson.Columns.Add("Lastname", typeof(string)); + tablePerson.Columns.Add("EMail", typeof(string)); + tablePerson.Columns.Add("PhoneNumber", typeof(string)); + tablePerson.Columns.Add("Form", typeof(string)); + tablePerson.Columns.Add("Total", typeof(decimal)); + tablePerson.Columns.Add("Rechnung", typeof(bool)); + ds.Tables.Add(tablePerson); + + var tableBooks = new DataTable("Books"); + tableBooks.Columns.Add("Student", typeof(string)); + tableBooks.Columns.Add("Title", typeof(string)); + tableBooks.Columns.Add("LabelId", typeof(string)); + tableBooks.Columns.Add("Price", typeof(decimal)); + ds.Tables.Add(tableBooks); + + ds.Relations.Add(new DataRelation("Person", tableRechnung.Columns["ID"], tablePerson.Columns["Rechnung"])); + ds.Relations.Add(new DataRelation("Books", tablePerson.Columns["ID"], tableBooks.Columns["Student"])); + + var types = MainWindow.BookTypeCollection.AsQueryable(); + var typesDict = new Dictionary(); + foreach(var type in types) + { + typesDict.Add(type.ID.ToString(), type.Name); + } + + var rowRechung = tableRechnung.NewRow(); + rowRechung["ID"] = true; + tableRechnung.Rows.Add(rowRechung); + + foreach (var student in MainWindow.StudentCollection.AsQueryable().OrderBy(r => r.Form).ThenBy(r => r.Lastname)) + { + var rowPerson = tablePerson.NewRow(); + rowPerson["ID"] = student.ID.ToString(); + rowPerson["Forname"] = student.Forname; + rowPerson["Lastname"] = student.Lastname; + rowPerson["EMail"] = student.EMail; + rowPerson["PhoneNumber"] = student.PhoneNumber; + rowPerson["Form"] = student.Form; + rowPerson["Rechnung"] = true; + tablePerson.Rows.Add(rowPerson); + + var total = 0m; + var books = 0; + foreach (var book in MainWindow.BookCollection.AsQueryable().Where(r=>r.Student == student.ID).OrderBy(r=>r.Price)) + { + var rowBook = tableBooks.NewRow(); + rowBook["Student"] = rowPerson["ID"]; + try + { + rowBook["Title"] = typesDict[book.BookType.ToString()]; + } catch + { + rowBook["Title"] = "Unbekannt"; + } + rowBook["LabelId"] = book.LabelId; + rowBook["Price"] = book.State == Models.BookState.BackToStudent ? (object)DBNull.Value : book.Price; + total += !rowBook.IsNull("Price") ? rowBook.Field("Price") : 0m; + tableBooks.Rows.Add(rowBook); + books++; + } + rowPerson["Total"] = total; + + if (books <= 0) rowPerson.Delete(); + } + WordReportGeneratorOpenXml.BuildDoc(@"Vorlage.docx", "Rechnungen.docx", ds, false); + } + } +} diff --git a/BuechermarktClient/BuechermarktClient.csproj b/BuechermarktClient/BuechermarktClient.csproj index f727c7a..0df5113 100644 --- a/BuechermarktClient/BuechermarktClient.csproj +++ b/BuechermarktClient/BuechermarktClient.csproj @@ -43,6 +43,10 @@ ..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll + + False + bin\Debug\MSOfficeUtils.dll + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll @@ -111,6 +115,7 @@ Code + Books.xaml diff --git a/BuechermarktClient/MainWindow.xaml b/BuechermarktClient/MainWindow.xaml index 806dbfc..20e686e 100644 --- a/BuechermarktClient/MainWindow.xaml +++ b/BuechermarktClient/MainWindow.xaml @@ -8,14 +8,19 @@ Title="Buechermarkt" Height="350" Width="525" Loaded="Window_Loaded"> - - - - + + + + + + + +