Depending on the modality of your application, you may or may not be providing so called power users' with the ability to create and edit schemas. Determining how you will approach this item is generally the next decision in the implementation process. Typical scenarios may be:
The developer will pre-define a range of schemas and not provide schema editing functionality in the application
A separate applet may be provided to edit the schema definitions for the application.
Schema editing may be incorporated into the main application for certain privileged users to perform edits and create new schemas.
Irrespective of which of these approaches that you decide on, you will however need to incorporate the schema editing capability somewhere - even if it is only for your own use to originally create the schema definitions.
SQL Designer's WinUI assembly includes a class (fSchema) that incorporates all of the component parts required for editing schemas and global settings into one integrated form. Using fSchema to managing your schemas and global settings is by far the simplest and most direct approach to the requirement of schema editing. This approach may be implemented by a simple three step process:
[Visual Basic]
Private Sub EditSchema(Schema As cSchema)
If Not Schema Is Nothing Then
'Initialize a new GUI interface form.
fs = New WinUI.fSchema
'Assign the schema to be edited to the interface.
fs.Schema = Schema
'Display the schema edit form.
fs.Show()
End If
End Sub
[C#]
private void EditSchema(cSchema schema)
{
if (this.Schema != null)
{
/// Initialize a new GUI interface form.
this.fs = new WinUI.fSchema();
/// Assign the schema to be edited to the interface.
this.fs.Schema = this.schema;
/// Display the schema edit form.
this.fs.Show();
}
}
Note: Per standard .Net Forms behavior, if you open the fSchema form modally (ie: fs.ShowDialog()), when you "close" or hide the form, it will NOT be disposed, unlike non-modal forms that are disposed immediately on closing. As a result, closing a Modal fSchema form will leave the WinUI objects assigned to the cSchema engine and the form may be re-displayed. To remove WinUI objects hosted on a form that is displayed modally, you must call Form.Dispose explicitly after the modal form returns.
If you require more flexibility to be able to construct a more customized schema editing experience into your end user application, you may wish to take advantage of the individual components that are available to build your own schema editing interface.
The more flexible component interface consists of a number of discrete UI based classes that provide individual elements of the UI for editing a schema and related information. The available classes are:
uSchemaPanel - provides the main table and join design surface.
uFieldView - provides the field sorting/properties/grouping panel.
uPropertyWindow - provides the property grid for setting schema element properties.
fComparisonType - edits Comparison Operators, both global and schema specific. This editor can be invoked from the uSchemaPanel.EditComparisonTypes method.
fValueFunctionEditor - edits inbuilt value function lists. This editor can be invoked from the uSchemaPanel.EditValueFunctions method.
Implementing this approach for schema editing involves the following steps:
Create the design surface on which you wish to place the schema editing components and ensure that you have referenced the Connect4.SQLDesigner.WinUI assembly in your project and/or added the assembly to your ToolBox in Visual Studio.
Drag the uSchemaPanel and the uFieldView panels from the toolbox onto your design surface
You may implement a single PropertyWindow control for both panel controls, or, you may use the inbuilt PropertyWindow controls in each panel control.
The uFieldView and the uSchemaPanel are linked via the schema engine object, once they are both set to the same engine, they just work automagically. (Similarly, on the query side of things, the criteria and results panels automagically populate when they are assigned to a cQuery's GUI property.)
By way of example, we have included the source code to WinUI.fSchema in the sample application. This code will demonstrate exactly how to implement the components used in schema and global settings editing.
For additional information on using the Property Window control, refer to the class documentation for uPropertyWindow and the section below on Schema Item Property Management.
DBMS objects may be added to SQL Designer using either a direct connection to a database, or, via DataTable and/or DataSet objects supplied via your host application. For additional information, review the reference documentation on the two methods in Connect4.SQLDesigner.Engine.Schema.cSchema for adding tables (ImportDataSetTables and ImportTable), and on specifying the connection string information to a database (SetDBInfo).
For further customization we can change the display name and attributes for the properties displayed in the property grid, changing the attributes provides the ability to hide property entries, make them read only and/or supply alternate type editors.
To do this you need to obtain a reference to the SchemaPropertyBag, the easiest way to do that is via the SchemaPanel (eg SchemaPanel.SchemaPropertyBag).
Once you have access to the SchemaPropertyBag, you can access the FieldProperties, TableProperties and RelationshipProperties property bags. From there you can access the property collection via Properties, and access each property in the collection via name or index. For a list of the Names to property display names see the tables below.
Here is an example of adding a read-only attribute to the Table Name property.
‘Add the read-only attribute to the TableName property
SchemaPanel.SchemaPropertyBag.TableProperties.Properties("TableName").AddAttribute(New System.ComponentModel.ReadOnlyAttribute(True))
’make the change visible
SchemaPanel.SchemaPropertyBag.RefreshPropertyWindow
We could have also done that via the FieldProperties attribute as the table properties are also shared with the field properties, any changes to one will affect the other.
To remove the an attribute there are two methods, you can either use the type of the attribute to remove all instances of that type, or pass in a specific instance to remove, this example is for the former.
[Visual Basic]
Dim TableNameProp As Connect4.SQLDesigner.WinUI.PropertySpec Dim ReadOnlyAttType As System.Type ReadOnlyAttType = GetType(System.ComponentModel.ReadOnlyAttribute) TableBag = SchemaPanel.SchemaPropertyBag.FieldProperties TableNameProp = TableBag.Properties("TableName") 'remove any attribute of type readonly from the TableName property TableNameProp.RemoveAttribute(ReadOnlyAttType) 'make the change visible SchemaPanel.SchemaPropertyBag.RefreshPropertyWindow()
[C#]
Connect4.SQLDesigner.WinUI.PropertySpec TableNameProp; System.Type ReadOnlyAttType; ReadOnlyAttType = typeof(System.ComponentModel.ReadOnlyAttribute); TableBag = SchemaPanel.SchemaPropertyBag.FieldProperties; TableNameProp = TableBag.Properties("TableName"); //remove any attribute of type readonly from the TableName property TableNameProp.RemoveAttribute(ReadOnlyAttType); //make change visible SchemaPanel.SchemaPropertyBag.RefreshPropertyWindow();
You can also do a few other
operations like change the display name and change the description. You
should not however change the category it is used internally, and the
property will no longer persist or load a value.
[Visual Basic]
Dim FieldBag As Connect4.SQLDesigner.WinUI.PropertyBag Dim NewName As String = "Shown In Criteria" Dim NewDesc As String = "Is this field to be shown in criteria" 'Obtain reference to the Field PropertyBag FieldBag = SchemaPanel.SchemaPropertyBag.FieldProperties 'Set the new display name '(this will cause the order of properties in the grid to change) FieldBag.Properties.Item("AvailableInCriteria").DisplayName = NewName 'Set the new description FieldBag.Properties.Item("AvailableInCriteria").Description = NewDesc 'make the changes visible SchemaPanel.SchemaPropertyBag.RefreshPropertyWindow()
[C#]
Connect4.SQLDesigner.WinUI.PropertyBag FieldBag; string NewName = "Shown In Criteria"; string NewDesc = "Is this field to be shown in criteria"; //Obtain reference to the Field PropertyBag FieldBag = SchemaPanel.SchemaPropertyBag.FieldProperties; //Set the new display name //(this will cause the order of properties in the grid to change) FieldBag.Properties.Item("AvailableInCriteria").DisplayName = NewName; //Set the new description FieldBag.Properties.Item("AvailableInCriteria").Description = NewDesc; //make the changes visible SchemaPanel.SchemaPropertyBag.RefreshPropertyWindow();
Although it is possible to
add extra properties to the Table/Field/Relationship Properties. Collection,
at this time there is no support for persisting or loading values for
the new properties.