private void button1_Click(object sender, EventArgs e)
 {
     if (Convert.ToInt32(Seattxt.Text) <= 200)
     {
         if (AvailableSeat() == true)
         {
             Reservation reservation = new Reservation();
             reservation.CustomerID      = Convert.ToInt32(CustomerIDtxt.Text);
             reservation.DateOfDeparture = dateTime.Value;
             reservation.RouteID         = Convert.ToInt32(Routetxt.Text);
             reservation.SeatNr          = Convert.ToInt32(Seattxt.Text);
             db.Reservations.Add(reservation);
             db.SaveChanges();
             MessageBox.Show("Ticket Booked Successfully");
         }
         else
         {
             MessageBox.Show("Seat is already reserved");
         }
     }
     else
     {
         MessageBox.Show("Seat number invalid");
     }
 }
Exemplo n.º 2
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            model.First_Name = textFName.Text.Trim();
            model.Last_Name  = textLName.Text.Trim();
            model.Birthday   = textBirthday.Text.Trim();
            model.City       = textCity.Text.Trim();
            model.Phone      = textPhone.Text.Trim();
            model.E_mail     = textMail.Text.Trim();

            using (RailwayDbEntities db = new RailwayDbEntities())
            {
                if (model.CustomerID == 0)
                {
                    db.Customers.Add(model);
                }
                else
                {
                    db.Entry(model).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            Clear();
            PopulateDataGrid();
            MessageBox.Show("Submitted Succesfully !");
        }
Exemplo n.º 3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete ?", "Delete Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (RailwayDbEntities db = new RailwayDbEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Customers.Attach(model);
             }
             db.Customers.Remove(model);
             db.SaveChanges();
             PopulateDataGrid();
             Clear();
             MessageBox.Show("Deleted Successfully !");
         }
     }
 }
Exemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            // common.Logger.OpenLogger();
            //common.Logger.LogThisLine(MethodBase.GetCurrentMethod().Name);
            Route rd = new Route();

            rd.TrainCode     = CodeText.Text;
            rd.DepartureCity = departureText.Text;
            rd.ArrivalCity   = arrivalText.Text;
            rd.DepartureTime = DepartTimeText.Text;
            rd.ArrivalTime   = ArrivTimeText.Text;
            rd.Class         = ClassText.Text;
            rd.Seat          = Convert.ToInt32(SeatText.Text);
            rd.Price         = Convert.ToDecimal(PriceText.Text);
            db.Routes.Add(rd);
            db.SaveChanges();
            MessageBox.Show("New route added successfully !");
            Clear();
            // common.Logger.CloseLogger();
        }