Esempio n. 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (comboBox2.SelectedIndex != -1 && numericUpDown1.Value != 0)
            {
                string query = "SELECT Event.MaxParticipants, ISNULL(SUM(TicketsSales.Amount),1) From Event Left join TicketsSales on Event.EventId = TicketsSales.EventId where Event.EventId =  '" + comboBox2.SelectedValue + "'" +
                               "group by Event.MaxParticipants";

                SqlCommand cmd = new SqlCommand(query, Program.con);
                con.Open();

                SqlDataAdapter da = new SqlDataAdapter(query, con);
                DataTable      dt = new DataTable();
                da.Fill(dt);

                query = "SELECT (MAX(IdTicketsSales)+1) From TicketsSales";
                da    = new SqlDataAdapter(query, con);
                DataTable dt1 = new DataTable();
                da.Fill(dt1);

                if (numericUpDown1.Value > 0)
                {
                    if (Convert.ToInt32(dt.Rows[0][1]) + numericUpDown1.Value <= Convert.ToInt32(dt.Rows[0][0]))
                    {
                        cmd             = new SqlCommand();
                        cmd.Connection  = con;
                        cmd.CommandText = "Insert INTO TicketsSales (IdTicketsSales, EventId,UserId,Amount)  " +
                                          " values('" + Convert.ToInt32(dt1.Rows[0][0]) + "','" + comboBox2.SelectedValue + "','" + Program.UserId + "','" + numericUpDown1.Value + "')";
                        cmd.ExecuteNonQuery();
                        con.Close();
                        MessageBox.Show("Билеты куплены");
                        TicketMatch TM = new TicketMatch();
                        TM.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Осталось " + (Convert.ToInt32(dt.Rows[0][0]) - Convert.ToInt32(dt.Rows[0][1])) + " билетов на матч");
                    }
                }
                TicketMatch asasa = new TicketMatch();
                asasa.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Введите корректное число билетов");
            }
        }
Esempio n. 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            TicketMatch tm = new TicketMatch();

            tm.ShowDialog();
        }