Exemple #1
0
        public static List<Repair> SearchForRepairs(string keyword, Vehicle vehicle)
        {
            var repairs =
                from repair in vehicle.Repairs
                where string.Format("{0} {1}", repair.Caption, repair.Guarantee).ToLower().Contains(keyword.ToLower())
                select repair;

            List<Repair> result = new List<Repair>();

            foreach (var repair in repairs)
            {
                result.Add(repair as Repair);
            }

            return result;
        }
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="navigationParameter">The parameter value passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
 /// </param>
 /// <param name="pageState">A dictionary of state preserved by this page during an earlier
 /// session.  This will be null the first time a page is visited.</param>
 protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
 {
     sn = (StructNavigator)navigationParameter;
     vehicle = Service.AutoShopInstance.GetVehicleByIndex(sn.VehicleIndex);
     repairs = vehicle.Repairs;
 }
        public bool Equals(Vehicle value)
        {
            if (ReferenceEquals(null, value))
            {
                return false;
            }

            if (ReferenceEquals(this, value))
            {
                return true;
            }

            return Equals(this.Manufacturer, value.Manufacturer) &&
                   Equals(this.Model, value.Model) &&
                   this.Year.Equals(value.Year) &&
                   Equals(this.RegistrationNumber, value.RegistrationNumber) &&
                   Equals(this.Owner, value.Owner);
        }
        public static string SaveVehicleInformation(Vehicle vehicle)
        {
            var assembly = Assembly.GetExecutingAssembly();

            StringBuilder builder = new StringBuilder();

            var userTypeProperties = assembly.GetType("GarageManagementSystem.Vehicle").GetProperties();

            foreach (var property in userTypeProperties)
            {
                if (property.Name == "Owner")
                {
                    builder.AppendLine("Owner");
                    if (vehicle.Owner == null)
                    {
                        builder.AppendLine("-");
                    }
                    else
                    {
                        builder.AppendLine("1");
                        builder.Append(Person.SaveOwnerInformation(vehicle.Owner));
                    }
                }
                else if (property.Name == "Repairs")
                {
                    dynamic repairsList = property.GetValue(vehicle, null);
                    builder.AppendLine("Repairs");
                    builder.AppendLine(repairsList.Count.ToString());

                    foreach (var repair in repairsList)
                    {
                        builder.Append(Repair.SaveRepairInformation(repair));
                    }
                }
                else if (property.Name == "Tasks")
                {
                    // TODO: Implement saving tasks in Vehicle class
                }
                else
                {
                    builder.AppendLine(property.Name);

                    try
                    {
                        builder.AppendLine(property.GetValue(vehicle, null).ToString());
                    }
                    catch (NullReferenceException)
                    {
                        builder.AppendLine("-");
                    }
                }
            }

            return builder.ToString();
        }
        public static Vehicle LoadVehicleInformation(string[] lines, ref int index)
        {
            Vehicle vehicle = new Vehicle();
            var assembly = Assembly.GetExecutingAssembly();
            var userType = assembly.GetType("GarageManagementSystem.Vehicle");
            int propertiesCount = Service.PropertiesCount(vehicle); // Get the number of properties

            for (int i = 0; i < propertiesCount; i++, index++)
            {
                var property = userType.GetProperty(lines[index]);

                if (property.Name == "Owner")
                {
                     index++;

                     if (lines[index] != "-")
                     {
                         index++;
                         Owner address = Person.LoadOwnerInformation(lines, ref index);
                         property.SetValue(vehicle, address, null);
                     }
                }
                else if (property.Name == "Status")
                {
                    index++;

                    if (lines[index] != "-")
                    {
                        var currentPropertyType = property.PropertyType;
                        Status status = (Status)Enum.Parse(typeof(Status), lines[index], false);
                        property.SetValue(vehicle, status, null);
                    }
                }
                else if (property.Name == "FuelType")
                {
                    index++;

                    if (lines[index] != "-")
                    {
                        var currentPropertyType = property.PropertyType;
                        FuelType fuilType = (FuelType)Enum.Parse(typeof(FuelType), lines[index], false);
                        property.SetValue(vehicle, fuilType, null);
                    }
                }
                else if (property.Name == "Gearbox")
                {
                    index++;

                    if (lines[index] != "-")
                    {
                        var currentPropertyType = property.PropertyType;
                        Gearbox gearBox = (Gearbox)Enum.Parse(typeof(Gearbox), lines[index], false);
                        property.SetValue(vehicle, gearBox, null);
                    }
                }
                else if (property.Name == "Repairs")
                {
                    List<Repair> repair = new List<Repair>();

                    int stopPoint = int.Parse(lines[index + 1]);
                    index += 2;

                    for (int element = 0; element < stopPoint; element++)
                    {
                        repair.Add(Repair.LoadRepairInformation(lines, ref index));
                    }

                    index--;
                    property.SetValue(vehicle, repair, null);
                }
                else if (property.Name == "Tasks")
                {
                    // TODO: Implement loading tasks in Vehicle class
                }
                else
                {
                    index++;

                    if (lines[index] != "-")
                    {
                        Type t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
                        object safeValue = (lines[index] == null) ? null : Convert.ChangeType(lines[index], t, null);
                        property.SetValue(vehicle, safeValue, null);
                    }
                }
            }

            return vehicle;
        }
 public void RemoveVehicle(Vehicle vehicle)
 {
     this.vehicles.Remove(vehicle);
 }
 public void AddVehicle(Vehicle vehicle)
 {
     this.vehicles.Add(vehicle);
 }
 private async void SendEmail(Vehicle vehicle)
 {
     // TODO: Add option to add owner for the car (name and email)
     string sendTo = "*****@*****.**"; // TODO: Get the email from the owner after implement it
     string subject = "Car is fully repaired";
     string body = string.Format("Dear Mr./Mrs., {0}%0d%0AWe inform you that your car {1} is completely repaired and you can take it whenever you want.%0d%0ABest wishes,%0d%0AService \"The CARS\"", "Pesho", vehicle.Manufacturer + " " + vehicle.Model + " " + vehicle.RegistrationNumber);
     var mailto = new Uri(string.Format("mailto:?to={0}&subject={1}&body={2}.", sendTo, subject, body));
     await Windows.System.Launcher.LaunchUriAsync(mailto);
 }
        private void AddCar_Click(object sender, RoutedEventArgs e)
        {
            FuelType fuelType = (FuelType)Enum.Parse(typeof(FuelType), FuelTypeComboBox.SelectedValue.ToString(), false);
            Gearbox gearbox = (Gearbox)Enum.Parse(typeof(Gearbox), GearBoxComboBox.SelectedValue.ToString(), false);
            Status status = (Status)Enum.Parse(typeof(Status), StatusComboBox.SelectedValue.ToString(), false);
            Vehicle newVehicle = new Vehicle(ManufacuturerTextBox.Text, ModelTextBox.Text, int.Parse(YearTextBox.Text), RegNumberTextBox.Text, fuelType, gearbox, status);

            Service.AutoShopInstance.AddVehicle(newVehicle);
            if (status.ToString() == "Completed")
            {
                SendEmail(newVehicle);
            }
            App.SaveServiceInformation();
            this.Frame.Navigate(typeof(CarsPage));
        }