温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:大学课程管理系统程序源码(印度)
当前文件:
CourseFinder/Colleges/AddStudentToCollege.aspx.cs[6K,2009-6-12 11:37:43],打开代码结构图
CourseFinder/Colleges/AddStudentToCollege.aspx.cs[6K,2009-6-12 11:37:43],打开代码结构图1using 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 AddStudentToCollege. 17
/// </summary> 18
public partial class AddStudentToCollege : System.Web.UI.Page 19
{ 20
protected System.Web.UI.WebControls.TextBox txtFeesStructure; 21
protected System.Web.UI.WebControls.TextBox txtSeatCount; 22
protected System.Web.UI.WebControls.DropDownList ddlStudentTypes; 23
24
protected void Page_Load(object sender, System.EventArgs e) 25
{ 26
this.Page.Form.DefaultFocus = ddlCourseName.ClientID; 27
28
// Put user code to initialize the page here 29
if ( Page.IsPostBack ) 30
return; 31
32
// Make sure user has logged in before can post a student. 33
34
if ( Session["CurrentUser"] == null ) 35
{ 36
// User has not logged in. Redirect to login page and pass current URL as a query string 37
// so that after login, we can redirect user back to this page again. 38
Response.Redirect("../Members/Login.aspx?ReturnUrl=" + Request.Url.PathAndQuery); 39
} 40
41
// Load the list of students in the drop down. 42
LoadCoursesDropdown(); 43
44
LoadYearsDropdown(); 45
46
string id = Request.QueryString["Id"]; 47
if ( id == null ) 48
{ 49
// No student id is passed in query string. So we are here to add a new student. 50
} 51
else 52
{ 53
// Id is passed as query string. So we are here to edit a student. 54
// Pre populate the student details by the id. 55
LoadClassmatesDetails( int.Parse(id) ); 56
} 57
} 58
59
60
protected void btnSave_Click(object sender, System.EventArgs e) 61
{ 62
int collegeId = int.Parse(Request.QueryString["CollegeId"].ToString()); 63
64
int courseId = Int32.Parse(ddlCourseName.SelectedValue.ToString()); 65
int year = Int32.Parse(ddlYears.SelectedValue.ToString()); 66
string remarks = txtRemarks.Text.Replace("'","''"); 67
68
string query = ""; 69
70
string id = Request.QueryString["Id"]; 71
if ( id == null ) 72
{ 73
// There is no query string passed. We are adding a new one.. 74
query = "insert into Classmates (CollegeId, CourseId, yearCompleted, Remarks, UserId) values(" + collegeId + ", " + courseId + ", " + year + ", '" + remarks + "', '" + Session["CurrentUser"].ToString() + "')"; 75
} 76
else 77
{ 78
// collegeId is passed as query string... this means we are editing an existing one. 79
query = "Update Classmates set CollegeId = '" + collegeId + "', CourseId = " + courseId + ", YearCompleted = '" + year + "', Remarks = '" + remarks + "' where Id = " + id; 80
} 81
82
Utils.DataManager.ExecuteNonQuery(query); 83
84
// Pass the tab "classmates" also to the collegedetails page so that it can display 85
// the Classmates tab by default. 86
Response.Redirect("CollegeDetails.aspx?CollegeId=" + collegeId + "&tab=classmates"); 87
} 88
89
protected void btnCancel_Click(object sender, System.EventArgs e) 90
{ 91
int collegeId = int.Parse(Request.QueryString["CollegeId"].ToString()); 92
93
// Pass the tab "classmates" also to the collegedetails page so that it can display 94
// the Classmates tab by default. 95
Response.Redirect("CollegeDetails.aspx?CollegeId=" + collegeId + "&tab=classmates"); 96
} 97
98
/// <summary> 99
/// This method reads the details of the selected item and prepopulate the Ui for editing. 100
/// </summary> 101
/// <param name="id"></param> 102
private void LoadClassmatesDetails( int id ) 103
{ 104
// Write the query to find the exact record from the database matching the given Id. 105
string query = "Select Classmates.*, Colleges.CollegeName as CollegeName from Classmates, Colleges where Classmates.Id = " + id + " AND Colleges.Id = Classmates.CollegeId"; 106
107
DataTable table = Utils.DataManager.ExecuteQuery(query); 108
DataRow row = table.Rows[0]; 109
110
// Only the administrator or the person who originally submitted this entry can edit this. Make sure 111
// nobody else is trying to edit this. 112
if ( !Utils.Utils.IsOwner(row["UserId"]) ) 113
{ 114
lblMessage.Text = "Sorry, you are not the owner of this submission and you are not allowed to edit this. Please <a href='../Members/Login.aspx?ReturnUrl=" + Request.Url.PathAndQuery + "'>Sign In</a> using an Id with appropriate permissions."; 115
btnSave.Enabled = false; 116
return; 117
} 118
119
lblCollegeName.Text = "<h2>" + row["CollegeName"] + "</h2>"; 120
txtRemarks.Text = row["Remarks"].ToString(); 121
122
// Initialize the drop downs to the saved course. 123
ddlCourseName.Items.FindByValue( row["CourseId"].ToString() ).Selected = true; 124
125
ddlYears.SelectedIndex = -1; // Remove all selections 126
ddlYears.Items.FindByValue( row["YearCompleted"].ToString() ).Selected = true; 127
} 128
129
130
Web Form Designer generated code 149
150
/// <summary> 151
/// This method loads the list of all courses for the selected college. 152
/// </summary> 153
private void LoadCoursesDropdown() 154
{ 155
int collegeId = int.Parse(Request.QueryString["CollegeId"]); 156
string query = "Select Courses.Id, (CourseName + ' (' + majorSubject + ')') as CourseName from Courses, CollegeCourses where Courses.Id = CollegeCourses.CourseId AND CollegeCourses.CollegeId = " + collegeId; 157
DataTable table = Utils.DataManager.ExecuteQuery(query); 158
159
ddlCourseName.DataTextField = "CourseName"; 160
ddlCourseName.DataValueField = "Id"; 161
ddlCourseName.DataSource = table; 162
ddlCourseName.DataBind(); 163
} 164
165
166
/// <summary> 167
/// This method loads the list of years 168
/// </summary> 169
private void LoadYearsDropdown() 170
{ 171
// Populate the years starting from 1925 to (current year + 5) 172
for (int year = (DateTime.Now.Year + 5); year > 1925; year--) 173
{ 174
ddlYears.Items.Add(year.ToString()); 175
} 176
177
// Select current year by default. 178
ddlYears.Items.FindByValue( DateTime.Now.Year.ToString() ).Selected = true; 179
} 180
} 181
} 182






}