-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivityDetails.aspx.cs
372 lines (320 loc) · 14.4 KB
/
ActivityDetails.aspx.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using UniStr;
using PolytexControls;
using PolytexObjects;
public partial class ActivityDetails : PolyPage
{
#region VARIABLES
private bool isMobile = false;
private string Path = "";
private int activityId;
private int systemuserId;
private string[] filePaths;
public string clientList = "";
public string clientListId = "";
#endregion
#region METHODS
protected void Page_Load(object sender, EventArgs e)
{
string sUA = Request.UserAgent.Trim().ToLower();
if (sUA.Contains("android"))
{
isMobile = true;
}
clientList = ApplicationData.UpdateClientList(CurrentUser.TerritoryId)[0];
clientListId = ApplicationData.UpdateClientList(CurrentUser.TerritoryId)[1];
string root = HttpContext.Current.Request.PhysicalApplicationPath;
this.Path = root + "ActivityImages\\";
systemuserId = CurrentUser.SystemUserId;
ObjectDataSourceClient.SelectParameters["territoryId"].DefaultValue = CurrentUser.TerritoryId.ToString();
ObjectDataSourceUnit.SelectParameters["territoryId"].DefaultValue = CurrentUser.TerritoryId.ToString();
activityId = Util.ValidateInt(RequestQuerystring("activityId"), 0);
CustomValidatorDate.ErrorMessage = _T["Date_End_Greater_Then_Date_Start"];
CustomValidatorRecommendation.ErrorMessage = _T["ItemRequired"];
CustomValidatorParts.ErrorMessage = _T["ItemRequired"];
CustomValidatorSolution.ErrorMessage = _T["ItemRequired"];
CustomValidatorDescription.ErrorMessage = _T["ItemRequired"];
CustomValidatorImageSize.ErrorMessage = _T["Max_File_Size"];
CustomValidatorCheckClient.ErrorMessage = "Client not exist";
RegularExpressionValidatorDescription.ErrorMessage = _T["Max_Length_400"];
RegularExpressionValidatorParts.ErrorMessage = _T["Max_Length_200"];
RegularExpressionValidatorSolution.ErrorMessage = _T["Max_Length_200"];
RegularExpressionValidatorRecommendations.ErrorMessage = _T["Max_Length_200"];
#region Dynamic DropDownList for Clients and Activity Groups
TextBoxClient.TextChanged += new EventHandler(TextBoxClient_TextBoxChanged);
TextBoxClient.AutoPostBack = true;
DropDownListActivityGroup.AspDropDownList.SelectedIndexChanged += new EventHandler(DropDownListActivityGroup_SelectedIndexChanged);
DropDownListActivityGroup.AspDropDownList.AutoPostBack = true;
#endregion
if (!IsPostBack)
{
switch (PolyUtils.RequestQuerystring("ActionSuccess"))
{
case "1":
SetActionMessage(PolytexLabelActionMessage, ActionMessage.InsertedSuccessfuly);
break;
case "2":
SetActionMessage(PolytexLabelActionMessage, ActionMessage.UpdatedSuccessfuly);
break;
}
DropDownListStartTime.AspDropDownList.DataSource = ApplicationData.GetTimeOptions();
DropDownListStartTime.AspDropDownList.DataBind();
DropDownListTimeEnd.AspDropDownList.DataSource = ApplicationData.GetTimeOptions();
DropDownListTimeEnd.AspDropDownList.DataBind();
DropDownListDriveTime.AspDropDownList.DataSource = ApplicationData.GetDriveTimeOptions();
DropDownListDriveTime.AspDropDownList.DataBind();
if (activityId > 0)
{
//Update fields to existing activity
PolytexObjects.Activity activity = new PolytexObjects.Activity(activityId);
ObjectDataSourceActivityTypes.SelectParameters["ActivityGroupId"].DefaultValue = activity.ActivityGroupId.ToString();
DropDownListActivityGroup.AspDropDownList.SelectedValue = activity.ActivityGroupId.ToString();
DropDownListActivityType.AspDropDownList.SelectedValue = activity.ActivityTypeId.ToString();
ObjectDataSourceUnit.SelectParameters["clientId"].DefaultValue = activity.ClientId.ToString();
DropDownListUnit.AspDropDownList.SelectedValue = activity.UnitId.ToString();
TextBoxClient.Text = ApplicationData.GetClientNameById(activity.ClientId);
HiddenFieldClientId.Value = activity.ClientId.ToString();
TextBoxDescription.Text = activity.Description;
TextBoxParts.Text = activity.Parts;
TextBoxSolution.Text = activity.Solution;
TextBoxRecommendations.Text = activity.Recommendation;
textboxActivityStart.Text = activity.DateStart;
DropDownListStartTime.AspDropDownList.SelectedValue = activity.HourStart;
DropDownListTimeEnd.AspDropDownList.SelectedValue = activity.HourEnd;
DropDownListDriveTime.AspDropDownList.SelectedValue = activity.DriveTime.ToString();
string rootPath = HttpContext.Current.Request.PhysicalApplicationPath;
string[] files = Directory.GetFiles(rootPath+"ActivityImages\\", activityId + "_1.*");
if (files.Length > 0)
{
// Getting the extension of the file
string[] extension = files[0].Split('.');
ImgPreview.ImageUrl = "ActivityImages/" + activityId + "_1." + extension[extension.Length - 1];
}
else
{
ImgPreview.Visible = false;
}
}
else
{
textboxActivityStart.Text = DateTime.Now.ToShortDateString();
ImgPreview.Visible = false;
}
}
}
protected void DropDownListActivityGroup_SelectedIndexChanged(object sender, EventArgs e)
{
System.Web.UI.WebControls.DropDownList dropDownList = (System.Web.UI.WebControls.DropDownList)(sender);
int activityGroupId = Util.ValidateInt(dropDownList.SelectedValue, 0);
if (activityGroupId > 0)
{
ObjectDataSourceActivityTypes.SelectParameters["ActivityGroupId"].DefaultValue = activityGroupId.ToString();
}
}
protected void TextBoxClient_TextBoxChanged(object sender, EventArgs e)
{
ObjectDataSourceUnit.SelectParameters["clientId"].DefaultValue = Util.ValidateInt(HiddenFieldClientId.Value, 0).ToString();
}
public void onButtonClick(object sender, EventArgs e)
{
Page.Validate("GridEditItem");
if (Page.IsValid)
{
PolytexObjects.Activity activity = new Activity();
activity.Id = activityId;
activity.SystemUserId = CurrentUser.SystemUserId;
activity.ClientId = Util.ValidateInt(HiddenFieldClientId.Value, 0);
activity.TerritoryId = Activity.getTerritoryIdByClient(activity.ClientId);
activity.UnitId = Util.ValidateInt(DropDownListUnit.AspDropDownList.SelectedValue, 0);
activity.ActivityGroupId = Util.ValidateInt(DropDownListActivityGroup.AspDropDownList.SelectedValue, 0);
activity.ActivityTypeId = Util.ValidateInt(DropDownListActivityType.AspDropDownList.SelectedValue, 0);
activity.Description = TextBoxDescription.Text.Trim();
activity.Parts = TextBoxParts.Text.Trim();
activity.Solution = TextBoxSolution.Text.Trim();
activity.Recommendation = TextBoxRecommendations.Text.Trim();
string dateStart = textboxActivityStart.Text + " " + DropDownListStartTime.AspDropDownList.SelectedValue + ":00";
activity.DtDateStart = DateTime.Parse(dateStart);
string dateEnd = textboxActivityStart.Text + " " + DropDownListTimeEnd.AspDropDownList.SelectedValue + ":00";
activity.DtDateEnd = DateTime.Parse(dateEnd);
activity.DriveTime = Util.ValidateInt(DropDownListDriveTime.AspDropDownList.SelectedValue, 0);
PolytexControls.Button btn = (PolytexControls.Button)sender;
string id = btn.ID;
if (activityId > 0)
{
activity.update();
UploadFile();
if (id.Equals("ButtonSaveActivity"))
{
Response.Redirect("ActivityDetails.aspx?ActionSuccess=2&activityId=" + activityId.ToString(), true);
//SetActionMessage(ActionMessage.UpdatedSuccessfuly);
}
else
{
Response.Redirect("Activities.aspx", true);
}
}
else
{
activityId = activity.insert();
UploadFile();
if (id.Equals("ButtonSaveActivity"))
{
Response.Redirect("ActivityDetails.aspx?ActionSuccess=1&activityId=" + activityId.ToString(), true);
//SetActionMessage(ActionMessage.InsertedSuccessfuly);
}
else
{
Response.Redirect("Activities.aspx", true);
}
}
}
}
public void ClearFields()
{
activityId = 0;
TextBoxClient.Text = "";
ObjectDataSourceActivityTypes.SelectParameters["ActivityGroupId"].DefaultValue = "";
DropDownListActivityGroup.AspDropDownList.SelectedValue = "";
DropDownListActivityType.AspDropDownList.SelectedValue = "";
DropDownListUnit.AspDropDownList.SelectedValue = "";
TextBoxDescription.Text = "";
TextBoxParts.Text = "";
TextBoxSolution.Text = "";
TextBoxRecommendations.Text = "";
textboxActivityStart.Text = "";
DropDownListStartTime.AspDropDownList.SelectedValue = "";
DropDownListTimeEnd.AspDropDownList.SelectedValue = "";
DropDownListDriveTime.AspDropDownList.SelectedValue = "";
ImgPreview.Visible = false;
FileUploadImage.Dispose();
}
protected void CustomValidator_FileSizeValidate(object source, ServerValidateEventArgs args)
{
string[] extension = FileUploadImage.PostedFile.ContentType.Split('/');
if (extension[0].Equals("image"))
{
if (FileUploadImage.FileBytes.Length > 1024 * 1024 * 8)
{
CustomValidatorImageSize.ErrorMessage = _T["Max_File_Size"];
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
else
{
CustomValidatorImageSize.ErrorMessage = _T["Only_image_files_are_allowed"];
args.IsValid = false;
}
}
protected void CustomValidator_CheckDate(object source, ServerValidateEventArgs args)
{
DateTime dtStart, dtEnd;
SetDatesValues(out dtStart, out dtEnd);
if (dtStart == new DateTime())
{
args.IsValid = false;
CustomValidatorDate.ErrorMessage = _T["General_Message_InvalidInput"];
}
else if (dtEnd == new DateTime())
{
args.IsValid = false;
CustomValidatorDate.ErrorMessage = _T["General_Message_InvalidInput"];
}
else if (dtStart > DateTime.Now.AddDays(1))
{
args.IsValid = false;
CustomValidatorDate.ErrorMessage = _T["Date_Start_Greater_Then_Today"];
}
else if (dtEnd > DateTime.Now.AddDays(1))
{
args.IsValid = false;
CustomValidatorDate.ErrorMessage = _T["Date_End_Greater_Then_Today"];
}
else
{
DateTime dateStartCollision, dateEndCollision;
PolytexData.Manage_Activities.GetUserActivityDateCollision(activityId, CurrentUser.SystemUserId, dtStart, dtEnd, out dateStartCollision, out dateEndCollision);
if (dateStartCollision != new DateTime())
{
args.IsValid = false;
CustomValidatorDate.ErrorMessage = _T["Activity_Collision_Dates"].Replace("%DATE_START%", UniStr.Util.MakeShortTimeByUIDateTimeFormat(dateStartCollision)).Replace("%DATE_END%", UniStr.Util.MakeShortTimeByUIDateTimeFormat(dateEndCollision));
}
else
{
args.IsValid = true;
}
}
}
protected void CustomValidator_CheckTimeEnd(object source, ServerValidateEventArgs args)
{
DateTime dtStart, dtEnd;
SetDatesValues(out dtStart, out dtEnd);
if (dtStart == dtEnd)
{
args.IsValid = false;
CustomValidatorTimeEnd.ErrorMessage = _T["Time_Start_Same_As_Time_End"];
}
else if (dtStart > dtEnd)
{
args.IsValid = false;
CustomValidatorTimeEnd.ErrorMessage = _T["Date_End_Greater_Then_Date_Start"];
}
else
{
args.IsValid = true;
}
}
private void SetDatesValues(out DateTime dtStart, out DateTime dtEnd)
{
dtStart = new DateTime();
dtEnd = new DateTime();
string dateStart = textboxActivityStart.Text.Trim();
string timeStart = DropDownListStartTime.AspDropDownList.SelectedValue;
string timeEnd = DropDownListTimeEnd.AspDropDownList.SelectedValue;
DateTime.TryParse(dateStart + " " + timeStart + ":00", out dtStart);
DateTime.TryParse(dateStart + " " + timeEnd + ":00", out dtEnd);
}
protected void CustomValidator_CheckClientExist(object source, ServerValidateEventArgs args)
{
string name = TextBoxClient.Text;
if (ApplicationData.GetClientIdByName(name)>0)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
public void UploadFile()
{
string[] extension = FileUploadImage.PostedFile.ContentType.Split('/');
if (FileUploadImage.HasFile)
{
try
{
FileUploadImage.SaveAs(Path + activityId + "_1."+extension[1]);
// Show image in Image Preview
ImgPreview.ImageUrl = "ActivityImages/" + activityId + "_1."+extension[1];
ImgPreview.Visible = true;
}
catch (Exception ex)
{
}
}
}
#endregion
}