Documentation YAML for OpenPetra Forms: Difference between revisions

From OpenPetra Wiki
Jump to navigation Jump to search
(Improve documentation on ManualCode (at least made a start, and all possible Methods are now mentioned))
(Replaced content with "Deprecated: this only applied to the winforms client")
Tag: Replaced
 
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Inheritance ==
Deprecated: this only applied to the winforms client
===General===
* Most YAML files inherit from each other. That inheritance is specified with the '''BaseYaml''' Element. ''You will find this kind of inheritance in the vast majority of YAML files.''
** This allows us to define many things once (e.g. default menu items, default Actions, default Events, StatusBar) in PetraForm.yaml and through that they will be included in all derived forms!
** Example: <code>BaseYaml: PetraForm.yaml</code>
 
===Special Cases===
* Base YAML files (and possibly in some rare instances also other YAML files) can inherit from a Base Class. That is specified with the '''BaseClass''' Element.
** This can be a Class that is specified by the .NET Framework's WinForms implementation (such as System.Windows.Forms.Form), or one of our own openPETRA Classes.
** Example: <code>BaseClass: System.Windows.Forms.Form</code>
* In certain (rare) circumstances a custom Interface might need to be implemented by a Class that is generated from a YAML file. This is achieved by specifiying the '''InterfaceName''' Element.
** Example: <code>InterfaceName: IMySpecialInterface</code>
** It is possible to implement several Interfaces by separating them by comma (see Note below).
** Note: The Interface 'Ict.Petra.Client.CommonForms.IFrmPetra' is automatically implemented by all Classes which are generated from YAML files. If the 'InterfaceName' Element is specified, this is no longer the case. In case you want to implement both your specific Interface and 'Ict.Petra.Client.CommonForms.IFrmPetra' (which is very likely), concatenate them as follows: <code>InterfaceName: IMySpecialInterface, Ict.Petra.Client.CommonForms.IFrmPetra</code>.
 
