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 63565fd..7c4aca8 100644 --- a/OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs +++ b/OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs @@ -58,7 +58,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,7 +66,7 @@ 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 @@ -94,7 +93,7 @@ private void InitializeComponent() // 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; @@ -112,14 +111,14 @@ 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; // // btnRoleBadge @@ -131,23 +130,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"; // @@ -155,11 +154,11 @@ 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; // @@ -181,7 +180,7 @@ 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)pictureBox2).EndInit(); 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/PersonelListForm.Designer.cs b/OpsFlow/UI/Forms/Management/PersonelListForm.Designer.cs index 21a941d..9071617 100644 --- a/OpsFlow/UI/Forms/Management/PersonelListForm.Designer.cs +++ b/OpsFlow/UI/Forms/Management/PersonelListForm.Designer.cs @@ -100,14 +100,14 @@ private void InitializeComponent() 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 = customizableEdges2; txtSearch.Size = new Size(227, 52); @@ -122,9 +122,9 @@ private void InitializeComponent() 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 = customizableEdges4; btnAddNewMember.Size = new Size(193, 64); @@ -144,10 +144,10 @@ private void InitializeComponent() 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 = customizableEdges6; cmbFilterStatus.Size = new Size(230, 36); @@ -160,7 +160,7 @@ private void InitializeComponent() guna2Panel3.Controls.Add(guna2HtmlLabel4); 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 = customizableEdges8; guna2Panel3.Size = new Size(260, 194); @@ -169,22 +169,22 @@ private void InitializeComponent() // 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"; // @@ -200,10 +200,10 @@ private void InitializeComponent() 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 = customizableEdges10; cmbFilterRole.Size = new Size(230, 36); @@ -216,7 +216,7 @@ private void InitializeComponent() guna2Panel2.Controls.Add(guna2HtmlLabel3); 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 = customizableEdges12; guna2Panel2.Size = new Size(275, 194); @@ -225,22 +225,22 @@ private void InitializeComponent() // 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; @@ -257,7 +257,7 @@ private void InitializeComponent() 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); @@ -282,22 +282,22 @@ private void InitializeComponent() // 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/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) + { } }