public void FoodsTypeMenusLoad() { #region 菜品类别 //菜品类别 动态生成button控件和text赋值 string stringJson = httpClient.Get("/Menu/GetFoodsType"); Data data = JsonConvert.DeserializeObject <Data>(stringJson); string json = JsonConvert.SerializeObject(data.Result); List <Base_Food_Menus> base_Foods = JsonConvert.DeserializeObject <List <Base_Food_Menus> >(json); DataTable table = GetListToDataTable.ListToDataTable(base_Foods); for (int i = 0; i < table.Rows.Count; i++) { int n = i % 1; if (n == 0 && i != 0) //这个条件语句的意思是:如果控件的数量正好是1的倍数的话那么tmp+1 这个是用于控制y轴的 { h++; } int x = n * 0, y = 65 * h;//这里定义的x和y便于控制控件在界面上的位置 Button btn = new Button(); btn.Dock = System.Windows.Forms.DockStyle.Top; btn.BorderRadius = 0; btn.Location = new System.Drawing.Point(x + 0, y); btn.Name = table.Rows[i]["Food_Id"].ToString(); btn.DataMember = table.Rows[i]["Food_Id"].ToString(); btn.DisplayMember = table.Rows[i]["Food_Name"].ToString(); btn.Size = new System.Drawing.Size(83, 85); btn.Text = table.Rows[i]["Food_Name"].ToString(); btn.BackColor = System.Drawing.Color.WhiteSmoke; btn.ForeColor = System.Drawing.Color.Black; btn.Press += new EventHandler(btn_Click);//button的单击事件 panel2.Controls.Add(btn); } #endregion #region All菜品 //所有菜品和类别id 给foods_listView绑定数据 string stringJson1 = httpClient.Get("/Menu/GetMenus"); Data data1 = JsonConvert.DeserializeObject <Data>(stringJson1); string json1 = JsonConvert.SerializeObject(data1.Result); List <Order_Food_Model.Base_Menus> base_Menus = JsonConvert.DeserializeObject <List <Order_Food_Model.Base_Menus> >(json1); if (base_Menus.Count > 0) { foods_listView.DataSource = base_Menus; foods_listView.DataBind(); } #endregion }
public void GetCarList() { int h = 1; string getCarList = http.Get("/Menu/GetCars"); Data data = JsonConvert.DeserializeObject <Data>(getCarList); string json = JsonConvert.SerializeObject(data.Result); List <ShowCarModel> list = JsonConvert.DeserializeObject <List <ShowCarModel> >(json); DataTable table = GetListToDataTable.ListToDataTable(list); if (table.Rows.Count > 0) { for (int i = 0; i < table.Rows.Count; i++) { int n = i % 1; if (n == 0 && i != 0) //这个条件语句的意思是:如果控件的数量正好是1的倍数的话那么tmp+1 这个是用于控制y轴的 { h++; } int x = n * 0, y = 49 * h;//这里定义的x和y便于控制控件在界面上的位置 int x1 = n * 10, y1 = 49 * h; int x2 = n * 128, y2 = 49 * h; int x3 = n * 278, y3 = 57 * h; int x4 = n * 235, y4 = 57 * h; int x5 = n * 255, y5 = 57 * h; Label label = new Label(); Label Menuname = new Label(); Label price = new Label(); Button btnplus = new Button(); Button btndes = new Button(); TextBox numberSum = new TextBox(); label.Dock = System.Windows.Forms.DockStyle.Top; label.BorderRadius = 0; label.Location = new System.Drawing.Point(x + 0, y); label.Size = new System.Drawing.Size(300, 35); label.BackColor = System.Drawing.Color.WhiteSmoke; panel2.Controls.Add(label); Menuname.Dock = System.Windows.Forms.DockStyle.Top; Menuname.BorderRadius = 0; Menuname.Location = new System.Drawing.Point(x1 + 0, y1); Menuname.Size = new System.Drawing.Size(100, 35); Menuname.Name = table.Rows[i]["Menu_Id"].ToString(); Menuname.Text = table.Rows[i]["Menu_Name"].ToString(); Menuname.DataMember = table.Rows[i]["Menu_Id"].ToString(); Menuname.DisplayMember = table.Rows[i]["Menu_Name"].ToString(); Menuname.BackColor = System.Drawing.Color.WhiteSmoke; Menuname.ForeColor = System.Drawing.Color.Black; panel2.Controls.Add(Menuname); price.Dock = System.Windows.Forms.DockStyle.Top; price.BorderRadius = 0; price.Location = new System.Drawing.Point(x2 + 0, y2); price.Size = new System.Drawing.Size(56, 35); price.Name = table.Rows[i]["Food_Id"].ToString(); price.Text = table.Rows[i]["Food_Name"].ToString(); price.DataMember = table.Rows[i]["Food_Id"].ToString(); price.DisplayMember = table.Rows[i]["Food_Name"].ToString(); price.BackColor = System.Drawing.Color.WhiteSmoke; price.ForeColor = System.Drawing.Color.Red; panel2.Controls.Add(price); btnplus.BorderRadius = 0; btnplus.Location = new System.Drawing.Point(x3 + 0, y3); btnplus.Dock = System.Windows.Forms.DockStyle.Top; btnplus.Size = new System.Drawing.Size(16, 18); btnplus.Name = table.Rows[i]["Food_Id"].ToString(); btnplus.Text = table.Rows[i]["Menu_Price"].ToString(); btnplus.DataMember = table.Rows[i]["Food_Id"].ToString(); btnplus.DisplayMember = table.Rows[i]["Menu_Price"].ToString(); btnplus.BackColor = System.Drawing.Color.WhiteSmoke; btnplus.ForeColor = System.Drawing.Color.Black; btndes.Press += new EventHandler(Addbtn_Click);//button的单击事件 panel2.Controls.Add(btnplus); btndes.BorderRadius = 0; btndes.Location = new System.Drawing.Point(x4 + 0, y4); btndes.Dock = System.Windows.Forms.DockStyle.Top; btndes.Size = new System.Drawing.Size(16, 18); btndes.Text = "+"; btndes.BackColor = System.Drawing.Color.WhiteSmoke; btndes.ForeColor = System.Drawing.Color.Black; btndes.Press += new EventHandler(Delbtn_Click);//button的单击事件 panel2.Controls.Add(btndes); numberSum.BorderRadius = 0; numberSum.Location = new System.Drawing.Point(x5 + 0, y5); numberSum.Dock = System.Windows.Forms.DockStyle.Top; numberSum.Size = new System.Drawing.Size(20, 18); numberSum.Name = "1"; numberSum.Text = "1"; numberSum.BackColor = System.Drawing.Color.WhiteSmoke; numberSum.ForeColor = System.Drawing.Color.Black; panel2.Controls.Add(numberSum); } } this.Close(); }