日期:2014-05-18 浏览次数:21083 次
public delegate void listSet(ListViewItem s); private void SetItem(ListViewItem s) { if (this.listView1.InvokeRequired) { listSet setitme = new listSet(SetItem); this.BeginInvoke(setitme,new object[]{s}); return; } else { listView1.Items.Add(s); } } private void ThreadProc() { listView1.Items.Clear(); string sql = " select tw.*,b.gprs_number from dbo.Temp_WaterState as tw join basis_use_water_origin_rtu as b on tw.T_ClientID=b.clientid"; DataSet dt = DHelper.GetDataSet(sql); int cot = dt.Tables[0].Rows.Count; for (int i = 0; i < cot; i++) { ListViewItem list = new ListViewItem(); list.SubItems.Clear(); list.Text = dt.Tables[0].Rows[i]["T_ClientID"] + ""; list.Tag = dt.Tables[0].Rows[i]["T_ClientID"] + ""; list.SubItems.Add(DHelper.getName(dt.Tables[0].Rows[i]["T_ClientID"] + "")); list.SubItems.Add(dt.Tables[0].Rows[i]["T_Time"] + ""); list.SubItems.Add(dt.Tables[0].Rows[i]["gprs_number"] + ""); list.SubItems.Add(DHelper.getKZQ(Convert.ToInt32(dt.Tables[0].Rows[i]["T_EquipState"]))); list.SubItems.Add(DHelper.getWL(Convert.ToInt32(dt.Tables[0].Rows[i]["T_GPRSState"]))); list.SubItems.Add(DHelper.getGD(Convert.ToInt32(dt.Tables[0].Rows[i]["T_PowerSupply"]))); list.SubItems.Add(DHelper.getM(Convert.ToInt32(dt.Tables[0].Rows[i]["T_OpenAlarm"]))); SetItem(list); Thread.Sleep(500); } Thread.Sleep(5000); } private void go_Click(object sender, EventArgs e) { Thread th1 = new Thread(new ThreadStart(ThreadProc)); th1.Start(); }