/// <summary> /// 读取数据库数据到listbox /// </summary> /// <param name="cloum">列名</param> /// <param name="tab">表名</param> /// <param name="listbox">listbox名</param> private void FreshUI(string cloum, string tab, string listbox) { /* * dataset.Clear(); * * dataset = ServiceContainer.GetService<IGasDAL>().QueryData(cloum, tab); * * int j = 0; * foreach (DataRow dr in dataset.Tables[0].Rows) * { * if (listbox == "lbox_Type") * { * * lbox_Type.Items.Add(dataset.Tables[0].Rows[j][0]); * } * else if (listbox == "lbox_Equip") * { * //dataset = ServiceContainer.GetService<IGasDAL>().QueryData(cloum, tab); * if (dataset.Tables[0].Rows[j][6].ToString() == "1") * lbox_Equip.Items.Add(dataset.Tables[0].Rows[j][0]); * } * j++; * } */ //if (listbox == "lbox_Gasometer") //{} lbox_Gasometer.Items.Clear(); panel1.Controls.Clear(); dataset.Clear(); dataset = ServiceContainer.GetService <IGasDAL>().QueryData(tab); int j = 0; foreach (DataRow dr in dataset.Tables[0].Rows) { //Listbox lbox_Gasometer.Items.Add(dataset.Tables[0].Rows[j][cloum]); //Panel Panel panelBar = new Panel(); panel1.Controls.Add(panelBar); panelBar.BorderStyle = BorderStyle.FixedSingle; panelBar.Location = new Point(10, 10 + panel1.Height * j / 4); panelBar.Size = new Size(this.ClientRectangle.Width, this.ClientRectangle.Height / 4); banner bar = new banner(); bar.LabelText = dataset.Tables[0].Rows[j][cloum].ToString() + "数量:"; bar.UDNum = int.Parse(dataset.Tables[0].Rows[j]["GasometerNum"].ToString()); panelBar.Controls.Add(bar); j++; } }
/// <summary> /// 读取数据库数据到listbox /// </summary> /// <param name="cloum">列名</param> /// <param name="tab">表名</param> /// <param name="listbox">listbox名</param> private void FreshUI(string cloum, string tab, string listbox) { /* dataset.Clear(); dataset = ServiceContainer.GetService<IGasDAL>().QueryData(cloum, tab); int j = 0; foreach (DataRow dr in dataset.Tables[0].Rows) { if (listbox == "lbox_Type") { lbox_Type.Items.Add(dataset.Tables[0].Rows[j][0]); } else if (listbox == "lbox_Equip") { //dataset = ServiceContainer.GetService<IGasDAL>().QueryData(cloum, tab); if (dataset.Tables[0].Rows[j][6].ToString() == "1") lbox_Equip.Items.Add(dataset.Tables[0].Rows[j][0]); } j++; } */ //if (listbox == "lbox_Gasometer") //{} lbox_Gasometer.Items.Clear(); panel1.Controls.Clear(); dataset.Clear(); try { dataset = ServiceContainer.GetService<IGasDAL>().QueryData(tab); } catch (Exception ex) { Console.WriteLine("查询异常" + ex.Message); return; } int j = 0; foreach (DataRow dr in dataset.Tables[0].Rows) { //Listbox lbox_Gasometer.Items.Add(dataset.Tables[0].Rows[j][cloum]); //Panel Panel panelBar = new Panel(); panel1.Controls.Add(panelBar); panelBar.BorderStyle = BorderStyle.FixedSingle; panelBar.Location = new Point(10, 10 + panel1.Height * j / 4); panelBar.Size = new Size(this.ClientRectangle.Width, this.ClientRectangle.Height / 4); banner bar = new banner(); //从数据库中读取数据存放到控件中显示 bar.LabelText = dataset.Tables[0].Rows[j][cloum].ToString(); bar.UDNum = int.Parse(dataset.Tables[0].Rows[j]["GasometerNum"].ToString()); panelBar.Controls.Add(bar); j++; } }