Пример #1
0
        /// <summary>
        /// 通用技术要求添加/修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGeneralRequirement_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (cobTypeName.SelectedIndex == -1)
            {
                MessageBox.Show("请选择项目类型", "验证信息");
                cobTypeName.Focus();
                return;
            }
            if (cobRiskLevel.SelectedIndex == -1)
            {
                MessageBox.Show("请选择项目等级", "验证信息");
                cobANSULSystem.Focus();
                return;
            }
            if (cobInputPower.SelectedIndex == -1)
            {
                MessageBox.Show("请选择电制", "验证信息");
                cobInputPower.Focus();
                return;
            }
            if (cobMARVEL.SelectedIndex == -1)
            {
                MessageBox.Show("请选择MARVEL", "验证信息");
                cobMARVEL.Focus();
                return;
            }
            if (cobANSULPrepipe.SelectedIndex == -1)
            {
                MessageBox.Show("请选择ANSUL预埋", "验证信息");
                cobANSULPrepipe.Focus();
                return;
            }
            if (cobANSULSystem.SelectedIndex == -1)
            {
                MessageBox.Show("请选择ANSUL系统", "验证信息");
                cobANSULSystem.Focus();
                return;
            }

            #endregion

            if (txtGeneralRequirementId.Text.Trim().Length == 0)
            {
                //提交添加
                //封装对象
                GeneralRequirement objGeneralRequirement = new GeneralRequirement()
                {
                    ProjectId    = Convert.ToInt32(txtProjectId.Text.Trim()),
                    TypeId       = Convert.ToInt32(cobTypeName.SelectedValue),
                    InputPower   = cobInputPower.Text,
                    MARVEL       = cobMARVEL.Text,
                    ANSULPrePipe = cobANSULPrepipe.Text,
                    ANSULSystem  = cobANSULSystem.Text,
                    RiskLevel    = Convert.ToInt32(cobRiskLevel.Text)
                };
                //提交添加
                try
                {
                    int GeneralRequirementId = objRequirementService.AddGeneralRequirement(objGeneralRequirement);
                    if (GeneralRequirementId > 1)
                    {
                        //提示添加成功
                        MessageBox.Show("通用技术要求添加成功", "提示信息");
                        //刷新显示
                        btnGeneralRequirement.Text   = "修改通用技术要求";
                        txtGeneralRequirementId.Text = GeneralRequirementId.ToString();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                //封装对象
                GeneralRequirement objGeneralRequirement = new GeneralRequirement()
                {
                    GeneralRequirementId = Convert.ToInt32(txtGeneralRequirementId.Text.Trim()),
                    ProjectId            = Convert.ToInt32(txtProjectId.Text.Trim()),
                    TypeId       = Convert.ToInt32(cobTypeName.SelectedValue),
                    InputPower   = cobInputPower.Text,
                    MARVEL       = cobMARVEL.Text,
                    ANSULPrePipe = cobANSULPrepipe.Text,
                    ANSULSystem  = cobANSULSystem.Text,
                    RiskLevel    = Convert.ToInt32(cobRiskLevel.Text)
                };
                //提交修改
                //调用后台方法修改对象
                try
                {
                    if (objRequirementService.EditGeneralRequirement(objGeneralRequirement) == 1)
                    {
                        MessageBox.Show("修改通用技术要求成功!", "提示信息");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }