pb data window setting operation

1 so that only the additional columns can not be modified DataWindow
how the DataWindow data only adds a new record can not be modified, using the Column Protect property easy to do this, as follows:
the Protect property of each column:
If (IsRowNew (), 0, 1))
can be modified dynamically in PowerScript Protect property:
dw_1.Modify ( "column_name_here.Protect = '~. 1 tIf (IsRowNew (), 0,1)'")
Thus, DataWindow only newly added records can be modified, while other records are read-only.

2 how the columns in the DataWindow automatically wrap
us in a PowerBuilder application development process, the use DataWindow, often encounter
case to a column of data is too long, can not show all. If automatic horizontal scrolling operation from
be simple and not following describes a method to realize the multi-line display column data, i.e., to achieve self-column data.
actuator wrapped following steps:
1) open DataWindow in the DataWindow Painter
2) needs to be set in automatic Double-click the mouse on a column, this column bounce the properties window break a line.
3) select the Position tab, select Autosize Height check box.
4) select Edit label, do not select Auto Horz Scroll check box.
5) click the OK button to save your changes.
6) points Detail band (Detail that is written with a long gray), click the right mouse button and select
Properties ... menu item.
7) select the Autosize Height check box.
8) click . the OK button to save the changes made
9) the DataWindow save this.
Note:
together characters (with no punctuation or space separated), the system will be a word that is not
automatically performed off line.

3 in the data window real Animation
To achieve the animation, you must have a timer in the data window already has a timer, double-click data window will pop-up dialog box, Timer Interval defined value greater than zero there is a timer (accurate to milliseconds), With this timer you can achieve animation. For example, to change the background color of a field can be provided
ackgound.color = RGB (Integer (Right ( string (now (), 'hhmmssf'), 1)) * 256/10, Integer (Right (string (now (), 'hhmmssf'), 1)) * 256 / 10,0)
  Of course, you can not only change the background color, and you can change any attribute fonts, etc., so that he can move up!

4 so that the selected row in the data window has a better appearance
We all know that, in the selection of a row in the data window, if you use select function SelectRow pb provided (), so really can not compliment the appearance, monotonous and old-fashioned blue background, may be beautiful and vivid and your application out of tune. There is no way to change it? Of course there are Hello, please listen to me slowly come.
  Change the background of a row of relatively simple, change the background properties of each column (backgroundcolor) can be, you had better change automatically selected according to the mouse, and can return the selected lines may also need certain skills. The following points single row and multiple row selection resolution selection instructions.
Selecting a single row
  single row selection is relatively simple, we will just background color to all fields expression:
IF (GetRow () = CurrentRow (), the RGB (255,126,0), the RGB (0,0,0))
  wherein the first color for the selected color, the second color is not selected color. Then GetRow () instead of getSelectedRow () function to get the selected row.
Select multiple rows
  Multi-row selection is more complex, if relying solely on changing the properties of the data window can not achieve, we must use the data and code window attributes combine to achieve
  First, change the data window SQL statement, add a calculated field: 0 as flag, Select statement changed:
the select col1, col2, 1 aS TableName Flag from the WHERE .....,
  when returning DataWindow painter, you'll find more than one field flag, we are using the information in this field holds the line is selected.
  Next, change the background color attribute of each field is set to: if (flag = 1, RGB (255,126,0), RGB (255,255,255))
  Third: in the data window control, increased handling of clicked event code is as follows:
row IF <. 1 SetRedraw the then // return (to false)
IF this.objec t.flag [row]. 1 = the then // if the row is selected, deselected, or select the line
 this.Object.flag [row] = 0
the else
 this.Object.flag [Row]. 1 =
End IF
SetRedraw (to true)

You can also customize the font, text attributes this selected row, and so on. The same principle will not be repeated.

5 date fields are initialized to the current date
   to set the initial value of the data is a better and more generic method Column Specifications dialog box. To date fields are initialized to today's date, as long as the initialization value provided Today, rather than today () can be. The same initial value is set NUll, may be used null, not null ().

