190 likes | 385 Views
Session 135. Where OO meets the GUI for .NET. It’s new, it’s different, it’s still just ABL. Peter Judge Principal Software Engineer OpenEdge Development. What is the GUI for .NET?. Who does what?. OpenEdge Built-in Progress.* classes do the ABL-to-.NET talking
E N D
Session 135 Where OO meets the GUI for .NET It’s new, it’s different, it’s still just ABL Peter Judge Principal Software Engineer OpenEdge Development
Who does what? • OpenEdge • Built-in Progress.* classes do the ABL-to-.NET talking • All ABL classes inherit Progress.Lang.Object • All .NET classes inherit System.Object … which also inherits Progress.Lang.Object • You • Composition of UI • UI logic • Business logic procedures or classes (on AppServer)
Building blocks used by Demo • .NET Controls • OpenEdge built-ins • Progress.Windows.FormProgress.Windows.UserControl • Progress.Data.BindingSource • MicrosoftSystem.Windows.FormsTextBox & LabelDataGridViewTreeViewSplitContainerPanelGroupBox • OOABL Classes • MainForm • ItemUserControl • DepartmentDataObjectCustomerDataObject SalesrepDataObject Sports2000
Form design • Start with static nodes • Easy resizing & layout • Multiple UI elements share ABL data • Compose complex controls: ABL User Controls
ProBindingSource:Binding UI controls to ProDataSet data ProDataSet • Set DataSource, DataMember on dataGridOrder • Set BindingSourceProp on Item detail UserControl eCustomer eOrder eOrderLine dataGridOrder:DataMember = "eOrder". dataGridOrder:DataSource = bsCustomer. ucItems1:BindingSourceProp = bsCustomer. eItem ItemNum edtItemNum:DataBindings:Add(new Binding( "Text", BindingSourceProp, "eOrder.eOrderLine.eItem.ItemNum")).
Interacting with the .NET UI:Handling UI events method private InitializeComponent(): /* lotsa stuff */ treeView1:NodeMouseClick:subscribe(treeView1_NodeMouseClick). methodprivatevoid treeview1_NodeMouseClick( sender as System.Object, e as TreeNodeMouseClickEventArgs ): System.EventArgs Empty : System.EventArgs System.Windows.Forms.MouseEventArgs Button : MouseButtons Clicks : integer System.Windows.Forms.TreeNodeMouseClickEventArgs Node : TreeNode
Interacting with the .NET UI:tree node click event handler using System.Windows.Forms.*. methodprivatevoid tree1_NodeMouseClick( sender asSystem.Object, e asTreeNodeMouseClickEventArgs ): /* Deal with top level (zero-based) */ if e:Node:Level eq0then do: cNodeName = e:Node:Name. /* only create the children once. */ if e:Node:Nodes:Count eq0then casecNodeName: when'CustomerNode' then do: CreateCustomerNodes(). DecorateCustomerNodes(). end./* customer */ • Everything’s an object • e:Node - Just Like Any Other Node Object • Chained calls • Call ABL node creation method • Using USING Makes Life Easier!
CreateCustomerNodes() method defvaroParent, oNodeasTreeNode. oData = GetCustomerData(). hBuffer = oData:DatasetHandle :get-buffer-handle('eCustomer'). bsCustomer:Handle = oData:DatasetHandle. oParent = treeView1:Nodes:Item['CustomerNode']. /* create ABL query, set buffers */ hQuery:query-prepare ('preselecteacheCustomerbyName'). hQuery:query-open(). hQuery:get-first(). dowhilehBuffer:available: cKey = hBuffer::CustNum. cText = hBuffer::Name. oNode = oParent:Nodes:Add(cKey, cText). oNode:Tag = 'Some extra info'. • oData contains filled ProDataSet • DatasetHandle property same as handle variable • BindingSource uses ProDataSet • Nodes property collection of Node objects • Query stuff is all standardABL • Can work on new node
DecorateCustomerNodes() method defvaroCustomerNodesasTreeNodeCollection. oCustomerNodes = treeView1:Nodes['CustomerNode']:Nodes. doiLoop = 0tooCustomerNodes:Count - 1: oNode = oCustomerNodes[iLoop]. /* hBuffer from oData, as earlier */ hBuffer:find-unique( ' where CustNum = ' + quoter(oNode:Name)). dPercent = hBuffer::Balance / hBuffer::CreditLimit * 100. ifdPercent > 90then oNode:BackColor = System.Drawing.Color:Red. • Get node by name or by index • Zero-based counting • Standard ABL query finds data to manipulate .NET UI • Node colour based on business rules
Customer data binding • OneBindingSource binds to oneProDataSet providing multi-level data to UI controls • Automatic “linkednavigation” via ProDataSet data-relations • WICKEDcool, no? CustomerBindingSource Orders OrderLines Items
ProBindingSource: Binding UI controls to an ABL query • Not using ProDataSets? Use a query instead • Can even query PDS data • Always single-level to UI • Provides data to multiple controls SalesrepBindingSource createqueryhQuery. hQuery:query-prepare('for each eSalesrep'). bsSalesrep:Handle = hQuery.
Sorting the DataGridView • Standard event handler signature • Sorting location depends on control, could be on grid or BindingSource • Identity is not equality • Build standard ABL query off event args • Easily make this generic methodvoidBindingSource_SortRequest( sender asSystem.Object, easProgress.Data.SortRequestEventArgs): ifsender:Equals(bsSalesrep) then do: hQuery = bsSalesrep:Handle. cSortBy = ' by ' + e:FieldName. ifnot e:Ascending then cSortBy = cSortBy + ' desc '. hQuery:query-prepare ('for each eSalesrep ' + cSortBy). hQuery:query-open(). end. end method.
Alternate controls: same data, same business logic, much prettier, different & more features • Microsoft controls do the basics • Vendor-specific functionality • Grouping, multi-column sorting, multi-level browsing • Filters, aggregates • Themes / skins • Presentation layer design opportunity: OERA, MVP et al
What you see is .NET, what you get is ABL • .NET … • Paints stuff on screen • Fires UI events : Click, Resize, Sort • ABL … • Works with data • Temp-tables, queries, ProDataSets • Built-in ProBindingSource talks both ways • Handles UI events • Invokes methods & classes, set properties • Same on all types: OO ABL and .NET
Where can I learn more? • Right here at ExchangeOnlineOhNine • Shelley Chase’s Introducing OpenEdge GUI for .NET • Alex Herbstritt’s Advanced OO Techniques • Niels Bredegaard’s Tales from the Trenches: Using the GUI for .NET • OpenEdge Documentation’s Getting Started books • Object Oriented Programming • Introducing the OpenEdge Architect Visual Designer • GUI for .NET Mapping Reference • GUI for .NET Programming • OpenEdge Architect : Class browser, help files, etc • Progress Communities discussions (forums) • 3rd party control vendors’ documentation, support, forums • MSDN
Conclusion • Pretty easy, right? • It’s Just ABL … and you’re all experts in ABL • From the ABL, you don’t care if it’s .NET
Peter Judge Principal Software Engineer, OpenEdge Development pjudge@progress.com