protected abstract void ChairPosition(ChairPosition args);
 protected override void ChairPosition(ChairPosition args)
 {
     send(args.SerializeToJson());
 }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserInfo = Session["UserInfo"] as Auth.UserInfo;

            if (UserInfo == null)
            {
                Response.Redirect("~/Login.aspx", true);
                return;
            }

            if (Session["PurchaseDate"] == null || Session["PurchaseMovieId"] == null || Session["PurchaseShowId"] == null)
            {
                Session["PurchaseDate"] = null;
                Session["PurchaseMovieId"] = null;
                Session["PurchaseShowId"] = null;
                Session["ShowDefaultError"] = true;
                Response.Redirect("~/Default.aspx", true);
                return;
            }

            try
            {
                var connString = ConfigurationManager.ConnectionStrings["CineQuilla"].ConnectionString;
                using (SqlConnection connection = new SqlConnection(connString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(null, connection))
                    {
                        command.CommandText = @"SELECT sr.rows, sr.columns, price FROM shows s LEFT JOIN (SELECT show_id, COUNT(*) as num_chairs FROM chairs WHERE date = @date GROUP BY chairs.show_id) ch ON ch.show_id = s.id LEFT JOIN showroom sr ON sr.id = s.showroom_id WHERE movie_id = @mov_id AND start_date <= @date AND end_date >= @date AND (sr.rows * sr.columns) - ISNULL(ch.num_chairs, 0) > 0 AND s.id = @show_id";
                        SqlParameter dateParam = new SqlParameter("@date", SqlDbType.Date);
                        SqlParameter movieParam = new SqlParameter("@mov_id", SqlDbType.Int);
                        SqlParameter showParam = new SqlParameter("@show_id", SqlDbType.Int);

                        dateParam.Value = Session["PurchaseDate"];
                        movieParam.Value = Session["PurchaseMovieId"];
                        showParam.Value = Session["PurchaseShowId"];

                        command.Parameters.Add(dateParam);
                        command.Parameters.Add(movieParam);
                        command.Parameters.Add(showParam);

                        var reader = command.ExecuteReader();
                        if (!reader.HasRows)
                        {
                            Session["PurchaseDate"] = null;
                            Session["PurchaseMovieId"] = null;
                            Session["PurchaseShowId"] = null;
                            Session["ShowDefaultError"] = true;
                            Response.Redirect("~/Default.aspx", true);
                            return;
                        }

                        reader.Read();

                        int rows = reader.GetInt32(0);
                        int columns = reader.GetInt32(1);
                        TicketPrice = reader.GetInt32(2);

                        reader.Close();

                        command.CommandText = "SELECT row, [column] FROM chairs WHERE show_id = @show_id AND date = @date";
                        var chairsReader = command.ExecuteReader();
                        List<ChairPosition> bought_chairs = new List<ChairPosition>();
                        while (chairsReader.Read())
                        {
                            bought_chairs.Add(new ChairPosition
                            {
                                Row = chairsReader.GetInt32(0),
                                Column = chairsReader.GetInt32(1)
                            });
                        }

                        for (int i = 0; i < rows; ++i)
                        {
                            var tr = new TableRow();
                            for (int j = 0; j < columns; ++j)
                            {
                                var td = new TableCell();
                                var chair = new ChairPosition
                                {
                                    Row = i,
                                    Column = j
                                };

                                CheckBox checkbox = new CheckBox();
                                checkbox.ID = i + "," + j;
                                if (bought_chairs.Contains(chair))
                                {
                                    checkbox.Checked = true;
                                    checkbox.Enabled = false;
                                }
                                else
                                    checkbox.Checked = false;

                                checkbox.CausesValidation = false;
                                checkbox.CheckedChanged += Checkbox_CheckedChanged;

                                td.Controls.Add(checkbox);
                                tr.Cells.Add(td);

                            }
                            ChairsTable.Rows.Add(tr);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                ErrorLabel.Visible = true;
                return;
            }
        }
Esempio n. 4
0
 protected override void ChairPosition(ChairPosition args)
 {
     state.chair_position_estimated = args.NewPosition;
 }