6 In the DataWindow adjust the order of columns
in Gird-style DataWindow, the order in which the columns are arranged according to your choice Column of order and can not be changed. To change the order the columns, you must re-create the DataWindow.
I recently discovered a way to change column order: open the DataWindow Painter DataWindow to modify, then press the 'preview' button to switch to the preview mode, select the column heading to be moved and drag it to a predetermined position, and then returns DataWindow drawing board, to save.

. 7 Retrieve when not clear existing Datawindow data
when you call the Retrieve function, PowerBuilder and DataWindow Retrieve automatically clear the original data. In Datawindow RetrieveStart event, the use of Return 2, so that PowerBuilder does not clear the original data but append new data.

8 beautify the DataWindow display
Single and double row of the DataWindow display different colors, not only can make your application more professional, and to enhance the readability of data. You need to call out to change the DataWindow, pressing the right button to select Properties, select Tab page expression_rs in the Detail band, enter the following contents in color attributes :( note the details in the Detail section is displayed by right, rather than on the Column) IF (MOD (GETROW (), 2) = 0, RGB (192, 192, 192), RGB (255, 255, 255)) immediately Preview about how look effect.

9 establish pretty Grid DataWindow with Line skills
although there Grid style PowerBuilder DataWindow, but less flexible, if you want to print a broad-brush or wire frame, the inner frame to form fine line directly Grid style DataWindow can not be achieved. So many people are using Tabular style DataWindow, then they used to achieve Line Grid. In other words adjust the line position is a nerve-wracking event hurts my eyes, and once the need to adjust the row height, all the work had to be heavy, try using the following method will greatly reduce your workload: in vertical lines, change properties on expression_rs Tab, input y1 line 0, input rowHeight the y2 line () - 1 horizontal lines, provided y1 and y2 = rowheight () - 5 so PowerBuilder will automatically adjust the line coordinates, you only need to set cross- and the length of the line x1, x2 to the coordinates. Preview immediately look and see the effect! You no longer need because the height of the line changes and re-adjust the line position.

10 How to create a report that follows
the Quantity Running Total
5,000 5,000
2,500 7,500
3,000 10,500
12,000 22,500
  For Running Total column, we can use computed columns: CumulativeSum (Quantity for all), you can achieve incremental summing function.

Confirmation before sending the data buffer 11 in step four data window is determined whether the data type correctly. Such as incorrect ItemError event is triggered. To determine whether the data are consistent with the validity of the rule. If it does not meet the validation rules, the same trigger ItemError event. Determining whether data has been altered. Determine whether the data through ItemChanged event, and if the data ItemChanged repulsion, will trigger ItemError event.

12 How to find the DataWindow conditions as with the data type of Datetime
  1. When looking for a date condition using the following expression when a constant:
   ls_Find = "datetime_col
    = the DateTime ( '1/1/1999')"
  2. Using the following expression when looking for a date condition variables:
   ls_Find = "datetime_col the DateTime = ( '" + ls_Date + "')"
  . 3. When looking for a date condition using the following expression when a DateTime data types:
   ls_Find = "datetime_col DateTime = ( '" + String (ldt_DateTime) + "')"

Window setting data 13 are three ways a Boolean attribute
  PowerBuilder provides three ways to set the data window Boolean attributes, are True / False, 1/0, 'Yes ' / 'No'. For example:
dw_1.Object.address.Visible = 0 = dw_1.Object.address.Visible dw_1.Object.address.Visible = False 'No'
  PowerBuilder attributes are stored in the form of a string of processing, regardless of the value of the attribute is a Boolean type, long integer or character.
For a further understanding can be derived a data window and see its original code can be found even if it is the color properties of the column with the use of double quotes
digital number expressed.

14 How to quickly delete multiple rows in the DataWindow
  in the development process may often have to be multi-row delete operation, generally operate using a loop:
