数据库零件表输入程序与界面
戻る
零件输入开始(mscenq1_parts1.pl)
sub mscenq1_parts1 { my $self = shift; my(%t,@rec,@loop,$n); # Get CGI query object $t{q} = $self->query(); $t{NE1} = $t{q}->param("NE1"); $t{enq1_id} = $t{q}->param("enq1_id"); $t{main_type1id} = $t{q}->param("main_type1id"); $t{name1} = $t{q}->param("name1"); $t{DWG0} = $t{q}->param("DWG0"); $t{DWG0_id} = $t{q}->param("DWG0_id"); $t{template} = $self->load_tmpl('mscenq1_parts1.htm') || die "error loading tmpl"; $t{partsname} = $t{q}->param("partsname"); $t{partscode} = $t{q}->param("partscode"); $t{partsqty} = $t{q}->param("partsqty"); $t{template}->param(partsname => $t{partsname}); $t{template}->param(partscode => $t{partscode}); $t{template}->param(partsqty => $t{partsqty}); # 读取主机的DWG $t{DWG} = $self->dbh->selectrow_array("SELECT DWG FROM main_type1 WHERE id = $t{main_type1id}"); if ( $t{DWG} ne 'NULL' ) { @{ $t{DWGs} } = split(/=/,$t{DWG}); @loop = (); for $n ( 0 .. $#{ $t{DWGs} } ) { my %row = ( content => $t{DWGs}[$n] ); push(@loop, \%row); } $t{template}->param(DWG => \@loop); } if ( $t{DWG0} ) { $t{template}->param(DWG0 => $t{DWG0}); $t{template}->param(DWG0_id => $t{DWG0_id}); } else { $t{template}->param(DWG0 => $t{DWGs}[0]); $t{template}->param(DWG0_id => 1); } $t{template}->param(NE1 => $t{NE1}); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(main_type1id => $t{main_type1id}); $t{template}->param(name1 => $t{name1}); $t{template}->param(pro => "mscenq1_parts1.pl"); return $t{template}->output; } 1;
mscenq1_parts1.htm
enq1_parts1(parts输入)
enq1_parts1(parts输入)
mode:modeenq1_parts1
">
main_type1id=>
,主机名=
enq1_id=>
,NE1=>
pro=>
输入或选择图纸号=>
New DWG
Old DWG
">
">
">
">
">
使用图纸,序号==>
,图号==>
输入parts的name,code,QTY
Parts name
Parts code
Parts QTY
">
">
">
">
">
">
读取零件数据(mscenq1_parts2.pl)
sub mscenq1_parts2 { my $self = shift; my(%t,$n,@loop1,@loop2,@rec); # Get CGI query object $t{q} = $self->query(); $t{NE1} = $t{q}->param("NE1"); # 选择主机的顺序 $t{enq1_id} = $t{q}->param("enq1_id"); $t{main_type1id} = $t{q}->param("main_type1id"); $t{name1} = $t{q}->param("name1"); $t{partsname} = $t{q}->param("partsname"); $t{partscode} = $t{q}->param("partscode"); $t{partsqty} = $t{q}->param("partsqty"); $t{partsqty} = $t{q}->param("partsqty"); $t{DWG0} = $t{q}->param("DWG0"); $t{DWG0_id} = $t{q}->param("DWG0_id"); # 取出数据 @{ $t{names} } = split(/\r\n/,$t{partsname}); @{ $t{codes} } = split(/\r\n/,$t{partscode}); @{ $t{qtys} } = split(/\r\n/,$t{partsqty}); $t{names_length} = $#{ $t{names} }; $t{codes_length} = $#{ $t{codes} }; $t{qtys_length} = $#{ $t{qtys} }; $t{length1} = $t{names_length} - 1; if ( $t{names_length} == $t{codes_length} && $t{names_length} == $t{qtys_length} && $t{names}[0] !~ /END/ ) { $t{mode} = 1; } else { # 出错,返回修改 $t{mode} = 2; } if ( $t{mode} == 1 ) { # 输入数据输出到HTML画面 @loop1 = (); for $n ( 0 .. $t{length1} ) { $t{id} = $n + 1; $t{n1} = $t{names}[$n]; $t{n1} =~ s/=/\
/g; #多行显示 $t{c1} = $t{codes}[$n]; $t{q1} = $t{qtys}[$n]; $t{unit1} = 'unit1_' . $t{id}; my %row = ( unit1 => $t{unit1}, id => $t{id}, name => $t{n1}, code => $t{c1}, qty => $t{q1} ); push(@loop1, \%row); } $t{template} = $self->load_tmpl('mscenq1_parts2.htm') || die "error loading tmpl"; $t{template}->param(DWG0 => $t{DWG0}); $t{template}->param(DWG0_id => $t{DWG0_id}); $t{template}->param(LOOP1 => \@loop1); $t{template}->param(NE1 => $t{NE1}); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(main_type1id => $t{main_type1id}); $t{template}->param(name1 => $t{name1}); $t{template}->param(pro => "mscenq1_parts2.pl"); $t{template}->param(partsname => $t{partsname}); $t{template}->param(partscode => $t{partscode}); $t{template}->param(partsqty => $t{partsqty}); $t{template}->param(names_length => $t{names_length}); $t{template}->param(codes_length => $t{codes_length}); $t{template}->param(qtys_length => $t{qtys_length}); $t{template}->param(mode => $t{mode}); } else { $t{template} = $self->load_tmpl('mscenq1_parts22.htm') || die "error loading tmpl"; $t{template}->param(DWG0 => $t{DWG0}); $t{template}->param(DWG0_id => $t{DWG0_id}); $t{template}->param(NE1 => $t{NE1}); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(main_type1id => $t{main_type1id}); $t{template}->param(name1 => $t{name1}); $t{template}->param(pro => "mscenq1_parts2.pl"); $t{template}->param(partsname => $t{partsname}); $t{template}->param(partscode => $t{partscode}); $t{template}->param(partsqty => $t{partsqty}); $t{template}->param(names_length => $t{names_length}); $t{template}->param(codes_length => $t{codes_length}); $t{template}->param(qtys_length => $t{qtys_length}); $t{template}->param(mode => $t{mode}); } return $t{template}->output; } 1;
mscenq1_parts2.htm
enq1_parts2(Parts输入确认,Unit选择)
enq1_parts2(Parts输入确认,Unit选择)
mode:modeenq1_parts2
">
">
">
">
">
">
">
">
">
NE1==>
主机NO=
;主机名=
enq1_id=>
pro=>
partsname=>
partscode=>
partsqty=>
names_length=>
codes_length=>
qtys_length=>
mode=>
使用图纸,序号==>
,图号==>
enq1输入数据
ID
name
code
QTY
unit
" size=1>
PCS
SET
BOX
ROLL
PAIR
CAN
DOZ
">
">
">
">
">
">
">
">
">
零件的比较和输入DB(mscenq1_parts3.pl)
sub mscenq1_parts3 { my $self = shift; my(%t,$n,$n1,@loop1,@loop2,@rec); my(@a,@b,@union,@isect,@diff,$e,%count,%count2); # 零件的单位 @{ $t{units_list} } = (PCS,SET,BOX,ROLL,PAIR,CAN,DOZ); # Get CGI query object $t{q} = $self->query(); $t{NE1} = $t{q}->param("NE1"); $t{enq1_id} = $t{q}->param("enq1_id"); $t{main_type1id} = $t{q}->param("main_type1id"); $t{name1} = $t{q}->param("name1"); $t{partsname} = $t{q}->param("partsname"); $t{partscode} = $t{q}->param("partscode"); $t{partsqty} = $t{q}->param("partsqty"); $t{DWG0} = $t{q}->param("DWG0"); $t{DWG0_id} = $t{q}->param("DWG0_id"); # 读人机界面的数据 @{ $t{names} } = split(/\r\n/,$t{partsname}); @{ $t{codes} } = split(/\r\n/,$t{partscode}); @{ $t{qtys} } = split(/\r\n/,$t{partsqty}); # 要去掉最后一个END $t{length1} = $#{ $t{names} } - 1; # units的存档 @{ $t{units} } = (); for $n ( 0 .. $t{length1} ) { $t{id} = $n + 1; $t{unit1} = 'unit1_' . $t{id}; $t{unit1} = $t{q}->param("$t{unit1}"); push(@{ $t{units} },$t{unit1}); } # enq1的输入数据进行配对(和DB同步时会打乱顺序) @b = (); for $n ( 0 .. $t{length1} ) { $t{n1} = $t{names}[$n]; $t{c1} = $t{codes}[$n]; $t{u1} = $t{units}[$n]; $t{c1} = $t{c1} . '===' . $t{DWG0_id}; $t{enq1_names}{$t{c1}} = $t{n1}; $t{enq1_units}{$t{c1}} = $t{u1}; push @b, $t{c1}; } # 零件表的名称 $t{ptable} = sprintf("%06d",$t{main_type1id}); $t{ptable} = 'a' . $t{ptable}; # 先判断是否是empty table. $t{count1} = $self->dbh->selectrow_array("SELECT count(*) FROM $t{ptable}"); # 取出DB的Parts的codes %count = %count2 = (); @union = @isect = @diff = (); if ( $t{count1} != 0 ) { # 只有在不是空表格时才进行操作 @{ $t{dbcodes} } = (); $t{sth} = $self->dbh->prepare("SELECT id,name,code,dwg_id,Nuid FROM $t{ptable}"); $t{sth}->execute; while ( @rec = $t{sth}->fetchrow_array ) { # 要考虑DWG不同,但是code相同的情况 $t{dbcode1} = $rec[2] . '===' . $rec[3]; # 这个操作合并code和DWG push @{ $t{dbcodes} }, $t{dbcode1}; $t{dbids}{$t{dbcode1}} = $rec[0]; $t{dbnames}{$t{dbcode1}} = $rec[1]; $t{dbunits}{$t{dbcode1}} = $rec[4]; $t{idmax} = $rec[0]; } $t{sth}->finish; # 同步作业 @a = @{ $t{dbcodes} }; foreach $e (@a,@b) { $count{$e}++ }; # @union = sort {$a<=>$b} keys %count; @union = sort keys %count; foreach $e ( keys %count ) { if ($count{$e} == 2 ) { $count2{$e}++; } } for $n ( 0 .. $#b ) { next if $count2{$b[$n]}; $t{idmax}++; push @diff, $b[$n]; $t{enq1_ids}{$b[$n]} = $t{idmax}; } # @diff = sort {$a<=>$b} @diff; # @diff = sort @diff; } else { # 空表格的情况 @union = @diff = @b; $t{idmax} = 0; for $n ( 0 .. $#b ) { $t{idmax}++; $t{enq1_ids}{$b[$n]} = $t{idmax}; } } # 显示零件表所有零件 for $n ( 0 .. $#union ) { $t{NO} = $n + 1; if ( $t{dbnames}{$union[$n]} ) { $t{name1} = $t{dbnames}{$union[$n]}; $t{unit1} = $t{dbunits}{$union[$n]}; $t{id1} = $t{dbids}{$union[$n]}; } else { $t{name1} = $t{enq1_names}{$union[$n]}; $t{unit1} = $t{enq1_units}{$union[$n]}; $t{id1} = $t{enq1_ids}{$union[$n]}; } $t{name1} =~ s/=/\
/g; # 多行显示 ($t{c1},$t{dwg_id}) = split(/===/,$union[$n]); $t{alllist}{NO}{$t{dwg_id}}{$t{c1}} = $t{NO}; $t{alllist}{id1}{$t{dwg_id}}{$t{c1}} = $t{id1}; $t{alllist}{name1}{$t{dwg_id}}{$t{c1}} = $t{name1}; $t{alllist}{unit1}{$t{dwg_id}}{$t{c1}} = $t{units_list}[$t{unit1}-1]; } @loop2 = (); # 这个操作的目的是先按DWG,再按code排列 for $n ( sort keys %{ $t{alllist}{NO} } ) { for $n1 ( sort keys %{ $t{alllist}{NO}{$n} } ) { $t{NO} = $t{alllist}{NO}{$n}{$n1}; $t{id1} = $t{alllist}{id1}{$n}{$n1}; $t{name1} = $t{alllist}{name1}{$n}{$n1}; $t{unit1} = $t{alllist}{unit1}{$n}{$n1}; my %row = ( NO => $t{NO}, id => $t{id1}, name => $t{name1}, code => $n1, dwg_id => $n, unit => $t{unit1} ); push(@loop2, \%row); } } # 把新增加的零件插入DB中 if ( $#diff >= 0 ) { for $n ( 0 .. $#diff ) { $t{c1} = $diff[$n]; $t{n1} = $t{enq1_names}{$t{c1}}; $t{u1} = $t{enq1_units}{$t{c1}}; ($t{c1},$t{ctmp}) = split(/===/,$t{c1}); # 这个操作把code和DWG分开 $t{sql} = "INSERT INTO $t{ptable} (name,code,group_id,dwg_id,Nuid,weight) "; $t{sql} .= 'VALUES("' . $t{n1} . '","'; $t{sql} .= $t{c1} . '","'; $t{sql} .= "1" . '","'; $t{sql} .= $t{DWG0_id} . '","'; $t{sql} .= $t{u1} . '","1")'; $t{DO} = $self->dbh->do("$t{sql}"); } } # 把enq1的QTY等输入到对应的位置上(注意多主机的处理) # 这个操作把最后的END去掉 $t{QTY1} = join("=",@{ $t{qtys} }[0..$t{length1}]); # 取出现有的QTY $t{QTY} = $self->dbh->selectrow_array("SELECT QTY FROM enq1 WHERE id = $t{enq1_id}"); @{ $t{QTYs} } = split(/==/,$t{QTY}); @{ $t{QTYnews} } = (); for $n ( 0 .. $#{ $t{QTYs} } ) { $t{NO} = $n + 1; if ( $t{NO} == $t{NE1} ) { # 注意把老的也留下,C代表还没有输入一个零件 if ( $t{QTYs}[$n] ne 'C' ) { $t{QTY1} = $t{QTYs}[$n] . '=' . $t{QTY1}; } push(@{ $t{QTYnews} }, $t{QTY1}); } else { push(@{ $t{QTYnews} }, $t{QTYs}[$n]); } } $t{QTY1} = join("==",@{ $t{QTYnews} }); $t{sql} = 'UPDATE enq1 SET QTY = "'; $t{sql} .= $t{QTY1} . '" WHERE id = ' . $t{enq1_id}; $t{DO} = $self->dbh->do($t{sql}); # 从零件表中抽出id放入enq1中 $t{cs} = ''; for $n ( 0 .. $t{length1} ) { $t{c1} = $t{codes}[$n]; $t{cs} .= '_' . $t{c1}; } $t{sth} = $self->dbh->prepare("SELECT id, code, dwg_id FROM $t{ptable}"); $t{sth}->execute; @{ $t{pids} } = (); while ( @rec = $t{sth}->fetchrow_array ) { # 注意!除了code以外,DWG图纸号也要一致! if ( $t{cs} =~ /$rec[1]/ && $rec[2] == $t{DWG0_id} ) { push(@{ $t{pids} },$rec[0]); $t{db_psid}{$rec[1]} = $rec[0]; } } $t{sth}->finish; $t{partsid1} = join("=",@{ $t{pids} }); # 取出现有的partsid $t{partsid} = $self->dbh->selectrow_array("SELECT partsid FROM enq1 WHERE id = $t{enq1_id}"); @{ $t{partsids} } = split(/==/,$t{partsid}); @{ $t{partsidnews} } = (); for $n ( 0 .. $#{ $t{partsids} } ) { $t{NO} = $n + 1; if ( $t{NO} == $t{NE1} ) { # 注意把老的也留下 if ( $t{partsids}[$n] ne 'C' ) { $t{partsid1} = $t{partsids}[$n] . '=' . $t{partsid1}; } push(@{ $t{partsidnews} }, $t{partsid1}); } else { push(@{ $t{partsidnews} }, $t{partsids}[$n]); } } $t{partsid1} = join("==",@{ $t{partsidnews} }); $t{sql} = 'UPDATE enq1 SET partsid = "'; $t{sql} .= $t{partsid1} . '" WHERE id = ' . $t{enq1_id}; $t{DO} = $self->dbh->do($t{sql}); # enq1输入数据输出到HTML画面(一台主机) @loop1 = (); for $n ( 0 .. $t{length1} ) { $t{NO} = $n + 1; $t{n1} = $t{names}[$n]; $t{n1} =~ s/=/\
/g; #多行显示 $t{c1} = $t{codes}[$n]; $t{q1} = $t{qtys}[$n]; $t{unit1} = $t{units}[$n]; my %row = ( unit1 => $t{units_list}[$t{unit1}-1], NO => $t{NO}, id => $t{db_psid}{$t{c1}}, name => $t{n1}, code => $t{c1}, dwg_id => $t{DWG0_id}, qty => $t{q1} ); push(@loop1, \%row); } $t{template} = $self->load_tmpl('mscenq1_parts3.htm') || die "error loading tmpl"; $t{template}->param(LOOP1 => \@loop1); $t{template}->param(LOOP2 => \@loop2); $t{template}->param(NE1 => $t{NE1}); $t{template}->param(ptable => $t{ptable}); $t{template}->param(DO => $t{DO}); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(main_type1id => $t{main_type1id}); $t{template}->param(name1 => $t{name1}); $t{template}->param(partsname => $t{partsname}); $t{template}->param(partscode => $t{partscode}); $t{template}->param(partsqty => $t{partsqty}); $t{template}->param(DWG0 => $t{DWG0}); $t{template}->param(DWG0_id => $t{DWG0_id}); $t{template}->param(pro => "mscenq1_parts3.pl"); return $t{template}->output; } 1;
mscenq1_parts3.htm
enq1_parts3(Parts输入完成)
enq1_parts3(Parts输入完成)
mode:modeenq1_parts3
" value="1">
">
">
">
">
">
">
">
">
">
主机NO=
;主机名=
enq1_id=>
pro=>
partsname=>
partscode=>
partsqty=>
ptable=>
DO=>
使用图纸,序号==>
,图号==>
">
enq1输入零件
NO
ID
name
code
dwg_id
QTY
unit
数据库所有零件
NO
ID
name
code
dwg_id
unit
戻る