This repository has been archived by the owner on Mar 15, 2019. It is now read-only.
/
MainWindow.xaml.cs
240 lines (204 loc) · 8.24 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.IO;
using System.Diagnostics;
using System.Collections;
using System.Data;
using System.Windows.Automation.Peers;
using System.Text.RegularExpressions;
namespace Zweiradverleih
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
WPFcommunication wpfc;
Hauptkonfiguration hc;
public string Projektpfad;
public MainWindow()
{
InitializeComponent();
System.Version MyVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
DateTime FCT = new DateTime(2000, 1, 1).AddDays(MyVersion.Build).AddSeconds(MyVersion.Revision * 2);
VersionStamp.Content = "Build " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
VersionStamp.ToolTip = "Created on \n" + FCT.ToString("dd.MM.yyyy HH:mm:ss");
EClose();
wpfc = new WPFcommunication();
}
private void EClose()
{
OpenData.IsEnabled = false;
AddData.IsEnabled = false;
RemData.IsEnabled = false;
RelMen.IsEnabled = false;
}
private void EOpen()
{
OpenData.IsEnabled = true;
AddData.IsEnabled = true;
RemData.IsEnabled = true;
RelMen.IsEnabled = true;
}
public void ÖffneFahrzeugFenster(string file)
{
Zweirad ci = new Zweirad(file);
ci.Show();
}
private void Open_Click(object sender, RoutedEventArgs e)
{
Pfadauswahl st = new Pfadauswahl();
if (st.Projektpfad == null || st.Projektpfad == "")
return;
this.Projektpfad = st.Projektpfad;
this.hc = new Hauptkonfiguration(this.Projektpfad);
Fahrzeuge.DataContext = wpfc.Fahrzeuge(this.Projektpfad);
EOpen();
}
private void Close_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult mb = MessageBox.Show("Möchten Sie wirklich schließen?\nAlle ungespeicherten Änderungen gehen verloren!", "Zweiradverwaltung - Warnung", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (mb == MessageBoxResult.Yes)
{
if (this.hc != null)
this.hc.Write();
foreach (Window win in App.Current.Windows)
if (win.Title != "Zweiradverwaltung")
win.Close();
Fahrzeuge.DataContext = new DataGrid();
EClose();
}
}
private void OpenData_Click(object sender, RoutedEventArgs e)
{
if (Fahrzeuge.SelectedIndex == -1)
MessageBox.Show("Es wurde kein Eintrag ausgewählt.", "Fehler - Zweiradverwaltung", MessageBoxButton.OK, MessageBoxImage.Information);
else
{
int index = Fahrzeuge.SelectedIndex;
DataRowView row = (DataRowView)Fahrzeuge.SelectedItems[0];
int WindowID = -1;
Regex reg = new Regex(@"Zweirad Eintrag \(([0-9]+)\)");
foreach (Window win in App.Current.Windows)
{
Match m = reg.Match(win.Title);
if (m.Success)
{
WindowID = Convert.ToInt32(m.Groups[1].Value);
if (Convert.ToInt32(row["ID"]) == WindowID)
{
// focus window
win.Activate();
win.Focus();
return;
}
}
}
ÖffneFahrzeugFenster(this.Projektpfad + @"\Zweirad_" + row["ID"] + ".bin");
}
}
private void AddData_Click(object sender, RoutedEventArgs e)
{
// Prüfe Verzeichnis vorhanden
// Lege neue Datei an
// Dateien haben eine fixe Dateinamenstruktur
// Zum Beispiel: Zweirad_%%i.bin
if (this.hc.Geladen != true || this.Projektpfad == "")
{
//MSG error no project opened
MessageBox.Show("Es wurde kein Projekt geöffnet.\nBitte öffne ein Projekt um einen neuen Eintrag hinzuzufügen", "Zweiradverleih - Fehler");
}
else
{
FileContents fc = new FileContents(this.Projektpfad + @"\Zweirad_" + this.hc.Einstellung.Einträge + ".bin");
fc.Data.ID = this.hc.Einstellung.Einträge;
fc.WriteFile();
fc.Poke();
// Display data window
ÖffneFahrzeugFenster(this.Projektpfad + @"\Zweirad_" + this.hc.Einstellung.Einträge + ".bin");
// increase data counter
this.hc.Einstellung.Einträge++;
Fahrzeuge.DataContext = wpfc.Fahrzeuge(this.Projektpfad);
}
}
private void RemData_Click(object sender, RoutedEventArgs e)
{
// Lösche eine vorhandene, zuvor markierten Eintrag
// Auswahl "Sind Sie sicher dass Sie ... löschen wollen?"
if (Fahrzeuge.SelectedIndex == -1)
{
MessageBox.Show("Es wurde kein Eintrag ausgewählt.", "Fehler - Zweiradverwaltung", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
MessageBoxResult mb = MessageBox.Show("Sind Sie sicher, dass Sie den ausgewählten Eintrag löschen möchten?", "Zweiradverwaltung - Löschen", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
if (mb == MessageBoxResult.Yes)
{
//Lösche ausgewählten Eintrag
int index = Fahrzeuge.SelectedIndex;
DataRowView row = (DataRowView)Fahrzeuge.SelectedItems[0];
int WindowID = -1;
Regex reg = new Regex(@"Zweirad Eintrag \(([0-9]+)\)");
foreach (Window win in App.Current.Windows)
{
Match m = reg.Match(win.Title);
if (m.Success)
{
WindowID = Convert.ToInt32(m.Groups[1].Value);
if (Convert.ToInt32(row["ID"]) == WindowID)
win.Close();
}
}
File.Delete(this.Projektpfad + @"\Zweirad_" + row["ID"] + ".bin");
Fahrzeuge.DataContext = wpfc.Fahrzeuge(this.Projektpfad);
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Überprüfe ob MainWindow noch offen ist
// Bug #F7368A85
bool isWindowOpen = false;
foreach (Window win in App.Current.Windows)
if (win.IsActive)
{
isWindowOpen = true;
continue;
}
if (isWindowOpen && this.hc != null)
{
if (this.hc != null)
this.hc.Write();
base.OnClosed(e);
Application.Current.Shutdown();
return;
}
}
private void New_Click(object sender, RoutedEventArgs e)
{
// Neue Niederlassung
Pfadauswahl pa = new Pfadauswahl();
if (pa.Projektpfad == null || pa.Projektpfad == "")
return;
this.Projektpfad = pa.Projektpfad;
this.hc = new Hauptkonfiguration(this.Projektpfad);
EOpen();
}
private void Reload_Click(object sender, RoutedEventArgs e)
{
if (this.Projektpfad != null && this.Projektpfad != "")
Fahrzeuge.DataContext = wpfc.Fahrzeuge(this.Projektpfad);
}
}
}