// use only through FullProject load, if there is no panel in session or project version has changed #region Deserialization /// <summary> /// loads the whole project from database (in 3 queries) /// </summary> public void FullProjectLoad() { Panels = new Dictionary <int, Panel>(); driver.BeginTransaction(); FK control_panel = new FK("controls", "id_panel", "panels", "id_panel", null); FK field_panel = new FK("fields", "id_panel", "panels", "id_panel", null); DataTable panels = driver.fetchAll("SELECT * FROM ", dbe.Table("panels"), "WHERE id_project =", CE.project.Id); DataTable controls = driver.fetchAll("SELECT controls.* FROM ", dbe.Table("controls"), dbe.Join(control_panel), "WHERE id_project =", CE.project.Id); DataTable fields = driver.fetchAll("SELECT fields.* FROM ", dbe.Table("fields"), dbe.Join(field_panel), "WHERE id_project =", CE.project.Id); driver.CommitTransaction(); panels.TableName = "panels"; controls.TableName = "controls"; fields.TableName = "fields"; DataSet ds = new DataSet(); /* * panels.PrimaryKey = new DataColumn[] { panels.Columns["id_panel"] }; * controls.PrimaryKey = new DataColumn[] { panels.Columns["id_control"] }; * fields.PrimaryKey = new DataColumn[] { panels.Columns["id_field"] }; */ if (panels.DataSet is DataSet) { panels.DataSet.Tables.Clear(); } if (controls.DataSet is DataSet) { controls.DataSet.Tables.Clear(); } if (fields.DataSet is DataSet) { fields.DataSet.Tables.Clear(); } ds.Tables.Add(panels); ds.Tables.Add(controls); ds.Tables.Add(fields); ds.Relations.Add(new DataRelation(CC.SYSDRIVER_FK_CONTROL_PANEL, ds.Tables["panels"].Columns["id_panel"], ds.Tables["controls"].Columns["id_panel"], true)); ds.Relations.Add(new DataRelation(CC.SYSDRIVER_FK_FIELD_PANEL, ds.Tables["panels"].Columns["id_panel"], ds.Tables["fields"].Columns["id_panel"], true)); ds.Relations.Add(new DataRelation(CC.SYSDRIVER_FK_PANEL_PARENT, ds.Tables["panels"].Columns["id_panel"], ds.Tables["panels"].Columns["id_parent"], true)); DataSet2Architecture(ds); }
/// <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); */ }