Пример #1
0
        private void tsbSave_Click(object sender, EventArgs e)
        {
            if (MessageService.AskQuestion("你确定要保存当前界面的数据吗?", "保存"))
            {
                MapControlsToSupplier();
                bool IsTrue = false;

                if (_supplierEntity.SupplierCode == string.Empty)
                {
                    MessageService.ShowMessage("供应商代码不为空", "保存");    //名称不能为空!
                    return;
                }

                if (_supplierEntity.SupplierName == string.Empty)
                {
                    MessageService.ShowMessage("供应商名称不为空", "保存");    //名称不能为空!
                    return;
                }
                if (_supplierEntity.SupplierNickName == string.Empty)
                {
                    MessageService.ShowMessage("简称不为空", "保存");    //名称不能为空!
                    return;
                }

                if (CtrlState == ControlState.New && _supplierEntity.GetSupplierCode(_supplierEntity.SupplierName, "").Tables[0].Rows.Count > 0)
                {
                    MessageService.ShowMessage("当前供应商代码已经存在,请重新设置", "保存");      //当前名称已存在!
                    return;
                }

                if (CtrlState == ControlState.New)
                {     //状态为new
                    if (_supplierEntity.Insert())
                    { //新增成功
                        IsTrue = true;
                    }
                }
                else
                {//状态不为new
                    if (lblCode.Text.ToString() != "")
                    {
                        if (_supplierEntity.Update(lblCode.Text.ToString()))
                        {//修改成功
                            IsTrue = true;
                        }
                    }
                    else
                    {
                        MessageService.ShowMessage("请选择要修改的供应商信息", "保存");      //当前名称已存在!
                    }
                }

                if (IsTrue)
                {                                      //值为true
                    BindSupplierCode();                //数据表数据重新绑定
                    CtrlState = ControlState.ReadOnly; //状态为readonly
                }
            }
        }