//获取摄像头列表 private void GetCameraList() { ArrayList clist = new ArrayList(); clist = DbControl.GetCamerasByDB(); if (clist.Count == 0) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\Release\access.log", true, Encoding.UTF8)) { string strLog = DateTime.Now.ToString().Replace('/', '-') + " - miss - 没有获取到摄像头信息"; file.WriteLine(strLog); file.Close(); } return; } foreach (string[] camera in clist) { SettingCameraListItem cameraItem = new SettingCameraListItem(); this.pnlCameraList.Controls.Add(cameraItem); cameraItem.Dock = System.Windows.Forms.DockStyle.Top; cameraItem.Location = new System.Drawing.Point(0, 30 + int.Parse(camera[0]) * 35); cameraItem.Name = "cameraItem" + int.Parse(camera[0]); cameraItem.Size = new System.Drawing.Size(298, 35); cameraItem.TabIndex = int.Parse(camera[0]); cameraItem.cNum = camera[0]; cameraItem.cAlias = camera[1]; cameraItem.cIp = camera[2]; } }
private void btnClose_Click(object sender, EventArgs e) { if (setCtls.GetType() == typeof(SettingListControl)) { SettingListControl setCtl = (SettingListControl)setCtls; this.Visible = false; setCtl.Visible = true; } else if (setCtls.GetType() == typeof(SettingCameraListItem)) { SettingCameraListItem setCli = (SettingCameraListItem)setCtls; this.Visible = false; setCli.Parent.Parent.Visible = true; } }
public SettingControl(Object ctl) { InitializeComponent(); setCtls = ctl; if (ctl.GetType() == typeof(SettingListControl)) { SettingListControl setCtl = (SettingListControl)ctl; Visible = false; } else if (ctl.GetType() == typeof(SettingCameraListItem)) { SettingCameraListItem setCli = (SettingCameraListItem)ctl; Visible = false; this.tbName.Text = setCli.cAlias; this.tbIP.Text = setCli.cIp; pictureBox1.Image = global::TeacherWorkTable.Properties.Resources.ok; pictureBox1.Visible = true; CheckNameFlag = true; pictureBox2.Image = global::TeacherWorkTable.Properties.Resources.ok; pictureBox2.Visible = true; CheckIpFlag = true; } }
private void btnFinished_Click(object sender, EventArgs e) { if (!(CheckNameFlag && CheckIpFlag && CheckUserFlag && CheckPwdFlag)) { return; } if (setCtls.GetType() == typeof(SettingListControl)) { SettingListControl setCtl = (SettingListControl)setCtls; setCtl.Visible = true; this.Visible = false; ArrayList clist = new ArrayList(); clist = DbControl.GetCamerasByDB(); int count = DbControl.GetCameraNumByDB(); int cNum = -1; for (int i = 0; i <= count; i++) { bool flag = true; foreach (string[] camera in clist) { if (int.Parse(camera[0]) == i) { flag = false; break; } } if (flag) { cNum = i; break; } } if (!DbControl.SetCameraToDB(cNum, this.tbName.Text, this.tbIP.Text, this.tbUser.Text, this.tbPassword.Text)) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\Release\access.log", true, Encoding.UTF8)) { string strLog = DateTime.Now.ToString().Replace('/', '-') + " - error - 摄像头添加失败"; file.WriteLine(strLog); file.Close(); } } else { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\Release\access.log", true, Encoding.UTF8)) { string strLog = DateTime.Now.ToString().Replace('/', '-') + " - info - 摄像头添加成功"; file.WriteLine(strLog); file.Close(); } if (cNum != -1) { //将摄像头添加到摄像头列表 SettingCameraListItem cameraItem = new SettingCameraListItem(); setCtl.GetPnlCameraList.Controls.Add(cameraItem); cameraItem.Dock = System.Windows.Forms.DockStyle.Top; cameraItem.Name = "cameraItem" + cNum; cameraItem.Size = new System.Drawing.Size(298, 35); cameraItem.TabIndex = cNum; cameraItem.cNum = cNum.ToString(); cameraItem.cAlias = this.tbName.Text; cameraItem.cIp = this.tbIP.Text; //将摄像头添加到切换列表 System.Windows.Forms.Panel panel = TeacherWorkTable.CaneraChangeList.GetPanel3; CameraChangeControl ccc = new CameraChangeControl(); panel.Controls.Add(ccc); ccc.GetLabel.Text = this.tbName.Text; ccc.TabIndex = cNum; //清空表单 this.tbName.Text = ""; this.tbIP.Text = ""; this.tbUser.Text = ""; this.tbPassword.Text = ""; this.pictureBox1.Visible = false; this.pictureBox2.Visible = false; this.pictureBox3.Visible = false; this.pictureBox4.Visible = false; } } } else if (setCtls.GetType() == typeof(SettingCameraListItem)) { SettingCameraListItem setCli = (SettingCameraListItem)setCtls; setCli.Parent.Visible = true; this.Visible = false; if (!DbControl.UpdateCameraDB(int.Parse(setCli.cNum), this.tbName.Text, this.tbIP.Text, this.tbUser.Text, this.tbPassword.Text)) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\Release\access.log", true, Encoding.UTF8)) { string strLog = DateTime.Now.ToString().Replace('/', '-') + " - error - 摄像头信息变更失败"; file.WriteLine(strLog); file.Close(); } } else { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\Release\access.log", true, Encoding.UTF8)) { string strLog = DateTime.Now.ToString().Replace('/', '-') + " - info - 摄像头信息变更成功"; file.WriteLine(strLog); file.Close(); } setCli.cAlias = this.tbName.Text; setCli.cIp = this.tbIP.Text; System.Windows.Forms.Panel panel = TeacherWorkTable.CaneraChangeList.GetPanel3; foreach (Control ctl in panel.Controls) { if (ctl.GetType() == typeof(CameraChangeControl)) { CameraChangeControl ccc = (CameraChangeControl)ctl; if (ccc.TabIndex == int.Parse(setCli.cNum)) { ccc.GetLabel.Text = this.tbName.Text; } } } //清空表单 this.tbUser.Text = ""; this.tbPassword.Text = ""; this.pictureBox3.Visible = false; this.pictureBox4.Visible = false; } } }