PowberBuilder daily code
2009-04-16 11:16
811 查看
PowberBuilder daily code
author:chinayaosir
blog:http://blog.csdn.net/chinayaosir
contents list
0.0 connection ini file
0.2 table struct list
0.3 database procedure (log_user )
1.1 application open script
1.2 application systemerror script
1.3 input win32 api function
2.1 w_main open script
2.2 w_main close() script
3.0 log_user PROCEDURE code
3.1 w_login windows open script
3.2 w_login login button clicked script
3.3 w_login get user authority of gf_authority()
4. w_authority is manage user authority
5.1 open a window with param
5.2 close a windows with param
6.1 open script
6.2 insert script
6.3 delete script
6.4 save script
6.5 find script
6.6 sort script
6.6.1 sort by use choose
6.6.2 sort data as outlook form
6.7 write data into excel script
6.8 read data from excel script
/*********************************************************************************/
0.0connection ini file
0.db.ini
[Database]
DBMS=SYC Adaptive Server Enterprise
Database=database name
LogPassword=logpassword
ServerName=server-computer-name
UserID=
DatabasePassword=
LogId=sa
Lock=
DbParm=Release='11.5'
Prompt=0
/*********************************************************************************/
0.2 table struct list
create table dbo.a_useability (
userof_id char(20) not null,
group_id char(3) not null,
menusite char(4) not null,
r_w_d_p char(4) not null)
alter table dbo.a_useability add constraint a_useability_x
primary key nonclustered (userof_id, group_id, menusite, r_w_d_p)
create table dbo.a_groupclass (
group_id char(3) not null,
groupname char(20) not null,
classtype int not null,
menusite char(4) not null,
r_w_d_p char(4) not null)
alter table dbo.a_groupclass
add constraint a_groupclass_x primary key nonclustered (group_id, menusite, r_w_d_p)
create table dbo.b_coordinator (
coordinaid char(20) not null, coordiname nvarchar(50) not null,
department nvarchar(20) null, competence nvarchar(20) null,
password char(6) null, user_code char(10) not null,
statusflag char(1) null, userofsite char(1) null
)
alter table dbo.b_coordinator
add constraint b_coordinator_x primary key nonclustered (coordinaid, user_code)
/*********************************************************************************/
0.3 database procedure (log_user )
CREATE PROCEDURE log_user(@user_code char(10), @password char(6), @logtype char(1), @result char(1) output )
AS
BEGIN
select @result='1'
if @logtype='0'
begin
/*login*/
if not exists(
select * from b_coordinator /*tablockx*/
where (user_code=upper(@user_code)) and (password=@password) and (statusflag<>'1')
)
begin
/*error user name*/
select @result='1'
raiserror 35007
end
else
begin
update b_coordinator
set statusflag='1'
where (user_code=upper(@user_code)) and (password=@password)
select @result='0'/*success*/
end
end
else
begin
/*logout*/
update b_coordinator
set statusflag='0'
where (user_code=upper(@user_code)) and (password=@password)
select @result='0'/*success*/
end
END
/*********************************************************************************/
1.1 application open script
application open script code
// This script will read all the database values from db.ini
// and store them in SQLCA.
SQLCA.DBMS =ProfileString("db.ini","Database","DBMS", " ")
SQLCA.Database =ProfileString("db.ini","Database","DataBase", " ")
SQLCA.LogID =ProfileString("db.ini","Database","LogID", " ")
SQLCA.LogPass =ProfileString("db.ini","Database","LogPassword", " ")
SQLCA.ServerName =ProfileString("db.ini","Database","ServerName", " ")
SQLCA.UserID =ProfileString("db.ini","Database","UserID", " ")
SQLCA.DBPass =ProfileString("db.ini","Database","DatabasePassword", " ")
SQLCA.Lock =ProfileString("db.ini","Database","Lock", " ")
SQLCA.DbParm =ProfileString("db.ini","Database","DbParm", " ")
connect;
open(w_main)
/*********************************************************************************/
1.2 application systemerror script
if err_sys=1 then
err_sys=0
return
else
open(w_system_error)
end if
/*********************************************************************************/
1.3 input win32 api function
//Global External Functions list
function double GetJpgSize(string filename) library 'jpg.dll'
Function ulong GetModuleFileNameA(ulong hModule,ref string lpFileName,ulong nSize) LIBRARY 'kernel32.dll'
/*********************************************************************************/
2.1 w_main open script
string li_flag='',ls_tile
select tablename.value into :gs_pict
from tablename where tablename.parameter='picture_path';
if sqlca.sqlcode<>0 then li_flag=li_flag+sqlca.sqlerrtext+'PI'
//open login window
open(w_login)
/*********************************************************************************/
2.2 w_main close() script
//Write user left message with log_user PROCEDURE
string ls_code
DECLARE P_loguser PROCEDURE FOR log_user
@user_code = :usercode,
@password = :password_in,
@logtype = '1',
@result = :ls_code OUTPUT;
execute P_loguser;
fetch P_loguser into :ls_code;
close P_loguser;
commit;
if ls_code='0' then
close(this)
else
messagebox('Warning!','Logout is Error !')
end if
/*********************************************************************************/
3.1 w_login windows open script
dw_1.settransobject(sqlca)
dw_1.retrieve(gs_site)
/*********************************************************************************/
3.2 w_login login button clicked script
//Write user login message with log_user PROCEDURE
string ls_code,ls_titl
DECLARE P_loguser PROCEDURE FOR log_user
@user_code = :usercode,
@password = :password_in,
@logtype = '0',
@result = :ls_code OUTPUT;
execute P_loguser;
fetch P_loguser into :ls_code;
close P_loguser;
commit;
if ls_code='0' then
gf_authority()//get user authority
ls_titl=w_main.title
w_mgmanager0.title=ls_titl+space(30)+usercode
close(w_login)
else
messagebox('Warning!','Login is Error !')
st_2.text=''
password=''
opration=''
return
end if
/*********************************************************************************/
3.3 w_login get user authority of gf_authority() script
//system menu default stauts is disable,when find a record from table,then open it
string ls_menuid
declare user_competence cursor for
select menusite from a_useability
where userof_id =:usercode;
open user_competence;
fetch user_competence into :ls_menuid;
do while sqlca.sqlcode = 0
choose case ls_menuid
case '1100'
m_menu.m_1000.m_1100.enabled=true
case '1200'
m_menu.m_1000.m_1200.enabled=true
case '1300'
m_menu.m_1000.m_1300.enabled=true
case '1401'
m_menu.m_1000.m_1400.m_1401.enabled=true
case '1402'
m_menu.m_1000.m_1400.m_1402.enabled=true
case '1501'
m_menu.m_1000.m_1500.m_1501.enabled=true
case '1502'
m_menu.m_1000.m_1500.m_1502.enabled=true
case '2100'
m_menu.m_2000.m_2100.enabled=true
case '2200'
m_menu.m_2000.m_2200.enabled=true
case '2301'
m_menu.m_2000.m_2300.m_2301.enabled=true
case '2302'
m_menu.m_2000.m_2300.m_2302.enabled=true
case '2401'
m_menu.m_2000.m_2400.m_2401.enabled=true
case '2402'
m_menu.m_2000.m_2400.m_2402.enabled=true
/*...*/
end choose
fetch user_competence into :ls_menuid;
loop
close user_competence;
return 1
/*********************************************************************************/
4. w_authority is modify user authority
4.1.1 the datawidnow dw_u is user list
/*dw_u datasource sql code
SELECT DISTINCT b_coordinator.coordinaid,
b_coordinator.coordiname,
a_useability.group_id,
b_coordinator.department,
b_coordinator.user_code
FROM b_coordinator,
a_useability
WHERE ( b_coordinator.user_code *= a_useability.userof_id) and
( ( b_coordinator.userofsite = :site ) )
*/
/****************************************/
4.1.2 w_authority open script
dw_u.settransobject(sqlca)
dw_u.retrieve(gs_site)
4.1.3 dw_u doubleclicked script
/***************************************/
string ls_grou
choose case dwo.name
case 'coordinaid'
is_user=this.object.user_code[row]
dw_pop.retrieve('%',is_user)
dw_pop.visible=true
dw_pop.title=is_user
case 'a_group_id'
is_user=this.object.user_code[row]
ls_grou=this.object.a_group_id[row]
if isnull(ls_grou) then return
dw_pop.retrieve(ls_grou,is_user)
dw_pop.visible=true
dw_pop.title=is_user
end choose
/***************************************/
4.1.4 dw_pop datasource
SELECT a_groupclass.group_id,
a_groupclass.menusite,
a_groupclass.r_w_d_p,
a_useability.userof_id,
a_useability.group_id,
a_useability.menusite,
a_useability.r_w_d_p,
prove=' '
FROM a_groupclass,
a_useability
WHERE ( a_groupclass.group_id *= a_useability.group_id) and
( a_groupclass.menusite *= a_useability.menusite) and
( a_groupclass.r_w_d_p *= a_useability.r_w_d_p) and
( ( a_groupclass.group_id like :grou ) AND
( a_useability.userof_id like :user ) )
/***************************************/
4.1.5 dw_pop doublecliked script
long ll_rows,ii
string ls_site,ls_rwdp,ls_grou,ls_chck
choose case dwo.name
case 't_menu'
this.setsort('#2 A')
this.sort()
case 't_group'
this.setsort('#1 A')
this.sort()
case 'b_s'
this.visible=false
ll_rows=this.rowcount()
for ii=1 to ll_rows
ls_grou=this.object.a_group_id[ii]
ls_rwdp=this.object.a_r_w_d_p[ii]
ls_site=this.object.a_menusite[ii]
ls_chck=this.object.prove[ii]
row_save(ls_grou,ls_site,ls_rwdp,ls_chck)
next
tab_1.tabpage_3.dw_u.retrieve(gs_local)
case 'b_e'
this.visible=false
end choose
/***************************************/
4.1.5.1 row_save function
//function format row_save(ls_grou,ls_site,ls_rwdp,ls_chck)
int li_sele
string ls_grou
select group_id into :ls_grou from a_useability where
(group_id=:grou)and(userof_id=:is_user)and(menusite=:site)and(r_w_d_p=:rwdp);
choose case sqlca.sqlcode
case 0
if chck<>'T' then
delete from a_useability where (group_id=:grou)and
(userof_id=:is_user)and(menusite=:site)and(r_w_d_p=:rwdp);
end if
case 100
if chck='T' then
insert into a_useability (userof_id,group_id,menusite,r_w_d_p)
values (:is_user,:grou,:site,:rwdp);
end if
case else
messagebox('Warning!',sqlca.sqlerrtext)
end choose
/*********************************************************************************/
5.1 open a window with param
//structure str_qsheet
string customer
datetime qsheetdate
string fobport
string itemnumber
integer row
string window
string shipfrom
string shipto
string company
/***********************************/
str_qsheet str_save
int row
row=dw_2.getrow()
str_save.customer=dw_2.object.customerid[row]
str_save.qsheetdate=dw_2.object.qsheetdate[row]
str_save.fobport=dw_2.object.fobport[row]
openwithparm(w_qs_excel_select,str_save)
/***********************************/
//w_qs_excel_select open script
string ls_customer,ls_fobport
datetime ld_qsheetdate
long row,i
str_qsheet str_save
str_save=Message.PowerObjectParm
ls_customer=str_save.customer
ld_qsheetdate=str_save.qsheetdate
ls_fobport=str_save.fobport
dw_1.settransobject(sqlca)
dw_1.retrieve(ls_customer,ld_qsheetdate,ls_fobport)
/*********************************************************************************/
5.2 open a window ,then close it return a param
//datawindow doublecicked script
if row<=0 then return
string item_data=""
choose case dwo.name
case "songid"
openwithparm(w_song,"")
item_data=message.stringparm
if len(item_data) > 0 then
dw_1.object.songid[row]=item_data
string song_name,seconds,version,studio,copyright,haveic,songpath
select song_name,seconds,version,studio,copyright,haveic,songpath
into :song_name,:seconds,:version,:studio,:copyright,:haveic,:songpath
from t_mu_song where songid=:item_data;
dw_1.object.song_name[row]=song_name
dw_1.object.seconds[row]=seconds
dw_1.object.version[row]=version
dw_1.object.studio[row]=studio
dw_1.object.copyright[row]=copyright
dw_1.object.haveic[row]=haveic
dw_1.object.songpath[row]=songpath
end if
end choose
/**************************/
//w_song close script
if dw_1.rowcount()>0 then
string songid
songid=dw_1.object.songid[dw_1.getrow()]
closewithreturn(parent,songid)
end if
//these code return songid into item_data=message.stringparm
/*********************************************************************************/
6. open,insert,delete,save,fresh script
6.1 open script
dw_1.settransobject(sqlca)
/*********************************************************************************/
6.2 insert script
dw_1.setfocus()
dw_1.ScrollToRow(dw_1.insertrow(0))
dw_1.setColumn(1)
dw_1.setfocus()
/*********************************************************************************/
6.3 delete script
integer li_return
li_return = MessageBox("Warning!","Are you true delete data?",Exclamation!,YesNo!,2)
if li_return=1 then
dw_1.deleterow(dw_1.getrow())
if dw_1.update()=1 then
commit using sqlca;
MessageBox("Happy!","Save Data OK!")
else
rollback using sqlca;
MessageBox("Error!","Save Data Fail!")
end if
dw_1.insertrow(0)
end if
/*********************************************************************************/
6.4 save script
string mid
if dw_1.rowcount()>=1 then
mid=dw_1.object.machineid[dw_1.getrow()]
if mid <> "" then
dw_1.object.modifyer[dw_1.getrow()]=g_username
if dw_1.update()=1 then
commit using sqlca;
MessageBox("Happy!","Save Data OK!")
else
rollback using sqlca;
MessageBox("Error!","Save Data Fail!")
end if
//fresh data
dw_1.SetRedraw(FALSE)
dw_1.retrieve(mid)
dw_1.SetRedraw(TRUE)
end if
end if
/*********************************************************************************/
6.5 find script
//find
string s1,s2,s3,s4,s5,s6
s1=trim(sle_1.text)
s2=trim(sle_2.text)
s3=trim(sle_3.text)
s4=trim(sle_4.text)
if s1="" then
s1="%"
else
s1=s1+"%"
end if
if s2="" then
s2="%"
else
s2=s2+"%"
end if
if s3="" then
s3="%"
else
s3="%"+s3+"%"
end if
if s4="" then
s4="%"
else
s4=s4+"%"
end if
//refresh
dw_1.SetRedraw(FALSE)
dw_1.retrieve(s1,s2,s3,s4)
dw_1.SetRedraw(TRUE)
st_rows.text=string(dw_1.rowcount())
/*********************************************************************************/
6.6.1 sort by use choose
sort button script
string st1,st2,st3,sortby,sort_str
st1=trim(ddlb_1.text)
st2=trim(ddlb_2.text)
st3=trim(ddlb_3.text)
sortby=trim(ddlb_sortby.text)
if sortby="升序" then
sortby=" a"
else
sortby=" d"
end if
sort_str=st1+sortby+","+st2+sortby+","+st3+sortby
dw_1.SetRedraw(false)
dw_1.SetSort(sort_str)
dw_1.Sort()
dw_1.SetRedraw(true)
/*******************************************/
6.6.2 sort data as outlook form
clicked data_window script
//1.公用变量定义
//string sortway=" a"
//2.范围检查
if dwo.type <> "text" then return
//----------------------------------
//3.初始化每列的原始值
//
dw_1.object.company_name_t.text="Area"
dw_1.object.department_t.text="Group/Factoryid"
dw_1.object.username_c_t.text="C-name"
dw_1.object.emailname_t.text="email-name"
dw_1.object.company_name_t.color=RGB(0,0,0)
dw_1.object.department_t.color=RGB(0,0,0)
dw_1.object.username_c_t.color=RGB(0,0,0)
dw_1.object.emailname_t.color=RGB(0,0,0)
//4.检查并得到单击的列名
string col_name //desc
col_name=left(dwo.name,len(string(dwo.name)) - 2)
if isnull(col_name) then return
//5.排序处理
if sortway=" a" then
//sort by asc
//5.1a列名上自动添加△和文字变为红色
choose case col_name
case "company_name"
if col_name="company_name" then
dw_1.object.company_name_t.text="Area"+"△"
dw_1.object.company_name_t.color=RGB(255,0,0)
end if
case "department"
if col_name="department" then
dw_1.object.department_t.text="Group/Factoryid"+"△"
dw_1.object.department_t.color=RGB(255,0,0)
end if
case "username_c"
if col_name="username_c" then
dw_1.object.username_c_t.text="C-name"+"△"
dw_1.object.username_c_t.color=RGB(255,0,0)
end if
case "emailname"
if col_name="emailname" then
dw_1.object.emailname_t.text="email-name"+"△"
dw_1.object.emailname_t.color=RGB(255,0,0)
end if
end choose
//5.1b升序处理
this.setsort(col_name+sortway)
this.sort()
sortway=" d"
//----------------------------------
else
//5.2a列名上自动添加▽和文字变为红色
//-----------------------------------
sortway=" d"
//st_sort.text=col_name+"▽"
choose case col_name
case "company_name"
if col_name="company_name" then
dw_1.object.company_name_t.text="Area"+"▽"
dw_1.object.company_name_t.color=RGB(255,0,0)
end if
case "department"
if col_name="department" then
dw_1.object.department_t.text="Group/Factoryid"+"▽"
dw_1.object.department_t.color=RGB(255,0,0)
end if
case "username_c"
if col_name="username_c" then
dw_1.object.username_c_t.text="C-name"+"▽"
dw_1.object.username_c_t.color=RGB(255,0,0)
end if
case "emailname"
if col_name="emailname" then
dw_1.object.emailname_t.text="email-name"+"▽"
dw_1.object.emailname_t.color=RGB(255,0,0)
end if
end choose
//5.2b降序处理
this.setsort(col_name+sortway)
this.sort()
sortway=" a"
//-----------------------------------
end if
/*********************************************************************************/
6.7 write data into excel script
pointer oldpointer
int ret,value,li_row,i,li_row2
string ls_customer,ls_fobport,ls_filename,path
datetime ld_qsheetdate
string docname, named,filename
OLEObject xlapp , xlsub, xls,xlsub1
xlApp = Create OLEObject
ret = xlApp.ConnectToNewObject( "Excel.Application" )
if ret < 0 then
MessageBox("Connect to Excel Failed !",string(ret))
return
end if
/************************************/
string pictname,aa,ff
long i=1,k,m,b,numrows,f
numrows=dw_1.rowcount()
K=CEILING(numrows/8)
xls=xlapp.application.activeworkbook
xlsub=xlapp.application.activeworkbook.worksheets[1]
xlApp.Application.Workbooks.Open("c:/pbssystem/document/DOLLARGE hangtag.xls")
xlApp.Application.Visible = true
for i=1 to K - 1
b=68*i+1
aa='A'+string(B)
xlapp.Application.range("A2:H54").Select
xlapp.Application.Selection.Copy
xlapp.Application.range(AA).Select
xlapp.Application.Selection.Insert()
next
M=3
for i=1 to numrows
xlsub.Cells[17*(I - 1)+M+1,2]=mid(dw_1.object.q_qsheetitem_itemnumber[i],3)
xlsub.Cells[17*(I - 1)+M+2,2]=dw_1.object.q_qsheetitem_briefdesc[i]
xlsub.Cells[17*(I - 1)+M+3,2]=dw_1.object.q_quotesheet_quotbuyer[i]
xlsub.Cells[17*(I - 1)+M+4,2]=round(dw_1.object.q_qsheetitem_price_fob[i],4)
xlsub.Cells[17*(I - 1)+M+5,2]=round(dw_1.object.compute_3[i],4)
xlsub.Cells[17*(I - 1)+M+6,2]=round(dw_1.object.q_qsheetitem_storecost[i],4)
xlsub.Cells[17*(I - 1)+M+7,2]=round(dw_1.object.q_qsheetitem_retailofprc[i],4)
f=17*(i - 1)+m
ff="H"+string(f)
pictname=dw_1.object.i_photoitem_photoname[i]
xlapp.Application.ActiveWorkbook.Worksheets[1].Range(ff).Select
if pictname<>'' and not(isnull(pictname)) then
if FILEEXISTS(pictname) = true then
xlapp.Application.ActiveSheet.Pictures.Insert(string(pictname)).select
xlapp.Application.Selection.ShapeRange.height=200
end if
end if
next
/************************************/
value=GetFileSaveName("Select File", docname, named, "xls", " Excel Files (*.xls), *.xls")
filename=docname
if value=1 then
if isnull(filename) or filename='' then
messagebox("attention","You don't save the file")
else
xlapp.Application.ActiveWorkbook.SaveAs(FileName)
xlapp.Application.ActiveWorkbook.close
end if
end if
xlApp.DisConnectObject()
destroy xlapp
setpointer(oldpointer)
/*********************************************************************************/
6.8 read data from excel script
dw_1.reset()
string is_filename,is_named
long ll_openfile
ll_openfile=getfileopenname("打开文件",is_filename, is_named,"XLS","EXCEL文檔,*.XLS")
if ll_openfile=1 then
if FileExists(is_filename)=false then
messagebox("注意!", "文件不存在,请重新选择!",information!)
return
else
sle_file.text=is_filename
end if
end if
string ls_excelfile
long l_maxrow,li,l_crow,l_srow
string ls1,ls2,ls3
l_srow=1 //start data row
l_maxrow=long(sle_trow.text) //excle file name full path
if l_maxrow<1 then
messagebox("注意","读入行数不能为0,请设置行数!")
return
end if
//开始读入数据
//messagebox("注意!", "开始读取数据...,请等待!",information!)
pointer oldpointer
oldpointer = setpointer(HourGlass!)
//connect to Excel is flase return 0
ls_excelfile=sle_file.text
oleobject excelapp
excelapp=create oleobject
if excelapp.ConnectTonewObject("excel.application" ) <> 0 then return 0
ls_excelfile=trim(sle_file.text)
if FileExists(ls_excelfile)=true then
excelapp.application.workbooks.open(ls_excelfile)
else
messagebox("注意","打开Excel文件出错!")
return 0
end if
delete from it_email_import_data using sqlca;
commit;
//tabname it_email_import_data
string s1,s2,s3,s4,s5,s6
for li=1 to l_maxrow
l_crow=dw_1.insertrow(0)
st_trow.text=string(dw_1.rowcount())
s1 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,1).value)
s2 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,2).value)
s3 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,3).value)
s4 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,4).value)
s5 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,5).value )
s6 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,6).value )
//check value
if isnull(s1) then s1=''
if isnull(s2) then s2=''
if isnull(s3) then s3=''
if isnull(s4) then s4=''
if isnull(s5) then s5=''
if isnull(s6) then s6=''
if isnull(s7) then s7=''
if s1<>"" then dw_1.object.company_name[l_crow]=s1
if s2<>"" then dw_1.object.department[l_crow] =s2
if s3<>"" then dw_1.object.username_c[l_crow] =s3
if s4<>"" then dw_1.object.username_e[l_crow] =s4
if s5<>"" then dw_1.object.emailname[l_crow] =s5
if s6<>"" then dw_1.object.emailadd[l_crow] =s6
next
excelapp.Application.ActiveWorkbook.close
destroy excelapp
oldpointer = setpointer(Arrow!)
/*********************************************************************************/
/*按条件过滤下拉数据窗口数据*/
string value
value=data
DataWindowChild dwc
dw_1.getchild("groupb",dwc)
dwc.settransobject(sqlca)
dwc.retrieve()
dwc.SetFilter("column='" + value+ "'")
dwc.Filter()
author:chinayaosir
blog:http://blog.csdn.net/chinayaosir
contents list
0.0 connection ini file
0.2 table struct list
0.3 database procedure (log_user )
1.1 application open script
1.2 application systemerror script
1.3 input win32 api function
2.1 w_main open script
2.2 w_main close() script
3.0 log_user PROCEDURE code
3.1 w_login windows open script
3.2 w_login login button clicked script
3.3 w_login get user authority of gf_authority()
4. w_authority is manage user authority
5.1 open a window with param
5.2 close a windows with param
6.1 open script
6.2 insert script
6.3 delete script
6.4 save script
6.5 find script
6.6 sort script
6.6.1 sort by use choose
6.6.2 sort data as outlook form
6.7 write data into excel script
6.8 read data from excel script
/*********************************************************************************/
0.0connection ini file
0.db.ini
[Database]
DBMS=SYC Adaptive Server Enterprise
Database=database name
LogPassword=logpassword
ServerName=server-computer-name
UserID=
DatabasePassword=
LogId=sa
Lock=
DbParm=Release='11.5'
Prompt=0
/*********************************************************************************/
0.2 table struct list
create table dbo.a_useability (
userof_id char(20) not null,
group_id char(3) not null,
menusite char(4) not null,
r_w_d_p char(4) not null)
alter table dbo.a_useability add constraint a_useability_x
primary key nonclustered (userof_id, group_id, menusite, r_w_d_p)
create table dbo.a_groupclass (
group_id char(3) not null,
groupname char(20) not null,
classtype int not null,
menusite char(4) not null,
r_w_d_p char(4) not null)
alter table dbo.a_groupclass
add constraint a_groupclass_x primary key nonclustered (group_id, menusite, r_w_d_p)
create table dbo.b_coordinator (
coordinaid char(20) not null, coordiname nvarchar(50) not null,
department nvarchar(20) null, competence nvarchar(20) null,
password char(6) null, user_code char(10) not null,
statusflag char(1) null, userofsite char(1) null
)
alter table dbo.b_coordinator
add constraint b_coordinator_x primary key nonclustered (coordinaid, user_code)
/*********************************************************************************/
0.3 database procedure (log_user )
CREATE PROCEDURE log_user(@user_code char(10), @password char(6), @logtype char(1), @result char(1) output )
AS
BEGIN
select @result='1'
if @logtype='0'
begin
/*login*/
if not exists(
select * from b_coordinator /*tablockx*/
where (user_code=upper(@user_code)) and (password=@password) and (statusflag<>'1')
)
begin
/*error user name*/
select @result='1'
raiserror 35007
end
else
begin
update b_coordinator
set statusflag='1'
where (user_code=upper(@user_code)) and (password=@password)
select @result='0'/*success*/
end
end
else
begin
/*logout*/
update b_coordinator
set statusflag='0'
where (user_code=upper(@user_code)) and (password=@password)
select @result='0'/*success*/
end
END
/*********************************************************************************/
1.1 application open script
application open script code
// This script will read all the database values from db.ini
// and store them in SQLCA.
SQLCA.DBMS =ProfileString("db.ini","Database","DBMS", " ")
SQLCA.Database =ProfileString("db.ini","Database","DataBase", " ")
SQLCA.LogID =ProfileString("db.ini","Database","LogID", " ")
SQLCA.LogPass =ProfileString("db.ini","Database","LogPassword", " ")
SQLCA.ServerName =ProfileString("db.ini","Database","ServerName", " ")
SQLCA.UserID =ProfileString("db.ini","Database","UserID", " ")
SQLCA.DBPass =ProfileString("db.ini","Database","DatabasePassword", " ")
SQLCA.Lock =ProfileString("db.ini","Database","Lock", " ")
SQLCA.DbParm =ProfileString("db.ini","Database","DbParm", " ")
connect;
open(w_main)
/*********************************************************************************/
1.2 application systemerror script
if err_sys=1 then
err_sys=0
return
else
open(w_system_error)
end if
/*********************************************************************************/
1.3 input win32 api function
//Global External Functions list
function double GetJpgSize(string filename) library 'jpg.dll'
Function ulong GetModuleFileNameA(ulong hModule,ref string lpFileName,ulong nSize) LIBRARY 'kernel32.dll'
/*********************************************************************************/
2.1 w_main open script
string li_flag='',ls_tile
select tablename.value into :gs_pict
from tablename where tablename.parameter='picture_path';
if sqlca.sqlcode<>0 then li_flag=li_flag+sqlca.sqlerrtext+'PI'
//open login window
open(w_login)
/*********************************************************************************/
2.2 w_main close() script
//Write user left message with log_user PROCEDURE
string ls_code
DECLARE P_loguser PROCEDURE FOR log_user
@user_code = :usercode,
@password = :password_in,
@logtype = '1',
@result = :ls_code OUTPUT;
execute P_loguser;
fetch P_loguser into :ls_code;
close P_loguser;
commit;
if ls_code='0' then
close(this)
else
messagebox('Warning!','Logout is Error !')
end if
/*********************************************************************************/
3.1 w_login windows open script
dw_1.settransobject(sqlca)
dw_1.retrieve(gs_site)
/*********************************************************************************/
3.2 w_login login button clicked script
//Write user login message with log_user PROCEDURE
string ls_code,ls_titl
DECLARE P_loguser PROCEDURE FOR log_user
@user_code = :usercode,
@password = :password_in,
@logtype = '0',
@result = :ls_code OUTPUT;
execute P_loguser;
fetch P_loguser into :ls_code;
close P_loguser;
commit;
if ls_code='0' then
gf_authority()//get user authority
ls_titl=w_main.title
w_mgmanager0.title=ls_titl+space(30)+usercode
close(w_login)
else
messagebox('Warning!','Login is Error !')
st_2.text=''
password=''
opration=''
return
end if
/*********************************************************************************/
3.3 w_login get user authority of gf_authority() script
//system menu default stauts is disable,when find a record from table,then open it
string ls_menuid
declare user_competence cursor for
select menusite from a_useability
where userof_id =:usercode;
open user_competence;
fetch user_competence into :ls_menuid;
do while sqlca.sqlcode = 0
choose case ls_menuid
case '1100'
m_menu.m_1000.m_1100.enabled=true
case '1200'
m_menu.m_1000.m_1200.enabled=true
case '1300'
m_menu.m_1000.m_1300.enabled=true
case '1401'
m_menu.m_1000.m_1400.m_1401.enabled=true
case '1402'
m_menu.m_1000.m_1400.m_1402.enabled=true
case '1501'
m_menu.m_1000.m_1500.m_1501.enabled=true
case '1502'
m_menu.m_1000.m_1500.m_1502.enabled=true
case '2100'
m_menu.m_2000.m_2100.enabled=true
case '2200'
m_menu.m_2000.m_2200.enabled=true
case '2301'
m_menu.m_2000.m_2300.m_2301.enabled=true
case '2302'
m_menu.m_2000.m_2300.m_2302.enabled=true
case '2401'
m_menu.m_2000.m_2400.m_2401.enabled=true
case '2402'
m_menu.m_2000.m_2400.m_2402.enabled=true
/*...*/
end choose
fetch user_competence into :ls_menuid;
loop
close user_competence;
return 1
/*********************************************************************************/
4. w_authority is modify user authority
4.1.1 the datawidnow dw_u is user list
/*dw_u datasource sql code
SELECT DISTINCT b_coordinator.coordinaid,
b_coordinator.coordiname,
a_useability.group_id,
b_coordinator.department,
b_coordinator.user_code
FROM b_coordinator,
a_useability
WHERE ( b_coordinator.user_code *= a_useability.userof_id) and
( ( b_coordinator.userofsite = :site ) )
*/
/****************************************/
4.1.2 w_authority open script
dw_u.settransobject(sqlca)
dw_u.retrieve(gs_site)
4.1.3 dw_u doubleclicked script
/***************************************/
string ls_grou
choose case dwo.name
case 'coordinaid'
is_user=this.object.user_code[row]
dw_pop.retrieve('%',is_user)
dw_pop.visible=true
dw_pop.title=is_user
case 'a_group_id'
is_user=this.object.user_code[row]
ls_grou=this.object.a_group_id[row]
if isnull(ls_grou) then return
dw_pop.retrieve(ls_grou,is_user)
dw_pop.visible=true
dw_pop.title=is_user
end choose
/***************************************/
4.1.4 dw_pop datasource
SELECT a_groupclass.group_id,
a_groupclass.menusite,
a_groupclass.r_w_d_p,
a_useability.userof_id,
a_useability.group_id,
a_useability.menusite,
a_useability.r_w_d_p,
prove=' '
FROM a_groupclass,
a_useability
WHERE ( a_groupclass.group_id *= a_useability.group_id) and
( a_groupclass.menusite *= a_useability.menusite) and
( a_groupclass.r_w_d_p *= a_useability.r_w_d_p) and
( ( a_groupclass.group_id like :grou ) AND
( a_useability.userof_id like :user ) )
/***************************************/
4.1.5 dw_pop doublecliked script
long ll_rows,ii
string ls_site,ls_rwdp,ls_grou,ls_chck
choose case dwo.name
case 't_menu'
this.setsort('#2 A')
this.sort()
case 't_group'
this.setsort('#1 A')
this.sort()
case 'b_s'
this.visible=false
ll_rows=this.rowcount()
for ii=1 to ll_rows
ls_grou=this.object.a_group_id[ii]
ls_rwdp=this.object.a_r_w_d_p[ii]
ls_site=this.object.a_menusite[ii]
ls_chck=this.object.prove[ii]
row_save(ls_grou,ls_site,ls_rwdp,ls_chck)
next
tab_1.tabpage_3.dw_u.retrieve(gs_local)
case 'b_e'
this.visible=false
end choose
/***************************************/
4.1.5.1 row_save function
//function format row_save(ls_grou,ls_site,ls_rwdp,ls_chck)
int li_sele
string ls_grou
select group_id into :ls_grou from a_useability where
(group_id=:grou)and(userof_id=:is_user)and(menusite=:site)and(r_w_d_p=:rwdp);
choose case sqlca.sqlcode
case 0
if chck<>'T' then
delete from a_useability where (group_id=:grou)and
(userof_id=:is_user)and(menusite=:site)and(r_w_d_p=:rwdp);
end if
case 100
if chck='T' then
insert into a_useability (userof_id,group_id,menusite,r_w_d_p)
values (:is_user,:grou,:site,:rwdp);
end if
case else
messagebox('Warning!',sqlca.sqlerrtext)
end choose
/*********************************************************************************/
5.1 open a window with param
//structure str_qsheet
string customer
datetime qsheetdate
string fobport
string itemnumber
integer row
string window
string shipfrom
string shipto
string company
/***********************************/
str_qsheet str_save
int row
row=dw_2.getrow()
str_save.customer=dw_2.object.customerid[row]
str_save.qsheetdate=dw_2.object.qsheetdate[row]
str_save.fobport=dw_2.object.fobport[row]
openwithparm(w_qs_excel_select,str_save)
/***********************************/
//w_qs_excel_select open script
string ls_customer,ls_fobport
datetime ld_qsheetdate
long row,i
str_qsheet str_save
str_save=Message.PowerObjectParm
ls_customer=str_save.customer
ld_qsheetdate=str_save.qsheetdate
ls_fobport=str_save.fobport
dw_1.settransobject(sqlca)
dw_1.retrieve(ls_customer,ld_qsheetdate,ls_fobport)
/*********************************************************************************/
5.2 open a window ,then close it return a param
//datawindow doublecicked script
if row<=0 then return
string item_data=""
choose case dwo.name
case "songid"
openwithparm(w_song,"")
item_data=message.stringparm
if len(item_data) > 0 then
dw_1.object.songid[row]=item_data
string song_name,seconds,version,studio,copyright,haveic,songpath
select song_name,seconds,version,studio,copyright,haveic,songpath
into :song_name,:seconds,:version,:studio,:copyright,:haveic,:songpath
from t_mu_song where songid=:item_data;
dw_1.object.song_name[row]=song_name
dw_1.object.seconds[row]=seconds
dw_1.object.version[row]=version
dw_1.object.studio[row]=studio
dw_1.object.copyright[row]=copyright
dw_1.object.haveic[row]=haveic
dw_1.object.songpath[row]=songpath
end if
end choose
/**************************/
//w_song close script
if dw_1.rowcount()>0 then
string songid
songid=dw_1.object.songid[dw_1.getrow()]
closewithreturn(parent,songid)
end if
//these code return songid into item_data=message.stringparm
/*********************************************************************************/
6. open,insert,delete,save,fresh script
6.1 open script
dw_1.settransobject(sqlca)
/*********************************************************************************/
6.2 insert script
dw_1.setfocus()
dw_1.ScrollToRow(dw_1.insertrow(0))
dw_1.setColumn(1)
dw_1.setfocus()
/*********************************************************************************/
6.3 delete script
integer li_return
li_return = MessageBox("Warning!","Are you true delete data?",Exclamation!,YesNo!,2)
if li_return=1 then
dw_1.deleterow(dw_1.getrow())
if dw_1.update()=1 then
commit using sqlca;
MessageBox("Happy!","Save Data OK!")
else
rollback using sqlca;
MessageBox("Error!","Save Data Fail!")
end if
dw_1.insertrow(0)
end if
/*********************************************************************************/
6.4 save script
string mid
if dw_1.rowcount()>=1 then
mid=dw_1.object.machineid[dw_1.getrow()]
if mid <> "" then
dw_1.object.modifyer[dw_1.getrow()]=g_username
if dw_1.update()=1 then
commit using sqlca;
MessageBox("Happy!","Save Data OK!")
else
rollback using sqlca;
MessageBox("Error!","Save Data Fail!")
end if
//fresh data
dw_1.SetRedraw(FALSE)
dw_1.retrieve(mid)
dw_1.SetRedraw(TRUE)
end if
end if
/*********************************************************************************/
6.5 find script
//find
string s1,s2,s3,s4,s5,s6
s1=trim(sle_1.text)
s2=trim(sle_2.text)
s3=trim(sle_3.text)
s4=trim(sle_4.text)
if s1="" then
s1="%"
else
s1=s1+"%"
end if
if s2="" then
s2="%"
else
s2=s2+"%"
end if
if s3="" then
s3="%"
else
s3="%"+s3+"%"
end if
if s4="" then
s4="%"
else
s4=s4+"%"
end if
//refresh
dw_1.SetRedraw(FALSE)
dw_1.retrieve(s1,s2,s3,s4)
dw_1.SetRedraw(TRUE)
st_rows.text=string(dw_1.rowcount())
/*********************************************************************************/
6.6.1 sort by use choose
sort button script
string st1,st2,st3,sortby,sort_str
st1=trim(ddlb_1.text)
st2=trim(ddlb_2.text)
st3=trim(ddlb_3.text)
sortby=trim(ddlb_sortby.text)
if sortby="升序" then
sortby=" a"
else
sortby=" d"
end if
sort_str=st1+sortby+","+st2+sortby+","+st3+sortby
dw_1.SetRedraw(false)
dw_1.SetSort(sort_str)
dw_1.Sort()
dw_1.SetRedraw(true)
/*******************************************/
6.6.2 sort data as outlook form
clicked data_window script
//1.公用变量定义
//string sortway=" a"
//2.范围检查
if dwo.type <> "text" then return
//----------------------------------
//3.初始化每列的原始值
//
dw_1.object.company_name_t.text="Area"
dw_1.object.department_t.text="Group/Factoryid"
dw_1.object.username_c_t.text="C-name"
dw_1.object.emailname_t.text="email-name"
dw_1.object.company_name_t.color=RGB(0,0,0)
dw_1.object.department_t.color=RGB(0,0,0)
dw_1.object.username_c_t.color=RGB(0,0,0)
dw_1.object.emailname_t.color=RGB(0,0,0)
//4.检查并得到单击的列名
string col_name //desc
col_name=left(dwo.name,len(string(dwo.name)) - 2)
if isnull(col_name) then return
//5.排序处理
if sortway=" a" then
//sort by asc
//5.1a列名上自动添加△和文字变为红色
choose case col_name
case "company_name"
if col_name="company_name" then
dw_1.object.company_name_t.text="Area"+"△"
dw_1.object.company_name_t.color=RGB(255,0,0)
end if
case "department"
if col_name="department" then
dw_1.object.department_t.text="Group/Factoryid"+"△"
dw_1.object.department_t.color=RGB(255,0,0)
end if
case "username_c"
if col_name="username_c" then
dw_1.object.username_c_t.text="C-name"+"△"
dw_1.object.username_c_t.color=RGB(255,0,0)
end if
case "emailname"
if col_name="emailname" then
dw_1.object.emailname_t.text="email-name"+"△"
dw_1.object.emailname_t.color=RGB(255,0,0)
end if
end choose
//5.1b升序处理
this.setsort(col_name+sortway)
this.sort()
sortway=" d"
//----------------------------------
else
//5.2a列名上自动添加▽和文字变为红色
//-----------------------------------
sortway=" d"
//st_sort.text=col_name+"▽"
choose case col_name
case "company_name"
if col_name="company_name" then
dw_1.object.company_name_t.text="Area"+"▽"
dw_1.object.company_name_t.color=RGB(255,0,0)
end if
case "department"
if col_name="department" then
dw_1.object.department_t.text="Group/Factoryid"+"▽"
dw_1.object.department_t.color=RGB(255,0,0)
end if
case "username_c"
if col_name="username_c" then
dw_1.object.username_c_t.text="C-name"+"▽"
dw_1.object.username_c_t.color=RGB(255,0,0)
end if
case "emailname"
if col_name="emailname" then
dw_1.object.emailname_t.text="email-name"+"▽"
dw_1.object.emailname_t.color=RGB(255,0,0)
end if
end choose
//5.2b降序处理
this.setsort(col_name+sortway)
this.sort()
sortway=" a"
//-----------------------------------
end if
/*********************************************************************************/
6.7 write data into excel script
pointer oldpointer
int ret,value,li_row,i,li_row2
string ls_customer,ls_fobport,ls_filename,path
datetime ld_qsheetdate
string docname, named,filename
OLEObject xlapp , xlsub, xls,xlsub1
xlApp = Create OLEObject
ret = xlApp.ConnectToNewObject( "Excel.Application" )
if ret < 0 then
MessageBox("Connect to Excel Failed !",string(ret))
return
end if
/************************************/
string pictname,aa,ff
long i=1,k,m,b,numrows,f
numrows=dw_1.rowcount()
K=CEILING(numrows/8)
xls=xlapp.application.activeworkbook
xlsub=xlapp.application.activeworkbook.worksheets[1]
xlApp.Application.Workbooks.Open("c:/pbssystem/document/DOLLARGE hangtag.xls")
xlApp.Application.Visible = true
for i=1 to K - 1
b=68*i+1
aa='A'+string(B)
xlapp.Application.range("A2:H54").Select
xlapp.Application.Selection.Copy
xlapp.Application.range(AA).Select
xlapp.Application.Selection.Insert()
next
M=3
for i=1 to numrows
xlsub.Cells[17*(I - 1)+M+1,2]=mid(dw_1.object.q_qsheetitem_itemnumber[i],3)
xlsub.Cells[17*(I - 1)+M+2,2]=dw_1.object.q_qsheetitem_briefdesc[i]
xlsub.Cells[17*(I - 1)+M+3,2]=dw_1.object.q_quotesheet_quotbuyer[i]
xlsub.Cells[17*(I - 1)+M+4,2]=round(dw_1.object.q_qsheetitem_price_fob[i],4)
xlsub.Cells[17*(I - 1)+M+5,2]=round(dw_1.object.compute_3[i],4)
xlsub.Cells[17*(I - 1)+M+6,2]=round(dw_1.object.q_qsheetitem_storecost[i],4)
xlsub.Cells[17*(I - 1)+M+7,2]=round(dw_1.object.q_qsheetitem_retailofprc[i],4)
f=17*(i - 1)+m
ff="H"+string(f)
pictname=dw_1.object.i_photoitem_photoname[i]
xlapp.Application.ActiveWorkbook.Worksheets[1].Range(ff).Select
if pictname<>'' and not(isnull(pictname)) then
if FILEEXISTS(pictname) = true then
xlapp.Application.ActiveSheet.Pictures.Insert(string(pictname)).select
xlapp.Application.Selection.ShapeRange.height=200
end if
end if
next
/************************************/
value=GetFileSaveName("Select File", docname, named, "xls", " Excel Files (*.xls), *.xls")
filename=docname
if value=1 then
if isnull(filename) or filename='' then
messagebox("attention","You don't save the file")
else
xlapp.Application.ActiveWorkbook.SaveAs(FileName)
xlapp.Application.ActiveWorkbook.close
end if
end if
xlApp.DisConnectObject()
destroy xlapp
setpointer(oldpointer)
/*********************************************************************************/
6.8 read data from excel script
dw_1.reset()
string is_filename,is_named
long ll_openfile
ll_openfile=getfileopenname("打开文件",is_filename, is_named,"XLS","EXCEL文檔,*.XLS")
if ll_openfile=1 then
if FileExists(is_filename)=false then
messagebox("注意!", "文件不存在,请重新选择!",information!)
return
else
sle_file.text=is_filename
end if
end if
string ls_excelfile
long l_maxrow,li,l_crow,l_srow
string ls1,ls2,ls3
l_srow=1 //start data row
l_maxrow=long(sle_trow.text) //excle file name full path
if l_maxrow<1 then
messagebox("注意","读入行数不能为0,请设置行数!")
return
end if
//开始读入数据
//messagebox("注意!", "开始读取数据...,请等待!",information!)
pointer oldpointer
oldpointer = setpointer(HourGlass!)
//connect to Excel is flase return 0
ls_excelfile=sle_file.text
oleobject excelapp
excelapp=create oleobject
if excelapp.ConnectTonewObject("excel.application" ) <> 0 then return 0
ls_excelfile=trim(sle_file.text)
if FileExists(ls_excelfile)=true then
excelapp.application.workbooks.open(ls_excelfile)
else
messagebox("注意","打开Excel文件出错!")
return 0
end if
delete from it_email_import_data using sqlca;
commit;
//tabname it_email_import_data
string s1,s2,s3,s4,s5,s6
for li=1 to l_maxrow
l_crow=dw_1.insertrow(0)
st_trow.text=string(dw_1.rowcount())
s1 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,1).value)
s2 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,2).value)
s3 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,3).value)
s4 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,4).value)
s5 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,5).value )
s6 =string(excelapp.application.workbooks(1).worksheets(1).cells(l_srow+li,6).value )
//check value
if isnull(s1) then s1=''
if isnull(s2) then s2=''
if isnull(s3) then s3=''
if isnull(s4) then s4=''
if isnull(s5) then s5=''
if isnull(s6) then s6=''
if isnull(s7) then s7=''
if s1<>"" then dw_1.object.company_name[l_crow]=s1
if s2<>"" then dw_1.object.department[l_crow] =s2
if s3<>"" then dw_1.object.username_c[l_crow] =s3
if s4<>"" then dw_1.object.username_e[l_crow] =s4
if s5<>"" then dw_1.object.emailname[l_crow] =s5
if s6<>"" then dw_1.object.emailadd[l_crow] =s6
next
excelapp.Application.ActiveWorkbook.close
destroy excelapp
oldpointer = setpointer(Arrow!)
/*********************************************************************************/
/*按条件过滤下拉数据窗口数据*/
string value
value=data
DataWindowChild dwc
dw_1.getchild("groupb",dwc)
dwc.settransobject(sqlca)
dwc.retrieve()
dwc.SetFilter("column='" + value+ "'")
dwc.Filter()
相关文章推荐
- Leecode Pow(x, n)实现任意次方函数
- Letcode 题:pow(x,n)
- 我在codeproject.com上post的一篇文章出现在www.asp.net的[ASP.NET Articles -- Updated Daily! ]频道, 发贴纪念一下.
- CodePlex Daily Summary for Monday, March 10, 2008
- LintCode_Pow(x, n)
- [leet code] Pow(x, n)
- CODE 83: Pow(x, n)
- reverse-daily(1)-audio_visual_receiver_code
- Codeforces Round #112 (Div. 2) & #125 (Div. 2)总结(不要用pow&log!!!)
- Leet Code 50 Pow(x, n) - 实现幂运算 - Java
- [leedcode 50] Pow(x, n)
- [leet code] Partition List Pow(x, n)
- python code segment daily collect
- lintcode:Pow(x, n)
- daily CodeWars
- codechef FIBTREE 码农题 线段树 树剖 标记永久化
- N85 code对照表
- 张恩明html5 Web SQL DB sample code
- CodeForces Gym 100500A A. Poetry Challenge DFS
- Python with VS Code