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});
# 取出圖紙?zhí)? @loop2 = ();
for $n ( 0 .. $#{ $t{type1} } ) {
$t{type2} = $t{type1}[$n];
$t{part2} = $t{part1}[$n];
$t{QTY2} = $t{QTY1}[$n];
# 從main_type1中取出主機(jī)名和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});
# 根據(jù)enq2的零件編號從數(shù)據(jù)庫取出零件信息和所屬圖紙?zhí)? @{ $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});
}
# 合并重復(fù)的圖紙?zhí)? %seen = ();
@{ $t{dwgs2} } = ();
foreach $item (@{ $t{dwgs1} }) {
unless ( $seen{$item} ) {
$seen{$item} = 1;
push(@{ $t{dwgs2} },$item);
}
}
# 把數(shù)據(jù)放入HTML的TABLE的TR
for $n1 ( 0 .. $#{ $t{dwgs2} } ) {
$t{dwg1} = $t{dwgs2}[$n1];
$t{DWG1} = $t{DWGs}[$t{dwg1}-1];
# 取出圖紙?zhí)? $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);
}
# 必須置零,因?yàn)橄乱慌_主機(jī)的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}");
# 顯示對應(yīng)enq1的所有零件供挑選
# 從enq1取出主機(jī)編號(type1id),零件號碼(partsid),數(shù)量(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的一行是一個項(xiàng)目
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中取出主機(jī)名和DWG圖號
($t{id1},$t{type1},$t{DWG}) = $self->dbh->selectrow_array("select id, name,DWG from main_type1 where id = $t{type1id1}");
# 從零件名表中取出零件編號和圖紙?zhí)? @{ $t{pid_list} } = split(/=/,$t{partsid1});
@{ $t{Q_list} } = split(/=/,$t{QTY1});
@{ $t{DWGs} } = split(/=/,$t{DWG});
# 生成零件表名,根據(jù)enq1的零件編號從數(shù)據(jù)庫取出零件信息和所屬圖紙?zhí)? $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});
}
# 合并重復(fù)的圖紙?zhí)? %seen = ();
@{ $t{dwgs2} } = ();
foreach $item (@{ $t{dwgs1} }) {
unless ( $seen{$item} ) {
$seen{$item} = 1;
push(@{ $t{dwgs2} },$item);
}
}
# 把數(shù)據(jù)放入HTML的TABLE的TR
for $n1 ( 0 .. $#{ $t{dwgs2} } ) {
$t{dwg1} = $t{dwgs2}[$n1];
$t{DWG1} = $t{DWGs}[$t{dwg1}-1];
# 取出圖紙?zhí)? $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);
}
# 必須置零,因?yàn)橄乱慌_主機(jī)的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");
# 顯示對應(yīng)enq1的所有零件供挑選
# 從enq1取出主機(jī)編號(type1id),零件號碼(partsid),數(shù)量(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的一行是一個項(xiàng)目
@{ $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中取出主機(jī)名和DWG圖號
($t{id1},$t{type1},$t{DWG}) = $self->dbh->selectrow_array("select id, name,DWG from main_type1 where id = $t{type1id1}");
# 從零件名表中取出零件編號和圖紙?zhí)? @{ $t{pid_list} } = split(/=/,$t{partsid1});
@{ $t{Q_list} } = split(/=/,$t{QTY1});
@{ $t{DWGs} } = split(/=/,$t{DWG});
# 生成零件表名,根據(jù)enq1的零件編號從數(shù)據(jù)庫取出零件信息和所屬圖紙?zhí)? $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});
}
# 合并重復(fù)的圖紙?zhí)? %seen = ();
@{ $t{dwgs2} } = ();
foreach $item (@{ $t{dwgs1} }) {
unless ( $seen{$item} ) {
$seen{$item} = 1;
push(@{ $t{dwgs2} },$item);
}
}
# 第一層:主機(jī)名
# 第二層:圖紙?zhí)?XXXDWG設(shè)定為不知道圖紙?zhí)?
# 第三層:零件名
# 把數(shù)據(jù)放入HTML的TABLE的TR
for $n1 ( 0 .. $#{ $t{dwgs2} } ) {
$t{dwg1} = $t{dwgs2}[$n1];
$t{DWG1} = $t{DWGs}[$t{dwg1}-1];
# 取出圖紙?zhí)? $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);
}
# 必須置零,因?yàn)橄乱慌_主機(jī)的DWG極有可能同名!
$t{plist}{id}{$t{dwg1}} = ();
$t{plist}{name}{$t{dwg1}} = ();
$t{plist}{code}{$t{dwg1}} = ();
}
}
# 顯示被選擇的零件
@loop2 = ();
$t{type_dwg1_old} = 0;
@{ $t{type1s} } = (); # 存放主機(jī)編號
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} ) { # 圖紙?zhí)?一個零件
$t{type_dwg1_old} = $t{select_dwg1}{$t{tp}};
# 圖紙?zhí)? $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};
# 從零件表中取出數(shù)據(jù)
@{ $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] . ' | '; # 零件數(shù)量
$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 { # 一個零件
# 從零件表中取出數(shù)據(jù)
@{ $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] . ' | '; # 零件數(shù)量
$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
# 把主機(jī)的重復(fù)編號除去,
%{ $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;