Exemple #1
0
        // private void button_GetCarList_Click(object sender, EventArgs e)
        //{
        //    this.dataGridView1.Rows.Clear();//清空datagridView
        //    string ChePaiHao = this.textBox_ChePaiHao.Text; //获取输入的车牌号
        //    DealDataGridViewQueryBLL bll = new DealDataGridViewQueryBLL();
        //    List<RfidStorage_AmbulanceInfo> list = bll.GetCarIOTList(ChePaiHao); //获取数据源List
        //    for (int i = 0; i < list.Count; i++)
        //    {
        //        AddCllbDataGridRow(i + 1, list[i].CangKuID, list[i].ChePaiHao, list[i].DuXieQiID);
        //    }
        //}


        //private delegate void AddCllbDataGridRowDelegate(int count, string carID, string carNum, string DuXieQiID);
        //public void AddCllbDataGridRow(int count, string carID, string carNum, string DuXieQiID)
        //{
        //    if (dataGridView1.InvokeRequired)
        //    {
        //        AddCllbDataGridRowDelegate c = new AddCllbDataGridRowDelegate(AddCllbDataGridRow);
        //        this.Invoke(c, new object[] { count, carID, carNum, DuXieQiID });
        //    }
        //    else
        //    {
        //        DataGridViewRow dgvr = new DataGridViewRow();
        //        foreach (DataGridViewColumn c in this.dataGridView1.Columns)
        //        {
        //            dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); //给行添加单元格
        //        }
        //        dgvr.Cells[0].Value = count;
        //        dgvr.Cells[1].Value = carID;
        //        dgvr.Cells[2].Value = carNum;
        //        dgvr.Cells[3].Value = DuXieQiID;
        //        this.dataGridView1.Rows.Add(dgvr);
        //        //Thread.Sleep(10000);

        //    }
        //}

        /// <summary>
        /// 车辆物联列表tabpage页 查询按钮点击回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_GetCarList_Click(object sender, EventArgs e)
        {
            this.dataGridView1.Rows.Clear();
            this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; //调整列宽
            string ChePaiHao = this.textBox_ChePaiHao.Text;                                                     //这两行代码放在这里不会报错
            //启线程
            Thread thread = new Thread(() =>
            {
                //this.dataGridView1.Rows.Clear();
                //string ChePaiHao = this.textBox_ChePaiHao.Text;  //放在这里会报错 因为涉及到跨线程访问控件 分别放开注释debug调试下

                DealDataGridViewQueryBLL bll          = new DealDataGridViewQueryBLL();
                List <RfidStorage_AmbulanceInfo> list = bll.GetCarIOTList(ChePaiHao); //获取数据源List
                for (int i = 0; i < list.Count; i++)
                {
                    AddCllbDataGridRow(i + 1, list[i].CangKuID, list[i].ChePaiHao, list[i].DuXieQiID);
                }
            }); //新建线程

            thread.IsBackground = true;
            thread.Start();
        }