//登录、注销设备 private void button4_Click(object sender, EventArgs e) { string ip; //存储ip int count = 0; //存储得到链表中确定设备的位置 if (listView1.SelectedItems.Count == 0) { return; } else { int selectCount = this.listView1.SelectedItems.Count; NVRCsharpDemo.Camera camera = null; for (int i = 0; i < selectCount; i++) { ip = this.listView1.SelectedItems[i].SubItems[5].Text; if (ip.Equals("离线")) //如果设备离线就登录 { camera = new NVRCsharpDemo.Camera(listView1.SelectedItems[i].SubItems[1].Text, //lid listView1.SelectedItems[i].SubItems[2].Text, //lname listView1.SelectedItems[i].SubItems[3].Text, //ip Convert.ToInt16(listView1.SelectedItems[i].SubItems[4].Text), //port listView1.SelectedItems[i].SubItems[5].Text, //username listView1.SelectedItems[i].SubItems[6].Text); //password try { Dcommon.AddCL(camera); listView1.SelectedItems[i].SubItems[5].Text = "在线"; } catch (Exception ex) { Console.WriteLine(ex.Message); } } else//设备在线就注销 { count = Dcommon.GetCamera(listView1.SelectedItems[i].SubItems[1].Text); try { Dcommon.RemoveCLByI(count - 1); listView1.SelectedItems[i].SubItems[5].Text = "离线"; } catch (Exception ex) { Console.WriteLine(ex.Message); } } camera = null; //把新建的对象登录,修改状态 } } }
//添加登录设备 public bool AddCL(NVRCsharpDemo.Camera camera) { if (CheckRepeat(camera.getIp())) { return(false); } CameraList.Add(camera);//添加 //登录 if (CameraList[GetCount() - 1].login()) { return(true); } else { CameraList.RemoveAt(GetCount() - 1); } return(false); }