powerbuilder编程简单入门(个人总结).doc_第1页
powerbuilder编程简单入门(个人总结).doc_第2页
powerbuilder编程简单入门(个人总结).doc_第3页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

2011-4 by 邵家鑫 From Tsinghua一种简单的powerbuilder10数据库编程介绍1、需求分析与数据库建立进行需求分析(需求分析文档),确定数据关系,建立各种数据表,建立数据库(Access),设置ODBC数据源(控制面板-管理工具-数据源ODBC-“用户DSN”菜单下点“添加”选相应的数据源驱动程序,如果用Access2003建立的,则选第三项“Driver do Microsoft Access(*.mdb),然后点击“完成”-输入数据源名,如mydata,然后点击“选择”按钮选择建好的数据库,最后点“确定”,如下图所示)2、界面设计(功能界面、重要数据表维护界面)界面设计主要分为几个部分(1)按照管理系统所需的功能设计界面。首先画出所有可能的业务流程(数据的各种可能输入、修改、删除业务,数据的输出、显示业务)(2)按照需要维护的表设计界面(往往给最高权限管理员直接修改数据用)3、开始程序编写(1) 新建一个workspace(new-workspace-workspace)(2) 在workspace下建立一个目标(new-Target-application),可取名frame(3) 在目标下建一个主窗口可取名w_main,窗体名一般以w_开头(new-PB Object-Window),将其Window Type设为“mdihelp!”(4) 为主窗口建一个主菜单可取名m_frame,菜单名一般以m_开头(new-PB Object-Menu)(5) 程序中设置ODB ODBC点击按钮,选中“ODB ODBC”项,然后单击右边“New”按钮,弹出如下对话框,设置Profile Name和Data Source,如图所示。(6) 建立配置文件配置文件取名“config.ini”,内容如下:MyDBDBMS=ODBCAutoCommit=FalseDBParm=ConnectString=DSN=mydata;UID=;PWD=(7) 自动连接数据库与退出程序关闭数据库的编写首先建立Global Variables如下:string gs_userid,gs_username/登录用户标识、用户姓名string gs_root_path,gs_ini_path/应用路径和主配置文件路径其次申明Global External Functions如下:FUNCTION int GetComputerNameA(ref string computername,ref long size) LIBRARY KERNEL32.DLL alias for GetComputerNameA;AnsiFUNCTION long GetCurrentDirectoryA( long nBufferLength, REF string szBuffer ) LIBRARY KERNEL32.DLL alias for GetCurrentDirectoryA;AnsiFUNCTION long SetCurrentDirectoryA( string szPathName ) LIBRARY KERNEL32.DLL alias for SetCurrentDirectoryA;Ansi/end prototypes在程序的总入口(进入“”)Open事件中写入以下代码:/ Profile moneyandfriendsstring ls_1/设置应用根目录gs_root_path = space(255)GetCurrentDirectoryA( 255, gs_root_path )if right(gs_root_path,1) = thengs_root_path = left(gs_root_path,len(gs_root_path) - 1)end if/设置配置文件路径gs_ini_path = gs_root_path + config.iniIF not FileExists ( gs_ini_path ) THENMessageBox( 找不到配置文件 +gs_ini_path,系统配置错误,stopsign!,ok! )RETURNEND IF/SetProfileString(gs_ini_path,DBMS,ls_1=ProfileString(gs_ini_path,MyDB,DBMS,ODBC)SQLCA.DBMS =ls_1SQLCA.AutoCommit = Falsels_1=ProfileString(gs_ini_path,MyDB,DBParm,error)SQLCA.DBParm = ls_1connect using sqlca;open(w_main)/打开主界面在Close事件中加入如下代码:disCONNECT USING sqlca;(8) 建立新的具体功能窗体(如w_zichuangti)8.1 设置窗体BackColor为“Cream”,输入窗体Title;要在1024*768分辨率下基本满屏,窗体大小可设置为“4645*2748” 8.2在新窗体上一般用GroupBox来划分功能区域,设置该控件的字体为“宋体”,大小为“10”,背景颜色为“Cream” 8.3用静态文本做功能说明或指示,一般加黑,宋体9号字 示例程序界面如下:(9) 响应菜单click事件弹出子窗口(相同子窗口只弹出一次待研究)在菜单下编写代码打开窗体(双击菜单即可在Click事件下编写),简单代码如下:/选择菜单时调出子窗体window lwopensheet(lw,w_ zichuangti,parentwindow,0,Cascaded! )lw.WindowState = Maximized!(10) 相同的子窗口只让弹出一次(代研究)(10) 建立数据窗口(11) 添加新的pbl文件 一般要用不同的pbl文件分类存储不同窗体、数据窗口和菜单等资源;建立新的pbl文件的方法如下:点击工具栏上“Library”按钮,然后在弹出子窗口中进入程序所在文件夹,在工具栏左下有“”创建pbl的按钮。创建好pbl库文件后在目标(如果按前面建立名称为frame的目标,则在“”)上单击右键,选择属性在弹出窗口中可添加Library List,如下图,也可在这里建立新的pbl库文件(12) 如何编译出可运行程序 首先新建一个Project(File-new-Project-Application),如取名p_main 然后打开新建的Project,设置可执行文件生成目录。(13) DataWindow窗口连通数据库dw_1.settransobject(sqlca)(14) 格式化日期(2007-10-05变为20071005)f_format_date函数,输入string变量ps_date,返回stringif isnull(ps_date) then return if len(ps_date) 0 thenif MessageBox(提示,数据没有保存,是否不保存退出?,Question!,YesNo!) =2 thenreturn 1end ifend if4、其他编程4.1 将数据库中数据显示到dropdownlistbox的下拉菜单里建立“f_ddlb_populate”函数,函数输入两个变量:dropdownlistbox:ddlb_this 要显示到的空间名string:as_sql 查询数据库的sql语句函数代码如下:ddlb_this.reset()ddlb_this.additem()string ls_disp, ls_dataDECLARE my_cursor DYNAMIC CURSOR FOR SQLSA ;PREPARE SQLSA FROM :as_sql ;OPEN DYNAMIC my_cursor ;FETCH my_cursor INTO :ls_disp, :ls_data;if isnull(ls_disp) then ls_disp = if isnull(ls_data) then ls_data = do while sqlca.sqlcode = 0 ddlb_this.additem(trim(left(ls_disp+space(200),200) + ls_data)FETCH my_cursor INTO :ls_disp, :ls_data;loopCLOSE my_cursor ;as_sql语句里面需要有两个输出如果ddlb的数据项比较多,一般选中VScrollBar如下调用这个函数:string ls_sqlls_sql=select zcr_bh, from zcr order by zcr_bh;/举例f_ddlb_populate(ddlb_bh,ls_sql) /将ddlb_bh列表框里写入列表项4.2 数据窗口常用几个函数dw_deal.settransobject(sqlca)/连接数据库dw_deal.insertrow(number row):在指定行之前插入一行,如果要在最后一行新增一行,取row=0dw_deal.deleterow(number row):删除指定行,row=0时删除当前行dw_deal.rowcount():返回数据窗口中总行数dw_deal.setitem(li_n,lxr_zpdz,pic)/设置某行某列的数据integer dwcontrol.AcceptText ( ):Applies the contents of the DataWindow controls edit control to the current item in the DataWindow eger dwcontrol.Filter ( ):根据给定过滤条件来列出满足条件的记录,过滤条件由SetFilter函数指定integer dwcontrol.SetFilter ( string format ):设定过滤条件integer dwcontrol.GetColumn ( ):Returns the number of the current column in the DataWindow controlstring dwcontrol.GetColumnName ( ):Returns the name of the current column in the DataWindow control.date dwcontrol.GetItemDate ( long row, string column , DWBuffer dwbuffer , boolean originalvalue )date dwcontrol.GetItemDate ( long row, integer column , DWBuffer dwbuffer, boolean originalvalue )GetItemStringGetItemString():long dwcontrol.GetNextModified (long row, DWBuffer dwbuffer ):SetRow(long row): 设定指定行为当前行GetRow():获得数据窗口中当前行GetSelectedRow ( long row ):获得指定行row后面第一个被选中的行,如没有则返回零integer dwcontrol.SelectRow ( long row, boolean select ):选中指定行IsSelected ( long row ):判断某行是否被选中ScrollToRow ( number row ):窗口数据滚动在指定行,如果row=0则规东到第一行integer dwcontrol.RowsMove ( long startrow, long endrow, DWBuffer , datawindow targetdw, long beforerow, DWBuffer targetbuffer ) 将一个数据窗口的几行数据移到另一个数据窗口。movebuffer和DWBuffer的范围为Primary!、Delete!和Filter!string dwcontrol.Describe ( string propertylist ):返回数据窗口中控件属性string dwcontrol.Modify ( string modstring ) :修改数据窗口中控件属性integer dwcontrol.SetItemStatus(long row, integer column, dwbuffer dwbuffer, dwitemstatus status):改变数据状态,dwitemstatus有以下四种状态NotModified!,DataModified!,New!,NewModified!4.3 数据窗口常用几个事件RetrieveRow event (DataWindows):在一行被检索后响应;返回0则继续,返回1则停止检索4.4 常用SQL语句SELECT *FROM financesWHERE description LIKE gs_ ESCAPE S这里ESCAPE S表示不将s后面的通配符_作为通配符,而只是作为一般的字符4.5 给数据窗口增加条件The following scripts dynamically add a WHERE clause to a DataWindow object that was created with a SELECT statement that did not include a WHERE clause. (Since this example appends a WHERE clause to the original SELECT statement, additional code would be needed to remove a where clause from the original SELECT statement if it had one.) This technique is useful when the arguments in the WHERE clause might change at execution time. The original SELECT statement might be:SELECT employee.emp_id, employee.l_name FROM employeePresumably, the application builds a WHERE clause based on the users choices. The WHERE clause might be:WHERE emp_id 40000The script for the windows Open event stores the original SELECT statement in original_select, an instance variable:dw_emp.SetTransObject(SQLCA)original_select = & dw_emp.Describe(DataWindow.Table.Select)The script for a CommandButtons Clicked event attaches a WHERE clause stored in the instance variable where_clause to original_select and assigns it to the DataWindows Table.Select property:string rc, mod_stringmod_string = DataWindow.Table.Select= & + original_select + where_clause + rc = dw_emp.Modify(mod_string)IF rc = THEN dw_emp.Retrieve( )ELSE MessageBox(Status, Modify Failed + rc)END IF4.6 常用PowerScript语句1) CHOOSE CASE语句CHOOSE CASE WeightCASE IS 0 thenls_front = left(ps_sql, pos(ps_sql, where ) - 1)if pos(ps_sql, group by ) 0 thenls_end = right(ps_sql, len(ps_sql) - pos(ps_sql, group by ) + 1)ls_where = mid(ps_sql, pos(ps_sql, where )+6, len(ps_sql)-len(ls_front)-len(ls_end)-6)elseif pos(ps_sql, order by ) 0 thenls_end = right(ps_sql, len(ps_sql) - pos(ps_sql, order by ) + 1)ls_where = mid(ps_sql, pos(ps_sql, where )+6, len(ps_sql)-len(ls_front)-len(ls_end)-6)elsels_where = mid(ps_sql, pos(ps_sql, where )+6, len(ps_sql)-len(ls_front)-6)end ifls_return = ls_front + where (

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论