$hid=isset($_POST['id'])?$_POST['id']:exit;
$src=isset($_POST['src'])?$_POST['src']:exit;
$rn=isset($_POST['recordN'])?$_POST['recordN']:exit;
$pn=isset($_POST['pageN'])?$_POST['pageN']:exit;
$part=isset($_POST['fixpart'])?$_POST['fixpart']:exit;
include('inc/mlog.php');
include('inc/head.php');
chk_priv('X');
include('inc/cols.php');
include('inc/tbs.php');
function get_id($str)
{
$sql="select id from #temp2 where fieldname='".$str."'";
list($id)=mssql_fetch_array(mssql_query($sql));
if(trim($id)=='')
{ $id=""; return $id; }
else
{
$id=$id-1;
return $id;
}
}
function getint($var)
{
$var=substr($var,0,strpos($var,"."));
return $var;
}
$sql="INSERT sys_hist(pwid,act,cont,tm) VALUES('$pwid','IMPORT','$hid',getdate())";
mssql_query($sql);
$tb_rpts='tmp_'.$hid;
$sql="select ROW_NUMBER() OVER (ORDER BY aa.name) AS id,* into #temp2 from
(SELECT a.tablename as name,a.fieldname,a.typelength,a.ifnull,b.text as cdefault from
(select A.name as tablename ,b.name as fieldname,c.name+'('+cast(b.length as varchar)+')' as typelength,b.isnullable as ifnull,B.cdefault
from sysobjects A ,syscolumns B,systypes C
where A.xtype='u' and a.id=b.id and B.xusertype=c.xusertype
) a left join syscomments B on a.cdefault=b.id
where A.tablename='$tb_rpts'
)aa";
mssql_query($sql);
if($rn==$pn)
{
//$sql="SELECT * FROM $tb_rpts where id>400";
$nStart=($pn-1)*$part+1;
$sql="SELECT * FROM $tb_rpts where id>=$nStart";
}
else
{ //$sql="SELECT * FROM $tb_rpts where id>400";
$nStart=($pn-1)*$part+1;
$nEnd=($pn)*$part;
$sql="SELECT * FROM $tb_rpts where id between $nStart and $nEnd";
}
//die("$sql");
$res=mssql_query($sql);// or rmdie('error');
$nrrcd = mssql_num_rows($res) or rmdie('no record');
echo "$sql";
$res=mssql_query($sql);// or rmdie('error');
while ($arr=mssql_fetch_array($res)){
$id=$arr[$id_cn];
$sql="SELECT COUNT(*) FROM dat_info WHERE $id_en='$id'";
$row=mssql_fetch_row(mssql_query($sql));
if($row[0]){
echo "duplicated: $id
n";
continue;
}
$var=$id_en;
$val="'$id'";
foreach ($info_cols as $idx => $dat){
//$str=isset($arr[$dat[CN_COL]])?$arr[$dat[CN_COL]]:'';
//print $str;
/*if($dat[CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_»éÒö×´¿ö_ÐÅÏ¢»ñÈ¡ÈÕÆÚ')
{
$idd=get_id($dat[CN_COL]);
$str=$arr[$idd];
//print "¸öÈËÉí·ÝÐÅÏ¢_»éÒö×´¿ö_ÐÅÏ¢»ñÈ¡ÈÕÆÚ".$str;
}
if($dat[CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_×î¸ßѧÀú_ÐÅÏ¢»ñÈ¡ÈÕÆÚ')
{
$idd=get_id($dat[CN_COL]);
$str=$arr[$idd];
//print "¸öÈËÉí·ÝÐÅÏ¢_×î¸ßѧÀú_ÐÅÏ¢»ñÈ¡ÈÕÆÚ".$str;
}
if($dat[CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_Ö°³Æ_ÐÅÏ¢»ñÈ¡ÈÕÆÚ')
{
$idd=get_id($dat[CN_COL]);
$str=$arr[$idd];
//print "¸öÈËÉí·ÝÐÅÏ¢_»éÒö×´¿ö_ÐÅÏ¢»ñÈ¡ÈÕÆÚ".$str;
}
if($dat[CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_»éÒö×´¿ö_»éÒöÃ÷ϸ')
{
$idd=get_id($dat[CN_COL]);
$str=$arr[$idd];
//print "¸öÈËÉí·ÝÐÅÏ¢_×î¸ßѧÀú_ÐÅÏ¢»ñÈ¡ÈÕÆÚ".$str;
}
if($dat[CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_×î¸ßѧÀú_ѧÀúÃ÷ϸ')
{
$idd=get_id($dat[CN_COL]);
$str=$arr[$idd];
//print "¸öÈËÉí·ÝÐÅÏ¢_»éÒö×´¿ö_ÐÅÏ¢»ñÈ¡ÈÕÆÚ".$str;
}*/
$idd=get_id($dat[CN_COL]);
if(trim($idd)=='')
{$str='';}
else
{$str=$arr[$idd];}
function_exists($dat[FUNC]) and eval('$str='.$dat[FUNC].'($str);');
$val.=",'$str'";
$var.=",".$dat[EN_COL];
}
$sql="INSERT dat_info(rpt_typ,rpt_src,$var) VALUES('$src',$hid,$val)";
mssql_query($sql);// or rmdie("mssqlserver error:"."
SQL: ".$sql."
n");
do_data_rows($tb_enquiry, $enquiry_cols, $id);
do_data_rows($tb_addr, $addr_cols, $id);
do_data_rows($tb_job, $job_cols, $id);
do_data_rows($tb_card, $card_cols, $id);
do_data_rows($tb_loan, $loan_cols, $id);
do_data_rows($tb_tele, $tele_cols, $id);
do_data_rows($tb_spec, $spec_cols, $id);
do_data_rows($tb_comm, $comm_cols, $id);
do_data_rows($tb_dspt, $dspt_cols, $id);
}
mssql_close();
//}
//$sql="DROP TABLE `$tb_rpts`";
//mssql_query($sql) or rmdie(mssql_error()."
SQL: ".$sql."
n");
if($rn>$pn){
echo "you have only finished the "."$pn"." of "."$rn"." step! So you have to go next....
";
$pn=$pn+1;
?>
include('inc/foot.php');
?>
function do_data_rows($tbname, $cols, $id){
global $arr, $id_en;
//if (empty($arr[$cols[0][CN_COL]]))
// return;
$idd=get_id($cols[0][CN_COL]);
$first=$cols[0][CN_COL];
//$str_change=$arr[$idd];
if(trim($idd)=='')
{$str_change='';}
else
{$str_change=$arr[$idd];}
if(empty($str_change))
return;
$n=count($cols);
$var=$id_en;
$val="'$id'";
for ($i=0; $i//$str=isset($arr[$cols[$i][CN_COL]])?$arr[$cols[$i][CN_COL]]:'';
/*if($cols[$i][CN_COL]=='ÒøÐÐÐÅÓÃ_ÐÅÓÿ¨_¶þÊ®ËÄÔÂÄÚ¸÷ÔÂ͸֧×ܶî×´¿ö')
{
$idd=get_id($cols[$i][CN_COL]);
//print "mmmmmmmmmmmm".$idd;
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='ÒøÐÐÐÅÓÃ_´û¿î_¶þÊ®ËÄÔÂÄÚ¸÷Ô»¹¿î×´¿ö')
{
$idd=get_id($cols[$i][CN_COL]);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_¹¤×÷µ¥Î»_ÐÅÏ¢»ñÈ¡ÈÕÆÚ')
{
$idd=get_id($cols[$i][CN_COL]);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_µØÖ·_ÐÅÏ¢»ñÈ¡ÈÕÆÚ')
{
$idd=get_id($cols[$i][CN_COL]);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_¹¤×÷µ¥Î»_¹¤×÷Ã÷ϸ')
{
$idd=get_id($cols[$i][CN_COL]);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_¹¤×÷µ¥Î»_¹¤×÷ÐòºÅ')
{
$idd=get_id($cols[$i][CN_COL]);
$str=$arr[$idd];
} */
$idd=get_id($cols[$i][CN_COL]);
if(trim($idd)=='')
{$str='';}
else
{$str=$arr[$idd];}
//print $str;
//$idd=get_id($cols[$i][CN_COL]);
//$str=$arr[$idd];
function_exists($cols[$i][FUNC]) and eval('$str='.$cols[$i][FUNC].'($str);');
$val.=",'$str'";
$var.=",".$cols[$i][EN_COL];
}
$sql="INSERT $tbname($var) VALUES($val)";
mssql_query($sql) or rmdie("error1"."
SQL: ".$sql."
n");
//print $sql;
$j=1;
$newstr=$cols[0][CN_COL].$j;
$idd=get_id($newstr);
$str_change=$arr[$idd];
//print "newstr"."$newstr"."=="."$str_change"."over";
//while (!empty($arr[$cols[0][CN_COL].$j])){
while (!empty($str_change)){
$var=$id_en;
$val="'$id'";
for ($i=0; $i//$str=isset($arr[$cols[$i][CN_COL].$j])?$arr[$cols[$i][CN_COL].$j]:'';
/* if($cols[$i][CN_COL]=='ÒøÐÐÐÅÓÃ_ÐÅÓÿ¨_¶þÊ®ËÄÔÂÄÚ¸÷ÔÂ͸֧×ܶî×´¿ö')
{
$tempstr=$cols[$i][CN_COL].$j;
$idd=get_id($tempstr);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='ÒøÐÐÐÅÓÃ_´û¿î_¶þÊ®ËÄÔÂÄÚ¸÷Ô»¹¿î×´¿ö')
{
$tempstr=$cols[$i][CN_COL].$j;
$idd=get_id($tempstr);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_¹¤×÷µ¥Î»_ÐÅÏ¢»ñÈ¡ÈÕÆÚ')
{
$tempstr=$cols[$i][CN_COL].$j;
$idd=get_id($tempstr);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_µØÖ·_ÐÅÏ¢»ñÈ¡ÈÕÆÚ')
{
$tempstr=$cols[$i][CN_COL].$j;
$idd=get_id($tempstr);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_¹¤×÷µ¥Î»_¹¤×÷ÐòºÅ')
{
$tempstr=$cols[$i][CN_COL].$j;
$idd=get_id($tempstr);
$str=$arr[$idd];
}
if($cols[$i][CN_COL]=='¸öÈËÉí·ÝÐÅÏ¢_¹¤×÷µ¥Î»_¹¤×÷Ã÷ϸ')
{
$tempstr=$cols[$i][CN_COL].$j;
$idd=get_id($tempstr);
$str=$arr[$idd];
} */
$tempstr=$cols[$i][CN_COL].$j;
$idd=get_id($tempstr);
if(trim($idd)=='')
{$str='';}
else
{$str=$arr[$idd];}
//print $str;
//$tempstr=$cols[$i][CN_COL].$j;
//$idd=get_id($tempstr);
//$str=$arr[$idd];
function_exists($cols[$i][FUNC]) and eval('$str='.$cols[$i][FUNC].'($str);');
$val.=",'$str'";
$var.=",".$cols[$i][EN_COL];
}
$j++;
$sql="INSERT $tbname($var) VALUES($val)";
mssql_query($sql) or rmdie("error2"."
SQL: ".$sql."
n");
//print "second"."$j".$sql;
$newstr=$cols[0][CN_COL].$j;
$idd=get_id($newstr);
if(trim($idd)=='')
{$str_change='';}
else
{$str_change=$arr[$idd];}
//$str_change=$arr[$idd];
//print "newstr="."$newstr"."$j"."==".$str_change."over";
if(empty($str_change))
return;
}
}
?>
au+1
py_enqids
sys_enqids
sys_hist
sys_log_transact
sys_transact_uat
t_blacklist
t_company
t_indiv
truncate table dat_addr2;
truncate table dat_card2;
truncate table dat_enquiry2;
truncate table dat_info2;
truncate table dat_job2;
truncate table dat_loan2;
truncate table dat_special2;
truncate table dat_telecom2;
truncate table sys_enqids2;
truncate table sys_hist2;
truncate table sys_log_transact2;
truncate table sys_user2;
truncate table tmp_company2;
truncate table tmp_individual2;
truncate table t_blacklist2;
truncate table t_company2;
truncate table t_lookup2;
truncate table t_notes2;
truncate table t_phone2;
truncate table dat_ssi2;
truncate table py_info2;
--1
truncate table dat_addr;
insert into dat_addr
select * from dat_addr2;
--2
truncate table dat_card;
update dat_card2 set [getdate]=0 where [getdate] is null;
insert into dat_card
select * from dat_card2;
--3
truncate table dat_enquiry;
insert into dat_enquiry
select * from dat_enquiry2;
--4
truncate table dat_info;
update dat_info2 set date_first_card=0
where date_first_card is null;
update dat_info2 set date_first_loan=0
where date_first_loan is null;
update dat_info2 set education_getdate=0
where education_getdate is null;
update dat_info2 set marriage_getdate=0
where marriage_getdate is null;
update dat_info2 set job_getdate=0
where job_getdate is null;
update dat_info2 set birthday=0
where birthday is null;
update dat_loan2 set latest_repay_date=0 where latest_repay_date is null;
insert into dat_info
select * from dat_info2;
--5
truncate table dat_job;
insert into dat_job
select * from dat_job2;
--6
truncate table dat_loan;
update dat_loan2
set latest_repay_date=0 where latest_repay_date is null;
insert into dat_loan select * from dat_loan2;
--7
truncate table dat_special;
insert into dat_special
select * from dat_special2;
--8
truncate table dat_telecom;
update dat_telecom2
set date_issuance=0 where date_issuance is null
insert into dat_telecom
select * from dat_telecom2;
--9 sys
truncate table sys_enqids;
insert into sys_enqids
select * from sys_enqids2;
--10
truncate table sys_hist;
insert into sys_hist
select * from sys_hist2;
--11
truncate table sys_log_transact;
insert into sys_log_transact
select * from sys_log_transact2;
--12
truncate table sys_user;
insert into sys_user
select * from sys_user2;
--13
truncate table tmp_company;
insert into tmp_company
select * from tmp_company2;
--14
truncate table tmp_individual;
insert into tmp_individual
select * from tmp_individual2;
--15
truncate table t_blacklist;
insert into t_blacklist select * from t_blacklist2;
--16
truncate table t_company;
insert into t_company
select * from t_company2;
--17
truncate table t_lookup;
insert into t_lookup
select * from t_lookup2;
--18
truncate table t_notes;
insert into t_notes
select * from t_notes2;
--19
truncate table t_phone;
insert into t_phone
select * from t_phone2
--20
truncate table dat_ssi;
insert into dat_ssi
select * from dat_ssi2;
--21
truncate table py_info;
insert into py_info
select * from py_info2;
update py_info2 set date_first_card='1900-01-01' where date_first_card is null;
update py_info2 set date_first_loan='1900-01-01' where date_first_loan is null;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/91551/viewspace-999544/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/91551/viewspace-999544/