コード例 #1
0
 public void AddTraveller(Travel t)
 {
     using (SqlCommand insertCommand = new SqlCommand(
                "INSERT INTO Travel2 (Destination, Name , PassportNO , Departure , ReturnDate , MethodOfTravel )  VALUES" + "(@Destination, @TravellerName , @TravellerPassport , @DepartureDate , @ReturnDate , @MethodOfTravel ) ", conn))
     {
         insertCommand.Parameters.AddWithValue("@Destination", t.Destination);
         insertCommand.Parameters.AddWithValue("@TravellerName", t.TravellerName);
         insertCommand.Parameters.AddWithValue("@TravellerPassport", t.TravellerPassport);
         insertCommand.Parameters.AddWithValue("@DepartureDate", t.DepartureDate.ToString("MM-dd-yyyy"));
         insertCommand.Parameters.AddWithValue("@ReturnDate", t.ReturnDate.ToString("MM-dd-yyyy"));
         insertCommand.Parameters.AddWithValue("@MethodOfTravel", t.MethodOfTravel.ToString());
         insertCommand.ExecuteNonQuery();
     }
 }
コード例 #2
0
        private void btnAddTrip_Click(object sender, RoutedEventArgs e)
        {
            //Travel currTravel = new Travel();

            string   destination = tbDestination.Text;
            string   name        = tbName.Text;
            string   passportNo  = tbPassportNo.Text;
            DateTime departure   = DateTime.Parse(dpDep.Text);
            DateTime returnDate  = DateTime.Parse(dpDep.Text);

            if (returnDate.Date < departure.Date)
            {
                MessageBox.Show("Invalid Return Date. Needs to be after Departure");
                return;
            }
            string methodOfTravelStr = cbxMethodTravel.Text;

            Travel.TravelEnum methodOfTravel;
            if (!Enum.TryParse <Travel.TravelEnum>(methodOfTravelStr, out methodOfTravel))
            {
                throw new InvalidCastException("Enum value invalid: " + methodOfTravelStr);
            }

            try
            {
                if (currTravel == null)
                {
                    Travel t = new Travel(destination, name, passportNo, departure, returnDate, methodOfTravel);
                    Globals.db.AddTraveller(t);
                }
                else
                {
                    currTravel.Destination       = destination;
                    currTravel.TravellerName     = name;
                    currTravel.TravellerPassport = passportNo;
                    currTravel.DepartureDate     = departure;
                    currTravel.ReturnDate        = returnDate;
                    currTravel.MethodOfTravel    = methodOfTravel;
                }
                this.DialogResult = true;
            }
            catch (SqlException ex)
            {
                MessageBox.Show(this, ex.Message, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #3
0
        private void lvTravel_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Travel currPerson = lvTravel.SelectedItem as Travel;

            if (currPerson == null)
            {
                return;
            }

            AddTravelDialog dlg = new AddTravelDialog(this);

            if (dlg.ShowDialog() == true)
            {
                RefreshList();
                MessageBox.Show("Seccess!");
            }
        }