Exemplo n.º 1
0
        protected void Page_Init(object sender, EventArgs e)
        {
            mm = (MinMaster)Master;

            if (!(Session["Summary"] is DataTable))
            {
                HierarchyNavTable baseNavTable = ((TreeControl)(mm.SysDriver.MainPanel.controls[0])).storedHierarchyData;

                List <string> tables = mm.Stats.Tables;

                // the summary of acessibility/dependency/... is generated at the begining, afterwards it is restroed from the Session
                summary = new DataTable();
                summary.Columns.Add("TableName", typeof(string));
                summary.Columns.Add("Independent", typeof(bool));
                summary.Columns.Add("HasPanels", typeof(bool));
                summary.Columns.Add("Reachable", typeof(bool));

                List <string> unsuitableData = mm.Stats.UnsuitableTables();

                foreach (string tableName in mm.Stats.Tables)
                {
                    if (!mm.Stats.PKs.ContainsKey(tableName))    // exclude the PKLess...
                    {
                        continue;
                    }
                    if (unsuitableData.Contains(tableName))      // ...and the binary
                    {
                        continue;
                    }

                    DataRow r = summary.NewRow();
                    r["TableName"] = tableName;     // get it only once - table is stored in Session and updated

                    // this will take a bit longer as the primary key needs to be determined based on the information schema
                    // A table for which the primary key is at least partly also a foreign key is dependant.
                    r["Independent"] = !(mm.Stats.PKs[tableName].Any(pkCol => mm.Stats.FKs[tableName].Any(fk => fk.myColumn == pkCol)));

                    List <MPanel> tablePanels = (from MPanel p in mm.SysDriver.Panels.Values where p.tableName == tableName select p).ToList <MPanel>();
                    r["HasPanels"] = tablePanels.Count > 0;     // now surely equal to 2 (panels are added/removed in pairs)
                    r["Reachable"] = false;
                    if ((bool)(r["HasPanels"]))
                    {
                        r["Reachable"] = baseNavTable.Select("NavId IN (" + tablePanels[0].panelId + ", " + tablePanels[1].panelId + ")").Length > 0;
                    }
                    summary.Rows.Add(r);
                }

                Session["Summary"] = summary;
            }
            else
            {
                summary = (DataTable)Session["Summary"];
            }



            if (!Page.IsPostBack)
            {
                // the next time grid is set like this will be after panels addition / removal
                TablesGrid.DataSource = summary;
                TablesGrid.DataBind();
                ResetActionClickablility();
            }

            BackButton.PostBackUrl = BackButton.GetRouteUrl("ArchitectShowRoute", new { projectName = _min.Common.Environment.project.Name });
        }
Exemplo n.º 2
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            mm.SysDriver.FullProjectLoad();
            int    index     = TablesGrid.SelectedIndex;
            string tableName = summary.Rows[index]["TableName"] as string;

            if ((bool)summary.Rows[index]["HasPanels"])     // then remove is the only option that could have been voted for
            {
                IEnumerable <MPanel> toRemove = from MPanel p in mm.SysDriver.Panels.Values where p.tableName == tableName select p;
                foreach (MPanel p in toRemove)
                {
                    mm.SysDriver.RemovePanel(p);
                }
                summary.Rows[index]["HasPanels"] = false;
            }
            else
            {                                                   // otherwise add new editation a navigation panel for this table
                mm.Architect.mappings    = mm.Stats.Mappings[tableName];
                mm.Architect.hierarchies = new List <string>(); // to speed it up, hierarchy nvigation can be set in panel customization
                MPanel editPanel    = mm.Architect.ProposeForTable(tableName);
                MPanel summaryPanel = mm.Architect.proposeSummaryPanel(tableName);


                summaryPanel.SetParentPanel(mm.SysDriver.MainPanel);       // add to db
                editPanel.SetParentPanel(mm.SysDriver.MainPanel);

                foreach (_min.Models.Control c in editPanel.controls)
                {
                    c.targetPanel = summaryPanel;
                }
                foreach (_min.Models.Control c in summaryPanel.controls)
                {
                    c.targetPanel = editPanel;
                }

                summaryPanel.panelName = "Summary of " + tableName;
                editPanel.panelName    = "Editation of " + tableName;
                mm.SysDriver.BeginTransaction();
                mm.SysDriver.AddPanels(new List <_min.Models.Panel> {
                    summaryPanel, editPanel
                });
                mm.SysDriver.CommitTransaction();
                foreach (_min.Models.Control c in summaryPanel.controls)    // simlified for now
                {
                    c.targetPanel = editPanel;
                }
                foreach (_min.Models.Control c in editPanel.controls)
                {
                    c.targetPanel = summaryPanel;
                }

                summary.Rows[index]["HasPanels"] = true;
            }
            // rebuild the grid
            TablesGrid.DataSource = summary;
            TablesGrid.DataBind();
            ResetActionClickablility();
            TablesGrid.SelectedRow.BackColor      = System.Drawing.Color.White;
            TablesGrid.SelectedRowStyle.BackColor = System.Drawing.Color.White;
            TablesGrid.SelectedIndex = -1;
            SaveButton.Enabled       = false;
            mm.SysDriver.IncreaseVersionNumber();

            Session["summary"] = summary;
        }