{"id":461,"date":"2010-10-20T20:20:34","date_gmt":"2010-10-21T01:20:34","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=461"},"modified":"2021-03-10T17:52:53","modified_gmt":"2021-03-10T22:52:53","slug":"powerbuilder-item-counter-for-datawindow-entries","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-item-counter-for-datawindow-entries\/","title":{"rendered":"PowerBuilder &#8211; Item counter for datawindow entries"},"content":{"rendered":"<p>This is a PFC based component I build for an application used to create purchasing requisitions. The main datawindow was used to enter new &#8216;documents&#8217; and was too large to allow for more than one row to be visible at a time. Rather than use a common &#8216;vcr&#8217; type control I created one which shows the current row number, the total number of rows, and the ability to go to any row within the total.<\/p>\n<p>The component, u_itemcounter, is inherited from u_dw.<\/p>\n<p>The dataobject, d_itemcounter, has an external datasource with three columns:<\/p>\n<pre name=\"code\" class=\"VB\">table(column=(type=number updatewhereclause=yes name=itmcount dbname=&quot;itmcount&quot; initial=&quot;0&quot; )\n column=(type=char(2) updatewhereclause=yes name=of dbname=&quot;of&quot; initial=&quot;of&quot; )\n column=(type=number updatewhereclause=yes name=itmtotal dbname=&quot;itmtotal&quot; initial=&quot;0&quot; )\n )\n<\/pre>\n<p style=\"text-align: center;\"><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/10\/u_itemcounter.png\"><img loading=\"lazy\" class=\"wp-image-462 size-full aligncenter\" title=\"u_itemcounter\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/10\/u_itemcounter.png\" alt=\"\" width=\"98\" height=\"25\" \/><\/a>Example control<\/p>\n<p>Instance variables:<\/p>\n<pre name=\"code\" class=\"VB\">u_dw\tidw_source\nlong\til_currentrow\nlong\til_rowcount<\/pre>\n<p>The code in the control is as follows:<\/p>\n<pre name=\"code\" class=\"VB\">public function integer of_setsource (ref u_dw adw_source);\n\/\/ sets the source datawindow\ninteger li_return\nli_return = 0\nidw_source = adw_source\nRETURN li_return\nend function\n\npublic subroutine of_setmaxrow (long al_row);\nil_rowcount = al_row\nthis.setitem(1,&#039;itmtotal&#039;,al_row)\nend subroutine\n\npublic function long of_getcurrentrow ();\nRETURN il_currentrow\nend function\n\npublic subroutine of_setcurrentrow (long al_row);\nil_currentrow = al_row\nthis.setitem(1,&#039;itmcount&#039;,al_row)\nend subroutine\n\nevent constructor;call super::constructor;\nthis.of_setbase(TRUE)\nthis.of_SetRowSelect(FALSE)\nthis.of_SetRowManager(FALSE)\nthis.of_SetSort(FALSE)\nthis.setrowfocusindicator(Off!)\nend event\n\nevent losefocus;call super::losefocus;\nlong ll_data\nIF this.rowcount( ) &lt; 1 THEN RETURN \nll_data = this.getitemnumber(1,&#039;itmcount&#039;) \nIF ll_data &gt; il_rowcount THEN\n\tll_data = il_rowcount\nEND IF\nof_setcurrentrow (ll_data)\nidw_source.setrow(il_currentrow)\nidw_source.scrolltorow(il_currentrow)\nend event\n\nevent itemchanged;call super::itemchanged;\nIF long(data) &gt; il_rowcount THEN\n\t\/\/ ERROR CONDITION\n\tRETURN 1\nELSE\n\tof_setcurrentrow (long(data))\n\tidw_source.setrow(row)\n\tidw_source.scrolltorow(row)\nEND IF\nend event\n\nevent type long pfc_insertrow();\ncall super::pfc_insertrow;\nlong\tll_maxrow\nll_maxrow = idw_source.rowcount()\nof_setmaxrow(ll_maxrow)\nof_setcurrentrow(ANCESTORRETURNVALUE)\nRETURN ANCESTORRETURNVALUE\nend event<\/pre>\n<p>To implement the control, place it on your window in a suitable location near the &#8216;master&#8217; datawindow. In my case just above the master datawindow on the left edge. I named the control &#8216;dw_counter.&#8217;<\/p>\n<p>When window opens, master control has three records<\/p>\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample1.png\"><img loading=\"lazy\" class=\" wp-image-1869 aligncenter\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample1-300x174.png\" alt=\"\" width=\"372\" height=\"216\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample1-300x174.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample1-150x87.png 150w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample1.png 653w\" sizes=\"(max-width: 372px) 100vw, 372px\" \/><\/a><\/p>\n<p>In the constructor event of the master datawindow add the following:<\/p>\n<pre name=\"code\" class=\"VB\">u_dw ldw\nldw = THIS\ndw_counter.of_setsource(ldw) \/\/ set the link to the counter object<\/pre>\n<p>In the pfc_addrow method add the following:<\/p>\n<pre name=\"code\" class=\"VB\">long ll_rc\nll_rc = this.rowcount()\nIF (dw_counter.rowcount() &lt; 1) THEN\n\tdw_counter.event trigger pfc_insertrow()\nELSE\n\tdw_counter.of_setmaxrow(ll_rc)\nEND IF\nRETURN ANCESTORRETURNVALUE<\/pre>\n<p>In the pfc_predeleterow method the following:<\/p>\n<pre name=\"code\" class=\"VB\">long ll_row\n\/\/ reset the counter dw\nIF ANCESTORRETURNVALUE = CONTINUE_ACTION THEN\n\tll_row = dw_counter.of_getcurrentrow()\n\tIF (ll_row = this.Rowcount()) THEN\n\t\tdw_counter.of_setcurrentrow(ll_row - 1)\n\t\tdw_counter.of_setmaxrow(ll_row - 1)\n\tELSE\n\t\tdw_counter.of_setmaxrow(this.Rowcount() - 1 )\n\tEND IF\nEND IF\nRETURN ANCESTORRETURNVALUE<\/pre>\n<p>And finally in the scrollvertical event the following:<\/p>\n<pre name=\"code\" class=\"VB\">long ll_row\nstring ls_row\n\/\/ set counter to current row when scrolling\nls_row = this.Object.Datawindow.FirstRowOnPage\nll_row = Long(ls_row)\ndw_counter.of_setcurrentrow(ll_row)<\/pre>\n<p>The master datawindow in the example window contains three records. To set the counter properly when the window opens the following is put in the pfc_postopen event:<\/p>\n<pre name=\"code\" class=\"VB\">dw_counter.event pfc_insertrow() \/\/ makes the control visible<\/pre>\n<p>Just after adding a record.<\/p>\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample2.png\"><img loading=\"lazy\" class=\" wp-image-1866 aligncenter\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample2-300x174.png\" alt=\"\" width=\"417\" height=\"242\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample2-300x174.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample2-150x87.png 150w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample2.png 653w\" sizes=\"(max-width: 417px) 100vw, 417px\" \/><\/a><\/p>\n<p>Moved to record two in the master datawindow<\/p>\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample3.png\"><img loading=\"lazy\" class=\" wp-image-1867 aligncenter\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample3-300x174.png\" alt=\"\" width=\"417\" height=\"242\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample3-300x174.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample3-150x87.png 150w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounterexample3.png 653w\" sizes=\"(max-width: 417px) 100vw, 417px\" \/><\/a><br \/>\nIf you choose to create your component without the PFC you will obviously have to change the code.<\/p>\n<p>Download example window (PFC based) here:\u00a0 <a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/03\/itemcounter.zip\">itemcounter example pbl<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a PFC based component I build for an application used to create purchasing requisitions. The main datawindow was used to enter new &#8216;documents&#8217; and was too large to allow for more than one row to be visible at a time. Rather than use a common &#8216;vcr&#8217; type control I created one which shows&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[21,33,12,16],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/461"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=461"}],"version-history":[{"count":21,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":1874,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/461\/revisions\/1874"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}