/// <summary>
 ///删除选中行数据的方法
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tslDelFVN()
 {
     try
     {
         int j = 0;
         if (dgvFVN.SelectedRows.Count > 0)//选中删除
         {
             if (MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 //选中数量
                 int    count = dgvFVN.SelectedRows.Count;
                 string id    = "";
                 //遍历
                 for (int i = 0; i < count; i++)
                 {
                     int fvnid = int.Parse(this.dgvFVN.SelectedRows[i].Cells["FVN_ID"].Value.ToString());
                     Expression <Func <FVNInfo, bool> > funuserinfo = n => n.FVN_ID == fvnid;
                     string strContent = LinQBaseDao.Query("select FVN_Name from FVNInfo where FVN_ID=" + fvnid).Tables[0].Rows[0][0].ToString();
                     if (FVNDAL.DeleteToMany(funuserinfo))
                     {
                         j++;
                         CommonalityEntity.WriteLogData("删除", "删除地感名称为 " + strContent + " 的信息", common.USERNAME);//添加日志
                     }
                 }
                 if (j == count)
                 {
                     MessageBox.Show("成功删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 else
                 {
                     MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
         }
         else//没有选中
         {
             MessageBox.Show("请选择要删除的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch
     {
         CommonalityEntity.WriteTextLog("地感管理 tslDelFVN()+");
     }
     finally
     {
         LogInfoLoad("");
     }
 }
        /// <summary>
        /// 查重方法
        /// </summary>
        /// <returns></returns>
        private bool btnCheckupdate()
        {
            bool rbool = true;

            try
            {
                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);
                string name         = this.txtFVN_Name.Text.Trim();
                int    value        = int.Parse(this.txtFVN_Value.Text.Trim());
                //判断名称是否已存在
                Expression <Func <View_FVN_Driveway_Position, bool> > funviewFVNInfo = n => n.Position_Name == PositionName && n.Driveway_Name == DrivewayName && n.FVN_Name == name && n.FVN_Name != this.dgvFVN.SelectedRows[0].Cells["FVN_Name"].Value.ToString();
                if (FVNDAL.QueryView(funviewFVNInfo).Count() > 0)
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "该地感名称已存在", txtFVN_Name, this);
                    this.txtFVN_Name.Focus();
                    rbool = false;;
                }
                Expression <Func <View_FVN_Driveway_Position, bool> > funviewFVNInfo1 = n => n.Position_Name == PositionName && n.Driveway_Name == DrivewayName && n.FVN_Value == value && n.FVN_Value != int.Parse(this.dgvFVN.SelectedRows[0].Cells["FVN_Value"].Value.ToString());
                if (FVNDAL.QueryView(funviewFVNInfo1).Count() > 0)
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "该地感值已存在", txtFVN_Value, this);
                    this.txtFVN_Value.Focus();
                    rbool = false;;
                }
                return(rbool);
            }
            catch
            {
                CommonalityEntity.WriteTextLog("地感管理 btnCheck()");
                rbool = false;
            }
            return(rbool);
        }
        /// <summary>
        /// 双击组件时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvFVN_DoubleClick(object sender, EventArgs e)
        {
            this.btnUpdate.Enabled = true;
            this.btnSave.Enabled   = false;
            if (this.dgvFVN.SelectedRows.Count > 0)//选中行
            {
                if (dgvFVN.SelectedRows.Count > 1)
                {
                    MessageBox.Show("修改只能选中一行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    //修改的值
                    int ID = int.Parse(this.dgvFVN.SelectedRows[0].Cells["FVN_ID"].Value.ToString());
                    Expression <Func <View_FVN_Driveway_Position, bool> > funviewinto = n => n.FVN_ID == ID;
                    foreach (var n in FVNDAL.QueryView(funviewinto))
                    {
                        if (n.FVN_Name != null)
                        {
                            // 地感名称
                            this.txtFVN_Name.Text = n.FVN_Name;
                        }
                        if (n.FVN_Type != null)
                        {
                            // 地感类型
                            this.cbxFVN_Type.Text = n.FVN_Type;
                        }
                        if (n.FVN_State != null)
                        {
                            // 地感状态
                            this.cbxFVN_State.Text = n.FVN_State;
                        }
                        if (n.FVN_Value != null)
                        {
                            // 地感PLC值
                            this.txtFVN_Value.Text = n.FVN_Value.ToString();
                        }
                        if (n.Position_Name != null)
                        {
                            // 门岗名称
                            this.cbxPositionName.Text = n.Position_Name;
                        }
                        if (n.FVN_Driveway_ID != null)
                        {
                            // 通道名称
                            this.cbxDrivewayName.Text = n.Driveway_Name + n.Driveway_Type;
                        }

                        if (n.FVN_Remark != null || n.FVN_Remark != "")
                        {
                            // 地感备注
                            this.txtFVN_Remark.Text = n.FVN_Remark;
                        }
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择要修改的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
 /// <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("");
     }
 }