//Gabriele 25/11/18 //UPDATE: Gabriele 4/12/18 - to also delete scouting reports for all recruits when applicable protected void BtnDelete_Click(object sender, EventArgs e) { string recruitID = Request.QueryString["id"]; RecruitClass recruit = ConnectionClass.GetRecruit(Convert.ToInt32(recruitID)); string position = recruit.Position; try { ConnectionClass.DeleteReport(recruitID, position); } catch (Exception ex) { throw; } finally { ConnectionClass.DeleteRecruit(recruitID); Response.Redirect("Recruits.aspx"); } }
//Convinience method to get recruit details from databse public static RecruitClass GetRecruit(int id) { RecruitClass recruit = new RecruitClass(); string query = "SELECT * FROM Recruit WHERE RecruitID=@Id"; //SqlDataAdapter sda = new SqlDataAdapter(query, cn); cmd = new SqlCommand(query, cn); try { cn.Open(); cmd.Parameters.AddWithValue("@Id", id); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { recruit.FirstName = reader[1].ToString(); recruit.LastName = reader[2].ToString(); recruit.ContactNumber = reader[3].ToString(); recruit.EmailAddress = reader[4].ToString(); recruit.Birthyear = Convert.ToInt32(reader[5]); recruit.GraduationYear = Convert.ToInt32(reader[6]); recruit.CurrentTeam = reader[7].ToString(); recruit.JerseyNumber = Convert.ToInt32(reader[8]); recruit.Position = reader[9].ToString(); recruit.MothersName = reader[10].ToString(); recruit.FathersName = reader[11].ToString(); recruit.Status = reader[12].ToString(); recruit.DateAdded = Convert.ToDateTime(reader[13]); } reader.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { cn.Close(); } return(recruit); }
// 25/11/18 Gabriele //Updated to master //UPDATE: Gabriele 4/12/18 - to also delete scouting reports for all recruits when applicable protected void ListViewRecruits_deleteRecruit(object sender, ListViewCommandEventArgs e) { string recruitID = e.CommandArgument.ToString(); RecruitClass recruit = ConnectionClass.GetRecruit(Convert.ToInt32(recruitID)); string position = recruit.Position; try { ConnectionClass.DeleteReport(recruitID, position); } catch (Exception ex) { throw; } finally { if (e.CommandName == "deleteRecruit") { ConnectionClass.DeleteRecruit(recruitID); Page.Response.Redirect(Page.Request.Url.ToString(), true); } } }