-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathElections.aspx.cs
94 lines (84 loc) · 3.37 KB
/
Elections.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Elections : System.Web.UI.Page
{
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
}
protected void apply_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string firstColData = grdrow.Cells[0].Text;
string name = grdrow.Cells[1].Text;
string secondColData = grdrow.Cells[2].Text;
string thirdColData = grdrow.Cells[3].Text;
DateTime start = Convert.ToDateTime(secondColData);
DateTime end = Convert.ToDateTime(thirdColData);
if (DateTime.Now <= start)
{
string str = ConfigurationManager.ConnectionStrings["votingdatabase"].ToString();
con = new SqlConnection(str);
con.Open();
string command = "insert into candidates values('" + Context.User.Identity.Name + "'," + Convert.ToInt32(firstColData) + ",'"+name+"')";
SqlCommand cmd = new SqlCommand(command, con);
try {
cmd.ExecuteNonQuery();
}
catch(SqlException dsfve)
{
Label1.Text = "Already applied for this election.";
}
con.Close();
LinkButton l1 = sender as LinkButton;
l1.Visible = false;
}
else if(DateTime.Now >start && DateTime.Now <=end)
{
Label1.Text = "Election Currently going on! Please vote";
}
else
{
Label1.Text = "Election Over!!";
}
}
protected void vote_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string firstColData = grdrow.Cells[0].Text;
string name = grdrow.Cells[1].Text;
string secondColData = grdrow.Cells[2].Text;
string thirdColData = grdrow.Cells[3].Text;
DateTime start = Convert.ToDateTime(secondColData);
DateTime end = Convert.ToDateTime(thirdColData);
if (DateTime.Now >= start && DateTime.Now <= end)
Response.Redirect("voting.aspx?id="+firstColData+"&title="+ name );
else if (DateTime.Now < start)
Label1.Text = "Election not started!!";
else
Label1.Text = "Election Over!!";
}
protected void result_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string firstColData = grdrow.Cells[0].Text;
string name = grdrow.Cells[1].Text;
string secondColData = grdrow.Cells[2].Text;
string thirdColData = grdrow.Cells[3].Text;
DateTime start = Convert.ToDateTime(secondColData);
DateTime end = Convert.ToDateTime(thirdColData);
if (DateTime.Now >= end)
Response.Redirect("result.aspx?id=" + firstColData + "&title=" + name);
else if (DateTime.Now >= start && DateTime.Now < end)
Label1.Text = "Election Currently going on! Please vote";
else
Label1.Text = "Election not started!!" ;
}
}