1. Trang chủ
  2. » Công Nghệ Thông Tin

POWER BUIDER VÀ CHƯƠNG TRÌNH TỔNG VỤ potx

34 516 5
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 34
Dung lượng 0,93 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

POWER BUIDER VÀ CHƯƠNG TRÌNH TỔNG VỤbiên soạn Đào Công Thới PHẦN I: CÁC CÚ PHÁP POWERBUILDER A Cac kiểu khai báo biến thông dụng Menu im_id //biến kiểu menu menu im_popm //kiểu menu int

Trang 1

POWER BUIDER VÀ CHƯƠNG TRÌNH TỔNG VỤ

(biên soạn Đào Công Thới)

PHẦN I: CÁC CÚ PHÁP POWERBUILDER

A )Cac kiểu khai báo biến thông dụng

Menu im_id //biến kiểu menu

menu im_popm //kiểu menu

int ii_nowrow //kiểu số nguyên lớn hơn kiểu interger(loại bỏ phần thập phân)

vd: - Int(3.2) Int(3.8) trả lại giá trị 3.0

- Int(-3.2)

Int(-3.8) trả lại giá trị là -4

datawindow idw_focus //kiểu dayawindow

boolean ib_ins, ib_upd //kiểu đúng sai

integer lds_ds //kiểu số nguyên

ulong AW_HOR_POSITIVE =1

pipelinez guo_pipelinez //kiểu dữ liệu được truyền dẫn

string g_transport //kiểu chuổi

long ll_newrow //kiểu số dài

A.1) khai báo biến kiểu currsor(kiểu con trỏ)

DECLARE emp_curs CURSOR FOR //khai báo biến cursor

SELECT emp_name FROM EMPLOYEE

WHERE emp_state = :sle_1.text;

string emp_name_var

OPEN emp_curs;

FETCH emp_curs INTO :emp_name_var;

// vòng lặp đến khi nào không còn dữ liệu mới ngừng

Trang 2

B) cách thiết lập menu(thong qua ví dụ từ chương trình tổng vụ)

-khai báo hai dang menu

+dạng menu trên thanh tasbar menu im_id

+dang menu popup menu im_popm

-thiết lập form sử dụng menu nào(thông qua biến)

Trong sự kiện open trên form

im_id = this.menuid //sử dụng chính menu trên form này

im_popm = create m_sheet //sử dụng menu m_sheet(menu này dạng popup)-đây là cách kiểm tra xem popup khác menu tasbar chổ nào

Ví dụ:

1-//biến chỉ đến menu tasbar là im_id //item trước là vị trí menu cha,item sau là vị trí menu conim_id.item[1].item[1].Enabled = TRUE // saveim_id.item[1].item[2].Enabled = FALSE // printim_id.item[1].item[5].Enabled = FALSE // queryim_id.item[4].item[1].Enabled = FALSE // newim_id.item[4].item[2].Enabled = FALSE // modifyim_id.item[4].item[3].Enabled = FALSE // deleteim_id.item[4].item[4].Enabled = TRUE // cancel

// biến chỉ dến menu popup là im_popmim_popm.item[4].item[1].Enabled = FALSE // newim_popm.item[4].item[2].Enabled = FALSE // modifyim_popm.item[4].item[3].Enabled = FALSE // deleteim_popm.item[4].item[5].Enabled = FALSE // cancelim_popm.item[4].item[7].Enabled = FALSE // save-ví dụ 2

im_id.item[1].item[1].Enabled = FALSE // saveim_id.item[1].item[2].Enabled = FALSE // printim_id.item[1].item[5].Enabled = FALSE // queryim_id.item[4].item[1].Enabled = FALSE // newim_id.item[4].item[2].Enabled = FALSE // modifyim_id.item[4].item[3].Enabled = FALSE // deleteim_id.item[4].item[4].Enabled = FALSE // cancel

im_popm.item[4].item[1].Enabled = FALSE // newim_popm.item[4].item[2].Enabled = FALSE // modifyim_popm.item[4].item[3].Enabled = FALSE // deleteim_popm.item[4].item[5].Enabled = TRUE // cancelim_popm.item[4].item[7].Enabled = TRUE // savesau hai ví dụ ta thấy menu frame sữ dụng cho thanh tasbar ma biến đại diện menu là im_id.Còn menu m_sheet sử dụng cho menu popup biến đại diện là im_popm

Và đây là 2 hình của 2 menu này

Trang 3

Sau khi xem ví dụ cụ thể trên tôi tin rằng bạn dư sức thiết lập menu cho nó hoạt động như thế nào rồi đó

