1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Web;
7
using System.Web.SessionState;
8
using System.Web.UI;
9
using System.Web.UI.WebControls;
10
using System.Web.UI.HtmlControls;
11
12
13
namespace IndiaStudyChannel.Colleges
14
...{
15
/**//// <summary>
16
/// Summary description for CollegeDetails.
17
/// </summary>
18
public partial class CollegeDetails : System.Web.UI.Page
19
...{
20
protected System.Web.UI.WebControls.DataGrid dgPhotos;
21
protected string collegeName = "";
22
protected string collegeCity = "";
23
24
protected void Page_Load(object sender, System.EventArgs e)
25
...{
26
int id = int.Parse(Request.QueryString["CollegeId"]);
27
28
ShowCollegeDetails(id);
29
30
string tab = Request.QueryString["Tab"];
31
if ( tab == null || tab == "courses" )
32
...{
33
// We are in the courses tab.. show all courses of this college.
34
pnlCourses.Visible = true;
35
36
if ( ! Page.IsPostBack )
37
LoadCourses(id);
38
}
39
else if ( tab == "classmates" )
40
...{
41
// We are in the classmates tab.
42
pnlClassmates.Visible = true;
43
44
// Set the default button so that when user press ENTER in this page, it will trigger the search for classmates!
45
Page.Form.DefaultButton = btnSearchClassmates.UniqueID;
46
47
if ( ! Page.IsPostBack )
48
...{
49
LoadCoursesDropdown();
50
LoadYearsDropdown();
51
LoadClassmates(id);
52
}
53
}
54
else if ( tab == "photos" )
55
...{
56
// We are in the photos tab.
57
pnlPhotos.Visible = true;
58
LoadPhotos(id);
59
60
string pageAction = Request.QueryString["PageAction"];
61
if ( pageAction == "addphoto" )
62
...{
63
// User has clicked the 'Add Photos' link. Show the panel to upload photos.
64
pnlEditPhotos.Visible = true;
65
}
66
67
// If the current user is an administrator, then show the link to upload photo.
68
if ( Utils.Utils.IsAdministrator() )
69
...{
70
lblAddPhoto.Text = "<a href='CollegeDetails.aspx?CollegeId=" + Request.QueryString["CollegeId"].ToString() + "&tab=photos&pageaction=addphoto'>Add New Photo</a>";
71
}
72
else
73
...{
74
lblAddPhoto.Text = "只有管理员才有上传图片的权限,如果你有突破推荐请<a href='../general/Contactus.aspx'>发给我们</a>.";
75
}
76
}
77
}
78
79
College Details#region College Details
80
81
/**//// <summary>
82
/// Edit College
83
/// </summary>
84
/// <param name="sender"></param>
85
/// <param name="e"></param>
86
protected void lnkEdit_Click(object sender, System.EventArgs e)
87
...{
88
int id = int.Parse(Request.QueryString["CollegeId"].ToString());
89
90
Response.Redirect("AddCollege.aspx?CollegeId=" + id);
91
}
92
93
/**//// <summary>
94
/// Delete College
95
/// </summary>
96
/// <param name="sender"></param>
97
/// <param name="e"></param>
98
protected void lnkDelete_Click(object sender, System.EventArgs e)
99
...{
100
if ( ! Utils.Utils.IsAdministrator() )
101
...{
102
lblMessage.Text = "Sorry, only administrator has permission to delete this entry.";
103
return;
104
}
105
106
int id = int.Parse(Request.QueryString["CollegeId"].ToString());
107
DeleteCollege(id);
108
109
Response.Redirect("Index.aspx");
110
}
111
112
/**//// <summary>
113
/// This method displays the details of the specific college
114
/// </summary>
115
/// <param name="collegeId"></param>
116
private void ShowCollegeDetails(int collegeId)
117
...{
118
// Query to retrieve college details.
119
string query = "Select Colleges.*, Universities.UniversityName from Colleges, Universities where Universities.id = Colleges.UniversityId AND Colleges.Id ='" + collegeId + "'";
120
DataTable table = Utils.DataManager.ExecuteQuery(query);
121
122
if ( table.Rows.Count > 0 )
123
...{
124
DataRow dr = table.Rows[0]; // take the first row since we can assume that there will be only one row matching the id.
125
126
// Only the administrator or the person who originally submitted this college can edit this. Make sure
127
// nobody else is trying to edit this.
128
if ( Utils.Utils.IsOwner(dr["PostedUser"]) )
129
...{
130
lnkEdit.Visible = true;
131
}
132
else
133
...{
134
lnkEdit.Visible = false;
135
}
136
137
// Only administrator can delete a college.
138
if ( Utils.Utils.IsAdministrator() )
139
...{
140
lnkDelete.Visible = true;
141
}
142
else
143
...{
144
lnkDelete.Visible = false;
145
}
146
147
collegeName = dr["CollegeName"].ToString();
148
149
// Ensure the word 'university' is there in the title so that when any one
150
// search for this college name, search engines will show our page!
151
if (collegeName.ToLower().IndexOf("college") == -1)
152
collegeName = collegeName + " College";
153
154
collegeCity = dr["City"].ToString();
155
156
lblName2.Text = dr["CollegeName"].ToString();
157
lblCollegeName.Text = dr["CollegeName"].ToString();
158
lblAddress.Text = dr["Address"].ToString();
159
lblCity.Text = dr["City"].ToString();
160
lblState.Text = dr["State"].ToString();
161
lblPhoneNumber1.Text = dr["PhoneNumber1"].ToString();
162
lblPhoneNumber2.Text = dr["PhoneNumber2"].ToString();
163
lblEmail.Text = dr["Email"].ToString();
164
lblHomePage.Text = dr["HomePage"].ToString();
165
lblUniversity.Text = "<a href='../universities/UniversityDetails.aspx?Id=" + dr["UniversityId"].ToString() + "'>" + dr["UniversityName"].ToString() + "</a>";
166
lblDescription.Text = dr["Description"].ToString();
167
168
this.Master.Page.Title = collegeName + " " + dr["City"].ToString() + " phone number & email address";
169
}
170
}
171
172
// This method is to delete a college based on it's Id.
173
private void DeleteCollege(int id )
174
...{
175
// Before we delete a college, we must delete all courses offered in this college.
176
// Query to delete all college courses for this college
177
string query = "delete from CollegeCourses Where CollegeId = " + id;
178
Utils.DataManager.ExecuteNonQuery(query);
179
180
query = "delete from Classmates Where CollegeId = " + id;
181
Utils.DataManager.ExecuteNonQuery(query);
182
183
query = "delete from Colleges Where Id = " + id;
184
Utils.DataManager.ExecuteNonQuery(query);
185
}
186
187
#endregion
188
189
Courses#region Courses
190
191
/**//// <summary>
192
/// Load all courses running in this college.
193
/// </summary>
194
/// <param name="collegeId"></param>
195
private void LoadCourses(int collegeId)
196
...{
197
// Query to find the courses offered in this college.
198
string query = "Select CollegeCourses.Id, Courses.Id as CourseId, CourseName, MajorSubject, FeesStructure, Seats, Remarks from Courses, CollegeCourses where CollegeCourses.CollegeId = " + collegeId + " AND COurses.Id = CollegeCourses.COurseId";
199
200
DataTable data = Utils.DataManager.ExecuteQuery(query);
201
202
if ( data.Rows.Count == 0 )
203
...{
204
lblMessage1.Text = "No courses available.";
205
}
206
else
207
...{
208
dgCourses.DataSource = data;
209
dgCourses.DataBind();
210
}
211
}
212
213
/**//// <summary>
214
/// This method is called from the data grid when the administrator clicks Edit or Delete link.
215
/// </summary>
216
/// <param name="sender"></param>
217
/// <param name="e"></param>
218
protected void dgCourses_RowCommand(object sender, DataGridCommandEventArgs e)
219
...{
220
string argument = e.CommandArgument.ToString();
221
222
if (e.CommandName == "Delete")
223
...{
224
// Delete the row.
225
string query = "delete from CollegeCourses Where Id = " + argument;
226
227
Utils.DataManager.ExecuteNonQuery(query);
228
229
LoadCourses(int.Parse(Request.QueryString["Id"].ToString()));
230
}
231
else if (e.CommandName == "Edit")
232
...{
233
Response.Redirect("AddCourseToCollege.aspx?Id=" + argument + "&CollegeId=" + Request.QueryString["id"].ToString());
234
}
235
}
236
237
/**//// <summary>
238
/// This method is called from the courses data grid
239
/// </summary>
240
/// <param name="sender"></param>
241
/// <param name="e"></param>
242
protected void dgCourses_DataBind(object sender, DataGridItemEventArgs e)
243
...{
244
if ( ! Utils.Utils.IsAdministrator() )
245
...{
246
// If not administrator, then hide delete and delete columns.
247
e.Item.Cells[5].Visible = false;
248
e.Item.Cells[6].Visible = false;
249
}
250
}
251
252
/**//// <summary>
253
/// This method is called when the page index is changed in the datagrid.
254
/// </summary>
255
/// <param name="o"></param>
256
/// <param name="e"></param>
257
protected void dgCourses_PageChanger(object o, DataGridPageChangedEventArgs e)
258
...{
259
dgCourses.CurrentPageIndex = e.NewPageIndex;
260
261
int id = int.Parse(Request.QueryString["Id"]);
262
LoadCourses(id);
263
}
264
265
#endregion Courses
266
267
Classmates#region Classmates
268
269
/**//// <summary>
270
/// Load all classmates for this college.
271
/// </summary>
272
/// <param name="collegeId"></param>
273
private void LoadClassmates(int collegeId)
274
...{
275
// Query to find the courses offered in this college.
276
string query = "Select Classmates.Id, Courses.Id as CourseId, CourseName, MajorSubject, Members.Name as MemberName, Classmates.userId, YearCompleted from Courses, Members, Classmates where Classmates.CollegeId = " + collegeId + " AND Classmates.userId = Members.userId AND Classmates.CourseId = Courses.Id";
277
278
if ( txtName.Text != "" && txtName.Text != null )
279
...{
280
query += " AND Members.Name like '%" + txtName.Text + "%' ";
281
}
282
283
if ( ddlCourses.SelectedIndex > 0 )
284
...{
285
query += " AND Courses.CourseName = '" + ddlCourses.SelectedValue + "' ";
286
}
287
288
if ( ddlMajors.SelectedIndex > 0 )
289
...{
290
query += " AND Courses.MajorSubject = '" + ddlMajors.SelectedValue + "' ";
291
}
292
293
if ( ddlYears.SelectedIndex > 0 )
294
...{
295
query += " AND Classmates.YearCompleted = '" + ddlYears.SelectedValue + "' ";
296
}
297
298
DataTable data = Utils.DataManager.ExecuteQuery(query);
299
300
if ( data.Rows.Count == 0 )
301
...{
302
lblMessage1.Text = "No students listed.<BR>";
303
}
304
else
305
...{
306
lblMessage1.Text = "";
307
}
308
309
dgClassmates.DataSource = data;
310
dgClassmates.DataBind();
311
}
312
313
protected void btnSearchClassmates_Click(object sender, System.EventArgs e)
314
...{
315
int collegeId = int.Parse(Request.QueryString["CollegeId"].ToString());
316
317
LoadClassmates(collegeId);
318
}
319
320
/**//// <summary>
321
/// This method is called from the data grid when the administrator clicks Edit or Delete link.
322
/// </summary>
323
/// <param name="sender"></param>
324
/// <param name="e"></param>
325
protected void dgClassmates_RowCommand(object sender, DataGridCommandEventArgs e)
326
...{
327
string argument = e.CommandArgument.ToString();
328
329
if (e.CommandName == "Delete")
330
...{
331
// Delete the row.
332
string query = "delete from Classmates Where Id = " + argument;
333
334
Utils.DataManager.ExecuteNonQuery(query);
335
336
LoadClassmates(int.Parse(Request.QueryString["CollegeId"].ToString()));
337
}
338
else if (e.CommandName == "Edit")
339
...{
340
Response.Redirect("AddStudentToCollege.aspx?Id=" + argument + "&CollegeId=" + Request.QueryString["CollegeId"].ToString());
341
}
342
}
343
344
/**//// <summary>
345
/// This method is called from the Classmates datagrid.
346
/// </summary>
347
/// <param name="sender"></param>
348
/// <param name="e"></param>
349
protected void dgClassmates_DataBind(object sender, DataGridItemEventArgs e)
350
...{
351
if ( ! Utils.Utils.IsAdministrator() )
352
...{
353
// If not administrator, then hide edit and delete columns.
354
e.Item.Cells[4].Visible = false;
355
e.Item.Cells[5].Visible = false;
356
}
357
}
358
359
/**//// <summary>
360
/// This method is called when the page index is changed in the datagrid.
361
/// </summary>
362
/// <param name="o"></param>
363
/// <param name="e"></param>
364
protected void dgClassmates_PageChanger(object o, DataGridPageChangedEventArgs e)
365
...{
366
dgCourses.CurrentPageIndex = e.NewPageIndex;
367
368
int id = int.Parse(Request.QueryString["CollegeId"]);
369
LoadClassmates(id);
370
}
371
372
/**//// <summary>
373
/// This method loads the list of years
374
/// </summary>
375
private void LoadYearsDropdown()
376
...{
377
ddlYears.Items.Add("ALL");
378
379
// Populate the years starting from 1925 to (current year + 5)
380
for (int year = (DateTime.Now.Year + 5); year > 1925; year--)
381
...{
382
ddlYears.Items.Add(year.ToString());
383
}
384
385
ddlYears.SelectedIndex = 0;
386
}
387
388
/**//// <summary>
389
/// This method loads the list of all courses for the selected college.
390
/// </summary>
391
private void LoadCoursesDropdown()
392
...{
393
int collegeId = int.Parse(Request.QueryString["CollegeId"]);
394
string query = "Select DISTINCT CourseName from Courses, CollegeCourses where Courses.Id = CollegeCourses.CourseId AND CollegeCourses.CollegeId = " + collegeId;
395
DataTable table = Utils.DataManager.ExecuteQuery(query);
396
397
ddlCourses.DataTextField = "CourseName";
398
ddlCourses.DataValueField = "CourseName";
399
ddlCourses.DataSource = table;
400
ddlCourses.DataBind();
401
402
ddlCourses.Items.Insert(0, "ALL");
403
}
404
405
#endregion Classmates
406
407
College Photos#region College Photos
408
409
/**//// <summary>
410
/// Load all photos for this college.
411
/// </summary>
412
/// <param name="collegeId"></param>
413
private void LoadPhotos(int collegeId)
414
...{
415
// Query to find the courses offered in this college.
416
string query = "Select * from CollegePhotos where CollegeId = " + collegeId;
417
418
DataTable data = Utils.DataManager.ExecuteQuery(query);
419
420
if ( data.Rows.Count == 0 )
421
...{
422
lblMessage1.Text = "No photos listed.<BR>";
423
}
424
else
425
...{
426
lblPhotos.Text = "<table><tr>";
427
int count = 0;
428
foreach (DataRow row in data.Rows )
429
...{
430
count = count + 1;
431
lblPhotos.Text += "<td><a href='ViewPhoto.aspx?PhotoId=" + row["Id"].ToString() + "'><img src='../pictures/colleges/thumbs/" + row["PhotoPath"].ToString() + "' border=0></a> </td>";
432
if ( count % 5 == 0 )
433
...{
434
lblPhotos.Text += "</TR><TR>";
435
}
436
}
437
lblPhotos.Text += "</TR></table>";
438
}
439
}
440
441
/**//// <summary>
442
/// This event is triggered when user press the SAVE button on photo upload panel.
443
/// </summary>
444
/// <param name="sender"></param>
445
/// <param name="e"></param>
446
protected void btnSave_Click(System.Object sender, System.EventArgs e)
447
...{
448
if ( !Utils.Utils.IsAdministrator() )
449
return;
450
451
string pageAction = Request.QueryString["PageAction"].ToString();
452
453
if ( pageAction.ToLower() != "addphoto" )
454
...{
455
lblMessage.Text = "Invalid Page Action";
456
return;
457
}
458
459
string fileName = "";
460
461
if ( File1.PostedFile == null || File1.PostedFile.FileName == "")
462
...{
463
lblMessage.Text = "Please select an image file by clicking on the 'Browse' button.";
464
lblMessage.ForeColor = Color.FromName("RED");
465
return;
466
}
467
468
int collegeId = Int32.Parse(Request.QueryString["CollegeId"]);
469
string title = Utils.Utils.MakeSafeWord(txtPhotoTitle.Text);
470
471
bool primary = chkPrimary.Checked; // This flag indicates whether the photo is an important photo
472
473
if ( File1.PostedFile != null && File1.PostedFile.FileName != "" )
474
...{
475
// Make a filename
476
fileName = Int32.Parse(Request.QueryString["CollegeId"]) + "__" + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + "__" + System.IO.Path.GetFileName(File1.PostedFile.FileName);
477
478
// let us save the image into a folder
479
string savePath = Server.MapPath("../pictures/colleges/");
480
481
// Let us create another folder for the thumbnail images.
482
string thumbsPath = savePath + "/thumbs/";
483
484
string saveFileFullName = System.IO.Path.Combine(savePath, fileName);
485
string thumbFileFullName = System.IO.Path.Combine(thumbsPath, fileName);
486
487
System.IO.Directory.CreateDirectory(savePath);
488
System.IO.Directory.CreateDirectory(thumbsPath);
489
490
File1.PostedFile.SaveAs(saveFileFullName);
491
PictureUploadManager.CreateThumbNail(File1.PostedFile.InputStream, thumbFileFullName, 200);
492
}
493
494
// Save a record in the CollegePhotos table with the Photo file name. The actual photo is saved as a file in the hard disk.
495
Utils.DataManager.ExecuteNonQuery("insert into CollegePhotos (CollegeId, PhotoPath, Title, [Primary], PostedUser) values (" + collegeId + ", '" + fileName + "', '" + title + "', " + (primary == true ? 1 : 0) + ", '" + Session["CurrentUser"].ToString() + "')");
496
497
// Relead the photos so that the new photo also will appear.
498
LoadPhotos(collegeId);
499
}
500
501
protected void btnCancel_Click(System.Object sender, System.EventArgs e)
502
...{
503
pnlEditPhotos.Visible = false;
504
}
505
506
#endregion
507
508
Web Form Designer generated code#region Web Form Designer generated code
509
override protected void OnInit(EventArgs e)
510
...{
511
//
512
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
513
//
514
InitializeComponent();
515
base.OnInit(e);
516
}
517
518
/**//// <summary>
519
/// Required method for Designer support - do not modify
520
/// the contents of this method with the code editor.
521
/// </summary>
522
private void InitializeComponent()
523
...{
524
this.lnkEdit.Click += new System.EventHandler(this.lnkEdit_Click);
525
this.lnkDelete.Click += new System.EventHandler(this.lnkDelete_Click);
526
this.btnSearchClassmates.Click += new System.EventHandler(this.btnSearchClassmates_Click);
527
this.Load += new System.EventHandler(this.Page_Load);
528
}
529
#endregion
530
531
}
532
}
533