using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; public partial class MasterPage : System.Web.UI.MasterPage { protected void aa(object sender1, object sender2, object sender3, EventArgs e) { Button2.Text = ""; Button3.Text = ""; Button4.Text = ""; Button5.Text = ""; Button6.Text = ""; Button7.Text = ""; Button8.Text = ""; Button9.Text = ""; Button2.Visible = false; Button3.Visible = false; Button4.Visible = false; Button5.Visible = false; Button6.Visible = false; Button7.Visible = false; Button8.Visible = false; Button9.Visible = false; SqlConnection con; SqlCommand checkuser2, name; int temp2; string cmdsg, cmdsg2, conv, usename; int c, d, m, k = 0, p = 0 ; c = sender1.GetHashCode(); m = sender2.GetHashCode(); d = sender3.GetHashCode(); con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); con.Open(); if (d == 1) { while (k < 8) { conv = Convert.ToString(c); cmdsg = "Select count (*) from text1 where UserNum='" + conv + "'"; checkuser2 = new SqlCommand(cmdsg, con); temp2 = Convert.ToInt32(checkuser2.ExecuteScalar().ToString()); if (temp2 == 1) { cmdsg2 = "Select UserName from text1 where UserNum='" + conv + "'"; name = new SqlCommand(cmdsg2, con); usename = name.ExecuteScalar().ToString(); if (Button2.Text == "") { Session["new4"] = c; Button2.Text = usename; Button2.Visible = true; k += 1; } else if (Button3.Text == "") { Button3.Text = usename; Button3.Visible = true; k += 1; } else if (Button4.Text == "") { Button4.Text = usename; Button4.Visible = true; k += 1; } else if (Button5.Text == "") { Button5.Text = usename; Button5.Visible = true; k += 1; } else if (Button6.Text == "") { Button6.Text = usename; Button6.Visible = true; k += 1; } else if (Button7.Text == "") { Button7.Text = usename; Button7.Visible = true; k += 1; } else if (Button8.Text == "") { Button8.Text = usename; Button8.Visible = true; k += 1; } else if (Button9.Text == "") { Button9.Text = usename; Button9.Visible = true; k += 1; } } if (c >= m && k < 8) { k = 8; p = 1; } c += 1; } if (p == 0 && c < m) { Button11.Visible = true; } if (c >= m) { Button11.Visible = false; } Session["new3"] = c; } /////// end incress if(d==2) { while (k < 8) { conv = Convert.ToString(c); cmdsg = "Select count (*) from text1 where UserNum='" + conv + "'"; checkuser2 = new SqlCommand(cmdsg, con); temp2 = Convert.ToInt32(checkuser2.ExecuteScalar().ToString()); if (temp2 == 1) { cmdsg2 = "Select UserName from text1 where UserNum='" + conv + "'"; name = new SqlCommand(cmdsg2, con); usename = name.ExecuteScalar().ToString(); if (Button9.Text == "") { Button9.Text = usename; Button9.Visible = true; k += 1; } else if (Button8.Text == "") { Button8.Text = usename; Button8.Visible = true; k += 1; } else if (Button7.Text == "") { Button7.Text = usename; Button7.Visible = true; k += 1; } else if (Button6.Text == "") { Button6.Text = usename; Button6.Visible = true; k += 1; } else if (Button5.Text == "") { Button5.Text = usename; Button5.Visible = true; k += 1; } else if (Button4.Text == "") { Button4.Text = usename; Button4.Visible = true; k += 1; } else if (Button3.Text == "") { Button3.Text = usename; Button3.Visible = true; k += 1; } else if (Button2.Text == "") { Button2.Text = usename; Button2.Visible = true; Session["new4"] = c; Session["new3"] = c; k += 1; } } c -= 1; } if (c==1) { Button10.Visible = false ; } } } protected void Page_Load(object sender, EventArgs e) { if (Session["new1"].GetHashCode() == 0) { Session["new1"] = 1; SqlConnection con; SqlCommand way; string cmd, root; int cop; con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); con.Open(); ///////////// for m loop cmd = "select * from text1 where id=(select max(id) from text1)"; way = new SqlCommand(cmd, con); root = way.ExecuteScalar().ToString();//// hw many element in table text1 cop = Convert.ToInt32(root); cmd = "select UserNum from text1 where id='" + cop + "'"; way = new SqlCommand(cmd, con); root = way.ExecuteScalar().ToString();///// the last number in table text1 int m, c = 1, d = 1; m = Convert.ToInt32(root); con.Close(); Session["new2"] = m; Button10.Visible = false; Button11.Visible = false; aa(c, m, d, e); } } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("login.aspx"); } protected void Button3_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button3.Text; Response.Redirect("f1.aspx"); } protected void Button2_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button2.Text; Response.Redirect("f1.aspx"); } protected void Button8_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button8.Text; Response.Redirect("f1.aspx"); } protected void Button11_Click(object sender, EventArgs e) { int c, m,d=1; m = Session["new2"].GetHashCode(); c = Session["new3"].GetHashCode(); aa(c, m, d, e); Button10.Visible = true; } protected void Button10_Click(object sender, EventArgs e) { int c, m,d=2; c = Session["new4"].GetHashCode(); m = Session["new2"].GetHashCode(); c = c - 1; aa(c, m, d, e); Button11.Visible = true; } protected void Button4_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button4.Text; Response.Redirect("f1.aspx"); } protected void Button5_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button5.Text; Response.Redirect("f1.aspx"); } protected void Button6_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button6.Text; Response.Redirect("f1.aspx"); } protected void Button7_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button7.Text; Response.Redirect("f1.aspx"); } protected void Button9_Click(object sender, EventArgs e) { Session["new1"] = 0; Session["new5"] = Button9.Text; Response.Redirect("f1.aspx"); } }