////edit post protected void SaveEdit_Click(object sender, EventArgs e) { if ((txtEditTitle.Text == "") || (txtEditREward.Value == "")) { StringBuilder builder = new StringBuilder(); builder.Append("<script language=JavaScript> ShowEdit(); </script>\n"); Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowEdit", builder.ToString()); lblEditError.Text = "Please enter all required values."; } else { Post post = new Post(1, "Scholarship", HttpUtility.HtmlEncode(txtEditTitle.Text), HttpUtility.HtmlEncode(txtEditDescription.Text)); localDB.Open(); System.Data.SqlClient.SqlCommand editPost = new System.Data.SqlClient.SqlCommand(); editPost.Connection = localDB; editPost.CommandText = "Execute EditPost @id, @title, @PostDate, @description, @lastUpdatedBy, @LastUpdated"; editPost.Parameters.Add("@id", SqlDbType.Int).Value = id.Text; editPost.Parameters.Add("@title", SqlDbType.VarChar, 100).Value = post.getTitle(); editPost.Parameters.Add("@PostDate", SqlDbType.VarChar, 30).Value = post.getPostDate(); editPost.Parameters.Add("@description", SqlDbType.VarChar, 500).Value = post.getDescription(); editPost.Parameters.Add("@lastUpdatedBy", SqlDbType.VarChar, 30).Value = post.getLastUpdatedBy(); editPost.Parameters.Add("@LastUpdated", SqlDbType.VarChar, 30).Value = post.getLastUpdated(); editPost.ExecuteNonQuery(); try { DateTime start = DateTime.Parse(txtEditDueDate.Value); txtEditDueDate.Value = start.ToString("MM/dd/yyyy"); } catch { } Scholarship sch = new Scholarship(id.Text, HttpUtility.HtmlEncode(txtEditRequirements.Text), HttpUtility.HtmlEncode(txtEditREward.Value), HttpUtility.HtmlEncode(txtEditDueDate.Value)); System.Data.SqlClient.SqlCommand editjob = new System.Data.SqlClient.SqlCommand(); editjob.Connection = localDB; editjob.CommandText = "Execute EditScholarship @id, @requirements, @reward, @duedate, @lastUpdatedBy, @lastUpdated"; editjob.Parameters.Add("@id", SqlDbType.Int).Value = sch.getpostID(); editjob.Parameters.Add("@requirements", SqlDbType.VarChar, 100).Value = sch.getReqs(); editjob.Parameters.Add("@reward", SqlDbType.VarChar, 30).Value = sch.getReward(); editjob.Parameters.Add("@duedate", SqlDbType.VarChar, 30).Value = sch.getDueDate(); editjob.Parameters.Add("@lastUpdatedBy", SqlDbType.VarChar, 30).Value = sch.getLastUpdatedBy(); editjob.Parameters.Add("@lastUpdated", SqlDbType.VarChar, 30).Value = sch.getLastUpdated(); editjob.ExecuteNonQuery(); localDB.Close(); showData(); } }
//create scholarship protected void SubmitButton_Click(object sender, EventArgs e) { if ((txtTitle.Text == "") || (txtAmount.Value == "")) { StringBuilder builder = new StringBuilder(); builder.Append("<script language=JavaScript> ShowCreate(); </script>\n"); Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowCreate", builder.ToString()); lblError.Text = "Please enter all required values."; } else { localDB.Open(); //create post object Post post = new Post(1, "Scholarship", HttpUtility.HtmlEncode(txtTitle.Text), HttpUtility.HtmlEncode(txtDescription.Text)); System.Data.SqlClient.SqlCommand insertPost = new System.Data.SqlClient.SqlCommand(); insertPost.Connection = localDB; insertPost.CommandText = "Execute InsertPost @busId, @type, @title, @postDate, @description, @lastUpdatedBy, @lastUpdated"; insertPost.Parameters.Add("@type", SqlDbType.VarChar, 30).Value = post.getType(); insertPost.Parameters.Add("@title", SqlDbType.VarChar, 100).Value = post.getTitle(); insertPost.Parameters.Add("@postDate", SqlDbType.VarChar, 30).Value = post.getPostDate(); insertPost.Parameters.Add("@description", SqlDbType.VarChar, 500).Value = post.getDescription(); insertPost.Parameters.Add("@busID", SqlDbType.Int).Value = post.getBusID(); insertPost.Parameters.Add("@lastUpdatedBy", SqlDbType.VarChar, 30).Value = post.getLastUpdatedBy(); insertPost.Parameters.Add("@lastUpdated", SqlDbType.VarChar, 30).Value = post.getLastUpdated(); insertPost.ExecuteNonQuery(); System.Data.SqlClient.SqlCommand selectPostID = new System.Data.SqlClient.SqlCommand(); selectPostID.Connection = localDB; selectPostID.CommandText = "select max(postID) from Post"; string postID = selectPostID.ExecuteScalar().ToString(); selectPostID.ExecuteNonQuery(); try { DateTime start = DateTime.Parse(txtDeadline.Value); txtDeadline.Value = start.ToString("MM/dd/yyyy"); } catch { } //create scholarship object Scholarship sch = new Scholarship(postID, HttpUtility.HtmlEncode(txtRequirements.Text), HttpUtility.HtmlEncode(txtAmount.Value), HttpUtility.HtmlEncode(txtDeadline.Value)); System.Data.SqlClient.SqlCommand insertScholarship = new System.Data.SqlClient.SqlCommand(); insertScholarship.Connection = localDB; insertScholarship.CommandText = "Execute InsertScholarship @postID, @requirements, @reward, @dueDate, @lastUpdatedBy, @lastUpdated"; insertScholarship.Parameters.Add("@postID", SqlDbType.Int).Value = sch.getpostID(); insertScholarship.Parameters.Add("@requirements", SqlDbType.VarChar, 100).Value = sch.getReqs(); insertScholarship.Parameters.Add("@reward", SqlDbType.VarChar, 30).Value = sch.getReward(); insertScholarship.Parameters.Add("@dueDate", SqlDbType.VarChar, 30).Value = sch.getDueDate(); insertScholarship.Parameters.Add("@lastUpdatedBy", SqlDbType.VarChar, 30).Value = sch.getLastUpdatedBy(); insertScholarship.Parameters.Add("@lastUpdated", SqlDbType.VarChar, 30).Value = sch.getLastUpdated(); insertScholarship.ExecuteNonQuery(); localDB.Close(); showData(); } }