Example #1
0
        /// <summary>
        /// Saves the content of stored hierarchy of a TreeControl to the database
        /// </summary>
        /// <param name="control"></param>
        private void SaveStroedHierarchyOfControl(TreeControl control)
        {
            if (control.controlId != null)
            {
                driver.query("DELETE FROM ", dbe.Table("hierarchy_nav_tables"), "WHERE", dbe.Col("id_control"), " = ", control.controlId);
            }
            bool wasInTran = driver.IsInTransaction;

            Dictionary <string, object> insVals = new Dictionary <string, object> {
                { "id_control", control.controlId }
            };

            if (!wasInTran)
            {
                driver.BeginTransaction();
            }
            foreach (HierarchyRow r in control.storedHierarchyData.Rows)
            {
                insVals["id_item"]   = r.Id;
                insVals["id_parent"] = r.ParentId;
                insVals["caption"]   = r.Caption;
                insVals["id_nav"]    = r.NavId;
                driver.query("INSERT INTO ", dbe.Table("hierarchy_nav_tables"), dbe.InsVals(insVals));
            }
            if (!wasInTran)
            {
                driver.CommitTransaction();
            }
        }
Example #2
0
        /// <summary>
        /// deserializes a Control, distinguishing TreeControls and creating hierarchy Relations in their sored DataTables
        /// </summary>
        /// <param name="s">serialized control</param>
        /// <returns>the deserialized Control object</returns>
        private Control DeserializeControl(string s, int id)
        {
            if (s.Contains("storedHierarchyDataSet"))
            {
                return(new Control(0, "", UserAction.Delete));
            }
            DataContractSerializer serializer = new DataContractSerializer(typeof(Control));
            Control res = (Control)(serializer.ReadObject(Functions.GenerateStreamFromString(s)));

            res.controlId = id;
            if (res is TreeControl)
            {
                AssignSotredHierarchyToControl((TreeControl)res);
                TreeControl tc = res as TreeControl;
                if (tc.storedHierarchyData is HierarchyNavTable)
                {
                    DataSet ds = new DataSet();
                    if (tc.storedHierarchyData.DataSet != null)
                    {
                        tc.storedHierarchyData.DataSet.Relations.Clear();
                        tc.storedHierarchyData.DataSet.Tables.Clear();
                    }
                    ds.Tables.Add(tc.storedHierarchyData);
                    tc.storedHierarchyData.ChildRelations.Add(new DataRelation(CC.CONTROL_HIERARCHY_RELATION,
                                                                               tc.storedHierarchyData.Columns["Id"], tc.storedHierarchyData.Columns["ParentId"], true));
                }
            }
            return(res);
        }
Example #3
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);
            }
        }
Example #4
0
        /// <summary>
        /// Saves a new contol to the database (must have null ID, which will be set to the AI from the database).
        /// </summary>
        /// <param name="control"></param>
        public void AddControl(Control control)
        {   // fieldId = 0
            Dictionary <string, object> insertVals = new Dictionary <string, object>();

            insertVals["id_panel"] = control.panelId;
            insertVals["content"]  = control.Serialize();
            if (!driver.IsInTransaction)
            {
                bool wasInTrans = driver.IsInTransaction;
                if (!wasInTrans)
                {
                    driver.BeginTransaction();
                }
                driver.query("INSERT INTO controls", dbe.InsVals(insertVals));
                control.SetCreationId(driver.LastId());    // must be 0 in creation
                if (!wasInTrans)
                {
                    driver.CommitTransaction();
                }
            }
            else
            {
                driver.query("INSERT INTO controls", dbe.InsVals(insertVals));
                control.SetCreationId(driver.LastId());    // must be 0 in creation
            }
            if (control is TreeControl)
            {
                SaveStroedHierarchyOfControl((TreeControl)control);
                TreeControl tc = control as TreeControl;
                if (tc.storedHierarchyData is HierarchyNavTable)
                {
                    DataSet ds = new DataSet();
                    if (tc.storedHierarchyData.DataSet != null)
                    {
                        tc.storedHierarchyData.DataSet.Relations.Clear();
                        tc.storedHierarchyData.DataSet.Tables.Clear();
                    }
                    ds.Tables.Add(tc.storedHierarchyData);
                    tc.storedHierarchyData.ChildRelations.Add(new DataRelation(CC.CONTROL_HIERARCHY_RELATION,
                                                                               tc.storedHierarchyData.Columns["Id"], tc.storedHierarchyData.Columns["ParentId"], true));
                }
            }
        }