C) các lệnh hoạt động của menu tieu biểu

I) Lệnh tạo một dòng dữ liệu mới (ue_newrow, ue_newrow_d)

ll_newrow = This.InsertRow(0) cho biến này inser một giá trị rỗng(lệnh inser)

(this) mang giá trị của form hay datawindow đang thực thi gọi nó

Trang 4

This.ScrollToRow( ll_newrow ) và giá trị rỗng ấy được đặt ở hàng cuối cùng

Gia tri (this) bây gio đại diện cho dw ii_nowrow = dw_1.GetRow() : đọc vô hàng hiện tại rồi gán biến ii_nowrow bằng giá trị hàng dữ liệu

dw_1.Setfocus() : uu tien cho dw_1(được đặt con trỏ hoặt rê chuột tác động)

II) lệnh lưu lại một dòng vừa inser vào

áp dụng ví dụ từ chương trình

If ii_status=11 or ii_status=12 then //neu chương trình kích hoạt inser or modify thì

If dw_1.AcceptText() = 1 then //kiểm tra xem có dòng dữ liệu chưa

dw_1.TriggerEvent("ue_save") // sau đó gọi đến sự kiện ue_save để thực hiện lệnh save

-ue_save -long ll_del,ll_mod,ll_total //khai báo biến

ll_del = this.DeletedCount() //biến nhận giá trị số dòng bị xóa

ll_mod = this.ModifiedCount() //biến nhận giá trị số dòng bị sữa

ll_total = ll_del + ll_mod

//nếu tổng số dòng thêm mới và số dòng được sữa lớn hơn 0 và lựa chọn update thì lệnh save kích hoạt

IF ll_total > 0 AND this.Update(TRUE,FALSE) = 1 THEN

commit Using SQLCA;

this.ResetUpdate() //lệnh này lưu dòng dữ liệu lại vào cơ sở dữ liệu

ue_save -IF dw_1.ib_save = true THEN

this.TriggerEvent ( 'ue_lostctrl_m' )//sau khi lưu lại lập tức set lại menudw_1.Object.DataWindow.ReadOnly = true

ii_status = 0 //trỡ về ban đầuELSEIF trim(dw_1.GetItemString(dw_1.GetRow(),1)) <> "" THEN

IF dw_1.DeletedCount() + dw_1.ModifiedCount() = 0 THENthis.TriggerEvent ( 'ue_lostctrl_m' )//nếu save không thành công lập tức set lại menu

dw_1.Object.DataWindow.ReadOnly = trueii_status = 0 //trỡ lại ban đầu

dw_1.ib_save = TRUEEND IF

END IFEnd if

End if

//sau khi xem ví dụ này chốt lại lệnh save dữ liệu là this.ResetUpdate()

III) lệnh sữa một dòng dữ liệu(ue_modify, ue_modify_d)

Trang 5

if dw_1.GetRow() > 0 then // nếu xác định có dòng dữ liệu

if Not IsNull(dw_1.GetItemString( dw_1.GetRow(), 1 )) then

this.TriggerEvent ( 'ue_control_m' )//menu được set lạidw_1.Object.DataWindow.ReadOnly="No"

ii_status = 12ii_nowrow = dw_1.GetRow() //dòng hiện tại được phép sữaelse

Messagebox ( "訊訊", "訊訊訊訊訊訊 !!" )// nếu không có dữ liệu để sữa thì thông báoend if

ii_status = 2idw_focus.Triggerevent('ue_modify_d')

ii_nowrow = idw_focus.GetRow()//biến bằng giá trị hiện thời(modify)else

Messagebox ( "訊訊", "訊訊訊訊訊訊訊訊 !!" )end if

IV) lệnh xóa một dòng dữ liệu(ue_deleterow, ue_deleterow_d)

if dw_1.GetRow() > 0 then

if Not IsNull(dw_1.GetItemString( dw_1.GetRow(), 1 )) then

if Messagebox ( "訊訊", "訊訊訊訊訊訊訊訊訊 ??", Question!, OkCancel! ) = 2 then

Return //hỏi xem có xóa dữ liệu không end if

ii_status = 13 dw_1.Triggerevent( 'ue_deleterow' ) //gọi đến sự kiện xóa dòng dw_1.TriggerEvent ( 'ue_save' ) //sau đó lưu lại

Trang 6

ll_currentrow = This.GetRow( )

This.deleterow(ll_currentrow) //xóa dòng dữ liệu

-ket

thúc -V) lệnh cancel lệnh vừa kich hoạt

ví dụ 1 (ue_cancel) lệnh cancel khi sử dụng menu tasbar

