Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
EliaSchenker committed Aug 20, 2021
1 parent c7087c1 commit dc08f05
Show file tree
Hide file tree
Showing 32 changed files with 2,726 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Buchhaltung_New.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31402.337
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Buchhaltung_New", "Buchhaltung_New\Buchhaltung_New.csproj", "{BBF262FB-E4E4-46CA-B2C0-29B20D9AF9D4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BBF262FB-E4E4-46CA-B2C0-29B20D9AF9D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBF262FB-E4E4-46CA-B2C0-29B20D9AF9D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBF262FB-E4E4-46CA-B2C0-29B20D9AF9D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBF262FB-E4E4-46CA-B2C0-29B20D9AF9D4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3DC9E241-656B-4DA4-B134-7E532A412B6C}
EndGlobalSection
EndGlobal
32 changes: 32 additions & 0 deletions Buchhaltung_New/Buchhaltung_New.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<Folder Include="Exception\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.13.1" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
75 changes: 75 additions & 0 deletions Buchhaltung_New/Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Buchhaltung_New.GUI;
using Buchhaltung_New.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

namespace Buchhaltung_New
{
public class Controller
{
//Reference to Main Window
private MainWindow mainWindow;

public List<Mode> modes;

public Controller()
{
mainWindow = new MainWindow(this);
Buchhaltung.buchungen = FileManager.loadBuchungen();
Buchhaltung.konten = FileManager.loadKonten();

initModes();
fillModeList();

Application.Run(mainWindow);
}

public void initModes()
{
modes = new List<Mode>();
modes.Add(new Mode("Buchen", new BuchenWindow()));
modes.Add(new Mode("Kontoübersicht", new Kontouebersicht()));
}

private void fillModeList()
{
mainWindow.getModeSelectionList().Items.Clear();
foreach(Mode m in modes)
{
mainWindow.getModeSelectionList().Items.Add(m.name);
}
}

/// <summary>
/// Opens the current selected mode (Programm)
/// </summary>
public void openCurrentMode()
{
if (mainWindow.getModeSelectionList().SelectedIndex != -1)
{
Debug.WriteLine("Opening Mode " + modes[mainWindow.getModeSelectionList().SelectedIndex].name);

//Get the Interface of the current selected mode
IMode mode = modes[mainWindow.getModeSelectionList().SelectedIndex].window;
//Cast it to a form for execution
Form windowForm = (Form)mode;

//Check if the cast was successfull
if(windowForm == null)
{
MessageHandler.showError("Beim öffnen des selektierten Programmes ist ein Fehler aufgetreten.");
}else
{
mode.setupForShow();
windowForm.ShowDialog();
}
}else
{
MessageHandler.showWarning("Kein Item selektiert.");
}
}
}
}
169 changes: 169 additions & 0 deletions Buchhaltung_New/Exporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
using Buchhaltung_New.Model;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Buchhaltung_New
{
/// <summary>
/// Class responsible for exporting the various data from Buchhaltung
/// </summary>
class Exporter
{
private string path;

public Exporter(string path = "C:/")
{
this.path = path;
}

/// <summary>
/// Exports every Buchung to an Excel Spreadsheet
/// </summary>
/// <returns>A boolean which is true if the export was successfull and false if it was not</returns>
public bool exportBuchungenToExcel()
{
int columncount = 5;
SpreadsheetDocument ssd;
try
{
ssd = SpreadsheetDocument.Create(path, SpreadsheetDocumentType.Workbook);
}
catch
{
MessageHandler.showError("Datei konnte nicht exportiert werden.");
return false;
}
//Add work part to the Document
WorkbookPart wbp = ssd.AddWorkbookPart();
wbp.Workbook = new Workbook();

//add work sheet to the work part
WorksheetPart wsp = wbp.AddNewPart<WorksheetPart>();
wsp.Worksheet = new Worksheet(new SheetData());
// add sheets
Sheets sht = ssd.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
// Append a new worksheet and associate it with the workbook.
Sheet sheet = new Sheet()
{
Id = ssd.WorkbookPart.
// create an new sheet
GetIdOfPart(wsp),
SheetId = 1,
Name = "Konto"
};
sht.Append(sheet);
Worksheet worksheet = new Worksheet();
SheetData sheetData = new SheetData();
//create a new row, cell
Row row = new Row();
Cell[] cell = new Cell[columncount];

string[] columnheaders = new string[] { "Konto 1", "Konto 2", "Datum", "Beschreibung", "Betrag"};

// the below used to create temple of the existing gridview
for (int i = 0; i < columncount; i++)
{
string[] columnheadname = new string[]
{
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"
};
cell[i] = new Cell()
//passing the cell value
{
CellReference = columnheadname[0].ToString(),
DataType = CellValues.String,

CellValue = new CellValue(columnheaders[i])
};

row.Append(cell[i]);
}
sheetData.Append(row);
worksheet.Append(sheetData);
wsp.Worksheet = worksheet;
wbp.Workbook.Save();
ssd.Close();

int rowcount = Buchhaltung.buchungen.Count;
using (SpreadsheetDocument document = SpreadsheetDocument.Open(path, true))
{
WorkbookPart wbPart = document.WorkbookPart;
// check whether the sheet is exist or not
IEnumerable<Sheet> sheets = document.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>().Where(s => s.Name == "Konto");

if (sheets == null)
{
throw new ArgumentException("sheetName");
}
else
{
//get the ID of the sheet
string sheetss = sheets.First().Id.Value;

// get the workpartsheet of the exesting data
WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheetss);
//get the sheet data of the exsting data
sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
for (int i = 0; i < rowcount; i++)
{
//Assign the column name dynamically using array

string[] columnheadname = new string[]
{
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"
};
//create a row
row = new Row();
//create the cell dynamically using array
cell = new Cell[columncount];
for (int j = 0; j < columncount; j++)
{
// get the value in the grid view

string data1 = "";
switch(j)
{
case 0:
data1 = Buchhaltung.buchungen[i].konto1;
break;
case 1:
data1 = Buchhaltung.buchungen[i].konto2;
break;
case 2:
data1 = Buchhaltung.buchungen[i].datum.ToString("dd-M-yyyy");
break;
case 3:
data1 = Buchhaltung.buchungen[i].beschreibung;
break;
case 4:
data1 = Buchhaltung.buchungen[i].betrag.ToString();
break;
}

cell[j] = new Cell()
{
CellReference = columnheadname[0].ToString(),
DataType = (j == columncount - 1) ? CellValues.Number : CellValues.String,

CellValue = new CellValue(data1)
};
row.Append(cell[j]);
}
sheetData.Append(row);
}
worksheetPart.Worksheet.Save();
}
}

return true;
}
}
}
Loading

0 comments on commit dc08f05

Please sign in to comment.