CGI プログラム16(パーツ入力テストプログラム)
戻る
#!C:/perl/bin/perl
# mp_start.pl Parts数据输入
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,$ref,@rec,$n);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
# 零件表格名
$t{ptable} = sprintf("%06d",$t{id});
$t{ptable} = 'a' . $t{ptable};
$t{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$t{dbh}->do("SET NAMES utf8");
if(!$t{dbh}){
print "SQL read ERROR!\n";
exit;
}
# 取出主机数据
($t{name},$t{series},$t{GR}) = $t{dbh}->selectrow_array("select name,series,GR from main_type1 where id = $t{id}");
# 取出零件名
# Table1の処理
$t{sth} = $t{dbh}->prepare("select id,name,code,group_id from $t{ptable}");
$t{sth}->execute;
@loop = ();
while (@rec = $t{sth}->fetchrow_array) {
my %row = (
aid => $t{id},
id => $rec[0],
name => $rec[1],
code => $rec[2],
group_id => $rec[3]
);
push(@loop, \%row);
}
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'mp_start.htm');
$t{template}->param(id => $t{id});
$t{template}->param(ptable => $t{ptable});
$t{template}->param(name => $t{name});
$t{template}->param(series => $t{series});
$t{template}->param(GR => $t{GR});
$t{template}->param(LOOP => \@loop);
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_start
ma_start
http://localhost/index.html
主機修正=>ma_modify.pl
パーツ入力=>mp_start.pl
ID |
NAME |
series |
GR |
DWG |
memo |
主機修正 |
パーツ入力 |
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# mp_input.pl Parts输入
use strict;
use CGI;
use HTML::Template;
my (%t,@loop,@rec,$n);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
$t{group} = $t{q}->param("group");
# 零件Table名
$t{ptable} = sprintf("%06d",$t{id});
$t{ptable} = 'a' . $t{ptable};
$t{template} = HTML::Template->new(filename => 'mp_input.htm');
$t{template}->param(id => $t{id});
$t{template}->param(ptable => $t{ptable});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
パーツ入力画面(mp_input)
パーツ入力画面(mp_input)
ptalbe=>
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# mp_select.pl 选择GR画面
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,$ref,@rec,$n);
$t{q} = new CGI;
$t{aid} = $t{q}->param("aid");
$t{id} = $t{q}->param("id");
# 零件表格名
$t{ptable} = sprintf("%06d",$t{id});
$t{ptable} = 'a' . $t{ptable};
$t{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$t{dbh}->do("SET NAMES utf8");
if(!$t{dbh}){
print "SQL read ERROR!\n";
exit;
}
# 取出GR数据
$t{GR} = $t{dbh}->selectrow_array("select GR from main_type1 where id = $t{id}");
$t{dbh}->disconnect;
#
@{ $t{GRs} } = split(/==/,$t{GR});
for $n ( 1 .. $#{ $t{GRs} } ) {
my %row = (
grid => $n,
name => $t{GRs}[$n]
);
push(@loop, \%row);
}
$t{template} = HTML::Template->new(filename => 'mp_select.htm');
$t{template}->param(aid => $t{aid});
$t{template}->param(id => $t{id});
$t{template}->param(GR => $t{GR});
$t{template}->param(LOOP => \@loop);
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
mp_select
选择GR画面(mp_select)
aID==>
pID==>
GR=>
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# mp_select2.pl GR确定
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,$ref,@rec,$n);
$t{q} = new CGI;
$t{aid} = $t{q}->param("aid");
$t{pid} = $t{q}->param("pid");
$t{grid} = $t{q}->param("GR");
# 零件表格名
$t{ptable} = sprintf("%06d",$t{aid});
$t{ptable} = 'a' . $t{ptable};
$t{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$t{dbh}->do("SET NAMES utf8");
if(!$t{dbh}){
print "SQL read ERROR!\n";
exit;
}
# 更新group_id
$t{sql} = 'UPDATE ' . $t{ptable} . ' set group_id = "';
$t{sql} .= $t{grid} . '" where id = ' . $t{pid};
$t{DO} = $t{dbh}->do($t{sql});
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'mp_select2.htm');
$t{template}->param(aid => $t{aid});
$t{template}->param(pid => $t{pid});
$t{template}->param(grid => $t{grid});
$t{template}->param(sql => $t{sql});
$t{template}->param(DO => $t{DO});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
mp_select2
GR确定(mp_select2)
aID==>
pID==>
GRID=>
sql=>
DO=>
-------------------------------------------------------------------------------
HTML::Template使用时的出错
push(@{ $$ref->{NO} },$n);
push(@{ $$ref->{grname} },$t{grname});
C:\Inetpub\Scripts>perl mp_start.pl
HTML::Template->output() : fatal error in loop output : Can't call method "isa"
on unblessed reference at C:/Perl/site/lib/HTML/Template.pm line 2563.
at mp_start.pl line 70
push(@{ $$ref{NO} },$n);
push(@{ $$ref{grname} },$t{grname});
C:\Inetpub\Scripts>perl mp_start.pl
HTML::Template->output() : fatal error in loop output : HTML::Template::param()
: attempt to set parameter 'grloop' with a scalar - parameter is not a TMPL_VAR!
at C:/Perl/site/lib/HTML/Template.pm line 3068
at mp_start.pl line 70
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# mp_update1.pl Parts修改
use strict;
use DBI;
use CGI;
use HTML::Template;
my (%t,@loop,@rec,$n);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
$t{aid} = $t{q}->param("aid");
# 零件Table名
$t{ptable} = sprintf("%06d",$t{aid});
$t{ptable} = 'a' . $t{ptable};
$t{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$t{dbh}->do("SET NAMES utf8");
if(!$t{dbh}){
print "SQL read ERROR!\n";
exit;
}
# 取出数据
($t{name},$t{code}) = $t{dbh}->selectrow_array("select name,code from $t{ptable} where id = $t{id}");
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'mp_update1.htm');
$t{template}->param(id => $t{id});
$t{template}->param(aid => $t{aid});
$t{template}->param(ptable => $t{ptable});
$t{template}->param(name => $t{name});
$t{template}->param(code => $t{code});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
パーツ修改画面(mp_update1)
パーツ修改画面(mp_update1)
aid=>
ptalbe=>
id=>
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# mp_update2.pl 零件修改确定
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,$ref,@rec,$n);
$t{q} = new CGI;
$t{aid} = $t{q}->param("aid");
$t{pid} = $t{q}->param("id");
$t{name} = $t{q}->param("name");
$t{code} = $t{q}->param("code");
# 零件表格名
$t{ptable} = sprintf("%06d",$t{aid});
$t{ptable} = 'a' . $t{ptable};
$t{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$t{dbh}->do("SET NAMES utf8");
if(!$t{dbh}){
print "SQL read ERROR!\n";
exit;
}
# 更新name和code
$t{sql} = 'UPDATE ' . $t{ptable} . ' set name = "';
$t{sql} .= $t{name} . '" where id = ' . $t{pid};
$t{DO} = $t{dbh}->do($t{sql});
$t{sql} = 'UPDATE ' . $t{ptable} . ' set code = "';
$t{sql} .= $t{code} . '" where id = ' . $t{pid};
$t{DO} = $t{dbh}->do($t{sql});
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'mp_update2.htm');
$t{template}->param(aid => $t{aid});
$t{template}->param(pid => $t{pid});
$t{template}->param(sql => $t{sql});
$t{template}->param(DO => $t{DO});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
mp_update2
零件修改确定(mp_update2)
aID==>
pID==>
DO=>
sql=>
-------------------------------------------------------------------------------
mp_start
零件输入开始画面(mp_start)
http://localhost/scripts/ma_start.pl
aID==>
ptable==>
主机TYPE=>
主机TYPE的series=>
GR=>
-------------------------------------------------------------------------------
戻る