if ii_status = 11 then //nếu mà thêm mới thì

dw_1.DeleteRow(dw_1.RowCount()) //xóa dòng hiện thời vừa thêm mới

IF dw_1.RowCount() < 1 THEN //kiểm tra xem dòng hiện tại nếu chưa có thì

dw_1.InsertRow(0) // thể hiện khung datawindow END IF

Else // nếu mà sữa dữ liệu thì

dw_1.object.data.current[dw_1.getrow()] = dw_1.object.data.original[dw_1.getrow()]dw_1.setitemstatus(dw_1.getrow(),0,primary!,NotModified!)

//thiết lập tình trạng không thay đổi dữ liệu ở dw_1

end if

ii_status = 0 //trả về như lúc ban đầu

dw_1.ScrollToRow(dw_1.RowCount()) // cuộn tới hàng kế tiếp

dw_1.Object.DataWindow.ReadOnly="Yes"

dw_1.TriggerEvent("ue_cancel") //goi đến ue_cancel

this.TriggerEvent ( 'ue_lostctrl_m' ) //set lai memu

ELSEIF ii_status = 12 THEN //sữa lại một dòng dữ liệu

this.Object.Data.Current[this.GetRow()] = this.Object.Data.Original[this.GetRow()]this.SetItemStatus(this.GetRow(),0,Primary!,NotModified!)

//set cho tình trạng không thay đổi dữ liệu

END IF

this.Modify("Datawindow.ReadOnly = YES")ii_status = 0 //trỡ lại tình trạng chưa có sự kiện nào kích hoạt -kết thúc ue_cancel -

Ví dụ 2(ue_cancel_d) lệnh cancel khi sử dụng menu popup

if Mod(ii_status, 10) = 1 then //biến ii_status chia cho 10 mà phần dư=1 thì

ii_status = 0 //trở lại tình trạng nguyên thủy

idw_focus.RowsDiscard ( ii_nowrow, idw_focus.RowCount(), Primary! )

else //nếu sữa dữ liệu

Trang 7

this.TriggerEvent ( 'ue_lostctrl_d' ) //set lai menu

(vậy sau khi xét ví dụ trên ta thấy lệnh cancel là lệnh quay lại ban đầu và không thực hiện lệnh Thay đổi dữ liệu)

VI ) các lệnh di chuyển trên dữ liệu( tới,lui,đầu,cuối)

1 ) ue_nexrow(tới dòng kế tiếp)

integer li_count,li_currowli_count = This.RowCount()li_currow = This.getrow()

if li_currow = li_count then

IF IsValid(m_frame) THEN

m_frame.m_edit.m_lastrow.Enabled = FALSEm_frame.m_edit.m_nextrow.Enabled = FALSEm_frame.m_edit.m_firstrow.Enabled = TRUEm_frame.m_edit.m_priorrow.Enabled = TRUEEND IF

else

This.ScrollNextRow( ) // chạy đến dòng kế tiếp

IF IsValid(m_frame) THEN

m_frame.m_edit.m_firstrow.Enabled = TRUEm_frame.m_edit.m_priorrow.Enabled = TRUEEND IF

end ifsetfocus(This)

3 ) ue_firstrow(về dòng đầu tiên)

Trang 8

This.ScrollToRow(0) //về dòng đầu tiênsetfocus(This)

IF IsValid(m_frame) THEN

m_frame.m_edit.m_firstrow.Enabled = FALSEm_frame.m_edit.m_priorrow.Enabled = FALSEm_frame.m_edit.m_lastrow.Enabled = TRUEm_frame.m_edit.m_nextrow.Enabled = TRUEEND IF

4) ue_priorrow (về dòng cuối cùng)

integer li_count,li_currowli_currow = This.getrow()

if li_currow = 1 then

IF IsValid(m_frame) THEN

m_frame.m_edit.m_firstrow.Enabled = FALSEm_frame.m_edit.m_priorrow.Enabled = FALSEm_frame.m_edit.m_lastrow.Enabled = TRUEm_frame.m_edit.m_nextrow.Enabled = TRUEEND IF

else

This.ScrollPriorRow() //về dòng cuối cùng

IF IsValid(m_frame) THEN

m_frame.m_edit.m_lastrow.Enabled = TRUEm_frame.m_edit.m_nextrow.Enabled = TRUEEND IF

end ifsetfocus(This)

VII ) các lệnh di chuyển trên trang báo biểu

1 ) ue_nextpage

This.scrollnextpage() //lệnh di chuyển đến trang kế tiếp

2) ue_priorpage

This.scrollpriorpage() //di chuyển đến trang cuối cùng

