Esempio n. 1
0
 public OrderPage(AvailableBicycle bicycle, BoveloUser user, Client client)
 {
     this.bicycle = bicycle;
     this.user    = user;
     this.client  = client;
     InitializeComponent();
 }
Esempio n. 2
0
        public List <AvailableBicycle> SelectAvailableBikes()
        {
            string bikeQuery          = "SELECT * FROM BikeModel";
            string colorQuery         = "SELECT * FROM Color";
            string sizeQuery          = "SELECT * FROM Size";
            string bikeVariationQuery = "SELECT * FROM BikeModel_variations";

            DataTable bikeDataTable;
            DataTable colorDataTable;
            DataTable sizeDataTable;
            DataTable bikeVariationDataTable;

            //Create a list to store the result
            List <AvailableBicycle> bikeList  = new List <AvailableBicycle>();
            List <BicycleColor>     colorList = new List <BicycleColor>();
            List <BicycleSize>      sizeList  = new List <BicycleSize>();

            //Open connection
            if (this.OpenConnection() == true)
            {
                bikeDataTable          = CreateDataTable(bikeQuery);
                colorDataTable         = CreateDataTable(colorQuery);
                sizeDataTable          = CreateDataTable(sizeQuery);
                bikeVariationDataTable = CreateDataTable(bikeVariationQuery);
                this.CloseConnection();
                for (int i = 0; i < colorDataTable.Rows.Count; i++)
                {
                    int          id        = (int)colorDataTable.Rows[i]["id"];
                    string       color     = (string)colorDataTable.Rows[i]["color"];
                    BicycleColor bikeColor = new BicycleColor(id, color);
                    colorList.Add(bikeColor);
                }
                for (int i = 0; i < sizeDataTable.Rows.Count; i++)
                {
                    int         id       = (int)sizeDataTable.Rows[i]["id"];
                    string      size     = (string)sizeDataTable.Rows[i]["size"];
                    BicycleSize bikeSize = new BicycleSize(id, size);
                    sizeList.Add(bikeSize);
                }
                for (int i = 0; i < bikeDataTable.Rows.Count; i++)
                {
                    int              id               = (int)bikeDataTable.Rows[i]["id"];
                    string           name             = (string)bikeDataTable.Rows[i]["bike_name"];
                    string           description      = (string)bikeDataTable.Rows[i]["description"];
                    float            price            = (float)bikeDataTable.Rows[i]["price"];
                    int              imageId          = (int)bikeDataTable.Rows[i]["image"];
                    AvailableBicycle availableBicycle = new AvailableBicycle(id, name, description, price, imageId);
                    for (int j = 0; j < bikeVariationDataTable.Rows.Count; j++)
                    {
                        if ((int)bikeVariationDataTable.Rows[j]["model"] == id)
                        {
                            for (int k = 0; k < colorList.Count; k++)
                            {
                                if (!availableBicycle.availableColors.Contains(colorList[k]) && colorList[k].id == (int)bikeVariationDataTable.Rows[j]["color"])
                                {
                                    availableBicycle.AddAvailableColor(colorList[k]);
                                    break;
                                }
                            }
                            for (int l = 0; l < sizeList.Count; l++)
                            {
                                if (!availableBicycle.availableSizes.Contains(sizeList[l]) && sizeList[l].id == (int)bikeVariationDataTable.Rows[j]["size"])
                                {
                                    availableBicycle.AddAvailableSize(sizeList[l]);
                                    break;
                                }
                            }
                        }
                    }
                    bikeList.Add(availableBicycle);
                }
                return(bikeList);
            }
            else
            {
                return(bikeList);
            }
        }