/* * @Method: EditVenueList_ItemUpdating * @Params: object sender, ListViewDeleteEventArgs e * @Return: void * @Description: This method will be activated on the click of Promote * or Demote venue button. It will decide whether the command is for promotion * or demotion, and then update the database accordingly */ protected void EditVenuesList_ItemUpdating(object sender, ListViewUpdateEventArgs e) { string query = null; venueID = EditVenuesList.SelectedDataKey.Value.ToString(); if (updateArgument == "Promote") { query = "update Venues set IsPromoted=1 where VenueID ='" + venueID + "'"; } else if (updateArgument == "Demote") { query = "update Venues set IsPromoted=0 where VenueID ='" + venueID + "'"; } string result = dbCommander.UpdateRecord(query); //If update is successful if (result == "1") { //Closing database connection dbCommander.CloseConnection(); //Turn the list into default EditVenuesList.SelectedIndex = -1; EditVenuesList.DataBind(); } }
/* * @Method: EditVenuesList_ItemEditing * @Params: object sender, ListViewEditEventArgs e * @Return: void * @Description: This method will be activated on the click of edit button. * The index of the selected item (to be edited) will be assigned for edit, * and the value of that index will be saved in a global variable to be used * later in another method for editing */ protected void EditVenuesList_ItemEditing(object sender, ListViewEditEventArgs e) { EditVenuesList.EditIndex = e.NewEditIndex; //This variable will be used to create edit request editIndex = EditVenuesList.EditIndex; EditVenuesList.DataBind(); }
/* * @Method: EditVenueList_PreRender * @Params: object sender, EventArgs e * @Return: void * @Description: This method will be activated before the ListView is rendered, * it will fetch all the approved venues from the database and bind them to * the ListView object */ protected void EditVenuesList_PreRender(object sender, EventArgs e) { //Configuring Data Source for the ListView string connectionString = ConfigurationManager.ConnectionStrings[dbCommander.sourceString].ConnectionString; string query = stringBuilder.BuildQuery(SearchLocationList.SelectedValue, SearchVenueNameInput.Text, SearchCustomerInput.Text); SqlDataSource source = new SqlDataSource(connectionString, query); EditVenuesList.DataSource = source; EditVenuesList.DataBind(); dbCommander.CloseConnection(); }
/* * @Method: EditVenueList_ItemDeleting * @Params: object sender, ListViewDeleteEventArgs e * @Return: void * @Description: This method will be activated on the click of delete venue button. * The selected VenueID will be assigned to a delete query, and database * will be updated accordingly */ protected void EditVenuesList_ItemDeleting(object sender, ListViewDeleteEventArgs e) { EditVenuesList.SelectedIndex = editIndex; string id = EditVenuesList.SelectedDataKey.Value.ToString(); try { //Delete the images folder string path = Server.MapPath("/Content/Images/") + id; DirectoryInfo directory = Directory.CreateDirectory(path); directory.Delete(true); string query = "delete from Venues where VenueID='" + id + "'"; string result = dbCommander.UpdateRecord(query); //If update is successful if (result == "1") { //Closing database connection dbCommander.CloseConnection(); //Turn the list into default EditVenuesList.EditIndex = -1; EditVenuesList.SelectedIndex = -1; EditVenuesList.DataBind(); //Showing success message ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Alert", "alert('Venue deleted successfully');", true); } } catch (SqlException) { //If the user is not inserted, show that there was an error with the database Response.Write ("<script>alert('Database error, please check your provided data to be correct');</script>"); } }
/* * @Method: CanecelPromoteButton_Click * @Params: object sender, EventArgs e * @Return: void * @Description: This method will be activated on the click of cancel Promote button. * The selected item index will be reset and the ListView items will be refreshed */ protected void CancelPromoteButton_Click(object sender, EventArgs e) { EditVenuesList.SelectedIndex = -1; EditVenuesList.DataBind(); }
/* * @Method: CancelEditButton_Click * @Params: object sender, EventArgs e * @Return: void * @Description: This method will be activated on the click of Cancel edit button. * The edit index will be reset and the ListView will be refreshed */ protected void CancelEditButton_Click(object sender, EventArgs e) { EditVenuesList.EditIndex = -1; EditVenuesList.DataBind(); }
/* * @Method: EditVenueList_SelectedIndexChanging * @Params: object sender, ListViewSelectEventArgs e * @Return: void * @Description: This method will be activated on the click of Promote or Demote button. * The respective item index will be assigned as selected. The ListView will be * refreshed after selection */ protected void EditVenuesList_SelectedIndexChanging(object sender, ListViewSelectEventArgs e) { EditVenuesList.SelectedIndex = e.NewSelectedIndex; EditVenuesList.DataBind(); }