Example #1
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         DataGridViewRow row  = dataGridView1.Rows[e.RowIndex];
         Controller      ctrl = (Controller)row.Tag;
         if (this.dataGridView1.ColumnCount == e.ColumnIndex + 2)//修改IP
         {
             if (MessageBox.Show("确定修改设备地址?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
             {
                 ctrl.ip      = row.Cells[2].Value.ToString();
                 ctrl.mask    = row.Cells[3].Value.ToString();
                 ctrl.gateway = row.Cells[4].Value.ToString();
                 IAccessCore access = new WGAccess();
                 access.SetControllerIP(ctrl);
             }
         }
         else if (this.dataGridView1.ColumnCount == e.ColumnIndex + 1)//获取控制器状态
         {
             IAccessCore     access = new WGAccess();
             ControllerState state  = access.GetControllerState(ctrl);
             MessageBox.Show(state.lastRecordIndex + " " + state.reasonNo.ToString());
         }
     }
 }
Example #2
0
        private void tsmiResetIP_Click(object sender, EventArgs e)
        {
            var rows = GetSelectedRows();

            if (rows.Count == 0)
            {
                WinInfoHelper.ShowInfoWindow(this, "请选择控制器!");
            }
            else
            {
                if (MessageBox.Show("确定恢复选择控制器IP?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }
                CtrlWaiting waiting = new CtrlWaiting(() =>
                {
                    List <ManualResetEvent> evts = new List <ManualResetEvent>();
                    foreach (var item in rows)
                    {
                        Controller c         = (Controller)item.Tag;
                        ManualResetEvent evt = new ManualResetEvent(false);
                        evts.Add(evt);
                        ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
                        {
                            try
                            {
                                using (IAccessCore ac = new WGAccess())
                                {
                                    c.ip      = "192.168.0.0";
                                    c.mask    = "255.255.255.0";
                                    c.gateway = "192.168.0.254";
                                    ac.SetControllerIP(c);
                                }
                            }
                            catch (Exception ex)
                            {
                                WinInfoHelper.ShowInfoWindow(this, c.sn + "重置IP异常:" + ex.Message);
                            }
                            finally
                            {
                                evt.Set();
                            }
                        }));
                    }
                    foreach (var item in evts)
                    {
                        item.WaitOne(30000);
                    }
                });
                waiting.Show(this);
            }
        }
Example #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            _ctrller.ip      = ipAdd.Value;
            _ctrller.mask    = ipMask.Value;
            _ctrller.gateway = ipGateway.Value;


            IAccessCore access = new WGAccess();

            access.SetControllerIP(_ctrller);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }