PowerBuilder常用代码

来源:互联网 发布:音乐初学者自学软件 编辑:程序博客网 时间:2024/05/13 18:04

-----------------------------------------------0001-----------------------------------------
                                            //datastore的用法
Integer ll_tmp , ll_rowcount
String ls_no,ls_name
datastore lds_branch

lds_branch = CREATE datastore
lds_branch.DataObject = 'd_dddw_person'
lds_branch.SetTransObject(sqlca)
ll_rowcount = lds_branch.Retrieve()

if ll_rowcount > 0 then
 for ll_tmp  = 1 TO ll_rowcount
  ls_name = lds_branch.Object.salername[ll_tmp]
  THIS.AddItem(ls_name)
 next
else
 MessageBox("宏力软件提示您",'',stopsign!)
 return
end if
THIS.AddItem('全部')
THIS.SelectItem( '全部',1)

//另一种使用方法:
String ls_sql,ls_syntax,ls_errors
datastore lds_data
ls_sql = "select * from com_dd" + &
 " where type_id=104 and gs_id = '"+String(gc_gs_id)+"' and status = 0 "

ls_syntax = sqlca.SyntaxFromSQL(ls_sql,"style(type=grid)",ls_errors )
if Len( ls_errors ) > 0 then
 MessageBox("宏力软件提示您",ls_errors,stopsign!)
 return
end if

lds_data = CREATE datastore
lds_data.Create(ls_syntax,ls_errors)
if Len( ls_errors ) > 0 then
 MessageBox("宏力软件提示您",ls_errors,stopsign!)
 return
end if

lds_data.SetTransObject(sqlca)
lds_data.Retrieve( )

-----------------------------------------------0002-----------------------------------------
                                    //动态修改数据窗口的where子句
string ls_oldsql,ls_newsql
dw_main.SetTransObject(sqlca)
ls_oldsql = dw_main.Describe("DataWindow.Table.SQLSelect")
ls_newsql = " branch_no='"+os_branchno+"' and supp_no = '"+os_suppno+"'"
//添加where条件
//子数据窗口
gf_add_childwhere(dw_main,ls_newsql)
//数据窗口
gf_add_where(dw_main,ls_newsql)
dw_main.Retrieve()
dw_main.Modify('datawindow.table.select = ~"' + ls_oldsql + '~"')

-----------------------------------------------0003-----------------------------------------
                        //关闭之前检测被修改的数据是否要保存(写在窗口的CloseQuery事件中):
Integer li_rtn
if dw_main .DeletedCount() + dw_main .ModifiedCount() > 0 then
 li_rtn = MessageBox("注意","数据已经被修改,是否存盘?",Question!,YesNoCancel!)
 choose case li_rtn
  case 1
   //this.triggerenevt("clicked")
   if dw_main .Update() = 1 then
    Commit;
    return 0
   else
    Rollback;
    MessageBox("出错","存盘时出错!请检查数据的正确性。")
    return 1
   end if
  case 2
   return 0
  case 3
   return 1
 end choose
end if
-----------------------------------------------0004-----------------------------------------
                        //-----------------------更新-------------------//
if dw_main.Update() = 1 then
 Commit;
 OpenWithParm(w_message,' 保存成功')
else
 Rollback;
 MessageBox("系统提示","保存时出错!请检查数据的正确性。")
end if
return
                               //-----数据窗口单击事件------------
if row < 1 then return

THIS.ScrollToRow( row)
THIS.SetRow( row)
THIS.SelectRow( 0,   FALSE)
THIS.SelectRow( row, TRUE)

                                   //-----添加行-------
Long ll_rownew
ll_rownew = dw_main.InsertRow(0)
dw_main.ScrollToRow(ll_rownew)
dw_main.SetRow(ll_rownew)
dw_main.SetColumn('salername')
//设置默认值
dw_main.setitem['creator',ll_rownew,gs_oper_name]
dw_main.setitem['createtime',ll_rownew,gf_getsysdatetime()]
                                 //-----行或字段状态的获取和设置-------
dw_main.GetItemStatus(dw_main.GetRow(), "Salary", Primary!)
Primary! Delete! Filter!
NotModified! DataModified! New! NewModified!
dw_main.SetItemStatus(5, "Salary", Primary!, NotModified!)


                                      //-删除行代码--
Long ll_getrow
ll_getrow = dw_main.GetRow( )
if ll_getrow < 1 then
  MessageBox("系统提示","请选择要删除的数据行")
  return
else
 //删除前的确认
 if  messagebox('系统提示','确定要删除选中的行吗?',question!,yesno!,1) = 1 then
 dw_main.deleterow( ll_getrow )
 /*   if dw_main.update( ) = 1 then
  commit;
  openwithparm(w_message,'删除成功')
 else
  rollback ;
  messagebox('系统提示','删除失败!')
 end if            */
 end if 
 
end if

                            //----------字段为空判断---------
if Trim() = '' OR IsNull() then
 MessageBox("系统提示","不能为空!")
 return
end if

                               //---敲回车键焦点转到下一列的代码(在事件ue_keyenter中):
Long i, j, k, h,tab,colnum, maxtab, n
String setting
i = GetColumn()
if IsNull(i) = FALSE AND i > 0 then
 if Describe("#" + String(i) + ".edit.VScrollBar") = "yes" then
  return 1
 end if
