예제 #1
0
        public List <Option> GetLevelOptions(EOptionsLevel level)
        {
            List <Option> options = new List <Option>();

            using (SqlConnection connection = DatabaseHelper.Instance.GetConnection())
            {
                string     sql     = "select id, [option], price from Options where level = '" + level.ToString() + "'";
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    int    optionId = (int)reader["id"];
                    string option   = (string)reader["option"];
                    float  price    = float.Parse(reader["price"].ToString());

                    Option optionObj = new Option(optionId, option, price, level);

                    options.Add(optionObj);
                }
                reader.Close();
            }

            return(options);
        }
예제 #2
0
        public List <Option> GetAllOptions()
        {
            List <Option> options = new List <Option>();

            using (SqlConnection connection = DatabaseHelper.Instance.GetConnection())
            {
                string     sql     = "select * from Options";
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    int    optionId = (int)reader["id"];
                    string option   = (string)reader["option"];
                    float  price    = float.Parse(reader["price"].ToString());
                    string level    = (string)reader["level"];

                    EOptionsLevel eLevel = EOptionsLevel.Basic;

                    switch (level)
                    {
                    case "Entry":
                        eLevel = EOptionsLevel.Entry;
                        break;

                    case "Premium":
                        eLevel = EOptionsLevel.Premium;
                        break;

                    case "Luxury":
                        eLevel = EOptionsLevel.Luxury;
                        break;
                    }

                    Option optionObj = new Option(optionId, option, price, eLevel);

                    options.Add(optionObj);
                }
                reader.Close();
            }

            return(options);
        }
예제 #3
0
 public CarInventory(
     int id,
     Model model,
     Color color,
     Engine engine,
     DateTime buildDate,
     int mileage,
     float initialPrice
     )
 {
     Id           = id;
     Model        = model;
     Color        = color;
     Engine       = engine;
     BuildDate    = buildDate;
     Mileage      = mileage;
     InitialPrice = initialPrice;
     OptionsLevel = EOptionsLevel.Basic;
 }
예제 #4
0
        public float GetLevelCost(EOptionsLevel level)
        {
            float price = 0;

            using (SqlConnection connection = DatabaseHelper.Instance.GetConnection())
            {
                string     sql     = "select price from Options where level = '" + level.ToString() + "'";
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    price += float.Parse(reader["price"].ToString());
                }

                reader.Close();
            }

            return(price);
        }
예제 #5
0
        public List <CarInventory> GetAllCars()
        {
            List <CarInventory> cars = new List <CarInventory>();

            using (SqlConnection connection = DatabaseHelper.Instance.GetConnection())
            {
                connection.Open();
                string     sql     = "select * from CarsInventory";
                SqlCommand command = new SqlCommand(sql, connection);

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    int      id           = (int)reader["id"];
                    int      modelId      = (int)reader["modelId"];
                    int      colorId      = (int)reader["colorId"];
                    DateTime buildDate    = (DateTime)reader["buildDate"];
                    int      mileage      = (int)reader["mileage"];
                    float    initialPrice = float.Parse(reader["initialPrice"].ToString());
                    float    finalPrice   = float.Parse(reader["finalPrice"].ToString());
                    string   optionsLevel = (string)reader["optionsLevel"];
                    int      engineId     = (int)reader["engineId"];

                    IModelDAO modelDAO = new ModelDAO();
                    Model     model    = modelDAO.GetModel(modelId);

                    IColorDAO colorDAO = new ColorDAO();
                    Color     color    = colorDAO.GetColor(colorId);

                    IEngineDAO engineDAO = new EngineDAO();
                    Engine     engine    = engineDAO.GetEngine(engineId);

                    CarInventory car = new CarInventory(id, model, color, engine, buildDate, mileage, initialPrice);

                    EOptionsLevel eLevel = EOptionsLevel.Basic;

                    switch (optionsLevel)
                    {
                    case "basic":
                        eLevel = EOptionsLevel.Luxury;
                        break;

                    case "Entry":
                        eLevel = EOptionsLevel.Entry;
                        break;

                    case "Premium":
                        eLevel = EOptionsLevel.Premium;
                        break;

                    case "Luxury":
                        eLevel = EOptionsLevel.Luxury;
                        break;
                    }

                    IOptionDAO    optionDAO = new OptionDAO();
                    List <Option> options   = optionDAO.GetLevelOptions(eLevel);

                    car.OptionsLevel = eLevel;
                    car.Options      = options;
                    car.FinalPrice   = finalPrice;

                    cars.Add(car);
                }
                reader.Close();
            }
            return(cars);
        }