the FOR ll_RowOn = 1 the TO dw_1.RowCount () dw_1.DeleteRow (ll_RowOn) the NEXT
  a the fast way is to delete to delete the row to delete the buffer from the main buffer. For example, to delete all the rows in the buffer:
dw_1.RowsMove (! Dw_1, 1, dw_1.RowCount, Primary !, dw_1, 1, the Delete)
  but do not forget the different filter in the line buffer.

15 does not use the SELECT DISTINCT how to delete duplicate implemented in SQL syntax DataWindow row
  at first you want to display the sort columns of unique values: "city A", then add filter string as follows: "city <> city [-1 ] or GetRow () = 1 "

16 show how the number of rows in each group form a packet of the DataWindow
  when we display line number in each row Datawindow may be a simple expression for the discharge GetRow () computed column. But for the Datawindow packet, respectively, to display the line numbers of each group should be used as the expression
GetRow () - First (GetRow ( ) for Group 1) + 1 computed column.

17 How to change the font color of the column, this column is to remind the user to make changes
  in the Color attribute column, enter the following expression
IF (column_name <> column_name.Original, RGB (255, 0, 0), RGB (0, 0, 0)).
  In this condition, if this column has changed, it is displayed in red, black or display font. This expression is mainly used column_name <> column_name.Original comparison value and the current column of the original column values are the same to achieve the purpose of the determination.

18 in the data window from which a row, but do not filter or delete
  RowsDiscard () function can do this, remove the work it performs in the data window, but it can not be removed row is deleted or make any changes of preservation.

19 How to display the Footer Band DataWindow multi-line display of the current first line data and the line number of the last line
  we look at the two computed column expressions: IF (GetRow () = First (GetRow () FOR Page) , 1, 0) // 1 for the current row of the first page
IF (GetRow () <> 1 AND GetRow () = last (GetRow () FOR page), 1, 0) // 1 is the last line of this page
  provided in the calculated column expression found above by the Footer Band:
'the Rows' + String (First (GetRow () the FOR Page)) +' to '+ String (Last (GetRow () the FOR Page)) +' are displayed '.
This feature can be achieved.

20 so that the data read-only edit window
Sometimes you may need a programming window of data used for display purposes, there may be several ways to achieve this requirement:
1. establishing two data windows, one for editor, for displaying a
2. set the taborder all objects in the data window is 0.
3. may protect the window attribute data columns set to On or Off, and you can not use but protect attribute editing
4 the data window has a read-only attribute is set to datawindow (readonly), it is most convenient to use.

21 duplicates the data window to check
dw_1.SetSort ( "user_id A")
dw_1.Sort ()
dw_1.SetFilter ( "user_id user_id = [-1]")
dw_1.Filter ()
IF dw_1.RowCount ()> 0 the then
Messagebox to ( "note", "user repeat encoding. ")
End iF
dw_1.SetFilter (" ")
dw_1.Filter ()

22 is how the line number of each group are shown in the form of a packet of the DataWindow
---- when we show line numbers for each row of Datawindow, you can put a simple expression for GetRow ()
---- computed column. But for the Datawindow packet, respectively, to display the line numbers of each group should be used as the expression
GetRow () - First (GetRow ( ) for Group 1) + 1 computed column.

23 how to make a window of data columns immobilized column at other cross brace
/////////////////////////////// /////////////////////////////////
// function: to freeze the left of the scroll bar
// Changelog:




Integer = I (this.objec t.datawindow.horizontalscrollposition2)
IF I <ISNULL. 1 or (I) the then return
IF scrollpos> 0 the then
this.objec t.datawindow.horizontalScrollPosition = 0
End IF
the else
I = Integer (this.Object. DataWindow.HorizontalScrollSplit)
IF I <ISNULL. 1 or (I) the then return
IF I> scrollpos the then
this.objec t.datawindow.horizontalScrollPosition2 = I
End IF
End IF

