-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
198 lines (175 loc) · 4.98 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
using Biblioteka.Admin;
using Biblioteka.Controllers;
using Biblioteka.Exceptions;
using Biblioteka.Models;
using Biblioteka.UserControls;
using Biblioteka.Windows;
using System;
using System.Configuration;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Biblioteka
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
//! Current BibliotekaDBConnectionString:
//? Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Programowanie\Biblioteka\BibliotekaDB.mdf;Integrated Security=True;Connect Timeout=30
private static string ConnectionStringBase = @"Data Source=(LocalDB)\MSSQLLocalDB;Integrated Security=True;Connect Timeout=30;" +
"AttachDbFilename=" + Directory.GetParent(Environment.CurrentDirectory).Parent.FullName + @"\BibliotekaDB.mdf;";
static MainWindow()
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["Biblioteka.Properties.Settings.BibliotekaDBConnectionString"].ConnectionString = ConnectionStringBase;
config.Save();
ConfigurationManager.RefreshSection("connectionStrings");
}
public MainWindow()
{
InitializeComponent();
//hide unnecessary elements if the user is logged in
if (UserModel.CurrentUser != null)
{
LoginButton.Visibility = Visibility.Hidden;
PleaseLogInGrid.Visibility = Visibility.Hidden;
ChangeContent(new Homepage());
UserDatabaseConnectionController.CountUserFees();
//For simple adding of new books/authors - special privilege account/s. True means the account has special privileges
if (UserModel.CurrentUser.IsSpecialAccount)
{
AdminAddContentButton.IsEnabled = true;
AdminAddContentButton.Visibility = Visibility.Visible;
}
}
}
public void ChangeContent(UserControl userControl)
{
if (!ContentGrid.Children.Contains(userControl))
{
ContentGrid.Children.Clear();
ContentGrid.Children.Add(userControl);
}
}
private void ButtonOpenMenu_Click(object sender, RoutedEventArgs e)
{
ButtonOpenMenu.Visibility = Visibility.Collapsed;
ButtonCloseMenu.Visibility = Visibility.Visible;
}
private void ButtonCloseMenu_Click(object sender, RoutedEventArgs e)
{
ButtonCloseMenu.Visibility = Visibility.Collapsed;
ButtonOpenMenu.Visibility = Visibility.Visible;
}
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
var loginWindow = new LoginWindow();
loginWindow.Show();
this.Close();
}
private void ExitButton_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void PleaseLogInGrid_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
var loginWindow = new LoginWindow();
loginWindow.Show();
this.Close();
}
private void ExitButton_MouseEnter(object sender, MouseEventArgs e)
{
ExitButton.Foreground = new SolidColorBrush(Colors.Black);
}
private void ExitButton_MouseLeave(object sender, MouseEventArgs e)
{
ExitButton.Foreground = new SolidColorBrush(Colors.DarkSlateGray);
}
private void Homepage_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (UserModel.CurrentUser == null)
{
UserNotLoggedInException.ShowGenericMessageBox();
}
else
{
ChangeContent(new Homepage());
}
}
private void Books_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (UserModel.CurrentUser == null)
{
UserNotLoggedInException.ShowGenericMessageBox();
}
else
{
ChangeContent(new BooksPage());
}
}
private void Authors_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (UserModel.CurrentUser == null)
{
UserNotLoggedInException.ShowGenericMessageBox();
}
else
{
ChangeContent(new AuthorsPage());
}
}
private void Contact_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (UserModel.CurrentUser == null)
{
UserNotLoggedInException.ShowGenericMessageBox();
}
else
{
ChangeContent(new ContactPage());
}
}
private void Account_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (UserModel.CurrentUser == null)
{
UserNotLoggedInException.ShowGenericMessageBox();
}
else
{
ChangeContent(new AccountPage());
}
}
private void LogOut_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (UserModel.CurrentUser == null)
{
UserNotLoggedInException.ShowGenericMessageBox();
}
else
{
var loginWindow = new LoginWindow();
loginWindow.Show();
UserModel.CurrentUser = null;
this.Close();
}
}
private void AdminAddContentButton_Click(object sender, RoutedEventArgs e)
{
var addContentWindow = new AdminAddContentWindow();
addContentWindow.Show();
this.Close();
}
private void DragableTop_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
this.DragMove();
}
}
}
}