Ejemplo n.º 1
0
 private void btnSaveCarRequment_Click(object sender, EventArgs e)
 {
     try
     {
         CarRequirement carRequirement = new Model.CarRequirement();
         carRequirement.CarYaoqiu = txtCarRequirement.Text;
         carRequirement.CarYongtu = txtCarPurpose.Text;
         carRequirement.Other     = txtOther.Text;
         carRequirement.GroupId   = Convert.ToInt32(dgvGroupList.CurrentRow.Cells["id"].Value.ToString());
         carRequirement.CreatTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
         try
         {
             carRequirementbll.InsertObject(carRequirement);
             MessageBox.Show("保存成功!");
         }
         catch (Exception ex)
         {
             MessageBox.Show("保存错误!");
         }
         try
         {
             dgvUserRequrement.DataSource = carRequirementbll.FindAllInfo(carRequirement.GroupId);
         }
         catch (Exception ex)
         {
             MessageBox.Show("更新列表错误!");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 public GroupRequirement(CarRequirement carRequirement, Form form)
 {
     InitializeComponent();
     this.carRequirement = carRequirement;
     this.form = form;
     txtCarYaoqiu.Text = carRequirement.CarYaoqiu;
     txtCarYongtu.Text=carRequirement.CarYongtu;
     txtOther.Text = carRequirement.Other;
 }
        private void btnSaveCarRequment_Click(object sender, EventArgs e)
        {
            try
            {
                CarRequirement carRequirement = new Model.CarRequirement();
                carRequirement.CarYaoqiu = txtCarRequirement.Text;
                carRequirement.CarYongtu = txtCarPurpose.Text;
                carRequirement.Other = txtOther.Text;
                carRequirement.GroupId = Convert.ToInt32(dgvGroupList.CurrentRow.Cells["id"].Value.ToString());
                carRequirement.CreatTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                try
                {
                    carRequirementbll.InsertObject(carRequirement);
                    MessageBox.Show("保存成功!");
                }
                catch (Exception ex)
                {

                    MessageBox.Show("保存错误!");
                }
                try
                {
                    dgvUserRequrement.DataSource = carRequirementbll.FindAllInfo(carRequirement.GroupId);
                }
                catch (Exception ex)
                {

                    MessageBox.Show("更新列表错误!");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        private void dgvUserRequrement_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvUserRequrement.Columns[e.ColumnIndex].Name == "UpdateRequirment")
            {

                CarRequirement carRequirement = new CarRequirement();
                carRequirement.Id = Convert.ToInt32(dgvUserRequrement.CurrentRow.Cells["RequirmentId"].Value.ToString());
                carRequirement.CarYaoqiu = dgvUserRequrement.CurrentRow.Cells["CarYaoqiu"].Value.ToString();
                carRequirement.CarYongtu = dgvUserRequrement.CurrentRow.Cells["CarYongtu"].Value.ToString();
                carRequirement.Other = dgvUserRequrement.CurrentRow.Cells["Other"].Value.ToString();
                 int a = dgvGroupList.CurrentRow.Index;
                 carRequirement.GroupId = Convert.ToInt32(dgvGroupList.Rows[a].Cells["id"].Value.ToString());
                GroupRequirement groupRequirement = new GroupRequirement(carRequirement, this);
                groupRequirement.Show();

            }
            if (dgvUserRequrement.Columns[e.ColumnIndex].Name == "DeleteRequirment")
            {
                CarRequirement carRequirement = new CarRequirement();
                carRequirement.Id = Convert.ToInt32(dgvUserRequrement.CurrentRow.Cells["RequirmentId"].Value.ToString());
                int a = dgvGroupList.CurrentRow.Index;
                carRequirement.GroupId = Convert.ToInt32(dgvGroupList.Rows[a].Cells["id"].Value.ToString());
                try
                {
                    carRequirementbll.DeleteCarRequirement(carRequirement.Id);
                    MessageBox.Show("删除成功");
                    dgvUserRequrement.DataSource = carRequirementbll.FindAllInfo(carRequirement.GroupId);

                }
                catch (Exception ex)
                {

                    MessageBox.Show("删除分组需求失败:" + ex.Message);
                }
            }
        }
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="carRequirement"></param>
 public void UpdateCarRequirement(CarRequirement carRequirement)
 {
     string sql = "update TB_CarRequriedment set CarYaoqiu ='" + carRequirement.CarYaoqiu + "' ,CarYongtu ='" + carRequirement.CarYongtu + "',Other ='" + carRequirement.Other + "' where id =" + carRequirement .Id+ "";
     AccessHelper.SQLExecute(sql);
 }
 /// <summary>
 /// 新增单个数据
 /// </summary>
 /// <param name="driverAbnormalNameList"></param>
 /// <returns></returns>
 public bool InsertObject(CarRequirement carRequirement)
 {
     string sql = "insert into TB_CarRequriedment (GroupId,CarYaoqiu,CarYongtu,Other) values(" +
         carRequirement.GroupId + ",'" + carRequirement.CarYaoqiu + "','" + carRequirement.CarYongtu + "','" + carRequirement.Other + "' )";
     return AccessHelper.SQLExecute(sql);
 }
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="carRequirement"></param>
 public void UpdateCarRequirement(CarRequirement carRequirement)
 {
     carRequriedmentDAL.UpdateCarRequirement(carRequirement);
 }
 /// <summary>
 /// 新增单个数据
 /// </summary>
 /// <param name="driverAbnormalNameList"></param>
 /// <returns></returns>
 public bool InsertObject(CarRequirement carRequirement)
 {
     return carRequriedmentDAL.InsertObject(carRequirement);
 }