public Group(DataRow row, Flight parent) : this() { Parent = parent; Extract(row); GroupMembers.Generate(this); }
public void AddFlight(Flight parent) { if (parent != null) { Parent = parent; Parent.Groups.Add(this); } }
public bool Insert(Flight parent) { Created = DateTime.Now; Updated = DateTime.Now; AddFlight(parent); List<SqlParameter> parameters = new List<SqlParameter>(); AddParameters(parameters); SqlParameter returnType = AddParameter(Property.RetVal, SqlDbType.Int); returnType.Direction = ParameterDirection.ReturnValue; parameters.Add(returnType); bool success = new UtilityFunctions().Insert(Transactions.InsertGroup, parameters); GroupId = (int)returnType.Value; return success; }
private void AddFlight() { Flight flight = new Flight(); if (ErrorsInFlightData(flight)) return; flight.Name = flightName.Text; flight.Capacity = int.Parse(flightCapacity.Text); flight.IsLocked = flightLocked.Checked; flight.FuelConsumed = decimal.Parse(flightFuel.Text); flight.Parent = Planes.Get(int.Parse(flightPlane.SelectedValue)); if (flight.Insert()) { Response.Redirect(Request.RawUrl); return; } }
private void GetDepartureTimeErrors(Flight flight, List<string> errors) { if (string.IsNullOrEmpty(flightTime.Text) || !flightTime.Text.Contains(':')) { errors.Add("Flight time is empty."); } else { string[] timeParts = flightTime.Text.Split(':'); Int32[] convertedTime = new Int32[2]; if (timeParts.Length != 2) { errors.Add("Flight time is not in the format = HH:MM."); } else if (Int32.TryParse(timeParts[0], out convertedTime[0]) && Int32.TryParse(timeParts[1], out convertedTime[1])) { // Time in correct format. flight.DepartureTime = DateTime.Now.Date.AddHours(convertedTime[0]). AddMinutes(convertedTime[1]); } else { errors.Add("Flight time is not in the format: (hh:mm)."); } } }
private bool ErrorsInFlightData(Flight flight) { List<string> errors = new List<string>(); if (string.IsNullOrEmpty(flightPlane.SelectedValue)) { errors.Add("Plane name is empty, try creating a new plane <a href='#createPlane'>here</a>."); } if (string.IsNullOrEmpty(flightName.Text)) { errors.Add("Flight name is empty, try creating a new plane <a href='#createPlane'>here</a>."); } // Work out if the time is set in a correct format. GetDepartureTimeErrors(flight, errors); // Fuel remaining. decimal fuelRemaining = 0; if (string.IsNullOrEmpty(flightFuel.Text) && !decimal.TryParse(flightFuel.Text, out fuelRemaining)) { errors.Add("Plane fuel is empty."); } else { flight.FuelConsumed = fuelRemaining; } int capacity = 0; if (string.IsNullOrEmpty(flightCapacity.Text) && !int.TryParse(flightCapacity.Text, out capacity)) { errors.Add("Plane capacity is empty."); } else { flight.Capacity = capacity; } foreach (string value in errors) { flightError.InnerHtml += "<p> Error: " + value + " </p>"; } return errors.Count > 0; }
public static void GenerateFlights(int numberOfFlights) { PlaneCollection planes = Timetable.Planes; List<Details> users = PlaneCollection.Users.ToList(); if(planes.Count == 0) { GeneratePlanes(7); } for (int counter = 0; counter < numberOfFlights; counter++) { Flight flight = new Flight(); flight.Parent = planes[counter % planes.Count]; flight.Name = flight.Parent.Name + ": Lift " + (flight.Parent.Flights.Count + 1); flight.Capacity = flight.Parent.MaxCapacity; flight.FuelConsumed = flight.Parent.FuelAfterPrevFlight; if (flight.Parent.Flights.Count != 0 && flight.Parent.Flights.Last().DepartureTime > DateTime.Now) { // If there are flights not departed yet queue next plane 20 mins after. flight.DepartureTime = flight.Parent.Flights.Last().DepartureTime.AddMinutes(20); } else { flight.DepartureTime = DateTime.Now.AddMinutes(20); } // Insert without db get. flight.Insert(); List<Details> listOfUsers = new List<Details>(users); Random rndUser = new Random(); while (flight.Spaces > 14) { Group group = new Group(); group.GroupType = Group.GroupTypeCollection[new Random().Next(Group.GroupTypeCollection.Count)]; group.StickToFlight = false; group.Created = DateTime.Now; group.Updated = DateTime.Now; group.Insert(flight); for (int userCounter = 0; userCounter < new Random().Next(1, 5); userCounter++) { GroupMember member = new GroupMember( listOfUsers[rndUser.Next(listOfUsers.Count)]); member.KitHire = new Random().Next(2) % 2 == 0; member.Payer = member.UserDetails; group.AddMember(member); listOfUsers.Remove(member.UserDetails); } } } }