public static Distributor LoadDistributorInformation(string[] lines, ref int index)
        {
            Distributor distributor = new Distributor();
            var assembly = Assembly.GetExecutingAssembly();
            var userType = assembly.GetType("GarageManagementSystem.Distributor");
            int propertiesCount = Service.PropertiesCount(distributor);

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

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

                    if (lines[index] != "-")
                    {
                        index++;
                        Address address = Address.LoadAddressInformation(lines, ref index);
                        property.SetValue(distributor, address, null);
                    }
                }
                else if (property.Name == "Parts")
                {
                    List<Part> parts = new List<Part>();

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

                    for (int element = 0; element < stopPoint; element++)
                    {
                        parts.Add(Part.LoadPartInformation(lines, ref index));
                    }

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

                    if (lines[index] != "-")
                    {
                        var currentPropertyType = property.PropertyType;
                        var convertedValue = Convert.ChangeType(lines[index], currentPropertyType, null);
                        property.SetValue(distributor, convertedValue, null);
                    }
                }
            }

            return distributor;
        }
        /// <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;

            if (sn.IsDistributor)
            {
                distirbutor = Service.AutoShopInstance.Distributors[sn.DistributorIndex];
                parts = distirbutor.Parts;
            }
            else
            {
                Repair repair = Service.AutoShopInstance.GetVehicleByIndex(sn.VehicleIndex).Repairs[sn.RepairIndex];
                parts = repair.ExchangedParts;
            }
        }
Example #3
0
 public void RemoveDistributor(Distributor distributor)
 {
     this.distributors.Remove(distributor);
 }
        public static string SaveDistributorInformation(Distributor distributor)
        {
            StringBuilder builder = new StringBuilder();

            var assembly = Assembly.GetExecutingAssembly();

            var distibutorProperties = assembly.GetType("GarageManagementSystem.Distributor").GetProperties();

            foreach (var property in distibutorProperties)
            {
                if (property.Name == "Address")
                {
                    builder.AppendLine("Address");
                    if (distributor.Address == null)
                    {
                        builder.AppendLine("-");
                    }
                    else
                    {
                        builder.AppendLine("1");
                        builder.Append(Address.SaveAddressInformation(distributor.Address));
                    }
                }
                else if (property.Name == "Parts")
                {
                    dynamic partList = property.GetValue(distributor, null);
                    builder.AppendLine("Parts");
                    builder.AppendLine(partList.Count.ToString());
                    foreach (var part in partList)
                    {
                        builder.Append(Part.SavePartInformation(part));
                    }
                }
                else if (property.Name == "Tasks")
                {
                    // TODO: Implement saving tasks in Distributor class
                }
                else
                {
                    builder.AppendLine(property.Name);
                    try
                    {
                        builder.AppendLine(property.GetValue(distributor, null).ToString());
                    }
                    catch (NullReferenceException)
                    {
                        builder.AppendLine("-");
                    }
                }
            }

            return builder.ToString();
        }
Example #5
0
 public void AddDistributor(Distributor distributor)
 {
     this.distributors.Add(distributor);
 }