Exemple #1
0
        /// <summary>
        /// Бронирование билетов
        /// </summary>
        private void BookingPlace()
        {
            if (this.lvResult.SelectedIndices.Count != 1) { return; }

            try
            {
                //Сеанс

                DataRow session = this.lvResult.SelectedItems[0].Tag as DataRow;
                if (session == null) { return; }

                //Проданные билеты на сеанс

                DataTable sessionTickets = new DataTable("Places");
                DbCommand cmd = this.dbConnection.CreateCommand();
                int sessionId = (int)session["session"];
                cmd.CommandText = String.Format("SELECT * FROM Tickets WHERE session_id = {0}", sessionId);
                this.dbAdapter.SelectCommand = cmd;
                this.dbAdapter.Fill(sessionTickets);

                List<Point> soldTickets = new List<Point>();
                foreach (DataRow item in sessionTickets.Rows)
                {
                    soldTickets.Add(new Point((int)item["row"], (int)item["place"]));
                }

                //Отображение формы заказа билетов

                frmBooking frmBooking = new frmBooking(session, soldTickets);
                if (frmBooking.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //Обновление таблицы

                    foreach (Point item in frmBooking.ReservedTickets)
                    {
                        DataRow ticket = sessionTickets.NewRow();
                        ticket["session_id"] = sessionId;
                        ticket["row"] = item.X;
                        ticket["place"] = item.Y;
                        sessionTickets.Rows.Add(ticket);
                    }

                    //Создание команды и обновление

                    DbCommand insertCmd = this.dbConnection.CreateCommand();
                    insertCmd.CommandText = String.Format("INSERT INTO Tickets (session_id, row, place) VALUES({0}, @row, @place)", sessionId);
                    DbParameter rowParam = insertCmd.CreateParameter();
                    rowParam.ParameterName = "@row";
                    rowParam.DbType = DbType.Int32;
                    rowParam.SourceColumn = "row";
                    insertCmd.Parameters.Add(rowParam);

                    DbParameter placeParam = insertCmd.CreateParameter();
                    placeParam.ParameterName = "@place";
                    placeParam.DbType = DbType.Int32;
                    placeParam.SourceColumn = "place";
                    insertCmd.Parameters.Add(placeParam);
                    this.dbAdapter.InsertCommand = insertCmd;
                    this.dbAdapter.Update(sessionTickets);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + "\n" + e.StackTrace, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        /// <summary>
        /// Бронирование билетов
        /// </summary>
        private void BookingPlace()
        {
            if (this.lvResult.SelectedIndices.Count != 1)
            {
                return;
            }

            try
            {
                //Сеанс

                DataRow session = this.lvResult.SelectedItems[0].Tag as DataRow;
                if (session == null)
                {
                    return;
                }

                //Проданные билеты на сеанс

                DataTable sessionTickets = new DataTable("Places");
                DbCommand cmd            = this.dbConnection.CreateCommand();
                int       sessionId      = (int)session["session"];
                cmd.CommandText = String.Format("SELECT * FROM Tickets WHERE session_id = {0}", sessionId);
                this.dbAdapter.SelectCommand = cmd;
                this.dbAdapter.Fill(sessionTickets);

                List <Point> soldTickets = new List <Point>();
                foreach (DataRow item in sessionTickets.Rows)
                {
                    soldTickets.Add(new Point((int)item["row"], (int)item["place"]));
                }

                //Отображение формы заказа билетов

                frmBooking frmBooking = new frmBooking(session, soldTickets);
                if (frmBooking.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //Обновление таблицы

                    foreach (Point item in frmBooking.ReservedTickets)
                    {
                        DataRow ticket = sessionTickets.NewRow();
                        ticket["session_id"] = sessionId;
                        ticket["row"]        = item.X;
                        ticket["place"]      = item.Y;
                        sessionTickets.Rows.Add(ticket);
                    }

                    //Создание команды и обновление

                    DbCommand insertCmd = this.dbConnection.CreateCommand();
                    insertCmd.CommandText = String.Format("INSERT INTO Tickets (session_id, row, place) VALUES({0}, @row, @place)", sessionId);
                    DbParameter rowParam = insertCmd.CreateParameter();
                    rowParam.ParameterName = "@row";
                    rowParam.DbType        = DbType.Int32;
                    rowParam.SourceColumn  = "row";
                    insertCmd.Parameters.Add(rowParam);

                    DbParameter placeParam = insertCmd.CreateParameter();
                    placeParam.ParameterName = "@place";
                    placeParam.DbType        = DbType.Int32;
                    placeParam.SourceColumn  = "place";
                    insertCmd.Parameters.Add(placeParam);
                    this.dbAdapter.InsertCommand = insertCmd;
                    this.dbAdapter.Update(sessionTickets);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + "\n" + e.StackTrace, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }