PB开发笔记(1)

//通过代码更改数据窗口对象的方法
string error_syntaxfromSQL, error_create
string new_sql, new_syntax
new_sql = 'SELECT emp_data.emp_id,emp_data.emp_name from emp_data ' &
          + 'WHERE emp_data.emp_salary>45000'
new_syntax = SQLCA.SyntaxFromSQL(new_sql,'Style(Type=Form)', error_syntaxfromSQL)
IF Len(error_syntaxfromSQL) > 0 THEN          // Display errors
          mle_sfs.Text = error_syntaxfromSQL
ELSE          // Generate new DataWindow
          dw_new.Create(new_syntax, error_create)
          IF Len(error_create) > 0 THEN
                  mle_create.Text = error_create
          END IF
END IF
dw_new.SetTransObject(SQLCA)
dw_new.Retrieve()


//打开动态窗口的方法:
window newarray[3]
string win[3]
int i
win[1] = "w_employee"
win[2] = "w_customer"
win[3] = "w_sales"
for i = 1 to 3
      Open(newarray[i], win[i])
next


//显示一个与Windows操作系统风格一致的About对话框。 首先声明如下外部函数:
function int ShellAboutA(ulong al_hWnd, string as_szApp, string as_szOtherStuff, ulong hIcon) library "shell32"
ShellAboutA(handle(parent),"关于...#摆渡人工作室","欢迎光临摆渡人工作室",0)


//如何将COLUMN的显示风格在EDIT、DDDW、DDLB之间相互切换:
(1)切换成DDDW:
dw_1.Modify("#1.dddw.Name='dddw_jg'")
dw_1.Modify("#1.dddw.DisplayColumn='name_jg'")
dw_1.Modify("#1.dddw.DataColumn='id_jg'")
(2)切换成DDLB:
dw_1.Modify("#1.ddlb.case='any'")        
dw_1.Object.#1.Values ="red~t1/white~t2"
(3)切换成EDIT:
dw_1.Modify("#1.edit.case='any'")
dw_1.Modify("#1.edit.AutoSelect='Yes'")
(4)获取当前风格:
dw_1.Describe("#1.Edit.Style")
(5)如果还不行,可能得要如下操作:
dw_1.Modify("#1.dddw.Name=''")一下;


//在dw_1中选定想要打印的几条记录
long ll_pos
dataStore lds_ds
lds_ds = create dataStore
lds_ds.dataObject = dw_1.dataObject
for ll_pos = 1 to dw_1.rowCount()
     if dw_1.IsSelected(ll_pos) then
               dw_1.RowsCopy(ll_pos,ll_pos,Primary!,lds_ds,lds_ds.rowCount()+1,Primary!)
     end if
next
lds_ds.print()


//实现在循环时可以通过点击按钮终止循环
integer n
//sb_interrupt 是共享变量
sb_interrupt=false
for n=1 to 3000
          yield()
          if sb_interrupt then //sb_interrupt的值在"取消”按纽的Clicked事件中修改为true
                  MessageBox("我不干了","你真坏!")
                  sb_interrupt=false
                  exit
          else //其它处理,在单行编辑器中显示当前n值
                  sle_1.text = string(n)
          end if
next


//SQL语句调用规范
INTEGER li_customer_id = 1
STRING ls_city_code = '501'
PREPARE SQLSA FROM "DELETE bb_customer_info_t WHERE city_code =? AND customer_id = ?" ;
EXECUTE SQLSA USING :ls_city_code,:li_customer_id;


//通过modify函数来同时修改多个表
1、新建一个数据窗口d_grid_dep_emp,它的Select语句为
SELECT department.dept_id,
department.dept_name,
employee.emp_id,
employee.emp_fname,
employee.emp_lname
FROM department, employee
WHERE employee.dept_id = department.dept_id
2、设置数据窗口d_grid_dep_emp的属性,将列的taborder改为非0值;并点击菜单Rows——>Update
Properties,设置此数据窗口Allow Updates,Table to Update设为department,Updateable Columns为
department.dept_id,department.dept_name。
3、在窗口中更新数据窗口按钮的clicked事件编写脚本:
long ll_rtn
// 修改Department表(Department表在第2步已设置为可更新)
ll_rtn = dw_1.update(true, false)
If ll_rtn = 1 then
          //关闭对Department表的修改
          dw_1.Modify("department_dept_name.Update = 'No'")
          dw_1.Modify("department_dept_id.Update = 'No'")
          dw_1.Modify("department_dept_id.Key = 'No'")
          //设置Employee表成为新的可修改表
          dw_1.Modify("DataWindow.Table.UpdateTable = 'employee'")
          dw_1.Modify("employee_emp_id.Update = 'Yes'")
          dw_1.Modify("employee_emp_fname.Update = 'Yes'")
          dw_1.Modify("employee_emp_lname.Update = 'Yes'")
          dw_1.Modify("employee_emp_id.Key = 'Yes'")
          //修改Employee表
          ll_rtn = dw_1.Update()
          IF ll_rtn = 1 THEN
                  COMMIT USING SQLCA;
                  dw_1.retrieve()
                  messagebox('提示信息','更新成功!')
          ELSE
                  ROLLBACK USING SQLCA;
                  MessageBox('提示信息', '更新失败!')
          END IF
          //重置修改标志
          dw_1.Modify("department_dept_name.Update = 'Yes'")
          dw_1.Modify("department_dept_id.Update = 'Yes'")
          dw_1.Modify("department_dept_id.Key = 'Yes'")
          dw_1.Modify("DataWindow.Table.UpdateTable = 'department'")
          dw_1.Modify("employee_emp_id.Update = 'No'")
          dw_1.Modify("employee_emp_fname.Update = 'No'")
          dw_1.Modify("employee_emp_lname.Update = 'No'")
          dw_1.Modify("employee_emp_id.Key = 'No'")
ELSE
          ROLLBACK USING SQLCA;
          MessageBox('提示信息', '更新失败!')
END IF
//可以将以上功能作成一个函数,在必要的时候调用即可。


//单击编辑框选中其中内容  
getfocus事件中书写代码:this.selecttext(1,len(this.text))。保存后运行,却得不到我们想要的
效果。想到了一个另类办法:以pbm_bnclicked为事件ID,创建单行编辑框的自定义事件ue_clicked,
代码是:this.selecttext(1,len(this.text)),
getfocus事件的代码改为:This.Post Event ue_clicked()。保存后运行,效果出来了!


//怎样得到字符串中汉字的个数
For i = 1 to Len(aString)
          ls_ch = Mid(aString,i,1)
          If Asc(ls_ch) >= 128 then //是汉字
                  li_num++
                  i = i+1
          End if
Next  
//最后,li_num就是汉字的个数了


//DW支持双击标题进行排序
String ls_old_sort,ls_column,ls_name,ls_criteria
Char lc_sort
IF Right(dwo.Name,2) = '_t' THEN     //取得是否是列标题名
          ls_column = LEFT(dwo.Name, LEN(String(dwo.Name)) - 2)
          ls_old_sort = this.Describe("Datawindow.Table.sort")
          IF ls_column = LEFT(ls_old_sort,LEN(ls_old_sort) - 2) THEN
                  lc_sort = RIGHT(ls_old_sort,1)
                  IF lc_sort = 'A' THEN
                          lc_sort = 'D'
                  ELSE
                          lc_sort = 'A'
                  END IF
                  this.SetSort(ls_column + " " + lc_sort)
          ELSE
                  ls_criteria = ls_column + " A"
                  this.SetSort(ls_criteria)
          END IF
          this.Sort()
END IF


//DW支持单击按Ctrl或Shift进行多选
int          il_last_row                  //il_last_row为实例变量,记录上次单击的行
int li_current_row          //当前单击行
int li_row                          //中间变量
//未选择就返回
if row = 0 then
          return
else
          li_current_row = row
end if
if keydown(keyshift!) then          //按下SHIFT键
     if il_last_row = 0 then
                  this.selectRow(row,true)
                  il_last_row = li_current_row
          else        
        this.selectRow(0,false)
        if li_current_row > il_last_row then
           for li_row = il_last_row to li_current_row
              this.selectrow(li_row,true)
           end for
        else
           for li_row = il_last_row to li_current_row step -1
              this.selectrow(li_row,true)
           end for
        end if
          end if
else                                                  //未按下SHIFT键
          il_last_row = li_current_row
     if keydown(keycontrol!) then           //按下CTRL键
        if this.isSelected(li_current_row) then
           this.selectrow(li_current_row,false)
        else
           this.selectrow(li_current_row,true)
        end if
     else                                                           //无CTRL键或SHIFT键按下
        this.selectrow(0,false)
        this.selectrow(li_current_row,true)
     end if
