string ls_qcbh,ls_dist_no,ls_dbtype_code,ls_con_no,ls_usageno,ls_dist_qcbh,ls_user_no,ls_assets_no
long i,j,currow,ll_order_no,insertcount=0,insertplccount=0,meter_total,plc_meter_total,li_resultupdate
//参数检索
dw_1.accepttext( )
if dw_1.rowcount( )<1 then return
ls_qcbh=dw_1.getitemstring( dw_1.getrow(), 'qcbh')
ls_dbtype_code=dw_1.getitemstring( dw_1.getrow(), 'dbtype_code')
ls_dist_no=dw_1.getitemstring( dw_1.getrow(), 'dist_no')
ls_con_no=dw_1.getitemstring( dw_1.getrow(), 'con_no')
ls_usageno=dw_1.getitemstring( dw_1.getrow(), 'price_type')
if isnull(ls_qcbh) or trim(ls_qcbh)='' then //LINENO:10
messagebox('提示','请输入抄表本编号')
return
end if
if isnull(ls_dbtype_code) or trim(ls_dbtype_code)='' then
messagebox('提示','请选择电表型号')
return
end if
if isnull(ls_dist_no) or trim(ls_dist_no)='' then
messagebox('提示','请选择台区编号')
return //LINENO:20
end if
ls_dist_qcbh=distdata.getitemstring(distdata.getrow(), 'read_book_no')
if isnull(ls_dist_qcbh) or ls_dist_qcbh<>ls_qcbh then
messagebox('提示','输入的抄表本号与所选台区区册编号不一致,请修改')
return
end if
if isnull(ls_con_no) or trim(ls_con_no)='' then
messagebox('提示','请选择集中器编号')
return
end if
if isnull(ls_usageno) or trim(ls_usageno)='' then
messagebox('提示','请选择用电类型')
return
end if
//连接数据源
mid_trans=create transaction
mid_trans.dbms='odbc'
mid_trans.dbparm="Connectstring='DSN=sa'"
connect using mid_trans;
if mid_trans.sqlcode<>0 then
messagebox('提示','连接中间表出错')
return
end if
dw_mis_read.SETTRANsobject(mid_trans)
dw_mis_read.retrieve('D','1',ls_qcbh)
if dw_mis_read.rowcount( )<=0 then
messagebox('提示','无新增或修改用户')
return
end if
//连接目标源
dw_2.settransobject(sqlca)
dw_2.retrieve(ls_dist_no,ls_con_no)
select max(order_no) into :ll_order_no from meter where dist_no=:ls_dist_no and con_no=:ls_con_no using sqlca;
if isnull(ll_order_no) then //LINENO:60
ll_order_no=0
end if
for i=1 to dw_mis_read.rowcount( )
ls_user_no=dw_mis_read.getitemstring(dw_mis_read.getrow(),'user_no')
ls_assets_no=dw_mis_read.getitemstring(dw_mis_read.getrow(),'assets_no')
select user_no,asset_no into :ls_user_no,:ls_assets_no from meter where user_no=:ls_user_no and asset_no=:ls_assets_no using sqlca;
if sqlca.sqlnrows<=0 then
currow=dw_2.insertrow(0)
insertcount=insertcount+1
end if
for j=1 to dw_2.rowcount()
if dw_mis_read.getitemstring(i,'user_no')=dw_2.getitemstring(j,'user_no') and dw_mis_read.getitemstring(i,'assets_no')=dw_2.getitemstring(j,'asset_no') then
currow=j
ll_order_no=ll_order_no+20
else
ll_order_no=long(dw_2.getitemstring(j,'order_no'))
exit
dw_2.setitem(currow, 'dist_no', ls_dist_no)
dw_2.setitem(currow, 'con_no', ls_con_no)
dw_2.setitem(currow, 'meter_no','000000'+right(dw_mis_read.getitemstring(i,'meter_sn'),6))
dw_2.setitem(currow, 'asset_no',dw_mis_read.getitemstring(i,'assets_sn'))
dw_2.setitem(currow, 'user_no',dw_mis_read.getitemstring(i,'user_no'))
dw_2.setitem(currow, 'user_name',dw_mis_read.getitemstring(i,'user_name')) //LINENO:70
dw_2.setitem(currow, 'fact_code',dw_mis_read.getitemstring(i,'fac_code'))
dw_2.setitem(currow, 'fact_name','中城电子科技(惠州)有限公司')
dw_2.setitem(currow, 'run_state','1')
dw_2.setitem(currow, 'down_state','0')
dw_2.setitem(currow, 'CURR_T0',0)
dw_2.setitem(currow, 'CURR_T1',0)
dw_2.setitem(currow, 'CURR_T2',0)
dw_2.setitem(currow, 'CURR_T3',0)
dw_2.setitem(currow, 'CURR_T4',0)
dw_2.setitem(currow, 'col_flag','0')
dw_2.setitem(currow,'order_no',ll_order_no)
dw_2.setitem(currow,'ini_t1',0)
dw_2.setitem(currow,'ini_t2',0)
dw_2.setitem(currow,'ini_t3',0)
dw_2.setitem(currow,'ini_t4',0)
if rb_1.checked=true then
dw_2.setitem(currow,'ini_t0',0)
end if
if rb_2.checked=true then
dw_2.setitem(currow,'ini_t0',dw_mis_read.getitemnumber(currow,'sq_qd_bd')) //??
end if
if rb_3.checked=true then
dw_2.setitem(currow,'ini_t0',dw_mis_read.getitemnumber(currow,'bq_qd_bd')) //??
end if
//以下为从电表型号表中取得的数据
if dbtypedata.getitemstring(dbtypedata.getrow(),'code')=dw_1.getitemstring(dw_1.getrow(),'dbtype_code') then
dw_2.setitem(currow, 'typecode',dbtypedata.getitemstring(dbtypedata.getrow(),'code'))
dw_2.setitem(currow, 'type',dbtypedata.getitemstring(dbtypedata.getrow(),'type'))
dw_2.setitem(currow, 'kind',dbtypedata.getitemstring(dbtypedata.getrow(),'kind'))
dw_2.setitem(currow, 'spec',dbtypedata.getitemstring(dbtypedata.getrow(),'spec'))
dw_2.setitem(currow, 'amp',dbtypedata.getitemstring(dbtypedata.getrow(),'amp'))
dw_2.setitem(currow, 'constant',dbtypedata.getitemnumber(dbtypedata.getrow(),'constant'))
dw_2.setitem(currow, 'tariff_no',dbtypedata.getitemstring(dbtypedata.getrow(),'tariff_no'))
dw_2.setitem(currow, 'measure_len',dbtypedata.getitemnumber(dbtypedata.getrow(),'measure_len'))
dw_2.setitem(currow, 'precision1',dbtypedata.getitemstring(dbtypedata.getrow(),'precision1'))
dw_2.setitem(currow, 'plc_meter_flag',dbtypedata.getitemstring(dbtypedata.getrow(),'plc_meter_flag'))
if dbtypedata.getitemstring(dbtypedata.getrow(), 'plc_meter_flag')='1' then
insertplccount=insertplccount+1
end if
dw_2.setitem(currow, 'ctl_elect_flag',dbtypedata.getitemstring(dbtypedata.getrow(),'ctl_elect_flag'))
dw_2.setitem(currow, 'onoff_type',dbtypedata.getitemstring(dbtypedata.getrow(),'onoff_type'))
dw_2.setitem(currow, 'tariff_no',dbtypedata.getitemstring(dbtypedata.getrow(),'TARIFF_NO'))
dw_2.setitem(currow, 'password',dbtypedata.getitemstring(dbtypedata.getrow(),'PASSWORD'))
dw_2.setitem(currow, 'password_key',dbtypedata.getitemstring(dbtypedata.getrow(),'PASSWORD_KEY'))
dw_2.setitem( currow, 'install_date',string(today()))
dw_2.setitem( currow, 'usage_type',ls_usageno)
dw_2.setitem( currow, 'phase','X')
end if
//更新表
li_resultupdate=dw_2.update(true,false)
if li_resultupdate=1 then
dw_2.modify('meter.dist_no.update="no"')
dw_2.modify('meter.con_no.update="no"')
dw_2.modify('meter.meter_no.update="no"')
dw_2.modify('meter.asset_no.update="no"')
dw_2.modify('meter.dist_no.update+meter.con_no.update+meter.asset_no.update="no"')
dw_2.modify('datawindow.table.update=~'jc_write_files~'')
dw_2.modify('jc_write_files.user_no.update="yes"')
dw_2.modify('jc_write_files.assets_no.update="yes"')
dw_2.modify('jc_write_files.meter_sn.update="yes"')
li_resultupdate=dw_2.update()
if li_resultupdate=1 then
commit using sqlca;
else
messagebox('提示','更新数据出错。~r~n~r~n错误号:'+string(sqlca.sqldbcode)+'~r~n~r~n错误信息:' +sqlca.sqlerrtext)
rollback using sqlca;
end if
dw_2.modify('meter.dist_no.update="yes"')
dw_2.modify('meter.con_no.update="yes"')
dw_2.modify('meter.meter_no.update="yes"')
dw_2.modify('meter.asset_no.update="yes"')
dw_2.modify('meter.dist_no.update+meter.con_no.update+meter.asset_no.update="yes"')
dw_2.modify('datawindow.table.update=~'meter~'')
dw_2.modify('jc_write_files.user_no.update="no"')
dw_2.modify('jc_write_files.assets_no.update="no"')
dw_2.modify('jc_write_files.meter_sn.update="no"')
else
messagebox("更新表失败","返回数据表")
rollback using SQLCA;
end if
if dw_2.update()=1 then
select meter_total,plc_meter_total into :meter_total,:plc_meter_total from concentrator where dist_no=:ls_dist_no and con_no=:ls_con_no using sqlca;
if (not isnull(meter_total)) and (not isnull(plc_meter_total)) then
meter_total=meter_total+insertcount
plc_meter_total=plc_meter_total+insertplccount
else
meter_total=insertcount
plc_meter_total=insertplccount
end if
update concentrator set meter_total=:meter_total,plc_meter_total=:plc_meter_total where dist_no=:ls_dist_no and con_no=:ls_con_no using sqlca;
update district set meter_total=:meter_total,plc_meter_total=:plc_meter_total where dist_no=:ls_dist_no using sqlca;
if sqlca.sqlcode=0 then
commit using sqlca;
messagebox('提示','用户档案导入完成')
else
rollback using sqlca;
messagebox('提示','更新数据出错。~r~n~r~n错误号:'+string(sqlca.sqldbcode)+'~r~n~r~n错误信息:' +sqlca.sqlerrtext)
end if
else
//messagebox('提示','更新数据出错。~r~n~r~n错误号:'+string(sqlca.sqldbcode)+'~r~n~r~n错误信息:' +sqlca.sqlerrtext)
rollback using sqlca;
end if
[此贴子已经被作者于2007-5-24 11:13:05编辑过]