Пример #1
0
        public static List<Part> SearchForParts(string keyword, Repair repair)
        {
            var parts =
                from part in repair.ExchangedParts
                where string.Format("{0}", part.Name).ToLower().Contains(keyword.ToLower())
                select part;

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

            foreach (var part in parts)
            {
                result.Add(part as Part);
            }

            return result;
        }
Пример #2
0
        public static Repair LoadRepairInformation(string[] lines, ref int index)
        {
            Repair repair = new Repair();
            var assembly = Assembly.GetExecutingAssembly();
            var userType = assembly.GetType("GarageManagementSystem.Repair");
            int propertiesCount = Service.PropertiesCount(repair);

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

                if (property.Name == "ExchangedParts")
                {
                    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(repair, parts, null);
                }
                else
                {
                    index++;

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

            return repair;
        }
Пример #3
0
 public void AddRepair(Repair repair)
 {
     // TODO: check if this repair not exist yet
     this.Repairs.Add(repair);
 }
Пример #4
0
        public static string SaveRepairInformation(Repair repair)
        {
            StringBuilder builder = new StringBuilder();

            var assembly = Assembly.GetExecutingAssembly();

            var repairProperties = assembly.GetType("GarageManagementSystem.Repair").GetProperties();

            foreach (var property in repairProperties)
            {
                if (property.Name == "ExchangedParts")
                {
                    dynamic partList = property.GetValue(repair, null);
                    builder.AppendLine("ExchangedParts");
                    builder.AppendLine(partList.Count.ToString());
                    foreach (var part in partList)
                    {
                        builder.Append(Part.SavePartInformation(part));
                    }
                }
                else
                {
                    builder.AppendLine(property.Name);
                    try
                    {
                        builder.AppendLine(property.GetValue(repair, null).ToString());
                    }
                    catch (NullReferenceException)
                    {
                        builder.AppendLine("-");
                    }
                }
            }

            return builder.ToString();
        }