Example #5
0
        /// <summary>
        /// Extrats the hierchy data for the given TreeControl and assigns it to it. If there is no
        /// data present, the data property of the control remains unchanged.
        /// </summary>
        /// <param name="control"></param>
        public void AssignSotredHierarchyToControl(TreeControl control)
        {
            if (control.controlId == null)
            {
                return;
            }

            List <IDbCol> cols = new List <IDbCol>();

            cols.Add(dbe.Col("id_item", "Id"));
            cols.Add(dbe.Col("id_parent", "ParentId"));
            cols.Add(dbe.Col("caption", "Caption"));
            cols.Add(dbe.Col("id_nav", "NavId"));
            DataTable tbl = driver.fetchAll("SELECT ", dbe.Cols(cols),
                                            " FROM ", dbe.Table("hierarchy_nav_tables"), "WHERE  id_control = ", control.controlId);

            HierarchyNavTable resHierarchy = new HierarchyNavTable();

            resHierarchy.Merge(tbl);
            control.storedHierarchyData = resHierarchy;
        }
Example #6
0
        /// <summary>
        /// Fills panel with data based on the columns included and possibly the Primary Key
        /// </summary>
        /// <param name="panel"></param>
        public void FillPanel(Panel panel)
        {
            if (panel.fields.Count() > 0)
            { // editable Panel, fetch the DataRow, simple controls - must have unique PK
                var       columns = panel.fields.Where(x => x is IColumnField).Select(x => ((IColumnField)x).ColumnName).ToList <string>();
                DataTable table   = driver.fetchAll("SELECT ", dbe.Cols(columns), " FROM ", panel.tableName, "WHERE", dbe.Condition(panel.PK));
                if (table.Rows.Count > 1)
                {
                    throw new Exception("PK is not unique");
                }
                if (table.Rows.Count == 0)
                {
                    throw new WebDriverDataModificationException(
                              "No data fulfill the condition. The record may have been removed.");
                }
                DataRow row = table.Rows[0];
                panel.OriginalData = table.Rows[0];

                foreach (IField field in panel.fields)       // fill the fields
                {
                    if (field is IColumnField)
                    {        // value
                        IColumnField cf = (IColumnField)field;
                        cf.Data = row[cf.ColumnName].GetType() != typeof(MySql.Data.Types.MySqlDateTime) ? row[cf.ColumnName] :
                                  ((MySql.Data.Types.MySqlDateTime)row[cf.ColumnName]).GetDateTime();
                    }
                    else
                    {           // mapping values are yet to fetch
                        M2NMappingField m2nf = (M2NMappingField)field;
                        m2nf.Data = FetchMappingValues(m2nf.Mapping, (int)panel.PK[0]);
                    }
                }
            }

            foreach (Control c in panel.controls)
            {
                if (c is NavTableControl)
                {
                    AssignDataForNavTable((NavTableControl)c, false);
                }
                // always gets the whole table, save in session
                else if (c is TreeControl && c.data is DataTable)
                {   // there are no data in storedHierarchy - that is only the case of menu in base panel - fill it
                    TreeControl tc = (TreeControl)c;
                    tc.data.DataSet.EnforceConstraints = false;
                    tc.data.Rows.Clear();
                    HierarchyNavTable hierarchy = (HierarchyNavTable)(tc.data);

                    List <IDbCol> selectCols = new List <IDbCol>();
                    // don`t need to use constants - the column names are set in HierarchNavTable
                    DataTable fetched = driver.fetchAll("SELECT",
                                                        dbe.Col(tc.PKColNames[0], "Id"), ",",
                                                        dbe.Cols(selectCols), dbe.Col(tc.parentColName, "ParentId"), ",",
                                                        "CAST(", dbe.Col(tc.displayColName), "AS CHAR) AS \"Caption\"", ",",
                                                        dbe.Col(tc.PKColNames[0], "NavId"),
                                                        "FROM", panel.tableName);


                    hierarchy.Merge(fetched);
                    tc.data.DataSet.EnforceConstraints = true;
                }
            }

            /*
             * foreach (Panel p in panel.children)
             *  FillPanel(p);
             */
        }
