2012-07-26 80 views
0

我在PowerBuilder 12.5 Classic上使用SetTransObject()和Retrieve()。但是,它不會爲用戶提供檢索數據的強大功能; 我有一個單行編輯(sle_employeeID),用戶需要在僱員ID中插入,而DataWindow顯示所選ID號的僱員數據(IDNO,姓名,年齡,指定)。PowerBuilder通過用戶控件檢索()

dw_1.settransobject(sqlca) 
string employeeID 
employeeID=sle_employee.text 
dw_1.retrieve(employeeID) 

的代碼檢索整個數據按我的規格從數據窗口對象,我用了一個表格和快速的select語句。 請幫助一個代碼,它會給我一個更自由的方式來通過控件選擇數據。

+0

你嘗試過什麼?您可能只需要更多的數據窗口中的檢索參數,以進一步過濾結果。 – Bernard 2012-07-26 18:36:26

+0

@somnath hehehe我聽到你的聲音 – Wepex 2012-07-31 15:37:49

回答

1

您可能需要使用數據窗口的查詢模式作爲特里提及。您必須向用戶提供說明,但基本用法是直接在DataWindow中輸入要匹配的值。有關詳細信息,請參閱主題在「DataWindow程序員指南」中爲用戶提供查詢功能。這是我在我的一個實用程序窗口中的代碼。它使用帶有工具欄按鈕的菜單將DataWindow置於查詢模式,並關閉查詢模式並進行檢索。我在菜單和DataWindow事件之間使用了PFC消息路由,但您可以簡單地通過按鈕單擊事件調用事件,在這種情況下,您會刪除修改菜單的行。

// this code is in an event in the DataWindow 
// toggles query mode on and off 

if "no" = object.dataWindow.queryMode then 
    // you may want to check for unsaved changes here and let the user go back 
    object.dataWindow.queryMode = "yes" 
    m_myMenu.m_rows.m_query.checked = TRUE // this has a button on the toolbar 

else 
    m_myMenu.m_rows.m_query.checked = FALSE 
    acceptText() 
    object.dataWindow.queryMode = "no" 
    retrieve() 

end if 

爲了獲得最大的靈活性,在一些或所有列上設置criteria.override_edit ='yes'。下面的代碼在所有列上設置criteria.override_edit ='yes'。這可能不適合您的情況。沒有override_edit,用戶被限制爲輸入通過列驗證的查詢值。

// this code is in an event in the DataWindow 
// it is called after the DataObject is set 
// it sets criteria.override_edit='yes' for all the columns 

string ls_describe, ls_modify, ls_col, ls_result 
integer li_colCount, li_col 

setTransObject(SQLCA) 
ls_describe = "datawindow.column.count" 
ls_result = dw_1.describe(ls_describe) 
if not isnumber(ls_result) then 
     // logging code elided 
     ls_result = '0' 
end if 
li_colCount = integer(ls_result) 
for li_col = li_colCount to 1 step -1 
    ls_col = "#" + string(li_col) 
    ls_modify = ls_col + ".criteria.override_edit='yes'" 
    ls_result = dw_1.modify(ls_modify) 
    if "" <> ls_result then 
    // every column may not have an edit, and some edits might not   // have the property. it's just as fast to try to modify it as it 
    // is to check it 
     // logging code elided 
    end if 
next 
1

這我不清楚你的期望是什麼,但是這讓我感到SetTransObject()和檢索()正在做你問他們該怎麼做;問題不在那裏。如果創建20個SLE和一個帶有20個參數的DataWindow(以及一個伴隨的SELECT語句足夠複雜,以便在參數爲空時處理跳過參數作爲條件),那麼SetTransObject()和Retrieve()就可以正常工作。

還有就是你可能想看看所謂的實例查詢(QBE)數據窗口的功能。但是,雖然這會爲用戶提供重要的查詢功能,但您可能需要考慮您的用戶是誰。如果用戶擁有數據分析或計算機科學方面的博士學位,那麼QBE就好了;如果用戶是一個懸而未決的臨時僱用電話推銷員,你可能會把他們拋在腦後。

祝你好運,

特里。