Exemplo n.º 1
0
        /// <summary>
        /// Ignores mappings, displays first 4 columns in a classic NavTable
        /// or the first display column in a NavTree if a self-referential FK is present.
        /// navtable includes edit and delete action buttons, second control - insert button
        /// </summary>
        /// <param name="tableName">string</param>
        /// <returns>Panel</returns>
        public Panel proposeSummaryPanel(string tableName)
        {
            DataColumnCollection cols = stats.ColumnTypes[tableName];
            List <FK>            FKs  = stats.FKs[tableName];
            // a table with more than one self-referential FK is improbable
            List <FK>     selfRefs  = new List <FK>(from FK in FKs where FK.myTable == FK.refTable select FK as FK);
            List <string> PKCols    = stats.PKs[tableName];
            FK            selfRefFK = null;

            // strict hierarchy structure validation - not nice => no Tree
            if (hierarchies.Contains(tableName))
            {
                selfRefFK = selfRefs.First();
            }
            List <string> displayColOrder = stats.ColumnsToDisplay[tableName];

            Control   control;
            DataTable controlTab = new DataTable();

            List <Control> Controls = new List <Control>();

            if (selfRefFK != null)  // this will be a NavTree
            {
                Panel res = new Panel(tableName, 0, PanelTypes.NavTree, new List <Panel>(), new List <IField>(),
                                      new List <Control>(), PKCols);
                res.displayAccessRights = 1;
                control = new TreeControl(0, new HierarchyNavTable(), PKCols[0], selfRefFK.myColumn,
                                          displayColOrder[0], new List <UserAction> {
                    UserAction.View
                });
                Controls.Add(control);
                control = new Control(0, null, PKCols, UserAction.Insert);
                Controls.Add(control);

                res.AddControls(Controls);
                return(res);
            }
            else
            {       // a simple NavTable
                Panel res = new Panel(tableName, 0, PanelTypes.NavTable, new List <Panel>(), new List <IField>(),
                                      new List <Control>(), PKCols);
                res.displayAccessRights = 1;
                List <UserAction> actions        = new List <UserAction>(new UserAction[] { UserAction.View, UserAction.Delete });
                List <string>     displayColumns = displayColOrder.GetRange(0, Math.Min(displayColOrder.Count, 4));
                List <FK>         neededFKs      = (from FK fk in FKs where displayColumns.Contains(fk.myColumn) select fk).ToList();

                control = new NavTableControl(0, null, PKCols, neededFKs, actions);

                control.displayColumns = displayColumns;
                Controls.Add(control);
                control = new Control(0, null, PKCols, UserAction.Insert);
                Controls.Add(control);

                res.AddControls(Controls);
                return(res);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// deserializes a specific panel with controls, fields and child panels
        /// </summary>
        /// <param name="ds">the dataset from FullProjectLoad</param>
        private Panel DataSet2Panel(DataSet ds, int panelId)
        {
            List <IField>  fields   = DataSet2PanelFields(ds, panelId);
            List <Control> controls = DataSet2PanelControls(ds, panelId);
            DataRow        panelRow = ds.Tables["panels"].AsEnumerable().Where(x => (Int32)x["id_panel"] == panelId).First();
            Panel          res      = DeserializePanel(panelRow["content"] as string);

            res.panelId = panelId;

            List <Panel> children = new List <Panel>();

            DataRow[] childRows = panelRow.GetChildRows(CC.SYSDRIVER_FK_PANEL_PARENT);
            foreach (DataRow childRow in childRows)
            {
                children.Add(DataSet2Panel(ds, (int)(childRow["id_panel"])));
            }

            res.AddChildren(children);
            res.AddFields(fields);
            res.AddControls(controls);
            return(res);
        }
Exemplo n.º 3
0
        /// <summary>
        /// get both edit and summary panel proposal for editable tables
        /// and create base Panel with MenuDrop field for each editable table
        /// with 2 children pointing to insert action and summary table view;
        /// also saves it to systemDB, because it needs the panelIDs to
        /// build navigation upon them.
        /// The proposal should always pass proposal check.
        ///
        /// Presenter must have sent a request banning others from initiating a proposal
        /// the whole proposal happens in a transaction
        /// </summary>
        /// <returns>Panel</returns>
        public Panel propose()
        {
            systemDriver.BeginTransaction();

            List <string> tables       = stats.Tables;
            List <Panel>  baseChildren = new List <Panel>();

            HierarchyNavTable basePanelHierarchy = new HierarchyNavTable();

            foreach (string tableName in tables)
            {
                if (excludedTables.Contains(tableName))
                {
                    continue;
                }
                //Notice(this, new ArchitectNoticeEventArgs("Exploring table \"" + tableName + "\"..."));
                Panel editPanel = ProposeForTable(tableName);
                if (editPanel != null)
                {      // editable panel available - add summary panel
                    Panel summaryPanel = proposeSummaryPanel(tableName);

                    foreach (Control c in summaryPanel.controls)        // simlified for now
                    {
                        c.targetPanel = editPanel;
                    }
                    foreach (Control c in editPanel.controls)
                    {
                        c.targetPanel = summaryPanel;
                    }

                    editPanel.panelName    = "Editation of " + tableName;
                    summaryPanel.panelName = "Summary of " + tableName;
                    baseChildren.Add(editPanel);
                    baseChildren.Add(summaryPanel);

                    HierarchyRow tableRow        = (HierarchyRow)basePanelHierarchy.NewRow();
                    HierarchyRow tableEditRow    = (HierarchyRow)basePanelHierarchy.NewRow();
                    HierarchyRow tableSummaryRow = (HierarchyRow)basePanelHierarchy.NewRow();
                    tableRow.ParentId        = null;
                    tableSummaryRow.ParentId = tableRow.Id;
                    tableEditRow.ParentId    = tableRow.Id;
                    tableRow.NavId           = null;

                    tableRow.Caption        = tableName;
                    tableEditRow.Caption    = "Add";
                    tableSummaryRow.Caption = "Browse";

                    basePanelHierarchy.Add(tableRow);
                    basePanelHierarchy.Add(tableEditRow);
                    basePanelHierarchy.Add(tableSummaryRow);
                }
            }

            Panel basePanel = new Panel(null, 0, PanelTypes.MenuDrop,
                                        baseChildren, null, null, null);

            basePanel.panelName      = "Main page";
            basePanel.isBaseNavPanel = true;
            systemDriver.AddPanel(basePanel);

            TreeControl basePanelTreeControl = new TreeControl(basePanel.panelId, basePanelHierarchy,
                                                               "Id", "ParentId", "Caption", UserAction.View);

            basePanelTreeControl.navThroughPanels = true;

            // navId for menu items
            for (int i = 0; i < basePanel.children.Count / 2; i++) // ad hoc beyond sense
            {
                basePanelHierarchy.Rows[i * 3]["NavId"]     = basePanel.children[2 * i].panelId;
                basePanelHierarchy.Rows[i * 3 + 1]["NavId"] = basePanel.children[2 * i].panelId;
                basePanelHierarchy.Rows[i * 3 + 2]["NavId"] = basePanel.children[2 * i + 1].panelId;
            }


            List <Control> addedList = new List <Control>();

            addedList.Add(basePanelTreeControl);
            basePanel.AddControls(addedList);
            systemDriver.AddControl(basePanelTreeControl);

            systemDriver.IncreaseVersionNumber();
            systemDriver.CommitTransaction();
            return(basePanel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Ignores mappings, displays first 4 columns in a classic NavTable 
        /// or the first display column in a NavTree if a self-referential FK is present.
        /// navtable includes edit and delete action buttons, second control - insert button
        /// </summary>
        /// <param name="tableName">string</param>
        /// <returns>Panel</returns>
        public Panel proposeSummaryPanel(string tableName)
        {
            DataColumnCollection cols = stats.ColumnTypes[tableName];
            List<FK> FKs = stats.FKs[tableName];
            // a table with more than one self-referential FK is improbable
            List<FK> selfRefs = new List<FK>(from FK in FKs where FK.myTable == FK.refTable select FK as FK);
            List<string> PKCols = stats.PKs[tableName];
            FK selfRefFK = null;
            // strict hierarchy structure validation - not nice => no Tree
            if (hierarchies.Contains(tableName))
                selfRefFK = selfRefs.First();
            List<string> displayColOrder = stats.ColumnsToDisplay[tableName];

            Control control;
            DataTable controlTab = new DataTable();

            List<Control> Controls = new List<Control>();
            if (selfRefFK != null)  // this will be a NavTree
            {
                Panel res = new Panel(tableName, 0, PanelTypes.NavTree, new List<Panel>(), new List<IField>(),
                    new List<Control>(), PKCols);
                res.displayAccessRights = 1;
                control = new TreeControl(0, new HierarchyNavTable(), PKCols[0], selfRefFK.myColumn,
                     displayColOrder[0], new List<UserAction> { UserAction.View });
                Controls.Add(control);
                control = new Control(0, null, PKCols, UserAction.Insert);
                Controls.Add(control);

                res.AddControls(Controls);
                return res;
            }
            else
            {       // a simple NavTable
                Panel res = new Panel(tableName, 0, PanelTypes.NavTable, new List<Panel>(), new List<IField>(),
                    new List<Control>(), PKCols);
                res.displayAccessRights = 1;
                List<UserAction> actions = new List<UserAction>(new UserAction[] { UserAction.View, UserAction.Delete });
                List<string> displayColumns = displayColOrder.GetRange(0, Math.Min(displayColOrder.Count, 4));
                List<FK> neededFKs = (from FK fk in FKs where displayColumns.Contains(fk.myColumn) select fk).ToList();

                control = new NavTableControl(0, null, PKCols, neededFKs, actions);

                control.displayColumns = displayColumns;
                Controls.Add(control);
                control = new Control(0, null, PKCols, UserAction.Insert);
                Controls.Add(control);

                res.AddControls(Controls);
                return res;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// get both edit and summary panel proposal for editable tables 
        /// and create base Panel with MenuDrop field for each editable table
        /// with 2 children pointing to insert action and summary table view;
        /// also saves it to systemDB, because it needs the panelIDs to 
        /// build navigation upon them.
        /// The proposal should always pass proposal check.
        /// 
        /// Presenter must have sent a request banning others from initiating a proposal
        /// the whole proposal happens in a transaction
        /// </summary>
        /// <returns>Panel</returns>
        public Panel propose()
        {
            systemDriver.BeginTransaction();

            List<string> tables = stats.Tables;
            List<Panel> baseChildren = new List<Panel>();

            HierarchyNavTable basePanelHierarchy = new HierarchyNavTable();
            foreach (string tableName in tables)
            {
                if (excludedTables.Contains(tableName)) continue;
                //Notice(this, new ArchitectNoticeEventArgs("Exploring table \"" + tableName + "\"..."));
                Panel editPanel = ProposeForTable(tableName);
                if (editPanel != null)
                {      // editable panel available - add summary panel
                    Panel summaryPanel = proposeSummaryPanel(tableName);

                    foreach (Control c in summaryPanel.controls)        // simlified for now
                        c.targetPanel = editPanel;
                    foreach (Control c in editPanel.controls)
                        c.targetPanel = summaryPanel;

                    editPanel.panelName = "Editation of " + tableName;
                    summaryPanel.panelName = "Summary of " + tableName;
                    baseChildren.Add(editPanel);
                    baseChildren.Add(summaryPanel);

                    HierarchyRow tableRow = (HierarchyRow)basePanelHierarchy.NewRow();
                    HierarchyRow tableEditRow = (HierarchyRow)basePanelHierarchy.NewRow();
                    HierarchyRow tableSummaryRow = (HierarchyRow)basePanelHierarchy.NewRow();
                    tableRow.ParentId = null;
                    tableSummaryRow.ParentId = tableRow.Id;
                    tableEditRow.ParentId = tableRow.Id;
                    tableRow.NavId = null;

                    tableRow.Caption = tableName;
                    tableEditRow.Caption = "Add";
                    tableSummaryRow.Caption = "Browse";

                    basePanelHierarchy.Add(tableRow);
                    basePanelHierarchy.Add(tableEditRow);
                    basePanelHierarchy.Add(tableSummaryRow);
                }
            }

            Panel basePanel = new Panel(null, 0, PanelTypes.MenuDrop,
                baseChildren, null, null, null);
            basePanel.panelName = "Main page";
            basePanel.isBaseNavPanel = true;
            systemDriver.AddPanel(basePanel);

            TreeControl basePanelTreeControl = new TreeControl(basePanel.panelId, basePanelHierarchy,
                "Id", "ParentId", "Caption", UserAction.View);
            basePanelTreeControl.navThroughPanels = true;

            // navId for menu items
            for (int i = 0; i < basePanel.children.Count / 2; i++) // ad hoc beyond sense
            {
                basePanelHierarchy.Rows[i * 3]["NavId"] = basePanel.children[2 * i].panelId;
                basePanelHierarchy.Rows[i * 3 + 1]["NavId"] = basePanel.children[2 * i].panelId;
                basePanelHierarchy.Rows[i * 3 + 2]["NavId"] = basePanel.children[2 * i + 1].panelId;
            }

            List<Control> addedList = new List<Control>();
            addedList.Add(basePanelTreeControl);
            basePanel.AddControls(addedList);
            systemDriver.AddControl(basePanelTreeControl);

            systemDriver.IncreaseVersionNumber();
            systemDriver.CommitTransaction();
            return basePanel;
        }
Exemplo n.º 6
0
        /// <summary>
        /// get both edit and summary panel proposal for editable tables
        /// and create base Panel with MenuDrop field for each editable table
        /// with 2 children pointing to insert action and summary table view;
        /// also saves it to systemDB, because it needs the panelIDs to
        /// build navigation upon them.
        /// The proposal should always pass proposal check.
        /// </summary>
        /// <returns>IPanel</returns>
        public IPanel propose()
        {
            Notice(this, new ArchitectNoticeEventArgs("Starting proposal..."));
            if (systemDriver.ProposalExists())
            {
                Dictionary <string, object> options = new Dictionary <string, object>();
                options.Add("Repropose", true);
                options.Add("Edit", false);
                Question(this, new ArchitectQuestionEventArgs("A proposal already exists for this project. \n" +
                                                              "Do you want to remove it and propose again or edit the existing proposal? (REMOVE)", options));
                //bool repropose = (bool)questionAnswer;
                bool repropose = true;
                if (!repropose)
                {
                    return(systemDriver.getArchitectureInPanel());
                }
                systemDriver.ClearProposal();
            }

            List <string> tables       = stats.TableList();
            List <IPanel> baseChildren = new List <IPanel>();

            foreach (string tableName in tables)
            {
                Notice(this, new ArchitectNoticeEventArgs("Exploring table \"" + tableName + "\"..."));
                IPanel editPanel = proposeForTable(tableName);
                if (editPanel != null)
                {      // editable panel available - add summary panel
                    Notice(this, new ArchitectNoticeEventArgs("Table \"" + tableName + "\" will be editable."));
                    IPanel summaryPanel = proposeSummaryPanel(tableName);
                    Notice(this, new ArchitectNoticeEventArgs("Proposed summary navigation panel for table \"" + tableName + "\"."));
                    baseChildren.Add(editPanel);
                    baseChildren.Add(summaryPanel);
                }
                else
                {
                    Notice(this, new ArchitectNoticeEventArgs("Table \"" + tableName + "\" is probably NOT suitable for direct management."));
                }
            }
            Notice(this, new ArchitectNoticeEventArgs("Creating navigation base with " +
                                                      baseChildren.Count + " options (2 per table)."));
            IPanel basePanel = new Panel(null, 0, panelTypeIdMp[PanelTypes.MenuDrop], PanelTypes.MenuDrop.ToString(),
                                         baseChildren, null, null, null);

            Notice(this, new ArchitectNoticeEventArgs("Updating database..."));
            systemDriver.addPanel(basePanel);
            DataTable basePanelTreeControlData = systemDriver.fetchBaseNavControlTable();
            IControl  basePanelTreeControl     = new TreeControl(basePanelTreeControlData, "id_panel", "id_parent", "name", UserAction.View);

            // now children have everything set, even parentid
            // as the parent was inserted first, his id was set and they took it from the object

            List <IControl> addedList = new List <IControl>();

            addedList.Add(basePanelTreeControl);
            basePanel.AddControls(addedList);

            basePanel.AddControlAttr(CC.NAV_THROUGH_PANELS, true);
            basePanel.AddViewAttr(CC.PANEL_NAME, "Main menu");
            basePanel.AddControlAttr(UserAction.View.ToString() + CC.CONTROL_ACCESS_LEVEL_REQUIRED_SUFFIX, 1);

            systemDriver.updatePanel(basePanel, false); // children aren`t changed, just adding a control for the basePanel
            return(basePanel);
        }