Example #7
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string panelName = PanelName.Text;
            List<string> displayCols = DisplayCols.RetrieveStringData();
            List<UserAction> actions = new List<UserAction>();
            foreach(string s in actionsControl.RetrieveStringData()){
                actions.Add((UserAction)Enum.Parse(typeof(UserAction), s));
            }

            ValidationResult.Items.Clear();
            // validate the proposal
            if (panelName == ".")
            {
                ValidationResult.Items.Add("Give the pannel a name, please.");
            }
            else if (displayCols.Count == 0) {
                ValidationResult.Items.Add("Select at leas one column to display");
            }
            else if (actions.Count == 0)
            {
                ValidationResult.Items.Add("Check at least one action users can perform in thie panel, please");
            }
            else {
                ValidationResult.Items.Add("Valid");
                // => create the panel and save it
                _min.Models.Control c;
                List<_min.Models.Control> controls = new List<_min.Models.Control>();

                _min.Models.Control insertButton = null;

                // insert is a separate button
                if (actions.Contains(UserAction.Insert))
                {
                    insertButton = new _min.Models.Control(actPanel.panelId, "Insert", UserAction.Insert);
                    actions.Remove(UserAction.Insert);
                }

                // it is a NavTable
                if (NavControlType.SelectedValue.EndsWith("Table"))
                {
                    List<FK> neededFKs = (from FK fk in FKs where displayCols.Contains(fk.myColumn) select fk).ToList<FK>();
                    c = new NavTableControl(actPanel.panelId, new System.Data.DataTable(), mm.Stats.PKs[actPanel.tableName],
                        neededFKs, actions);
                    c.displayColumns = displayCols;
                }
                else {  // NavTree
                    actions.Remove(UserAction.Delete);      // cannot use delete in NavTrees
                    c = new TreeControl(actPanel.panelId, new HierarchyNavTable(), mm.Stats.PKs[actPanel.tableName][0],
                        hierarchy.myColumn, displayCols[0], actions);
                }
                controls.Add(c);
                if (insertButton != null)
                    controls.Add(insertButton);

                foreach (_min.Models.Control listedControl in controls) {
                    listedControl.targetPanelId = actPanel.controls[0].targetPanelId;
                }

                MPanel resPanel = new MPanel(actPanel.tableName, actPanel.panelId,
                    c is TreeControl ? PanelTypes.NavTree : PanelTypes.NavTable, new List<MPanel>(),
                    new List<IField>(), controls, actPanel.PKColNames, null, actPanel.parent);
                resPanel.panelName = panelName;

                actPanel = resPanel;

                mm.SysDriver.BeginTransaction();
                mm.SysDriver.UpdatePanel(actPanel);
                mm.SysDriver.CommitTransaction();
                mm.SysDriver.IncreaseVersionNumber();
                ValidationResult.Items.Add("Saved");
                Response.Redirect(Page.Request.RawUrl);
            }
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// Saves the content of stored hierarchy of a TreeControl to the database
        /// </summary>
        /// <param name="control"></param>
        private void SaveStroedHierarchyOfControl(TreeControl control)
        {
            if(control.controlId != null)
                driver.query("DELETE FROM ", dbe.Table("hierarchy_nav_tables"), "WHERE", dbe.Col("id_control"), " = ", control.controlId);
            bool wasInTran = driver.IsInTransaction;

            Dictionary<string, object> insVals = new Dictionary<string, object> {
                { "id_control", control.controlId }
            };

            if (!wasInTran)
                driver.BeginTransaction();
            foreach (HierarchyRow r in control.storedHierarchyData.Rows) {
                insVals["id_item"] = r.Id;
                insVals["id_parent"] = r.ParentId;
                insVals["caption"] = r.Caption;
                insVals["id_nav"] = r.NavId;
                driver.query("INSERT INTO ", dbe.Table("hierarchy_nav_tables"), dbe.InsVals(insVals));
            }
            if (!wasInTran)
                driver.CommitTransaction();
        }
Example #10
0
        /// <summary>
        /// Extrats the hierchy data for the given TreeControl and assigns it to it. If there is no
        /// data present, the data property of the control remains unchanged.
        /// </summary>
        /// <param name="control"></param>
        public void AssignSotredHierarchyToControl(TreeControl control)
        {
            if (control.controlId == null) return;

            List<IDbCol> cols = new List<IDbCol>();
            cols.Add(dbe.Col("id_item", "Id"));
            cols.Add(dbe.Col("id_parent", "ParentId"));
            cols.Add(dbe.Col("caption", "Caption"));
            cols.Add(dbe.Col("id_nav", "NavId"));
            DataTable tbl = driver.fetchAll("SELECT ", dbe.Cols(cols),
                " FROM ", dbe.Table("hierarchy_nav_tables"), "WHERE  id_control = ", control.controlId);

            HierarchyNavTable resHierarchy = new HierarchyNavTable();
            resHierarchy.Merge(tbl);
            control.storedHierarchyData = resHierarchy;
        }
