MySQL操作程序三十二(零件选择程序,mscshowparts10.pl)

返回

[Sun Sep 12 21:25:37 2010] [error] [client 127.0.0.1] Use of uninitialized value in pattern match (m//) at ./pro/mscshowparts.pl line 122, <CONFIG> line [Sun Sep 12 21:25:37 2010] [error] [client 127.0.0.1] Use of uninitialized value in join or string at ./pro/mscshowparts.pl line 201, <CONFIG> line 11., [Sun Sep 12 21:24:43 2010] [error] [client 127.0.0.1] splice() offset past end of array at ./pro/mscshowparts.pl line 324, <CONFIG> line 11., referer: sub is_positive_integer { my $s = shift; 122: return ($s =~ /^\+?\d+$/ && $s > 0 ); } 修改如下 if ($t{p11s}[4]) { $t{valid} = is_positive_integer($t{p11s}[4]); if ( $t{valid} == 1 && $t{p11s}[4] <= $t{owner_maxid} ) { $t{owner} = $self->dbh->selectrow_array("SELECT company FROM owners WHERE id = $t{p11s}[4]"); } else { $t{owner} = 'X'; } } else { $t{owner} = 'X'; } 201: $t{p13} = join('/',@{ $t{p12} }); 324:@{ $t{percents} } = splice(@{ $t{percent_all} },$t{N1},$t{N2});;

# showprice.pl # 程序检查数据库数据 use strict; use DBI; my(%t,$n,@fld,@rec,$pref); print "This is showprice.pl.\n"; # 输入表格ID print "Please input type id="; chop($t{typeid}=<STDIN>); print "$t{typeid}\n"; # 连接数据库 $$pref{dsn} = "DBI:mysql:host=localhost;database=cookbook"; $$pref{dbh} = DBI->connect($$pref{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n"; $$pref{dbh}->do("SET NAMES utf8"); if(!$$pref{dbh}){ print "SQL read ERROR!\n"; exit; } # 取出DWG图号 $t{DWG} = $$pref{dbh}->selectrow_array("SELECT DWG FROM main_type1 WHERE id = $t{typeid}"); @{ $t{DWGs} } = split(/=/,$t{DWG}); # 零件表名 $t{ptable} = sprintf("%06d",$t{typeid}); $t{ptable} = 'a' . $t{ptable}; # 最大厂家id $t{maker_maxid} = $$pref{dbh}->selectrow_array("SELECT max(id) FROM makers"); # 取出零件 $t{sth} = $$pref{dbh}->prepare("select * from $t{ptable}"); $t{sth}->execute; while (@rec = $t{sth}->fetchrow_array) { $t{dwg} = $t{DWGs}[$rec[3]-1]; $t{Nuid1} = $rec[4]; $t{Nuid} = $$pref{dbh}->selectrow_array("select parts_Unit from parts_nu where id = $t{Nuid1}"); $t{p1} = $rec[6]; $t{p2} = $rec[7]; @{ $t{p1s} } = split(/==/,$t{p1}); for $n ( 0 .. $#{ $t{p1s} } ) { $t{p11} = $t{p1s}[$n]; @{ $t{p11s} } = split(/=/,$t{p11}); @{ $t{p12} } = @{ $t{p11s} }[0..1]; $t{valid} = is_positive_integer($t{p11s}[2]); if ( $t{valid} == 1 && $t{p11s}[2] <= 5 ) { $t{money1} = $$pref{dbh}->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]"); } else { $t{money1} = 'X'; } push(@{ $t{p12} },$t{money1}); push(@{ $t{p12} },$t{p11s}[3]); push(@{ $t{p12} },$t{p11s}[4]); $t{valid} = is_positive_integer($t{p11s}[5]); if ( $t{valid} == 1 && $t{p11s}[5] <= $t{maker_maxid} ) { $t{maker1} = $$pref{dbh}->selectrow_array("SELECT company FROM makers WHERE id = $t{p11s}[5]"); } else { $t{maker1} = 'X'; } push(@{ $t{p12} },$t{maker1}); if ( $t{p11s}[6] ) { push(@{ $t{p12} },$t{p11s}[6]); } else { push(@{ $t{p12} },'Y'); } print $rec[0],'--',"@{ $t{p11s} }\n"; print $rec[0],'==',"@{ $t{p12} }\n"; } } $t{sth}->finish; #print "ptable=$t{ptable}\n"; # 关闭数据库 $$pref{dbh}->disconnect; exit; sub is_positive_integer { my $s = shift; return ($s =~ /^\+?\d+$/ && $s > 0 ); }
mscshorparts.pl sub is_positive_integer { my $s = shift; return ($s =~ /^\+?\d+$/ && $s > 0 ); } sub show_price1 { my($row_ref,$self,$pref) = @_; my(%t,@members,%price1); $price1{p1} = ''; @{ $t{p1s} } = split(/==/,$$pref{p1}); $t{maker_maxid} = $self->dbh->selectrow_array("SELECT max(id) FROM makers"); for $n ( 0 .. $#{ $t{p1s} } ) { $t{p11} = $t{p1s}[$n]; @{ $t{p11s} } = split(/=/,$t{p11}); @{ $t{p12} } = @{ $t{p11s} }[0..1]; $t{valid} = is_positive_integer($t{p11s}[2]); if ( $t{valid} == 1 && $t{p11s}[2] <= 5 ) { $t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]"); } else { $t{money1} = 'X'; } push(@{ $t{p12} },$t{money1}); # push(@{ $t{p12} },$t{p11s}[2]); push(@{ $t{p12} },$t{p11s}[3]); push(@{ $t{p12} },$t{p11s}[4]); if ( $t{p11s}[5] ) { # 增加 $t{valid} = is_positive_integer($t{p11s}[5]); if ( $t{valid} == 1 && $t{p11s}[5] <= $t{maker_maxid} ) { $t{maker1} = $self->dbh->selectrow_array("SELECT company FROM makers WHERE id = $t{p11s}[5]"); } else { $t{maker1} = 'X'; } } else { $t{maker1} = 'X'; } push(@{ $t{p12} },$t{maker1}); # push(@{ $t{p12} },$t{p11s}[5]); if ( $t{p11s}[6] ) { # 增加 push(@{ $t{p12} },$t{p11s}[6]); } else { push(@{ $t{p12} },'Y'); } $t{p13} = join('/',@{ $t{p12} }); $price1{p1} .= '<OPTION VALUE="' . $t{p13} . '">' . $t{p13} . '</OPTION>'; @members = (); push @members, { %price1 }; $row_ref->{PRICE1} = [ @members ]; } return($row_ref,$self,$pref); } sub show_price2 { my($row_ref,$self,$pref) = @_; my(%t,@members,%price1); $price1{p1} = ''; @{ $t{p1s} } = split(/==/,$$pref{p1}); $t{owner_maxid} = $self->dbh->selectrow_array("SELECT max(id) FROM owners"); for $n ( 0 .. $#{ $t{p1s} } ) { $t{p11} = $t{p1s}[$n]; @{ $t{p11s} } = split(/=/,$t{p11}); @{ $t{p12} } = @{ $t{p11s} }[0..1]; $t{valid} = is_positive_integer($t{p11s}[2]); if ( $t{valid} == 1 && $t{p11s}[2] <= 5 ) { $t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]"); } else { $t{money1} = 'X'; } push(@{ $t{p12} },$t{money1}); # push(@{ $t{p12} },$t{p11s}[2]); push(@{ $t{p12} },$t{p11s}[3]); $t{valid} = is_positive_integer($t{p11s}[4]); if ( $t{valid} == 1 && $t{p11s}[4] <= $t{owner_maxid} ) { $t{owner} = $self->dbh->selectrow_array("SELECT company FROM owners WHERE id = $t{p11s}[4]"); } else { $t{owner} = 'X'; } push(@{ $t{p12} },$t{owner}); # push(@{ $t{p12} },$t{p11s}[4]); $t{p13} = join('/',@{ $t{p12} }); $price1{p1} .= '<OPTION VALUE="' . $t{p13} . '">' . $t{p13} . '</OPTION>'; @members = (); push @members, { %price1 }; $row_ref->{PRICE2} = [ @members ]; } return($row_ref,$self,$pref); }
mscparts10.htm ----------------------------------------------------------------- 搬家=>恢复 <form action="" method="post"> <input type="submit" value="更新价格"><p> <input type="hidden" name="id" value="<TMPL_VAR NAME="tid">"> <input type="hidden" name="enq1_id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="tname" value="<TMPL_VAR NAME="tname">"> <input type="hidden" name="NE1" value="<TMPL_VAR NAME="NE1">"> <input type="hidden" name="DWG" value="<TMPL_VAR NAME="DWG">"> <input type="hidden" name="rm" value="modenew_price"> </form> ----------------------------------------------------------------- 取消=>恢复 <td> <SELECT NAME = "<TMPL_VAR NAME="NO_P1">"> <TMPL_LOOP NAME="PRICE1"> <TMPL_VAR NAME="p1"> </TMPL_LOOP> </SELECT> </td> <td> <SELECT NAME = "<TMPL_VAR NAME="NO_P2">"> <TMPL_LOOP NAME="PRICE2"> <TMPL_VAR NAME="p1"> </TMPL_LOOP> </SELECT> </td> ----------------------------------------------------------------- mscshowparts10.pl,show_price1/show_price2放在mscshowparts.pl里面 $$row_ref{NO_P1} = 'price1_' . $rec[0]; # PRICE1 $$row_ref{NO_P2} = 'price2_' . $rec[0]; # PRICE2 # $$pref{p1} = $rec[6]; # ($row_ref,$self,$pref) = show_price1($row_ref,$self,$pref); # $$pref{p1} = $rec[7]; # ($row_ref,$self,$pref) = show_price2($row_ref,$self,$pref); sub show_price1 { my($row_ref,$self,$pref) = @_; my(%t,@members,%price1); $price1{p1} = ''; @{ $t{p1s} } = split(/==/,$$pref{p1}); for $n ( 0 .. $#{ $t{p1s} } ) { $t{p11} = $t{p1s}[$n]; @{ $t{p11s} } = split(/=/,$t{p11}); @{ $t{p12} } = @{ $t{p11s} }[0..1]; $t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]"); push(@{ $t{p12} },$t{money1}); push(@{ $t{p12} },$t{p11s}[3]); push(@{ $t{p12} },$t{p11s}[4]); $t{maker1} = $self->dbh->selectrow_array("SELECT company FROM makers WHERE id = $t{p11s}[5]"); push(@{ $t{p12} },$t{maker1}); push(@{ $t{p12} },$t{p11s}[6]); $t{p13} = join('/',@{ $t{p12} }); $price1{p1} .= '<OPTION VALUE="' . $t{p13} . '">' . $t{p13} . '</OPTION>'; @members = (); push @members, { %price1 }; $row_ref->{PRICE1} = [ @members ]; } return($row_ref,$self,$pref); } sub show_price2 { my($row_ref,$self,$pref) = @_; my(%t,@members,%price1); $price1{p1} = ''; @{ $t{p1s} } = split(/==/,$$pref{p1}); for $n ( 0 .. $#{ $t{p1s} } ) { $t{p11} = $t{p1s}[$n]; @{ $t{p11s} } = split(/=/,$t{p11}); @{ $t{p12} } = @{ $t{p11s} }[0..1]; $t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]"); push(@{ $t{p12} },$t{money1}); push(@{ $t{p12} },$t{p11s}[3]); $t{owner} = $self->dbh->selectrow_array("SELECT company FROM owners WHERE id = $t{p11s}[4]"); push(@{ $t{p12} },$t{owner}); $t{p13} = join('/',@{ $t{p12} }); $price1{p1} .= '<OPTION VALUE="' . $t{p13} . '">' . $t{p13} . '</OPTION>'; @members = (); push @members, { %price1 }; $row_ref->{PRICE2} = [ @members ]; } return($row_ref,$self,$pref); }
返回