private bool CheckCameraInfo() { if (txtCameraName.Text.Trim() == "" || txtIPAddress.Text.Trim() == "") { MessageBox.Show("摄像机名称和IP地址均不可为空"); return(false); } if (!Basic_WindowOperation.IPCheck(txtIPAddress.Text)) { MessageBox.Show("摄像机IP地址格式不正确,请修正"); return(false); } if (ExistName(txtCameraName.Text)) { MessageBox.Show("摄像机名称已存在,请修正"); txtCameraName.Select(0, txtCameraName.Text.Length); return(false); } if (ExistIPAddress(txtIPAddress.Text)) { MessageBox.Show("摄像机IP地址已存在,请修正"); txtIPAddress.Select(0, txtIPAddress.Text.Length); return(false); } return(true); }
/// <summary> /// 逻辑要清晰 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void decoderView_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { DataGridViewRow drg = decoderView.Rows[e.RowIndex]; drg.ErrorText = ""; if (drg.IsNewRow) { return; } if (drg.Cells[1].FormattedValue.ToString() == "") { e.Cancel = true; drg.ErrorText = "解码器名称不得为空"; return; } if (drg.Cells[2].FormattedValue.ToString() == "") { e.Cancel = true; drg.ErrorText = "解码器IP地址不得为空"; return; } if (drg.Cells[5].FormattedValue.ToString() == "") { e.Cancel = true; drg.ErrorText = "解码器的序列号不得不为空,可通过在浏览器地址栏输入如下命令查询:\n http://DecoderIP/axis-cgi/admin/param.cgi?action=list&group=root.Properties.System.SerialNumber "; return; } if (!Basic_WindowOperation.IPCheck(drg.Cells[2].FormattedValue.ToString())) { e.Cancel = true; drg.ErrorText = "IP地址格式错误"; return; } foreach (DataGridViewRow dr in decoderView.Rows) { if (e.RowIndex != dr.Index && drg.Cells[1].FormattedValue.ToString() == dr.Cells[1].FormattedValue.ToString()) { e.Cancel = true; drg.ErrorText = "解码器名称重复"; return; } if (e.RowIndex != dr.Index && drg.Cells[2].FormattedValue.ToString() == dr.Cells[2].FormattedValue.ToString()) { e.Cancel = true; drg.ErrorText = "IP地址重复"; return; } if (e.RowIndex != dr.Index && drg.Cells[5].FormattedValue.ToString() == dr.Cells[5].FormattedValue.ToString()) { e.Cancel = true; drg.ErrorText = "解码器序列号重复"; return; } } }