Example #11
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;
            }
        }
Example #12
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;
        }
Example #13
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);
        }
Example #14
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>IPanel</returns>
        private IPanel proposeSummaryPanel(string tableName)
        {
            DataColumnCollection cols = stats.columnTypes(tableName);
            List <IFK>           FKs  = stats.foreignKeys(tableName);
            // a table with more than one self-referential FK is improbable
            List <IFK>    selfRefs  = new List <IFK>(from FK in FKs where FK.myTable == FK.refTable select FK as IFK);
            List <string> PKCols    = stats.primaryKeyCols(tableName);
            IFK           selfRefFK = null;
            // strict hierarchy structure validation - not nice => no Tree

            string hierarchyExplanation = "(For a tree-like navigation within view, the table must have exactly one FK pointing "
                                          + " to it`s PK column. (It can of course have other FKs refering to other tables.))";

            if (selfRefs.Count > 1)
            {
                Warning(this, new ArchitectWarningEventArgs(
                            "Unexpected hierarchy table structure for " + tableName + " - multiple self-referential columns. "
                            + hierarchyExplanation, tableName));
            }
            else
            if (selfRefs.Count == 1 && PKCols.Count == 1)
            {
                selfRefFK = selfRefs.First();

                if (PKCols.Count > 1)
                {
                    Warning(this, new ArchitectWarningEventArgs(
                                "Hierarchical table " + tableName + " does have a signle-column PK. "
                                + hierarchyExplanation, tableName));
                    selfRefFK = null;       // remove the selfRefFK => as if there was no hierarchy
                }
                if (selfRefFK.refColumn != PKCols[0])
                {
                    selfRefFK = null;
                    Warning(this, new ArchitectWarningEventArgs("The self-referential FK in table "
                                                                + tableName + " must refer to the PK column. "
                                                                + hierarchyExplanation, tableName));
                }
            }
            List <string> displayColOrder = DisplayColOrder(tableName);

            PropertyCollection controlProps = new PropertyCollection();
            PropertyCollection displayProps = new PropertyCollection();

            displayProps.Add(CC.PANEL_DISPLAY_COLUMN_ORDER, String.Join(",", displayColOrder));
            displayProps.Add(CC.PANEL_NAME, tableName);
            controlProps.Add(UserAction.View.ToString() + CC.CONTROL_ACCESS_LEVEL_REQUIRED_SUFFIX, 1);
            IControl   control;
            DataTable  controlTab = new DataTable();
            PanelTypes panelType;

            List <IField> fields = new List <IField>();

            if (selfRefFK == null)
            {
                //displayProps.Add(CC.NAVTAB_COLUMNS_DISLAYED, CC.NAVTAB_COLUMNS_DISLAYED_DEFAULT);
                // table takes first four display-suitable fields; the above is not neccessary, in Navtable Columns are fields
                foreach (string column in displayColOrder.Take(CC.NAVTAB_COLUMNS_DISLAYED_DEFAULT))
                {
                    //controlTab.Columns.Add(column);
                    if (FKs.Any(x => x.myColumn == column))
                    {
                        IFK myFK = FKs.Find(x => x.myColumn == column);
                        fields.Add(new FKField(0, column, fieldTypeIdMap[FieldTypes.Varchar], FieldTypes.Varchar.ToString(),
                                               0, myFK));
                    }
                    else
                    {
                        fields.Add(new Field(0, column, fieldTypeIdMap[FieldTypes.Varchar], FieldTypes.Varchar.ToString(), 0));
                    }
                    fields.OrderBy(x => displayColOrder.IndexOf(x.column));
                    // to maintain the order from displayColOrder without further properties
                }
                control   = new Control(controlTab, PKCols, UserAction.Update);
                panelType = PanelTypes.NavTable;
            }
            else
            {
                controlProps.Add(CC.CONTROL_HIERARCHY_SELF_FK_COL, selfRefFK.myColumn);
                controlTab.Columns.Add(PKCols[0]);
                controlTab.Columns.Add(selfRefFK.myColumn);
                controlTab.Columns.Add(displayColOrder[0]);
                control   = new TreeControl(controlTab, PKCols[0], selfRefFK.myColumn, displayColOrder[0], UserAction.Update);
                panelType = PanelTypes.NavTree;
            }

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

            controls.Add(control);

            return(new Panel(tableName, 0, panelTypeIdMp[panelType], panelType.ToString(),
                             new List <IPanel>(), fields, controls, PKCols, null, displayProps, controlProps));
        }