diff --git a/OfficeFlow/App.xaml b/OfficeFlow/App.xaml
index 54dfc52..5e82c02 100644
--- a/OfficeFlow/App.xaml
+++ b/OfficeFlow/App.xaml
@@ -4,6 +4,31 @@
xmlns:local="clr-namespace:OfficeFlow"
StartupUri="MainWindow.xaml">
-
+
+
+
+
diff --git a/OfficeFlow/MainWindow.xaml.cs b/OfficeFlow/MainWindow.xaml.cs
index 2e6e4ba..3b4a610 100644
--- a/OfficeFlow/MainWindow.xaml.cs
+++ b/OfficeFlow/MainWindow.xaml.cs
@@ -1,17 +1,8 @@
-using System;
-using System.Collections.Generic;
+using OfficeFlow.Pages;
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;
namespace OfficeFlow
{
@@ -28,6 +19,10 @@ namespace OfficeFlow
{
MainFrame.Navigate(new Pages.StartupPages.InitializeDataPage());
}
+ else
+ {
+ MainFrame.Navigate(new MainPage());
+ }
}
diff --git a/OfficeFlow/OfficeFlow.csproj b/OfficeFlow/OfficeFlow.csproj
index 9eb9bf1..d129894 100644
--- a/OfficeFlow/OfficeFlow.csproj
+++ b/OfficeFlow/OfficeFlow.csproj
@@ -64,6 +64,19 @@
MSBuild:Compile
Designer
+
+ NewEmployeePage.xaml
+
+
+ NewUserPage.xaml
+
+
+ LoginPage.xaml
+
+
+ MainPage.xaml
+
+
MSBuild:Compile
Designer
@@ -76,6 +89,22 @@
MainWindow.xaml
Code
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/OfficeFlow/Pages/EmployeePages/NewEmployeePage.xaml b/OfficeFlow/Pages/EmployeePages/NewEmployeePage.xaml
new file mode 100644
index 0000000..bf92057
--- /dev/null
+++ b/OfficeFlow/Pages/EmployeePages/NewEmployeePage.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/OfficeFlow/Pages/EmployeePages/NewEmployeePage.xaml.cs b/OfficeFlow/Pages/EmployeePages/NewEmployeePage.xaml.cs
new file mode 100644
index 0000000..6beb91d
--- /dev/null
+++ b/OfficeFlow/Pages/EmployeePages/NewEmployeePage.xaml.cs
@@ -0,0 +1,28 @@
+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;
+
+namespace OfficeFlow.Pages.EmployeePages
+{
+ ///
+ /// Interaction logic for NewEmployeePage.xaml
+ ///
+ public partial class NewEmployeePage : Page
+ {
+ public NewEmployeePage()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/OfficeFlow/Pages/EmployeePages/NewUserPage.xaml b/OfficeFlow/Pages/EmployeePages/NewUserPage.xaml
new file mode 100644
index 0000000..28ca236
--- /dev/null
+++ b/OfficeFlow/Pages/EmployeePages/NewUserPage.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/OfficeFlow/Pages/EmployeePages/NewUserPage.xaml.cs b/OfficeFlow/Pages/EmployeePages/NewUserPage.xaml.cs
new file mode 100644
index 0000000..fe0caa2
--- /dev/null
+++ b/OfficeFlow/Pages/EmployeePages/NewUserPage.xaml.cs
@@ -0,0 +1,28 @@
+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;
+
+namespace OfficeFlow.Pages.EmployeePages
+{
+ ///
+ /// Interaction logic for NewUserPage.xaml
+ ///
+ public partial class NewUserPage : Page
+ {
+ public NewUserPage()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/OfficeFlow/Pages/LoginPage.xaml b/OfficeFlow/Pages/LoginPage.xaml
new file mode 100644
index 0000000..662e3d5
--- /dev/null
+++ b/OfficeFlow/Pages/LoginPage.xaml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OfficeFlow/Pages/LoginPage.xaml.cs b/OfficeFlow/Pages/LoginPage.xaml.cs
new file mode 100644
index 0000000..ad86e7a
--- /dev/null
+++ b/OfficeFlow/Pages/LoginPage.xaml.cs
@@ -0,0 +1,59 @@
+using OfficeFlow.Utils;
+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;
+
+namespace OfficeFlow.Pages
+{
+ ///
+ /// Interaction logic for LoginPage.xaml
+ ///
+ public partial class LoginPage : Page
+ {
+ public LoginPage()
+ {
+ InitializeComponent();
+ }
+
+ private void LoginButton_Click(object sender, RoutedEventArgs e)
+ {
+
+
+ string login = LoginTextBox.Text.Trim();
+ string password = PasswordBox.Password;
+
+ if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
+ {
+ ErrorMessage.Text = "Заполните все поля.";
+ ErrorMessage.Visibility = Visibility.Visible;
+ return;
+ }
+
+ try
+ {
+ Session.Authenticate(login, password);
+
+ NavigationService.Navigate(new MainPage());
+ }
+ catch (Exception)
+ {
+ ErrorMessage.Text = "Неверный логин или пароль.";
+ ErrorMessage.Visibility = Visibility.Visible;
+ }
+
+
+ }
+
+ }
+}
diff --git a/OfficeFlow/Pages/MainPage.xaml b/OfficeFlow/Pages/MainPage.xaml
new file mode 100644
index 0000000..9d25242
--- /dev/null
+++ b/OfficeFlow/Pages/MainPage.xaml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OfficeFlow/Pages/MainPage.xaml.cs b/OfficeFlow/Pages/MainPage.xaml.cs
new file mode 100644
index 0000000..5eb271b
--- /dev/null
+++ b/OfficeFlow/Pages/MainPage.xaml.cs
@@ -0,0 +1,64 @@
+using OfficeFlow.Utils;
+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;
+
+namespace OfficeFlow.Pages
+{
+ ///
+ /// Interaction logic for MainPage.xaml
+ ///
+ public partial class MainPage : Page
+ {
+ public MainPage()
+ {
+ InitializeComponent();
+
+
+ }
+
+ public void ReloadMenu()
+ {
+ MainMenu.Items.Clear();
+ }
+
+ public void ClearHistory()
+ {
+ while (NavigationService.CanGoBack)
+ {
+ NavigationService.RemoveBackEntry();
+ }
+ }
+
+ private void Page_Loaded(object sender, RoutedEventArgs e)
+ {
+
+ ClearHistory();
+ if (Session.CurrentUser == null)
+ {
+ NavigationService.Navigate(new LoginPage());
+ }
+ else
+ {
+ ReloadMenu();
+ }
+ }
+
+ private void MenuItemAbout_Click(object sender, RoutedEventArgs e)
+ {
+ MessageBox.Show("Программа была сделана в рамках дипломной работы " +
+ "специальности \"Информационные системы и программирование\".");
+ }
+ }
+}
diff --git a/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml b/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml
index 6a6d975..6156f5a 100644
--- a/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml
+++ b/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml
@@ -6,9 +6,51 @@
xmlns:local="clr-namespace:OfficeFlow.Pages.StartupPages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
- Title="CreateAdministrator">
+ Title="Создание главного администратора">
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml.cs b/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml.cs
index 8a71bb3..3786c56 100644
--- a/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml.cs
+++ b/OfficeFlow/Pages/StartupPages/CreateAdministratorPage.xaml.cs
@@ -1,4 +1,6 @@
-using System;
+using OfficeFlow.Models;
+using OfficeFlow.Utils;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -24,5 +26,102 @@ namespace OfficeFlow.Pages.StartupPages
{
InitializeComponent();
}
+
+ private void CreateAdministrator_Click(object sender, RoutedEventArgs e)
+ {
+ // Получаем значения из полей
+ string login = LoginTextBox.Text.Trim();
+ string password = PasswordBox.Password.Trim();
+ string email = EmailTextBox.Text.Trim();
+
+ // Проверяем, что все поля заполнены
+ if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
+ {
+ ShowStatusMessage("Ошибка: заполните все поля.", true);
+ return;
+ }
+
+ // Простая валидация email
+ if (!IsValidEmail(email))
+ {
+ ShowStatusMessage("Ошибка: введите корректный email.", true);
+ return;
+ }
+
+ bool success = false;
+
+ using (var transaction = App.Entities.Database.BeginTransaction())
+ {
+
+ // Логика создания администратора (например, сохранение в базу данных)
+ try
+ {
+ var newUser = Session.CreateUser(login, password, App.Entities.Roles.Where((r) => r.RoleName == "Администратор").First(), email);
+
+ App.Entities.SaveChanges();
+
+ // Фиксируем транзакцию
+ transaction.Commit();
+
+ ShowStatusMessage("Администратор успешно создан!", false);
+ ClearFields();
+
+ Session.Authenticate(newUser);
+
+ success = true;
+
+
+ }
+ catch (Exception ex)
+ {
+ transaction.Rollback();
+ ShowStatusMessage($"Ошибка: {ex.Message}", true);
+ }
+
+ }
+
+ if (success)
+ {
+ NavigationService.Navigate(new MainPage());
+
+ }
+
+ }
+
+
+
+ private bool IsValidEmail(string email)
+ {
+
+ if (string.IsNullOrEmpty(email))
+ {
+ return true;
+ }
+
+ try
+ {
+ var addr = new System.Net.Mail.MailAddress(email);
+ return addr.Address == email;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ private void ShowStatusMessage(string message, bool isError)
+ {
+ StatusMessage.Text = message;
+ StatusMessage.Foreground = isError ? Brushes.Red : Brushes.Green;
+ StatusMessage.Visibility = Visibility.Visible;
+ }
+
+ private void ClearFields()
+ {
+ LoginTextBox.Clear();
+ PasswordBox.Clear();
+ EmailTextBox.Clear();
+ }
+
}
}
diff --git a/OfficeFlow/Pages/StartupPages/InitializeDataPage.xaml b/OfficeFlow/Pages/StartupPages/InitializeDataPage.xaml
index 58bb99b..2147d97 100644
--- a/OfficeFlow/Pages/StartupPages/InitializeDataPage.xaml
+++ b/OfficeFlow/Pages/StartupPages/InitializeDataPage.xaml
@@ -17,7 +17,9 @@
+ Width="250" Height="40" Click="Button_Click"
+ Background="#4CAF50" Foreground="White"
+ />
diff --git a/OfficeFlow/Utils/Session.cs b/OfficeFlow/Utils/Session.cs
new file mode 100644
index 0000000..59aff4b
--- /dev/null
+++ b/OfficeFlow/Utils/Session.cs
@@ -0,0 +1,121 @@
+using OfficeFlow.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OfficeFlow.Utils
+{
+ public static class Session
+ {
+ // Текущий авторизованный пользователь
+ public static User CurrentUser { get; private set; }
+
+ ///
+ /// Авторизация пользователя по логину и паролю
+ ///
+ /// Логин пользователя
+ /// Пароль пользователя
+ /// True, если авторизация успешна
+ public static bool Authenticate(string login, string password)
+ {
+ try
+ {
+ // Находим пользователя по логину
+ var user = App.Entities.Users.FirstOrDefault(u => u.Login == login);
+ if (user == null)
+ {
+ throw new Exception("Пользователь с таким логином не найден.");
+ }
+
+ // Проверяем пароль
+ if (!String.Equals(HashPassword(password), user.PasswordHash))//!BCrypt.Verify(password, user.PasswordHash))
+ {
+ throw new Exception("Неверный пароль.");
+ }
+
+ // Устанавливаем текущего пользователя
+ CurrentUser = user;
+ return true;
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"Ошибка авторизации: {ex.Message}");
+ }
+ }
+
+ ///
+ /// Создание нового пользователя
+ ///
+ /// Логин
+ /// Пароль
+ /// Email
+ /// Созданный пользователь
+ public static User CreateUser(string login, string password, Role role, string email=null)
+ {
+ try
+ {
+ // Проверяем уникальность логина и email
+ if (App.Entities.Users.Any(u => u.Login == login))
+ {
+ throw new Exception("Пользователь с таким логином уже существует.");
+ }
+ if (App.Entities.Users.Any(u => u.Email == email))
+ {
+ throw new Exception("Пользователь с таким email уже существует.");
+ }
+
+ // Создаем нового пользователя
+ var newUser = new User
+ {
+ Login = login,
+ PasswordHash = HashPassword(password), // Хэшируем пароль
+ Email = email,
+ AccountStatusID = App.Entities.AccountStatuses.Where((acs) => acs.StatusName == "Активен").First().StatusID
+ };
+
+ App.Entities.Users.Add(newUser);
+ App.Entities.User_Role.Add(
+ new User_Role
+ {
+ Role = role,
+ User = newUser
+ }
+ );
+
+
+ // Возвращаем созданного пользователя
+ return newUser;
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"Ошибка при создании пользователя: {ex.Message}");
+ }
+ }
+
+ ///
+ /// Хэширование пароля
+ ///
+ /// Пароль
+ /// Хэшированный пароль
+ private static string HashPassword(string password)
+ {
+ return password.GetHashCode().ToString();
+ }
+
+ ///
+ /// Выход из системы (очистка текущего пользователя)
+ ///
+ public static void Logout()
+ {
+ CurrentUser = null;
+ }
+
+ public static bool Authenticate(User user)
+ {
+ CurrentUser = user;
+ return true;
+ }
+ }
+}