end if


//改变DW的查询条件语句
string ls_select,ls_filter
ls_select = dw_1.getSqlSelect()
ls_select = mid(ls_select,1,pos(upper(ls_select),'FROM ')+30)
ls_filter="WHERE service_kind=" + vi_service_kind + " ORDER BY FEE_ID ASC "        
ls_select = ls_select + ls_filter
dw_1.Reset()
dw_1.SetTransObject(SQLCA)
dw_1.SetSQLSelect(ls_select)
dw_1.Retrieve()


//数据窗口的closeQuery事件:提示保存数据
dw_1.AcceptText()
IF dw_1.ModifiedCount() + dw_1.DeletedCount() > 0 THEN
          CHOOSE CASE MessageBox("操作提示","数据已经发生变化,是否保存?",Question!,YesNoCancel!,1)
                  CASE 1        
                          cb_save.TriggerEvent(clicked!)
                  CASE 2        
                          Return 0          //不做任何操作直接关闭窗口
                  CASE 3        
                          Return 1          //不会运行Close Event,维持原来的情况
          END CHOOSE
END IF


//提示:请选择要删除的记录
if dw_2.GetSelectedRow(0)= 0 then
          MessageBox("提示信息","请选择要删除的记录!")
          return
end if


//按某字段进行排序
IF dwo.name = "fee_id_t" THEN
          this.setSort("fee_id a")
          this.sort()
elseif dwo.name = "fee_position_t" then
          this.setsort("fee_position a, fee_id a")
          this.sort()
END IF


//控制DATAWINDOW里每页显示的行数
1、在Datawindow中增加一个计算域,起名为:ceil_page,此计算域必须放在Detail段中,
Expression中输入 ceiling(getrow()/25) 25表示每页打印25行,也可以是一个参数。
2、分组,选择菜单Rows/Create Group,选择ceil_page
按ceil_page分组,并选中New Page On Group Break(意思是新组开始时换页)。
3、将此计算域设为隐藏(在属性页中的expression页中在visible属性中写0)。
4、补空行:
在窗口的open事件中写如下代码:
long li_count,li_i
li_count=dw_1.retrieve()
if mod(li_count,25)<>0 then
          for li_i=1 to 25 - mod(li_count,25)
                  dw_1.insertrow(0)
          next
end if


//如何实现数据窗口数据的自动折行
1) 在DataWindow Painter中打开此DataWindow对象。
2) 在需设定自动折行的列上双击鼠标, 弹开此列的属性窗口。
3) 选择Position标签, 选中Autosize Height 多选框。
4) 选择Edit标签, 不选中Auto Horz Scroll多选框。
5) 单击OK按钮, 保存所做的修改。
6) 点中Detail Band (即写有Detail的灰色长带), 单击鼠标右键, 选择 Properties... 菜单项。
7) 选中Autosize Height多选框。
8) 单击OK按钮, 保存所做的修改。
9) 保存此DataWindow。
注意:连在一起的汉字(中间没有标点或空格分隔), 系统将认为是一个单词, 不会自动进行折行,
英文也是如此……DW窗口折行如果有汉字的话就必需中间加空格才会折行,否则怎样设置都不行。例如你
如果想在第20位折行,就先判断第20位是否是个汉字,如不是就在第20位后加空格,如果是汉字就在
第19位加空格。判断是否是汉字可以用它的ASCII码是否大于127来判断。


//按条件对某行数据进行颜色区分
case(cj when is >= 90 then rgb(255,0,0) when is < 60 then rgb(0,255,0) else rgb(0,0,255)))


