/// <summary> /// deserializes a specific panel with controls, fields and child panels /// </summary> /// <param name="ds">the dataset from FullProjectLoad</param> private Panel DataSet2Panel(DataSet ds, int panelId) { List <IField> fields = DataSet2PanelFields(ds, panelId); List <Control> controls = DataSet2PanelControls(ds, panelId); DataRow panelRow = ds.Tables["panels"].AsEnumerable().Where(x => (Int32)x["id_panel"] == panelId).First(); Panel res = DeserializePanel(panelRow["content"] as string); res.panelId = panelId; List <Panel> children = new List <Panel>(); DataRow[] childRows = panelRow.GetChildRows(CC.SYSDRIVER_FK_PANEL_PARENT); foreach (DataRow childRow in childRows) { children.Add(DataSet2Panel(ds, (int)(childRow["id_panel"]))); } res.AddChildren(children); res.AddFields(fields); res.AddControls(controls); return(res); }
public IPanel getPanel(int panelId, bool recursive = true, IPanel parent = null) { DataRow panelRow = fetch("SELECT * FROM panels " + " JOIN panel_types USING(id_panel) WHERE id_panel = ", panelId); List<Field> fields = PanelFields(panelId); List<string> PKColNames = new List<string>(((string)panelRow["pk_column_names"]).Split(',')); PropertyCollection viewProperties = new PropertyCollection(); PropertyCollection controlProperties = new PropertyCollection(); // !! attrs to handle global validation rules needed? DataTable propsTab = fetchAll("SELECT name, val, concerns FROM panels_meta WHERE id_panel = ", panelId); foreach(DataRow row in propsTab.Rows) switch(row["concerns"] as string){ case CC.ATTR_VIEW: viewProperties.Add(row["name"], row["val"]); break; case CC.ATTR_CONTROLS: controlProperties.Add(row["name"], row["val"]); break; default: throw new Exception("Cannot handle panel properties concerning " + row["concerns"] as string + " (yet). "); } //determine the controls List<Control> controls = new List<Control>(); // TODO (probably don`t) rewrite into enum over PanelTypes string pTypeStr = (string)panelRow["type_name"]; switch(pTypeStr){ case Constants.PANEL_EDITABLE: // standard edit window case Constants.PANEL_NAVTABLE: foreach(UserAction action in Enum.GetValues(typeof(UserAction))){ if((action == UserAction.View && pTypeStr == Constants.PANEL_EDITABLE) || (action == UserAction.Update && pTypeStr == Constants.PANEL_NAVTABLE ) ) continue; string actionName = action.ToString(); string controlCaption = (string)controlProperties[actionName]; //!! if(controlCaption != CC.CONTROL_DISABLED && (int)controlProperties[actionName + "ALR"] <= CE.user.rights){ // Authorization Level Required controls.Add(new Control(controlCaption, action)); } } break; case CC.PANEL_MONITOR: // just display, no controls break; case CC.PANEL_MENUDROP: // the contol is the whole panel, do not load data case CC.PANEL_MENUTABS: // will be a field type case CC.PANEL_NAVTREE: string localActionName = UserAction.View.ToString(); // duplicite information about controls - in controlProperties and as Control objects. For Proposal phase use only if((string)controlProperties[localActionName] != CC.CONTROL_DISABLED && // there is sth to show and user can see it (int)controlProperties[localActionName + "ALR"] <= (int)CE.user.rights){ DataTable controlTabStruct = new DataTable(); List<string> displayColumns = new List<string>( // table structure for summary (viewProperties[CC.PANEL_DISPLAY_COLUMN_ORDER] as string).Split(',')); // already in database - only first few columns string panelTypeName = (string)panelRow["type_name"]; if (panelTypeName == CC.PANEL_MENUTABS) { // will take data from children (captions as panel Names) controlTabStruct.Columns.Add("childPanelName"); controls.Add(new Control(controlTabStruct, "childPanelName", UserAction.View)); } else { // gotta be navTree or menuDrop => treeControl if (PKColNames.Count > 1) // must have single PKcol throw new Exception("Tree hierarchies must have single-column primay key"); controlTabStruct.Columns.Add(PKColNames[0]); controlTabStruct.Columns.Add(controlProperties[CC.CONTROL_HIERARCHY_SELF_FK_COL] as string); controlTabStruct.Columns.Add(displayColumns[0]); controls.Add(new TreeControl( controlTabStruct, PKColNames[0], controlProperties[CC.CONTROL_HIERARCHY_SELF_FK_COL] as string, displayColumns[0], UserAction.View)); } } break; } List<IField> fieldsAsInterface = new List<IField>(fields); List<IControl> controlsAsInterface = new List<IControl>(controls); Panel res = new Panel(panelRow["table_name"] as string, panelId, (int)panelRow["id_type"], panelRow["type_name"] as string, null, fieldsAsInterface, controlsAsInterface, PKColNames, null, viewProperties, controlProperties, parent); if(recursive) res.AddChildren(getPanelChildren(res, true)); return res; }
public IPanel getPanel(int panelId, bool recursive = true, IPanel parent = null) { DataRow panelRow = fetch("SELECT * FROM panels " + " JOIN panel_types USING(id_panel) WHERE id_panel = ", panelId); List <Field> fields = PanelFields(panelId); List <string> PKColNames = new List <string>(((string)panelRow["pk_column_names"]).Split(',')); PropertyCollection viewProperties = new PropertyCollection(); PropertyCollection controlProperties = new PropertyCollection(); // !! attrs to handle global validation rules needed? DataTable propsTab = fetchAll("SELECT name, val, concerns FROM panels_meta WHERE id_panel = ", panelId); foreach (DataRow row in propsTab.Rows) { switch (row["concerns"] as string) { case CC.ATTR_VIEW: viewProperties.Add(row["name"], row["val"]); break; case CC.ATTR_CONTROLS: controlProperties.Add(row["name"], row["val"]); break; default: throw new Exception("Cannot handle panel properties concerning " + row["concerns"] as string + " (yet). "); } } //determine the controls List <Control> controls = new List <Control>(); // TODO (probably don`t) rewrite into enum over PanelTypes string pTypeStr = (string)panelRow["type_name"]; switch (pTypeStr) { case Constants.PANEL_EDITABLE: // standard edit window case Constants.PANEL_NAVTABLE: foreach (UserAction action in Enum.GetValues(typeof(UserAction))) { if ((action == UserAction.View && pTypeStr == Constants.PANEL_EDITABLE) || (action == UserAction.Update && pTypeStr == Constants.PANEL_NAVTABLE )) { continue; } string actionName = action.ToString(); string controlCaption = (string)controlProperties[actionName]; //!! if (controlCaption != CC.CONTROL_DISABLED && (int)controlProperties[actionName + "ALR"] <= CE.user.rights) // Authorization Level Required { controls.Add(new Control(controlCaption, action)); } } break; case CC.PANEL_MONITOR: // just display, no controls break; case CC.PANEL_MENUDROP: // the contol is the whole panel, do not load data case CC.PANEL_MENUTABS: // will be a field type case CC.PANEL_NAVTREE: string localActionName = UserAction.View.ToString(); // duplicite information about controls - in controlProperties and as Control objects. For Proposal phase use only if ((string)controlProperties[localActionName] != CC.CONTROL_DISABLED && // there is sth to show and user can see it (int)controlProperties[localActionName + "ALR"] <= (int)CE.user.rights) { DataTable controlTabStruct = new DataTable(); List <string> displayColumns = new List <string>( // table structure for summary (viewProperties[CC.PANEL_DISPLAY_COLUMN_ORDER] as string).Split(',')); // already in database - only first few columns string panelTypeName = (string)panelRow["type_name"]; if (panelTypeName == CC.PANEL_MENUTABS) { // will take data from children (captions as panel Names) controlTabStruct.Columns.Add("childPanelName"); controls.Add(new Control(controlTabStruct, "childPanelName", UserAction.View)); } else { // gotta be navTree or menuDrop => treeControl if (PKColNames.Count > 1) // must have single PKcol { throw new Exception("Tree hierarchies must have single-column primay key"); } controlTabStruct.Columns.Add(PKColNames[0]); controlTabStruct.Columns.Add(controlProperties[CC.CONTROL_HIERARCHY_SELF_FK_COL] as string); controlTabStruct.Columns.Add(displayColumns[0]); controls.Add(new TreeControl( controlTabStruct, PKColNames[0], controlProperties[CC.CONTROL_HIERARCHY_SELF_FK_COL] as string, displayColumns[0], UserAction.View)); } } break; } List <IField> fieldsAsInterface = new List <IField>(fields); List <IControl> controlsAsInterface = new List <IControl>(controls); Panel res = new Panel(panelRow["table_name"] as string, panelId, (int)panelRow["id_type"], panelRow["type_name"] as string, null, fieldsAsInterface, controlsAsInterface, PKColNames, null, viewProperties, controlProperties, parent); if (recursive) { res.AddChildren(getPanelChildren(res, true)); } return(res); }