从enq1中选择零件程序与界面

戻る

显示程序(mscenq2_body.pl)

sub mscenq2_body { my $self = shift; my(%t,$n,$n1,@loop1,@loop2); # Get CGI query object $t{q} = $self->query(); $t{enq2_id} = $t{q}->param("id"); # 显示已挑选好的enq2所有零件 # 取出type1id,partsid和QTY ($t{type1id},$t{partsid},$t{QTY}) = $self->dbh->selectrow_array("select type1id, partsid,QTY from enq2 where id = $t{enq2_id}"); @{ $t{type1} } = split(/==/,$t{type1id}); @{ $t{part1} } = split(/==/,$t{partsid}); @{ $t{QTY1} } = split(/==/,$t{QTY}); # 取出图纸号 @loop2 = (); for $n ( 0 .. $#{ $t{type1} } ) { $t{type2} = $t{type1}[$n]; $t{part2} = $t{part1}[$n]; $t{QTY2} = $t{QTY1}[$n]; # 从main_type1中取出主机名和DWG图号 $t{DWG} = $self->dbh->selectrow_array("select DWG from main_type1 where id = $t{type2}"); @{ $t{DWGs} } = split(/=/,$t{DWG}); # 零件表名 $t{ptable} = sprintf("%06d",$t{type2}); $t{ptable} = 'a' . $t{ptable}; @{ $t{pid_list} } = split(/=/,$t{part2}); @{ $t{Q_list} } = split(/=/,$t{QTY2}); # 根据enq2的零件编号从数据库取出零件信息和所属图纸号 @{ $t{dwgs1} } = (); for $n1 ( 0 .. $#{ $t{pid_list} } ) { $t{pid1} = $t{pid_list}[$n1]; $t{Q1} = $t{Q_list}[$n1]; @{ $t{p1} } = $self->dbh->selectrow_array("select * from $t{ptable} where id = $t{pid1}"); $t{dwg1} = $t{p1}[4]; push(@{ $t{plist}{id}{$t{dwg1}} },$t{p1}[0]); push(@{ $t{plist}{name}{$t{dwg1}} },$t{p1}[1]); push(@{ $t{plist}{code}{$t{dwg1}} },$t{p1}[2]); push(@{ $t{plist}{QTY}{$t{dwg1}} },$t{Q1}); push(@{ $t{dwgs1} },$t{dwg1}); } # 合并重复的图纸号 %seen = (); @{ $t{dwgs2} } = (); foreach $item (@{ $t{dwgs1} }) { unless ( $seen{$item} ) { $seen{$item} = 1; push(@{ $t{dwgs2} },$item); } } # 把数据放入HTML的TABLE的TR for $n1 ( 0 .. $#{ $t{dwgs2} } ) { $t{dwg1} = $t{dwgs2}[$n1]; $t{DWG1} = $t{DWGs}[$t{dwg1}-1]; # 取出图纸号 $t{line1} = '<tr bgcolor="#FFF000" align="center"><td colspan=7>'; $t{line1} .= $t{type2} . '==>' . $t{DWG1}; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop2, \%row); # 处理零件 for $n2 ( 0 .. $#{ $t{plist}{id}{$t{dwg1}} } ) { $t{NO}++; # enq1的所有Parts的编号 $t{pid1} = $t{plist}{id}{$t{dwg1}}[$n2]; $t{name1} = $t{plist}{name}{$t{dwg1}}[$n2]; $t{code1} = $t{plist}{code}{$t{dwg1}}[$n2]; $t{QTY1} = $t{plist}{QTY}{$t{dwg1}}[$n2]; $t{line1} = '<tr bgcolor="#F0FFF0" align="center"><td>'; $t{line1} .= $t{NO} . '</td><td>'; $t{line1} .= $t{name1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{QTY1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1}; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop2, \%row); } # 必须置零,因为下一台主机的DWG极有可能同名! $t{plist}{id}{$t{dwg1}} = (); $t{plist}{name}{$t{dwg1}} = (); $t{plist}{code}{$t{dwg1}} = (); } } # 取出船东询价编号enq1_id $t{enq1_id} = $self->dbh->selectrow_array("SELECT enq1id FROM enq2 WHERE id = $t{enq2_id}"); # 显示对应enq1的所有零件供挑选 # 从enq1取出主机编号(type1id),零件号码(partsid),数量(QTY) ($t{type1id},$t{partsid},$t{QTY}) = $self->dbh->selectrow_array("SELECT type1id,partsid,QTY FROM enq1 WHERE id = $t{enq1_id}"); @loop1 = (); $t{NO} = 0; @{ $t{type1id_list} } = split(/==/,$t{type1id}); @{ $t{partsid_list} } = split(/==/,$t{partsid}); @{ $t{QTY_list} } = split(/==/,$t{QTY}); # Table的一行是一个项目 for $n ( 0 .. $#{ $t{type1id_list} } ) { $t{type1id1} = $t{type1id_list}[$n]; $t{partsid1} = $t{partsid_list}[$n]; $t{QTY1} = $t{QTY_list}[$n]; # 从main_type1中取出主机名和DWG图号 ($t{id1},$t{type1},$t{DWG}) = $self->dbh->selectrow_array("select id, name,DWG from main_type1 where id = $t{type1id1}"); # 从零件名表中取出零件编号和图纸号 @{ $t{pid_list} } = split(/=/,$t{partsid1}); @{ $t{Q_list} } = split(/=/,$t{QTY1}); @{ $t{DWGs} } = split(/=/,$t{DWG}); # 生成零件表名,根据enq1的零件编号从数据库取出零件信息和所属图纸号 $t{ptable} = sprintf("%06d",$t{type1id1}); $t{ptable} = 'a' . $t{ptable}; @{ $t{dwgs1} } = (); for $n1 ( 0 .. $#{ $t{pid_list} } ) { $t{pid1} = $t{pid_list}[$n1]; $t{Q1} = $t{Q_list}[$n1]; @{ $t{p1} } = $self->dbh->selectrow_array("select * from $t{ptable} where id = $t{pid1}"); $t{dwg1} = $t{p1}[4]; push(@{ $t{plist}{id}{$t{dwg1}} },$t{p1}[0]); push(@{ $t{plist}{name}{$t{dwg1}} },$t{p1}[1]); push(@{ $t{plist}{code}{$t{dwg1}} },$t{p1}[2]); push(@{ $t{dwgs1} },$t{dwg1}); } # 合并重复的图纸号 %seen = (); @{ $t{dwgs2} } = (); foreach $item (@{ $t{dwgs1} }) { unless ( $seen{$item} ) { $seen{$item} = 1; push(@{ $t{dwgs2} },$item); } } # 把数据放入HTML的TABLE的TR for $n1 ( 0 .. $#{ $t{dwgs2} } ) { $t{dwg1} = $t{dwgs2}[$n1]; $t{DWG1} = $t{DWGs}[$t{dwg1}-1]; # 取出图纸号 $t{line1} = '<tr bgcolor="#FFF000" align="center"><td colspan=8>'; $t{line1} .= $t{id1} . '==>' . $t{DWG1}; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop1, \%row); # 处理零件 for $n2 ( 0 .. $#{ $t{plist}{id}{$t{dwg1}} } ) { $t{NO}++; # enq1的所有Parts的编号 $t{pid1} = $t{plist}{id}{$t{dwg1}}[$n2]; $t{name1} = $t{plist}{name}{$t{dwg1}}[$n2]; $t{code1} = $t{plist}{code}{$t{dwg1}}[$n2]; $t{check1} = 'c_t' . $t{type1id1} . '_d' . $t{dwg1} . '_p' . $t{pid1}; $t{line1} = '<tr bgcolor="#F0FFF0" align="center"><td>'; $t{line1} .= '<INPUT TYPE="checkbox" NAME="'; $t{line1} .= $t{check1} . '">' . $t{check1} . '</td><td>'; $t{line1} .= $t{NO} . '</td><td>'; $t{line1} .= $t{name1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1}; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop1, \%row); } # 必须置零,因为下一台主机的DWG极有可能同名! $t{plist}{id}{$t{dwg1}} = (); $t{plist}{name}{$t{dwg1}} = (); $t{plist}{code}{$t{dwg1}} = (); } } $t{template} = $self->load_tmpl('mscenq2_body.htm') || die "error loading tmpl"; $t{template}->param(pro => "mscenq2_body.pl"); $t{template}->param(enq2_id => $t{enq2_id}); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(LOOP1 => \@loop1); $t{template}->param(LOOP2 => \@loop2); return $t{template}->output; } 1;

选择(mscenq2_select.pl)

sub mscenq2_select { my $self = shift; my(%t,$n,$n1,@loop1,@loop2); # Get CGI query object $t{q} = $self->query(); $t{enq1_id} = $t{q}->param("enq1_id"); $t{enq2_id} = $t{q}->param("enq2_id"); # 显示对应enq1的所有零件供挑选 # 从enq1取出主机编号(type1id),零件号码(partsid),数量(QTY) ($t{type1id},$t{partsid},$t{QTY}) = $self->dbh->selectrow_array("SELECT type1id,partsid,QTY FROM enq1 WHERE id = $t{enq1_id}"); @loop1 = (); $t{NO} = 0; @{ $t{type1id_list} } = split(/==/,$t{type1id}); @{ $t{partsid_list} } = split(/==/,$t{partsid}); @{ $t{QTY_list} } = split(/==/,$t{QTY}); # Table的一行是一个项目 @{ $t{select} } = (); # 被选择的零件 for $n ( 0 .. $#{ $t{type1id_list} } ) { $t{type1id1} = $t{type1id_list}[$n]; $t{partsid1} = $t{partsid_list}[$n]; $t{QTY1} = $t{QTY_list}[$n]; # 从main_type1中取出主机名和DWG图号 ($t{id1},$t{type1},$t{DWG}) = $self->dbh->selectrow_array("select id, name,DWG from main_type1 where id = $t{type1id1}"); # 从零件名表中取出零件编号和图纸号 @{ $t{pid_list} } = split(/=/,$t{partsid1}); @{ $t{Q_list} } = split(/=/,$t{QTY1}); @{ $t{DWGs} } = split(/=/,$t{DWG}); # 生成零件表名,根据enq1的零件编号从数据库取出零件信息和所属图纸号 $t{ptable} = sprintf("%06d",$t{type1id1}); $t{ptable} = 'a' . $t{ptable}; @{ $t{dwgs1} } = (); for $n1 ( 0 .. $#{ $t{pid_list} } ) { $t{pid1} = $t{pid_list}[$n1]; $t{Q1} = $t{Q_list}[$n1]; @{ $t{p1} } = $self->dbh->selectrow_array("select * from $t{ptable} where id = $t{pid1}"); $t{dwg1} = $t{p1}[4]; push(@{ $t{plist}{id}{$t{dwg1}} },$t{p1}[0]); push(@{ $t{plist}{name}{$t{dwg1}} },$t{p1}[1]); push(@{ $t{plist}{code}{$t{dwg1}} },$t{p1}[2]); push(@{ $t{plist}{QTY}{$t{dwg1}} },$t{Q1}); push(@{ $t{dwgs1} },$t{dwg1}); } # 合并重复的图纸号 %seen = (); @{ $t{dwgs2} } = (); foreach $item (@{ $t{dwgs1} }) { unless ( $seen{$item} ) { $seen{$item} = 1; push(@{ $t{dwgs2} },$item); } } # 第一层:主机名 # 第二层:图纸号(XXXDWG设定为不知道图纸号) # 第三层:零件名 # 把数据放入HTML的TABLE的TR for $n1 ( 0 .. $#{ $t{dwgs2} } ) { $t{dwg1} = $t{dwgs2}[$n1]; $t{DWG1} = $t{DWGs}[$t{dwg1}-1]; # 取出图纸号 $t{line1} = '<tr bgcolor="#FFF000" align="center"><td colspan=8>'; $t{line1} .= $t{id1} . '==>' . $t{DWG1}; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop1, \%row); # 处理零件 for $n2 ( 0 .. $#{ $t{plist}{id}{$t{dwg1}} } ) { $t{NO}++; # enq1的所有Parts的编号 $t{pid1} = $t{plist}{id}{$t{dwg1}}[$n2]; $t{name1} = $t{plist}{name}{$t{dwg1}}[$n2]; $t{code1} = $t{plist}{code}{$t{dwg1}}[$n2]; $t{QTY1} = $t{plist}{QTY}{$t{dwg1}}[$n2]; $t{check1} = 'c_t' . $t{type1id1} . '_d' . $t{dwg1} . '_p' . $t{pid1}; $t{check2} = $t{q}->param("$t{check1}"); # 选择后的零件登记 if ( $t{check2} ) { push(@{ $t{select} },$t{pid1}); push(@{ $t{select_type1} },$t{type1id1}); push(@{ $t{select_QTY} },$t{QTY1}); # 这样编号的目的是为了防止pid1同名而引起的问题 # 这样编号的目的是为了防止dwg1同名而引起的问题 $t{tp} = $t{type1id1} . '_' . $t{pid1}; $t{select_dwg1}{$t{tp}} = $t{type1id1} . '_' . $t{dwg1}; } $t{line1} = '<tr bgcolor="#F0FFF0" align="center"><td>'; $t{line1} .= '<INPUT TYPE="checkbox" NAME="'; $t{line1} .= $t{check1} . '">' . $t{check1} . '</td><td>'; $t{line1} .= $t{NO} . '</td><td>'; $t{line1} .= $t{name1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1} . '</td><td>'; $t{line1} .= $t{code1}; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop1, \%row); } # 必须置零,因为下一台主机的DWG极有可能同名! $t{plist}{id}{$t{dwg1}} = (); $t{plist}{name}{$t{dwg1}} = (); $t{plist}{code}{$t{dwg1}} = (); } } # 显示被选择的零件 @loop2 = (); $t{type_dwg1_old} = 0; @{ $t{type1s} } = (); # 存放主机编号 for $n ( 0 .. $#{ $t{select} } ) { $t{NO} = $n + 1; $t{pid1} = $t{select}[$n]; $t{type1id1} = $t{select_type1}[$n]; $t{tp} = $t{type1id1} . '_' . $t{pid1}; push(@{ $t{type1s} },$t{type1id1}); push(@{ $t{partsids}{$t{type1id1}} },$t{pid1}); push(@{ $t{QTYs}{$t{type1id1}} },$t{select_QTY}[$n]); if ( $t{select_dwg1}{$t{tp}} ne $t{type_dwg1_old} ) { # 图纸号+一个零件 $t{type_dwg1_old} = $t{select_dwg1}{$t{tp}}; # 图纸号 $t{line1} = '<tr bgcolor="#FFF000" align="center"><td colspan=8>'; $t{line1} .= $t{type_dwg1_old}; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop2, \%row); $t{ptable} = sprintf("%06d",$t{type1id1}); $t{ptable} = 'a' . $t{ptable}; # 从零件表中取出数据 @{ $t{p1} } = $self->dbh->selectrow_array("select * from $t{ptable} where id = $t{pid1}"); $t{line1} = '<tr bgcolor="#F0FFF0" align="center"><td>'; $t{line1} .= $t{NO} . '</td><td>'; $t{line1} .= $t{p1}[1] . '</td><td>'; $t{line1} .= $t{p1}[2] . '</td><td>'; $t{line1} .= $t{select_QTY}[$n] . '</td><td>'; # 零件数量 $t{line1} .= $t{p1}[4] . '</td><td>'; # 零件单位 $t{line1} .= $t{p1}[5] . '</td><td>'; $t{line1} .= $t{p1}[6]; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop2, \%row); } else { # 一个零件 # 从零件表中取出数据 @{ $t{p1} } = $self->dbh->selectrow_array("select * from $t{ptable} where id = $t{pid1}"); $t{line1} = '<tr bgcolor="#F0FFF0" align="center"><td>'; $t{line1} .= $t{NO} . '</td><td>'; $t{line1} .= $t{p1}[1] . '</td><td>'; $t{line1} .= $t{p1}[2] . '</td><td>'; $t{line1} .= $t{select_QTY}[$n] . '</td><td>'; # 零件数量 $t{line1} .= $t{p1}[4] . '</td><td>'; # 零件单位 $t{line1} .= $t{p1}[5] . '</td><td>'; $t{line1} .= $t{p1}[6]; $t{line1} .= '</td></tr>'; my %row = ( line1 => $t{line1} ); push(@loop2, \%row); } } # enq2中写入type1id # 把主机的重复编号除去, %{ $t{seen} } = (); @{ $t{uniq} } = (); foreach $n ( @{ $t{type1s} } ) { unless ( $t{seen}{$n} ) { $t{seen}{$n} = 1; push(@{ $t{uniq} }, $n); } } $t{type1id1} = join('==',@{ $t{uniq} }); $t{sql} = 'UPDATE enq2 SET type1id = "'; $t{sql} .= $t{type1id1} . '" '; $t{sql} .= "where id =" . $t{enq2_id}; $t{DO} = $self->dbh->do("$t{sql}"); # enq2中写入partsid和QTY for $n ( 0 .. $#{ $t{uniq} } ) { $t{type1id1} = $t{uniq}[$n]; $t{parts1} = join('=',@{ $t{partsids}{$t{type1id1}} }); push(@{ $t{parts2} },$t{parts1}); $t{QTY1} = join('=',@{ $t{QTYs}{$t{type1id1}} }); push(@{ $t{Qs} },$t{QTY1}); } $t{partsid} = join('==',@{ $t{parts2} }); $t{sql} = 'UPDATE enq2 SET partsid = "'; $t{sql} .= $t{partsid} . '" '; $t{sql} .= "where id =" . $t{enq2_id}; $t{DO} = $self->dbh->do("$t{sql}"); $t{QTY} = join('==',@{ $t{Qs} }); $t{sql} = 'UPDATE enq2 SET QTY = "'; $t{sql} .= $t{QTY} . '" '; $t{sql} .= "where id =" . $t{enq2_id}; $t{DO} = $self->dbh->do("$t{sql}"); $t{template} = $self->load_tmpl('mscenq2_body.htm') || die "error loading tmpl"; $t{template}->param(pro => "mscenq2_select.pl"); $t{template}->param(enq2_id => $t{enq2_id}); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(LOOP1 => \@loop1); $t{template}->param(LOOP2 => \@loop2); return $t{template}->output; } 1;

mscenq2_body.htm

<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>挑选零件(enq2)</TITLE> <style type="text/css"> body { background: lightcyan; color:black; margin-left:2em;margin-right:2em;} </style> </HEAD> <BODY bgcolor="#FFFFFF"> <center><h2>挑选零件(enq2)</h2></center> 目的:从船东询价enq1中挑选有关零件。<br> mode:mscenq2_body;table:enq2;Perl:<TMPL_VAR NAME="pro"> <hr color="#003366"> enq2_id=><TMPL_VAR NAME="enq2_id"><br> enq1_id=><TMPL_VAR NAME="enq1_id"><br> <hr> <center> 显示项目(从enq2表格中取):ITEM顺序/Type/name/code/QTY/Units/Weight/Prices/memo <table width=80% align="center" border=1 cellpadding=5> <tr bgcolor="#FFD700" align="center"> <th>ITEM</th> <th>name</th> <th>code</th> <th>QTY</th> <th>unit</th> <th>weight</th> <th>price</th> </tr> <TMPL_LOOP NAME="LOOP2"> <TMPL_VAR NAME="line1"> </TMPL_LOOP> </table> <hr> <form action="" method="post"> <table width=80% align="center" border=1 cellpadding=5> <tr bgcolor="#FFD700" align="center"> <th>选择</th> <th>ITEM</th> <th>name</th> <th>code</th> <th>QTY</th> <th>unit</th> <th>weight</th> <th>price</th> </tr> <TMPL_LOOP NAME="LOOP1"> <TMPL_VAR NAME="line1"> </TMPL_LOOP> </table> <input type="submit" value="选择后点击"><p> <input type="hidden" name="enq1_id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="enq2_id" value="<TMPL_VAR NAME="enq2_id">"> <input type="hidden" name="rm" value="modeenq2_select"> </form> </center> <hr color="#003366"> <form action="" method="post"> <input type="submit" value="ヘッダ入力へ"><p> <input type="hidden" name="id" value="<TMPL_VAR NAME="enq2_id">"> <input type="hidden" name="rm" value="modeenq2_header"> </form> <form action="" method="post"> <input type="submit" value="生成EXCEL"><p> <input type="hidden" name="id" value="<TMPL_VAR NAME="enq2_id">"> <input type="hidden" name="rm" value="modeenq2"> </form> <form action="" method="post"> <input type="submit" value="enq2(To メーカー)作成開始へ戻る"><p> <input type="hidden" name="rm" value="modeenq2_start"> </form> </BODY> </HTML>
戻る