-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainView.cs
173 lines (145 loc) · 4.47 KB
/
MainView.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
using DataPresentation.Common;
namespace Views
{
public partial class MainView : Form, IMainView
{
public event Action? OnSave;
public event Action? OnSendPost;
public event Action? OnViewLoaded;
public event Action? OnAuthClick;
public event Action? OnLogoutClick;
public string PostContent
{
get
{
if (postContentTextBox.Text.Length <= 0)
return string.Empty;
return postContentTextBox.Text;
}
protected set
{
if (value != null)
postContentTextBox.Text = value;
}
}
public List<string> UrlList
{
get
{
if (groupUrlsGrid.Rows.Count <= 0)
return new List<string>();
var urls = new List<string>();
foreach(DataGridViewRow urlsRow in groupUrlsGrid.Rows)
{
string? urlValue = urlsRow.Cells[urlColumn.Name].Value?.ToString();
if (urlValue == null || urlValue.Equals(string.Empty))
continue;
urlValue = urlValue.Replace(" ", "");
urls.Add(urlValue);
}
return urls;
}
private set
{
foreach(string url in value)
{
int indexRow = groupUrlsGrid.Rows.Add();
groupUrlsGrid.Rows[indexRow].Cells[urlColumn.Name].Value = url;
}
}
}
public string Username
{
get
{
return usernameLabel.Text;
}
}
public MainView()
{
InitializeComponent();
Load += ViewLoad;
saveButton.Click += SaveClick;
sendPostButton.Click += SendPostClick;
authButton.Click += AuthClick;
logoutButton.Click += LogoutClick;
postContentTextBox.TextChanged += PostContentChanged;
DisableSendButtonIfPostEmpty();
}
public void ShowError(string errorString)
{
LockView(true);
MessageBox.Show(errorString, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
LockView(false);
}
public void SetUrlList(List<string> urlList)
{
if (urlList.Count <= 0)
return;
groupUrlsGrid.Rows.Clear();
UrlList = urlList;
}
public void SetPostContent(string postContent)
{
PostContent = postContent;
}
public void SetUserData(string username)
{
SetUserDataPanelVisible(true);
usernameLabel.Text = username;
}
public void RemoveUserData()
{
SetUserDataPanelVisible(false);
}
public new void Show()
{
Application.Run(this);
}
public void LockView(bool locked)
{
Enabled = !locked;
}
private void SaveClick(object? sender, EventArgs e)
{
if (OnSave != null)
OnSave.Invoke();
}
private void SendPostClick(object? sender, EventArgs e)
{
if (OnSendPost != null)
OnSendPost.Invoke();
}
private void ViewLoad(object? sender, EventArgs e)
{
if (OnViewLoaded != null)
OnViewLoaded.Invoke();
}
private void AuthClick(object? sender, EventArgs e)
{
if (OnAuthClick != null)
OnAuthClick.Invoke();
}
private void LogoutClick(object? sender, EventArgs e)
{
if (OnLogoutClick != null)
OnLogoutClick.Invoke();
}
private void PostContentChanged(object? sender, EventArgs e)
{
DisableSendButtonIfPostEmpty();
}
private void SetUserDataPanelVisible(bool visible)
{
userDataPanel.Visible = visible;
authButton.Visible = !visible;
}
private void DisableSendButtonIfPostEmpty()
{
if (postContentTextBox == null || postContentTextBox.TextLength <= 0)
sendPostButton.Enabled = false;
else
sendPostButton.Enabled = true;
}
}
}