private int Save()
        {
            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                int index = 0;
                foreach (TreeListNode node in this.trvLstMain.Nodes)
                {
                    int    id   = (int)node.GetValue(_TreeListHoster.TreeViewCfg.KeyFieldName);
                    string name = (string)node.GetValue(_TreeListHoster.TreeViewCfg.DisplayFieldName);//调试用

                    IList dataSource = _BindingSource.DataSource as IList;
                    foreach (object data in dataSource)
                    {
                        int dataId = (int)MB.Util.MyReflection.Instance.InvokePropertyForGet(data, _TreeListHoster.TreeViewCfg.KeyFieldName);
                        if (id == dataId)
                        {
                            MB.Util.Model.EntityState entityState = MB.WinBase.UIDataEditHelper.Instance.GetEntityState(data);
                            if (entityState == MB.Util.Model.EntityState.Persistent)
                            {
                                MB.WinBase.UIDataEditHelper.Instance.SetEntityState(data, MB.Util.Model.EntityState.Modified);
                            }

                            MB.Util.MyReflection.Instance.InvokePropertyForSet(data, _TreeListHoster.TreeViewCfg.OrderFieldName, index);
                            _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, data, false, (string[])null);
                            index++;
                            break;
                        }
                    }
                }
                re = _ClientRuleObject.Flush(commObject);
            }
            catch (Exception ex) {
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex);
            }
            finally {
                try {
                    commObject.Close();
                }
                catch { }
            }
            if (re > 0)
            {
                try {
                    _IsMainTreeNeedRefreshed = true;
                    MB.WinBase.MessageBoxEx.Show("数据保存成功");
                }
                catch (Exception ex) {
                    MB.Util.TraceEx.Write(ex.Message);
                    throw new MB.Util.APPException("数据保存成功,但本地数据更新有误,请关闭窗口手动完成刷新", MB.Util.APPMessageType.DisplayToUser);
                }
            }
            return(re);
        }
示例#2
0
        /// <summary>
        ///  对象数据保存。
        /// </summary>
        /// <param name="editEntity"></param>
        /// <param name="propertys"></param>
        /// <returns></returns>
        protected virtual int ObjectDataSave(object editEntity, string[] propertys)
        {
            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                if (!_DataValidated.DataValidated(this.ClientRuleObject as IClientRule, _EditColumnCtlBinding, _EditBindingSource.Current))
                {
                    throw new MB.Util.APPException("单据主体数据检验不成功,请检查", Util.APPMessageType.DisplayToUser);
                }
                _EditBindingSource.EndEditNoRaiseEvent();
                _BeforeSaveDetailEntityCache.RaiseBeforeDataSave();

                //判断并追加登录用户的相关信息( 实体数据的登录用户操作信息一般只在主表中存在 )
                if (propertys == null || propertys.Length == 0)
                {
                    MB.WinBase.UIDataEditHelper.Instance.AppendLoginUserInfo(editEntity);
                }
                //增加主表实体对象
                _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, editEntity, false, propertys);
                //增加明细数据
                foreach (KeyValuePair <int, object> detailInfo in _BeforeSaveDetailEntityCache)
                {
                    bool isDelete = false;
                    if (MB.WinBase.UIDataEditHelper.Instance.CheckExistsEntityState(detailInfo.Value))
                    {
                        if (MB.WinBase.UIDataEditHelper.Instance.GetEntityState(detailInfo.Value) == MB.Util.Model.EntityState.Deleted)
                        {
                            isDelete = true;
                        }
                    }
                    _ClientRuleObject.AddToCache(commObject, detailInfo.Key, detailInfo.Value, isDelete, null);
                }
                re = _ClientRuleObject.Flush(commObject);
            }
            catch (Exception ex) {
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex);
            }
            finally {
                try {
                    commObject.Close();
                }
                catch { }
            }
            if (re > 0)
            {
                try {
                    ////刷新当前编辑的对象。
                    AcceptDataChanged(true);
                }
                catch (Exception x) {
                    MB.WinBase.MessageBoxEx.Show("对象数据库保存已经成功,但本地化更新时出错,请关闭窗口后重新刷新!");
                    MB.Util.TraceEx.Write("对象数据库保存已经成功,但本地化更新时出错." + x.Message);
                    return(0);
                }
            }
            else
            {
                MB.WinBase.MessageBoxEx.Show("对象数据库保存不成功,请重试");
            }
            return(re);
        }
        public virtual int Delete()
        {
            if (_BindingSource.Current == null)
            {
                return(0);
            }
            if (this.GetViewDataNavigator().FocusedRowHandle < 0)
            {
                return(0);
            }

            if (MB.WinBase.UIDataEditHelper.Instance.CheckExistsDocState(_BindingSource.Current))
            {
                var docState = MB.WinBase.UIDataEditHelper.Instance.GetEntityDocState(_BindingSource.Current);
                if (docState != MB.Util.Model.DocState.Progress)
                {
                    MB.WinBase.MessageBoxEx.Show("当前单据已在提交状态,不能进行删除操作!");
                    return(0);
                }
            }
            //add by aifang 增加逻辑:如果数据未提交保存,直接进行删除 begin
            if (MB.WinBase.UIDataEditHelper.Instance.CheckExistsEntityState(_BindingSource.Current))
            {
                var entityState = MB.WinBase.UIDataEditHelper.Instance.GetEntityState(_BindingSource.Current);
                if (entityState == Util.Model.EntityState.New)
                {
                    MB.WinBase.UIDataEditHelper.Instance.SetEntityState(_BindingSource.Current, Util.Model.EntityState.Deleted);
                    this.GetViewDataNavigator().RemoveFocusedRow(_BindingSource);
                    _BindingSource.EndEdit();
                    return(0);
                }
            }
            //end

            DialogResult dre = MB.WinBase.MessageBoxEx.Question("删除操作不可逆,是否继续?");

            if (dre != DialogResult.Yes)
            {
                return(0);
            }

            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, _BindingSource.Current, true, null);

                re = _ClientRuleObject.Flush(commObject);

                commObject.Close();
            }
            catch (Exception ex) {
                try {
                    commObject.Close();
                }
                catch { }

                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex, "数据删除出错,请重试!");
            }
            if (re > 0)
            {
                // _BindingSource.RemoveCurrent();
                this.GetViewDataNavigator().RemoveFocusedRow(_BindingSource);
                _BindingSource.EndEdit();
            }
            return(0);
        }