From 31d961826e419eec399d2c8e1f843f95eec37658 Mon Sep 17 00:00:00 2001 From: alisec Date: Mon, 5 Jan 2026 21:57:01 +0300 Subject: [PATCH 1/2] fix: profile edit form UX improvements and data refresh --- OpsFlow/Program.cs | 2 +- .../Services/Implementations/UserService.cs | 7 +- OpsFlow/UI/Forms/Main/MainForm.cs | 2 +- .../Forms/Management/PersonelCard.Designer.cs | 98 ++- OpsFlow/UI/Forms/Management/PersonelCard.cs | 117 +++- OpsFlow/UI/Forms/Management/PersonelCard.resx | 4 +- .../Management/PersonelListForm.Designer.cs | 144 ++--- .../UI/Forms/Management/PersonelListForm.cs | 581 +++++++++++++++++- .../UI/Forms/Management/PersonelListForm.resx | 2 +- .../Management/ProfileEditForm.Designer.cs | 84 ++- .../UI/Forms/Management/ProfileEditForm.cs | 392 +++++++++++- 11 files changed, 1222 insertions(+), 211 deletions(-) diff --git a/OpsFlow/Program.cs b/OpsFlow/Program.cs index 140ef08..aa37b01 100644 --- a/OpsFlow/Program.cs +++ b/OpsFlow/Program.cs @@ -10,7 +10,7 @@ static void Main() { DotNetEnv.Env.Load(); ApplicationConfiguration.Initialize(); - WindowManager.Run(); + WindowManager.Run(); } } } \ No newline at end of file diff --git a/OpsFlow/Services/Implementations/UserService.cs b/OpsFlow/Services/Implementations/UserService.cs index 633556b..6a867c3 100644 --- a/OpsFlow/Services/Implementations/UserService.cs +++ b/OpsFlow/Services/Implementations/UserService.cs @@ -24,6 +24,7 @@ public List GetAllUsers() return _context.Users .Include(u => u.Company) .Include(u => u.Role) + .Include(u => u.Department) .AsNoTracking() .ToList(); } @@ -43,6 +44,7 @@ public User GetUserById(int id) var user = _context.Users .Include(u => u.Company) .Include(u => u.Role) + .Include(u => u.Department) .FirstOrDefault(u => u.Id == id); if (user == null) @@ -133,6 +135,7 @@ public void UpdateUser(User user) existingUser.Phone = user.Phone; existingUser.CompanyId = user.CompanyId; existingUser.RoleId = user.RoleId; + existingUser.DepartmentId = user.DepartmentId; existingUser.IsActive = user.IsActive; existingUser.AvatarUrl = user.AvatarUrl; @@ -141,7 +144,6 @@ public void UpdateUser(User user) existingUser.Password = HashingHelper.HashPassword(user.Password); } - _context.Users.Update(existingUser); _context.SaveChanges(); } catch (NotFoundException) @@ -230,9 +232,6 @@ private void ValidateUser(User user) if (string.IsNullOrWhiteSpace(user.Email) || !user.Email.Contains("@")) throw new ValidationException("Lütfen geçerli bir e-posta adresi giriniz."); - if (user.CompanyId <= 0) - throw new ValidationException("Lütfen geçerli bir şirket seçiniz."); - if (user.RoleId <= 0) throw new ValidationException("Lütfen kullanıcı için bir rol tanımlayınız."); } diff --git a/OpsFlow/UI/Forms/Main/MainForm.cs b/OpsFlow/UI/Forms/Main/MainForm.cs index c5a46d6..251d07d 100644 --- a/OpsFlow/UI/Forms/Main/MainForm.cs +++ b/OpsFlow/UI/Forms/Main/MainForm.cs @@ -78,7 +78,7 @@ private void LoadContent(string viewName) case "Dashboard": break; case "Staff": - LoadForm(new AddPersonelForm()); + LoadForm(new PersonelListForm()); break; case "Tasks": break; diff --git a/OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs b/OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs index 3658907..958cdae 100644 --- a/OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs +++ b/OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs @@ -30,25 +30,24 @@ private void InitializeComponent() { Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges6 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges7 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PersonelCard)); Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges1 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges2 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges3 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges4 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges5 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PersonelCard)); guna2Panel1 = new Guna.UI2.WinForms.Guna2Panel(); + pictureBox2 = new PictureBox(); + pictureBox1 = new PictureBox(); lblTask = new Guna.UI2.WinForms.Guna2HtmlLabel(); btnViewProfile = new Guna.UI2.WinForms.Guna2Button(); - lblRole = new Guna.UI2.WinForms.Guna2HtmlLabel(); btnRoleBadge = new Guna.UI2.WinForms.Guna2Button(); lblName = new Guna.UI2.WinForms.Guna2HtmlLabel(); PictureBox = new Guna.UI2.WinForms.Guna2CirclePictureBox(); - pictureBox1 = new PictureBox(); - pictureBox2 = new PictureBox(); guna2Panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)PictureBox).BeginInit(); - ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)PictureBox).BeginInit(); SuspendLayout(); // // guna2Panel1 @@ -58,7 +57,6 @@ private void InitializeComponent() guna2Panel1.Controls.Add(pictureBox1); guna2Panel1.Controls.Add(lblTask); guna2Panel1.Controls.Add(btnViewProfile); - guna2Panel1.Controls.Add(lblRole); guna2Panel1.Controls.Add(btnRoleBadge); guna2Panel1.Controls.Add(lblName); guna2Panel1.Controls.Add(PictureBox); @@ -67,14 +65,34 @@ private void InitializeComponent() guna2Panel1.Location = new Point(0, 0); guna2Panel1.Name = "guna2Panel1"; guna2Panel1.ShadowDecoration.CustomizableEdges = customizableEdges7; - guna2Panel1.Size = new Size(321, 184); + guna2Panel1.Size = new Size(450, 225); guna2Panel1.TabIndex = 0; // + // pictureBox2 + // + pictureBox2.Image = (Image)resources.GetObject("pictureBox2.Image"); + pictureBox2.Location = new Point(15, 179); + pictureBox2.Name = "pictureBox2"; + pictureBox2.Size = new Size(52, 43); + pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage; + pictureBox2.TabIndex = 6; + pictureBox2.TabStop = false; + // + // pictureBox1 + // + pictureBox1.Image = (Image)resources.GetObject("pictureBox1.Image"); + pictureBox1.Location = new Point(73, 179); + pictureBox1.Name = "pictureBox1"; + pictureBox1.Size = new Size(53, 43); + pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; + pictureBox1.TabIndex = 1; + pictureBox1.TabStop = false; + // // lblTask // lblTask.BackColor = Color.Transparent; lblTask.ForeColor = Color.White; - lblTask.Location = new Point(246, 112); + lblTask.Location = new Point(365, 133); lblTask.Name = "lblTask"; lblTask.Size = new Size(32, 22); lblTask.TabIndex = 5; @@ -92,27 +110,16 @@ private void InitializeComponent() btnViewProfile.DisabledState.FillColor = Color.FromArgb(169, 169, 169); btnViewProfile.DisabledState.ForeColor = Color.FromArgb(141, 141, 141); btnViewProfile.FillColor = Color.FromArgb(48, 48, 61); - btnViewProfile.Font = new Font("Poppins", 6F, FontStyle.Regular, GraphicsUnit.Point, 162); + btnViewProfile.Font = new Font("Microsoft Sans Serif", 6F, FontStyle.Regular, GraphicsUnit.Point, 162); btnViewProfile.ForeColor = Color.White; - btnViewProfile.Location = new Point(201, 140); + btnViewProfile.Location = new Point(317, 161); btnViewProfile.Name = "btnViewProfile"; btnViewProfile.ShadowDecoration.CustomizableEdges = customizableEdges2; - btnViewProfile.Size = new Size(117, 41); + btnViewProfile.Size = new Size(130, 61); btnViewProfile.TabIndex = 4; - btnViewProfile.Text = "Profili Görüntüle"; + btnViewProfile.Text = "Profili Düzenle"; btnViewProfile.Click += btnViewProfile_Click; // - // lblRole - // - lblRole.BackColor = Color.Transparent; - lblRole.Font = new Font("Poppins", 7.8F, FontStyle.Regular, GraphicsUnit.Point, 162); - lblRole.ForeColor = Color.White; - lblRole.Location = new Point(102, 98); - lblRole.Name = "lblRole"; - lblRole.Size = new Size(30, 25); - lblRole.TabIndex = 3; - lblRole.Text = "Role"; - // // btnRoleBadge // btnRoleBadge.BorderRadius = 10; @@ -122,23 +129,23 @@ private void InitializeComponent() btnRoleBadge.DisabledState.FillColor = Color.FromArgb(169, 169, 169); btnRoleBadge.DisabledState.ForeColor = Color.FromArgb(141, 141, 141); btnRoleBadge.FillColor = Color.FromArgb(108, 92, 231); - btnRoleBadge.Font = new Font("Poppins", 10.8F, FontStyle.Regular, GraphicsUnit.Point, 162); + btnRoleBadge.Font = new Font("Microsoft Sans Serif", 10.8F, FontStyle.Regular, GraphicsUnit.Point, 162); btnRoleBadge.ForeColor = Color.White; - btnRoleBadge.Location = new Point(102, 62); + btnRoleBadge.Location = new Point(140, 66); btnRoleBadge.Name = "btnRoleBadge"; btnRoleBadge.ShadowDecoration.CustomizableEdges = customizableEdges4; - btnRoleBadge.Size = new Size(109, 30); + btnRoleBadge.Size = new Size(123, 40); btnRoleBadge.TabIndex = 2; btnRoleBadge.Text = "Role"; // // lblName // lblName.BackColor = Color.Transparent; - lblName.Font = new Font("Poppins", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); + lblName.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); lblName.ForeColor = Color.White; - lblName.Location = new Point(102, 18); + lblName.Location = new Point(140, 20); lblName.Name = "lblName"; - lblName.Size = new Size(65, 38); + lblName.Size = new Size(59, 27); lblName.TabIndex = 1; lblName.Text = "Name"; // @@ -146,34 +153,14 @@ private void InitializeComponent() // PictureBox.FillColor = Color.Black; PictureBox.ImageRotate = 0F; - PictureBox.Location = new Point(3, 3); + PictureBox.Location = new Point(15, 0); PictureBox.Name = "PictureBox"; PictureBox.ShadowDecoration.CustomizableEdges = customizableEdges5; PictureBox.ShadowDecoration.Mode = Guna.UI2.WinForms.Enums.ShadowMode.Circle; - PictureBox.Size = new Size(93, 93); + PictureBox.Size = new Size(106, 103); PictureBox.TabIndex = 0; PictureBox.TabStop = false; // - // pictureBox1 - // - pictureBox1.Image = (Image)resources.GetObject("pictureBox1.Image"); - pictureBox1.Location = new Point(55, 148); - pictureBox1.Name = "pictureBox1"; - pictureBox1.Size = new Size(31, 33); - pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; - pictureBox1.TabIndex = 1; - pictureBox1.TabStop = false; - // - // pictureBox2 - // - pictureBox2.Image = (Image)resources.GetObject("pictureBox2.Image"); - pictureBox2.Location = new Point(19, 148); - pictureBox2.Name = "pictureBox2"; - pictureBox2.Size = new Size(30, 33); - pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage; - pictureBox2.TabIndex = 6; - pictureBox2.TabStop = false; - // // PersonelCard // AutoScaleDimensions = new SizeF(8F, 20F); @@ -181,12 +168,12 @@ private void InitializeComponent() BackColor = Color.Transparent; Controls.Add(guna2Panel1); Name = "PersonelCard"; - Size = new Size(323, 185); + Size = new Size(450, 225); guna2Panel1.ResumeLayout(false); guna2Panel1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)PictureBox).EndInit(); - ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox2).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + ((System.ComponentModel.ISupportInitialize)PictureBox).EndInit(); ResumeLayout(false); } @@ -196,7 +183,6 @@ private void InitializeComponent() private Guna.UI2.WinForms.Guna2CirclePictureBox PictureBox; private Guna.UI2.WinForms.Guna2Button btnRoleBadge; private Guna.UI2.WinForms.Guna2HtmlLabel lblName; - private Guna.UI2.WinForms.Guna2HtmlLabel lblRole; private Guna.UI2.WinForms.Guna2Button btnViewProfile; private Guna.UI2.WinForms.Guna2HtmlLabel lblTask; private PictureBox pictureBox2; diff --git a/OpsFlow/UI/Forms/Management/PersonelCard.cs b/OpsFlow/UI/Forms/Management/PersonelCard.cs index 609da29..d30cb3f 100644 --- a/OpsFlow/UI/Forms/Management/PersonelCard.cs +++ b/OpsFlow/UI/Forms/Management/PersonelCard.cs @@ -1,22 +1,90 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; +using OpsFlow.Core.Models; +using OpsFlow.Core.Services; +using OpsFlow.Services.Implementations; namespace OpsFlow.UI.Forms.Management; public partial class PersonelCard : UserControl { + private User? _user; + public PersonelCard() { InitializeComponent(); + this.Margin = new Padding(35, 35, 35, 35); + } + + public void SetUserData(User user) + { + _user = user; + + lblName.Text = $"{user.Name} {user.Surname}"; + + string departmentName = user.Department?.DepartmentName ?? "Departman Yok"; + btnRoleBadge.Text = departmentName; + + Size textSize = TextRenderer.MeasureText(departmentName, btnRoleBadge.Font); + int requiredWidth = textSize.Width + 24; + int maxWidth = 215; + btnRoleBadge.Width = Math.Min(requiredWidth, maxWidth); + + LoadAvatarAsync(user.AvatarUrl); + } + + private async void LoadAvatarAsync(string? avatarUrl) + { + if (string.IsNullOrWhiteSpace(avatarUrl)) + { + PictureBox.Image = null; + return; + } + + try + { + if (Uri.TryCreate(avatarUrl, UriKind.Absolute, out Uri? uri) && + (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)) + { + using (HttpClient client = new HttpClient()) + { + byte[] imageData = await client.GetByteArrayAsync(uri); + using (MemoryStream ms = new MemoryStream(imageData)) + { + PictureBox.Image = Image.FromStream(ms); + } + } + } + else + { + string baseDir = AppDomain.CurrentDomain.BaseDirectory; + string[] possiblePaths = { + Path.Combine(baseDir, "Resources", "Uploads", avatarUrl), + Path.Combine(baseDir, "..", "..", "..", "Resources", "Uploads", avatarUrl), + Path.Combine(baseDir, "..", "..", "Resources", "Uploads", avatarUrl), + avatarUrl + }; + + foreach (string path in possiblePaths) + { + if (File.Exists(path)) + { + PictureBox.Image = Image.FromFile(path); + return; + } + } + + PictureBox.Image = null; + } + } + catch + { + PictureBox.Image = null; + } } - private void btnViewProfile_Click(object sender, EventArgs e) + private async void btnViewProfile_Click(object sender, EventArgs e) { + if (_user == null) return; + if (this.FindForm() is Form anaForm) { Form dimmer = new Form(); @@ -27,13 +95,42 @@ private void btnViewProfile_Click(object sender, EventArgs e) dimmer.StartPosition = FormStartPosition.Manual; dimmer.Location = anaForm.Location; dimmer.Size = anaForm.Size; - using (ProfileEditForm popup = new ProfileEditForm()) + using (ProfileEditForm popup = new ProfileEditForm(_user)) { popup.StartPosition = FormStartPosition.CenterParent; dimmer.Show(anaForm); - popup.ShowDialog(dimmer); + DialogResult result = popup.ShowDialog(dimmer); dimmer.Close(); + + // Eğer kullanıcı bilgileri güncellendiyse, kartı yeniden yükle + if (result == DialogResult.OK) + { + await RefreshUserDataAsync(); + } } } } + + private async Task RefreshUserDataAsync() + { + if (_user == null) return; + + try + { + using var context = OpsFlow.Core.Services.DatabaseManager.CreateContext(); + var userService = new OpsFlow.Services.Implementations.UserService(context); + + // Güncel kullanıcı bilgilerini veritabanından çek + var updatedUser = userService.GetUserById(_user.Id); + if (updatedUser != null) + { + // Kartı güncel verilerle yeniden yükle + SetUserData(updatedUser); + } + } + catch + { + // Hata durumunda sessizce devam et + } + } } diff --git a/OpsFlow/UI/Forms/Management/PersonelCard.resx b/OpsFlow/UI/Forms/Management/PersonelCard.resx index c9652cd..8e910fa 100644 --- a/OpsFlow/UI/Forms/Management/PersonelCard.resx +++ b/OpsFlow/UI/Forms/Management/PersonelCard.resx @@ -121,7 +121,7 @@ iVBORw0KGgoAAAANSUhEUgAAACgAAAArCAYAAAAKasrDAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL - EgAACxIB0t1+/AAAAnBJREFUWEftmf1RwzAMxRmBERihI3SEblA2gA3KBu0GZQPYgBEYgRE6wuNeeWoV + DgAACw4BQL7hQQAAAnBJREFUWEftmf1RwzAMxRmBERihI3SEblA2gA3KBu0GZQPYgBEYgRE6wuNeeWoV xXHsNB/9g99d7nK267zIsiK5Dw8FAHgEsAZwAPAN4IR6fgB8aY51fMYgJGwnQZz8BcCK7XFsHwCe3EtS LK9tHFeMxFDYkZPH/luRWL40hdbND2CvH65i39gAeJYhXmNfElnsfcgyDkXLT4PsYl8DWe4jts+BE5n2 S5maA2azXEQbsO2TTn2ds04AgDduntjIUHJsNC6IjHWNlfdiPYM7+mJFAJuWSRdGH4i//aDIXhaDZkRB @@ -137,7 +137,7 @@ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL - EgAACxIB0t1+/AAAAaVJREFUWEe9luFRwzAMhTsCI3SEjtAN6AawAWwAG8AG7QYdgREYoSMwwuMeJ909 + DgAACw4BQL7hQQAAAaVJREFUWEe9luFRwzAMhTsCI3SEjtAN6AawAWwAG8AG7QYdgREYoSMwwuMeJ909 XhwncZ18f3KNXD9ZkqXsdgaAA4BvAD8A3ty+KiFOYWUbJ0z8AuB5MycA7FVc3m/jBICbi4ttXSdE4Oa2 ZFUnAHzFxk9uU8yJV7c3I7l/cJtD4Vg7Gq3F5JH8vROFmrVydXszsunebYmJ8zm6djFx58m725LVxAmA Y2xODm4nU/a7AfAZAjzhoBjlpoxG6W5iAJFBgVmU+qYgsXY8uOcSJTo6iFIXAJzkpP/yTVEpxg+1daVW diff --git a/OpsFlow/UI/Forms/Management/PersonelListForm.Designer.cs b/OpsFlow/UI/Forms/Management/PersonelListForm.Designer.cs index 4a341d5..bd5188f 100644 --- a/OpsFlow/UI/Forms/Management/PersonelListForm.Designer.cs +++ b/OpsFlow/UI/Forms/Management/PersonelListForm.Designer.cs @@ -28,25 +28,25 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges35 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges36 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges19 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges17 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges18 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges1 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PersonelListForm)); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges20 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges21 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges22 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges23 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges24 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges25 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges26 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges27 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges28 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges29 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges30 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges31 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges32 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges33 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); - Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges34 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges2 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges3 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges4 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges5 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges6 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges7 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges8 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges9 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges10 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges11 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges12 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges13 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges14 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges15 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); + Guna.UI2.WinForms.Suite.CustomizableEdges customizableEdges16 = new Guna.UI2.WinForms.Suite.CustomizableEdges(); pnlHeader = new Guna.UI2.WinForms.Guna2Panel(); txtSearch = new Guna.UI2.WinForms.Guna2TextBox(); btnAddNewMember = new Guna.UI2.WinForms.Guna2Button(); @@ -79,12 +79,12 @@ private void InitializeComponent() pnlHeader.Controls.Add(guna2Panel2); pnlHeader.Controls.Add(cmbFilterDept); pnlHeader.Controls.Add(guna2Panel1); - pnlHeader.CustomizableEdges = customizableEdges35; + pnlHeader.CustomizableEdges = customizableEdges17; pnlHeader.Dock = DockStyle.Top; pnlHeader.Location = new Point(0, 0); pnlHeader.Name = "pnlHeader"; - pnlHeader.ShadowDecoration.CustomizableEdges = customizableEdges36; - pnlHeader.Size = new Size(1382, 297); + pnlHeader.ShadowDecoration.CustomizableEdges = customizableEdges18; + pnlHeader.Size = new Size(1606, 297); pnlHeader.TabIndex = 0; pnlHeader.Paint += pnlHeader_Paint; // @@ -92,42 +92,42 @@ private void InitializeComponent() // txtSearch.BorderColor = Color.DarkGray; txtSearch.BorderRadius = 10; - txtSearch.CustomizableEdges = customizableEdges19; - txtSearch.DefaultText = "Personel ara..."; + txtSearch.CustomizableEdges = customizableEdges1; + txtSearch.DefaultText = ""; txtSearch.DisabledState.BorderColor = Color.FromArgb(208, 208, 208); txtSearch.DisabledState.FillColor = Color.FromArgb(226, 226, 226); txtSearch.DisabledState.ForeColor = Color.FromArgb(138, 138, 138); txtSearch.DisabledState.PlaceholderForeColor = Color.FromArgb(138, 138, 138); txtSearch.FillColor = Color.FromArgb(42, 45, 62); txtSearch.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - txtSearch.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + txtSearch.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); txtSearch.HoverState.BorderColor = Color.FromArgb(94, 148, 255); txtSearch.IconLeft = (Image)resources.GetObject("txtSearch.IconLeft"); txtSearch.IconLeftOffset = new Point(10, 0); - txtSearch.Location = new Point(1049, 220); + txtSearch.Location = new Point(1250, 237); txtSearch.Margin = new Padding(3, 5, 3, 5); txtSearch.Name = "txtSearch"; - txtSearch.PlaceholderText = ""; + txtSearch.PlaceholderText = "Personel ara..."; txtSearch.SelectedText = ""; - txtSearch.ShadowDecoration.CustomizableEdges = customizableEdges20; - txtSearch.Size = new Size(227, 52); + txtSearch.ShadowDecoration.CustomizableEdges = customizableEdges2; + txtSearch.Size = new Size(282, 52); txtSearch.TabIndex = 39; // // btnAddNewMember // btnAddNewMember.BorderRadius = 12; - btnAddNewMember.CustomizableEdges = customizableEdges21; + btnAddNewMember.CustomizableEdges = customizableEdges3; btnAddNewMember.DisabledState.BorderColor = Color.DarkGray; btnAddNewMember.DisabledState.CustomBorderColor = Color.DarkGray; btnAddNewMember.DisabledState.FillColor = Color.FromArgb(169, 169, 169); btnAddNewMember.DisabledState.ForeColor = Color.FromArgb(141, 141, 141); btnAddNewMember.FillColor = Color.FromArgb(46, 74, 98); - btnAddNewMember.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + btnAddNewMember.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); btnAddNewMember.ForeColor = Color.White; - btnAddNewMember.Location = new Point(1049, 69); + btnAddNewMember.Location = new Point(1250, 68); btnAddNewMember.Name = "btnAddNewMember"; - btnAddNewMember.ShadowDecoration.CustomizableEdges = customizableEdges22; - btnAddNewMember.Size = new Size(193, 64); + btnAddNewMember.ShadowDecoration.CustomizableEdges = customizableEdges4; + btnAddNewMember.Size = new Size(282, 64); btnAddNewMember.TabIndex = 15; btnAddNewMember.Text = "+ Yeni Üye Ekle"; btnAddNewMember.Click += btnAddNewMember_Click; @@ -138,19 +138,19 @@ private void InitializeComponent() cmbFilterStatus.BorderColor = Color.FromArgb(45, 55, 72); cmbFilterStatus.BorderRadius = 10; cmbFilterStatus.BorderThickness = 2; - cmbFilterStatus.CustomizableEdges = customizableEdges23; + cmbFilterStatus.CustomizableEdges = customizableEdges5; cmbFilterStatus.DrawMode = DrawMode.OwnerDrawFixed; cmbFilterStatus.DropDownStyle = ComboBoxStyle.DropDownList; cmbFilterStatus.FillColor = Color.FromArgb(26, 31, 46); cmbFilterStatus.FocusedColor = Color.FromArgb(94, 148, 255); cmbFilterStatus.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - cmbFilterStatus.Font = new Font("Poppins", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); + cmbFilterStatus.Font = new Font("Microsoft Sans Serif", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); cmbFilterStatus.ForeColor = Color.White; cmbFilterStatus.ItemHeight = 30; - cmbFilterStatus.Location = new Point(640, 255); + cmbFilterStatus.Location = new Point(842, 255); cmbFilterStatus.Name = "cmbFilterStatus"; - cmbFilterStatus.ShadowDecoration.CustomizableEdges = customizableEdges24; - cmbFilterStatus.Size = new Size(230, 36); + cmbFilterStatus.ShadowDecoration.CustomizableEdges = customizableEdges6; + cmbFilterStatus.Size = new Size(319, 36); cmbFilterStatus.TabIndex = 38; // // guna2Panel3 @@ -158,33 +158,33 @@ private void InitializeComponent() guna2Panel3.BorderRadius = 15; guna2Panel3.Controls.Add(txtDep); guna2Panel3.Controls.Add(guna2HtmlLabel4); - guna2Panel3.CustomizableEdges = customizableEdges25; + guna2Panel3.CustomizableEdges = customizableEdges7; guna2Panel3.FillColor = Color.FromArgb(26, 31, 46); - guna2Panel3.Location = new Point(721, 37); + guna2Panel3.Location = new Point(842, 37); guna2Panel3.Name = "guna2Panel3"; - guna2Panel3.ShadowDecoration.CustomizableEdges = customizableEdges26; - guna2Panel3.Size = new Size(260, 194); + guna2Panel3.ShadowDecoration.CustomizableEdges = customizableEdges8; + guna2Panel3.Size = new Size(356, 194); guna2Panel3.TabIndex = 2; // // txtDep // txtDep.BackColor = Color.Transparent; - txtDep.Font = new Font("Poppins", 28.2F, FontStyle.Bold); + txtDep.Font = new Font("Microsoft Sans Serif", 28.2F, FontStyle.Bold); txtDep.ForeColor = Color.White; txtDep.Location = new Point(8, 12); txtDep.Name = "txtDep"; - txtDep.Size = new Size(34, 84); + txtDep.Size = new Size(30, 56); txtDep.TabIndex = 2; txtDep.Text = "0"; // // guna2HtmlLabel4 // guna2HtmlLabel4.BackColor = Color.Transparent; - guna2HtmlLabel4.Font = new Font("Poppins", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); + guna2HtmlLabel4.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); guna2HtmlLabel4.ForeColor = Color.White; guna2HtmlLabel4.Location = new Point(3, 153); guna2HtmlLabel4.Name = "guna2HtmlLabel4"; - guna2HtmlLabel4.Size = new Size(121, 38); + guna2HtmlLabel4.Size = new Size(108, 27); guna2HtmlLabel4.TabIndex = 0; guna2HtmlLabel4.Text = "Depertman"; // @@ -194,19 +194,19 @@ private void InitializeComponent() cmbFilterRole.BorderColor = Color.FromArgb(45, 55, 72); cmbFilterRole.BorderRadius = 10; cmbFilterRole.BorderThickness = 2; - cmbFilterRole.CustomizableEdges = customizableEdges27; + cmbFilterRole.CustomizableEdges = customizableEdges9; cmbFilterRole.DrawMode = DrawMode.OwnerDrawFixed; cmbFilterRole.DropDownStyle = ComboBoxStyle.DropDownList; cmbFilterRole.FillColor = Color.FromArgb(26, 31, 46); cmbFilterRole.FocusedColor = Color.FromArgb(94, 148, 255); cmbFilterRole.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - cmbFilterRole.Font = new Font("Poppins", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); + cmbFilterRole.Font = new Font("Microsoft Sans Serif", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); cmbFilterRole.ForeColor = Color.White; cmbFilterRole.ItemHeight = 30; - cmbFilterRole.Location = new Point(345, 255); + cmbFilterRole.Location = new Point(448, 258); cmbFilterRole.Name = "cmbFilterRole"; - cmbFilterRole.ShadowDecoration.CustomizableEdges = customizableEdges28; - cmbFilterRole.Size = new Size(230, 36); + cmbFilterRole.ShadowDecoration.CustomizableEdges = customizableEdges10; + cmbFilterRole.Size = new Size(319, 36); cmbFilterRole.TabIndex = 37; // // guna2Panel2 @@ -214,33 +214,33 @@ private void InitializeComponent() guna2Panel2.BorderRadius = 15; guna2Panel2.Controls.Add(txtActivePersonel); guna2Panel2.Controls.Add(guna2HtmlLabel3); - guna2Panel2.CustomizableEdges = customizableEdges29; + guna2Panel2.CustomizableEdges = customizableEdges11; guna2Panel2.FillColor = Color.FromArgb(26, 31, 46); - guna2Panel2.Location = new Point(387, 37); + guna2Panel2.Location = new Point(448, 37); guna2Panel2.Name = "guna2Panel2"; - guna2Panel2.ShadowDecoration.CustomizableEdges = customizableEdges30; - guna2Panel2.Size = new Size(275, 194); + guna2Panel2.ShadowDecoration.CustomizableEdges = customizableEdges12; + guna2Panel2.Size = new Size(364, 194); guna2Panel2.TabIndex = 1; // // txtActivePersonel // txtActivePersonel.BackColor = Color.Transparent; - txtActivePersonel.Font = new Font("Poppins", 28.2F, FontStyle.Bold); + txtActivePersonel.Font = new Font("Microsoft Sans Serif", 28.2F, FontStyle.Bold); txtActivePersonel.ForeColor = Color.White; txtActivePersonel.Location = new Point(8, 12); txtActivePersonel.Name = "txtActivePersonel"; - txtActivePersonel.Size = new Size(34, 84); + txtActivePersonel.Size = new Size(30, 56); txtActivePersonel.TabIndex = 2; txtActivePersonel.Text = "0"; // // guna2HtmlLabel3 // guna2HtmlLabel3.BackColor = Color.Transparent; - guna2HtmlLabel3.Font = new Font("Poppins", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); + guna2HtmlLabel3.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); guna2HtmlLabel3.ForeColor = Color.White; guna2HtmlLabel3.Location = new Point(3, 153); guna2HtmlLabel3.Name = "guna2HtmlLabel3"; - guna2HtmlLabel3.Size = new Size(143, 38); + guna2HtmlLabel3.Size = new Size(137, 27); guna2HtmlLabel3.TabIndex = 0; guna2HtmlLabel3.Text = "Aktif Personel"; guna2HtmlLabel3.Click += guna2HtmlLabel3_Click; @@ -251,19 +251,19 @@ private void InitializeComponent() cmbFilterDept.BorderColor = Color.FromArgb(45, 55, 72); cmbFilterDept.BorderRadius = 10; cmbFilterDept.BorderThickness = 2; - cmbFilterDept.CustomizableEdges = customizableEdges31; + cmbFilterDept.CustomizableEdges = customizableEdges13; cmbFilterDept.DrawMode = DrawMode.OwnerDrawFixed; cmbFilterDept.DropDownStyle = ComboBoxStyle.DropDownList; cmbFilterDept.FillColor = Color.FromArgb(26, 31, 46); cmbFilterDept.FocusedColor = Color.FromArgb(94, 148, 255); cmbFilterDept.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - cmbFilterDept.Font = new Font("Poppins", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); + cmbFilterDept.Font = new Font("Microsoft Sans Serif", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); cmbFilterDept.ForeColor = Color.White; cmbFilterDept.ItemHeight = 30; cmbFilterDept.Location = new Point(50, 255); cmbFilterDept.Name = "cmbFilterDept"; - cmbFilterDept.ShadowDecoration.CustomizableEdges = customizableEdges32; - cmbFilterDept.Size = new Size(230, 36); + cmbFilterDept.ShadowDecoration.CustomizableEdges = customizableEdges14; + cmbFilterDept.Size = new Size(319, 36); cmbFilterDept.TabIndex = 36; // // guna2Panel1 @@ -271,33 +271,33 @@ private void InitializeComponent() guna2Panel1.BorderRadius = 15; guna2Panel1.Controls.Add(txtPersonel); guna2Panel1.Controls.Add(guna2HtmlLabel2); - guna2Panel1.CustomizableEdges = customizableEdges33; + guna2Panel1.CustomizableEdges = customizableEdges15; guna2Panel1.FillColor = Color.FromArgb(26, 31, 46); guna2Panel1.Location = new Point(53, 37); guna2Panel1.Name = "guna2Panel1"; - guna2Panel1.ShadowDecoration.CustomizableEdges = customizableEdges34; - guna2Panel1.Size = new Size(275, 194); + guna2Panel1.ShadowDecoration.CustomizableEdges = customizableEdges16; + guna2Panel1.Size = new Size(364, 194); guna2Panel1.TabIndex = 0; // // txtPersonel // txtPersonel.BackColor = Color.Transparent; - txtPersonel.Font = new Font("Poppins", 28.2F, FontStyle.Bold); + txtPersonel.Font = new Font("Microsoft Sans Serif", 28.2F, FontStyle.Bold); txtPersonel.ForeColor = Color.White; txtPersonel.Location = new Point(8, 12); txtPersonel.Name = "txtPersonel"; - txtPersonel.Size = new Size(34, 84); + txtPersonel.Size = new Size(30, 56); txtPersonel.TabIndex = 1; txtPersonel.Text = "0"; // // guna2HtmlLabel2 // guna2HtmlLabel2.BackColor = Color.Transparent; - guna2HtmlLabel2.Font = new Font("Poppins", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); + guna2HtmlLabel2.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Bold, GraphicsUnit.Point, 162); guna2HtmlLabel2.ForeColor = Color.White; guna2HtmlLabel2.Location = new Point(3, 153); guna2HtmlLabel2.Name = "guna2HtmlLabel2"; - guna2HtmlLabel2.Size = new Size(175, 38); + guna2HtmlLabel2.Size = new Size(166, 27); guna2HtmlLabel2.TabIndex = 0; guna2HtmlLabel2.Text = "Toplam Personel"; // @@ -308,7 +308,7 @@ private void InitializeComponent() flpPersonelContainer.Location = new Point(0, 297); flpPersonelContainer.Name = "flpPersonelContainer"; flpPersonelContainer.Padding = new Padding(20, 10, 0, 0); - flpPersonelContainer.Size = new Size(1382, 494); + flpPersonelContainer.Size = new Size(1606, 494); flpPersonelContainer.TabIndex = 1; // // PersonelListForm @@ -316,7 +316,7 @@ private void InitializeComponent() AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; BackColor = Color.FromArgb(17, 19, 25); - ClientSize = new Size(1382, 791); + ClientSize = new Size(1606, 791); Controls.Add(flpPersonelContainer); Controls.Add(pnlHeader); FormBorderStyle = FormBorderStyle.None; diff --git a/OpsFlow/UI/Forms/Management/PersonelListForm.cs b/OpsFlow/UI/Forms/Management/PersonelListForm.cs index a0eecb5..6488837 100644 --- a/OpsFlow/UI/Forms/Management/PersonelListForm.cs +++ b/OpsFlow/UI/Forms/Management/PersonelListForm.cs @@ -1,24 +1,301 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; +using OpsFlow.Core.Enums; +using OpsFlow.Core.Exceptions; +using OpsFlow.Core.Models; +using OpsFlow.Core.Services; +using OpsFlow.Services.Implementations; +using OpsFlow.UI.Forms.Core; +using OpsFlow.UI.Forms.Dialogs.Notifications; namespace OpsFlow.UI.Forms.Management; -public partial class PersonelListForm : Form +public partial class PersonelListForm : BaseForm { + private List _allUsers = new List(); + private List _filteredUsers = new List(); + private int _currentPage = 0; + private const int PageSize = 6; + private bool _isLoading = false; + private System.Windows.Forms.Timer? _scrollTimer; + private System.Windows.Forms.Timer? _searchTimer; + public PersonelListForm() { InitializeComponent(); + if (this.HeaderPanel != null) this.HeaderPanel.SendToBack(); + cmbFilterDept.DropDownStyle = ComboBoxStyle.DropDown; cmbFilterRole.DropDownStyle = ComboBoxStyle.DropDown; cmbFilterStatus.DropDownStyle = ComboBoxStyle.DropDown; + + SetLoadingState(); + + if (flpPersonelContainer != null) + { + flpPersonelContainer.AutoScroll = true; + flpPersonelContainer.WrapContents = true; + flpPersonelContainer.FlowDirection = FlowDirection.LeftToRight; + flpPersonelContainer.BackColor = Color.FromArgb(17, 19, 25); + + SetModernScrollbarStyle(); + + _scrollTimer = new System.Windows.Forms.Timer(); + _scrollTimer.Interval = 200; + _scrollTimer.Tick += ScrollTimer_Tick; + _scrollTimer.Start(); + } + + if (txtSearch != null) + { + _searchTimer = new System.Windows.Forms.Timer(); + _searchTimer.Interval = 100; + _searchTimer.Tick += SearchTimer_Tick; + txtSearch.TextChanged += TxtSearch_TextChanged; + txtSearch.Leave += TxtSearch_Leave; + } + + cmbFilterDept.SelectedIndexChanged += CmbFilterDept_SelectedIndexChanged; + cmbFilterRole.SelectedIndexChanged += CmbFilterRole_SelectedIndexChanged; + cmbFilterStatus.SelectedIndexChanged += CmbFilterStatus_SelectedIndexChanged; + + this.Load += PersonelListForm_Load; + } + + private void SetLoadingState() + { + txtPersonel.Text = "Yükleniyor..."; + txtActivePersonel.Text = "Yükleniyor..."; + txtDep.Text = "Yükleniyor..."; + } + + private void SetModernScrollbarStyle() + { + if (flpPersonelContainer == null) return; + + try + { + flpPersonelContainer.HorizontalScroll.Enabled = false; + flpPersonelContainer.HorizontalScroll.Visible = false; + flpPersonelContainer.AutoScrollMargin = new Size(0, 0); + flpPersonelContainer.AutoScrollMinSize = new Size(0, 0); + } + catch + { + } + } + + private async void PersonelListForm_Load(object? sender, EventArgs e) + { + if (flpPersonelContainer != null) + { + flpPersonelContainer.WrapContents = true; + flpPersonelContainer.FlowDirection = FlowDirection.LeftToRight; + } + await LoadFilterComboBoxesAsync(); + await LoadStatisticsAsync(); + } + + private async Task LoadFilterComboBoxesAsync() + { + try + { + using var roleContext = DatabaseManager.CreateContext(); + using var departmentContext = DatabaseManager.CreateContext(); + + var roleService = new RoleService(roleContext); + var departmentService = new DepartmentService(departmentContext); + + var rolesTask = roleService.GetAllRolesAsync(); + var departmentsTask = departmentService.GetAllDepartmentsAsync(); + + await Task.WhenAll(rolesTask, departmentsTask); + + var roles = await rolesTask; + var departments = await departmentsTask; + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + LoadFilterComboBoxes(roles, departments); + })); + } + else + { + LoadFilterComboBoxes(roles, departments); + } + } + catch (DatabaseQueryException ex) + { + string errorMessage = ex.Message; + if (ex.InnerException != null && !ex.Message.Contains(ex.InnerException.Message)) + { + errorMessage += $"\n\nDetay: {ex.InnerException.Message}"; + } + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + Notifier.Show("Veritabanı Hatası", errorMessage, NotificationType.Error); + })); + } + else + { + Notifier.Show("Veritabanı Hatası", errorMessage, NotificationType.Error); + } + } + catch (Exception ex) + { + string errorMessage = $"Filtre verileri yüklenirken bir hata oluştu: {ex.Message}"; + if (ex.InnerException != null) + { + errorMessage += $"\n\nDetay: {ex.InnerException.Message}"; + } + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + Notifier.Show("Hata", errorMessage, NotificationType.Error); + })); + } + else + { + Notifier.Show("Hata", errorMessage, NotificationType.Error); + } + } + } + + private void LoadFilterComboBoxes(List roles, List departments) + { + cmbFilterDept.BeginUpdate(); + cmbFilterDept.Items.Clear(); + cmbFilterDept.Items.Add("Departman"); + foreach (var department in departments) + cmbFilterDept.Items.Add(department.DepartmentName); cmbFilterDept.Text = "Departman"; + cmbFilterDept.EndUpdate(); + + cmbFilterRole.BeginUpdate(); + cmbFilterRole.Items.Clear(); + cmbFilterRole.Items.Add("Rol"); + foreach (var role in roles) + cmbFilterRole.Items.Add(role.RoleName); cmbFilterRole.Text = "Rol"; + cmbFilterRole.EndUpdate(); + + cmbFilterStatus.BeginUpdate(); + cmbFilterStatus.Items.Clear(); + cmbFilterStatus.Items.Add("Durum"); + cmbFilterStatus.Items.Add("Aktif"); + cmbFilterStatus.Items.Add("Pasif"); cmbFilterStatus.Text = "Durum"; + cmbFilterStatus.EndUpdate(); + } + + private async Task LoadStatisticsAsync() + { + try + { + using var userContext = DatabaseManager.CreateContext(); + using var departmentContext = DatabaseManager.CreateContext(); + + var userService = new UserService(userContext); + var departmentService = new DepartmentService(departmentContext); + + var usersTask = Task.Run(() => userService.GetAllUsers()); + var departmentsTask = departmentService.GetAllDepartmentsAsync(); + + await Task.WhenAll(usersTask, departmentsTask); + + var users = await usersTask; + var departments = await departmentsTask; + + int totalPersonel = users.Count; + int activePersonel = users.Count(u => u.IsActive); + int totalDepartments = departments.Count; + + if (this.InvokeRequired) + { + this.BeginInvoke(new Action(async () => + { + await UpdateStatistics(totalPersonel, activePersonel, totalDepartments); + _allUsers = users; + _filteredUsers = users; + _currentPage = 0; + if (flpPersonelContainer != null) + { + flpPersonelContainer.Controls.Clear(); + } + await LoadNextPage(); + })); + } + else + { + await UpdateStatistics(totalPersonel, activePersonel, totalDepartments); + _allUsers = users; + _filteredUsers = users; + _currentPage = 0; + if (flpPersonelContainer != null) + { + flpPersonelContainer.Controls.Clear(); + } + await LoadNextPage(); + } + } + catch (DatabaseQueryException ex) + { + string errorMessage = ex.Message; + if (ex.InnerException != null && !ex.Message.Contains(ex.InnerException.Message)) + { + errorMessage += $"\n\nDetay: {ex.InnerException.Message}"; + } + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + Notifier.Show("Veritabanı Hatası", errorMessage, NotificationType.Error); + })); + } + else + { + Notifier.Show("Veritabanı Hatası", errorMessage, NotificationType.Error); + } + } + catch (Exception ex) + { + string errorMessage = $"İstatistikler yüklenirken bir hata oluştu: {ex.Message}"; + if (ex.InnerException != null) + { + errorMessage += $"\n\nDetay: {ex.InnerException.Message}"; + } + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + Notifier.Show("Hata", errorMessage, NotificationType.Error); + })); + } + else + { + Notifier.Show("Hata", errorMessage, NotificationType.Error); + } + } + } + + private async Task UpdateStatistics(int totalPersonel, int activePersonel, int totalDepartments) + { + await Task.Delay(300); + + txtPersonel.Text = totalPersonel.ToString(); + await Task.Delay(100); + + txtActivePersonel.Text = activePersonel.ToString(); + await Task.Delay(100); + + txtDep.Text = totalDepartments.ToString(); } private void pnlHeader_Paint(object sender, PaintEventArgs e) @@ -31,6 +308,294 @@ private void guna2HtmlLabel3_Click(object sender, EventArgs e) } + private void ScrollTimer_Tick(object? sender, EventArgs e) + { + if (_isLoading || flpPersonelContainer == null) + return; + + if (_currentPage * PageSize >= _filteredUsers.Count) + return; + + try + { + int scrollTop = flpPersonelContainer.VerticalScroll.Value; + int scrollMax = flpPersonelContainer.VerticalScroll.Maximum; + int clientHeight = flpPersonelContainer.ClientSize.Height; + + if (scrollMax > 0 && scrollTop + clientHeight >= scrollMax - 100) + { + _ = LoadNextPage(); + } + } + catch + { + } + } + + private async Task LoadNextPage() + { + if (_isLoading || flpPersonelContainer == null) + return; + + int startIndex = _currentPage * PageSize; + + if (startIndex >= _filteredUsers.Count) + return; + + int currentLoadedCount = flpPersonelContainer.Controls.Count; + int expectedCount = startIndex + PageSize; + + if (currentLoadedCount >= expectedCount) + return; + + _isLoading = true; + + try + { + var usersToLoad = _filteredUsers.Skip(startIndex).Take(PageSize).ToList(); + + if (usersToLoad.Count == 0) + return; + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + flpPersonelContainer.SuspendLayout(); + foreach (var user in usersToLoad) + { + var card = new PersonelCard(); + card.SetUserData(user); + flpPersonelContainer.Controls.Add(card); + } + flpPersonelContainer.ResumeLayout(false); + flpPersonelContainer.PerformLayout(); + })); + } + else + { + flpPersonelContainer.SuspendLayout(); + foreach (var user in usersToLoad) + { + var card = new PersonelCard(); + card.SetUserData(user); + flpPersonelContainer.Controls.Add(card); + } + flpPersonelContainer.ResumeLayout(false); + flpPersonelContainer.PerformLayout(); + } + + _currentPage++; + await Task.Delay(50); + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + EnsureScrollbarVisible(); + })); + } + else + { + EnsureScrollbarVisible(); + } + } + finally + { + _isLoading = false; + } + } + + private void TxtSearch_TextChanged(object? sender, EventArgs e) + { + if (_searchTimer != null && txtSearch != null) + { + _searchTimer.Stop(); + _searchTimer.Start(); + } + } + + private async void SearchTimer_Tick(object? sender, EventArgs e) + { + if (_searchTimer != null) + { + _searchTimer.Stop(); + } + + await ApplyFiltersAsync(); + } + + private void CmbFilterDept_SelectedIndexChanged(object? sender, EventArgs e) + { + _ = ApplyFiltersAsync(); + } + + private void CmbFilterRole_SelectedIndexChanged(object? sender, EventArgs e) + { + _ = ApplyFiltersAsync(); + } + + private void CmbFilterStatus_SelectedIndexChanged(object? sender, EventArgs e) + { + _ = ApplyFiltersAsync(); + } + + private async Task ApplyFiltersAsync() + { + string searchText = txtSearch?.Text ?? string.Empty; + searchText = searchText.Trim(); + + string selectedDepartment = cmbFilterDept?.Text ?? "Departman"; + string selectedRole = cmbFilterRole?.Text ?? "Rol"; + string selectedStatus = cmbFilterStatus?.Text ?? "Durum"; + + var filtered = _allUsers.AsEnumerable(); + + if (!string.IsNullOrWhiteSpace(searchText)) + { + filtered = filtered.Where(u => + (u.Name + " " + u.Surname).Contains(searchText, StringComparison.OrdinalIgnoreCase) || + u.Name.Contains(searchText, StringComparison.OrdinalIgnoreCase) || + u.Surname.Contains(searchText, StringComparison.OrdinalIgnoreCase)); + } + + if (selectedDepartment != "Departman" && !string.IsNullOrWhiteSpace(selectedDepartment)) + { + filtered = filtered.Where(u => u.Department != null && u.Department.DepartmentName == selectedDepartment); + } + + if (selectedRole != "Rol" && !string.IsNullOrWhiteSpace(selectedRole)) + { + filtered = filtered.Where(u => u.Role != null && u.Role.RoleName == selectedRole); + } + + if (selectedStatus != "Durum" && !string.IsNullOrWhiteSpace(selectedStatus)) + { + bool isActive = selectedStatus == "Aktif"; + filtered = filtered.Where(u => u.IsActive == isActive); + } + + _filteredUsers = filtered.ToList(); + + _currentPage = 0; + if (flpPersonelContainer != null) + { + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + flpPersonelContainer.SuspendLayout(); + flpPersonelContainer.Controls.Clear(); + flpPersonelContainer.AutoScroll = true; + flpPersonelContainer.ResumeLayout(false); + flpPersonelContainer.PerformLayout(); + })); + } + else + { + flpPersonelContainer.SuspendLayout(); + flpPersonelContainer.Controls.Clear(); + flpPersonelContainer.AutoScroll = true; + flpPersonelContainer.ResumeLayout(false); + flpPersonelContainer.PerformLayout(); + } + } + await LoadNextPage(); + + // Scrollbar'ın görünür olmasını sağlamak için içeriğin yüksekliğini kontrol et + if (flpPersonelContainer != null) + { + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + EnsureScrollbarVisible(); + })); + } + else + { + EnsureScrollbarVisible(); + } + } + } + + private void TxtSearch_Leave(object? sender, EventArgs e) + { + if (flpPersonelContainer != null) + { + EnsureScrollbarVisible(); + } + } + + private void EnsureScrollbarVisible() + { + if (flpPersonelContainer == null) + return; + + flpPersonelContainer.AutoScroll = true; + flpPersonelContainer.HorizontalScroll.Enabled = false; + flpPersonelContainer.HorizontalScroll.Visible = false; + + // Daha fazla içerik olup olmadığını kontrol et + bool hasMoreContent = _currentPage * PageSize < _filteredUsers.Count; + + // FlowLayoutPanel'in gerçek içerik yüksekliğini al + int contentHeight = 0; + if (flpPersonelContainer.Controls.Count > 0) + { + // En alttaki kontrolün alt pozisyonunu bul + int maxBottom = 0; + foreach (Control control in flpPersonelContainer.Controls) + { + int bottom = control.Bottom + control.Margin.Bottom; + if (bottom > maxBottom) + maxBottom = bottom; + } + contentHeight = maxBottom + flpPersonelContainer.Padding.Bottom; + } + + int containerHeight = flpPersonelContainer.ClientSize.Height; + bool contentExceedsContainer = contentHeight > containerHeight; + + // Eğer içerik varsa ve (container'dan büyükse veya daha fazla sayfa varsa) scrollbar'ı görünür yap + if (flpPersonelContainer.Controls.Count > 0 && (contentExceedsContainer || hasMoreContent)) + { + // Scrollbar'ın görünür olması için AutoScrollMinSize ayarla + int requiredHeight = contentHeight; + if (hasMoreContent) + { + // Daha fazla içerik varsa, scrollbar'ın görünür olması için minimum boyutu container'dan büyük yap + // Tahmini toplam yüksekliği hesapla (mevcut sayfa sayısına göre) + int estimatedTotalItems = _filteredUsers.Count; + int itemsPerRow = Math.Max(1, flpPersonelContainer.ClientSize.Width / (flpPersonelContainer.Controls.Count > 0 ? + (flpPersonelContainer.Controls[0].Width + flpPersonelContainer.Controls[0].Margin.Left + flpPersonelContainer.Controls[0].Margin.Right) : 1)); + int estimatedRows = (int)Math.Ceiling((double)estimatedTotalItems / itemsPerRow); + int estimatedHeight = estimatedRows * (flpPersonelContainer.Controls.Count > 0 ? + (flpPersonelContainer.Controls[0].Height + flpPersonelContainer.Controls[0].Margin.Top + flpPersonelContainer.Controls[0].Margin.Bottom) : 100) + + flpPersonelContainer.Padding.Top + flpPersonelContainer.Padding.Bottom; + + requiredHeight = Math.Max(requiredHeight, Math.Max(containerHeight + 1, estimatedHeight)); + } + else + { + // Sadece mevcut içerik varsa, container'dan biraz büyük yap + requiredHeight = Math.Max(requiredHeight, containerHeight + 1); + } + + flpPersonelContainer.AutoScrollMinSize = new Size(0, requiredHeight); + } + else if (flpPersonelContainer.Controls.Count == 0) + { + // İçerik yoksa, minimum boyutu sıfırla + flpPersonelContainer.AutoScrollMinSize = new Size(0, 0); + } + + flpPersonelContainer.PerformLayout(); + flpPersonelContainer.Refresh(); + flpPersonelContainer.Invalidate(); + flpPersonelContainer.Update(); + } + private void btnAddNewMember_Click(object sender, EventArgs e) { AddPersonelForm frm = new AddPersonelForm(); diff --git a/OpsFlow/UI/Forms/Management/PersonelListForm.resx b/OpsFlow/UI/Forms/Management/PersonelListForm.resx index c3147ca..268b48b 100644 --- a/OpsFlow/UI/Forms/Management/PersonelListForm.resx +++ b/OpsFlow/UI/Forms/Management/PersonelListForm.resx @@ -121,7 +121,7 @@ iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL - EQAACxEBf2RfkQAAAXxJREFUSEvtlN1NwzAQgDtCN2ADygvkElDEBN2gEjr7sd0ANugGdIM+9BUlPirx + EAAACxABrSO9dQAAAXxJREFUSEvtlN1NwzAQgDtCN2ADygvkElDEBN2gEjr7sd0ANugGdIM+9BUlPirx mA3oBh0BiQd0Ts64DnGM4A0+yWrPOd+d78eTyT/f4e52N9WZeVBgagXmzVu1ymgR6iejs5dzBeYQGA3X QRV0Fp6NwoY10LE1QJUqqORb8Df+VQUtPMfpDlhRDiKYteyzUXFg5YvdVINpJE3OQAyEemUN56Zh2eYd aO1uckml6LYO+vuDuOt2yhro8TPH9BqmQOX7ZRsMbf39HhwJK+qcjizjzdNsLK9dGt2ZQbhwUkQrZ7Zw diff --git a/OpsFlow/UI/Forms/Management/ProfileEditForm.Designer.cs b/OpsFlow/UI/Forms/Management/ProfileEditForm.Designer.cs index 7770b66..543c2e3 100644 --- a/OpsFlow/UI/Forms/Management/ProfileEditForm.Designer.cs +++ b/OpsFlow/UI/Forms/Management/ProfileEditForm.Designer.cs @@ -58,10 +58,10 @@ private void InitializeComponent() btnCancel = new Guna.UI2.WinForms.Guna2Button(); txtName = new Guna.UI2.WinForms.Guna2TextBox(); txtSurname = new Guna.UI2.WinForms.Guna2TextBox(); - txtTitle = new Guna.UI2.WinForms.Guna2TextBox(); + txtTitle = new Guna.UI2.WinForms.Guna2ComboBox(); txtPhone = new Guna.UI2.WinForms.Guna2TextBox(); txtEmail = new Guna.UI2.WinForms.Guna2TextBox(); - txtDepartmant = new Guna.UI2.WinForms.Guna2TextBox(); + txtDepartmant = new Guna.UI2.WinForms.Guna2ComboBox(); label6 = new Label(); ((System.ComponentModel.ISupportInitialize)PictureBox).BeginInit(); SuspendLayout(); @@ -69,33 +69,33 @@ private void InitializeComponent() // label3 // label3.AutoSize = true; - label3.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + label3.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); label3.ForeColor = Color.White; label3.Location = new Point(95, 49); label3.Name = "label3"; - label3.Size = new Size(34, 26); + label3.Size = new Size(27, 18); label3.TabIndex = 19; label3.Text = "Ad"; // // label1 // label1.AutoSize = true; - label1.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + label1.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); label1.ForeColor = Color.White; label1.Location = new Point(279, 49); label1.Name = "label1"; - label1.Size = new Size(65, 26); + label1.Size = new Size(55, 18); label1.TabIndex = 20; label1.Text = "Soyad"; // // label2 // label2.AutoSize = true; - label2.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + label2.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); label2.ForeColor = Color.White; label2.Location = new Point(95, 357); label2.Name = "label2"; - label2.Size = new Size(109, 26); + label2.Size = new Size(90, 18); label2.TabIndex = 21; label2.Text = "Departman"; label2.Click += label2_Click; @@ -103,22 +103,22 @@ private void InitializeComponent() // label4 // label4.AutoSize = true; - label4.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + label4.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); label4.ForeColor = Color.White; label4.Location = new Point(95, 126); label4.Name = "label4"; - label4.Size = new Size(80, 26); + label4.Size = new Size(67, 18); label4.TabIndex = 22; label4.Text = "E-posta"; // // label5 // label5.AutoSize = true; - label5.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + label5.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); label5.ForeColor = Color.White; label5.Location = new Point(95, 203); label5.Name = "label5"; - label5.Size = new Size(162, 26); + label5.Size = new Size(141, 18); label5.TabIndex = 23; label5.Text = "Telefon Numarası"; // @@ -143,7 +143,7 @@ private void InitializeComponent() btnSave.DisabledState.FillColor = Color.FromArgb(169, 169, 169); btnSave.DisabledState.ForeColor = Color.FromArgb(141, 141, 141); btnSave.FillColor = Color.FromArgb(46, 74, 98); - btnSave.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + btnSave.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); btnSave.ForeColor = Color.White; btnSave.Location = new Point(95, 435); btnSave.Name = "btnSave"; @@ -163,7 +163,7 @@ private void InitializeComponent() btnAddPhoto.DisabledState.FillColor = Color.FromArgb(169, 169, 169); btnAddPhoto.DisabledState.ForeColor = Color.FromArgb(141, 141, 141); btnAddPhoto.FillColor = Color.FromArgb(0, 104, 139); - btnAddPhoto.Font = new Font("Poppins", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); + btnAddPhoto.Font = new Font("Microsoft Sans Serif", 10.2F, FontStyle.Regular, GraphicsUnit.Point, 162); btnAddPhoto.ForeColor = Color.White; btnAddPhoto.Location = new Point(488, 91); btnAddPhoto.Name = "btnAddPhoto"; @@ -184,7 +184,7 @@ private void InitializeComponent() btnCancel.DisabledState.FillColor = Color.FromArgb(169, 169, 169); btnCancel.DisabledState.ForeColor = Color.FromArgb(141, 141, 141); btnCancel.FillColor = Color.Transparent; - btnCancel.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + btnCancel.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); btnCancel.ForeColor = Color.White; btnCancel.Location = new Point(518, 435); btnCancel.Name = "btnCancel"; @@ -206,7 +206,7 @@ private void InitializeComponent() txtName.DisabledState.PlaceholderForeColor = Color.FromArgb(138, 138, 138); txtName.FillColor = Color.FromArgb(26, 31, 46); txtName.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - txtName.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + txtName.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); txtName.ForeColor = Color.White; txtName.HoverState.BorderColor = Color.FromArgb(94, 148, 255); txtName.Location = new Point(95, 80); @@ -231,7 +231,7 @@ private void InitializeComponent() txtSurname.DisabledState.PlaceholderForeColor = Color.FromArgb(138, 138, 138); txtSurname.FillColor = Color.FromArgb(26, 31, 46); txtSurname.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - txtSurname.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + txtSurname.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); txtSurname.ForeColor = Color.White; txtSurname.HoverState.BorderColor = Color.FromArgb(94, 148, 255); txtSurname.Location = new Point(279, 80); @@ -245,27 +245,22 @@ private void InitializeComponent() // // txtTitle // + txtTitle.BackColor = Color.Transparent; txtTitle.BorderColor = Color.FromArgb(45, 55, 72); txtTitle.BorderRadius = 10; txtTitle.BorderThickness = 2; txtTitle.CustomizableEdges = customizableEdges12; - txtTitle.DefaultText = ""; - txtTitle.DisabledState.BorderColor = Color.FromArgb(208, 208, 208); - txtTitle.DisabledState.FillColor = Color.FromArgb(226, 226, 226); - txtTitle.DisabledState.ForeColor = Color.FromArgb(138, 138, 138); - txtTitle.DisabledState.PlaceholderForeColor = Color.FromArgb(138, 138, 138); + txtTitle.DrawMode = DrawMode.OwnerDrawFixed; + txtTitle.DropDownStyle = ComboBoxStyle.DropDown; txtTitle.FillColor = Color.FromArgb(26, 31, 46); - txtTitle.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - txtTitle.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + txtTitle.FocusedColor = Color.FromArgb(94, 148, 255); + txtTitle.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); txtTitle.ForeColor = Color.White; - txtTitle.HoverState.BorderColor = Color.FromArgb(94, 148, 255); + txtTitle.ItemHeight = 30; txtTitle.Location = new Point(95, 311); - txtTitle.Margin = new Padding(3, 5, 3, 5); txtTitle.Name = "txtTitle"; - txtTitle.PlaceholderText = ""; - txtTitle.SelectedText = ""; txtTitle.ShadowDecoration.CustomizableEdges = customizableEdges13; - txtTitle.Size = new Size(310, 37); + txtTitle.Size = new Size(310, 36); txtTitle.TabIndex = 30; // // txtPhone @@ -281,7 +276,7 @@ private void InitializeComponent() txtPhone.DisabledState.PlaceholderForeColor = Color.FromArgb(138, 138, 138); txtPhone.FillColor = Color.FromArgb(26, 31, 46); txtPhone.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - txtPhone.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + txtPhone.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); txtPhone.ForeColor = Color.White; txtPhone.HoverState.BorderColor = Color.FromArgb(94, 148, 255); txtPhone.Location = new Point(95, 234); @@ -306,7 +301,7 @@ private void InitializeComponent() txtEmail.DisabledState.PlaceholderForeColor = Color.FromArgb(138, 138, 138); txtEmail.FillColor = Color.FromArgb(26, 31, 46); txtEmail.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - txtEmail.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + txtEmail.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); txtEmail.ForeColor = Color.White; txtEmail.HoverState.BorderColor = Color.FromArgb(94, 148, 255); txtEmail.Location = new Point(95, 157); @@ -320,37 +315,32 @@ private void InitializeComponent() // // txtDepartmant // + txtDepartmant.BackColor = Color.Transparent; txtDepartmant.BorderColor = Color.FromArgb(45, 55, 72); txtDepartmant.BorderRadius = 10; txtDepartmant.BorderThickness = 2; txtDepartmant.CustomizableEdges = customizableEdges18; - txtDepartmant.DefaultText = ""; - txtDepartmant.DisabledState.BorderColor = Color.FromArgb(208, 208, 208); - txtDepartmant.DisabledState.FillColor = Color.FromArgb(226, 226, 226); - txtDepartmant.DisabledState.ForeColor = Color.FromArgb(138, 138, 138); - txtDepartmant.DisabledState.PlaceholderForeColor = Color.FromArgb(138, 138, 138); + txtDepartmant.DrawMode = DrawMode.OwnerDrawFixed; + txtDepartmant.DropDownStyle = ComboBoxStyle.DropDown; txtDepartmant.FillColor = Color.FromArgb(26, 31, 46); - txtDepartmant.FocusedState.BorderColor = Color.FromArgb(94, 148, 255); - txtDepartmant.Font = new Font("Poppins", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); + txtDepartmant.FocusedColor = Color.FromArgb(94, 148, 255); + txtDepartmant.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Regular, GraphicsUnit.Point, 162); txtDepartmant.ForeColor = Color.White; - txtDepartmant.HoverState.BorderColor = Color.FromArgb(94, 148, 255); + txtDepartmant.ItemHeight = 30; txtDepartmant.Location = new Point(95, 388); - txtDepartmant.Margin = new Padding(3, 5, 3, 5); txtDepartmant.Name = "txtDepartmant"; - txtDepartmant.PlaceholderText = ""; - txtDepartmant.SelectedText = ""; txtDepartmant.ShadowDecoration.CustomizableEdges = customizableEdges19; - txtDepartmant.Size = new Size(310, 37); + txtDepartmant.Size = new Size(310, 36); txtDepartmant.TabIndex = 33; // // label6 // label6.AutoSize = true; - label6.Font = new Font("Poppins Medium", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); + label6.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 162); label6.ForeColor = Color.White; label6.Location = new Point(95, 280); label6.Name = "label6"; - label6.Size = new Size(38, 26); + label6.Size = new Size(34, 18); label6.TabIndex = 34; label6.Text = "Rol"; // @@ -398,9 +388,9 @@ private void InitializeComponent() private Guna.UI2.WinForms.Guna2Button btnCancel; private Guna.UI2.WinForms.Guna2TextBox txtName; private Guna.UI2.WinForms.Guna2TextBox txtSurname; - private Guna.UI2.WinForms.Guna2TextBox txtTitle; + private Guna.UI2.WinForms.Guna2ComboBox txtTitle; private Guna.UI2.WinForms.Guna2TextBox txtPhone; private Guna.UI2.WinForms.Guna2TextBox txtEmail; - private Guna.UI2.WinForms.Guna2TextBox txtDepartmant; + private Guna.UI2.WinForms.Guna2ComboBox txtDepartmant; private Label label6; } \ No newline at end of file diff --git a/OpsFlow/UI/Forms/Management/ProfileEditForm.cs b/OpsFlow/UI/Forms/Management/ProfileEditForm.cs index 71bcce4..fb6bb46 100644 --- a/OpsFlow/UI/Forms/Management/ProfileEditForm.cs +++ b/OpsFlow/UI/Forms/Management/ProfileEditForm.cs @@ -1,22 +1,396 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; +using OpsFlow.Core.Enums; +using OpsFlow.Core.Exceptions; +using OpsFlow.Core.Models; +using OpsFlow.Core.Services; +using OpsFlow.Services.Helpers; +using OpsFlow.Services.Implementations; +using OpsFlow.Services.Interfaces; +using OpsFlow.UI.Forms.Dialogs.Notifications; +using OpsFlow.UI.Forms.Core; namespace OpsFlow.UI.Forms.Management; public partial class ProfileEditForm : Form { - public ProfileEditForm() + private User? _user; + private User? _originalUser; + private string? _uploadedFilePath; + private readonly IFileUploadService _fileUploadService; + private List _roles = new List(); + private List _departments = new List(); + + public ProfileEditForm(User user) { InitializeComponent(); + _user = user; + _originalUser = new User + { + Id = user.Id, + Name = user.Name, + Surname = user.Surname, + Email = user.Email, + Phone = user.Phone, + RoleId = user.RoleId, + DepartmentId = user.DepartmentId, + AvatarUrl = user.AvatarUrl, + CompanyId = user.CompanyId, + IsActive = user.IsActive + }; + _fileUploadService = FileUploadServiceFactory.Create(); + this.Load += ProfileEditForm_Load; + AttachEventHandlers(); } - private void label2_Click(object sender, EventArgs e) + private async void ProfileEditForm_Load(object? sender, EventArgs e) + { + await LoadComboBoxDataAsync(); + LoadUserData(); + } + + private async Task LoadComboBoxDataAsync() + { + try + { + using var roleContext = DatabaseManager.CreateContext(); + using var departmentContext = DatabaseManager.CreateContext(); + + var roleService = new RoleService(roleContext); + var departmentService = new DepartmentService(departmentContext); + + var rolesTask = roleService.GetAllRolesAsync(); + var departmentsTask = departmentService.GetAllDepartmentsAsync(); + + await Task.WhenAll(rolesTask, departmentsTask); + + var roles = await rolesTask; + var departments = await departmentsTask; + + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + LoadComboBoxes(roles, departments); + })); + } + else + { + LoadComboBoxes(roles, departments); + } + } + catch (Exception ex) + { + string errorMessage = $"Veriler yüklenirken bir hata oluştu: {ex.Message}"; + if (ex.InnerException != null) + { + errorMessage += $"\n\nDetay: {ex.InnerException.Message}"; + } + Notifier.Show("Hata", errorMessage, NotificationType.Error); + } + } + + private void LoadComboBoxes(List roles, List departments) + { + _roles = roles; + _departments = departments; + + txtTitle.BeginUpdate(); + txtTitle.Items.Clear(); + foreach (var role in roles) + txtTitle.Items.Add(role.RoleName); + txtTitle.EndUpdate(); + + txtDepartmant.BeginUpdate(); + txtDepartmant.Items.Clear(); + foreach (var department in departments) + txtDepartmant.Items.Add(department.DepartmentName); + txtDepartmant.EndUpdate(); + } + + private void AttachEventHandlers() + { + btnSave.Click += BtnSave_Click; + btnCancel.Click += BtnCancel_Click; + btnAddPhoto.Click += BtnAddPhoto_Click; + } + + private void LoadUserData() + { + if (_user == null) return; + + txtName.Text = _user.Name; + txtSurname.Text = _user.Surname; + txtEmail.Text = _user.Email; + txtPhone.Text = _user.Phone ?? string.Empty; + + if (_user.Role != null) + { + txtTitle.Text = _user.Role.RoleName; + } + + if (_user.Department != null) + { + txtDepartmant.Text = _user.Department.DepartmentName; + } + + LoadAvatarAsync(_user.AvatarUrl); + } + + private async void LoadAvatarAsync(string? avatarUrl) + { + if (string.IsNullOrWhiteSpace(avatarUrl)) + { + PictureBox.Image = null; + return; + } + + try + { + if (Uri.TryCreate(avatarUrl, UriKind.Absolute, out Uri? uri) && + (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)) + { + using (HttpClient client = new HttpClient()) + { + byte[] imageData = await client.GetByteArrayAsync(uri); + using (MemoryStream ms = new MemoryStream(imageData)) + { + PictureBox.Image = Image.FromStream(ms); + } + } + } + else + { + string baseDir = AppDomain.CurrentDomain.BaseDirectory; + string[] possiblePaths = { + Path.Combine(baseDir, "Resources", "Uploads", avatarUrl), + Path.Combine(baseDir, "..", "..", "..", "Resources", "Uploads", avatarUrl), + Path.Combine(baseDir, "..", "..", "Resources", "Uploads", avatarUrl), + avatarUrl + }; + + foreach (string path in possiblePaths) + { + if (File.Exists(path)) + { + PictureBox.Image = Image.FromFile(path); + return; + } + } + + PictureBox.Image = null; + } + } + catch + { + PictureBox.Image = null; + } + } + + private void BtnAddPhoto_Click(object? sender, EventArgs e) { + using (OpenFileDialog openFileDialog = new OpenFileDialog()) + { + openFileDialog.Filter = "Resim Dosyaları|*.jpg;*.jpeg;*.png;*.gif;*.bmp|Tüm Dosyalar|*.*"; + openFileDialog.FilterIndex = 1; + openFileDialog.RestoreDirectory = true; + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + _uploadedFilePath = openFileDialog.FileName; + try + { + PictureBox.Image = Image.FromFile(_uploadedFilePath); + } + catch + { + Notifier.Show("Hata", "Seçilen dosya bir resim dosyası değil veya bozuk.", NotificationType.Error); + _uploadedFilePath = null; + } + } + } + } + + private async void BtnSave_Click(object? sender, EventArgs e) + { + if (_user == null) return; + + bool hasChanges = HasChanges(); + + if (!hasChanges) + { + Notifier.Show("Bilgi", "Herhangi bir değişiklik yapılmadı.", NotificationType.Information); + return; + } + + try + { + this.Enabled = false; + Notifier.Show("Kaydediliyor", "Değişiklikler kaydediliyor...", NotificationType.Information); + + await Task.Run(async () => + { + using var context = DatabaseManager.CreateContext(); + var userService = new UserService(context); + + // Kullanıcıyı Find ile çek (tracked entity) + var existingUser = context.Users.Find(_user.Id); + if (existingUser == null) + { + throw new NotFoundException("Güncellenmek istenen kullanıcı bulunamadı."); + } + + // Değişiklikleri uygula + existingUser.Name = txtName.Text.Trim(); + existingUser.Surname = txtSurname.Text.Trim(); + existingUser.Email = txtEmail.Text.Trim(); + existingUser.Phone = string.IsNullOrWhiteSpace(txtPhone.Text) ? null : txtPhone.Text.Trim(); + + // Rol güncelleme + if (!string.IsNullOrWhiteSpace(txtTitle.Text)) + { + var selectedRole = ComboBoxHelper.FindRoleByName(_roles, txtTitle.Text); + if (selectedRole != null) + { + existingUser.RoleId = selectedRole.Id; + } + } + + // Departman güncelleme + if (!string.IsNullOrWhiteSpace(txtDepartmant.Text)) + { + var selectedDepartment = ComboBoxHelper.FindDepartmentByName(_departments, txtDepartmant.Text); + if (selectedDepartment != null) + { + existingUser.DepartmentId = selectedDepartment.Id; + } + else + { + existingUser.DepartmentId = null; + } + } + else + { + existingUser.DepartmentId = null; + } + + // Yeni resim yüklendiyse + if (!string.IsNullOrWhiteSpace(_uploadedFilePath)) + { + var fileUploadService = FileUploadServiceFactory.Create(); + string relativePath = await fileUploadService.UploadProfilePhotoAsync(_uploadedFilePath, _user.Id); + existingUser.AvatarUrl = relativePath; + } + + // CompanyId'yi koru (değiştirilmemeli) + existingUser.CompanyId = _user.CompanyId; + + // Validasyon + if (string.IsNullOrWhiteSpace(existingUser.Name) || existingUser.Name.Length < 2) + throw new ValidationException("İsim alanı en az 2 karakter olmalıdır."); + + if (string.IsNullOrWhiteSpace(existingUser.Surname) || existingUser.Surname.Length < 2) + throw new ValidationException("Soyisim alanı en az 2 karakter olmalıdır."); + + if (string.IsNullOrWhiteSpace(existingUser.Email) || !existingUser.Email.Contains("@")) + throw new ValidationException("Lütfen geçerli bir e-posta adresi giriniz."); + + if (existingUser.RoleId <= 0) + throw new ValidationException("Lütfen kullanıcı için bir rol tanımlayınız."); + + // Kullanıcıyı güncelle - tracked entity olduğu için direkt SaveChanges yeterli + context.SaveChanges(); + }); + + // UI thread'de mesajı göster ve formu kapat + if (this.InvokeRequired) + { + this.Invoke(new Action(() => + { + Notifier.Show("Başarılı", "Kullanıcı bilgileri başarıyla güncellendi.", NotificationType.Success); + this.DialogResult = DialogResult.OK; + + // Mesajın görünmesi için kısa bir gecikme sonrası formu kapat + var timer = new System.Windows.Forms.Timer(); + timer.Interval = 1500; + timer.Tick += (s, args) => + { + timer.Stop(); + timer.Dispose(); + this.Close(); + }; + timer.Start(); + })); + } + else + { + Notifier.Show("Başarılı", "Kullanıcı bilgileri başarıyla güncellendi.", NotificationType.Success); + this.DialogResult = DialogResult.OK; + + // Mesajın görünmesi için kısa bir gecikme sonrası formu kapat + var timer = new System.Windows.Forms.Timer(); + timer.Interval = 1500; + timer.Tick += (s, args) => + { + timer.Stop(); + timer.Dispose(); + this.Close(); + }; + timer.Start(); + } + } + catch (ValidationException ex) + { + this.Invoke(new Action(() => + { + Notifier.Show("Doğrulama Hatası", ex.Message, NotificationType.Error); + this.Enabled = true; + })); + } + catch (BusinessException ex) + { + this.Invoke(new Action(() => + { + Notifier.Show("İş Kuralı Hatası", ex.Message, NotificationType.Error); + this.Enabled = true; + })); + } + catch (Exception ex) + { + this.Invoke(new Action(() => + { + string errorMessage = $"Kullanıcı bilgileri güncellenirken bir hata oluştu: {ex.Message}"; + if (ex.InnerException != null) + { + errorMessage += $"\n\nDetay: {ex.InnerException.Message}"; + } + Notifier.Show("Hata", errorMessage, NotificationType.Error); + this.Enabled = true; + })); + } + } + + private bool HasChanges() + { + if (_originalUser == null || _user == null) return false; + + bool nameChanged = txtName.Text.Trim() != _originalUser.Name; + bool surnameChanged = txtSurname.Text.Trim() != _originalUser.Surname; + bool emailChanged = txtEmail.Text.Trim() != _originalUser.Email; + bool phoneChanged = (txtPhone.Text.Trim() ?? string.Empty) != (_originalUser.Phone ?? string.Empty); + bool avatarChanged = !string.IsNullOrWhiteSpace(_uploadedFilePath); + + bool roleChanged = txtTitle.Text.Trim() != (_user.Role?.RoleName ?? string.Empty); + bool departmentChanged = txtDepartmant.Text.Trim() != (_user.Department?.DepartmentName ?? string.Empty); + + return nameChanged || surnameChanged || emailChanged || phoneChanged || avatarChanged || roleChanged || departmentChanged; + } + + private void BtnCancel_Click(object? sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void label2_Click(object sender, EventArgs e) + { } } From b4c4aadf20ce7a311bc2c410d35efe24aacff2aa Mon Sep 17 00:00:00 2001 From: alisec Date: Mon, 5 Jan 2026 22:01:08 +0300 Subject: [PATCH 2/2] fix: restore splash screen as startup form --- OpsFlow/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpsFlow/Program.cs b/OpsFlow/Program.cs index aa37b01..140ef08 100644 --- a/OpsFlow/Program.cs +++ b/OpsFlow/Program.cs @@ -10,7 +10,7 @@ static void Main() { DotNetEnv.Env.Load(); ApplicationConfiguration.Initialize(); - WindowManager.Run(); + WindowManager.Run(); } } } \ No newline at end of file