示例#1
0
 /// <summary>
 /// Creates and places an order with the specified <paramref name="customer"/> and
 /// <paramref name="model"/>. Optionally, there can be a priority, but by default it is <see cref="OrderPriority.Normal"/>.
 /// </summary>
 /// <param name="customer">The customer of the order.</param>
 /// <param name="model"></param>
 /// <param name="op"></param>
 public void OrderModel(Customer customer, CarModel model, OrderPriority op = OrderPriority.Normal)
 {
     this.PlaceOrder(new Order(customer, model, op));
 }
示例#2
0
        /// <summary>
        /// Generates a random car model from a predefined list.
        /// </summary>
        /// <returns>A <see cref="CarModel"/> object.</returns>
        private CarModel GetRandomCarModel()
        {
            List <CarModel> randomModels = new List <CarModel>();

            // 1
            CarModel m = new CarModel();
            Tires    t = new Tires(Inches.Sixteen);

            m.AddPart(new Cabrio());
            m.AddPart(new AirSuspension());
            m.AddPart(new DieselEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Average));
            m.AddPart(new ManualTransmission());
            m.AddPart(new LeatherInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            m.AddPart(new AudioSystem());
            m.AddPart(new GPS());
            randomModels.Add(m);

            // 2
            m = new CarModel();
            t = new Tires(Inches.Eighteen);
            m.AddPart(new Jeep());
            m.Chassis.SetChassisColor(ChassisColors.Red);
            m.AddPart(new HydraulicSuspension());
            m.AddPart(new DieselEngine());
            m.AddPart(new Accumulator(AccumulatorSize.MegaPower));
            m.AddPart(new ManualTransmission());
            m.AddPart(new LeatherInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            m.AddPart(new _4x4());
            m.AddPart(new GPS());
            randomModels.Add(m);

            // 3
            m = new CarModel();
            t = new Tires(Inches.Sixteen);
            m.AddPart(new SportCar());
            m.Chassis.SetChassisColor(ChassisColors.Blue);
            m.AddPart(new AirSuspension());
            m.AddPart(new DieselEngine());
            m.AddPart(new Accumulator(AccumulatorSize.MegaPower));
            m.AddPart(new ManualTransmission());
            m.AddPart(new LeatherInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            m.AddPart(new _4x4());
            m.AddPart(new AudioSystem());
            m.AddPart(new GPS());
            randomModels.Add(m);

            // 4
            m = new CarModel();
            t = new Tires(Inches.Fourteen);
            m.AddPart(new Sedan());
            m.Chassis.SetChassisColor(ChassisColors.Grey);
            m.AddPart(new HydraulicSuspension());
            m.AddPart(new PetrolEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Small));
            m.AddPart(new AutomaticTransmission());
            m.AddPart(new TextileInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            randomModels.Add(m);

            // 5
            m = new CarModel();
            t = new Tires(Inches.Sixteen);
            m.AddPart(new Sedan());
            m.Chassis.SetChassisColor(ChassisColors.Red);
            m.AddPart(new AirSuspension());
            m.AddPart(new ElectricEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Average));
            m.AddPart(new AutomaticTransmission());
            m.AddPart(new LeatherInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            m.AddPart(new _4x4());
            m.AddPart(new AudioSystem());
            m.AddPart(new GPS());
            m.AddPart(new Parktronic());
            m.AddPart(new AC());
            m.AddPart(new ButtonStarter());
            randomModels.Add(m);

            // 6
            m = new CarModel();
            t = new Tires(Inches.Fourteen);
            m.AddPart(new SportCar());
            m.Chassis.SetChassisColor(ChassisColors.Blue);
            m.AddPart(new HydraulicSuspension());
            m.AddPart(new DieselEngine());
            m.AddPart(new Accumulator(AccumulatorSize.MegaPower));
            m.AddPart(new ManualTransmission());
            m.AddPart(new LeatherInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            m.AddPart(new _4x4());
            m.AddPart(new AudioSystem());
            m.AddPart(new GPS());
            m.AddPart(new AC());
            randomModels.Add(m);

            // 7
            m = new CarModel();
            t = new Tires(Inches.Eighteen);
            m.AddPart(new Jeep());
            m.Chassis.SetChassisColor(ChassisColors.Grey);
            m.AddPart(new GasSuspension());
            m.AddPart(new PetrolEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Average));
            m.AddPart(new ManualTransmission());
            m.AddPart(new TextileInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            m.AddPart(new _4x4());
            m.AddPart(new GPS());
            m.AddPart(new CruiseControl());
            randomModels.Add(m);

            // 8
            m = new CarModel();
            t = new Tires(Inches.Fourteen);
            m.AddPart(new Cabrio());
            m.Chassis.SetChassisColor(ChassisColors.Grey);
            m.AddPart(new HydraulicSuspension());
            m.AddPart(new DieselEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Small));
            m.AddPart(new ManualTransmission());
            m.AddPart(new TextileInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            randomModels.Add(m);

            // 9
            m = new CarModel();
            t = new Tires(Inches.Fourteen);
            m.AddPart(new Minivan());
            m.Chassis.SetChassisColor(ChassisColors.Grey);
            m.AddPart(new HydraulicSuspension());
            m.AddPart(new PetrolEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Small));
            m.AddPart(new AutomaticTransmission());
            m.AddPart(new TextileInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            randomModels.Add(m);

            // 9
            m = new CarModel();
            t = new Tires(Inches.Sixteen);
            m.AddPart(new Minivan());
            m.Chassis.SetChassisColor(ChassisColors.Blue);
            m.AddPart(new GasSuspension());
            m.AddPart(new DieselEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Average));
            m.AddPart(new ManualTransmission());
            m.AddPart(new LeatherInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            randomModels.Add(m);

            // 10
            m = new CarModel();
            t = new Tires(Inches.Fourteen);
            m.AddPart(new Minivan());
            m.Chassis.SetChassisColor(ChassisColors.Blue);
            m.AddPart(new AirSuspension());
            m.AddPart(new ElectricEngine());
            m.AddPart(new Accumulator(AccumulatorSize.Average));
            m.AddPart(new AutomaticTransmission());
            m.AddPart(new LeatherInterior());
            m.AddPart(t);
            m.AddPart(new Rims(t));
            randomModels.Add(m);

            // Retrieve a model from the list based on a random integer.
            int position = rand.Next(randomModels.Count - 1);

            return(randomModels.ElementAt(position));
        }
示例#3
0
 /// <summary>
 /// Load a model's reference into <see cref="CurrentModel"/>.
 /// </summary>
 /// <param name="model">The reference to the model.</param>
 public void LoadModel(CarModel model)
 {
     this.CurrentModel = model;
 }
        /// <summary>
        /// Synchronizes the already processed orders list with the information in the database.
        /// </summary>
        private void SyncProcessedOrders()
        {
            this.ProcessedOrders = new List <Order>();

            // Open connection to database
            using (MySqlConnection con = ApplicationSettings.GetConnection())
            {
                con.Open();

                // Get all orders, customers and models from DB
                MySqlCommand cmd = new MySqlCommand("SELECT * FROM `processed_order` AS O JOIN `car_model` " +
                                                    "AS M on (O.model_id=M.model_id) JOIN `customer` AS C on (O.customer_id = C.customer_id)", con);
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int        order_id       = Convert.ToInt32(reader[0]);
                    int        model_id       = Convert.ToInt32(reader[1]);
                    int        customer_id    = Convert.ToInt32(reader[2]);
                    DateTime   issued_date    = Convert.ToDateTime(reader[3]);
                    DateTime   processed_date = Convert.ToDateTime(reader[5]);
                    DateTime   expected_date  = Convert.ToDateTime(reader[4]);
                    int        priority       = Convert.ToInt32(reader[6]);
                    List <int> partIds        = new List <int>();
                    partIds.Add(Convert.ToInt32(reader[8]));
                    partIds.Add(Convert.ToInt32(reader[9]));
                    partIds.Add(Convert.ToInt32(reader[10]));
                    partIds.Add(Convert.ToInt32(reader[11]));
                    partIds.Add(Convert.ToInt32(reader[12]));
                    partIds.Add(Convert.ToInt32(reader[13]));
                    partIds.Add(Convert.ToInt32(reader[14]));
                    partIds.Add(Convert.ToInt32(reader[15]));
                    string extras = reader[16].ToString();
                    // TODO name reader[17]
                    string fname = reader[19].ToString();
                    string lname = reader[20].ToString();
                    string email = reader[21].ToString();
                    string phone = reader[22].ToString();

                    foreach (string extra in extras.Split(null))
                    {
                        if (!(extra == ""))
                        {
                            partIds.Add(Convert.ToInt32(extra));
                        }
                    }

                    // Create model
                    CarModel model = new CarModel();
                    foreach (int id in partIds)
                    {
                        model.AddPart(ApplicationSettings.GetPartById(id));
                    }

                    model.ID = model_id;

                    // Create customer
                    Customer cust = new Customer(fname, lname, email, phone);
                    cust.ID = customer_id;

                    // Create order
                    Order o = new Order(cust, model, RecreateOrderPriorityFromDB(priority));
                    o.ID = order_id;
                    o.SetExpectedDate(expected_date);
                    o.SetTimeOfCreation(issued_date);
                    o.ProcessOrder(processed_date);

                    this.ProcessedOrders.Add(o);
                }

                // Close connection
                con.Close();
            }
        }