PB里执行RUN带参数及判断是否成功的办法
string ls_run_rar,ls_file_zip_in,ls_file_pathls_file_zip_in = c:\a.rar//原文件
ls_file_path = c:\bak\ //需要解压缩的一个目录
int li_run_rar
ls_run_rar = "C:\Program Files\WinRAR\WinRAR.exe " + " e "+ ls_file_zip_in + " " + ls_file_path + " /y"
li_run_rar = Run(ls_run_rar,Minimized!) //执行
IF li_run_rar = 1 THEN //解压缩成功
//
END IF
最新的处理方法一般在最后,找新贴请倒着看。 附上写的一个文件导入的主程序,使用二个游标(一个检索所有门店,一个检索每个门店下的所有文件)
Global Variables
string ls_pos_in ='1' 差不多花了一周的时间,就弄了点这个
Declare Local External Functions
FUNCTION boolean CopyFileA(ref string cfrom, ref string cto, boolean flag) LIBRARY "Kernel32.dll"
FUNCTION long Sleep(Long ms)library "kernel32" //定义门店编号,与上传路径相关
String ls_bran_id
ls_pos_in = "1"
String ls_file_date
//
cb_in.Enabled = False
cb_close.Enabled = False
cb_stop.Enabled = True
cb_in.Text = "数据正在导入中..."
//
DO UNTIL ls_pos_in = "0"
//游标取值,所有门店的上传数据处理
DECLARE cur_bran_id CURSOR FOR
SELECT bran_id
FROM bran_cust_rec
WHERE bran_id LIKE "C%"
Order By bran_id;
OPEN cur_bran_id ;
FETCH cur_bran_id Into :ls_bran_id;
DO WHILE sqlca.SQLCode = 0
st_pos_id.Text = ls_bran_id
Yield()
//====================================================================
//数据导入到DW里
//====================================================================
//ls_bran_id = "CZ001" //调试用
Long ll_filelength_zip,ll_filelength
String ls_file_in ,ls_file_bak
String ls_file_zip_in,ls_file_zip_bak //
String ls_file_path //文件目录
String ls_run_rar //rar命令
Int li_run_rar //rar是否运行成功
String ls_t_file,ls_t_table,ls_t_dw //导入相关的文件名,表名,数据窗口
Int li_importfile,li_update //是否导入文件成功,是否update成功
DECLARE cur_pos_in CURSOR FOR
SELECT t_file,t_table,t_dw
FROM t_pos_in
Where t_y = 'y' ;
OPEN cur_pos_in ;
FETCH cur_pos_in Into :ls_t_file,:ls_t_table,:ls_t_dw;
DO WHILE sqlca.SQLCode = 0
Yield()
//文件导入
ls_file_date = String(Today(),"yyyymmddhhmm")
//压缩处理
ls_file_zip_in = "E:\posftp\" + ls_bran_id + "\"+ls_t_file + ".zip"
ll_filelength_zip = FileLength(ls_file_zip_in)
ls_file_in = "E:\posftp\" + ls_bran_id + "\"+ls_t_file
ls_file_bak = "E:\posftpbak\" + ls_bran_id + "\"+ls_file_date+ls_t_file
ll_filelength = FileLength(ls_file_in)
IF ll_filelength_zip >= 1 And ll_filelength = -1 THEN //ZIP文件存在,TXT文件不存在
st_file.Text = ls_file_zip_in
ls_file_zip_bak = "E:\posftpbak\" + ls_bran_id + "\"+ls_file_date+ls_t_file + ".zip"
ls_file_path = "E:\posftp\"+ls_bran_id+"\"
ls_run_rar = "C:\Program Files\WinRAR\WinRAR.exe " + " e "+ ls_file_zip_in + " " + ls_file_path + " /y"
li_run_rar = Run(ls_run_rar,Minimized!)
sleep(3000)
IF li_run_rar = 1 THEN //解压缩成功
ls_file_in = "E:\posftp\" + ls_bran_id + "\"+ls_t_file
//ls_file_bak = "E:\posftpbak\" + ls_bran_id + "\"+ls_file_date+ls_t_file
ll_filelength = FileLength(ls_file_in) //解压缩后重新取
IF ll_filelength >= 30 THEN
dw_pos_in.DataObject = ls_t_dw
dw_pos_in.SetTransObject(sqlca)
dw_pos_in.Retrieve()
li_importfile = dw_pos_in.ImportFile(ls_file_in)
st_file.Text = ls_file_in
IF li_importfile > 0 THEN
CopyFileA(ls_file_zip_in,ls_file_zip_bak,False)
FileDelete(ls_file_in)
FileDelete(ls_file_zip_in)
END IF
//数据入库
String Sqlstatement
Sqlstatement = "DELETE From " +ls_t_table
EXECUTE Immediate :Sqlstatement Using sqlca;
dw_pos_in.SetTransObject(sqlca)
li_update = dw_pos_in.Update()
IF li_update <> 1 THEN
MessageBox("提示","更新失败" + ls_file_zip_in)
RETURN
END IF
END IF
END IF
ELSE
IF ll_filelength >= 30 THEN
dw_pos_in.DataObject = ls_t_dw
dw_pos_in.SetTransObject(sqlca)
dw_pos_in.Retrieve()
li_importfile = dw_pos_in.ImportFile(ls_file_in)
st_file.Text = ls_file_in
IF li_importfile > 0 THEN
CopyFileA(ls_file_in,ls_file_bak,False)
FileDelete(ls_file_in)
END IF
//数据入库
Sqlstatement = "DELETE From " +ls_t_table
EXECUTE Immediate :Sqlstatement Using sqlca;
dw_pos_in.SetTransObject(sqlca)
li_update = dw_pos_in.Update()
IF li_update <> 1 THEN
MessageBox("提示","更新失败" + ls_file_zip_in)
RETURN
END IF
ELSEIF ll_filelength <= 29 THEN
CopyFileA(ls_file_in,ls_file_bak,False)
FileDelete(ls_file_in)
END IF
END IF
sleep(30)
FETCH cur_pos_in Into :ls_t_file,:ls_t_table,:ls_t_dw;
LOOP
CLOSE cur_pos_in;
//
sleep(3000)
st_file.Text = ""
FETCH cur_bran_id Into :ls_bran_id;
LOOP
CLOSE cur_bran_id;
LOOP
cb_in.Enabled = True
cb_close.Enabled = True
cb_in.Text = "导入"
//更新有压缩文件及未压缩文件同时存在的情况的处理,对于程序更新过程中的问题解决
//20080912 呵呵
有点复杂啊:lol
页:
[1]