/// <summary>
        /// 在门岗名称上更改SelectedValueChanged的值时引发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbxPositionName_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cbxDrivewayName.Items.Count > 0)
            {
                this.cbxDrivewayName.Items.Clear();
            }
            if (cbxPositionName.Text == "")
            {
                return;
            }

            string PositionName = this.cbxPositionName.Text;
            var    name         = DrivewayDAL.GetViewDrivewayName(String.Format("select * from View_DrivewayPosition where Position_Name='{0}' and Driveway_State='启动'", PositionName));

            if (name != null)
            {
                foreach (var item in name)
                {
                    if (item.Driveway_Name != null)
                    {
                        if (item.Driveway_Type != null)
                        {
                            cbxDrivewayName.Items.Add(item.Driveway_Name + item.Driveway_Type);
                            cbxDrivewayName.SelectedIndex = 0;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// “修改”  按钮的单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtCamera_Name.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "摄像头名称不能为空!", txtCamera_Name, this);
                    return;
                }
                if (this.txtCamera_CardAdd.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "摄像头地址码不能为空!", txtCamera_CardAdd, this);
                    return;
                }

                string PositionName = this.cbxPositionName.Text.ToString();
                int    lenth        = cbxDrivewayName.Text.Trim().Length;
                string DrivewayName = cbxDrivewayName.Text.Trim().Substring(0, 4);
                string DrivewayType = cbxDrivewayName.Text.Trim().Substring(lenth - 1, 1);
                int    DrivewayID   = 0;
                var    p            = DrivewayDAL.GetViewDrivewayName(String.Format("select Driveway_ID from View_DrivewayPosition where Position_Name='{0}' and  Driveway_Name= '{1}' and Driveway_Type= '{2}'", PositionName, DrivewayName, DrivewayType));
                if (p != null)
                {
                    foreach (var n in p)
                    {
                        if (n.Driveway_ID > 0)
                        {
                            DrivewayID = n.Driveway_ID;
                        }
                        break;
                    }
                }
                if (this.dgvCamera.SelectedRows.Count > 0)//选中行
                {
                    if (dgvCamera.SelectedRows.Count > 1)
                    {
                        MessageBox.Show("修改只能选中一行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        if (!btnCheckupdate())
                        {
                            return;                    // 去重复
                        }
                        Expression <Func <Camera, bool> > pc = n => n.Camera_ID == int.Parse(this.dgvCamera.SelectedRows[0].Cells["Camera_ID"].Value.ToString());
                        string          id         = "";
                        string          strfront   = "";
                        string          strcontent = "";
                        Action <Camera> ap         = s =>
                        {
                            strfront             = s.Camera_Driveway_ID + "," + s.Camera_Name + "," + s.Camera_AddCard + "," + s.Camera_State + "," + s.Camera_Location + "," + s.Camera_Remark;
                            s.Camera_Driveway_ID = DrivewayID;
                            s.Camera_Name        = this.txtCamera_Name.Text.Trim();
                            s.Camera_AddCard     = this.txtCamera_CardAdd.Text.Trim();
                            s.Camera_State       = this.cbxCamera_State.Text;
                            s.Camera_Location    = this.cbxCamera_Location.Text;
                            s.Camera_Remark      = this.txtCamera_Remark.Text.Trim();
                            s.Camera_DVIName     = cmbDVI.Text;
                            strcontent           = s.Camera_Driveway_ID + "," + s.Camera_Name + "," + s.Camera_AddCard + "," + s.Camera_State + "," + s.Camera_Location + "," + s.Camera_Remark;
                            id = s.Camera_ID.ToString();
                        };

                        if (CameraDAL.Update(pc, ap))
                        {
                            MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            CommonalityEntity.WriteLogData("修改", "更新编号为:" + id + "的摄像头信息;修改前:" + strfront + ";修改后:" + strcontent, CommonalityEntity.USERNAME);//添加操作日志
                        }
                        else
                        {
                            MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            catch
            {
                CommonalityEntity.WriteTextLog("摄像头管理 btnUpdate_Click()");
            }
            finally
            {
                LogInfoLoad("");
                this.btnUpdate.Enabled = false;
                this.btnSave.Enabled   = true;
            }
        }
        /// <summary>
        /// “保存” 按钮的单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtCamera_Name.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "摄像头名称不能为空!", txtCamera_Name, this);
                    return;
                }
                if (this.txtCamera_CardAdd.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "摄像头地址码不能为空!", txtCamera_CardAdd, this);
                    return;
                }

                string PositionName = this.cbxPositionName.Text.ToString();
                int    lenth        = cbxDrivewayName.Text.Trim().Length;
                string DrivewayName = cbxDrivewayName.Text.Trim().Substring(0, 4);
                string DrivewayType = cbxDrivewayName.Text.Trim().Substring(lenth - 1, 1);
                int    DrivewayID   = 0;
                var    p            = DrivewayDAL.GetViewDrivewayName(String.Format("select Driveway_ID from View_DrivewayPosition where Position_Name='{0}' and  Driveway_Name= '{1}' and Driveway_Type= '{2}'", PositionName, DrivewayName, DrivewayType));
                if (p != null)
                {
                    foreach (var n in p)
                    {
                        if (n.Driveway_ID > 0)
                        {
                            DrivewayID = n.Driveway_ID;
                        }
                        break;
                    }
                }
                if (!btnCheck())
                {
                    return;              // 去重复
                }
                var Cameraadd = new Camera
                {
                    Camera_Driveway_ID = DrivewayID,
                    Camera_Name        = this.txtCamera_Name.Text.Trim(),
                    Camera_AddCard     = this.txtCamera_CardAdd.Text.Trim(),
                    Camera_State       = this.cbxCamera_State.Text,
                    Camera_Location    = this.cbxCamera_Location.Text,
                    Camera_Remark      = this.txtCamera_Remark.Text.Trim(),
                    Camera_DVIName     = cmbDVI.Text
                };

                if (CameraDAL.InsertOneCamera(Cameraadd))
                {
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    CommonalityEntity.WriteLogData("新增", "新增摄像头名称为:" + txtCamera_Name.Text.Trim() + "的信息", CommonalityEntity.USERNAME);//添加操作日志
                }
                else
                {
                    MessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch
            {
                CommonalityEntity.WriteTextLog("摄像头管理 btnSave_Click()");
            }
            finally
            {
                LogInfoLoad("");
            }
        }
 /// <summary>
 /// “修改” 按钮的单击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.txtFVN_Name.Text == "")
         {
             PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "地感名称不能为空!", txtFVN_Name, this);
             return;
         }
         if (this.txtFVN_Value.Text == "")
         {
             PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "地感PLC值不能为空!", txtFVN_Value, this);
             return;
         }
         string PositionName = this.cbxPositionName.Text.ToString();
         int    lenth        = cbxDrivewayName.Text.Trim().Length;
         string DrivewayName = cbxDrivewayName.Text.Trim();
         string DrivewayType = cbxFVN_Type.Text.Trim();
         int    DrivewayID   = 0;
         var    p            = DrivewayDAL.GetViewDrivewayName(String.Format("select Driveway_ID from View_DrivewayPosition where Position_Name='{0}' and  Driveway_Name= '{1}'", PositionName, DrivewayName));
         if (p != null)
         {
             foreach (var n in p)
             {
                 if (n.Driveway_ID > 0)
                 {
                     DrivewayID = n.Driveway_ID;
                 }
                 break;
             }
         }
         if (this.dgvFVN.SelectedRows.Count > 0)//选中行
         {
             if (dgvFVN.SelectedRows.Count > 1)
             {
                 MessageBox.Show("修改只能选中一行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 if (!btnCheckupdate())
                 {
                     return;                    // 去重复
                 }
                 #region  修改
                 string id         = "";
                 string strfront   = "";
                 string strcontent = "";
                 Expression <Func <FVNInfo, bool> > pf = n => n.FVN_ID == int.Parse(this.dgvFVN.SelectedRows[0].Cells["FVN_ID"].Value.ToString());
                 Action <FVNInfo> ap = s =>
                 {
                     strfront          = s.FVN_Driveway_ID + "," + s.FVN_Value + "," + s.FVN_Name + "," + s.FVN_State + "," + s.FVN_Remark + "," + s.FVN_Type;
                     s.FVN_Driveway_ID = DrivewayID;
                     s.FVN_Value       = int.Parse(this.txtFVN_Value.Text);
                     s.FVN_Name        = this.txtFVN_Name.Text.Trim();
                     s.FVN_State       = this.cbxFVN_State.Text;
                     s.FVN_Remark      = this.txtFVN_Remark.Text.Trim();
                     s.FVN_Type        = this.cbxFVN_Type.Text;
                     strcontent        = s.FVN_Driveway_ID + "," + s.FVN_Value + "," + s.FVN_Name + "," + s.FVN_State + "," + s.FVN_Remark + "," + s.FVN_Type;
                     id = s.FVN_ID.ToString();
                 };
                 if (FVNDAL.Update(pf, ap))
                 {
                     MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     CommonalityEntity.WriteLogData("修改", "更新编号为:" + id + "的地感信息;修改前:" + strfront + ";修改后:" + strcontent, CommonalityEntity.USERNAME);//添加日志
                 }
                 else
                 {
                     MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 #endregion
             }
         }
     }
     catch
     {
         CommonalityEntity.WriteTextLog("地感管理 btnUpdate_Click()");
     }
     finally
     {
         LogInfoLoad("");
         this.btnUpdate.Enabled = false;
         this.btnSave.Enabled   = true;
     }
 }
 /// <summary>
 /// “保存” 按钮的单击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.txtFVN_Name.Text == "")
         {
             PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "地感名称不能为空!", txtFVN_Name, this);
             return;
         }
         if (this.txtFVN_Value.Text == "")
         {
             PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "地感PLC值不能为空!", txtFVN_Value, this);
             return;
         }
         string PositionName = this.cbxPositionName.Text.ToString();
         int    lenth        = cbxDrivewayName.Text.Trim().Length;
         string DrivewayName = cbxDrivewayName.Text.Trim().Substring(0, 4);
         string DrivewayType = cbxDrivewayName.Text.Trim().Substring(lenth - 1, 1);
         int    DrivewayID   = 0;
         var    p            = DrivewayDAL.GetViewDrivewayName(String.Format("select Driveway_ID from View_DrivewayPosition where Position_Name='{0}' and  Driveway_Name= '{1}' and Driveway_Type= '{2}'", PositionName, DrivewayName, DrivewayType));
         if (p != null)
         {
             foreach (var n in p)
             {
                 if (n.Driveway_ID > 0)
                 {
                     DrivewayID = n.Driveway_ID;
                 }
                 break;
             }
         }
         if (!btnCheck())
         {
             return;              // 去重复
         }
         var FVNadd = new FVNInfo
         {
             FVN_Driveway_ID = DrivewayID,
             FVN_Value       = int.Parse(this.txtFVN_Value.Text),
             FVN_Name        = this.txtFVN_Name.Text.Trim(),
             FVN_State       = this.cbxFVN_State.Text,
             FVN_Remark      = this.txtFVN_Remark.Text.Trim(),
             FVN_Type        = this.cbxFVN_Type.Text
         };
         if (FVNDAL.InsertOneQCRecord(FVNadd))
         {
             MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             string strContent1 = "地感名称为:" + this.txtFVN_Name.Text.Trim();
             CommonalityEntity.WriteLogData("新增", "新增 " + strContent1 + " 的信息", common.NAME);//添加日志
         }
         else
         {
             MessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch
     {
         CommonalityEntity.WriteTextLog("地感管理 btnSave_Click()");
     }
     finally
     {
         LogInfoLoad("");
     }
 }