Day 29 -资料库应用小程序 菜单显示(内涵程序码)

废话不多说直接开始

我们点选菜单按钮会连结到这个表单
https://ithelp.ithome.com.tw/upload/images/20211013/20141567U0q8Or3yUe.jpg

全域变数

   string MyConnection2 = "datasource=122.0.0.0;port=3366;username=root;password=;Allow Zero Datetime=True;";
        private string dbHost = "localhost";
        private string dbPort = "3306";
        private string dbUser = "root";
        private string dbPassword = ""; 
        private string dbName = "db85cc"; 
        MySqlConnection conn = null;
        MySqlDataAdapter mySqlDataAdapter;
        DataSet ds;

按钮按照菜单内商品去做分类

面包按钮:

 try
                {

                string Query = "select product.Product_name,product.Product_price from db85cc.product where product.prodict_id='bread'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); 
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvmenu.DataSource = dTable;             
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }

切片蛋糕:

    try
                {

                string Query = "select product.Product_name,product.Product_price from db85cc.product where product.prodict_id='cake'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvmenu.DataSource = dTable;          
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }

大杯饮料:

     try
                {

                string Query = "select product.Product_name,product.Product_price from db85cc.product where product.prodict_id='drinkL'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); 
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvmenu.DataSource = dTable; 
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }

中杯饮料:

try
                { 
                string Query = "select product.Product_name,product.Product_price from db85cc.product where product.prodict_id='drinkM'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvmenu.DataSource = dTable;  
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }

小杯饮料:

 try
                {
                string Query = "select product.Product_name,product.Product_price from db85cc.product where product.prodict_id='drinkS'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvmenu.DataSource = dTable;           
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }

六寸蛋糕:

try
                {
                string Query = "select product.Product_name,product.Product_price from db85cc.product where product.prodict_id='cake6'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvmenu.DataSource = dTable; 
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }

八寸蛋糕:

try
                {
                string Query = "select product.Product_name,product.Product_price from db85cc.product where product.prodict_id='cake8'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvmenu.DataSource = dTable; 
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }

实测

https://ithelp.ithome.com.tw/upload/images/20211013/20141567Qxhe69PZS0.jpg

https://ithelp.ithome.com.tw/upload/images/20211013/20141567TWn1QlwQgH.jpg

下篇见~~


<<:  Day29:29 - Facebook、Line分享

>>:  Day28-结合全部所学-前端实作篇

我的读书方法

一本书, 要在1到3小时内看完第一次. 第一轮就要把书的背景, 结构及重点抓出来. 第一轮的快速看...

Day27 测试写起乃 - logger level

如果不想看到一堆 SQL 的 log,有另一种方式可以清除,就是调整 logger level 看官...

Day08 Flutter 和 Native 通讯的原理 02

概念: Flutter 会将资料通过 engine 层传送到 native 层,native 处理...

Day 28 角色造型

这个单元是献给没有想像力的新手(94我),画原创的时候很常脑中一片空白,角色单调无力,索性不画了QQ...

让unRiad RAID起来(使用ZFS)

unRaid,顾名思义就「不是RAID」,并不能像一般nas系统一样使用RAID 所以这时候就要用Z...