D ) các giá trị biến được gán với sự kiện

ii_status = 11: sự kiện ue_newrow(thêm mới một dòng dữ liệu)

ii_status = 0: chưa có sự kiện nào kích hoạt

ii_status = 12: sự kiện ue_modify(sữa chữa lại một dòng cũ)

ii_status = 22: sự kiện ue_modify_d (sữa chữa trên dòng dữ liệu)

ii_status = 13: sự kiện ue_deleterow

ii_status = 23: sự kiện ue_deleterow_d(xóa trên dòng dữ liệu)

ii_startus=1 : sự kiện ue_newrow

ii_status=21 : sự kiện thêm mới

* dw_1.SetTransObject ( SQLCA ) //cho phép thể hiện dw_1

* dw_1.Object.DataWindow.ReadOnly="No" //datawindow này được phép thêm xóa hoặc sữa

* dw_1.Object.DataWindow.ReadOnly="yes” // datawindow này chỉ đọc không làm gì hết

Trang 9

Tương tự:

* dw_1.Object.DataWindow.ReadOnly=false //.datawindow này được phép thêm xóa hoặc sữa

* dw_1.Object.DataWindow.ReadOnly= true //datawindow này chỉ đọc không làm gì hết

E) truyền giá trị từ cột,giá trị đệm vào biến

1) getitem

-diễn giải

Truyền dữ liệu từ cột và hàng xác dịnh vào biến,hoac giá trị lưu trữ ở bộ đệm vào biến

-cú pháp

returnvalue dwcontrol.GetItem (number row, number column )

returnvalue dwcontrol.GetItem (number row, string column )

-ví dụ

var LName = dw_employee.GetItem(3, "emp_name");

đặt giá trị cột emp_name hàng số 3 vào biến lname có kiểu var

hiredate = dw_employee.GetItemDate(3, "first_day")

//lấy giá trị kiểu ngày từ cột first_date hàng số 3 vào biến hiredate

EmpNbr = dw_employee.GetItemNumber(4, "emp_nbr")

// lấy giá trị kiểu số từ hàng 4 cột emp_npr đưa vào biến EmpNprte

Trang 10

cú pháp:

string dwcontrol.GetItemString (number row, number column {, string dwbuffer, boolean originalvalue } )

ví dụ:

String LName

LName = dw_employee.GetItemString(3, "emp_name")

//Biến LName nhận giá trị hàng 3 trong cột có tên emp_name trong DataWindow dw_employee

Dữ liệu hàng 3 cột title được chuyển vào biến start dưới dạng giờ

F )truyền giá trị từ biến vào cột

number dwcontrol.SetItemDate ( number row, string column, Date value )

number dwcontrol.SetItemDate ( number row, number column, Date value )

3)setitemdatetime

-cú pháp:

number dwcontrol.SetItemDateTime ( number row, string column, Date value )

number dwcontrol.SetItemDateTime ( number row, number column, Date value )

4)setitemnumber

-diễn giải:

truyền giá trị số vào hàng cột xác định

-cú pháp:

short dwcontrol.SetItemNumber ( long row, string column, double value )

short dwcontrol.SetItemNumberByColNum ( long row, short column,double value )

5)setitemstatus(thiết lập tình trạng cho ô dữ liệu)

Trang 11

Primary! Số 0 mặc định giá tri khi lấy ra không xóa hay lọc ra

delete! số 1 xóa trong datawindow nhưng không xóa trong csdl

Filter! Số 2 dữ liệu này đã được lọc ra

+giải thích rieng về dwitemstatus

NotModified! Số 0 không được thay đổi

DataModified! Số 1 được thay đổi

new số 2 thêm một hàng mới

NewModified! Số 3 hàng được tạo mới hay sữa mới

-ví dụ

+ dw_history.SetItemStatus(5, "Salary", &Primary!, NotModified!)

thiết lập cột tiền lương mang giá trị nguyên thủy không thể sữa được

+ dw_new_hire.SetItemStatus(5, "emp_status", & Primary!, DataModified!)

Thiet lập cột dòng 5 cột em_status nguyen thủy là sữa dữ liệu

+ dwItemStatus l_status

l_status = dw_rpt.GetItemStatus(5, 0, Primary!)

IF l_status = NewModified! THEN

dw_rpt.SetItemStatus(5, 0, Primary!, DataModified!)

END IF

// Nếu tình trang hiện thời của hàng 5 này thêm mới thì cho phép sữa giá trị mới thêm mới đó

6)setitemstring

-cú pháp:

short dwcontrol.SetItemString ( long row, string column, string value )

