示例#1
0
        public void OpenViewHandler(object sender, OpenViewEventArgs e)
        {
            Epi.View view = mCurrentProject.Views.GetViewById(e.ViewId);
            if (this.mCurrentView.Count == 0)
            {
                this.mCurrentView.Push(new RunTimeView(e.EnterCheckCodeInterface, view));
            }
            else
            {
                if (
                    this.mCurrentProject.FilePath != view.GetProject().FilePath ||
                    view.ParentView == null ||
                    view.ParentView.Name != this.mCurrentView.Peek().View.Name
                    )
                {
                    while (this.mCurrentView.Count > 0)
                    {
                        this.mCurrentView.Pop().CloseView(this, new RunCheckCodeEventArgs(EventActionEnum.CloseView, ""));
                    }

                    this.mCurrentView.Push(new RunTimeView(e.EnterCheckCodeInterface, view));
                }
                else
                {
                    RunTimeView runTimeView           = this.mCurrentView.Peek();
                    int         CurrentRecordId       = runTimeView.View.CurrentRecordId;
                    string      CurrentGlobalRecordId = runTimeView.View.CurrentGlobalRecordId;

                    EpiInfo.Plugin.IScope scope = runTimeView.EpiInterpreter.Context.GetNewScope(runTimeView.View.Name, runTimeView.EpiInterpreter.Context.Scope);

                    foreach (Epi.Fields.Field field in runTimeView.View.Fields)
                    {
                        if (field is EpiInfo.Plugin.IVariable)
                        {
                            PluginVariable pluginVariable = new PluginVariable();
                            pluginVariable.VariableScope = EpiInfo.Plugin.VariableScope.Standard;
                            pluginVariable.Name          = field.Name;
                            pluginVariable.DataType      = ((EpiInfo.Plugin.IVariable)field).DataType;

                            if (field is Epi.Fields.CheckBoxField || field is Epi.Fields.YesNoField)
                            {
                                if (((Epi.Fields.IDataField)field).CurrentRecordValueString == "1")
                                {
                                    pluginVariable.Expression = "true";
                                }
                                else if (((Epi.Fields.IDataField)field).CurrentRecordValueString == "0")
                                {
                                    pluginVariable.Expression = "false";
                                }
                                else
                                {
                                    pluginVariable.Expression = null;
                                }
                            }
                            else
                            {
                                pluginVariable.Expression = ((Epi.Fields.IDataField)field).CurrentRecordValueString;
                            }

                            scope.Define(pluginVariable);
                        }
                    }

                    this.mCurrentView.Push(new RunTimeView(e.EnterCheckCodeInterface, view, CurrentRecordId, CurrentGlobalRecordId, scope));
                }
            }

            this.mCurrentView.Peek().OpenViewHandler(sender, e);
        }