== Attributes of the root node ==
* '''Template''': this refers to the C# (.cs) file that is used for the template. The templates are located in csharp\ICT\PetraTools\Templates\Winforms. A description of templates and the snippets is here: [[Code Templates and snippets]]
** ''window'': the default template, sufficient for module main screens etc.
*** Examples: Finance Modules Main Menu (FinanceMain.yaml). PetraForm.yaml also points to window.cs.
** ''windowBasic'': a simpler template than 'window', which allows for less dependencies (but also has a lot less functionality!). Currently only used for YAML forms in Project Ict.Petra.Client.App.Core.
** ''reportwindow'': for the reporting screens
** ''windowEditUIConnector'': this is for bigger edit screens, that require stateful sessions on the server; example: PartnerEdit? APEditSupplier?
** ''windowMaintainTable'': maintain the rows of a single table, in a grid, with edit section at the bottom; example: SetupCurrency
** ''windowMaintainCacheableTable'': maintain the rows of a single table, in a grid, with edit section at the bottom; example: GiftMotivationSetup
*** the difference to 'windowMaintainTable' is that 'windowMaintainCacheableTable' works with ''only'' with 'Cacheable DataTables'. The ''CacheableTable'' Attribute of the root node needs to be set to the name of an existing Cacheable DataTable (e.g 'MotivationList').
*** For Cacheable DataTables in the Finance Module which need to be filtered on the Ledger Number, the additional Attribute ''CacheableTableSpecificFilter'' of the root node needs to be set to 'Ledger'.
*** The data that is displayed in the screen is retrieved and saved through the client-side CacheManager, TDataCache (namespace Ict.Petra.Client.App.Core), which in turn use server-side Methods that use the server-side Cache. Because of this, no WebConnectors or other static function calls on server-side methods need to be used for such screens!
** ''windowEditWebConnectorMasterDetail'': edit a master row, and maintain the detail rows; Example: APEditDocument
** ''windowFind'': template for find screens. uses UIConnector for paged search results; example: APMain
** ''windowTDS'': template for complex find and browse screens that allow to change the data; example: GLBatch
** ''usercontrol'': template for UserControls.
*** UserControls can be understood as 'sub-forms' or simply parts of a screen whose layout is specified separately from the screen.
** ''usercontrolUnbound''. Same as usercontrol, except for controls that don't host data fields, e.g. container controls.
* '''FormType''': Is not so important, because '''Template''' already defines a lot; at the moment, only the ''report'' type is different from the other types; this might change, and we will only need Template but not FormType
** ''abstract'': if this is just used as a base form for other real forms
** ''navigation'': the main window, the module windows
** ''edit'': edit screens
** ''crud'': CRUD screens (Create, Read, Update, Delete)
** ''find'', ''browse'': find screens
** ''report'': reporting screens
** ''dialog'': Dialog screens (have OK, Cancel, Help Buttons)
* '''MasterTable''': if this is set, you will need to write less DataField attributes for the controls. The name of the controls will be matched to a field in the given table; if such a table field exists, it will be linked to the control.
* '''DetailTable''': similar to MasterTable, but this is for the detail table; controls must have the word ''Detail'' after the prefix, eg. txtDetailAmount
* '''DatatableType''': this is used for the DetailTable, if it is derived from a database table, in a dataset; eg UC_GLTransactions: <code>DatatableType: Ict.Petra.Shared.MFinance.GL.Data.GLBatchTDSATransaction</code>
** Update: better use DatasetType, which allows mapping of tables to their dataset names automatically
* '''MasterTableType''': this is used for the MasterTable, if it is derived from a database table, in a dataset
** Update: better use DatasetType, which allows mapping of tables to their dataset names automatically
* '''DatasetType''': this will make sure that fields get mapped much easier to the appropriate table and datafield. You can use eg a controlname txtPFamilyFirstName, txtNoSolicitation, etc., and the controls will be mapped to the right table. You can even use data fields from custom tables and custom fields. You have to use the full namespace for DatasetType.
* '''UsingNamespaces''': adds one or more reference(s) to Namespace(s) that should be included to the auto-generated C# file. Many of the usual Namespaces are already included automatically by the WinForms Generator, but there are situations where one needs one or more other Namespaces to be added.
** Correct capitalisation of the namespace(s) is important as the WinForms Generator just puts whatever is written in the UsingNamespaces into using ... clauses in the C# file.
** If you need to add more than one namespace, separate the namespaces with commas ( , ).
** Example #1: <code>UsingNamespaces: [Ict.Petra.Shared.MFinance.Account.Data]</code>
** Example #2: <code>UsingNamespaces: [Ict.Petra.Shared.MPartner.Partner.Data, Ict.Petra.Client.CommonForms.Logic]</code>
* '''Namespace''': this is the namespace that this screen should belong to. eg. <code>Ict.Petra.Client.MFinance.Gui.AccountsPayable</code>
** if you want methods to be linked automatically to a web connector, you need to make sure that there is a webconnector in the same namespace (Server instead of Client, without Gui, but WebConnectors at the end), eg. <code>Ict.Petra.Server.MFinance.AccountsPayable.WebConnectors</code>.
* '''ClassName''': this is only required if the name of the yaml file should not be the same as the name of the class; the naming convention is: TFrmSetupCurrency is the classname, SetupCurrency.cs is the filename; for user controls: TUC_GLJournals is in file UC_GLJournals.cs
* '''PropertyForSubScreens''': this is useful if you use '''ActionOpenScreen''' in your actions, because it will assign the property to the new screen (if it has that propery too); eg. in Finance module the ledger number
* '''ReportParameters''': this is needed only in the reports. It will set the available fields that can be used in this report. Those fields automatically appear in the sorting list and in the column list of the report.
*'''CacheableTable''': see definition [[How-To: Creating a Maintain Table screen#CacheableTable_Element|here]]
*'''Comment''': an arbitrary text that doesn't get parsed. This can be used as a comment for the YAML file.
* TODO: '''BaseYaml''', '''FormTitle''', '''WindowWidth''', '''WindowHeight'''
 
== Events ==
* '''Events''': here you can link form events to methods in your code
** eg. <code>Activated: {class=System.EventHandler,method=FTheObject.TFrmPetra_Activated}</code>
== Actions ==
* '''Actions''': actions can be used by menuitems, toolbarbuttons, and other controls; this is useful to be able to enable/disable an action on the whole screen, and to only define a certain action once, and refer to it from all controls that trigger the same action
** eg. <code>actClose: {Label=&Close, ActionId=eClose, Tooltip=Closes this window, Image=Close.ico}</code>
** eg. <code>actMainMenu: {Label=Petra &Main Menu, ActionClick=FTheObject.OpenMainScreen}</code>
** '''Enabled''': Actions can depend on other actions or conditions; they will be disabled if the condition is false; eg <code>Enabled: cndSelectedSupplier</code>; this can be set in a grid, with '''SelectedRowActivates'''; eg <code>grdSupplierResult: {Dock=Fill, ActionDoubleClick=actSupplierTransactions, SelectedRowActivates=cndSelectedSupplier}</code>
** '''InitiallyEnabled''': this is used for disabling an action when the window is opened
 
* special situation: create a detail row: see for example APEditDocument.ManualCode.cs; we do use the generated function CreateAApDocumentDetail, but we need to first calculate some actual parameters
 
* Actions are linked by menu items, toolbar buttons etc either by using attribute '''Action''', or by convention, ie. the name of the control matches the name of the action (eg. mniSaveSettingsAs matches actSaveSettingsAs)
 
* You can read more about the special auto-generated code for the '''Delete''' action in [[Adding Delete Functionality to a Screen or Control]].
 
== ManualCode ==
The following functions can be written in the *.ManualCode.cs file, and the next run of nant generateWinforms will pick them up and call them from the generated code. If the functions don't exist, they will not be called from the generated code: this avoids unnecessary empty functions in the manual code file.
 
Here are the manual functions:
 
=== <code>InitializeManualCode</code> ===
* called from within the Constructor of the Form/UserControl
** run after loading of data takes place
** run before a Grid is set up
** run before Form Activation takes place
 
=== <code>RunOnceOnActivationManual</code> ===
* runs when the WinForms <code>Form.Activated</code> Event is fired
* only for Forms, not for UserControls!
 
=== <code>ExitManualCode</code> ===
* '''TODO'''
 
=== <code>CanCloseManual</code> ===
* '''TODO'''
 
=== <code>NewRowManual</code> ===
* only works where a Grid Control (grdDetails) is present
* used for supplying (default) values for DataColumns
** e.g. 'NEWVALUE' in many Setup-type Screens
** specifically needed for DataTables that have NOT NULL constraints on at least one DataColumn
 
=== <code>StoreManualCode</code> ===
* '''TODO'''
 
=== <code>ShowDataManual</code> ===
* '''TODO'''
 
=== <code>Show''Details''Manual</code> ===
* only works where a Details Panel is present
* '''TODO'''
 
=== <code>BeforeShow''Details''Manual</code> ===
* only works where a Details Panel is present
* '''TODO'''
 
=== <code>ValidateDataManual</code> ===
* '''TODO'''
 
=== <code>ValidateData''Details''Manual</code> ===
* only works where a Details Panel is present
* '''TODO'''
 
=== <code>GetDataFromControlsManual</code> ===
* '''TODO'''
 
=== <code>Get''Detail''DataFromControlsManual</code> ===
* only works where a Details Panel is present
* '''TODO'''
 
=== <code>GetSelectedDetailRowManual</code> ===
* only works where a Details Panel is present
* '''TODO'''
 
=== <code>PreDeleteManual</code> ===
* only works where a Grid Control (grdDetails) is present
* for Details see [[Adding Delete Functionality to a Screen or Control#Auto-generated_Client_Code | here]]
 
=== <code>DeleteRowManual</code> ===
* only works where a Grid Control (grdDetails) is present
* for Details see [[Adding Delete Functionality to a Screen or Control#Auto-generated_Client_Code | here]]
 
=== <code>PostDeleteManual</code> ===
* only works where a Grid Control (grdDetails) is present
* for Details see [[Adding Delete Functionality to a Screen or Control#Auto-generated_Client_Code | here]]
 
=== <code>SelectTabManual</code> ===
* only works where a Tab Control is present
* '''TODO'''
 
 
=== Only for Reports:===
==== <code>ReadControlsManual</code> ====
* '''TODO'''
 
==== <code>SetControlsManual</code> ====
* '''TODO'''
 
== Controls ==
* '''Controls''': see [[Screen scaffolding: controls]]
== Menu & Toolbar ==
* '''Menu''':
** Structure
*** A Menu is introduced with the item 'Menu:' in the yaml file.
*** The children under the 'Menu:' entry form the top-level menus, e.g. 'mniFile' represents the 'File' menu.
*** The children under such entries form the menu items of the top-level menus, e.g. 'mniFilePrint' represents the 'Print' Menu item of the 'File' Menu. Children of these children form sub-menus. This can go several levels deep.
** Naming conventions
*** Menu item names start with 'mni', e.g. mniFilePrint.
*** Use 'mniSeparator' for a horizontal Separator Bar between Menu items.
** Inheritance of Menus
*** If you are working with a window template derived from PetraForm.yaml, then there is already a mnuMain control with the Close button.
*** When deriving forms from each other the menu items are inherited; use attribute '''Order''' with values '''AlwaysLast''', or '''AlwaysFirst'''. Whoever is higher in the hierarchy will have more weight.
**** Example: the Help Menu Item in the root yaml file with Order=AlwaysLast will always be last, even if derived forms will have another item with AlwaysLast, which will be inserted before the help menu item.
*** If you use a name for a top-level Menu that already exists in a yaml file that is an ancestor to the yaml file you are working with, Menu items are added to the already existing top level menu.
** TabControls
*** If you are working with TabPages (e.g. using template controlMaintainTable, deriving from UserControl), you should add a control with name mnuTabPage; the contents of that menu will be added to the main menu when the TabPage is active.
* '''Toolbar''': very similar to Menu, just different names: tbrMain, tbrTabPage
** Structure
*** A ToolBar is introduced with the item 'Toolbar:' in the yaml file.
*** Currently there is a limit of only one ToolBar for each form.
** Naming conventions
*** Toolbar item names start with 'tbb', e.g. tbbNewPartner.
*** use 'tbbSeparator' for a vertical Separator Bar between Toolbar items.
** Inheritance of ToolBars
*** When deriving forms from each other the ToolBar items are inherited; use attribute Order with values AlwaysLast, or AlwaysFirst. Whoever is higher in the hierarchy will have more weight.
**** Example: the 'Save' ToolBar item in the PetraEditForm.yaml file with Order=AlwaysFirst will always be first, even if derived forms will have another item with AlwaysFirst, which will be inserted afer the 'Save' ToolBar item.
** TabControls
*** If you are working with TabPages (e.g. using template controlMaintainTable, deriving from UserControl), you should add a control with name tbrTabPage; the contents of ToolBar will be added to the ToolBar when the TabPage is active.
 
== Layout ==
===Dialogs (Forms That Have OK, Cancel, Help Buttons)===
To create Forms which are Dialogs, specify the value '<code>PetraFormDialog.yaml</code>' for the '<code>BaseYaml</code>' Element (instead of e.g. '<code>PetraForm.yaml</code>').
* When using '<code>PetraFormDialog.yaml</code>' as BaseYaml, there is no need to put OK, Cancel or Help Buttons on the Form, as this is already taken care of in '<code>PetraFormDialog.yaml</code>'.
* Such Forms don't have a Menu or a ToolBar.
* ''Important:'' all Controls need to be contained in a Panel called '<code>pnlDialogContent</code>' and this needs to be the 'Root Control'!
** Other than that, there is nothing special about the layout of such Forms, all the usual layout methods and Controls can be used.
* Corresponding *.ManualCode.cs file
** Needs to contain an event-handling Method called '<code>BtnOK_Click</code>' - this is wired up by the Generator to get called when the OK Button is clicked by the user.
** Dialogs have a hidden 'Apply' Button Control. To make it visible and wire it up to custom program code, create an event-handling Method called '<code>BtnApply_Click</code>' and add the following lines of code to the '<code>InitializeManualCode</code>' Method (the layout of the Buttons Panel is automatically taken care of!):
btnApply.Visible = true;
btnApply.Click += new EventHandler(BtnApply_Click);
 
 
 
=== TODO (Tabbed pages etc) ===
 
=== Other ===
Another option for layout is the '''Controls''' property that can be used for Panels and GroupBoxes: You can use several rows to arrange the controls and they are aligned in a table layout. see also [[Screen_scaffolding:_controls#Layout_of_Controls|Layout of Controls]]

Latest revision as of 20:46, 11 Mayıs 2022

Deprecated: this only applied to the winforms client