コード例 #1
0
        /// <summary>
        /// フォーム起動後、店舗リストとジャンルリストを取得する
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewForm_Load(object sender, EventArgs e)
        {
            try
            {
                // 店舗リストの取得準備
                ShopListController shopListController = new ShopListController();
                List <ItemSet>     shop = shopListController.GetShop();

                // ListBoxに表示名と値を格納する
                this.ShopListBox.DataSource    = shop;
                this.ShopListBox.DisplayMember = "ItemDisp";
                this.ShopListBox.ValueMember   = "ItemValue";

                // ジャンルリストの取得準備
                GetGenreController getGenreController = new GetGenreController();
                List <ItemSet>     genreList          = getGenreController.GetGenre();

                // ComboBoxに表示名と値を格納する
                this.GenreComboBox.DataSource    = genreList;
                this.GenreComboBox.DisplayMember = "ItemDisp";
                this.GenreComboBox.ValueMember   = "ItemValue";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// ResultFormを開き、取得した店舗のリストからランダムに1店舗表示する
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResultFormButton_Click(object sender, EventArgs e)
        {
            string         genre = GenreComboBox.SelectedValue.ToString();
            List <ItemSet> shop  = null;

            try
            {
                // お任せを選んだ場合は全店舗のリスト
                if (genre == "0")
                {
                    ShopListController shopListController = new ShopListController();
                    shop = shopListController.GetShop();
                }
                else
                {
                    GetShopController getShopController = new GetShopController();
                    shop = getShopController.GetShop(genre);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // Listの中からランダムに1店舗表示
            ResultForm resultForm = new ResultForm();

            resultForm.Show();

            string shopName = shop.OrderBy(_ => Guid.NewGuid()).First().ItemDisp.ToString();

            resultForm.ResultLabel.Text = shopName;

            // 旧ランダムコード(勉強用に記録しています)
            // Random random = new Random();
            // int i = random.Next(0, shop.Count);
            // string shopResult = shop[i].ItemDisp.ToString();
            // resultForm.ResultLabel.Text = shopResult;
        }