short dwcontrol.SetItemStringByColNum ( long row, short column, string value )

-diễn giải:

Truyền giá trị chuổi ký tự vào dòng và cột xác định

-ví dụ:

this.setitem(this.getrow(),’matm_mat_no’,bien):

lấy dữ liệu của biến vào cột(mat_no của bảng matm)

-lấy dữ liệu từ file đuôi ini

ProfileString("C:\PROFILE.INI", "Employee", "Name", "None")

-chuyển dữ liệu vào file đuôi ini

*cú pháp:

SetProfileString ( filename, section, key, value )

Ví dụ thực tế:

setprofilestring(is_ini_file,'database','logid',sle_1.text)setprofilestring(is_ini_file,'database','logpassword',ls_password)setprofilestring(is_ini_file,'database','servername',sle_3.text)

ví dụ :

SetProfileString("C:\PROFILE.INI", "Position", "Title", "MGR")

Trang 12

- is_ini_file = message.stringparm //biến nhận giá trị kiểu chuổi

7) GetFileOpenName

Cú pháp:

GetFileOpenName ( title, pathname, filename {, extension {, filter { , initdir { , aFlag } } } } )

GetFileOpenName ( title, pathname, filename[ ] {, extension {, filter { , initdir { , aFlag } } } } )

ll_value =1 có nghĩa là đã chọn file

ll_value =0 không chọn hoặc cancel

Trang 13

trả lại giá trị "":

Mid("BABE RUTH", 40, 5)trả lại giá trị BE RUTH:

Trả lại giá trị BABE RUTH:

Trim(" BABE RUTH ")string emp_fnameemp_fname = Trim(sle_emp_fname.Text)

3)hàm asc(lấy số trong mã ansi)

IF Asc(ls_name) > 64 and Asc(ls_name) < 91 THEN

4) hàm Mod (chia lấy phần dư)

Round(9.6, 3)

// trả lại giá trị -9.63:

Round(-9.625, 2)//trả lại giá trị 0:

Round(-9.625, -1)

6) hàm truncate (cắt lấy số thập phân tới số xác định)

Trang 14

Ví dụ: đặt giá trị biến num tới số 5:

decimal dec, numdec = 4.8

num = Ceiling(dec)

đặt giá trị biến num là số -4decimal num

num = Ceiling(-4.2) num = Ceiling(-4.8)

8)hàm sqrt (Cho căn bậc 2 của n, n>=0)

Trang 15

14) hàm right (cắt lấy vị trí xác định của chuổi kí tự từ phía bên phải)

Name = Replace(Name, 4, 2, "e")

//Chữ BABE RUTH được thay đổi thành BABY RUTH:Replace("BABE RUTH", 1, 4, "BABY")

//Chuổi kí tự ‘close for vacation’ được thay đổi thành ‘Closed for the Winter:’

Replace("Closed for Vacation", 12, 8, "the Winter")

//Chuổi kí tự ABCDEF được thay bằng ABZZZZ:Replace("ABCDEF", 3, 2, "ZZZZ")

//Chuổi kí tự ABCDEF được thay bằng ABZZZZ:

Trang 16

start_month = Month(date(sle_start_date.Text))

18) hàm date (chuyển chuổi thành dạng ngày)

Cú phap: Date ( string )

Ví dụ:

//trả về giá trị năm 2004 tháng 7 ngày 04 (kiểu ngày)Date("2004/07/04")

Date("2004 July 4")Date("July 4, 2004")

Emp_lname LIKE 'G%'

BETWEEN Nằm trong khoản giá trị cả giá trị đầu và

giá trị cuối

Price BETWEEN 1000 AND 3000

Emp_lname NOT LIKE 'G%'

NOT BETWEEN không nằm trong khoản xác định cả giá

trị đầu và giá trị cuối Price NOT BETWEEN 1000 AND 2000

20) hàm today (lấy ngày giờ hệ thống)

Trang 17

Today()//Nếu ngày tháng hệ thống trước 2003/04/15 thì

date1 = String(order_date,"m-d-yy")

- //trả lại giá trị chuổi là ‘Jan 31, 2001 6 hrs and 8 min’

String(DateTime(2001-01-31, 06:08:00), 'mmm dd, yyyy h "hrs and" m "min"')

22) hàm number (chuyển giá trị chuổi thành số)

Cú pháp:

Number ( string )

Ví dụ:

//trả lại chuổi ‘24’ thành số24Number("24")

23) hàm year (xác định năm của chuổi ngày tháng)

Cú pháp:

Year ( date )

Ví dụ:

Trả lại năm 2005:

Ngày đăng: 02/08/2014, 02:21

w