Example #1
0
 public override void AfterPost(object senter, EventArgs e)
 {
     if (m_RelatedLists != null)
     {
         foreach (string name in m_RelatedLists)
         {
             BaseFormManager.RefreshList(name);
         }
     }
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="parameters">
        /// The predefined order of parameters:
        /// 0 - key of onject to edit
        /// 1- instance of IObject to edit
        /// 2 - instance of IBaseListPanel
        /// 3 - startup parameters
        /// </param>
        /// <param name="actionType"></param>
        /// <param name="readOnly"></param>
        public override IApplicationForm Edit(object key, List <object> parameters, ActionTypes actionType, bool readOnly)
        {
            IObject bo = null;

            if ((parameters != null) && (parameters.Count > 1) && (parameters[1] is IObject))
            {
                bo = (IObject)parameters[1];
            }
            Dictionary <string, object> startupParams = null;

            if ((parameters != null) && (parameters.Count > 3) && (parameters[3] is Dictionary <string, object>))
            {
                startupParams = parameters[3] as Dictionary <string, object>;
            }
            var detailPanelName = GetDetailFormName(bo);

            if (Utils.IsEmpty(detailPanelName))
            {
                ErrorForm.ShowMessage("msgNoDetails", "msgNoDetails");
                return(null);
            }
            object detailPanel;

            using (new WaitDialog())
            {
                detailPanel = ClassLoader.LoadClass(detailPanelName);
                Dbg.Assert(detailPanel != null, "class {0} can't be loaded", detailPanelName);
                Dbg.Assert(detailPanel is IApplicationForm,
                           "detail form  {0} doesn't implement IApplicationFrom interface",
                           detailPanelName);
                InitDetailForm(detailPanel);
                if (detailPanel is IBasePanel)
                {
                    //((IBasePanel)detailPanel).ReadOnly = readOnly;

                    var meta        = ObjectAccessor.MetaInterface(BusinessObject.GetType());
                    var foundAction =
                        meta.Actions.Find(
                            item =>
                            ((item.ActionType == ActionTypes.View) || (item.ActionType == ActionTypes.Edit)) &&
                            (item.PanelType == ActionsPanelType.Top));
                    if (foundAction != null)
                    {
                        using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                        {
                            var childObject = foundAction.RunAction(manager, null as IObject, new List <object> {
                                key
                            });
                            if (childObject.result)
                            {
                                if (readOnly)
                                {
                                    BaseFormManager.ShowNormal_ReadOnly(detailPanel as IApplicationForm, childObject.obj, startupParams);
                                }
                                else
                                {
                                    BaseFormManager.ShowNormal(detailPanel as IApplicationForm, childObject.obj, startupParams);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (Utils.IsEmpty(key))
                    {
                        key = null;
                    }
                    if (readOnly)
                    {
                        BaseFormManager.ShowNormal_ReadOnly(detailPanel as IApplicationForm, ref key, startupParams);
                    }
                    else
                    {
                        BaseFormManager.ShowNormal(detailPanel as IApplicationForm, ref key, startupParams);
                    }
                }
            }
            return(detailPanel as IApplicationForm);
        }
Example #3
0
        /// <summary>
        /// </summary>
        /// <param name="key"></param>
        /// <param name="parameters"></param>
        /// <param name="actionType"></param>
        /// <param name="readOnly"></param>
        public override IApplicationForm Edit(object key, List <object> parameters, ActionTypes actionType, bool readOnly)
        {
            //TODO переписать метод более понятным
            IObject processedBusinessObject = null;
            var     meta = ObjectAccessor.MetaInterface(BusinessObject.GetType());

            if (key == null)
            {
                ActionMetaItem createAction = meta.Actions.Find(item => item.ActionType == ActionTypes.Create && item.PanelType == ActionsPanelType.Group);
                if (createAction == null)
                {
                    return(this);
                }

                using (var manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                {
                    var ret = createAction.RunAction(manager, m_DataSourceParent, parameters);
                    if (ret.result)
                    {
                        processedBusinessObject = ret.obj;
                    }
                }
                if (processedBusinessObject != null)
                {
                    SetEnvironment(processedBusinessObject);
                    if (InlineMode == InlineMode.UseCreateButton)
                    {
                        DataSource.Add(processedBusinessObject);
                        for (var i = Grid.GridView.RowCount - 1; i >= 0; i--)
                        {
                            var row = Grid.GridView.GetRow(i);
                            if (row.Equals(processedBusinessObject))
                            {
                                Grid.GridView.FocusedRowHandle = i;
                            }
                        }
                    }
                }
            }
            else
            {
                if (InlineMode == InlineMode.None)
                {
                    ActionMetaItem editAction = meta.Actions.Find(
                        item => item.ActionType == actionType && item.PanelType == ActionsPanelType.Group);
                    if (editAction == null)
                    {
                        return(this);
                    }

                    using (var manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                    {
                        processedBusinessObject = editAction.IsCreate
                            ? editAction.RunAction(manager, null as IObject, new List <object> {
                            key
                        }).obj
                                : FocusedItem;
                    }
                }
            }

            if ((InlineMode == InlineMode.None) && (processedBusinessObject != null))
            {
                using (var manager = CreateDbManagerProxy())
                {
                    var clone = processedBusinessObject.CloneWithSetup(manager);

                    #region В отдельном окне

                    //для нового элемента FocusedItem == null
                    var detailPanelName = GetDetailFormName(FocusedItem ?? BusinessObject);
                    if (Utils.IsEmpty(detailPanelName))
                    {
                        ErrorForm.ShowMessage("msgNoDetails", "msgNoDetails");
                        return(this);
                    }
                    var detailPanel = ClassLoader.LoadClass(detailPanelName);
                    Dbg.Assert(detailPanel != null, "class {0} can't be loaded", detailPanelName);
                    Dbg.Assert(detailPanel is IApplicationForm,
                               "detail form  {0} doesn't implement IApplicationFrom interface",
                               detailPanelName);
                    if (detailPanel is IBasePanel)
                    {
                        var appForm = detailPanel as IApplicationForm;
                        if (readOnly)
                        {
                            clone.ReadOnly = true;
                            (detailPanel as IBasePanel).ReadOnly = true;
                        }

                        /*
                         * var layout = GetLayout() as LayoutEmpty;
                         * if (layout != null)
                         * {
                         *  var cancel = false;
                         *  layout.OnBeforeActionExecutingRaised(this, createAction ?? editAction, clone, ref cancel);
                         *  if (cancel) return this;
                         * }
                         */
                        BaseFormManager.ShowModal(appForm, clone);
                        SetEnvironment(clone);
                        //определяем действие, по которому закрылась форма
                        if (appForm != null)
                        {
                            //если Ok, то заменяем клоном исходный объект
                            LastExecutedActionInternal = appForm.GetLastExecutedAction();
                            if (LastExecutedActionInternal != null)
                            {
                                if (LastExecutedActionInternal.ActionType.Equals(ActionTypes.Ok) ||
                                    LastExecutedActionInternal.ActionType.Equals(ActionTypes.Close) ||
                                    (LastExecutedActionInternal.ActionType.Equals(ActionTypes.Action) && LastExecutedActionInternal.IsNeedClose)
                                    )
                                {
                                    var index = DataSource.IndexOf(processedBusinessObject);
                                    if (index < 0)
                                    {
                                        clone.DeepSetChange();
                                        DataSource.Add(clone);
                                    }
                                    else
                                    {
                                        DataSource.ReplaceAndSetChange(processedBusinessObject as T, clone as T);
                                    }
                                    SetObjects(clone);

                                    Refresh();
                                }
                                else
                                {
                                    //видимо, происходит отмена. Надо дать возможность удалить временные объекты.
                                    DeleteTempObjects(processedBusinessObject);
                                }
                            }
                            else
                            {
                                //видимо, происходит отмена. Надо дать возможность удалить временные объекты.
                                DeleteTempObjects(processedBusinessObject);
                            }
                        }
                    }

                    #endregion
                }
            }
            return(this);
        }