コード例 #1
0
        int LowerID; // 定义一个下级编号的变量
        /// <summary>
        /// “保存” 按钮的单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtCarAttribute_Name.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "车辆属性名称不能为空!", txtCarAttribute_Name, this);
                    return;
                }
                if (this.comboxCarAttribute_HeightID.Text != "")
                {
                    LowerID = int.Parse(this.comboxCarAttribute_HeightID.SelectedValue.ToString());
                }
                else
                {
                    LowerID = 0;
                }
                if (!btnCheck())
                {
                    return;              // 去重复
                }
                var CarAttributeadd = new CarAttribute
                {
                    CarAttribute_Name     = this.txtCarAttribute_Name.Text.Trim(),
                    CarAttribute_State    = this.cbxCarAttribute_State.Text,
                    CarAttribute_HeightID = LowerID
                };

                if (CarAttributeDAL.InsertOneCarAttribute(CarAttributeadd))
                {
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                string strContent1 = "车辆属性名称为:" + this.txtCarAttribute_Name.Text.Trim();;
                CommonalityEntity.WriteLogData("添加", strContent1, CommonalityEntity.USERNAME);//添加操作日志
            }
            catch
            {
                CommonalityEntity.WriteTextLog("车辆属性管理 btnSave_Click()");
            }
            finally
            {
                LogInfoLoad("");
                BindHeightIDAttribute();
                Empty(); // 调用清空的方法
            }
        }
コード例 #2
0
        /// <summary>
        ///删除选中数据信息的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tslDelCarAttribute()
        {
            try
            {
                int j = 0;
                if (dgvCarAttribute.SelectedRows.Count > 0)//选中删除
                {
                    if (MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        //选中数量
                        int    count = dgvCarAttribute.SelectedRows.Count;
                        string id    = "";
                        //遍历
                        for (int i = 0; i < count; i++)
                        {
                            Expression <Func <CarAttribute, bool> > funuserinfo = n => n.CarAttribute_ID == int.Parse(this.dgvCarAttribute.SelectedRows[i].Cells["CarAttribute_ID"].Value.ToString());

                            if (!CarAttributeDAL.DeleteToMany(funuserinfo))
                            {
                                j++;
                            }
                        }
                        if (j == 0)
                        {
                            MessageBox.Show("成功删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            BindHeightIDAttribute(); // 刷新绑定上级编号
                        }
                        else
                        {
                            MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        string strContent = "车辆属性编号为:" + this.dgvCarAttribute.SelectedRows[0].Cells["CarAttribute_ID"].Value.ToString();
                        CommonalityEntity.WriteLogData("删除", strContent, CommonalityEntity.USERNAME);//添加操作日志
                    }
                }
                else//没有选中
                {
                    MessageBox.Show("请选择要删除的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch
            {
                CommonalityEntity.WriteTextLog("车辆属性管理 tslDelCarAttribute()+");
            }
            finally
            {
                LogInfoLoad("");
            }
        }
コード例 #3
0
 /// <summary>
 /// 双击组件时发生
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvCarAttribute_DoubleClick(object sender, EventArgs e)
 {
     this.btnUpdate.Enabled = true;
     this.btnSave.Enabled   = false;
     if (this.dgvCarAttribute.SelectedRows.Count > 0)//选中行
     {
         if (dgvCarAttribute.SelectedRows.Count > 1)
         {
             MessageBox.Show("修改只能选中一行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             //修改的值
             int ID = int.Parse(this.dgvCarAttribute.SelectedRows[0].Cells["CarAttribute_ID"].Value.ToString());
             Expression <Func <CarAttribute, bool> > funviewinto = n => n.CarAttribute_ID == ID;
             foreach (var n in CarAttributeDAL.QueryView(funviewinto))
             {
                 id = n.CarAttribute_ID;
                 this.txtCarAttribute_Name.Enabled = false;
                 if (n.CarAttribute_Name != null)
                 {
                     // 车辆属性名称
                     this.txtCarAttribute_Name.Text = n.CarAttribute_Name;
                 }
                 if (n.CarAttribute_State != null)
                 {
                     //车辆属性状态
                     this.cbxCarAttribute_State.Text = n.CarAttribute_State;
                 }
                 if (n.CarAttribute_HeightID != null)
                 {
                     //车辆属性下级编号
                     this.comboxCarAttribute_HeightID.Text = n.CarAttribute_Name;
                 }
                 break;
             }
         }
     }
     else
     {
         MessageBox.Show("请选择要修改的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
コード例 #4
0
 /// <summary>
 /// 绑定车辆属性上级编号
 /// </summary>
 private void BindHeightIDAttribute()
 {
     try
     {
         string sql = String.Format("select * from CarAttribute where CarAttribute_State='启动'");
         this.comboxCarAttribute_HeightID.DataSource = CarAttributeDAL.GetViewCarAttributeName(sql);
         if (CarAttributeDAL.GetViewCarAttributeName(sql).Count() > 0)
         {
             this.comboxCarAttribute_HeightID.DisplayMember = "CarAttribute_Name";
             this.comboxCarAttribute_HeightID.ValueMember   = "CarAttribute_ID";
             this.comboxCarAttribute_HeightID.SelectedIndex = 0;
         }
         else
         {
             MessageBox.Show("车辆属性下级编号暂无数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch
     {
         MessageBox.Show("车辆属性“车辆属性下级编号”绑定有误,请查看车辆属性信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }
コード例 #5
0
        /// <summary>
        /// “修改”  按钮的单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (id == 0)
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "请选择修改的数据!", txtCarAttribute_Name, this);
                    return;
                }
                if (this.txtCarAttribute_Name.Text == "")
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "车辆属性名称不能为空!", txtCarAttribute_Name, this);
                    return;
                }
                if (this.comboxCarAttribute_HeightID.Text != "" && this.dgvCarAttribute.SelectedRows[0].Cells["CarAttribute_ID"].Value.ToString() != this.comboxCarAttribute_HeightID.Text)
                {
                    LowerID = int.Parse(this.comboxCarAttribute_HeightID.SelectedValue.ToString());
                }
                else
                {
                    LowerID = 0;
                }
                if (this.dgvCarAttribute.SelectedRows[0].Cells["CarAttribute_ID"].Value.ToString() == this.comboxCarAttribute_HeightID.Text)
                {
                    MessageBox.Show("车辆属性的上级编号不能使本身编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                #region 修改
                Expression <Func <CarAttribute, bool> > pc = n => n.CarAttribute_ID == id;

                Action <CarAttribute> ap = s =>
                {
                    s.CarAttribute_Name     = this.txtCarAttribute_Name.Text.Trim();
                    s.CarAttribute_State    = this.cbxCarAttribute_State.Text;
                    s.CarAttribute_HeightID = LowerID;
                };

                if (CarAttributeDAL.Update(pc, ap))
                {
                    MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                string strContent = "车辆属性名称为:" + this.txtCarAttribute_Name.Text.Trim();;
                CommonalityEntity.WriteLogData("修改", strContent, CommonalityEntity.USERNAME);//添加操作日志
                #endregion
            }
            catch
            {
                CommonalityEntity.WriteTextLog("车辆属性管理 btnUpdate_Click()");
            }
            finally
            {
                LogInfoLoad("");
                BindHeightIDAttribute();
                this.btnUpdate.Enabled            = false;
                this.btnSave.Enabled              = true;
                this.txtCarAttribute_Name.Enabled = true;
                Empty(); // 调用清空的方法
            }
        }