diff --git a/HelpDesk/HelpDesk.Common/Application/ApplicationDIController.cs b/HelpDesk/HelpDesk.Common/Application/ApplicationDIController.cs index e1c66d3..ee4e705 100644 --- a/HelpDesk/HelpDesk.Common/Application/ApplicationDIController.cs +++ b/HelpDesk/HelpDesk.Common/Application/ApplicationDIController.cs @@ -11,8 +11,10 @@ public void Start() private void RegisterSystems() { - SystemManager.Register(this); - SystemManager.Register(() => new JsonStorage()); + SystemManager.Register(this); + + SystemManager.Register(new JsonUserStorage()); + SystemManager.Register(new JsonTroubleTicketStorage()); } } } diff --git a/HelpDesk/HelpDesk.Common/Constants/TicketStatuses.cs b/HelpDesk/HelpDesk.Common/Constants/TicketStatuses.cs new file mode 100644 index 0000000..5fb40be --- /dev/null +++ b/HelpDesk/HelpDesk.Common/Constants/TicketStatuses.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HelpDesk.Common.Constants +{ + public static class TicketStatuses + { + public const string Registered = "Зарегистрирована"; + public const string InProgress = "В работе"; + public const string Completed = "Выполнена"; + public const string Rejected = "Отклонена"; + + } +} diff --git a/HelpDesk/HelpDesk.Common/FileProvider.cs b/HelpDesk/HelpDesk.Common/FileProvider.cs index 94eba02..88837c8 100644 --- a/HelpDesk/HelpDesk.Common/FileProvider.cs +++ b/HelpDesk/HelpDesk.Common/FileProvider.cs @@ -12,16 +12,13 @@ public static bool Exist(string fileName) public static void Put(string fileName, string text) { + text = SimpleEncryption.Encrypt(text); + using (var writer = new StreamWriter(fileName, false, Encoding.UTF8)) { writer.WriteLine(text); } - } - - public static void Delete(string fileName) - { - File.Delete(fileName); - } + } public static string Get(string fileName) { @@ -32,7 +29,7 @@ public static string Get(string fileName) text = reader.ReadToEnd(); } - return text; + return SimpleEncryption.Decrypt(text); } } } diff --git a/HelpDesk/HelpDesk.Common/IProvider.cs b/HelpDesk/HelpDesk.Common/IProvider.cs deleted file mode 100644 index 3a35786..0000000 --- a/HelpDesk/HelpDesk.Common/IProvider.cs +++ /dev/null @@ -1,22 +0,0 @@ -using HelpDesk.Common.Models; -using System.Collections.Generic; - -namespace HelpDesk.Common -{ - public interface IProvider - { - bool IsCorrectLoginPassword(string login, string password); - User GetUser(string login); - User GetUser(int id); - void AddUser(User user); - List GetAllUsers(); - void AddTrubleTicket(TrubleTicket trubleTicket); - List GetAllTrubleTickets(); - TrubleTicket GetTrubleTicket(int id); - void ResolveTrubleTicket(int id, string status, string resolve, int resolveUserId); - void ChangeStatusTrubleTicket(int id, string staatus, int resolveUserId); - void ChangeUserToEmployee(User user, string function, string department); - void ChangeEmployeeToUser(User user); - void UpdateUser(User user); - } -} \ No newline at end of file diff --git a/HelpDesk/HelpDesk.Common/ITroubleTicketProvider.cs b/HelpDesk/HelpDesk.Common/ITroubleTicketProvider.cs new file mode 100644 index 0000000..2fb0905 --- /dev/null +++ b/HelpDesk/HelpDesk.Common/ITroubleTicketProvider.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using HelpDesk.Common.Models; + +namespace HelpDesk.Common +{ + public interface ITroubleTicketProvider + { + void Add(TroubleTicket troubleTicket); + List GetAll(); + TroubleTicket Get(int id); + void Resolve(int id, string status, string resolve, int resolveUserId); + void ChangeStatus(int id, string status, int resolveUserId); + } +} + diff --git a/HelpDesk/HelpDesk.Common/IUserProvider.cs b/HelpDesk/HelpDesk.Common/IUserProvider.cs new file mode 100644 index 0000000..918d526 --- /dev/null +++ b/HelpDesk/HelpDesk.Common/IUserProvider.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using HelpDesk.Common.Models; + +namespace HelpDesk.Common +{ + public interface IUserProvider + { + bool IsCorrectLoginPassword(string login, string password); + User Get(string login); + User Get(int id); + void Add(User user); + List GetAll(); + void ChangeUserToEmployee(User user, string function, string department); + void ChangeEmployeeToUser(User user); + void Update(User user); + } +} diff --git a/HelpDesk/HelpDesk.Common/JsonStorage.cs b/HelpDesk/HelpDesk.Common/JsonStorage.cs deleted file mode 100644 index 3b786a7..0000000 --- a/HelpDesk/HelpDesk.Common/JsonStorage.cs +++ /dev/null @@ -1,240 +0,0 @@ -using HelpDesk.Common.Models; -using System.Collections.Generic; -using System; -using System.Linq; - -namespace HelpDesk.Common -{ - public class JsonStorage : IProvider - { - private string usersFileName = "users.json"; - private string trubleTicketsFileName = "trubleTicket.json"; - - public bool IsCorrectLoginPassword(string login, string password) - { - var users = JsonProvider.Deserialize(usersFileName); - User user = null; - - if (users == null || users.Count == 0) - { - return false; - } - else - { - user = users.FirstOrDefault(x => x.Login == login); - } - - if (user == null) - { - return false; - } - - return user.Password != Methods.GetHashMD5(password); - } - - public User GetUser(string login) - { - var users = JsonProvider.Deserialize(usersFileName); - User user = null; - - if (users == null || users.Count == 0) - { - return new User(); - } - else - { - user = users.FirstOrDefault(x => x.Login == login); - } - - if (user == null) - { - return new User(); - } - - return user; - } - - public User GetUser(int id) - { - var users = JsonProvider.Deserialize(usersFileName); - User user = null; - - if (users == null || users.Count == 0) - { - return new User(); - } - else - { - user = users.FirstOrDefault(x => x.Id == id); - } - - if (user == null) - { - return new User(); - } - - return user; - } - - public void AddUser(User user) - { - var users = JsonProvider.Deserialize(usersFileName); - - if (users != null) - { - user.Id = users.Max(x => x.Id) + 1; - - users.Add(user); - } - else - { - users = new List { user }; - } - - - JsonProvider.Serialize(users, usersFileName); - } - - public List GetAllUsers() - { - return JsonProvider.Deserialize(usersFileName); - } - - public void AddTrubleTicket(TrubleTicket trubleTicket) - { - var trubleTickets = JsonProvider.Deserialize(trubleTicketsFileName); - - if (trubleTickets == null) - { - trubleTickets = new List { trubleTicket }; - } - else - { - trubleTicket.Id = trubleTickets.Max(x => x.Id) + 1; - - trubleTickets.Add(trubleTicket); - } - - JsonProvider.Serialize(trubleTickets, trubleTicketsFileName); - } - - public List GetAllTrubleTickets() - { - var trubleTickets = JsonProvider.Deserialize(trubleTicketsFileName); - - if (trubleTickets == null) - { - return new List(); - } - else - { - return JsonProvider.Deserialize(trubleTicketsFileName); - } - } - - public TrubleTicket GetTrubleTicket(int id) - { - var trubleTickets = JsonProvider.Deserialize(trubleTicketsFileName); - - if (trubleTickets == null) - { - return new TrubleTicket(); - } - else - { - var trubleTicket = trubleTickets.FirstOrDefault(t => t.Id == id); - - return trubleTicket; - } - } - - public void ResolveTrubleTicket(int id, string status, string resolve, int resolveUserId) - { - var trubleTickets = GetAllTrubleTickets(); - var trubleTicket = GetTrubleTicket(id); - - trubleTickets.RemoveAll(x => x.Id == id); - - trubleTicket.IsSolved = true; - trubleTicket.Status = status; - trubleTicket.Resolve = resolve; - trubleTicket.ResolveTime = DateTime.Now; - trubleTicket.ResolveUser = resolveUserId; - - trubleTickets.Add(trubleTicket); - - var sortedTrubleTickets = trubleTickets.OrderBy(x => x.Id).ToList(); - - JsonProvider.Serialize(sortedTrubleTickets, trubleTicketsFileName); - } - - public void ChangeStatusTrubleTicket(int id, string status, int resolveUserId) - { - var trubleTickets = GetAllTrubleTickets(); - var trubleTicket = GetTrubleTicket(id); - - trubleTickets.RemoveAll(x => x.Id == id); - - trubleTicket.Status = status; - trubleTicket.ResolveUser = resolveUserId; - - trubleTickets.Add(trubleTicket); - - var sortedTrubleTickets = trubleTickets.OrderBy(x => x.Id).ToList(); - - JsonProvider.Serialize(sortedTrubleTickets, trubleTicketsFileName); - - } - - public void ChangeUserToEmployee(User user, string function, string department) - { - var users = GetAllUsers(); - users.RemoveAll(x => x.Id == user.Id); - - var convertedUser = new User - { - Id = user.Id, - Name = user.Name, - Login = user.Login, - Password = user.Password, - Email = user.Email, - IsEmployee = true, - Function = function, - Department = department - }; - - users.Add(convertedUser); - - var sortedUsers = users.OrderBy(x => x.Id).ToList(); - - JsonProvider.Serialize(sortedUsers, usersFileName); - } - - public void ChangeEmployeeToUser(User user) - { - var users = GetAllUsers(); - users.RemoveAll(x => x.Id == user.Id); - - user.IsEmployee = false; - user.Function = null; - user.Department = null; - - users.Add(user); - - var sortedUsers = users.OrderBy(x => x.Id).ToList(); - - JsonProvider.Serialize(sortedUsers, usersFileName); - } - - public void UpdateUser(User user) - { - var users = GetAllUsers(); - users.RemoveAll(x => x.Id == user.Id); - users.Add(user); - - var sortedUsers = users.OrderBy(x => x.Id).ToList(); - - JsonProvider.Serialize(sortedUsers, usersFileName); - } - } -} diff --git a/HelpDesk/HelpDesk.Common/JsonTroubleTicketStorage.cs b/HelpDesk/HelpDesk.Common/JsonTroubleTicketStorage.cs new file mode 100644 index 0000000..459e9cd --- /dev/null +++ b/HelpDesk/HelpDesk.Common/JsonTroubleTicketStorage.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using HelpDesk.Common.Models; + +namespace HelpDesk.Common +{ + public class JsonTroubleTicketStorage : ITroubleTicketProvider + { + private readonly string troubleTicketsFileName = "troubleTicket.json"; + + public void Add(TroubleTicket troubleTicket) + { + var troubleTickets = JsonProvider.Deserialize(troubleTicketsFileName) ?? new List(); + + troubleTicket.Id = troubleTickets.Count == 0 ? 1 : troubleTickets.Max(x => x.Id) + 1; + troubleTickets.Add(troubleTicket); + + JsonProvider.Serialize(troubleTickets, troubleTicketsFileName); + } + + public List GetAll() + { + var troubleTickets = JsonProvider.Deserialize(troubleTicketsFileName); + + return troubleTickets ?? new List(); + } + + public TroubleTicket Get(int id) + { + var troubleTickets = JsonProvider.Deserialize(troubleTicketsFileName); + + return troubleTickets?.FirstOrDefault(t => t.Id == id); + } + + private void Save(List tickets) + { + JsonProvider.Serialize(tickets.OrderBy(x => x.Id).ToList(), troubleTicketsFileName); + } + + private List GetAllInternal() + { + return JsonProvider.Deserialize(troubleTicketsFileName) + ?? new List(); + } + + public void Resolve(int id, string status, string resolve, int resolveUserId) + { + var troubleTickets = GetAllInternal(); + var troubleTicket = troubleTickets.FirstOrDefault(t => t.Id == id); + + if (troubleTicket == null) return; + + troubleTicket.IsSolved = true; + troubleTicket.Status = status; + troubleTicket.Resolve = resolve; + troubleTicket.ResolveTime = DateTime.Now; + troubleTicket.ResolveUser = resolveUserId; + + Save(troubleTickets); + } + + public void ChangeStatus(int id, string status, int resolveUserId) + { + var troubleTickets = GetAllInternal(); + var troubleTicket = troubleTickets.FirstOrDefault(t => t.Id == id); + + if (troubleTicket == null) return; + + troubleTicket.Status = status; + troubleTicket.ResolveUser = resolveUserId; + + Save(troubleTickets); + + } + } +} diff --git a/HelpDesk/HelpDesk.Common/JsonUserStorage.cs b/HelpDesk/HelpDesk.Common/JsonUserStorage.cs new file mode 100644 index 0000000..ada0603 --- /dev/null +++ b/HelpDesk/HelpDesk.Common/JsonUserStorage.cs @@ -0,0 +1,111 @@ +using System.Collections.Generic; +using System.Linq; +using HelpDesk.Common.Models; + +namespace HelpDesk.Common +{ + public class JsonUserStorage : IUserProvider + { + private readonly string usersFileName = "users.json"; + + public bool IsCorrectLoginPassword(string login, string password) + { + var users = JsonProvider.Deserialize(usersFileName); + + if (users == null || users.Count == 0) + { + return false; + } + + var user = users.FirstOrDefault(x => x.Login == login); + + if (user == null) + { + return false; + } + + return user.Password == Methods.GetHashMD5(password); + } + + public User Get(string login) + { + var users = JsonProvider.Deserialize(usersFileName); + + return users?.FirstOrDefault(x => x.Login == login); + + } + + public User Get(int id) + { + var users = JsonProvider.Deserialize(usersFileName); + + return users?.FirstOrDefault(x => x.Id == id); + } + + public void Add(User user) + { + var users = JsonProvider.Deserialize(usersFileName) ?? new List(); + + user.Id = users.Count == 0 ? 1 : users.Max(x => x.Id) + 1; + users.Add(user); + + JsonProvider.Serialize(users, usersFileName); + } + + public List GetAll() + { + return JsonProvider.Deserialize(usersFileName) ?? new List(); + } + + private void Save(List users) + { + JsonProvider.Serialize(users.OrderBy(x => x.Id).ToList(), usersFileName); + } + + public void ChangeUserToEmployee(User user, string function, string department) + { + var users = GetAll() ?? new List(); + users.RemoveAll(x => x.Id == user.Id); + + var convertedUser = new User + { + Id = user.Id, + Name = user.Name, + Login = user.Login, + Password = user.Password, + Email = user.Email, + IsEmployee = true, + Function = function, + Department = department + }; + + users.Add(convertedUser); + + Save(users); + } + + public void ChangeEmployeeToUser(User user) + { + var users = GetAll() ?? new List(); + users.RemoveAll(x => x.Id == user.Id); + + user.IsEmployee = false; + user.Function = null; + user.Department = null; + + users.Add(user); + + Save(users); + } + + public void Update(User user) + { + var users = GetAll() ?? new List(); + users.RemoveAll(x => x.Id == user.Id); + users.Add(user); + + Save(users); + } + + } +} diff --git a/HelpDesk/HelpDesk.Common/Models/TroubleTicket.cs b/HelpDesk/HelpDesk.Common/Models/TroubleTicket.cs new file mode 100644 index 0000000..0ae17a0 --- /dev/null +++ b/HelpDesk/HelpDesk.Common/Models/TroubleTicket.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; +using System; + +namespace HelpDesk.Common.Models +{ + public class TroubleTicket + { + public int Id { get; set; } + public string Status { get; set; } + public int CreateUserId { get; set; } + public string Text { get; set; } + public string? Resolve { get; set; } + public bool IsSolved { get; set; } + public DateTime Created { get; set; } + public DateTime? ResolveTime { get; set; } + public int? ResolveUser { get; set; } + public DateTime Deadline { get; set; } + + + public TroubleTicket() { } + + } +} diff --git a/HelpDesk/HelpDesk.Common/Models/TrubleTicket.cs b/HelpDesk/HelpDesk.Common/Models/TrubleTicket.cs deleted file mode 100644 index 593af05..0000000 --- a/HelpDesk/HelpDesk.Common/Models/TrubleTicket.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace HelpDesk.Common.Models -{ - public class TrubleTicket - { - public int Id { get; set; } - public string Status { get; set; } - public int CreateUser { get; set; } - public string Text { get; set; } - public string? Resolve { get; set; } - public bool IsSolved { get; set; } - public DateTime Created { get; set; } - public DateTime? ResolveTime { get; set; } - public int? ResolveUser { get; set; } - public DateTime Deadline { get; set; } - - - public TrubleTicket() { } - - [JsonConstructor] - private TrubleTicket(int id, string status, int createUser, string text, string? resolve, bool isSolved, DateTime created, DateTime? resolveTime, int? resolveUser, DateTime deadline) - { - Id = id; - Status = status; - CreateUser = createUser; - Text = text; - Resolve = resolve; - IsSolved = isSolved; - Created = created; - ResolveTime = resolveTime; - ResolveUser = resolveUser; - Deadline = deadline; - } - } -} diff --git a/HelpDesk/HelpDesk.Common/Models/User.cs b/HelpDesk/HelpDesk.Common/Models/User.cs index dc89eda..97bcfd3 100644 --- a/HelpDesk/HelpDesk.Common/Models/User.cs +++ b/HelpDesk/HelpDesk.Common/Models/User.cs @@ -14,18 +14,6 @@ public class User public string? Department { get; set; } public User() { } - - [JsonConstructor] - private User(int id, string name, string login, string password, string email, bool isEmployee, string? function, string? department) - { - Id = id; - Name = name; - Login = login; - Password = password; - Email = email; - IsEmployee = isEmployee; - Function = function; - Department = department; - } + } } \ No newline at end of file diff --git a/HelpDesk/HelpDesk.Common/SimpleEncryption.cs b/HelpDesk/HelpDesk.Common/SimpleEncryption.cs new file mode 100644 index 0000000..dcdac31 --- /dev/null +++ b/HelpDesk/HelpDesk.Common/SimpleEncryption.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace HelpDesk.Common +{ + public static class SimpleEncryption + { + private static string password = "MyHelpDeskApp2025!"; + + public static string Encrypt(string text) + { + if (string.IsNullOrEmpty(text)) return text; + + byte[] key = Encoding.UTF8.GetBytes(password.PadRight(32).Substring(0, 32)); + byte[] iv = Encoding.UTF8.GetBytes(password.PadRight(16).Substring(0, 16)); + + using (Aes aes = Aes.Create()) + { + aes.Key = key; + aes.IV = iv; + + using (MemoryStream ms = new MemoryStream()) + { + using (CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write)) + { + byte[] data = Encoding.UTF8.GetBytes(text); + cs.Write(data, 0, data.Length); + cs.FlushFinalBlock(); + + return Convert.ToBase64String(ms.ToArray()); + } + } + } + } + + public static string Decrypt(string encryptedText) + { + if (string.IsNullOrEmpty(encryptedText)) return encryptedText; + + try + { + byte[] key = Encoding.UTF8.GetBytes(password.PadRight(32).Substring(0, 32)); + byte[] iv = Encoding.UTF8.GetBytes(password.PadRight(16).Substring(0, 16)); + + using (Aes aes = Aes.Create()) + { + aes.Key = key; + aes.IV = iv; + + byte[] encryptedData = Convert.FromBase64String(encryptedText); + + using (MemoryStream ms = new MemoryStream(encryptedData)) + using (CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Read)) + using (StreamReader reader = new StreamReader(cs)) + { + return reader.ReadToEnd(); + } + } + } + catch + { + return encryptedText; + } + } + } +} \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.Designer.cs new file mode 100644 index 0000000..614dc18 --- /dev/null +++ b/HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.Designer.cs @@ -0,0 +1,131 @@ +namespace HelpDeskWinFormsApp +{ + partial class AddTroubleTicketForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.loginLabel = new System.Windows.Forms.Label(); + this.userNameTextBox = new System.Windows.Forms.TextBox(); + this.troubleRichLabel = new System.Windows.Forms.Label(); + this.troubleRichTextBox = new System.Windows.Forms.RichTextBox(); + this.createTroubleTicketButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // loginLabel + // + this.loginLabel.AutoSize = true; + this.loginLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.loginLabel.Location = new System.Drawing.Point(12, 9); + this.loginLabel.Name = "loginLabel"; + this.loginLabel.Size = new System.Drawing.Size(192, 30); + this.loginLabel.TabIndex = 0; + this.loginLabel.Text = "Имя пользователя"; + // + // userNameTextBox + // + this.userNameTextBox.Location = new System.Drawing.Point(200, 16); + this.userNameTextBox.Name = "userNameTextBox"; + this.userNameTextBox.ReadOnly = true; + this.userNameTextBox.Size = new System.Drawing.Size(190, 23); + this.userNameTextBox.TabIndex = 1; + // + // troubleRichLabel + // + this.troubleRichLabel.AutoSize = true; + this.troubleRichLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.troubleRichLabel.Location = new System.Drawing.Point(12, 42); + this.troubleRichLabel.Name = "troubleRichLabel"; + this.troubleRichLabel.Size = new System.Drawing.Size(258, 30); + this.troubleRichLabel.TabIndex = 2; + this.troubleRichLabel.Text = "Опишите вашу проблему"; + // + // troubleRichTextBox + // + this.troubleRichTextBox.Location = new System.Drawing.Point(12, 75); + this.troubleRichTextBox.Name = "troubleRichTextBox"; + this.troubleRichTextBox.Size = new System.Drawing.Size(378, 241); + this.troubleRichTextBox.TabIndex = 3; + this.troubleRichTextBox.Text = ""; + this.troubleRichTextBox.TextChanged += new System.EventHandler(this.TroubleRichTextBox_TextChanged); + // + // createTroubleTicketButton + // + this.createTroubleTicketButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.createTroubleTicketButton.Enabled = false; + this.createTroubleTicketButton.Location = new System.Drawing.Point(12, 322); + this.createTroubleTicketButton.Name = "createTroubleTicketButton"; + this.createTroubleTicketButton.Size = new System.Drawing.Size(378, 34); + this.createTroubleTicketButton.TabIndex = 4; + this.createTroubleTicketButton.Text = "&Создать заявку"; + this.createTroubleTicketButton.UseVisualStyleBackColor = true; + // + // cancelButton + // + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(12, 362); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(378, 34); + this.cancelButton.TabIndex = 5; + this.cancelButton.Text = "&Отмена"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // AddTroubleTicketForm + // + this.AcceptButton = this.createTroubleTicketButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(402, 404); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.createTroubleTicketButton); + this.Controls.Add(this.troubleRichTextBox); + this.Controls.Add(this.troubleRichLabel); + this.Controls.Add(this.userNameTextBox); + this.Controls.Add(this.loginLabel); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "AddTroubleTicketForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "HelpDesk Создание заявки"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AddTroubleTicketForm_FormClosing); + this.Shown += new System.EventHandler(this.AddTroubleTicketForm_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label loginLabel; + private System.Windows.Forms.TextBox userNameTextBox; + private System.Windows.Forms.Label troubleRichLabel; + private System.Windows.Forms.RichTextBox troubleRichTextBox; + private System.Windows.Forms.Button createTroubleTicketButton; + private System.Windows.Forms.Button cancelButton; + } +} \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.cs b/HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.cs new file mode 100644 index 0000000..4d4f56b --- /dev/null +++ b/HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.cs @@ -0,0 +1,50 @@ +using HelpDesk.Common; +using HelpDesk.Common.Models; +using System; +using System.Windows.Forms; +using HelpDesk.Common.Constants; + +namespace HelpDeskWinFormsApp +{ + public partial class AddTroubleTicketForm : Form + { + private User user; + private readonly ITroubleTicketProvider ticketProvider; + private const int MinTroubleTextLength = 5; + + public AddTroubleTicketForm(User user, ITroubleTicketProvider ticketProvider) + { + InitializeComponent(); + + this.ticketProvider = ticketProvider; + this.user = user; + } + + private void AddTroubleTicketForm_Shown(object sender, EventArgs e) + { + userNameTextBox.Text = $"{user.Name} \\ {user.Login}"; + } + + private void AddTroubleTicketForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (DialogResult == DialogResult.OK) + { + var troubelTicket = new TroubleTicket + { + CreateUserId = user.Id, + Text = troubleRichTextBox.Text, + Status = TicketStatuses.Registered, + Created = DateTime.Now, + Deadline = DateTime.Now.AddDays(4) + }; + + ticketProvider.Add(troubelTicket); + } + } + + private void TroubleRichTextBox_TextChanged(object sender, EventArgs e) + { + createTroubleTicketButton.Enabled = troubleRichTextBox.Text.Length >= MinTroubleTextLength; + } + } +} diff --git a/HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.resx b/HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.resx similarity index 100% rename from HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.resx rename to HelpDesk/HelpDeskWinFormsApp/AddTroubleTicketForm.resx diff --git a/HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.Designer.cs deleted file mode 100644 index 569eb44..0000000 --- a/HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.Designer.cs +++ /dev/null @@ -1,131 +0,0 @@ -namespace HelpDeskWinFormsApp -{ - partial class AddTrubleTicketForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.label1 = new System.Windows.Forms.Label(); - this.userNameTextBox = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.trubleRichTextBox = new System.Windows.Forms.RichTextBox(); - this.createTrubleTicketButton = new System.Windows.Forms.Button(); - this.cancelButton = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(192, 30); - this.label1.TabIndex = 0; - this.label1.Text = "Имя пользователя"; - // - // userNameTextBox - // - this.userNameTextBox.Location = new System.Drawing.Point(200, 16); - this.userNameTextBox.Name = "userNameTextBox"; - this.userNameTextBox.ReadOnly = true; - this.userNameTextBox.Size = new System.Drawing.Size(190, 23); - this.userNameTextBox.TabIndex = 1; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label2.Location = new System.Drawing.Point(12, 42); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(258, 30); - this.label2.TabIndex = 2; - this.label2.Text = "Опишите вашу проблему"; - // - // trubleRichTextBox - // - this.trubleRichTextBox.Location = new System.Drawing.Point(12, 75); - this.trubleRichTextBox.Name = "trubleRichTextBox"; - this.trubleRichTextBox.Size = new System.Drawing.Size(378, 241); - this.trubleRichTextBox.TabIndex = 3; - this.trubleRichTextBox.Text = ""; - this.trubleRichTextBox.TextChanged += new System.EventHandler(this.TrubleRichTextBox_TextChanged); - // - // createTrubleTicketButton - // - this.createTrubleTicketButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.createTrubleTicketButton.Enabled = false; - this.createTrubleTicketButton.Location = new System.Drawing.Point(12, 322); - this.createTrubleTicketButton.Name = "createTrubleTicketButton"; - this.createTrubleTicketButton.Size = new System.Drawing.Size(378, 34); - this.createTrubleTicketButton.TabIndex = 4; - this.createTrubleTicketButton.Text = "&Создать заявку"; - this.createTrubleTicketButton.UseVisualStyleBackColor = true; - // - // cancelButton - // - this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Location = new System.Drawing.Point(12, 362); - this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(378, 34); - this.cancelButton.TabIndex = 5; - this.cancelButton.Text = "&Отмена"; - this.cancelButton.UseVisualStyleBackColor = true; - // - // AddTrubleTicketForm - // - this.AcceptButton = this.createTrubleTicketButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.cancelButton; - this.ClientSize = new System.Drawing.Size(402, 404); - this.Controls.Add(this.cancelButton); - this.Controls.Add(this.createTrubleTicketButton); - this.Controls.Add(this.trubleRichTextBox); - this.Controls.Add(this.label2); - this.Controls.Add(this.userNameTextBox); - this.Controls.Add(this.label1); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "AddTrubleTicketForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "HelpDesk Создание заявки"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AddTrubleTicketForm_FormClosing); - this.Shown += new System.EventHandler(this.AddTrubleTicketForm_Shown); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox userNameTextBox; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.RichTextBox trubleRichTextBox; - private System.Windows.Forms.Button createTrubleTicketButton; - private System.Windows.Forms.Button cancelButton; - } -} \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.cs b/HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.cs deleted file mode 100644 index 306ef5b..0000000 --- a/HelpDesk/HelpDeskWinFormsApp/AddTrubleTicketForm.cs +++ /dev/null @@ -1,55 +0,0 @@ -using HelpDesk.Common; -using HelpDesk.Common.Models; -using System; -using System.Windows.Forms; - -namespace HelpDeskWinFormsApp -{ - public partial class AddTrubleTicketForm : Form - { - User user; - private readonly IProvider provider; - - public AddTrubleTicketForm(User user, IProvider provider) - { - InitializeComponent(); - - this.provider = provider; - this.user = user; - } - - private void AddTrubleTicketForm_Shown(object sender, EventArgs e) - { - userNameTextBox.Text = $"{user.Name} \\ {user.Login}"; - } - - private void AddTrubleTicketForm_FormClosing(object sender, FormClosingEventArgs e) - { - if (DialogResult == DialogResult.OK) - { - var trubelTicket = new TrubleTicket - { - CreateUser = user.Id, - Text = trubleRichTextBox.Text, - Status = "Зарегистрирована", - Created = DateTime.Now, - Deadline = DateTime.Now.AddDays(4) - }; - - provider.AddTrubleTicket(trubelTicket); - } - } - - private void TrubleRichTextBox_TextChanged(object sender, EventArgs e) - { - if (trubleRichTextBox.Text.Length < 5) - { - createTrubleTicketButton.Enabled = false; - } - else - { - createTrubleTicketButton.Enabled = true; - } - } - } -} diff --git a/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.Designer.cs new file mode 100644 index 0000000..73794b1 --- /dev/null +++ b/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.Designer.cs @@ -0,0 +1,190 @@ +using System.Windows.Forms; + +namespace HelpDeskWinFormsApp +{ + partial class AuthorizationForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + loginTextBox = new TextBox(); + passwordTextBox = new TextBox(); + loginLabel = new Label(); + passwordLabel = new Label(); + loginButton = new Button(); + cancelButton = new Button(); + registrationButton = new Button(); + mainMenuStrip = new MenuStrip(); + fileToolStripMenuItem = new ToolStripMenuItem(); + exitToolStripMenuItem = new ToolStripMenuItem(); + mainMenuStrip.SuspendLayout(); + SuspendLayout(); + // + // loginTextBox + // + loginTextBox.Enabled = false; + loginTextBox.Location = new System.Drawing.Point(14, 100); + loginTextBox.Margin = new Padding(3, 4, 3, 4); + loginTextBox.Name = "loginTextBox"; + loginTextBox.Size = new System.Drawing.Size(318, 27); + loginTextBox.TabIndex = 0; + // + // passwordTextBox + // + passwordTextBox.Enabled = false; + passwordTextBox.Location = new System.Drawing.Point(14, 185); + passwordTextBox.Margin = new Padding(3, 4, 3, 4); + passwordTextBox.Name = "passwordTextBox"; + passwordTextBox.Size = new System.Drawing.Size(318, 27); + passwordTextBox.TabIndex = 1; + passwordTextBox.UseSystemPasswordChar = true; + // + // loginLabel + // + loginLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + loginLabel.Location = new System.Drawing.Point(14, 56); + loginLabel.Name = "loginLabel"; + loginLabel.Size = new System.Drawing.Size(319, 40); + loginLabel.TabIndex = 2; + loginLabel.Text = "&Логин"; + loginLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // passwordLabel + // + passwordLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + passwordLabel.Location = new System.Drawing.Point(14, 135); + passwordLabel.Name = "passwordLabel"; + passwordLabel.Size = new System.Drawing.Size(319, 47); + passwordLabel.TabIndex = 3; + passwordLabel.Text = "&Пароль"; + passwordLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // loginButton + // + loginButton.DialogResult = DialogResult.OK; + loginButton.Enabled = false; + loginButton.Location = new System.Drawing.Point(14, 269); + loginButton.Margin = new Padding(3, 4, 3, 4); + loginButton.Name = "loginButton"; + loginButton.Size = new System.Drawing.Size(319, 44); + loginButton.TabIndex = 4; + loginButton.Text = "&Вход"; + loginButton.UseVisualStyleBackColor = true; + loginButton.Click += LoginButton_Click; + // + // cancelButton + // + cancelButton.DialogResult = DialogResult.Cancel; + cancelButton.Location = new System.Drawing.Point(14, 373); + cancelButton.Margin = new Padding(3, 4, 3, 4); + cancelButton.Name = "cancelButton"; + cancelButton.Size = new System.Drawing.Size(319, 44); + cancelButton.TabIndex = 5; + cancelButton.Text = "В&ыход"; + cancelButton.UseVisualStyleBackColor = true; + // + // registrationButton + // + registrationButton.Enabled = false; + registrationButton.Location = new System.Drawing.Point(14, 321); + registrationButton.Margin = new Padding(3, 4, 3, 4); + registrationButton.Name = "registrationButton"; + registrationButton.Size = new System.Drawing.Size(319, 44); + registrationButton.TabIndex = 6; + registrationButton.Text = "&Регистрация"; + registrationButton.UseVisualStyleBackColor = true; + registrationButton.Click += RegistrationButton_Click; + // + // mainMenuStrip + // + mainMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + mainMenuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem }); + mainMenuStrip.Location = new System.Drawing.Point(0, 0); + mainMenuStrip.Name = "mainMenuStrip"; + mainMenuStrip.Padding = new Padding(7, 3, 0, 3); + mainMenuStrip.Size = new System.Drawing.Size(346, 30); + mainMenuStrip.TabIndex = 9; + mainMenuStrip.Text = "mainMenuStrip"; + // + // fileToolStripMenuItem + // + fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { exitToolStripMenuItem }); + fileToolStripMenuItem.Name = "fileToolStripMenuItem"; + fileToolStripMenuItem.Size = new System.Drawing.Size(59, 24); + fileToolStripMenuItem.Text = "&Файл"; + // + // exitToolStripMenuItem + // + exitToolStripMenuItem.Name = "exitToolStripMenuItem"; + exitToolStripMenuItem.Size = new System.Drawing.Size(136, 26); + exitToolStripMenuItem.Text = "&Выход"; + exitToolStripMenuItem.Click += ExitToolStripMenuItem_Click; + // + // AuthorizationForm + // + AcceptButton = loginButton; + AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + CancelButton = cancelButton; + ClientSize = new System.Drawing.Size(346, 445); + ControlBox = false; + Controls.Add(registrationButton); + Controls.Add(cancelButton); + Controls.Add(loginButton); + Controls.Add(passwordLabel); + Controls.Add(loginLabel); + Controls.Add(passwordTextBox); + Controls.Add(loginTextBox); + Controls.Add(mainMenuStrip); + FormBorderStyle = FormBorderStyle.FixedDialog; + MainMenuStrip = mainMenuStrip; + Margin = new Padding(3, 4, 3, 4); + Name = "AuthorizationForm"; + ShowIcon = false; + StartPosition = FormStartPosition.CenterScreen; + Text = "HelpDesk Авторизация"; + FormClosing += AuthorizationForm_FormClosing; + Shown += AuthorizationForm_Shown; + mainMenuStrip.ResumeLayout(false); + mainMenuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label loginLabel; + private Label passwordLabel; + private Button loginButton; + private Button cancelButton; + public TextBox loginTextBox; + public TextBox passwordTextBox; + private Button registrationButton; + private ContextMenuStrip contextMenuStrip; + private MenuStrip mainMenuStrip; + private ToolStripMenuItem fileToolStripMenuItem; + private ToolStripMenuItem exitToolStripMenuItem; + } +} \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.cs b/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.cs new file mode 100644 index 0000000..17200cc --- /dev/null +++ b/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.cs @@ -0,0 +1,120 @@ +using System; +using System.Windows.Forms; +using HelpDesk.Common; +using HelpDesk.Common.Models; + +namespace HelpDeskWinFormsApp +{ + public partial class AuthorizationForm : Form + { + public bool RegistrationChoice = false; + private readonly IUserProvider userProvider; + + public AuthorizationForm(IUserProvider userProvider) + { + InitializeComponent(); + this.userProvider = userProvider; + } + + + private void AuthorizationForm_Shown(object sender, EventArgs e) + { + AddFirstEmployee(); + UnlockTextBox(); + } + + + private void RegistrationButton_Click(object sender, EventArgs e) + { + RegistrationChoice = true; + cancelButton.PerformClick(); + } + + private void UnlockTextBox() + { + loginTextBox.Enabled = true; + passwordTextBox.Enabled = true; + loginButton.Enabled = true; + registrationButton.Enabled = true; + } + + private void AddFirstEmployee() + { + var isEmptyUsers = userProvider.GetAll(); + + if (isEmptyUsers == null || isEmptyUsers.Count == 0) + { + var employee = new User + { + Name = "startAdmin", + Login = "admin", + Password = Methods.GetHashMD5("admin"), + Email = "admin@admin.admin", + IsEmployee = true, + Department = "Разработка", + Function = "Разработчик" + }; + + userProvider.Add(employee); + } + } + + private bool ValidateAllFields() + { + var loginValidation = InputValidator.ValidateLogin(loginTextBox.Text); + if (!loginValidation.IsValid) + { + MessageBox.Show(loginValidation.Message, "Ошибка валидации", + MessageBoxButtons.OK, MessageBoxIcon.Error); + loginTextBox.Focus(); + return false; + } + + var passwordValidation = InputValidator.ValidatePassword(passwordTextBox.Text); + if (!passwordValidation.IsValid) + { + MessageBox.Show(passwordValidation.Message, "Ошибка валидации", + MessageBoxButtons.OK, MessageBoxIcon.Error); + passwordTextBox.Focus(); + return false; + } + + return true; + } + + + private void AuthorizationForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (DialogResult == DialogResult.Cancel) + { + return; + } + + if (!ValidateAllFields()) + { + e.Cancel = true; + return; + } + + if (!userProvider.IsCorrectLoginPassword(loginTextBox.Text, passwordTextBox.Text)) + { + e.Cancel = true; + MessageBox.Show("Неверный логин или пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ExitToolStripMenuItem_Click(object sender, EventArgs e) + { + Environment.Exit(0); + } + + private void LoginButton_Click(object sender, EventArgs e) + { + if (!ValidateAllFields()) + { + return; + } + DialogResult = DialogResult.OK; + } + } +} diff --git a/HelpDesk/HelpDeskWinFormsApp/AuthorizationFrom.resx b/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.resx similarity index 96% rename from HelpDesk/HelpDeskWinFormsApp/AuthorizationFrom.resx rename to HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.resx index ef8ebb8..25af1eb 100644 --- a/HelpDesk/HelpDeskWinFormsApp/AuthorizationFrom.resx +++ b/HelpDesk/HelpDeskWinFormsApp/AuthorizationForm.resx @@ -1,7 +1,7 @@  diff --git a/HelpDesk/HelpDeskWinFormsApp/ExportForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/ExportForm.Designer.cs index 99511d7..3ea5e6c 100644 --- a/HelpDesk/HelpDeskWinFormsApp/ExportForm.Designer.cs +++ b/HelpDesk/HelpDeskWinFormsApp/ExportForm.Designer.cs @@ -28,30 +28,30 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.fileTypeLabel = new System.Windows.Forms.Label(); this.fileTypeComboBox = new System.Windows.Forms.ComboBox(); this.exportFileDialog = new System.Windows.Forms.SaveFileDialog(); this.exportButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button(); - this.label2 = new System.Windows.Forms.Label(); + this.timeIntervalLabel = new System.Windows.Forms.Label(); this.startDateTimePicker = new System.Windows.Forms.DateTimePicker(); this.endDateTimePicker = new System.Windows.Forms.DateTimePicker(); - this.label3 = new System.Windows.Forms.Label(); + this.exportLabel = new System.Windows.Forms.Label(); this.typeComboBox = new System.Windows.Forms.ComboBox(); this.statusFilterCheckBox = new System.Windows.Forms.CheckBox(); this.statusFilterComboBox = new System.Windows.Forms.ComboBox(); this.progressBar = new System.Windows.Forms.ProgressBar(); this.SuspendLayout(); // - // label1 + // fileTypeLabel // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label1.Location = new System.Drawing.Point(12, 39); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(113, 30); - this.label1.TabIndex = 0; - this.label1.Text = "Тип файла"; + this.fileTypeLabel.AutoSize = true; + this.fileTypeLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.fileTypeLabel.Location = new System.Drawing.Point(12, 39); + this.fileTypeLabel.Name = "fileTypeLabel"; + this.fileTypeLabel.Size = new System.Drawing.Size(113, 30); + this.fileTypeLabel.TabIndex = 0; + this.fileTypeLabel.Text = "Тип файла"; // // fileTypeComboBox // @@ -92,15 +92,15 @@ private void InitializeComponent() this.cancelButton.UseVisualStyleBackColor = true; this.cancelButton.Click += new System.EventHandler(this.CancelButton_Click); // - // label2 + // timeIntervalLabel // - this.label2.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label2.Location = new System.Drawing.Point(12, 72); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(299, 30); - this.label2.TabIndex = 4; - this.label2.Text = "Временной интервал"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.timeIntervalLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.timeIntervalLabel.Location = new System.Drawing.Point(12, 72); + this.timeIntervalLabel.Name = "timeIntervalLabel"; + this.timeIntervalLabel.Size = new System.Drawing.Size(299, 30); + this.timeIntervalLabel.TabIndex = 4; + this.timeIntervalLabel.Text = "Временной интервал"; + this.timeIntervalLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // startDateTimePicker // @@ -120,22 +120,22 @@ private void InitializeComponent() this.endDateTimePicker.Size = new System.Drawing.Size(121, 23); this.endDateTimePicker.TabIndex = 6; // - // label3 + // exportLabel // - this.label3.AutoSize = true; - this.label3.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label3.Location = new System.Drawing.Point(12, 9); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(169, 30); - this.label3.TabIndex = 7; - this.label3.Text = "Экспортировать"; + this.exportLabel.AutoSize = true; + this.exportLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.exportLabel.Location = new System.Drawing.Point(12, 9); + this.exportLabel.Name = "exportLabel"; + this.exportLabel.Size = new System.Drawing.Size(169, 30); + this.exportLabel.TabIndex = 7; + this.exportLabel.Text = "Экспортировать"; // // typeComboBox // this.typeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.typeComboBox.FormattingEnabled = true; this.typeComboBox.Items.AddRange(new object[] { - "Truble Ticket", + "Trouble Ticket", "Пользователи"}); this.typeComboBox.Location = new System.Drawing.Point(176, 16); this.typeComboBox.Name = "typeComboBox"; @@ -185,14 +185,14 @@ private void InitializeComponent() this.Controls.Add(this.statusFilterComboBox); this.Controls.Add(this.statusFilterCheckBox); this.Controls.Add(this.typeComboBox); - this.Controls.Add(this.label3); + this.Controls.Add(this.exportLabel); this.Controls.Add(this.endDateTimePicker); this.Controls.Add(this.startDateTimePicker); - this.Controls.Add(this.label2); + this.Controls.Add(this.timeIntervalLabel); this.Controls.Add(this.cancelButton); this.Controls.Add(this.exportButton); this.Controls.Add(this.fileTypeComboBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.fileTypeLabel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "ExportForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; @@ -206,15 +206,15 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label fileTypeLabel; private System.Windows.Forms.ComboBox fileTypeComboBox; private System.Windows.Forms.SaveFileDialog exportFileDialog; private System.Windows.Forms.Button exportButton; private System.Windows.Forms.Button cancelButton; - private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label timeIntervalLabel; private System.Windows.Forms.DateTimePicker startDateTimePicker; private System.Windows.Forms.DateTimePicker endDateTimePicker; - private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label exportLabel; private System.Windows.Forms.ComboBox typeComboBox; private System.Windows.Forms.CheckBox statusFilterCheckBox; private System.Windows.Forms.ComboBox statusFilterComboBox; diff --git a/HelpDesk/HelpDeskWinFormsApp/ExportForm.cs b/HelpDesk/HelpDeskWinFormsApp/ExportForm.cs index 24b5f48..0fbb090 100644 --- a/HelpDesk/HelpDeskWinFormsApp/ExportForm.cs +++ b/HelpDesk/HelpDeskWinFormsApp/ExportForm.cs @@ -1,12 +1,14 @@ -using ClosedXML.Excel; -using HelpDesk.Common; -using HelpDesk.Common.Models; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; +using ClosedXML.Excel; +using HelpDesk.Common; +using HelpDesk.Common.Constants; +using HelpDesk.Common.Models; +using HelpDeskWinFormsApp.Costants; namespace HelpDeskWinFormsApp { @@ -16,15 +18,16 @@ public partial class ExportForm : Form private bool successfullyExport = false; private DialogResult exportFileDialogResult = DialogResult.Cancel; private bool isSupport = false; - private readonly IProvider provider; + private readonly IUserProvider userProvider; + private readonly ITroubleTicketProvider ticketProvider; - public ExportForm(bool isSupport, IProvider provider) + public ExportForm(bool isSupport, IUserProvider userProvider, ITroubleTicketProvider ticketProvider) { InitializeComponent(); - this.provider = provider; + this.userProvider = userProvider; this.isSupport = isSupport; - this.provider = provider; + this.ticketProvider = ticketProvider; } private void ExportForm_Shown(object sender, EventArgs e) @@ -58,47 +61,47 @@ private void ExportButton_Click(object sender, EventArgs e) return; } - var allTrubleTickets = provider.GetAllTrubleTickets(); - var trubleTickets = new List(); + var allTroubleTickets = ticketProvider.GetAll(); + var troubleTickets = new List(); - foreach ( var tt in allTrubleTickets) + foreach ( var tt in allTroubleTickets) { if (tt.Created >= startDateTimePicker.Value && tt.Created <= endDateTimePicker.Value) { - trubleTickets.Add(tt); + troubleTickets.Add(tt); } } - var users = provider.GetAllUsers(); + var users = userProvider.GetAll(); var exportFile = exportFileDialog.FileName; - if (typeComboBox.Text == "Truble Ticket") + if (typeComboBox.Text == "Trouble Ticket") { if (statusFilterCheckBox.Checked) { - var tempTrubleTickets = new List(); + var tempTroubleTickets = new List(); - foreach( var tt in trubleTickets) + foreach( var tt in troubleTickets) { if (tt.Status == statusFilterComboBox.Text) { - tempTrubleTickets.Add(tt); + tempTroubleTickets.Add(tt); } } - trubleTickets.Clear(); - trubleTickets.AddRange(tempTrubleTickets); + troubleTickets.Clear(); + troubleTickets.AddRange(tempTroubleTickets); } - if (trubleTickets.Count != 0) + if (troubleTickets.Count != 0) { if (fileTypeComboBox.Text == "Excel (.xlsx)") { - ExcelTrubleTicketExport(trubleTickets, users, exportFile); + ExcelTroubleTicketExport(troubleTickets, users, exportFile); } else if (fileTypeComboBox.Text == "Comma-Separated Values (.csv)") { - CsvTrubleTicketExport(trubleTickets, users, exportFile); + CsvTroubleTicketExport(troubleTickets, users, exportFile); } } else @@ -148,7 +151,7 @@ private void ExportButton_Click(object sender, EventArgs e) } } - private void CsvTrubleTicketExport(List result, List users, string exportFile) + private void CsvTroubleTicketExport(List result, List users, string exportFile) { var rowsCount = result.Count; @@ -173,7 +176,7 @@ private void CsvTrubleTicketExport(List result, List users, progressBar.PerformStep(); var resolveUser = users.Where(u => u.Id == result[i].ResolveUser).FirstOrDefault(); - var createUser = users.Where(u => u.Id == result[i].CreateUser).FirstOrDefault(); + var createUser = users.Where(u => u.Id == result[i].CreateUserId).FirstOrDefault(); sw.Write("\"" + result[i].Id + "\";"); sw.Write(result[i].IsSolved == true ? "\"Да\";" : "\"Нет\";"); @@ -305,7 +308,7 @@ private void ExcelUsersExport(List users, string exportFile, bool onlyClie workBook.SaveAs(exportFile); } - private void ExcelTrubleTicketExport(List result, List users, string exportFile) + private void ExcelTroubleTicketExport(List result, List users, string exportFile) { var rowsCount = result.Count; @@ -332,7 +335,7 @@ private void ExcelTrubleTicketExport(List result, List users progressBar.PerformStep(); var resolveUser = users.Where(u => u.Id == result[i].ResolveUser).FirstOrDefault(); - var createUser = users.Where(u => u.Id == result[i].CreateUser).FirstOrDefault(); + var createUser = users.Where(u => u.Id == result[i].CreateUserId).FirstOrDefault(); sheet.Cell(i + 2, 1).SetValue(result[i].Id); sheet.Cell(i + 2, 2).SetValue(result[i].IsSolved == true ? "Да" : "Нет"); @@ -353,13 +356,20 @@ private void ExcelTrubleTicketExport(List result, List users private void TypeComboBox_SelectedIndexChanged(object sender, EventArgs e) { - if (typeComboBox.Text == "Truble Ticket") + if (typeComboBox.Text == "Trouble Ticket") { startDateTimePicker.Enabled = true; endDateTimePicker.Enabled = true; statusFilter.Clear(); - statusFilter.AddRange(new List() { "Зарегистрирована", "В работе", "Выполнена", "Отклонена" }); + statusFilter.AddRange(new List() + { + TicketStatuses.Registered, + TicketStatuses.InProgress, + TicketStatuses.Completed, + TicketStatuses.Rejected + }); + statusFilterComboBox.DataSource = null; statusFilterComboBox.DataSource = statusFilter; } @@ -369,7 +379,7 @@ private void TypeComboBox_SelectedIndexChanged(object sender, EventArgs e) endDateTimePicker.Enabled = false; statusFilter.Clear(); - statusFilter.AddRange(new List() { "Клиент", "Сотрудник" }); + statusFilter.AddRange(new List() { UserInterfaceTexts.UserTypeClient, UserInterfaceTexts.UserTypeEmployee }); statusFilterComboBox.DataSource = null; statusFilterComboBox.DataSource = statusFilter; } diff --git a/HelpDesk/HelpDeskWinFormsApp/InputValidator.cs b/HelpDesk/HelpDeskWinFormsApp/InputValidator.cs new file mode 100644 index 0000000..25fbc2a --- /dev/null +++ b/HelpDesk/HelpDeskWinFormsApp/InputValidator.cs @@ -0,0 +1,109 @@ +using System; +using System.Net.Mail; + + +namespace HelpDesk.Common +{ + public static class InputValidator + { + private const int minNameLength = 2; + private const int maxNameLength = 100; + private const int minLoginLength = 3; + private const int maxLoginLength = 50; + private const int minPasswordLength = 5; + private const int maxPasswordLength = 50; + + + public static (bool IsValid, string Message) ValidateName(string inputName) + { + var name = inputName?.Trim() ?? string.Empty; + + if (string.IsNullOrWhiteSpace(name)) + { + return (false, "Имя обязательно для заполнения"); + } + + if (name.Length < minNameLength || name.Length > maxNameLength) + { + return (false, $"Имя должно быть от {minNameLength} до {maxNameLength} символов"); + } + + return (true, string.Empty); + } + + public static (bool IsValid, string Message) ValidateLogin(string inputLogin) + { + var login = inputLogin?.Trim() ?? string.Empty; + + if (string.IsNullOrWhiteSpace(login)) + { + return (false, "Логин обязателен для заполнения"); + } + + if (login.Length < minLoginLength || login.Length > maxLoginLength) + { + return (false, $"Логин должен быть от {minLoginLength} до {maxLoginLength} символов"); + } + return (true, string.Empty); + } + + public static (bool IsValid, string Message) ValidatePassword(string inputPassword) + { + var password = inputPassword ?? string.Empty; + + if (string.IsNullOrWhiteSpace(password)) + { + return (false, "Пароль обязателен для заполнения"); + } + + if (password.Length < minPasswordLength || password.Length > maxPasswordLength) + { + return (false, $"Пароль должен быть от {minPasswordLength} до {maxPasswordLength} символов"); + } + + return (true, string.Empty); + } + + public static (bool IsValid, string Message) ValidatePasswordMatch( + string password, string confirmPassword) + { + + if (password != confirmPassword) + { + return (false, "Пароли не совпадают"); + } + + return (true, string.Empty); + } + + public static (bool IsValid, string Message) ValidateEmail(string inputEmail) + { + var email = inputEmail?.Trim() ?? string.Empty; + + if (string.IsNullOrWhiteSpace(email)) + { + return (false, "Email обязателен для заполнения"); + } + try + { + var mailAddress = new MailAddress(email); + return (true, string.Empty); + } + catch (FormatException) + { + return (false, "Неверный формат email"); + } + } + + public static (bool IsValid, string Message) ValidateDepartment(string inputDepartment) + { + var department = inputDepartment?.Trim() ?? string.Empty; + + if (string.IsNullOrWhiteSpace(department)) + { + return (false, "Отдел обязателен для заполнения"); + } + return (true, string.Empty); + } + } +} diff --git a/HelpDesk/HelpDeskWinFormsApp/MainForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/MainForm.Designer.cs index 3d20eb5..6d68fa8 100644 --- a/HelpDesk/HelpDeskWinFormsApp/MainForm.Designer.cs +++ b/HelpDesk/HelpDeskWinFormsApp/MainForm.Designer.cs @@ -58,11 +58,11 @@ private void InitializeComponent() this.loginToolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.splitContainer = new System.Windows.Forms.SplitContainer(); this.editUserButton = new System.Windows.Forms.Button(); - this.addTrubleTicketbutton = new System.Windows.Forms.Button(); - this.openTrubleTicketButton = new System.Windows.Forms.Button(); + this.addTroubleTicketbutton = new System.Windows.Forms.Button(); + this.openTroubleTicketButton = new System.Windows.Forms.Button(); this.exitButton = new System.Windows.Forms.Button(); this.treeView = new System.Windows.Forms.TreeView(); - this.listTTDataGridView = new System.Windows.Forms.DataGridView(); + this.troubleTicketsDataGridView = new System.Windows.Forms.DataGridView(); this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -70,7 +70,7 @@ private void InitializeComponent() this.splitContainer.Panel1.SuspendLayout(); this.splitContainer.Panel2.SuspendLayout(); this.splitContainer.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.listTTDataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.troubleTicketsDataGridView)).BeginInit(); this.SuspendLayout(); // // menuStrip @@ -171,15 +171,15 @@ private void InitializeComponent() // splitContainer.Panel1 // this.splitContainer.Panel1.Controls.Add(this.editUserButton); - this.splitContainer.Panel1.Controls.Add(this.addTrubleTicketbutton); - this.splitContainer.Panel1.Controls.Add(this.openTrubleTicketButton); + this.splitContainer.Panel1.Controls.Add(this.addTroubleTicketbutton); + this.splitContainer.Panel1.Controls.Add(this.openTroubleTicketButton); this.splitContainer.Panel1.Controls.Add(this.exitButton); this.splitContainer.Panel1.Controls.Add(this.treeView); this.splitContainer.Panel1.Resize += new System.EventHandler(this.SplitContainer_Panel1_Resize); // // splitContainer.Panel2 // - this.splitContainer.Panel2.Controls.Add(this.listTTDataGridView); + this.splitContainer.Panel2.Controls.Add(this.troubleTicketsDataGridView); this.splitContainer.Panel2.Resize += new System.EventHandler(this.SplitContainer_Panel2_Resize); this.splitContainer.Size = new System.Drawing.Size(982, 610); this.splitContainer.SplitterDistance = 168; @@ -195,25 +195,25 @@ private void InitializeComponent() this.editUserButton.UseVisualStyleBackColor = true; this.editUserButton.Click += new System.EventHandler(this.EditUserButton_Click); // - // addTrubleTicketbutton + // addTroubleTicketbutton // - this.addTrubleTicketbutton.Location = new System.Drawing.Point(3, 551); - this.addTrubleTicketbutton.Name = "addTrubleTicketbutton"; - this.addTrubleTicketbutton.Size = new System.Drawing.Size(158, 23); - this.addTrubleTicketbutton.TabIndex = 3; - this.addTrubleTicketbutton.Text = "&Создать заявку"; - this.addTrubleTicketbutton.UseVisualStyleBackColor = true; - this.addTrubleTicketbutton.Click += new System.EventHandler(this.AddTrubleTicketbutton_Click); + this.addTroubleTicketbutton.Location = new System.Drawing.Point(3, 551); + this.addTroubleTicketbutton.Name = "addTroubleTicketbutton"; + this.addTroubleTicketbutton.Size = new System.Drawing.Size(158, 23); + this.addTroubleTicketbutton.TabIndex = 3; + this.addTroubleTicketbutton.Text = "&Создать заявку"; + this.addTroubleTicketbutton.UseVisualStyleBackColor = true; + this.addTroubleTicketbutton.Click += new System.EventHandler(this.AddTroubleTicketButton_Click); // - // openTrubleTicketButton + // openTroubleTicketButton // - this.openTrubleTicketButton.Location = new System.Drawing.Point(3, 522); - this.openTrubleTicketButton.Name = "openTrubleTicketButton"; - this.openTrubleTicketButton.Size = new System.Drawing.Size(158, 23); - this.openTrubleTicketButton.TabIndex = 2; - this.openTrubleTicketButton.Text = "&Открыть ТТ"; - this.openTrubleTicketButton.UseVisualStyleBackColor = true; - this.openTrubleTicketButton.Click += new System.EventHandler(this.OpenTrubleTicketButton_Click); + this.openTroubleTicketButton.Location = new System.Drawing.Point(3, 522); + this.openTroubleTicketButton.Name = "openTroubleTicketButton"; + this.openTroubleTicketButton.Size = new System.Drawing.Size(158, 23); + this.openTroubleTicketButton.TabIndex = 2; + this.openTroubleTicketButton.Text = "&Открыть ТТ"; + this.openTroubleTicketButton.UseVisualStyleBackColor = true; + this.openTroubleTicketButton.Click += new System.EventHandler(this.OpenTroubleTicketButton_Click); // // exitButton // @@ -229,23 +229,23 @@ private void InitializeComponent() // this.treeView.Location = new System.Drawing.Point(0, 0); this.treeView.Name = "treeView"; - treeNode1.Name = "allTrubleTicket"; + treeNode1.Name = "allTroubleTicket"; treeNode1.Text = "Все ТТ"; - treeNode2.Name = "openTrubleTicket"; + treeNode2.Name = "openTroubleTicket"; treeNode2.Text = "Открытые ТТ"; - treeNode3.Name = "closedTrubleTicket"; + treeNode3.Name = "closedTroubleTicket"; treeNode3.Text = "Закрытые ТТ"; - treeNode4.Name = "overdueTrubleTicketNode"; + treeNode4.Name = "overdueTroubleTicketNode"; treeNode4.Text = "Просроченные ТТ"; - treeNode5.Name = "registeredTrubleTicketNode"; + treeNode5.Name = "registeredTroubleTicketNode"; treeNode5.Text = "Зарегистрирован"; - treeNode6.Name = "workTrubleTicketNode"; + treeNode6.Name = "workTroubleTicketNode"; treeNode6.Text = "В работе"; - treeNode7.Name = "completedTrubleTicketNode"; + treeNode7.Name = "completedTroubleTicketNode"; treeNode7.Text = "Выполнен"; - treeNode8.Name = "rejectedTrubleTicketNode"; + treeNode8.Name = "rejectedTroubleTicketNode"; treeNode8.Text = "Отклонен"; - treeNode9.Name = "statusTrubleTicketNode"; + treeNode9.Name = "statusTroubleTicketNode"; treeNode9.Text = "Статус ТТ"; treeNode10.Name = "trubleTicketlist"; treeNode10.Text = "Лента ТТ"; @@ -255,24 +255,24 @@ private void InitializeComponent() this.treeView.TabIndex = 0; this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TreeView_AfterSelect); // - // listTTDataGridView - // - this.listTTDataGridView.AllowUserToAddRows = false; - this.listTTDataGridView.AllowUserToDeleteRows = false; - this.listTTDataGridView.AllowUserToResizeRows = false; - this.listTTDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells; - this.listTTDataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.RaisedHorizontal; - this.listTTDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.listTTDataGridView.Location = new System.Drawing.Point(0, 0); - this.listTTDataGridView.MultiSelect = false; - this.listTTDataGridView.Name = "listTTDataGridView"; - this.listTTDataGridView.ReadOnly = true; - this.listTTDataGridView.RowHeadersVisible = false; - this.listTTDataGridView.RowTemplate.Height = 25; - this.listTTDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.listTTDataGridView.Size = new System.Drawing.Size(811, 588); - this.listTTDataGridView.TabIndex = 0; - this.listTTDataGridView.DoubleClick += new System.EventHandler(this.ListTTDataGridView_DoubleClick); + // troubleTicketsDataGridView + // + this.troubleTicketsDataGridView.AllowUserToAddRows = false; + this.troubleTicketsDataGridView.AllowUserToDeleteRows = false; + this.troubleTicketsDataGridView.AllowUserToResizeRows = false; + this.troubleTicketsDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells; + this.troubleTicketsDataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.RaisedHorizontal; + this.troubleTicketsDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.troubleTicketsDataGridView.Location = new System.Drawing.Point(0, 0); + this.troubleTicketsDataGridView.MultiSelect = false; + this.troubleTicketsDataGridView.Name = "listTTDataGridView"; + this.troubleTicketsDataGridView.ReadOnly = true; + this.troubleTicketsDataGridView.RowHeadersVisible = false; + this.troubleTicketsDataGridView.RowTemplate.Height = 25; + this.troubleTicketsDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.troubleTicketsDataGridView.Size = new System.Drawing.Size(811, 588); + this.troubleTicketsDataGridView.TabIndex = 0; + this.troubleTicketsDataGridView.DoubleClick += new System.EventHandler(this.ListTTDataGridView_DoubleClick); // // exportToolStripMenuItem // @@ -303,7 +303,7 @@ private void InitializeComponent() this.splitContainer.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); this.splitContainer.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.listTTDataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.troubleTicketsDataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -321,10 +321,10 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem logoutToolStripMenuItem; private System.Windows.Forms.SplitContainer splitContainer; private System.Windows.Forms.TreeView treeView; - private System.Windows.Forms.DataGridView listTTDataGridView; - private System.Windows.Forms.Button openTrubleTicketButton; + private System.Windows.Forms.DataGridView troubleTicketsDataGridView; + private System.Windows.Forms.Button openTroubleTicketButton; private System.Windows.Forms.Button exitButton; - private System.Windows.Forms.Button addTrubleTicketbutton; + private System.Windows.Forms.Button addTroubleTicketbutton; private System.Windows.Forms.Button editUserButton; private System.Windows.Forms.ToolStripMenuItem refreshToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exportToolStripMenuItem; diff --git a/HelpDesk/HelpDeskWinFormsApp/MainForm.cs b/HelpDesk/HelpDeskWinFormsApp/MainForm.cs index e2e7fd2..4ece032 100644 --- a/HelpDesk/HelpDeskWinFormsApp/MainForm.cs +++ b/HelpDesk/HelpDeskWinFormsApp/MainForm.cs @@ -2,65 +2,81 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; -using System.Net.NetworkInformation; using System.Windows.Forms; using HelpDesk.Common; using HelpDesk.Common.Application; using HelpDesk.Common.Models; -using HelpDesk.Common.System; +using HelpDesk.Common.Constants; +using HelpDeskWinFormsApp.Costants; namespace HelpDeskWinFormsApp { public partial class MainForm : Form { private User user = new(); - private IProvider provider; + private readonly IUserProvider userProvider; + private readonly ITroubleTicketProvider troubleTicketProvider; + public const int InvalidId = -1; - public MainForm(ApplicationDIController controller) + public MainForm(ApplicationDIController controller, + IUserProvider userProvider, + ITroubleTicketProvider troubleTicketProvider) { - controller.Start(); + this.userProvider = userProvider; + this.troubleTicketProvider = troubleTicketProvider; + InitializeComponent(); - GetProvider(); } - - public void GetProvider() + + private void MainForm_Load(object sender, EventArgs e) { - SystemManager.Get(out provider); + var login = AuthorizationUser(); + + if (!string.IsNullOrEmpty(login)) + { + InitializeUserSession(login); + } } - private void MainForm_Load(object sender, EventArgs e) + private void InitializeUserSession(string login) { - string login = AuthorizationUser(); + user = userProvider.Get(login); - if (login != string.Empty) - { - user = provider.GetUser(login); + SetupUserInterface(); + SetupTreeViewLayout(); + SetupDataGridViewLayout(); - ShowUserTreeNode(); - SetHeaderWindowText(); - ShowExportSubMenu(); + UpdateUserInfoUI(); + } + + private void SetupUserInterface() + { + ShowUserTreeNode(); + SetWindowHeaderText(); + ShowExportSubMenu(); + } - treeView.Width = splitContainer.Panel1.Width; - treeView.Height = splitContainer.Panel1.Height - 152; + private void SetupTreeViewLayout() + { + treeView.Width = splitContainer.Panel1.Width; + treeView.Height = splitContainer.Panel1.Height - UIConstants.TreeViewBottomMargin; + } - listTTDataGridView.Size = splitContainer.Panel2.Size; + private void SetupDataGridViewLayout() + { + troubleTicketsDataGridView.Size = splitContainer.Panel2.Size; + } - userNameToolStripStatusLabel.Text = $"Имя: {user.Name}"; - loginToolStripStatusLabel.Text = $"Логин: {user.Login}"; - userNameToolStripMenuItem.Text = $"&{user.Name}"; - } + private void UpdateUserInfoUI() + { + userNameToolStripStatusLabel.Text = $"Имя: {user.Name}"; + loginToolStripStatusLabel.Text = $"Логин: {user.Login}"; + userNameToolStripMenuItem.Text = $"&{user.Name}"; } private void ShowExportSubMenu() { - if (!user.IsEmployee) - { - exportToolStripMenuItem.Visible = false; - } - else - { - exportToolStripMenuItem.Visible = true; - } + exportToolStripMenuItem.Visible = user.IsEmployee; } private void ExitToolStripMenuItem_Click(object sender, EventArgs e) @@ -70,435 +86,538 @@ private void ExitToolStripMenuItem_Click(object sender, EventArgs e) private void LogoutToolStripMenuItem_Click(object sender, EventArgs e) { - listTTDataGridView.Rows.Clear(); - listTTDataGridView.Columns.Clear(); - + ClearDataGridView(); Hide(); var login = AuthorizationUser(); - if (login != string.Empty) + if (!string.IsNullOrEmpty(login)) { - user = provider.GetUser(login); - - SetHeaderWindowText(); - - userNameToolStripStatusLabel.Text = $"Имя: {user.Name}"; - loginToolStripStatusLabel.Text = $"Логин: {user.Login}"; - userNameToolStripMenuItem.Text = $"&{user.Name}"; - treeView.SelectedNode = treeView.Nodes[0]; - + user = userProvider.Get(login); + SetWindowHeaderText(); + UpdateUserInfoUI(); + ResetTreeViewSelection(); ShowUserTreeNode(); ShowExportSubMenu(); Show(); } } + private void ClearDataGridView() + { + troubleTicketsDataGridView.Rows.Clear(); + troubleTicketsDataGridView.Columns.Clear(); + } + + private void ResetTreeViewSelection() + { + treeView.SelectedNode = treeView.Nodes[0]; + } + private void SplitContainer_Panel1_Resize(object sender, EventArgs e) + { + UpdateTreeViewLayout(); + UpdateButtonPositions(); + } + + private void UpdateTreeViewLayout() { treeView.Width = splitContainer.Panel1.Width; - treeView.Height = splitContainer.Panel1.Height - 152; - editUserButton.Location = new Point(openTrubleTicketButton.Location.X, splitContainer.Panel1.Height - 117); - openTrubleTicketButton.Location = new Point(openTrubleTicketButton.Location.X, splitContainer.Panel1.Height - 88); - addTrubleTicketbutton.Location = new Point(openTrubleTicketButton.Location.X, splitContainer.Panel1.Height - 59); - exitButton.Location = new Point(exitButton.Location.X, splitContainer.Panel1.Height - 30); + treeView.Height = splitContainer.Panel1.Height - UIConstants.TreeViewBottomMargin; + } + + private void UpdateButtonPositions() + { + var panelHeight = splitContainer.Panel1.Height; + + editUserButton.Location = new Point( + openTroubleTicketButton.Location.X, + panelHeight - UIConstants.EditButtonOffset); + + openTroubleTicketButton.Location = new Point( + openTroubleTicketButton.Location.X, + panelHeight - UIConstants.OpenButtonOffset); + + addTroubleTicketbutton.Location = new Point( + openTroubleTicketButton.Location.X, + panelHeight - UIConstants.AddButtonOffset); + + exitButton.Location = new Point( + exitButton.Location.X, + panelHeight - UIConstants.ExitButtonOffset); } private void SplitContainer_Panel2_Resize(object sender, EventArgs e) { - listTTDataGridView.Size = splitContainer.Panel2.Size; + troubleTicketsDataGridView.Size = splitContainer.Panel2.Size; } - private void OpenTrubleTicketButton_Click(object sender, EventArgs e) + private void OpenTroubleTicketButton_Click(object sender, EventArgs e) { - if (listTTDataGridView.SelectedRows.Count != 0) + if (TryGetSelectedTicketId(out int ticketId)) { - var ticketId = Convert.ToInt32(listTTDataGridView.SelectedCells[0].Value); + OpenTroubleTicketForm(ticketId); + } + } - var resolvedUser = Convert.ToInt32(provider.GetTrubleTicket(ticketId).ResolveUser != null ? user.Id : -1); + private bool TryGetSelectedTicketId(out int ticketId) + { + ticketId = InvalidId; - if (user.IsEmployee && resolvedUser == -1) - { - resolvedUser = user.Id; - } + if (troubleTicketsDataGridView.SelectedRows.Count > 0) + { + ticketId = Convert.ToInt32(troubleTicketsDataGridView.SelectedCells[0].Value); + return true; + } - var dialogResult = new TrubleTicketForm(ticketId, user.IsEmployee, resolvedUser, provider).ShowDialog(); + return false; + } - if (dialogResult == DialogResult.OK) + private void OpenTroubleTicketForm(int ticketId) + { + var resolveUserId = GetResolveUserIdForTicket(ticketId); + + using (var ticketForm = new TroubleTicketForm(ticketId, user.IsEmployee, resolveUserId, troubleTicketProvider, userProvider)) + { + if (ticketForm.ShowDialog() == DialogResult.OK) { - RefreshTrubleTicketsDataGrid(); + RefreshTroubleTicketsDataGrid(); } } } - private void AddTrubleTicketbutton_Click(object sender, EventArgs e) + private int GetResolveUserIdForTicket(int ticketId) { - var dialogResult = new AddTrubleTicketForm(user, provider); + var ticket = troubleTicketProvider.Get(ticketId); + + if (ticket.ResolveUser != null) + { + return (int)ticket.ResolveUser; + } + + return user.IsEmployee ? user.Id : InvalidId; + } - if (dialogResult.ShowDialog() == DialogResult.OK) + private void AddTroubleTicketButton_Click(object sender, EventArgs e) + { + using (var addForm = new AddTroubleTicketForm(user, troubleTicketProvider)) { - treeView.SelectedNode = treeView.Nodes["trubleTicketlist"].Nodes["openTrubleTicket"]; - RefreshTrubleTicketsDataGrid(); + if (addForm.ShowDialog() == DialogResult.OK) + { + SelectOpenTroubleTicketsNode(); + RefreshTroubleTicketsDataGrid(); + } } } + private void SelectOpenTroubleTicketsNode() + { + treeView.SelectedNode = treeView.Nodes[TreeViewNodes.TroubleTicketList] + .Nodes[TreeViewNodes.OpenTroubleTickets]; + } + private void TreeView_AfterSelect(object sender, TreeViewEventArgs e) { refreshToolStripMenuItem.PerformClick(); } - private void ListTTDataGridView_DoubleClick(object sender, EventArgs e) + private void RefreshDataGridBasedOnSelectedNode() { - if (treeView.SelectedNode.Level != 0) + if (treeView.SelectedNode?.Parent == null) return; + + var parentName = treeView.SelectedNode.Parent.Name; + + UpdateButtonStates(parentName); + + if (parentName == TreeViewNodes.TroubleTicketList || + parentName == TreeViewNodes.StatusTroubleTicket) { - if (treeView.SelectedNode.Parent.Name == "trubleTicketlist" || treeView.SelectedNode.Parent.Name == "statusTrubleTicketNode") - { - openTrubleTicketButton.PerformClick(); - } + RefreshTroubleTicketsDataGrid(); + return; + } + if (parentName == TreeViewNodes.Users) + { + RefreshUsersDataGrid(); + return; + } + } - if (treeView.SelectedNode.Parent.Name == "usersNode") - { - editUserButton.PerformClick(); - } + private void UpdateButtonStates(string parentName) + { + var isUsersNode = parentName == TreeViewNodes.Users; + + editUserButton.Enabled = isUsersNode; + openTroubleTicketButton.Enabled = !isUsersNode; + } + + private void RefreshToolStripMenuItem_Click(object sender, EventArgs e) + { + RefreshDataGridBasedOnSelectedNode(); + } + + private void ListTTDataGridView_DoubleClick(object sender, EventArgs e) + { + if (treeView.SelectedNode?.Parent == null) return; + + var parentName = treeView.SelectedNode.Parent.Name; + + if (parentName == TreeViewNodes.TroubleTicketList || + parentName == TreeViewNodes.StatusTroubleTicket) + { + openTroubleTicketButton.PerformClick(); + return; + } + if (parentName == TreeViewNodes.Users) + { + editUserButton.PerformClick(); + return; } } private void ExportToolStripMenuItem_Click(object sender, EventArgs e) { - var isSupport = false; + var isSupport = user.IsEmployee && user.Department == Departments.TechnicalSupport; - if (user.IsEmployee) + using (var exportForm = new ExportForm(isSupport, userProvider, troubleTicketProvider)) { - isSupport = user.Department == "Техническая поддержка"; + exportForm.ShowDialog(); } - - new ExportForm(isSupport, provider).ShowDialog(); } private void EditUserButton_Click(object sender, EventArgs e) { - if (listTTDataGridView.SelectedRows.Count != 0) + if (TryGetSelectedUserId(out int userId)) { - var userId = Convert.ToInt32(listTTDataGridView.SelectedCells[0].Value); + OpenEditUserForm(userId); + } + } - var dialogResult = new EditUserForm(userId, provider).ShowDialog(); + private bool TryGetSelectedUserId(out int userId) + { + userId = InvalidId; - if (dialogResult == DialogResult.OK) - { - RefreshUsersDataGrid(); - } + if (troubleTicketsDataGridView.SelectedRows.Count > 0) + { + userId = Convert.ToInt32(troubleTicketsDataGridView.SelectedCells[0].Value); + return true; } + + return false; } - private void RefreshToolStripMenuItem_Click(object sender, EventArgs e) + private void OpenEditUserForm(int userId) { - if (treeView.SelectedNode.Level != 0) + using (var editForm = new EditUserForm(userId, userProvider)) { - if (treeView.SelectedNode.Parent.Name == "trubleTicketlist" || treeView.SelectedNode.Parent.Name == "statusTrubleTicketNode") - { - RefreshTrubleTicketsDataGrid(); - editUserButton.Enabled = false; - openTrubleTicketButton.Enabled = true; - } - - if (treeView.SelectedNode.Parent.Name == "usersNode") + if (editForm.ShowDialog() == DialogResult.OK) { RefreshUsersDataGrid(); - editUserButton.Enabled = true; - openTrubleTicketButton.Enabled = false; } } - else + } + + private void SetWindowHeaderText() + { + var userType = user.IsEmployee ? $"{user.Function}: {user.Name}" : $"Клиент: {user.Name}"; + Text = $"HelpDesk. {userType}/{user.Login}"; + } + + private void RemoveUserTreeNode() + { + if (treeView.Nodes.Count > 1) { - editUserButton.Enabled = false; - openTrubleTicketButton.Enabled = false; + treeView.Nodes.RemoveAt(1); } } private void ShowUserTreeNode() { - if (!user.IsEmployee || user.Department == "Техническая поддержка") + var shouldShowUsersNode = user.IsEmployee && user.Department != Departments.TechnicalSupport; + + editUserButton.Visible = shouldShowUsersNode; + + if (!shouldShowUsersNode) { RemoveUserTreeNode(); - editUserButton.Visible = false; + return; } - else + + if (treeView.Nodes.Count == 1) { - if (treeView.Nodes.Count == 1) - { - AddUserTreeNode(); - } + var usersNode = CreateUsersTreeStructure(); + treeView.Nodes.Add(usersNode); + } - editUserButton.Visible = true; - } + } - private void SetHeaderWindowText() + private TreeNode CreateUsersTreeStructure() { - if (user.IsEmployee) + var allUsersNode = new TreeNode("Все пользователи") { - Text = $"HelpDesk. {user.Function}: {user.Name}/{user.Login}"; - } - else + Name = TreeViewNodes.AllUsers + }; + + var clientsNode = new TreeNode("Клиенты") { - Text = $"HelpDesk. Клиент: {user.Name}/{user.Login}"; - } - } + Name = TreeViewNodes.Clients + }; - private void RemoveUserTreeNode() - { - if (treeView.Nodes.Count > 1) + var employeesNode = new TreeNode("Сотрудники") { - treeView.Nodes.RemoveAt(1); - } + Name = TreeViewNodes.Employees + }; + + return new TreeNode("Пользователи", new TreeNode[] { allUsersNode, clientsNode, employeesNode }) + { + Name = TreeViewNodes.Users + }; } - private void AddUserTreeNode() + private string AuthorizationUser() { - TreeNode treeNode1 = new TreeNode("Все пользователи"); - TreeNode treeNode2 = new TreeNode("Клиенты"); - TreeNode treeNode3 = new TreeNode("Сотрудники"); - TreeNode treeNode4 = new TreeNode("Пользователи", new TreeNode[] { treeNode1, treeNode2, treeNode3 }); + var authorizationForm = new AuthorizationForm(userProvider); - treeNode1.Name = "allUsersNode"; - treeNode2.Name = "clientsNode"; - treeNode3.Name = "EmployeeNode"; - treeNode4.Name = "usersNode"; + if (authorizationForm.ShowDialog() == DialogResult.OK) + { + return authorizationForm.loginTextBox.Text; + } - treeView.Nodes.AddRange(new TreeNode[] { treeNode4 }); + return HandleAuthorizationFailure(authorizationForm.RegistrationChoice); } - private string AuthorizationUser() + private string HandleAuthorizationFailure(bool isNeedRegistration) { - var isNeedRegistration = false; - var login = string.Empty; - var authorizationFrom = new AuthorizationFrom(provider); - - if (authorizationFrom.ShowDialog() == DialogResult.OK) + if (!isNeedRegistration) { - login = authorizationFrom.LoginTextBox.Text; + Environment.Exit(0); + return string.Empty; } - else - { - isNeedRegistration = authorizationFrom.RegistrationChoice; - if (!isNeedRegistration) - { - Environment.Exit(0); - return string.Empty; - } - } + return ProcessRegistration(); + } - if (isNeedRegistration) + private string ProcessRegistration() + { + using (var registrationForm = new RegistrationForm(userProvider)) { - var registrationForm = new RegistrationForm(provider); - var registrationFormDialogResult = registrationForm.ShowDialog(); + DialogResult result = registrationForm.ShowDialog(); - if (registrationFormDialogResult == DialogResult.OK) + switch (result) { - login = registrationForm.loginTextBox.Text; - } - else if (registrationFormDialogResult == DialogResult.Cancel) - { - Application.Restart(); - } - else - { - Environment.Exit(0); + case DialogResult.OK: + return registrationForm.loginTextBox.Text; + case DialogResult.Cancel: + Application.Restart(); + break; + default: + Environment.Exit(0); + break; } } - return login; + return string.Empty; } private void RefreshUsersDataGrid() { var selectedNode = treeView.SelectedNode.Name; + var users = GetFilteredUsers(selectedNode); - listTTDataGridView.Columns.Clear(); - - switch (selectedNode) - { - case "allUsersNode": - FillUsersDataGreedView(provider.GetAllUsers()); - break; - case "clientsNode": - FillUsersDataGreedView(provider.GetAllUsers().Where(u => !u.IsEmployee).ToList()); - break; - case "EmployeeNode": - FillUsersDataGreedView(provider.GetAllUsers().Where(u => u.IsEmployee).ToList()); - break; - default: - break; - } + ClearAndSetupDataGridViewForUsers(); + FillUsersDataGridView(users); } - private void RefreshTrubleTicketsDataGrid() + private List GetFilteredUsers(string nodeName) { - var selectedNode = treeView.SelectedNode.Name; + var allUsers = userProvider.GetAll(); - if (selectedNode == "statusTrubleTicketNode") + return nodeName switch { - return; - } + TreeViewNodes.AllUsers => allUsers, + TreeViewNodes.Clients => allUsers.Where(u => !u.IsEmployee).ToList(), + TreeViewNodes.Employees => allUsers.Where(u => u.IsEmployee).ToList(), + _ => new List() + }; + } + + private void ClearAndSetupDataGridViewForUsers() + { + troubleTicketsDataGridView.Columns.Clear(); + AddUserColumnsToDataGridView(); + } - List trubleTickets = new(); + private void AddUserColumnsToDataGridView() + { + troubleTicketsDataGridView.Columns.Add("id", "ID"); + troubleTicketsDataGridView.Columns.Add("name", "Имя"); + troubleTicketsDataGridView.Columns.Add("login", "Логин"); + troubleTicketsDataGridView.Columns.Add("email", "E-Mail"); + troubleTicketsDataGridView.Columns.Add("discriminator", "Тип"); + troubleTicketsDataGridView.Columns.Add("function", "Функция"); + troubleTicketsDataGridView.Columns.Add("department", "Отдел"); + } - listTTDataGridView.Columns.Clear(); + private void FillUsersDataGridView(List users) + { + troubleTicketsDataGridView.Rows.Clear(); - if (user.IsEmployee) - { - trubleTickets = provider.GetAllTrubleTickets(); - } - else + foreach (var userData in users) { - trubleTickets = provider.GetAllTrubleTickets().Where(t => t.CreateUser == user.Id).ToList(); - } + var rowIndex = troubleTicketsDataGridView.Rows.Add(); + var row = troubleTicketsDataGridView.Rows[rowIndex]; - switch (selectedNode) - { - case "allTrubleTicket": - FillTrubleTicketsDataGreedView(trubleTickets); - break; - case "openTrubleTicket": - FillTrubleTicketsDataGreedView(trubleTickets.Where(s => s.IsSolved == false).ToList()); - break; - case "closedTrubleTicket": - FillTrubleTicketsDataGreedView(trubleTickets.Where(s => s.IsSolved == true).ToList()); - break; - case "overdueTrubleTicketNode": - FillTrubleTicketsDataGreedView(trubleTickets.Where(s => (DateTime.Now - s.Deadline).TotalSeconds > 0).ToList()); - break; - case "registeredTrubleTicketNode": - FillTrubleTicketsDataGreedView(trubleTickets.Where(s => s.Status == "Зарегистрирована").ToList()); - break; - case "workTrubleTicketNode": - FillTrubleTicketsDataGreedView(trubleTickets.Where(s => s.Status == "В работе").ToList()); - break; - case "completedTrubleTicketNode": - FillTrubleTicketsDataGreedView(trubleTickets.Where(s => s.Status == "Выполнена").ToList()); - break; - case "rejectedTrubleTicketNode": - FillTrubleTicketsDataGreedView(trubleTickets.Where(s => s.Status == "Отклонена").ToList()); - break; - default: - break; + PopulateUserRow(row, userData); } + + troubleTicketsDataGridView.ClearSelection(); } - private void FillUsersDataGreedView(List users) + private void PopulateUserRow(DataGridViewRow row, User userData) { - listTTDataGridView.Columns.Add("id", "ID"); - listTTDataGridView.Columns.Add("name", "Имя"); - listTTDataGridView.Columns.Add("login", "Логин"); - listTTDataGridView.Columns.Add("email", "E-Mail"); - listTTDataGridView.Columns.Add("discriminator", "Тип"); - listTTDataGridView.Columns.Add("function", "Функция"); - listTTDataGridView.Columns.Add("department", "Отдел"); - - listTTDataGridView.Rows.Clear(); + row.Cells[0].Value = userData.Id; + row.Cells[1].Value = userData.Name; + row.Cells[2].Value = userData.Login; + row.Cells[3].Value = userData.Email; + row.Cells[4].Value = userData.IsEmployee ? "Сотрудник" : "Клиент"; - var countRows = users.Count; - - for (int i = 0; i < countRows; i++) + if (userData.IsEmployee) { - listTTDataGridView.Rows.Add(); - listTTDataGridView.Rows[i].Cells[0].Value = users[i].Id; - listTTDataGridView.Rows[i].Cells[1].Value = users[i].Name; - listTTDataGridView.Rows[i].Cells[2].Value = users[i].Login; - listTTDataGridView.Rows[i].Cells[3].Value = users[i].Email; - - var userType = users[i].IsEmployee; + row.Cells[5].Value = userData.Function; + row.Cells[6].Value = userData.Department; + return; + } + + row.Cells[5].Style.BackColor = Color.Gray; + row.Cells[6].Style.BackColor = Color.Gray; + + } - listTTDataGridView.Rows[i].Cells[4].Value = userType ? "Сотрудник" : "Клиент"; + private void RefreshTroubleTicketsDataGrid() + { + var selectedNode = treeView.SelectedNode.Name; - if (userType) - { - listTTDataGridView.Rows[i].Cells[5].Value = user.Function; - listTTDataGridView.Rows[i].Cells[6].Value = user.Department; - } - else - { - listTTDataGridView.Rows[i].Cells[5].Style.BackColor = Color.Gray; - listTTDataGridView.Rows[i].Cells[6].Style.BackColor = Color.Gray; - } + if (selectedNode == TreeViewNodes.StatusTroubleTicket) + { + return; } - listTTDataGridView.ClearSelection(); + var tickets = GetFilteredTroubleTickets(selectedNode); + + ClearAndSetupDataGridViewForTickets(); + FillTroubleTicketsDataGridView(tickets); } - private void FillTrubleTicketsDataGreedView(List allTrubleTickets) + private List GetFilteredTroubleTickets(string nodeName) { - AddColumnsTrubleTicketsDataGreedView(); + var allTickets = GetAllRelevantTickets(); - listTTDataGridView.Rows.Clear(); - - var countRow = allTrubleTickets.Count; - var allUsers = provider.GetAllUsers(); - - for (int i = 0; i < countRow; i++) + return nodeName switch { - var user = allUsers.Where(u => u.Id == allTrubleTickets[i].CreateUser).FirstOrDefault(); - var resolveUser = allUsers.Where(u => u.Id == allTrubleTickets[i].ResolveUser).FirstOrDefault(); + TreeViewNodes.AllTroubleTickets => allTickets, + TreeViewNodes.OpenTroubleTickets => allTickets.Where(t => !t.IsSolved).ToList(), + TreeViewNodes.ClosedTroubleTickets => allTickets.Where(t => t.IsSolved).ToList(), + TreeViewNodes.OverdueTroubleTickets => allTickets.Where(t => DateTime.Now > t.Deadline).ToList(), + TreeViewNodes.RegisteredTroubleTickets => allTickets.Where(t => t.Status == TicketStatuses.Registered).ToList(), + TreeViewNodes.WorkTroubleTickets => allTickets.Where(t => t.Status == TicketStatuses.InProgress).ToList(), + TreeViewNodes.CompletedTroubleTickets => allTickets.Where(t => t.Status == TicketStatuses.Completed).ToList(), + TreeViewNodes.RejectedTroubleTickets => allTickets.Where(t => t.Status == TicketStatuses.Rejected).ToList(), + _ => new List() + }; + } - listTTDataGridView.Rows.Add(); + private List GetAllRelevantTickets() + { + return user.IsEmployee + ? troubleTicketProvider.GetAll() + : troubleTicketProvider.GetAll().Where(t => t.CreateUserId == user.Id).ToList(); + } - listTTDataGridView.Rows[i].Cells[0].Value = allTrubleTickets[i].Id; + private void ClearAndSetupDataGridViewForTickets() + { + troubleTicketsDataGridView.Columns.Clear(); + AddTicketColumnsToDataGridView(); + } - if (allTrubleTickets[i].IsSolved) - { - listTTDataGridView.Rows[i].Cells[1].Value = "Да"; - listTTDataGridView.Rows[i].DefaultCellStyle.BackColor = allTrubleTickets[i].Status == "Выполнена" ? Color.LightGreen : Color.LightGray; - } - else - { - listTTDataGridView.Rows[i].Cells[1].Value = "Нет"; + private void FillTroubleTicketsDataGridView(List tickets) + { + troubleTicketsDataGridView.Rows.Clear(); + var allUsers = userProvider.GetAll(); - if ((DateTime.Now - allTrubleTickets[i].Deadline).TotalSeconds > 0) - { - listTTDataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightSalmon; - } + foreach (var ticket in tickets) + { + var rowIndex = troubleTicketsDataGridView.Rows.Add(); + var row = troubleTicketsDataGridView.Rows[rowIndex]; - if (allTrubleTickets[i].Status == "В работе") - { - listTTDataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightYellow; - } - } + PopulateTicketRow(row, ticket, allUsers); + } - listTTDataGridView.Rows[i].Cells[2].Value = allTrubleTickets[i].Status; + troubleTicketsDataGridView.ClearSelection(); + } - if (allTrubleTickets[i].Text.Length > 50) - { - listTTDataGridView.Rows[i].Cells[3].Value = $"{allTrubleTickets[i].Text.Substring(0, 47)}..."; - } - else - { - listTTDataGridView.Rows[i].Cells[3].Value = allTrubleTickets[i].Text; - } + private void PopulateTicketRow(DataGridViewRow row, TroubleTicket ticket, List allUsers) + { + var createUser = allUsers.FirstOrDefault(u => u.Id == ticket.CreateUserId); + var resolveUser = allUsers.FirstOrDefault(u => u.Id == ticket.ResolveUser); + + row.Cells[0].Value = ticket.Id; + row.Cells[1].Value = ticket.IsSolved ? "Да" : "Нет"; + row.Cells[2].Value = ticket.Status; + row.Cells[3].Value = GetPreviewText(ticket.Text); + row.Cells[4].Value = ticket.Resolve; + row.Cells[5].Value = resolveUser?.Name ?? string.Empty; + row.Cells[6].Value = ticket.Created; + row.Cells[7].Value = ticket.ResolveTime; + row.Cells[8].Value = ticket.Deadline; + row.Cells[9].Value = $"{createUser?.Name} \\ {createUser?.Email}"; + + ApplyRowStylingBasedOnTicket(row, ticket); + } - listTTDataGridView.Rows[i].Cells[4].Value = allTrubleTickets[i].Resolve; - listTTDataGridView.Rows[i].Cells[5].Value = resolveUser != null ? resolveUser.Name : string.Empty; - listTTDataGridView.Rows[i].Cells[6].Value = allTrubleTickets[i].Created; - listTTDataGridView.Rows[i].Cells[7].Value = allTrubleTickets[i].ResolveTime; - listTTDataGridView.Rows[i].Cells[8].Value = allTrubleTickets[i].Deadline; - listTTDataGridView.Rows[i].Cells[9].Value = $"{user.Name} \\ {user.Email}"; + private void ApplyRowStylingBasedOnTicket(DataGridViewRow row, TroubleTicket ticket) + { + if (ticket.IsSolved) + { + row.DefaultCellStyle.BackColor = ticket.Status == TicketStatuses.Completed + ? Color.LightGreen + : Color.LightGray; + return; } + if (DateTime.Now > ticket.Deadline) + { + row.DefaultCellStyle.BackColor = Color.LightSalmon; + return; + } + + if (ticket.Status == TicketStatuses.InProgress) + { + row.DefaultCellStyle.BackColor = Color.LightYellow; + return; + } + row.DefaultCellStyle.BackColor = Color.Empty; + } - listTTDataGridView.ClearSelection(); + private string GetPreviewText(string text) + { + if (text.Length > UIConstants.TextPreviewLength) + { + return $"{text.Substring(0, UIConstants.TextPreviewEllipsisLength)}..."; + } + return text; } - private void AddColumnsTrubleTicketsDataGreedView() + private void AddTicketColumnsToDataGridView() { - listTTDataGridView.Columns.Add("id", "ID"); - listTTDataGridView.Columns.Add("isSolved", "Решён"); - listTTDataGridView.Columns.Add("status", "Статус"); - listTTDataGridView.Columns.Add("text", "Текст"); - listTTDataGridView.Columns.Add("resolve", "Решение"); - listTTDataGridView.Columns.Add("resolveUser", "Решил"); - listTTDataGridView.Columns.Add("created", "Создано"); - listTTDataGridView.Columns.Add("resolveDate", "Дата решения"); - listTTDataGridView.Columns.Add("deadline", "Крайний срок"); - listTTDataGridView.Columns.Add("userCreate", "Кем создано"); + troubleTicketsDataGridView.Columns.Add("id", "ID"); + troubleTicketsDataGridView.Columns.Add("isSolved", "Решён"); + troubleTicketsDataGridView.Columns.Add("status", "Статус"); + troubleTicketsDataGridView.Columns.Add("text", "Текст"); + troubleTicketsDataGridView.Columns.Add("resolve", "Решение"); + troubleTicketsDataGridView.Columns.Add("resolveUser", "Решил"); + troubleTicketsDataGridView.Columns.Add("created", "Создано"); + troubleTicketsDataGridView.Columns.Add("resolveDate", "Дата решения"); + troubleTicketsDataGridView.Columns.Add("deadline", "Крайний срок"); + troubleTicketsDataGridView.Columns.Add("userCreate", "Кем создано"); } } } \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/Program.cs b/HelpDesk/HelpDeskWinFormsApp/Program.cs index 9dddfda..d6fbfa7 100644 --- a/HelpDesk/HelpDeskWinFormsApp/Program.cs +++ b/HelpDesk/HelpDeskWinFormsApp/Program.cs @@ -1,6 +1,9 @@ -using HelpDesk.Common.Application; -using System; +using System; +using System.IO; using System.Windows.Forms; +using HelpDesk.Common; +using HelpDesk.Common.Application; +using HelpDesk.Common.System; namespace HelpDeskWinFormsApp { @@ -15,7 +18,42 @@ static void Main() // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new MainForm(new ApplicationDIController())); - } + + CheckAndEncryptOldFiles(); + + var controller = new ApplicationDIController(); + controller.Start(); + + var userProvider = SystemManager.Get(); + var ticketProvider = SystemManager.Get(); + + Application.Run(new MainForm(controller, userProvider, ticketProvider)); + } + static void CheckAndEncryptOldFiles() + { + string[] files = { "users.json", "troubleTicket.json" }; + + foreach (var file in files) + { + if (File.Exists(file)) + { + try + { + string content = File.ReadAllText(file); + + if (content.Trim().StartsWith("[") || content.Trim().StartsWith("{")) + { + File.Copy(file, file + ".backup", true); + + FileProvider.Put(file, content); + } + } + catch + { + + } + } + } + } } } \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.Designer.cs index 15b8f55..612437e 100644 --- a/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.Designer.cs +++ b/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.Designer.cs @@ -28,185 +28,195 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.label4 = new System.Windows.Forms.Label(); - this.nameTextBox = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.loginTextBox = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.passwordTextBox = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.emailTextBox = new System.Windows.Forms.TextBox(); - this.registrationButton = new System.Windows.Forms.Button(); - this.cancelButton = new System.Windows.Forms.Button(); - this.exitButton = new System.Windows.Forms.Button(); - this.label5 = new System.Windows.Forms.Label(); - this.replyPasswordTextBox = new System.Windows.Forms.TextBox(); - this.SuspendLayout(); - // - // label4 - // - this.label4.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label4.Location = new System.Drawing.Point(12, 5); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(279, 30); - this.label4.TabIndex = 0; - this.label4.Text = "&Имя"; - this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + nameLabel = new System.Windows.Forms.Label(); + nameTextBox = new System.Windows.Forms.TextBox(); + loginLabel = new System.Windows.Forms.Label(); + loginTextBox = new System.Windows.Forms.TextBox(); + passwordLabel = new System.Windows.Forms.Label(); + passwordTextBox = new System.Windows.Forms.TextBox(); + emailLabel = new System.Windows.Forms.Label(); + emailTextBox = new System.Windows.Forms.TextBox(); + registrationButton = new System.Windows.Forms.Button(); + cancelButton = new System.Windows.Forms.Button(); + exitButton = new System.Windows.Forms.Button(); + replyPasswordLabel = new System.Windows.Forms.Label(); + replyPasswordTextBox = new System.Windows.Forms.TextBox(); + SuspendLayout(); + // + // nameLabel + // + nameLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + nameLabel.Location = new System.Drawing.Point(14, 7); + nameLabel.Name = "nameLabel"; + nameLabel.Size = new System.Drawing.Size(319, 40); + nameLabel.TabIndex = 0; + nameLabel.Text = "&Имя"; + nameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // nameTextBox // - this.nameTextBox.Location = new System.Drawing.Point(12, 38); - this.nameTextBox.Name = "nameTextBox"; - this.nameTextBox.Size = new System.Drawing.Size(279, 23); - this.nameTextBox.TabIndex = 1; + nameTextBox.Location = new System.Drawing.Point(14, 51); + nameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + nameTextBox.Name = "nameTextBox"; + nameTextBox.Size = new System.Drawing.Size(318, 27); + nameTextBox.TabIndex = 1; // - // label1 + // loginLabel // - this.label1.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label1.Location = new System.Drawing.Point(12, 64); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(279, 30); - this.label1.TabIndex = 2; - this.label1.Text = "&Логин"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + loginLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + loginLabel.Location = new System.Drawing.Point(14, 85); + loginLabel.Name = "loginLabel"; + loginLabel.Size = new System.Drawing.Size(319, 40); + loginLabel.TabIndex = 2; + loginLabel.Text = "&Логин"; + loginLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // loginTextBox // - this.loginTextBox.Location = new System.Drawing.Point(12, 97); - this.loginTextBox.Name = "loginTextBox"; - this.loginTextBox.Size = new System.Drawing.Size(279, 23); - this.loginTextBox.TabIndex = 3; + loginTextBox.Location = new System.Drawing.Point(14, 129); + loginTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + loginTextBox.Name = "loginTextBox"; + loginTextBox.Size = new System.Drawing.Size(318, 27); + loginTextBox.TabIndex = 3; // - // label2 + // passwordLabel // - this.label2.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label2.Location = new System.Drawing.Point(12, 123); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(279, 30); - this.label2.TabIndex = 4; - this.label2.Text = "&Пароль"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + passwordLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + passwordLabel.Location = new System.Drawing.Point(14, 164); + passwordLabel.Name = "passwordLabel"; + passwordLabel.Size = new System.Drawing.Size(319, 40); + passwordLabel.TabIndex = 4; + passwordLabel.Text = "&Пароль"; + passwordLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // passwordTextBox // - this.passwordTextBox.Location = new System.Drawing.Point(12, 156); - this.passwordTextBox.Name = "passwordTextBox"; - this.passwordTextBox.Size = new System.Drawing.Size(279, 23); - this.passwordTextBox.TabIndex = 5; - this.passwordTextBox.UseSystemPasswordChar = true; + passwordTextBox.Location = new System.Drawing.Point(14, 208); + passwordTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + passwordTextBox.Name = "passwordTextBox"; + passwordTextBox.Size = new System.Drawing.Size(318, 27); + passwordTextBox.TabIndex = 5; + passwordTextBox.UseSystemPasswordChar = true; // - // label3 + // emailLabel // - this.label3.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label3.Location = new System.Drawing.Point(12, 241); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(279, 30); - this.label3.TabIndex = 8; - this.label3.Text = "&E-Mail"; - this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + emailLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + emailLabel.Location = new System.Drawing.Point(14, 321); + emailLabel.Name = "emailLabel"; + emailLabel.Size = new System.Drawing.Size(319, 40); + emailLabel.TabIndex = 8; + emailLabel.Text = "&E-Mail"; + emailLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // emailTextBox // - this.emailTextBox.Location = new System.Drawing.Point(12, 274); - this.emailTextBox.Name = "emailTextBox"; - this.emailTextBox.Size = new System.Drawing.Size(279, 23); - this.emailTextBox.TabIndex = 9; + emailTextBox.Location = new System.Drawing.Point(14, 365); + emailTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + emailTextBox.Name = "emailTextBox"; + emailTextBox.Size = new System.Drawing.Size(318, 27); + emailTextBox.TabIndex = 9; // // registrationButton // - this.registrationButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.registrationButton.Location = new System.Drawing.Point(12, 316); - this.registrationButton.Name = "registrationButton"; - this.registrationButton.Size = new System.Drawing.Size(279, 33); - this.registrationButton.TabIndex = 10; - this.registrationButton.Text = "&Регистрация"; - this.registrationButton.UseVisualStyleBackColor = true; + registrationButton.DialogResult = System.Windows.Forms.DialogResult.OK; + registrationButton.Location = new System.Drawing.Point(14, 421); + registrationButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + registrationButton.Name = "registrationButton"; + registrationButton.Size = new System.Drawing.Size(319, 44); + registrationButton.TabIndex = 10; + registrationButton.Text = "&Регистрация"; + registrationButton.UseVisualStyleBackColor = true; + registrationButton.Click += RegistrationButton_Click; // // cancelButton // - this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Location = new System.Drawing.Point(12, 355); - this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(279, 33); - this.cancelButton.TabIndex = 11; - this.cancelButton.Text = "&Отмена"; - this.cancelButton.UseVisualStyleBackColor = true; + cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + cancelButton.Location = new System.Drawing.Point(14, 473); + cancelButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + cancelButton.Name = "cancelButton"; + cancelButton.Size = new System.Drawing.Size(319, 44); + cancelButton.TabIndex = 11; + cancelButton.Text = "&Отмена"; + cancelButton.UseVisualStyleBackColor = true; // // exitButton // - this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Abort; - this.exitButton.Location = new System.Drawing.Point(12, 394); - this.exitButton.Name = "exitButton"; - this.exitButton.Size = new System.Drawing.Size(279, 33); - this.exitButton.TabIndex = 12; - this.exitButton.Text = "Выход"; - this.exitButton.UseVisualStyleBackColor = true; - // - // label5 - // - this.label5.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label5.Location = new System.Drawing.Point(12, 182); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(279, 30); - this.label5.TabIndex = 6; - this.label5.Text = "Повторите пароль"; - this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + exitButton.DialogResult = System.Windows.Forms.DialogResult.Abort; + exitButton.Location = new System.Drawing.Point(14, 525); + exitButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + exitButton.Name = "exitButton"; + exitButton.Size = new System.Drawing.Size(319, 44); + exitButton.TabIndex = 12; + exitButton.Text = "Выход"; + exitButton.UseVisualStyleBackColor = true; + // + // replyPasswordLabel + // + replyPasswordLabel.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + replyPasswordLabel.Location = new System.Drawing.Point(14, 243); + replyPasswordLabel.Name = "replyPasswordLabel"; + replyPasswordLabel.Size = new System.Drawing.Size(319, 40); + replyPasswordLabel.TabIndex = 6; + replyPasswordLabel.Text = "Повторите пароль"; + replyPasswordLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // replyPasswordTextBox // - this.replyPasswordTextBox.Location = new System.Drawing.Point(12, 215); - this.replyPasswordTextBox.Name = "replyPasswordTextBox"; - this.replyPasswordTextBox.Size = new System.Drawing.Size(279, 23); - this.replyPasswordTextBox.TabIndex = 7; - this.replyPasswordTextBox.UseSystemPasswordChar = true; + replyPasswordTextBox.Location = new System.Drawing.Point(14, 287); + replyPasswordTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + replyPasswordTextBox.Name = "replyPasswordTextBox"; + replyPasswordTextBox.Size = new System.Drawing.Size(318, 27); + replyPasswordTextBox.TabIndex = 7; + replyPasswordTextBox.UseSystemPasswordChar = true; // // RegistrationForm // - this.AcceptButton = this.registrationButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.cancelButton; - this.ClientSize = new System.Drawing.Size(303, 437); - this.ControlBox = false; - this.Controls.Add(this.replyPasswordTextBox); - this.Controls.Add(this.label5); - this.Controls.Add(this.exitButton); - this.Controls.Add(this.cancelButton); - this.Controls.Add(this.registrationButton); - this.Controls.Add(this.nameTextBox); - this.Controls.Add(this.label4); - this.Controls.Add(this.loginTextBox); - this.Controls.Add(this.label1); - this.Controls.Add(this.passwordTextBox); - this.Controls.Add(this.label2); - this.Controls.Add(this.emailTextBox); - this.Controls.Add(this.label3); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "RegistrationForm"; - this.ShowIcon = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "HelpDesk Регистрация"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.RegistrationForm_FormClosing); - this.ResumeLayout(false); - this.PerformLayout(); + AcceptButton = registrationButton; + AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + CancelButton = cancelButton; + ClientSize = new System.Drawing.Size(346, 583); + ControlBox = false; + Controls.Add(replyPasswordTextBox); + Controls.Add(replyPasswordLabel); + Controls.Add(exitButton); + Controls.Add(cancelButton); + Controls.Add(registrationButton); + Controls.Add(nameTextBox); + Controls.Add(nameLabel); + Controls.Add(loginTextBox); + Controls.Add(loginLabel); + Controls.Add(passwordTextBox); + Controls.Add(passwordLabel); + Controls.Add(emailTextBox); + Controls.Add(emailLabel); + Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + MaximizeBox = false; + MinimizeBox = false; + Name = "RegistrationForm"; + ShowIcon = false; + StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + Text = "HelpDesk Регистрация"; + FormClosing += RegistrationForm_FormClosing; + ResumeLayout(false); + PerformLayout(); } #endregion - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label loginLabel; + private System.Windows.Forms.Label passwordLabel; private System.Windows.Forms.TextBox passwordTextBox; - private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label emailLabel; private System.Windows.Forms.TextBox emailTextBox; - private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label nameLabel; private System.Windows.Forms.TextBox nameTextBox; private System.Windows.Forms.Button registrationButton; private System.Windows.Forms.Button cancelButton; private System.Windows.Forms.Button exitButton; public System.Windows.Forms.TextBox loginTextBox; - private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label replyPasswordLabel; private System.Windows.Forms.TextBox replyPasswordTextBox; } } \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.cs b/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.cs index f5738ed..c9905d9 100644 --- a/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.cs +++ b/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.cs @@ -1,19 +1,71 @@ -using HelpDesk.Common; -using HelpDesk.Common.Models; -using System.Linq; + using System.Windows.Forms; +using HelpDesk.Common; +using HelpDesk.Common.Models; namespace HelpDeskWinFormsApp { public partial class RegistrationForm : Form { - private readonly IProvider provider; + private readonly IUserProvider userProvider; - public RegistrationForm(IProvider provider) + public RegistrationForm(IUserProvider userProvider) { InitializeComponent(); - this.provider = provider; + this.userProvider = userProvider; + } + + private bool ValidateAllFields() + { + var nameValidation = InputValidator.ValidateName(nameTextBox.Text); + if (!nameValidation.IsValid) + { + MessageBox.Show(nameValidation.Message, "Ошибка валидации", + MessageBoxButtons.OK, MessageBoxIcon.Error); + nameTextBox.Focus(); + return false; + } + + var loginValidation = InputValidator.ValidateLogin(loginTextBox.Text); + if (!loginValidation.IsValid) + { + MessageBox.Show(loginValidation.Message, "Ошибка валидации", + MessageBoxButtons.OK, MessageBoxIcon.Error); + loginTextBox.Focus(); + return false; + } + + var passwordValidation = InputValidator.ValidatePassword(passwordTextBox.Text); + if (!passwordValidation.IsValid) + { + MessageBox.Show(passwordValidation.Message, "Ошибка валидации", + MessageBoxButtons.OK, MessageBoxIcon.Error); + passwordTextBox.Focus(); + return false; + } + + var matchValidation = InputValidator.ValidatePasswordMatch( + passwordTextBox.Text, replyPasswordTextBox.Text); + + if (!matchValidation.IsValid) + { + MessageBox.Show(matchValidation.Message, "Ошибка валидации", + MessageBoxButtons.OK, MessageBoxIcon.Error); + replyPasswordTextBox.Focus(); + return false; + } + + var emailValidation = InputValidator.ValidateEmail(emailTextBox.Text); + if (!emailValidation.IsValid) + { + MessageBox.Show(emailValidation.Message, "Ошибка валидации", + MessageBoxButtons.OK, MessageBoxIcon.Error); + emailTextBox.Focus(); + return false; + } + + return true; } private void RegistrationForm_FormClosing(object sender, FormClosingEventArgs e) @@ -22,6 +74,11 @@ private void RegistrationForm_FormClosing(object sender, FormClosingEventArgs e) { return; } + if (!ValidateAllFields()) + { + e.Cancel = true; + return; + } var user = new User { @@ -31,7 +88,19 @@ private void RegistrationForm_FormClosing(object sender, FormClosingEventArgs e) Email = emailTextBox.Text }; - provider.AddUser(user); + userProvider.Add(user); + } + + private void RegistrationButton_Click(object sender, System.EventArgs e) + { + if (!ValidateAllFields()) + { + DialogResult = DialogResult.None; + return; + } + + DialogResult = DialogResult.OK; + Close(); } } } diff --git a/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.resx b/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.resx index f298a7b..8b2ff64 100644 --- a/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.resx +++ b/HelpDesk/HelpDeskWinFormsApp/RegistrationForm.resx @@ -1,4 +1,64 @@ - + + + diff --git a/HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.Designer.cs new file mode 100644 index 0000000..3aae98a --- /dev/null +++ b/HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.Designer.cs @@ -0,0 +1,185 @@ +namespace HelpDeskWinFormsApp +{ + partial class TroubleTicketForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.userCreateLabel = new System.Windows.Forms.Label(); + this.userCreateTextBox = new System.Windows.Forms.TextBox(); + this.troubleTicketRichLabel = new System.Windows.Forms.Label(); + this.troubleTicketRichTextBox = new System.Windows.Forms.RichTextBox(); + this.resolveRichLabel = new System.Windows.Forms.Label(); + this.resolveRichTextBox = new System.Windows.Forms.RichTextBox(); + this.saveButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.statusLabel = new System.Windows.Forms.Label(); + this.statusTroubleTicketComboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // userCreateLabel + // + this.userCreateLabel.AutoSize = true; + this.userCreateLabel.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.userCreateLabel.Location = new System.Drawing.Point(12, 9); + this.userCreateLabel.Name = "userCreateLabel"; + this.userCreateLabel.Size = new System.Drawing.Size(89, 19); + this.userCreateLabel.TabIndex = 0; + this.userCreateLabel.Text = "Кем создано"; + // + // userCreateTextBox + // + this.userCreateTextBox.Location = new System.Drawing.Point(12, 31); + this.userCreateTextBox.Name = "userCreateTextBox"; + this.userCreateTextBox.ReadOnly = true; + this.userCreateTextBox.Size = new System.Drawing.Size(380, 23); + this.userCreateTextBox.TabIndex = 1; + // + // troubleTicketRichLabel + // + this.troubleTicketRichLabel.AutoSize = true; + this.troubleTicketRichLabel.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.troubleTicketRichLabel.Location = new System.Drawing.Point(12, 57); + this.troubleTicketRichLabel.Name = "troubleTicketRichLabel"; + this.troubleTicketRichLabel.Size = new System.Drawing.Size(119, 19); + this.troubleTicketRichLabel.TabIndex = 2; + this.troubleTicketRichLabel.Text = "Текст обращения"; + // + // troubleTicketRichTextBox + // + this.troubleTicketRichTextBox.Location = new System.Drawing.Point(12, 79); + this.troubleTicketRichTextBox.Name = "trubleTicketRichTextBox"; + this.troubleTicketRichTextBox.ReadOnly = true; + this.troubleTicketRichTextBox.Size = new System.Drawing.Size(380, 244); + this.troubleTicketRichTextBox.TabIndex = 3; + this.troubleTicketRichTextBox.Text = ""; + // + // resolveRichLabel + // + this.resolveRichLabel.AutoSize = true; + this.resolveRichLabel.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.resolveRichLabel.Location = new System.Drawing.Point(12, 326); + this.resolveRichLabel.Name = "resolveRichLabel"; + this.resolveRichLabel.Size = new System.Drawing.Size(65, 19); + this.resolveRichLabel.TabIndex = 4; + this.resolveRichLabel.Text = "Решение"; + // + // resolveRichTextBox + // + this.resolveRichTextBox.Location = new System.Drawing.Point(12, 348); + this.resolveRichTextBox.Name = "resolveRichTextBox"; + this.resolveRichTextBox.Size = new System.Drawing.Size(380, 165); + this.resolveRichTextBox.TabIndex = 5; + this.resolveRichTextBox.Text = ""; + // + // saveButton + // + this.saveButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.saveButton.Location = new System.Drawing.Point(12, 582); + this.saveButton.Name = "saveButton"; + this.saveButton.Size = new System.Drawing.Size(380, 37); + this.saveButton.TabIndex = 6; + this.saveButton.Text = "&Сохранить"; + this.saveButton.UseVisualStyleBackColor = true; + // + // cancelButton + // + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(12, 625); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(380, 37); + this.cancelButton.TabIndex = 7; + this.cancelButton.Text = "&Закрыть"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // statusLabel + // + this.statusLabel.AutoSize = true; + this.statusLabel.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.statusLabel.Location = new System.Drawing.Point(12, 516); + this.statusLabel.Name = "statusLabel"; + this.statusLabel.Size = new System.Drawing.Size(50, 19); + this.statusLabel.TabIndex = 8; + this.statusLabel.Text = "Статус"; + // + // statusTroubleTicketComboBox + // + this.statusTroubleTicketComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.statusTroubleTicketComboBox.FormattingEnabled = true; + this.statusTroubleTicketComboBox.Items.AddRange(new object[] { + "Зарегистрирована", + "В работе", + "Выполнена", + "Отклонена"}); + this.statusTroubleTicketComboBox.Location = new System.Drawing.Point(12, 538); + this.statusTroubleTicketComboBox.Name = "statusTroubleTicketComboBox"; + this.statusTroubleTicketComboBox.Size = new System.Drawing.Size(380, 23); + this.statusTroubleTicketComboBox.TabIndex = 9; + // + // TroubleTicketForm + // + this.AcceptButton = this.saveButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(404, 673); + this.ControlBox = false; + this.Controls.Add(this.statusTroubleTicketComboBox); + this.Controls.Add(this.statusLabel); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.saveButton); + this.Controls.Add(this.resolveRichTextBox); + this.Controls.Add(this.resolveRichLabel); + this.Controls.Add(this.troubleTicketRichTextBox); + this.Controls.Add(this.troubleTicketRichLabel); + this.Controls.Add(this.userCreateTextBox); + this.Controls.Add(this.userCreateLabel); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "TroubleTicketForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "TroubleTicketForm"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TroubleTicketForm_FormClosing); + this.Shown += new System.EventHandler(this.TroubleTicketForm_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label userCreateLabel; + private System.Windows.Forms.TextBox userCreateTextBox; + private System.Windows.Forms.Label troubleTicketRichLabel; + private System.Windows.Forms.RichTextBox troubleTicketRichTextBox; + private System.Windows.Forms.Label resolveRichLabel; + private System.Windows.Forms.RichTextBox resolveRichTextBox; + private System.Windows.Forms.Button saveButton; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.Label statusLabel; + private System.Windows.Forms.ComboBox statusTroubleTicketComboBox; + } +} \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.cs b/HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.cs new file mode 100644 index 0000000..7492911 --- /dev/null +++ b/HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.cs @@ -0,0 +1,93 @@ +using HelpDesk.Common; +using HelpDesk.Common.Models; +using System.Windows.Forms; +using HelpDesk.Common.Constants; + +namespace HelpDeskWinFormsApp +{ + public partial class TroubleTicketForm : Form + { + private int ticketId; + private TroubleTicket troubleTicket; + private User userCreate; + private bool isEmployee; + private int resolveUserId; + private string lastStatus; + private readonly ITroubleTicketProvider troubleTicketProvider; + private readonly IUserProvider userProvider; + + public TroubleTicketForm(int ticketId, bool isEmployee, int resolveUserId, ITroubleTicketProvider troubleTicketProvider, IUserProvider userProvider) + { + InitializeComponent(); + this.ticketId = ticketId; + this.isEmployee = isEmployee; + this.resolveUserId = resolveUserId; + this.troubleTicketProvider = troubleTicketProvider; + this.userProvider = userProvider; + } + + private void TroubleTicketForm_Shown(object sender, System.EventArgs e) + { + troubleTicket = troubleTicketProvider.Get(ticketId); + userCreate = userProvider.Get(troubleTicket.CreateUserId); + lastStatus = troubleTicket.Status; + + Text = $"HelpDesk. Заяка №{troubleTicket.Id}"; + userCreateTextBox.Text = $"{userCreate.Name} \\ {userCreate.Email}"; + troubleTicketRichTextBox.Text = troubleTicket.Text; + statusTroubleTicketComboBox.Text = troubleTicket.Status; + + if (troubleTicket.Resolve != null) + { + resolveRichTextBox.Text = $"Заявка решена {troubleTicket.ResolveTime}\n\r"; + resolveRichTextBox.Text += troubleTicket.Resolve; + resolveRichTextBox.ReadOnly = true; + statusTroubleTicketComboBox.Enabled = false; + saveButton.Enabled = false; + } + + if (!isEmployee) + { + saveButton.Visible = false; + resolveRichTextBox.Enabled = false; + statusTroubleTicketComboBox.Enabled = false; + } + } + + private void TroubleTicketForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (DialogResult != DialogResult.OK) return; + var newStatus = statusTroubleTicketComboBox.Text; + + var isResolutionRequired = newStatus == TicketStatuses.Completed || + newStatus == TicketStatuses.Rejected; + if (isResolutionRequired && resolveRichTextBox.Text == string.Empty) + { + e.Cancel = true; + MessageBox.Show("Пожалуйста заполните решение.", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (newStatus == lastStatus) return; + + if (newStatus == TicketStatuses.Registered && lastStatus != TicketStatuses.Registered) + { + e.Cancel = true; + MessageBox.Show("Возврат в статус \"Зарегистрирована\" запрещён.", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (isResolutionRequired) + { + troubleTicketProvider.Resolve(troubleTicket.Id, newStatus, + resolveRichTextBox.Text, resolveUserId); + return; + } + + troubleTicketProvider.ChangeStatus(troubleTicket.Id, newStatus, resolveUserId); + + } + } +} diff --git a/HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.resx b/HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.resx similarity index 100% rename from HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.resx rename to HelpDesk/HelpDeskWinFormsApp/TroubleTicketForm.resx diff --git a/HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.Designer.cs b/HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.Designer.cs deleted file mode 100644 index fa8d46a..0000000 --- a/HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.Designer.cs +++ /dev/null @@ -1,185 +0,0 @@ -namespace HelpDeskWinFormsApp -{ - partial class TrubleTicketForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.label1 = new System.Windows.Forms.Label(); - this.userCreateTextBox = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.trubleTicketRichTextBox = new System.Windows.Forms.RichTextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.resolveRichTextBox = new System.Windows.Forms.RichTextBox(); - this.saveButton = new System.Windows.Forms.Button(); - this.cancelButton = new System.Windows.Forms.Button(); - this.label4 = new System.Windows.Forms.Label(); - this.statusTrubleTicketComboBox = new System.Windows.Forms.ComboBox(); - this.SuspendLayout(); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(89, 19); - this.label1.TabIndex = 0; - this.label1.Text = "Кем создано"; - // - // userCreateTextBox - // - this.userCreateTextBox.Location = new System.Drawing.Point(12, 31); - this.userCreateTextBox.Name = "userCreateTextBox"; - this.userCreateTextBox.ReadOnly = true; - this.userCreateTextBox.Size = new System.Drawing.Size(380, 23); - this.userCreateTextBox.TabIndex = 1; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label2.Location = new System.Drawing.Point(12, 57); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(119, 19); - this.label2.TabIndex = 2; - this.label2.Text = "Текст обращения"; - // - // trubleTicketRichTextBox - // - this.trubleTicketRichTextBox.Location = new System.Drawing.Point(12, 79); - this.trubleTicketRichTextBox.Name = "trubleTicketRichTextBox"; - this.trubleTicketRichTextBox.ReadOnly = true; - this.trubleTicketRichTextBox.Size = new System.Drawing.Size(380, 244); - this.trubleTicketRichTextBox.TabIndex = 3; - this.trubleTicketRichTextBox.Text = ""; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label3.Location = new System.Drawing.Point(12, 326); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(65, 19); - this.label3.TabIndex = 4; - this.label3.Text = "Решение"; - // - // resolveRichTextBox - // - this.resolveRichTextBox.Location = new System.Drawing.Point(12, 348); - this.resolveRichTextBox.Name = "resolveRichTextBox"; - this.resolveRichTextBox.Size = new System.Drawing.Size(380, 165); - this.resolveRichTextBox.TabIndex = 5; - this.resolveRichTextBox.Text = ""; - // - // saveButton - // - this.saveButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.saveButton.Location = new System.Drawing.Point(12, 582); - this.saveButton.Name = "saveButton"; - this.saveButton.Size = new System.Drawing.Size(380, 37); - this.saveButton.TabIndex = 6; - this.saveButton.Text = "&Сохранить"; - this.saveButton.UseVisualStyleBackColor = true; - // - // cancelButton - // - this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Location = new System.Drawing.Point(12, 625); - this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(380, 37); - this.cancelButton.TabIndex = 7; - this.cancelButton.Text = "&Закрыть"; - this.cancelButton.UseVisualStyleBackColor = true; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label4.Location = new System.Drawing.Point(12, 516); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(50, 19); - this.label4.TabIndex = 8; - this.label4.Text = "Статус"; - // - // statusTrubleTicketComboBox - // - this.statusTrubleTicketComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.statusTrubleTicketComboBox.FormattingEnabled = true; - this.statusTrubleTicketComboBox.Items.AddRange(new object[] { - "Зарегистрирована", - "В работе", - "Выполнена", - "Отклонена"}); - this.statusTrubleTicketComboBox.Location = new System.Drawing.Point(12, 538); - this.statusTrubleTicketComboBox.Name = "statusTrubleTicketComboBox"; - this.statusTrubleTicketComboBox.Size = new System.Drawing.Size(380, 23); - this.statusTrubleTicketComboBox.TabIndex = 9; - // - // TrubleTicketForm - // - this.AcceptButton = this.saveButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.cancelButton; - this.ClientSize = new System.Drawing.Size(404, 673); - this.ControlBox = false; - this.Controls.Add(this.statusTrubleTicketComboBox); - this.Controls.Add(this.label4); - this.Controls.Add(this.cancelButton); - this.Controls.Add(this.saveButton); - this.Controls.Add(this.resolveRichTextBox); - this.Controls.Add(this.label3); - this.Controls.Add(this.trubleTicketRichTextBox); - this.Controls.Add(this.label2); - this.Controls.Add(this.userCreateTextBox); - this.Controls.Add(this.label1); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "TrubleTicketForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "TrubleTicketForm"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TrubleTicketForm_FormClosing); - this.Shown += new System.EventHandler(this.TrubleTicketForm_Shown); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox userCreateTextBox; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.RichTextBox trubleTicketRichTextBox; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.RichTextBox resolveRichTextBox; - private System.Windows.Forms.Button saveButton; - private System.Windows.Forms.Button cancelButton; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.ComboBox statusTrubleTicketComboBox; - } -} \ No newline at end of file diff --git a/HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.cs b/HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.cs deleted file mode 100644 index 29d9932..0000000 --- a/HelpDesk/HelpDeskWinFormsApp/TrubleTicketForm.cs +++ /dev/null @@ -1,85 +0,0 @@ -using HelpDesk.Common; -using HelpDesk.Common.Models; -using System.Windows.Forms; - -namespace HelpDeskWinFormsApp -{ - public partial class TrubleTicketForm : Form - { - int ticketId; - TrubleTicket trubleTicket; - User userCreate; - bool isEmployee; - int resolveUserId; - string lastStatus; - private readonly IProvider provider; - - public TrubleTicketForm(int ticketId, bool isEmployee, int resolveUserId, IProvider provider) - { - InitializeComponent(); - this.ticketId = ticketId; - this.isEmployee = isEmployee; - this.resolveUserId = resolveUserId; - this.provider = provider; - } - - private void TrubleTicketForm_Shown(object sender, System.EventArgs e) - { - trubleTicket = provider.GetTrubleTicket(ticketId); - userCreate = provider.GetUser(trubleTicket.CreateUser); - lastStatus = trubleTicket.Status; - - Text = $"HelpDesk. Заяка №{trubleTicket.Id}"; - userCreateTextBox.Text = $"{userCreate.Name} \\ {userCreate.Email}"; - trubleTicketRichTextBox.Text = trubleTicket.Text; - statusTrubleTicketComboBox.Text = trubleTicket.Status; - - if (trubleTicket.Resolve != null) - { - resolveRichTextBox.Text = $"Заявка решена {trubleTicket.ResolveTime}\n\r"; - resolveRichTextBox.Text += trubleTicket.Resolve; - resolveRichTextBox.ReadOnly = true; - statusTrubleTicketComboBox.Enabled = false; - saveButton.Enabled = false; - } - - if (!isEmployee) - { - saveButton.Visible = false; - resolveRichTextBox.Enabled = false; - statusTrubleTicketComboBox.Enabled = false; - } - } - - private void TrubleTicketForm_FormClosing(object sender, FormClosingEventArgs e) - { - if (DialogResult == DialogResult.OK) - { - if (resolveRichTextBox.Text == string.Empty && (statusTrubleTicketComboBox.Text == "Выполнена" || statusTrubleTicketComboBox.Text == "Отклонена")) - { - e.Cancel = true; - MessageBox.Show("Пожалуйста заполните решение.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (statusTrubleTicketComboBox.Text != lastStatus) - { - if (statusTrubleTicketComboBox.Text == "Выполнена" || statusTrubleTicketComboBox.Text == "Отклонена") - { - provider.ResolveTrubleTicket(trubleTicket.Id, statusTrubleTicketComboBox.Text, resolveRichTextBox.Text, resolveUserId); - } - else if (statusTrubleTicketComboBox.Text == "Зарегистрирована" && lastStatus != "Зарегистрирована") - { - e.Cancel = true; - MessageBox.Show("Возврат в статус \"Зарегистрирована\" запрещён.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - else - { - provider.ChangeStatusTrubleTicket(trubleTicket.Id, statusTrubleTicketComboBox.Text, resolveUserId); - } - } - } - } - } -}