//PB中同时连接多个数据库,如连接SQLServer2000和Oracle8
string ls_startupfile
ls_startupfile='hisini.ini'
sqlca.DBMS = ProfileString(ls_startupfile, "database", "dbms", "")
sqlca.database = ProfileString(ls_startupfile, "database", "database", "")
sqlca.userid = ProfileString(ls_startupfile, "database", "userid", "")
sqlca.dbpass = ProfileString(ls_startupfile, "database", "dbpass", "")
sqlca.logid = ProfileString(ls_startupfile, "database", "logid", "")
sqlca.logpass = ProfileString(ls_startupfile, "database", "LogPassWord", "")
sqlca.servername = ProfileString(ls_startupfile, "database", "servername", "")
sqlca.dbparm = ProfileString(ls_startupfile, "database", "dbparm", "")
remote_trans= CREATE transaction
remote_trans.DBMS = ProfileString(ls_startupfile, "Database_remote", "dbms", "")
remote_trans.database = ProfileString(ls_startupfile, "Database_remote", "database", "")
remote_trans.userid = ProfileString(ls_startupfile, "database_remote", "userid", "")
remote_trans.dbpass = ProfileString(ls_startupfile, "database_remote", "dbpass", "")
remote_trans.logid = ProfileString(ls_startupfile, "database_remote", "logid", "")
remote_trans.logpass = ProfileString(ls_startupfile, "database_remote", "LogPassWord", "")
remote_trans.servername = ProfileString(ls_startupfile, "database_remote", "servername", "")
remote_trans.dbparm = ProfileString(ls_startupfile, "database_remote", "dbparm", "")
//附hisini.ini
[Database]
DBMS=MSS Microsoft SQL Server 6.x
Database=his
UserId=
DatabasePassword=
ServerName=.
LogId=sa
Lock=
Prompt=0
computer='11'
ocx= 0
use0='之住院管理'
cfprint='1'
[Database_remote]
DBMS = "O84 Oracle8/8i(8.x.4+)"
ServerName = "oracle8"
LogId = "dba"
Database=zx
UserId=
DatabasePassword=
Lock=
Prompt=0
computer='11'
ocx= 0
cfprint='1'


//PB6.5连接Oracle8i和9i的情况
SQLCA.DBMS = "O84 Oracle8/8i (8.x.4+)"
SQLCA.LogPass = "test"
SQLCA.ServerName = "myora"
SQLCA.LogId = "test"
SQLCA.AutoCommit = False
SQLCA.DBParm = "TableCriteria=',test,''TABLE'',''VIEW'''"


//在检索的数据行上再加上一行记录
dataWindowChild dwc
dw_service.getchild('svcid',dwc)
dwc.settransobject(sqlca)
dwc.retrieve()
dwc.insertrow(1)
dwc.setitem(1,'svcid','00')
dwc.setitem(1,'svcname','不区分')
dw_service.setTransObject(sqlca)
dw_service.Retrieve()


//数据窗口中按enter键实现tab功能(在数据窗口的Enter事件中)
send(handle(this),256,9,long(0,0))
return 1


//send用法:Send(handle,message#,lowword,long)
//This statement scrolls the window w_emp up one page:
Send(Handle(w_emp), 277, 2, 0)
//Both of the following statements click the CommandButton cb_OK:
Send(Handle(Parent), 273, 0, Handle(cb_OK))
cb_OK.TriggerEvent(Clicked!)
//minimizes the DataWindow:
Send(Handle(dw_1), 274, 61472, 0)
//maximizes the DataWindow:
Send(Handle(dw_1), 274, 61488, 0)
//returns the DataWindow to its normal, defined size:
Send(Handle(dw_1), 274, 61728, 0)


//重设数据窗口的检索语句
ls_accept_city = gs_citycode
ld_beg_date = datetime(date(em_assign_beg_date.text),time('00:00:00'))
ld_end_date = datetime(date(em_assign_end_date.text),time('23:59:59'))
ls_where = " WHERE b.assign_date >= :id_begin_date &
          AND b.assign_date <= :id_end_date &
          AND a.register_number = b.register_number &
          AND a.accept_city = :is_accept_city &
          AND a.action = 6 AND current_action = 1 AND status IN(1,-1) "
ls_sql = dw_wp.Describe("DataWindow.Table.Select")
if pos(ls_sql,'WHERE') <> 0 then
          ls_sql = mid(ls_sql,1,pos(ls_sql,'WHERE') - 1)
end if
ls_sql = 'DataWindow.Table.Select=" ' + ls_sql + ls_where + '"'
ls_err_info = dw_wp.modify(ls_sql)
if ls_err_info <> "" then
          messagebox('提示信息','查询异常,请核查' + ls_err_info)
          return
end if
af_connect()
dw_wp.settransobject(sqlca)
dw_wp.retrieve(ld_beg_date,ld_end_date,ls_accept_city)
af_disconnect()

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

bjash

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值