public List <ElectionData> SelectRow_Candidate(int id) { List <ElectionData> clist = new List <ElectionData>(); SqlConnection con = new SqlConnection("Data Source=MOHAMED-PC;Initial Catalog=Elections;Integrated Security=True"); SqlCommand cmd = new SqlCommand("SelectRow_Election", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("ID", id); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { ElectionData e = new ElectionData(); e.Id = Convert.ToInt32(rdr["ID"]); e.ElectedNumber1 = Convert.ToInt32(rdr["ElectedNumber"]); e.ElectedName1 = rdr["ElectedName"].ToString(); e.CandidateNumber1 = Convert.ToInt32(rdr["CandidateNumber"]); e.CandidateName1 = rdr["CandidateName"].ToString(); e.CommissionNumber1 = Convert.ToInt32(rdr["CommissionNumber"]); e.CommissionName1 = rdr["CommissionName"].ToString(); clist.Add(e); } con.Close(); return(clist); }
protected void LinkButton1_Click(object sender, EventArgs e) { LinkButton l = (LinkButton)sender; Label lbl1 = (Label)l.Parent.FindControl("IdLabel"); int id_candidate = Convert.ToInt32(lbl1.Text); Label lbl2 = (Label)l.Parent.FindControl("Commission_fkLabel"); int id_commissiion = Convert.ToInt32(lbl2.Text); ElectionData election = new ElectionData(); ElectionDal eledal = new ElectionDal(); CandidateDal candal = new CandidateDal(); ElectedDal ed = new ElectedDal(); string n = (TextBox1.Text).ToString(); int id = ed.ReturnID(n); election.Elected_fk = id; election.Commission_fk = id_commissiion; election.Candidate_fk = id_candidate; int no = ed.Check_Elected(id); if (no == 0) { eledal.InsertElection(election); Response.Redirect("OK.aspx"); } else { Response.Redirect("VoteInfo.aspx"); } }
public void DeleteElection(ElectionData e) { SqlConnection con = new SqlConnection("Data Source=MOHAMED-PC;Initial Catalog=Elections;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Delete_Election", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", e.Id); con.Open(); cmd.ExecuteNonQuery(); con.Close(); }
public void InsertElection(ElectionData e) { SqlConnection con = new SqlConnection("Data Source=MOHAMED-PC;Initial Catalog=Elections;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Insert_Election", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Elected_FK", e.Elected_fk); cmd.Parameters.AddWithValue("@Candidate_FK", e.Candidate_fk); cmd.Parameters.AddWithValue("@Commission_FK", e.Commission_fk); con.Open(); cmd.ExecuteNonQuery(); con.Close(); }