Ejemplo n.º 1
0
        public static Control showBarService()
        {
            // make a list for retrieving data from it
            List <SomerenModel.BarService> barServices = new List <SomerenModel.BarService>();

            // linking the list to the DB connection in order to get data from it
            barServices = SomerenDB.DB_getBarServices();

            // Making a list and editing its format
            ListView barServiceListView = new ListView();

            barServiceListView.Height        = 370;
            barServiceListView.Width         = 370;
            barServiceListView.View          = View.Details;
            barServiceListView.FullRowSelect = true;

            // add columns to the list view
            barServiceListView.Columns.Add("ID", -2, HorizontalAlignment.Left);
            barServiceListView.Columns.Add("Drink Name", -2, HorizontalAlignment.Left);
            barServiceListView.Columns.Add("Drink Price", -2, HorizontalAlignment.Left);
            barServiceListView.Columns.Add("Amount (In Stock)", -2, HorizontalAlignment.Left);

            // declare a string variable for adding new text to stock amount data
            string StockState;

            // store data to the list view
            foreach (SomerenModel.BarService barService in barServices)
            {
                ListViewItem entryListItem = barServiceListView.Items.Add(barService.getDrinkId().ToString());
                entryListItem.SubItems.Add(barService.getDrinkName().ToString());
                entryListItem.SubItems.Add(barService.getDrinkPrice().ToString());

                // adding new text to stock amount data depending on its value
                if (barService.getStockAmount() < 10)
                {
                    StockState = barService.getStockAmount() + "   (Stock nearly depleted)";
                }
                else
                {
                    StockState = barService.getStockAmount() + "   (Stock sufficient)";
                }
                entryListItem.SubItems.Add(StockState.ToString());
            }

            // return a list view
            return(barServiceListView);
        }