-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain chat window.cs
251 lines (180 loc) · 6.58 KB
/
main chat window.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chatio
{
public partial class Form2 : Form
{
Globle globle = new Globle();
List<User> users;
List<Group> groups;
public Form2()
{
users=globle.contactlist();
groups = globle.grouplist();
InitializeComponent();
}
//chat button
private void pictureBox3_Click_1(object sender, EventArgs e)
{
panel3.Controls.Clear();
panel3contacts(panel3);
panel3.Show();
}
private void pictureBox6_Click(object sender, EventArgs e)
{
panel3.Controls.Clear();
panel3groups(panel3);
}
private void pictureBox2_Click_1(object sender, EventArgs e)
{
contextMenuStrip2.Show(pictureBox2, new Point( 0,pictureBox2.Height));
}
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = Globle.name;
label2.Text = "@"+Globle.uname;
panel3contacts(panel3);
panel3.AutoScroll = true;
}
private void panel3contacts(Panel p)
{
// List<Panel> ls = new List<Panel>();
int i = 1;
foreach(User user in this.users )
{
Label dynamicLabel = new Label();
dynamicLabel.Text = user.FullName;
dynamicLabel.Margin = new Padding(10);
dynamicLabel.Location = new Point(60, i * 65);
dynamicLabel.Height = 20;
dynamicLabel.Width = 100;
dynamicLabel.Click += new EventHandler(contact_Click);
dynamicLabel.Show();
p.Controls.Add(dynamicLabel);
i++;
}
}
private void panel3groups(Panel p)
{
List<Panel> ls = new List<Panel>();
int i = 1;
foreach (Group group in this.groups)
{
Label dynamicLabel = new Label();
dynamicLabel.Text = group.groupname;
dynamicLabel.Name = group.id.ToString();
dynamicLabel.Margin = new Padding(10);
dynamicLabel.Location = new Point(60, i * 65);
dynamicLabel.Height = 20;
dynamicLabel.Width = 100;
dynamicLabel.Click += new EventHandler(group_Click);
dynamicLabel.Show();
p.Controls.Add(dynamicLabel);
i++;
}
}
private void button_Click(object sender, EventArgs e)
{
}
private Timer timer1;
public void InitTimer()
{
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 2000; // in miliseconds
timer1.Start();
panel3groups(panel3);
}
private void timer1_Tick(object sender, EventArgs e)
{
messagebox();
gmessagebox();
}
public void messagebox()
{
var messages = this.globle.messagelist();
textBox3.Clear();
foreach (message m in messages)
{
textBox3.Text += "\r\n" + m.from.ToString() + " : " + m.text.ToString() + "\r\n" + m.created_at.ToString() + "\r\n\r\n";
}
}
public void gmessagebox()
{
var messages = this.globle.gmessagelist();
textBox4.Clear();
foreach (message m in messages)
{
textBox4.Text += "\r\n" + m.from.ToString() + " : " + m.text.ToString() + "\r\n" + m.created_at.ToString() + "\r\n\r\n";
}
}
void contact_Click(object sender, EventArgs e)
{
panel5.Hide();
string fullname=(sender as Label).Text;
int index = users.FindIndex(item => item.FullName==fullname);
string username = users[index].username;
int to=users[index].id;
panel4.Hide();
Globle.to = to;
label4.Text = fullname;
label3.Text = "@"+username;
messagebox();
}
void group_Click(object sender, EventArgs e)
{
panel4.Hide();
panel5.Show();
string gname = (sender as Label).Text;
int index = groups.FindIndex(item => item.groupname == gname);
bool isadmin = groups[index].isadmin;
int to = groups[index].id;
if (isadmin == false) { button1.Hide(); } else { button1.Show();}
Globle.to = to;
this.label5.Text = gname;
gmessagebox();
}
private void pictureBox9_Click(object sender, EventArgs e)
{string query="INSERT INTO `message` (`mid`, `from_user`, `to_user`, `message`, `created_at`) VALUES (NULL, "+Globle.id+", "+Globle.to+", '"+textBox2.Text+"', CURRENT_TIMESTAMP);";
if(textBox2.Text!=" ")
globle.insert(query);
messagebox();
}
private void pictureBox4_Click_1(object sender, EventArgs e)
{
string query = "INSERT INTO `gchat` (`gcid`, `Users_Uid`, `groups_gid`, `message`, `created_at`) VALUES (NULL, " + Globle.id + ", " + Globle.to + ", '" + textBox5.Text + "', CURRENT_TIMESTAMP);";
if (textBox2.Text != " ")
globle.insert(query);
gmessagebox();
}
private void pictureBox8_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.Show();
}
private void button1_Click_1(object sender, EventArgs e)
{
Form4 f4 = new Form4();
f4.Show();
}
private void pictureBox5_Click(object sender, EventArgs e)
{
foreach(Control c in this.panel3.Controls){
if(c is Label && c.Text.Contains(textBox1.Text)){
c.Show();
}
else{
c.Hide();
}
}
}
}
}