/// <summary>
 /// 双击组件时发生
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvBusinessType_DoubleClick(object sender, EventArgs e)
 {
     this.btnUpdate.Enabled = true;
     this.btnSave.Enabled   = false;
     if (this.dgvBusinessType.SelectedRows.Count > 0)//选中行
     {
         if (dgvBusinessType.SelectedRows.Count > 1)
         {
             MessageBox.Show("修改只能选中一行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             //修改的值
             int ID = int.Parse(this.dgvBusinessType.SelectedRows[0].Cells["BusinessType_ID"].Value.ToString());
             Expression <Func <BusinessType, bool> > funviewinto = n => n.BusinessType_ID == ID;
             foreach (var n in BusinessTypeDAL.QueryView(funviewinto))
             {
                 if (n.BusinessType_Name != null)
                 {
                     // 业务类别名称
                     this.txtBusinessType_Name.Text = n.BusinessType_Name;
                 }
                 if (n.BusinessType_CarType_ID != null && n.BusinessType_CarType_ID > 0)
                 {
                     cmbCarType.Text = LinQBaseDao.GetSingle("select CarType_Name from CarType where CarType_ID=" + n.BusinessType_CarType_ID).ToString();
                 }
                 if (n.BusinessType_State != null)
                 {
                     // 业务类别状态
                     this.cbxBusinessType_State.Text = n.BusinessType_State;
                 }
                 if (n.BusinessType_Loaded != null)
                 {
                     //装货类型
                     this.cbxBusinessType_Loaded.Text = n.BusinessType_Loaded;
                 }
                 if (n.BusinessType_Use != null)
                 {
                     //业务类别用途
                     this.txtBusinessType_Use.Text = n.BusinessType_Use;
                 }
                 if (n.BusinessType_Content != null)
                 {
                     // 业务类别描述
                     this.txtBusinessType_Content.Text = n.BusinessType_Content;
                 }
                 if (n.BusinessType_Remark != null)
                 {
                     // 业务类别备注
                     this.txtBusinessType_Remark.Text = n.BusinessType_Remark;
                 }
                 break;
             }
         }
     }
     else
     {
         MessageBox.Show("请选择要修改的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        /// <summary>
        /// 删除选中数据信息的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tslDelBusinessType()
        {
            try
            {
                int j = 0;
                if (this.dgvBusinessType.SelectedRows.Count > 0)//选中删除
                {
                    if (MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        //选中数量
                        int    count = dgvBusinessType.SelectedRows.Count;
                        string id    = "";
                        //遍历
                        for (int i = 0; i < count; i++)
                        {
                            Expression <Func <BusinessType, bool> > funuserinfo = n => n.BusinessType_ID == int.Parse(this.dgvBusinessType.SelectedRows[i].Cells["BusinessType_ID"].Value.ToString());

                            if (BusinessTypeDAL.DeleteToMany(funuserinfo))
                            {
                                j++;
                                string strContent = "业务类别编号为:" + this.dgvBusinessType.SelectedRows[0].Cells["BusinessType_ID"].Value.ToString();
                                CommonalityEntity.WriteLogData("删除", "删除 " + strContent + " 的信息", common.USERNAME);//添加日志
                            }
                        }
                    }
                    if (j != 0)
                    {
                        MessageBox.Show("成功删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else//没有选中
                {
                    MessageBox.Show("请选择要删除的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception err)
            {
                CommonalityEntity.WriteTextLog("业务类别管理 tslDelBusinessType()+");
            }
            finally
            {
                LogInfoLoad("");
            }
        }
        /// <summary>
        /// “保存” 按钮的单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtBusinessType_Name.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "业务类别名称不能为空!", txtBusinessType_Name, this);
                    return;
                }
                if (!btnCheck())
                {
                    return;              // 去重复
                }
                var BusinessTypeadd = new BusinessType
                {
                    BusinessType_UserId     = int.Parse(common.USERID),
                    BusinessType_Name       = this.txtBusinessType_Name.Text.Trim(),
                    BusinessType_Content    = this.txtBusinessType_Content.Text.Trim(),
                    BusinessType_CreatTime  = Convert.ToDateTime(CommonalityEntity.GetServersTime().ToString()),
                    BusinessType_Remark     = this.txtBusinessType_Remark.Text.Trim(),
                    BusinessType_Use        = this.txtBusinessType_Use.Text.Trim(),
                    BusinessType_State      = this.cbxBusinessType_State.Text,
                    BusinessType_Loaded     = this.cbxBusinessType_Loaded.Text,
                    BusinessType_CarType_ID = Convert.ToInt32(cmbCarType.SelectedValue.ToString())
                };

                if (BusinessTypeDAL.InsertOneBusinessType(BusinessTypeadd))
                {
                    string strContent1 = "业务类别名称为:" + this.txtBusinessType_Name.Text.Trim();;
                    CommonalityEntity.WriteLogData("新增", "新增 " + strContent1 + " 的信息", common.USERNAME);//添加日志
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch
            {
                CommonalityEntity.WriteTextLog("业务类别管理 btnAdd_Click()");
            }
            finally
            {
                LogInfoLoad("");
                Empty(); // 调用清空的方法
            }
        }
        /// <summary>
        /// 查重方法
        /// </summary>
        /// <returns></returns>
        private bool btnCheckupdate()
        {
            bool rbool = true;

            try
            {
                string BusinessType_Name = this.txtBusinessType_Name.Text.ToString();
                //判断名称是否已存在
                Expression <Func <BusinessType, bool> > funviewFVNInfo = n => n.BusinessType_Name == BusinessType_Name && n.BusinessType_Name != this.dgvBusinessType.SelectedRows[0].Cells["BusinessType_Name"].Value.ToString();
                if (BusinessTypeDAL.QueryView(funviewFVNInfo).Count() > 0)
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "该业务类型名称已存在", txtBusinessType_Name, this);
                    this.txtBusinessType_Name.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 btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtBusinessType_Name.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "业务类别名称不能为空!", txtBusinessType_Name, this);
                    return;
                }
                if (this.dgvBusinessType.SelectedRows.Count > 0)//选中行
                {
                    if (dgvBusinessType.SelectedRows.Count > 1)
                    {
                        MessageBox.Show("修改只能选中一行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        if (!btnCheckupdate())
                        {
                            return;                    // 去重复
                        }
                        Expression <Func <BusinessType, bool> > pc = n => n.BusinessType_ID == int.Parse(this.dgvBusinessType.SelectedRows[0].Cells["BusinessType_ID"].Value.ToString());

                        Action <BusinessType> ap = s =>
                        {
                            s.BusinessType_UserId     = CommonalityEntity.USERID;
                            s.BusinessType_Name       = this.txtBusinessType_Name.Text.Trim();
                            s.BusinessType_Content    = this.txtBusinessType_Content.Text.Trim();
                            s.BusinessType_CreatTime  = Convert.ToDateTime(CommonalityEntity.GetServersTime().ToString());
                            s.BusinessType_Remark     = this.txtBusinessType_Remark.Text.Trim();
                            s.BusinessType_Use        = this.txtBusinessType_Use.Text.Trim();
                            s.BusinessType_State      = this.cbxBusinessType_State.Text;
                            s.BusinessType_Loaded     = this.cbxBusinessType_Loaded.Text;
                            s.BusinessType_CarType_ID = Convert.ToInt32(cmbCarType.SelectedValue.ToString());
                        };

                        if (BusinessTypeDAL.Update(pc, ap))
                        {
                            string strContent = "业务类别名称为:" + this.txtBusinessType_Name.Text.Trim();;
                            CommonalityEntity.WriteLogData("修改", "修改 " + strContent + " 的信息", common.USERNAME);//添加日志
                            MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            catch
            {
                CommonalityEntity.WriteTextLog("业务类别管理 btnAdd_Click()");
            }
            finally
            {
                LogInfoLoad("");
                this.btnUpdate.Enabled = false;
                this.btnSave.Enabled   = true;
                Empty(); // 调用清空的方法
            }
        }