/// <summary>
        ///
        /// </summary>
        /// <param name="cm"></param>
        /// <param name="infos"></param>
        protected void Initialize(IControlManager cm, IList <GridColumnInfo> infos)
        {
            m_cm = cm;
            if (infos != null)
            {
                foreach (GridColumnInfo info in infos)
                {
                    if (string.IsNullOrEmpty(info.DataControlType))
                    {
                        continue;
                    }

                    IDataControl dc = ControlFactory.GetDataControl(info, cm.DisplayManager.Name);
                    if (dc != null)
                    {
                        //m_dcc.Add(dc);
                        m_cm.DisplayManager.DataControls.Add(dc);

                        Control c = dc as Control;

                        this.flowLayoutPanel1.Controls.Add(c);
                    }
                }

                ArchiveDetailForm.SetDataControlDefaultValues(m_cm);
            }

            m_closeOk = false;
        }
        internal static void ShowFrom(string actionId, ISearchExpression se, bool asDetailDialog)
        {
            IDisplayManagerContainer seeForm    = null;
            ArchiveDetailForm        detailForm = null;
            ISearchManager           sm         = null;

            if (!asDetailDialog)
            {
                seeForm = (ServiceProvider.GetService <IApplication>() as IWinFormApplication).ExecuteAction(actionId) as IDisplayManagerContainer;
                if (seeForm == null)
                {
                    throw new InvalidOperationException("未能创建目标窗体!");
                }

                sm = seeForm.DisplayManager.SearchManager;
            }
            else
            {
                //detailForm = Feng.Utils.ReflectionHelper.CreateInstanceFromType(Feng.Utils.ReflectionHelper.GetTypeFromName(info.ToDetailForm)) as ArchiveDetailForm;
                //if (detailForm == null)
                //{
                //    MessageForm.ShowError("未能创建目标窗体!");
                //    return;
                //}
                //detailForm.UpdateContent();
                //findWindow = detailForm.DisplayManager.SearchManager;
            }

            if (sm == null)
            {
                throw new InvalidOperationException("未能找到目标窗体的查找窗口!");
            }

            //List<ISearchExpression> findList = new List<ISearchExpression>();
            //ISearchExpression findCondition = GetAndFindCondition(selected, 0, toColumns);
            //for (int i = 1; i < selected[0].Count; ++i)
            //{
            //    findCondition = new LogicalExpression(findCondition, GetAndFindCondition(selected, i, toColumns), LogicalOperator.Or);
            //}
            //findList.Add(findCondition);
            sm.LoadData(se, null);

            if (asDetailDialog)
            {
                if (detailForm.ControlManager.DisplayManager.Count == 0)
                {
                    ServiceProvider.GetService <IMessageBox>().ShowWarning("未能找到相应记录!");
                    return;
                }

                detailForm.ControlManager.DisplayManager.Position = 0;

                detailForm.ShowDialog();

                detailForm.Dispose();
            }
        }
Exemple #3
0
        public static void UpdateContent(IWindowControlManager cm, string gridName)
        {
            ArchiveDetailForm.ResetStatusDataControl(cm);
            ArchiveDetailForm.UpdateStatusDataControl(cm, gridName);

            //m_masterCm.DisplayManager.OnPositionChanged(System.EventArgs.Empty);

            if (cm != null)
            {
                if (cm.State == StateType.Add)
                {
                    cm.DisplayManager.DataControls.FocusFirstInsertableControl();

                    ArchiveDetailForm.SetDataControlDefaultValues(cm);
                }
                else if (cm.State == StateType.Edit)
                {
                    cm.DisplayManager.DataControls.FocusFirstEditableControl();
                }
            }
        }
