예제 #1
0
 public TreeControl(int panelId, HierarchyNavTable data, string PKColName,    // tree controls must have a single-column primary key
                    string parentColName, string displayColName,
                    List <UserAction> actions)
     : base(panelId, data, PKColName, UserAction.Multiple)
 {
     this.actions        = actions;
     this.parentColName  = parentColName;
     this.displayColName = displayColName;
     this.displayColumns = new List <string> {
         displayColName
     };
     this.data = data;
 }
예제 #2
0
        /// <summary>
        /// stores the orinal hierarchy in a dataset that will be saved to viewstatee so that this doesn`t need to be called upon every postback.
        /// </summary>
        /// <param name="hierarchy">The data property of the original menu</param>
        /// <param name="basePanel">the root panel of the architecture</param>
        public void SetInitialState(DataTable hierarchy, MPanel basePanel)
        {
            hierarchyDataset = new DataSet();
            menuHierarchy = new HierarchyNavTable();
            panelsTable = new DataTable();
            panelsTable.Columns.Add("Id", typeof(int));
            panelsTable.Columns.Add("Name", typeof(string));
            menuHierarchy.TableName = "menuHierarchy";
            menuHierarchy.Merge(hierarchy);
            hierarchyDataset.Tables.Add(menuHierarchy);
            hierarchyDataset.Relations.Add(new DataRelation("Hierarchy", menuHierarchy.Columns["Id"], menuHierarchy.Columns["ParentId"], true));

            AddPanelToList(basePanel);
            panelsTable.TableName = "panelsTable";
            hierarchyDataset.Tables.Add(panelsTable);
            ViewState["hierarchyDS"] = hierarchyDataset;
        }
예제 #3
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;
        }
예제 #4
0
        public TreeNavigatorControl(HierarchyNavTable hierarchy, List<UserAction> actions)
        {
            this.hierarchy = hierarchy;
            this.actions = actions;

                tree = new TreeView();

                tree.ShowLines = true;
                WC.TreeNode item;

                foreach (HierarchyRow r in hierarchy.Rows)
                {
                    if (r.ParentId == null)
                    {
                        item = new WC.TreeNode(r.Caption, r.NavId.ToString());
                        AddSubtreeForItem(r, item);
                        tree.Nodes.Add(item);
                    }
                }
                tree.SelectedNodeChanged += SelectionChanged;
                tree.SelectedNodeStyle.Font.Bold = true;

                radios = new RadioButtonList();
                radios.DataSource = actions;
                radios.DataBind();

                // if there is only one action option, don`t show the radios at all
                if (actions.Count == 1)
                {
                    radios.SelectedIndex = 0;
                    radios.Visible = false;
                }
                radios.SelectedIndexChanged += SelectionChanged;
                radios.AutoPostBack = true;

            this.Controls.Add(tree);
            this.Controls.Add(radios);
        }
예제 #5
0
        public override void InventData()
        {
            Random rnd = new Random((Int32)(DateTime.Now.Ticks % 10000000));

            data.DataSet.EnforceConstraints = false;
            data.Rows.Clear();
            data.DataSet.EnforceConstraints = true;
            int n = rnd.Next() % 10 + 10;
            HierarchyNavTable hierarchy = (HierarchyNavTable)(data);

            for (int i = 0; i < n; i++) // generate a random tree - each node picks a parent or no parent with equal chance
            {
                HierarchyRow r = (HierarchyRow)hierarchy.NewRow();
                r.Id       = i + 1;
                r.ParentId = rnd.Next() % (i + 1);
                if ((int)(r.ParentId) == 0)
                {
                    r.ParentId = null;
                }
                r.Caption = NLipsum.Core.LipsumGenerator.Generate(1, NLipsum.Core.Features.Words, "{0}", NLipsum.Core.Lipsums.LeMasque);
                r.NavId   = r.Id;
                data.Rows.Add(r);
            }
        }
예제 #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);
             */
        }
예제 #7
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);
        }
예제 #8
0
     public TreeControl(int panelId, HierarchyNavTable data, string PKColName,    // tree controls must have a single-column primary key
 string parentColName, string displayColName,
 UserAction action)
         : base(panelId, data, PKColName, action)
     {
         this.actions = new List<UserAction> { action };
         this.parentColName = parentColName;
         this.displayColName = displayColName;
         this.displayColumns = new List<string> { displayColName };
         this.data = data;
     }
예제 #9
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;
        }
예제 #10
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;
        }
예제 #11
0
        /// <summary>
        /// loads the current menu hierarchy from the ViewState
        /// </summary>
        /// <param name="savedState"></param>
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            hierarchyDataset = (DataSet)ViewState["hierarchyDS"];
            hierarchyDataset.Relations.Clear();
            menuHierarchy = new HierarchyNavTable();
            menuHierarchy.Merge(hierarchyDataset.Tables["menuHierarchy"]);
            menuHierarchy.TableName = "menuHierarchy";
            panelsTable = hierarchyDataset.Tables["panelsTable"];

            hierarchyDataset.Tables.Clear();
            hierarchyDataset.Tables.Add(menuHierarchy);
            hierarchyDataset.Relations.Add(new DataRelation("Hierarchy", menuHierarchy.Columns["Id"], menuHierarchy.Columns["ParentId"], true));
            hierarchyDataset.Tables.Add(panelsTable);
        }