24 in the data window to make wherein if a read-only attribute, that is, does not allow users to modify, then simply the Table Order this column can be set to 0. However, in some cases,
it requires some modifications to the line of this column, and some lines can not be modified, which use to protect the property of the column. Open the properties of the column expression_rs, protect the input condition is determined in the
formula. For example: allow users to modify the newly added records, and retrieved records you can not modify. Discriminant conditions can be written as:
IF (isRowNew (), 0,1)
can be modified dynamically in PowerScript Protect properties:
dw_1.Modify ( "column_name_here.Protect = '1 ~ tIf (IsRowNew (), 0,1)'")
Thus, the DataWindow only the newly added record can be modified, while other records are read-only.

25 controls the number of lines per page in the DATAWINDOW
1, an increase in the computational domain in Datawindow, named: ceil_page, this field must be placed in Detail calculation section,
expression_r input ceiling (getrow () / 25) 25 each represents Print page 25 lines, it can also be a parameter.
2, grouping, select the menu RowsCreate Group, select ceil_page
by ceil_page group, and select New Page On Group Break (meaning change when a new group start page).
3, this computational domain is hidden (write 0 in the visible property in the property page expression_r page).
4, a blank line up:
write the following open event code window:
Long li_count, li_i
li_count = dw_1.retrieve ()
IF MOD (li_count, 25) <> 0 the then
for li_i =. 1 to 25 - MOD (li_count, 25 )
dw_1.insertrow (0)
the Next
End IF

CloseQuery 26 event data window: prompt to save data
dw_1.AcceptText ()
Dw_1.ModifiedCount IF () + dw_1.DeletedCount ()> 0 THEN
CHOOSE the CASE MessageBox ( "Operation Tips", "Data has changed, whether to save?" Question!, YesNoCancel!, 1)
the CASE 1
cb_save.TriggerEvent (clicked !)
the cASE 2
the Return 0 // close the window without doing anything
the cASE 3
the Return does not run 1 // Close Event, to maintain the original case
END CHOOSE
END IF

27 Getchild function is used primarily to obtain a data sub-window data window
this function can be used in two cases, 1, remove the pull-down window data window object data;
a data window object 2, taken style composite (Composite) in the subdata embedded window object.
Syntax: Integer dwcontrol.GetChild (String name, the REF DataWindowChild
dwchildvariable)

Example 1 This program fetch a composite of two sub-data window object data window, and filtering them, and sort operations.

 

Ls_filter String
DataWindowChild dwc_czrw, dwc_czx // define sub data window variables
dw_dy.Settranso bject (SQLCA)
dw_dy.Retrieve ()
dw_dy.GetChild ( "dw_2", dwc_czrw)
dw_dy.Getchild ( "dw_1", dwc_czx)
ls_filter = "czrw_bh = ' "+ dw_3.GetItemString (dw_3.GetRow () ," czrw_bh ") +"' "// filter condition
dwc_czrw.SetFilter (ls_filter)
dwc_czrw.Filter ()
ls_filter =" czx_rwbh = ' "+ dw_3.GetItemString (dw_3. GetRow (), "czrw_bh") + " '"
dwc_czx.SetSort ( "czx_sx A")
dwc_czx.Sort ()
dwc_czx.SetFilter (ls_filter)
dwc_czx.filter ()
of course be shared by the data (ShareData) sub-operations, etc. data window.
Composite window object data access methods:. Dw_dy.objec t.dw_1.objec t.



