コード例 #1
0
        private void updateTicketToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Ticket  ticket = db.Tickets.Find(id);
                Waybill route1 = db.Waybills.Find(id);

                TicketForm tkForm = new TicketForm();

                tkForm.From.Text              = route1.DispatchCity;
                tkForm.To.Text                = route1.ArrivalCity;
                tkForm.CountryTo.Text         = route1.DispatchCity;
                tkForm.CountyFrom.Text        = route1.ArrivalCity;
                tkForm.comboBox1.SelectedItem = ticket.Price;
                tkForm.numericUpDown1.Value   = ticket.NumberOfPassenger;
                tkForm.numericUpDown2.Value   = ticket.Row;
                tkForm.numericUpDown2.Value   = ticket.Seat;

                DialogResult result = tkForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                ticket.Price             = (int)tkForm.comboBox1.SelectedItem;
                ticket.NumberOfPassenger = (int)tkForm.numericUpDown1.Value;
                ticket.Row          = (int)tkForm.numericUpDown2.Value;
                ticket.Seat         = (int)tkForm.numericUpDown3.Value;
                route1.DispatchCity = tkForm.From.Text;
                route1.ArrivalCity  = tkForm.To.Text;
                route1.DispatchCity = tkForm.CountryTo.Text;
                route1.ArrivalCity  = tkForm.CountyFrom.Text;

                db.SaveChanges();
                dataGridView1.Refresh(); // обновляем грид
                MessageBox.Show("Объект обновлен");
            }
        }
コード例 #2
0
        private void addTicketToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TicketForm   tkForm = new TicketForm();
            DialogResult result = tkForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }
            else if (result == DialogResult.OK)
            {
                Waybill route = new Waybill();
                route.DispatchCity = tkForm.From.Text;
                route.ArrivalCity  = tkForm.To.Text;
                route.Departure    = tkForm.dateTimePicker1.Value;
                route.Arrival      = tkForm.dateTimePicker2.Value;

                db.Waybills.Add(route);
                db.SaveChanges();

                Airplane airplane = new Airplane();
                airplane.Airplane_class = tkForm.comboBox2.SelectedItem.ToString();
                airplane.Airplane_type  = tkForm.comboBox3.SelectedItem.ToString();
                db.Airplanes.Add(airplane);


                Ticket ticket = new Ticket();

                ticket.RouteID           = route.Id;
                ticket.Route             = route;
                ticket.Price             = tkForm.comboBox1.SelectedIndex;
                ticket.NumberOfPassenger = (int)tkForm.numericUpDown1.Value;
                ticket.Row  = (int)tkForm.numericUpDown2.Value;
                ticket.Seat = (int)tkForm.numericUpDown3.Value;



                db.Tickets.Add(ticket);
                db.SaveChanges();

                MessageBox.Show("Новый объект добавлен");
                return;
            }
        }