从文本中导入数据

string pathname, named
integer value
long  ll_count,ll_cnt
string ls_record,ls_card_num,ls_dt,ls_tm,ls_machine
integer li_card,li_dt,li_tm
datetime  ldt_dtm
long  ll_success,ll_failed,ll_track
string ls_track
integer  li_result

value = GetFileOpenName("选择文件", pathname, named, "*.TXT")

IF value <> 1 THEN
 messagebox('提示','文件有误!')
 return -1
end if
//删除原来的数据
dw_1.reset()
ll_count=dw_1.ImportFile(pathname)
if ll_count< 0 then
 messagebox('提示','导入文件时出错!')
 return -1
end if
if ll_count= 0 then
 messagebox('提示','数据量太大!') 
 return -1
end if

ii_collect=0
hpb_1.maxposition=ll_count
hpb_1.setstep=1
for ll_cnt=1 to ll_count
 YIELD()
 if ii_collect=1 then
  exit
 end if
 hpb_1.position=ll_cnt
 ls_record=dw_1.object.record[ll_cnt]//364117,2007-03-31,03:36,10
 li_card=pos(ls_record,',',1)
 li_dt=pos(ls_record,',',li_card+1)
 li_tm=pos(ls_record,',',li_dt+1)
 
 ls_card_num=mid(ls_record,1,li_card - 1)//卡号
 ls_dt=mid(ls_record,li_card + 1,li_dt - 1 - li_card)//日期
 ls_tm=mid(ls_record,li_dt + 1,li_tm - 1 - li_dt)//时间
 ls_machine=mid(ls_record,li_tm + 1, 10)//机号

 ldt_dtm=datetime(date(ls_dt),time(ls_tm+':00'))//签到时间
 ll_track++
 
 li_result=of_import_record(ls_card_num,ls_machine,ldt_dtm,ls_tm)
 if li_result=-1 then
  ll_failed++
  ls_track+=string(ll_track)+"、|"+ls_record+"|条记录,数据库中已存在,导入失败! ~r~n"
  mle_1.text=ls_track
  continue;
 end if
 
 if li_result=-2 then
  ll_failed++
  ls_track+=string(ll_track)+"、|"+ls_record+"|条记录,员工编号不存在,导入失败! ~r~n"
  mle_1.text=ls_track
  continue;
 end if
 
 ll_success++
 ls_track+=string(ll_track)+"、|"+ls_record+"|条记录,导入成功! ~r~n"
 mle_1.text=ls_track
next
ls_track="      导入失败"+string(ll_failed)+"条记录~r~n"+ls_track
ls_track="合计:导入成功"+string(ll_success)+"条记录~r~n"+ls_track
mle_1.text=ls_track

 


 

posted @ 2007-05-30 09:10  kuailewangzi1212  阅读(486)  评论(0编辑  收藏  举报