Ls_nowFld String, ls_deptid, ls_sql
DataWindowChild fld_child
rtncode = dw_1.GetChild ( "Unit_id" fld_child) // get Unit_id field name drop-down data window handle
If rtncode = -1 Then MessageBox ( "Error!", "Is not a drop-down data window! ")
fld_child.SetTransObject (SQLCA) // set transaction object
ls_sql = Lower (fld_child.GetSQLSelect ()) // get DDDW SQL statements
// remove Sql statement Where condition clause, such as the original Sql statement shall Where conditional clause, where need for a more
// complex processing, as the case may be.
Pos IF (ls_sql, "WHERE")> = 0 the then ls_sql Left (ls_sql, Pos (ls_sql, "WHERE"))
// reset condition Sql statement Where clause
ls_deptid = dw_1.Object.dept_id [GetRow () ] // get the current value of the selected dept_id
ls_sql ls_sql + = "the Where dept_id = '" + Trim (ls_deptid) + "'"
// reset Sql statement
fld_child.SetSQLSelect (ls_sql)
fld_child.


Single: dept_id Suppose we want to read the first data field can be expressed by the following manner :li_id = dw_1.objec t.dept_id [1]
Suppose we first data row to read the second field, can be used represents the following manner :ls_name = dw_1.objec t.DATA [1,2]
Suppose we want to read all the data dept_id field can be expressed by the following manner :li_array = dw_1.objec t.dept_id.CURRENT
Suppose we want to read filter dept_id first data field in the buffer (filter buffer), it can be expressed by the following manner dw_1.objec t.dept_id.Filter = :li_id
[. 1]
Suppose we want to read from the first field of the second data to the pen data between two field data of the third pen, represents :lstr_array = dw_1.objec t.DATA [2,1,3,2]
Suppose we want to read the entire data of the second pen can be expressed by the following manner: lstr_dept = dw_1.objec t.DATA [2]
using GetItemX () function is the string number x and the like
lstr_name = dw_1.getitemstring (li_count, "emp_name ") li_count which one of
a plurality of: ls_name String []
ls_name = dw_ 1.objec t.emp_name.current
read data generally Format: data window control .Retrieve () returns the number of, error -1
Increase in the data window control .InsertRow (number of rows) parameter is added to the last 0
data deleting data window control .Deleterow (rows)
filtering l .SetFilter data window control data (criteria string). 
Data window control .Filter ( ) usage: data does not meet the filter criteria in the main buffer (Primary buffer) moved filtration buffer (filter buffer)
inside.
Examples: string ls_exp ls_exp = "dept_id = 100" dw_1.SetFilter (ls_exp) dw_1.Filter ()
Sort dw_1.SetSort ( "dept_id") dw_1.Sort ( )
remove the data from all the dw_1 buffer (Buffer) in. RESET ()
calculates the number of data. E.g. :dw_1.Rowcount () similar to: .DeletedCount () .ModifiedCount () .FilteredCount ()
data window scrolling window controls data .ScrollToRow (rows)

29 to change the data window attributes:
Description Data color window object itself, can be expressed as :long ll_color ll_color = dw_emplist.Describe ( "DataWindow.Color ")
describes the color data of the window object header dept_id_t can be expressed as follows :long ll_color ll_color = dw_emplist.Describe ( "dept_id_t.Color ")
Modify color data window object itself, can be expressed as follows: dw_emplist.Modify ( "DataWindow.Color = 255" )
within the data window object header dept_id modify color, can be expressed as follows :dw_emplist.Modify ( "dept_id_t.Color = 255")
is assumed when we want to allow them a downstream conditions in the operational phase of the program: salary more than 50000 red, black display is below 50000. Written procedures are as follows:
ls_modstring = "Salary.Color = '0 ~ tIf (the Salary> 50000,255,0)'"
dw_1.Modify (ls_modstring)

