예제 #1
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         //save
         ModelService modelService = new ModelService();
         if (this.Model == null)//新建
         {
             Company model = new Company();
             model.Code        = this.txtCode.Text.Trim();
             model.Name        = this.txtName.Text.Trim();
             model.CompanyType = (CompanyType)this.cmbCompanyType.SelectedItem;
             model.Actived     = this.ckbActived.Checked;
             model.Remark      = this.txtRemark.Text.Trim();
             modelService.CreateCompany(model, PermissionService.GetCurrentUser().Name);
         }
         else//修改
         {
             this.Model.Code        = this.txtCode.Text.Trim();
             this.Model.Name        = this.txtName.Text.Trim();
             this.Model.CompanyType = (CompanyType)this.cmbCompanyType.SelectedItem;
             this.Model.Actived     = this.ckbActived.Checked;
             this.Model.Remark      = this.txtRemark.Text.Trim();
             modelService.SaveCompany(this.Model, PermissionService.GetCurrentUser().Name);
         }
         //close diaglog
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         ErrorHandler.OnError(ex);
     }
 }
예제 #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //Verify
                if (string.IsNullOrEmpty(this.txtCode.Text.Trim()))
                {
                    throw new ApplicationException("编码不能为空");
                }
                if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
                {
                    throw new ApplicationException("名称不能为空");
                }

                //Save
                ModelService service = new ModelService();
                if (this._Model == null) //新建
                {
                    if (service.GetCompanyByCode(this.txtCode.Text.Trim()) != null)
                    {
                        throw new ApplicationException(string.Format("编码{0}已经被使用,请尝试其他编码。", this.txtCode.Text.Trim()));
                    }
                    Company newModel = new Company();
                    newModel.Code        = this.txtCode.Text.Trim();
                    newModel.Name        = this.txtName.Text.Trim();
                    newModel.Remark      = this.txtRemark.Text.Trim();
                    newModel.Actived     = true;
                    newModel.CompanyType = this.CompanyType;
                    service.CreateCompany(newModel, PermissionService.GetCurrentUser().Name);
                }
                else//修改
                {
                    this._Model.Code   = this.txtCode.Text.Trim();
                    this._Model.Name   = this.txtName.Text.Trim();
                    this._Model.Remark = this.txtRemark.Text.Trim();
                    service.SaveCompany(this._Model, PermissionService.GetCurrentUser().Name);
                }

                //Close dialog
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                ErrorHandler.OnError(ex);
            }
        }