Разработка WEB приложений в ASP,NET, страница 4

public  static int num=0;

public static int LabelsCount = 0;

public static int CaseMesto = 0;

public static int CaseRiad = 0;

//

public static int SeansKey = 0;

public static string LastBtnName = "";

}

//private static Global GlobalVars= new Global();

protected void Page_Init(object sender, EventArgs e)

{

if (Session[CONTROLS_STORE] == null) Session[CONTROLS_STORE] = buttons;

else buttons = (List<Button>)Session[CONTROLS_STORE];

int LbCount = 0;

foreach (Button b in buttons)

{

if (b.Text == "br")

{

Label lb = new Label();

lb.Text = "<br>";

LbCount++;

lb.ID = "L" + LbCount;

this.Form.Controls.Add(lb);

}

else

{

b.Click += new EventHandler(foo);

this.Form.Controls.Add(b);

}

}

Global.LabelsCount = LbCount;

}

protected void foo(object sender, EventArgs e)

{

if (((Button)sender).BackColor == System.Drawing.Color.Red)

return;

if ((Global.CaseRiad != 0) && (Global.CaseMesto != 0))

{

string BtnName = "";

BtnName = Global.CaseRiad + "_" + Global.CaseMesto;

Button btnAddress = (Button)form1.FindControl(BtnName);

btnAddress.BackColor = System.Drawing.Color.Green;

}

((Button)sender).BackColor = System.Drawing.Color.Yellow;

Global.LastBtnName = ((Button)sender).ID;

string tmpNum="";

int i=0;

while (Global.LastBtnName[i]!='_')

{

tmpNum=tmpNum+Global.LastBtnName[i];

i++;

}

Global.CaseRiad =Convert.ToInt32(tmpNum);

tmpNum="";

i++;

while (i<Global.LastBtnName.Length)

{

tmpNum=tmpNum+Global.LastBtnName[i];

i++;

}

Global.CaseMesto =Convert.ToInt32(tmpNum);

RiadLabel.Text = Convert.ToString(Global.CaseRiad);

MestoLabel.Text = Convert.ToString(Global.CaseMesto);

//Получим цену билета(извращение конечно...)

string Key = "INSERT INTO Bilet ([Код сеанса],место, ряд, цена) VALUES(" + Global.SeansKey + "," + Global.CaseMesto

+ "," + Global.CaseRiad + ",1" + ")";

SqlConnection myConnection = new SqlConnection("server=localhost;Database=MOVIES;Trusted_Connection=Yes");

SqlCommand comm = new SqlCommand(Key, myConnection);

myConnection.Open();

comm.ExecuteNonQuery();

//////

DataSet dataset = new DataSet();

SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from Bilet where Bilet.[Код сеанса]=" + Global.SeansKey

+ " and Bilet.[ряд]=" + Global.CaseRiad + " and Bilet.[место]=" + Global.CaseMesto, myConnection);

adapter.Fill(dataset, "Bilet");

foreach (DataRow Row in dataset.Tables["Bilet"].Rows)

{

CenaLabel.Text = Convert.ToString(Row["Цена"]);

}

//////

Key = "DELETE from Bilet where Bilet.[Код сеанса]=" + Global.SeansKey

+ " and Bilet.[ряд]=" + Global.CaseRiad + " and Bilet.[место]=" + Global.CaseMesto;

SqlCommand comm2 = new SqlCommand(Key, myConnection);

comm2.ExecuteNonQuery();

myConnection.Close();

}

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Page_Close(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

if (Global.CaseRiad == 0)

{

//ShowMessage

}

string Key = "INSERT INTO Bilet ([Код сеанса],место, ряд, цена) VALUES("+Global.SeansKey+"," + Global.CaseMesto

+ "," + Global.CaseRiad + ",1"+")";

SqlConnection myConnection = new SqlConnection("server=localhost;Database=MOVIES;Trusted_Connection=Yes");

SqlCommand comm = new SqlCommand(Key, myConnection);

myConnection.Open();

comm.ExecuteNonQuery();

myConnection.Close();

Clear();

EndBuy();

GridView1.DataBind();

Page_Init(null, null);

}

protected void Clear()

{

Global.CaseRiad = 0;

Global.CaseMesto = 0;

Global.SeansKey = 0;

foreach (Button b in buttons)