作者将以一个例子来详细说明f1的用法,以补充前文所述,此例为电力企业停电申请票的上报审批过程,内含过程权限控制,每一权限只能修改f1报表的一个部分,且有做图功能,采用pb 6.5 和 f1 6 所编,下面将详细说明:
1.建一张申请票的f1文件作为模板,如下图:
为实现权限控制,将i1:p38的单元格设上保护,使右半边报表不可写:
1)、选中单元格,鼠标右键format cells:protection下的locked前打勾。
2)、format菜单下sheet项的protection前打勾,这句很重要,否则上句不起作用。
2.库中建一停电申请票表dfs_tdsqp:
lrsj 录入时间 tdsj 停电时间
lrdw 录入单位
gldw 管理单位
tdsb 停电设备
gznr 工作内容
kgsj 开工时间
wgsj 完工时间
gzr 工作人
ztm 状态码
sqpnr 申请票内容 image类型
3.在pb窗口中插入f1控件:
在powerbuilder的窗口中点中ole图标:会出现“插入对象”对话框,选择insert control 标签项(如下图),
在对象列表中选择 vci formula one workbook,按确定键后,选好插入位置点击鼠标,即加入了一个名为ole_1的ole对象,在其上用鼠标右键选中ocx properties项,在show标签下可将row heading和column heading项取消选中,将tabs的值由bottom改为off(如下图),加入的ole对象就是一个没有行头、列头及标签的空白表格。
4.读模板的内容至控件:
declare instance variables: blob vcf_form declare global variables: string gs_ztm,gs_lrdw,gs_gldw datetime gd_lrsj,gd_tdsj 在窗口的open事件中写脚本: datetime sj int fh string ls_dwmc em_1.text=string(gd_tdsj,"yyyy年mm月dd日hh:mm") selectblob sqpnr into :vcf_form from dfs_tdsqp where lrsj=:gd_lrsj and lrdw=:gs_lrdw using sqlca;//取出库中申请票内容 if isnull(vcf_form) then ole_1.object.read("模板.vts", ref fh)//把模板读入ole控件 ole_1.object.setactivecell(21,2) ole_1.object.entry=string(gd_tdsj,"mm月dd日hh时mm分至")//填入计划停电时间 ole_1.object.setactivecell(4,3) select zz_dwmc into :ls_dwmc from b04 where zz_dwbm=:gs_lrdw; ole_1.object.entry=ls_dwmc//填入计划停电单位 ole_1.object.setactivecell(4,6) ole_1.object.entry=xm//填入姓名 else if fileexists("c:\book1.vts") then filedelete("c:\book1.vts") end if fh=fileopen("c:\book1.vts",streammode!,write!)//建一临时文件 if fh<>-1 then filewrite(fh,vcf_form)//把库中的库中申请票内容写入临时文件 fileclose(fh) ole_1.object.read("c:\book1.vts", ref fh)//把临时文件内容读入控件 else messagebox("错误提示", "打开文件操作错误!") close(this) return end if end if choose case qx case "lr"//权限为二级单位录入时只能录入左半边的报表 ole_1.object.selection="a1:g38" ole_1.object.setprotection(false,false)//将a1:g38的单元格置为可写,其余不可。 ole_1.object.enableprotection=true ole_1.object.selection="c4"//光标停在c4单元格处 case "gl" case "zd" case "zb" end choose |
5.鼠标右键双击ole_1控件可直接编辑报表,填入内容至可写的单元格内,可以采用f1的画图工具对报表进行简单的做图。
6.将已修改的控件内容写入数据库:
int fh oleobject book; string filename="c:\book1.vts" book=ole_1.object book.write(filename, 12)//将控件内容写入临时文件 fh=fileopen( filename, streammode!) if fh<>-1 then fileread(fh, vcf_form) //将临时文件内容写入blob变量 fileclose(fh) else return 0 end if if len(vcf_form )>0 then updateblob dfs_tdsqp set sqpnr=:vcf_form where lrsj=:gd_lrsj and lrdw=:gs_lrdw using sqlca;//将blob变量内容写入库中 if sqlca.sqlcode=0 then commit using sqlca; // messagebox("提示", "完成对数据库的申请票存储操作!") else rollback using sqlca; messagebox("提示", "申请票存储操作失败!") return 0 end if end if gd_tdsj=datetime(date(left(em_1.text,4)+"-"+mid(em_1.text,7,2)+"-"+mid(em_1.text,11,2)),& time(mid(em_1.text,15,5)+":00")) update dfs_tdsqp set tdsj=:gd_tdsj , ztm=:ztm_wf where lrsj=:gd_lrsj and lrdw=:gs_lrdw using sqlca;//保存录入时间和录入单位的值 if sqlca.sqlcode=0 then commit using sqlca; messagebox("提示", "完成对数据库的存储操作!") return 1 else rollback using sqlca; messagebox("提示", "停电时间存储操作失败!") return 0 end if |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器