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.GetGoodsCategoryByCode(this.txtCode.Text.Trim()) != null) { throw new ApplicationException(string.Format("编码{0}已经被使用,请尝试其他编码。", this.txtCode.Text.Trim())); } GoodsCategory newModel = new GoodsCategory(); newModel.Code = this.txtCode.Text.Trim(); newModel.Name = this.txtName.Text.Trim(); newModel.Remark = this.txtRemark.Text.Trim(); newModel.Actived = true; service.CreateGoodsCategory(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.SaveGoodsCategory(this._Model, PermissionService.GetCurrentUser().Name); } //Close dialog this.DialogResult = DialogResult.OK; } catch (Exception ex) { ErrorHandler.OnError(ex); } }