1- using System ;
2- using System . Collections . Generic ;
3- using System . ComponentModel ;
4- using System . Data ;
5- using System . Drawing ;
6- using System . Text ;
7- using System . Windows . Forms ;
1+ using OpsFlow . Core . Models ;
2+ using OpsFlow . Core . Services ;
3+ using OpsFlow . Services . Implementations ;
84
95namespace OpsFlow . UI . Forms . Management ;
106
117public partial class PersonelCard : UserControl
128{
9+ private User ? _user ;
10+
1311 public PersonelCard ( )
1412 {
1513 InitializeComponent ( ) ;
14+ this . Margin = new Padding ( 35 , 35 , 35 , 35 ) ;
15+ }
16+
17+ public void SetUserData ( User user )
18+ {
19+ _user = user ;
20+
21+ lblName . Text = $ "{ user . Name } { user . Surname } ";
22+
23+ string departmentName = user . Department ? . DepartmentName ?? "Departman Yok" ;
24+ btnRoleBadge . Text = departmentName ;
25+
26+ Size textSize = TextRenderer . MeasureText ( departmentName , btnRoleBadge . Font ) ;
27+ int requiredWidth = textSize . Width + 24 ;
28+ int maxWidth = 215 ;
29+ btnRoleBadge . Width = Math . Min ( requiredWidth , maxWidth ) ;
30+
31+ LoadAvatarAsync ( user . AvatarUrl ) ;
32+ }
33+
34+ private async void LoadAvatarAsync ( string ? avatarUrl )
35+ {
36+ if ( string . IsNullOrWhiteSpace ( avatarUrl ) )
37+ {
38+ PictureBox . Image = null ;
39+ return ;
40+ }
41+
42+ try
43+ {
44+ if ( Uri . TryCreate ( avatarUrl , UriKind . Absolute , out Uri ? uri ) &&
45+ ( uri . Scheme == Uri . UriSchemeHttp || uri . Scheme == Uri . UriSchemeHttps ) )
46+ {
47+ using ( HttpClient client = new HttpClient ( ) )
48+ {
49+ byte [ ] imageData = await client . GetByteArrayAsync ( uri ) ;
50+ using ( MemoryStream ms = new MemoryStream ( imageData ) )
51+ {
52+ PictureBox . Image = Image . FromStream ( ms ) ;
53+ }
54+ }
55+ }
56+ else
57+ {
58+ string baseDir = AppDomain . CurrentDomain . BaseDirectory ;
59+ string [ ] possiblePaths = {
60+ Path . Combine ( baseDir , "Resources" , "Uploads" , avatarUrl ) ,
61+ Path . Combine ( baseDir , ".." , ".." , ".." , "Resources" , "Uploads" , avatarUrl ) ,
62+ Path . Combine ( baseDir , ".." , ".." , "Resources" , "Uploads" , avatarUrl ) ,
63+ avatarUrl
64+ } ;
65+
66+ foreach ( string path in possiblePaths )
67+ {
68+ if ( File . Exists ( path ) )
69+ {
70+ PictureBox . Image = Image . FromFile ( path ) ;
71+ return ;
72+ }
73+ }
74+
75+ PictureBox . Image = null ;
76+ }
77+ }
78+ catch
79+ {
80+ PictureBox . Image = null ;
81+ }
1682 }
1783
18- private void btnViewProfile_Click ( object sender , EventArgs e )
84+ private async void btnViewProfile_Click ( object sender , EventArgs e )
1985 {
86+ if ( _user == null ) return ;
87+
2088 if ( this . FindForm ( ) is Form anaForm )
2189 {
2290 Form dimmer = new Form ( ) ;
@@ -27,13 +95,42 @@ private void btnViewProfile_Click(object sender, EventArgs e)
2795 dimmer . StartPosition = FormStartPosition . Manual ;
2896 dimmer . Location = anaForm . Location ;
2997 dimmer . Size = anaForm . Size ;
30- using ( ProfileEditForm popup = new ProfileEditForm ( ) )
98+ using ( ProfileEditForm popup = new ProfileEditForm ( _user ) )
3199 {
32100 popup . StartPosition = FormStartPosition . CenterParent ;
33101 dimmer . Show ( anaForm ) ;
34- popup . ShowDialog ( dimmer ) ;
102+ DialogResult result = popup . ShowDialog ( dimmer ) ;
35103 dimmer . Close ( ) ;
104+
105+ // Eğer kullanıcı bilgileri güncellendiyse, kartı yeniden yükle
106+ if ( result == DialogResult . OK )
107+ {
108+ await RefreshUserDataAsync ( ) ;
109+ }
36110 }
37111 }
38112 }
113+
114+ private async Task RefreshUserDataAsync ( )
115+ {
116+ if ( _user == null ) return ;
117+
118+ try
119+ {
120+ using var context = OpsFlow . Core . Services . DatabaseManager . CreateContext ( ) ;
121+ var userService = new OpsFlow . Services . Implementations . UserService ( context ) ;
122+
123+ // Güncel kullanıcı bilgilerini veritabanından çek
124+ var updatedUser = userService . GetUserById ( _user . Id ) ;
125+ if ( updatedUser != null )
126+ {
127+ // Kartı güncel verilerle yeniden yükle
128+ SetUserData ( updatedUser ) ;
129+ }
130+ }
131+ catch
132+ {
133+ // Hata durumunda sessizce devam et
134+ }
135+ }
39136}
0 commit comments