Exemple #4
0
        private static bool InternalExecuteWindowMenu2(IControlManager cm, WindowMenuInfo info, Form parentForm)
        {
            object entity = cm.DisplayManager.CurrentItem;
            int    pos    = cm.DisplayManager.Position;

            //ArchiveOperationForm opForm = masterForm as ArchiveOperationForm;
            switch (info.Type)
            {
            case WindowMenuType.Add:
            {
                ArchiveOperationForm.DoAddS(cm);
            }
            break;

            case WindowMenuType.Edit:
            {
                ArchiveOperationForm.DoEditS(cm, (parentForm as IGridNamesContainer).GridNames[0]);
            }
            break;

            case WindowMenuType.Delete:
            {
                ArchiveOperationForm.DoDeleteS(cm, (parentForm as IGridNamesContainer).GridNames[0]);
            }
            break;

            case WindowMenuType.Confirm:
            {
                parentForm.ValidateChildren();
                ArchiveDetailForm.DoSaveS(cm);
            }
            break;

            case WindowMenuType.Cancel:
            {
                ArchiveDetailForm.DoCancelS(cm);
            }
            break;

            case WindowMenuType.Submit:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认提交?"))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    cm.EditCurrent();
                    se.Submitted = true;
                    cm.EndEdit();
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            se.Submitted = true;
                            rep.BeginTransaction();
                            dao.Submit(rep, entity);
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = false;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.Unsubmit:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要撤销提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认撤销提交?", "确认", true))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    cm.EditCurrent();
                    se.Submitted = false;
                    cm.EndEdit();
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            se.Submitted = false;
                            rep.BeginTransaction();
                            dao.Unsubmit(rep, entity);
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = true;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.SubmitMulti:
            {
                if (cm.DisplayManager.Count == 0)
                {
                    MessageForm.ShowError("请选择要提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认提交(当前全部)?"))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    IBatchDao batchDao = cm.Dao as IBatchDao;
                    if (batchDao != null)
                    {
                        batchDao.SuspendOperation();
                    }

                    for (int i = 0; i < cm.DisplayManager.Count; ++i)
                    {
                        cm.DisplayManager.Position = i;
                        cm.EditCurrent();
                        (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true;
                        cm.EndEdit();
                    }

                    if (batchDao != null)
                    {
                        batchDao.ResumeOperation();
                    }
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            rep.BeginTransaction();
                            for (int i = 0; i < cm.DisplayManager.Count; ++i)
                            {
                                (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true;
                                dao.Submit(rep, cm.DisplayManager.Items[i]);
                            }
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = false;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.Cancellate:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要作废的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认作废?", "确认", true))
                {
                    return(true);
                }

                ICancellateDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ICancellateDao;
                if (dao == null)
                {
                    throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ICancellateDao!");
                }
                using (IRepository rep = dao.GenerateRepository())
                {
                    try
                    {
                        rep.BeginTransaction();
                        dao.Cancellate(rep, entity);
                        rep.CommitTransaction();
                        cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ExceptionProcess.ProcessWithNotify(ex);
                    }
                }
            }
            break;

            case WindowMenuType.DaoProcess:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要操作的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否要执行" + info.Text + "?"))
                {
                    return(true);
                }

                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length != 2)
                {
                    throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam should be IDao;MethodName!");
                }
                IRepositoryDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(ss[0].Trim()) as IRepositoryDao;
                if (dao == null)
                {
                    throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam's first part should be IDao!");
                }

                using (IRepository rep = dao.GenerateRepository())
                {
                    try
                    {
                        rep.BeginTransaction();
                        Feng.Utils.ReflectionHelper.RunInstanceMethod(ss[0].Trim(), ss[1].Trim(), dao, new object[] { rep, entity });
                        rep.CommitTransaction();
                        cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ExceptionProcess.ProcessWithNotify(ex);
                    }
                }
            }
            break;

            case WindowMenuType.Select:
            {
                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length == 0)
                {
                    throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name);
                }
                ArchiveCheckForm form = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveCheckForm;
                if (ss.Length > 1)
                {
                    string exp = ss[1];
                    exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName)
                        {
                            Tuple <string, object> t = EventProcessUtils.GetDataControlValue(paramName, cm.DisplayManager);
                            if (t.Item2 == null)
                            {
                                throw new InvalidUserOperationException(string.Format("请先填写{0}!", paramName));
                            }
                            cm.DisplayManager.DataControls[t.Item1].ReadOnly = true;
                            // save controlValue to entity because readonly will not save
                            EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, t.Item1, t.Item2);

                            return(t.Item2);
                        }));
                    if (string.IsNullOrEmpty(form.DisplayManager.SearchManager.AdditionalSearchExpression))
                    {
                        form.DisplayManager.SearchManager.AdditionalSearchExpression = exp;
                    }
                    else
                    {
                        form.DisplayManager.SearchManager.AdditionalSearchExpression = "(" + form.DisplayManager.SearchManager.AdditionalSearchExpression + ") and " + exp;
                    }
                }

                int detailGridIdx = 0;
                if (ss.Length > 2)
                {
                    detailGridIdx = Feng.Utils.ConvertHelper.ToInt(ss[2]).Value;
                }
                if (form.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                {
                    IControlManager detailCm = (((IArchiveDetailFormWithDetailGrids)(parentForm as IArchiveMasterForm).ArchiveDetailForm).DetailGrids[detailGridIdx] as IArchiveGrid).ControlManager;

                    var nowList = detailCm.DisplayManager.Items;
                    foreach (object i in form.SelectedEntites)
                    {
                        if (nowList.Contains(i))
                        {
                            continue;
                        }

                        detailCm.AddNew();
                        detailCm.DisplayManager.Items[detailCm.DisplayManager.Position] = i;
                        detailCm.EndEdit();
                    }
                }
                form.Dispose();
            }
            break;

            case WindowMenuType.Input:
                throw new NotSupportedException("Not supported now!");

            case WindowMenuType.ManyToOneWindow:
            {
                if (cm.DisplayManager.CurrentItem == null)
                {
                    MessageForm.ShowInfo("无当前项,不能操作!");
                    return(true);
                }
                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length < 2)
                {
                    throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name);
                }
                ArchiveDetailForm selectForm   = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveDetailForm;
                string            propertyName = ss[1];
                object            masterEntity = EntityScript.GetPropertyValue(cm.DisplayManager.CurrentItem, propertyName);
                if (masterEntity == null)
                {
                    ArchiveOperationForm.DoAddS(selectForm.ControlManager);
                    selectForm.UpdateContent();
                    if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                    {
                        cm.EditCurrent();
                        EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, propertyName, selectForm.DisplayManager.CurrentItem);
                        cm.EndEdit();

                        cm.OnCurrentItemChanged();
                    }
                }
                else
                {
                    selectForm.ControlManager.AddNew();
                    selectForm.DisplayManager.Items[selectForm.DisplayManager.Position] = masterEntity;
                    selectForm.ControlManager.EndEdit(false);
                    ArchiveOperationForm.DoEditS(selectForm.ControlManager, selectForm.GridName);
                    selectForm.UpdateContent();

                    if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                    {
                        ((parentForm as IArchiveMasterForm).MasterGrid as IBoundGrid).ReloadData();
                    }
                }
                selectForm.Dispose();
            }
            break;

            default:
                return(false);
            }
            return(true);
        }