end if
if GetRow() = RowCount() then
 tab = Long(Describe("#" + String(i) + ".TabSequence"))
 colnum = Long(Object.datawindow.column.count)
 for j = 1 TO colnum
  if Left(Describe("#" + String(j) + ".visible"),1) = "0" then
  else
   if Left(Describe("#" + String(j) + ".protect"),1) = "1" then
   else
    k = Long(Describe("#" + String(j) + ".TabSequence"))
    if maxtab < k then
     maxtab = k
    end if
   end if
  end if
 next
 if tab >= maxtab then
  AcceptText()
  PARENT.TriggerEvent( "ue_new") //开始新的一行
  //最好在新的一行中添加:dw_main.setcolumn( '第一列')
  return 1
 end if
end if
Send(Handle(THIS),256,9,0)
return 1

                        //--------------获取数据窗口对象全部的列名
Long ll_ColCount
String ls_colname
ll_ColCount = Long(dw_main.Describe("datawindow.column.count"))
for ll_t = 1 TO ll_ColCount //列循环
 ls_colname = dw_main.Describe('#' + String(ll_t) + ".name")
next

-----------------------------------------------0005-----------------------------------------
                          //删除重复数据,时间日期型过滤及find用法
DateTime  start_date_time,end_date_time
Long      ll_ColCount ,ll_insertrow , ll_tmprow,ll_tmpcol ,ll_rowcount
String    ls_findconditon , ls_tmpname
dw_main.AcceptText( )
ll_rowcount = dw_main.RowCount( )
for ll_tmprow = ll_rowcount TO  1 STEP - 1
 ldt_tmp   = dw_main.GetItemDateTime(ll_tmprow, "operationtime")
 ls_tmpname = dw_main.GetItemString(ll_tmprow, "patientname")
 ls_findconditon = "operationtime = DateTime ('" +String(ldt_tmp) + "') and patientname='" + String(ls_tmpname) + "'"
 if ll_tmprow > 1 then //必须是大于1
  if dw_main.Find(ls_findconditon,ll_tmprow - 1 ,1) > 0 then
   dw_main.DeleteRow(ll_tmprow)
  end if
 end if
next

-----------------------------------------------0006-----------------------------------------
                         //不适用rowscopy实现两个数据窗口之间的数据copy
Long ll_ColCount,ll_insertrow, ll_tmprow,ll_tmpcol,ll_rowcount
ll_ColCount = Long(dw_import.Describe("datawindow.column.count"))
ll_rowcount = dw_import.RowCount( )
for ll_tmprow = 1 TO ll_rowcount
 ll_insertrow = dw_main.InsertRow( 0)
 for ll_tmpcol = 1 TO ll_ColCount
   dw_main.Object.Data.Primary[ll_insertrow,ll_tmpcol] = dw_import.Object.Data.Primary[ll_tmprow,ll_tmpcol]
 next
next


-----------------------------------------------0007-----------------------------------------
                                   //对SQL语句执行后的判断:
Int  li_code
String ls_err
ls_err  = sqlca.SQLErrText
li_code = sqlca.SQLCode
if li_code = 0 then
 Commit;
 OpenWithParm(w_message,'成功!')
elseif li_code =  100 then
 MessageBox('系统提示','没有符合条件的记录' )
elseif li_code = - 1 then
 Rollback;
 MessageBox('系统提示','SQL语句在执行过程中发生错误:' + ls_err)
end if
return


//---------------------------------------------0008--------------------------------------------
                          //--------------下拉数据窗口常用方法
//一  声明
DataWindowChild idwc_tmp
//二 在ue_open时间中检验下拉数据窗口的合理性并将其提出来
if dw_main.GetChild('suppid',idwc_tmp) = 1 then
 idwc_tmp.settransobject( sqlca)
 idwc_tmp.retrieve()
else
 MessageBox('数据窗口提示','没有下拉数据窗口出错!')
 return 1
end if
//三 用来过滤(在dw_main的EditChanged事件中)
THIS.AcceptText( )
if row < 1 then return
String ls_suppno,ls_filter
if dwo.Name = "suppid" then
 ls_suppno = THIS.Object.suppid[row]
 if ls_suppno = '' OR IsNull(ls_suppno) then
 else
  ls_filter = "factory_num like'"+ls_suppno+"%'"
  if idwc_tmp.SetFilter(ls_filter) <> 1 then
   MessageBox('过滤失败',ls_filter)
   return 1
  end if
  idwc_tmp.Filter()
  idwc_tmp.SetFilter('')
 end if
end if
//四 用下拉数据窗口中的字段来赋值(在使用回车键的时间中)itemchanged
dw_main.Object.TYPE[dw_main.GetRow()] = idwc_tmp.GetItemString( idwc_tmp.GetRow(), 'type')

//---------------------------------------------0009--------------------------------------------
//oracle将字符型转化成DateTime类型:
 >= to_date('2009-12-16 00:00:01','yyyy-mm-dd hh24:mi:ss')
//字符型转化为Date型
 = to_date('2009-12-16 ','yyyy-mm-dd ')

//由字符型的日期合并成时间日期型
DateTime  ldt_begin ,ldt_end
ldt_begin = DateTime(Date(tab_1.tabpage_1.uo_1.em_1.Text),00:00:00)
ldt_end = DateTime(Date(tab_1.tabpage_1.uo_1.em_2.Text),23:59:59)
//---------------------------------------------0010--------------------------------------------
                                     //-----更改打印方式-----
Int li_PrintOrientation
//默认的打印方式
li_PrintOrientation = Integer(dw_main.Describe('dw_main.Object.DataWindow.Print.Orientation'))
dw_main.Object.datawindow.Print.Orientation = 1 //横向打印
dw_main.Object.datawindow.Print.Orientation = 2 //Portrait 纵向
//恢复原来的打印方式
dw_main.Object.datawindow.Print.Orientation = li_PrintOrientation

原创粉丝点击