/// <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; }
/// <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; }
/// <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); */ }
/// <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; }
/// <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); }