30 to obtain the current band is located referents mouse
String str_band
str_band GetBandAtPointer = ( ) // get the current mouse location referents band
str_band = left (str_band, (pos (str_band, '~ t') - 1)) // obtain "header", "detail" and so
if str_band <> 'header 'then return // click the non-head area, exit
31 to get the mouse pointer to the column name of the object
str_o bject = GetObjectAtPointer () // get the current mouse referent name
str_o bject = left (str_o bject, (pos (str_o bject,' ~ t '

= left str_column (str_o bject, (len (str_title) - 2))
// determine whether the name of the column name
'!' if this.describe (str_column + ". band") = then return // Non-column name, that column headings are not named in the normal law.

32 to obtain the current row, column, the head office, for the purposes of the column // this data window
li_col = this.GetColumn ()
li_ColCount = Long (DESCRIBE (the this, "datawindow.column.count"))
ll_row = this.GetRow ()
ll_RowCount this.RowCount = ()
// sets the current row, column
scrolltorow (the this, ll_Row)
setrow (the this, ll_Row)
setColumn (the this, li_col)
this.SetFocus ()

33 to give the column headers
ll_colnum = Long (dw_1.objec t.datawindow.column.count)
for I =. 1 to ll_colnum
// give the title name of the header
ls_colname = dw_1.describe ( '#' + string (i) + ". name ") +" _t is "
ls_value = dw_1.describe (ls_colname +" .text ")
Next

How to get the value 34 aggregated with the data window is computed columns in code?  
String ls_value
ls_value = dw_1.Describe ( "uate (" 'compute_1',. 1) ")
If the value type to be converted.

35 acquired clicking column heading, column name, the database field name
String ls_dwo
Long ll_pos
String ls_type
String ls_title
String ls_column
String ls_dbname
IF Not the KeyDown (KeyControl!) the then return
ls_dwo = dwo.Name
IF TRIM (ls_dwo) = '' or ISNULL (ls_dwo) the then return
ls_type = This .describe (ls_dwo + '.Type')
IF ls_type = 'column' the then
ls_title = This.describe (ls_dwo + '_t.text') // title
ls_column = This.describe (ls_dwo + '.Name ') // data window column name
ls_dbname = This.describe (ls_dwo + '.dbname ') // database field name
MessageBox ( 'information', 'Title text: '+ ls_title + &
'~ r ~ n data window Column name:' + + & ls_column
'~ r ~ n the database field names:' + ls_dbname)
End IF

Window 36 within w_gcde, into a DW_1, how to get the contents of a column value in the column dw_1 yuonghu_id
Method:
Long lng_column_count
Integer I
String str_column [] // column name
string str_column_text [] // text name
  // get the data the total number of columns in the window
  lng_column_count = Long (dw_1.Describe ( "DataWindow.Column.Count"))
  // read cycle sequentially
  for I =. 1 to lng_column_count
  str_column [I] = dw_1.Describe ( "#" + String (I) +. "name")
   str_column_text [I] = dw_1.Describe (str_column [I] + "_t.text")
  Next

37 realized with the currently highlighted row in the mouse moves DDDW
DataWindowChild ldwc_Child
String ls_Pointer
Long ll_Row

GetChild( "dept_id", ldwc_Child ) // Replace the column name "dept_id" as you needed

HwndChild the Handle = IF (ldwc_child) THEN
IF notificationcode = 2311 // DDDW of the then mousemove event
// get the mouse row
ls_Pointer = ldwc_Child.GetObjectAtPointer ()
ll_Row = Long (Mid (ls_Pointer, Pos (ls_Pointer, "~ t") + 1))
// row mouse moves
the IF ldwc_Child.GetRow () <> ll_Row the AND ll_Row> 0 THEN
ldwc_Child.ScrollToRow (ll_Row)
the END the IF
End IF
the END the IF

38 is implemented does not change after completion of printing a page DataWindow
first of datawindow print print output to a file, enter the other print this prn, then print the print file on the line.
Such as:
datawindow_control1.object.datawindow.print.filename = "C: printfilepathexam_1.prn"
datawindow_control2.object.datawindow.print.filename = "C: printfilepathexam_1.prn"
dw_1.print ()
dw_2.print ()
RUN ( "Print // d: \ printservenamesharename" c: printfilepathexam_1.prn ")
// d: \ printer name printservenamesharename

Guess you like

Origin www.cnblogs.com/Bokeyan/p/12095800.html