-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profile.cs
219 lines (207 loc) · 8.85 KB
/
Profile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
namespace Instagram
{
public partial class Profile : Form
{
int listViewItemsCount = 0;
ImageList listViewImageList = new ImageList();
DBHandlingUtilities dbHandler;
UIUtilities UI;
string ImageNewName = "";
Main main;
string externalUserId, externalUserName;
bool isExternalProfile;
public Profile(Main main, bool isExternalProfile = false, string _userId = null, string _userName = null)
{
InitializeComponent();
dbHandler = new DBHandlingUtilities();
this.main = main;
this.isExternalProfile = isExternalProfile;
if (isExternalProfile)
{
this.externalUserId = _userId;
this.externalUserName = _userName;
this.themeBtn.Visible = false;
Change_Button_According_To_Data(dbHandler.Check_If_User_Followed_Or_Not(main.userID, main.userName, _userId));
}
else
{
this.externalUserId = main.userID;
this.externalUserName = main.userName;
}
userNameLabel.Text = this.externalUserId;
Configure_Theme();
Retrieve_Profile_Information(this.externalUserId, this.externalUserName);
Add_All_Posts_ThumbNail(this.externalUserId, this.externalUserName);
}
private void Change_Button_According_To_Data(bool isFollowed, bool isChangeOnRunTime = false)
{
if (isFollowed)
{
this.editProfileBtn.Text = "Following";
this.editProfileBtn.BackgroundColor = Color.DodgerBlue;
if (isChangeOnRunTime)
{
this.followersCountLabel.Text = (Int32.Parse(this.followersCountLabel.Text) + 1).ToString();
}
}
else
{
this.editProfileBtn.Text = "Follow";
this.editProfileBtn.BackgroundColor = Color.DarkBlue;
dbHandler.Truncate_Temporary_Post_Table();
dbHandler.Create_View_For_Following_Posts(main.userID, main.userName);
if (isChangeOnRunTime)
{
this.followersCountLabel.Text = (Int32.Parse(this.followersCountLabel.Text) - 1).ToString();
}
}
}
private void Configure_Theme()
{
UI = new UIUtilities(main.lightModeOn);
Color backColor, textColor, barColor;
if (main.lightModeOn)
{
barColor = Color.FromArgb(242, 242, 242);
textColor = Color.FromArgb(0, 0, 0);
backColor = Color.FromArgb(209, 209, 209);
themeBtn.Text = "Dark Mode";
themeBtn.BackColor = Color.FromArgb(105, 105, 105);
themeBtn.Image = Image.FromFile(UI.Return_UI_Location() + "moon.png");
}
else
{
barColor = Color.FromArgb(43, 43, 43);
textColor = Color.FromArgb(255, 255, 255);
backColor = Color.FromArgb(31, 31, 31);
themeBtn.Text = "Light Mode";
themeBtn.BackColor = Color.FromArgb(141, 177, 246);
themeBtn.Image = Image.FromFile(UI.Return_UI_Location() + "sun.png");
}
UI = new UIUtilities(main.lightModeOn);
this.BackColor = backColor;
realUserNameLabel.ForeColor = userNameLabel.ForeColor = followersCountLabel.ForeColor = followingCountLabel.ForeColor = postCountLabel.ForeColor = textColor;
followersIndicatorLabel.ForeColor = followingIndicatorLabel.ForeColor = postIndicatorLabel.ForeColor = taglineBox.ForeColor = textColor;
taglineBox.BackColor = postFeed.BackColor = backColor;
bookMarkBtn.FlatAppearance.BorderSize = streamViewBtn.FlatAppearance.BorderSize = gridViewBtn.FlatAppearance.BorderSize = 0;
bookMarkBtn.FlatStyle = streamViewBtn.FlatStyle = gridViewBtn.FlatStyle = FlatStyle.Flat;
bookMarkBtn.BackColor = streamViewBtn.BackColor = gridViewBtn.BackColor = barColor;
}
public void Retrieve_Profile_Information(string userId, string userName)
{
Console.WriteLine(userId + " " + userName);
List<string> profileInformation = dbHandler.Return_Profile_Information(userId, userName);
profilePictureBox.Bitmap = new Bitmap(dbHandler.Retrieve_Profile_Picture_Using_SQL(Int32.Parse(main.userID)));
userNameLabel.Text = userName;
try
{
followingCountLabel.Text = profileInformation[0];
followersCountLabel.Text = profileInformation[1];
postCountLabel.Text = profileInformation[2];
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
followingCountLabel.Text = "0";
followersCountLabel.Text = "0";
postCountLabel.Text = "0";
}
try
{
realUserNameLabel.Text = profileInformation[3];
taglineBox.Text = profileInformation[4];
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
realUserNameLabel.Text = "";
taglineBox.Text = "";
}
}
private void Add_All_Posts_ThumbNail(string userID, string userName)
{
listViewImageList.ImageSize = new Size(150, 150);
Image[] images = dbHandler.Retrieve_All_Pictures((userName + "_" + userID + "_PostTable"), "PostID", "ORDER BY TimeLine DESC");
if (images != null && images.Length > 0)
{
try
{
for (int i = 0; i < images.Length; i++)
{
try
{
listViewImageList.Images.Add(images[i]);
postFeed.Items.Add(new ListViewItem
{
ImageIndex = listViewItemsCount,
Tag = images[i].Tag.ToString()
}); ; ; ; ; ; ;
listViewItemsCount++;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
postFeed.LargeImageList = listViewImageList;
}
private void editProfile_Click(object sender, EventArgs e)
{
if (isExternalProfile)
{
bool result = dbHandler.Return_True_If_Added_To_Following_Otherwise_False_If_Removed(main.userID, main.userName, this.externalUserId, this.externalUserName);
Change_Button_According_To_Data(result, true);
}
else
{
this.main.form.Dispose();
this.main.form = new SignUp(this.main, this.main.userID, this.userNameLabel.Text, this.realUserNameLabel.Text, this.taglineBox.Text, this.profilePictureBox.ImageLocation) { TopLevel = false, TopMost = true};
}
}
private void customButton1_Click(object sender, EventArgs e)
{
if (main.lightModeOn)
main.lightModeOn = false;
else
main.lightModeOn = true;
Configure_Theme();
main.Configure_Theme();
}
private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
if (e.Label == null)
return;
ImageNewName = Convert.ToString(e.Label);
ListViewItem item1 = postFeed.SelectedItems[0];
FileInfo fileInfo = new FileInfo(item1.Tag.ToString());
fileInfo.MoveTo(fileInfo.Directory.FullName + "\\" + ImageNewName + fileInfo.Extension);
postFeed.Items[listViewItemsCount].Text = ImageNewName;
}
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (postFeed.SelectedIndices.Count <= 0)
{
Console.WriteLine(postFeed.SelectedItems.Count);
return;
}
if (postFeed.SelectedIndices[0] >= 0)
{
var item = postFeed.SelectedItems[0];
string postID = item.Tag.ToString();
main.form.Dispose();
main.form = dbHandler.Return_Post(externalUserId, externalUserName, main.lightModeOn, postID, main);
}
}
}
}