Exemple #1
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("名称不能为空");
                }

                ModelService service = new ModelService();

                //Save
                if (this._Model == null) //新建
                {
                    if (service.GetStorehouseByCode(this.txtCode.Text.Trim()) != null)
                    {
                        throw new ApplicationException(string.Format("编码{0}已经被使用,请尝试其他编码。", this.txtCode.Text.Trim()));
                    }

                    Storehouse newModel = new Storehouse();
                    newModel.Code    = this.txtCode.Text.Trim();
                    newModel.Name    = this.txtName.Text.Trim();
                    newModel.Remark  = this.txtRemark.Text.Trim();
                    newModel.Actived = true;
                    service.CreateStorehouse(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.SaveStorehouse(this._Model, PermissionService.GetCurrentUser().Name);
                }

                //Close dialog
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                ErrorHandler.OnError(ex);
            }
        }
Exemple #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 modelService = new ModelService();
         if (this.Model == null)//新建
         {
             Storehouse model = new Storehouse();
             model.Code    = this.txtCode.Text.Trim();
             model.Name    = this.txtName.Text.Trim();
             model.Actived = this.ckbActived.Checked;
             model.Remark  = this.txtRemark.Text.Trim();
             modelService.CreateStorehouse(model, PermissionService.GetCurrentUser().Name);
         }
         else//修改
         {
             this.Model.Code    = this.txtCode.Text.Trim();
             this.Model.Name    = this.txtName.Text.Trim();
             this.Model.Actived = this.ckbActived.Checked;
             this.Model.Remark  = this.txtRemark.Text.Trim();
             modelService.SaveStorehouse(this.Model, PermissionService.GetCurrentUser().Name);
         }
         //close diaglog
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         ErrorHandler.OnError(ex);
     }
 }