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} = '';
$t{line1} .= $t{type2} . '==>' . $t{DWG1};
$t{line1} .= ' |
';
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} = '';
$t{line1} .= $t{NO} . ' | ';
$t{line1} .= $t{name1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{QTY1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1};
$t{line1} .= ' |
';
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} = '';
$t{line1} .= $t{id1} . '==>' . $t{DWG1};
$t{line1} .= ' |
';
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} = '';
$t{line1} .= '' . $t{check1} . ' | ';
$t{line1} .= $t{NO} . ' | ';
$t{line1} .= $t{name1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1};
$t{line1} .= ' |
';
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;
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} = '';
$t{line1} .= $t{id1} . '==>' . $t{DWG1};
$t{line1} .= ' |
';
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} = '';
$t{line1} .= '' . $t{check1} . ' | ';
$t{line1} .= $t{NO} . ' | ';
$t{line1} .= $t{name1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1} . ' | ';
$t{line1} .= $t{code1};
$t{line1} .= ' |
';
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} = '';
$t{line1} .= $t{type_dwg1_old};
$t{line1} .= ' |
';
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} = '';
$t{line1} .= $t{NO} . ' | ';
$t{line1} .= $t{p1}[1] . ' | ';
$t{line1} .= $t{p1}[2] . ' | ';
$t{line1} .= $t{select_QTY}[$n] . ' | '; # 零件数量
$t{line1} .= $t{p1}[4] . ' | '; # 零件单位
$t{line1} .= $t{p1}[5] . ' | ';
$t{line1} .= $t{p1}[6];
$t{line1} .= ' |
';
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} = '';
$t{line1} .= $t{NO} . ' | ';
$t{line1} .= $t{p1}[1] . ' | ';
$t{line1} .= $t{p1}[2] . ' | ';
$t{line1} .= $t{select_QTY}[$n] . ' | '; # 零件数量
$t{line1} .= $t{p1}[4] . ' | '; # 零件单位
$t{line1} .= $t{p1}[5] . ' | ';
$t{line1} .= $t{p1}[6];
$t{line1} .= ' |
';
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;