CGI プログラム15(主機(jī)入力テストプログラム)
戻る
#!C:/perl/bin/perl
# ma_start.pl 主機(jī)和零件數(shù)據(jù)輸入
# 07.12.17
use strict;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n);
$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{sth} = $t{dbh}->prepare("select * from main_type1");
$t{sth}->execute;
@loop = ();
while (@rec = $t{sth}->fetchrow_array) {
my %row = (
id => $rec[0],
name => $rec[1],
series => $rec[2],
GR => $rec[3],
DWG => $rec[4],
memo => $rec[5]
);
push(@loop, \%row);
}
$t{sth}->finish;
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_start.htm');
$t{template}->param(LOOP => \@loop);
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_start
ma_start
http://localhost/index.html
主機(jī)修正=>ma_modify.pl
パーツ入力=>mp_start.pl
ID |
NAME |
series |
GR |
DWG |
memo |
主機(jī)修正 |
パーツ入力 |
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_add.pl 追加主機(jī)項(xiàng)目開(kāi)始畫(huà)面
# 07.12.17
use strict;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n);
# 取出最大的ID
$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{id} = $t{dbh}->selectrow_array("select max(id) from main_type1");
$t{id} = $t{id} + 1;
$t{ptable} = sprintf("%06d",$t{id});
$t{ptable} = 'a' . $t{ptable};
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_add.htm');
$t{template}->param(maxid => $t{id});
$t{template}->param(ptable => $t{ptable});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_add
主機(jī)追加開(kāi)始畫(huà)面(ma_add)
http://localhost/scripts/ma_start.pl
按下決定后,在輸入以上數(shù)據(jù)的同時(shí),也生成零件表格。
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_insert.pl 追加主機(jī)項(xiàng)目執(zhí)行畫(huà)面
# 07.12.18
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
$t{ptable} = $t{q}->param("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{sql} = 'DROP TABLE IF EXISTS ' . $t{ptable} . ';';
$t{dbh}->do($t{sql});
$t{sql} = 'CREATE TABLE ' . $t{ptable};
$t{sql} .= ' (';
$t{sql} .= 'id INT AUTO_INCREMENT,';
$t{sql} .= 'name VARCHAR(50),';
$t{sql} .= 'code VARCHAR(50),';
$t{sql} .= 'group_id INT,';
$t{sql} .= 'dwg_id INT,';
$t{sql} .= 'price TEXT,';
$t{sql} .= 'oem TEXT,';
$t{sql} .= 'memo TEXT,';
$t{sql} .= 'PRIMARY KEY (id));';
$t{DO} = $t{dbh}->do($t{sql});
# 插入主機(jī)數(shù)據(jù)
$t{sql} = 'INSERT INTO main_type1 (id) VALUES("';
$t{sql} .= $t{id} . '")';
$t{DO1} = $t{dbh}->do($t{sql});
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_insert.htm');
$t{template}->param(id => $t{id});
$t{template}->param(DO => $t{DO});
$t{template}->param(ptable => $t{ptable});
$t{template}->param(DO1 => $t{DO1});
$t{template}->param(sql => $t{sql});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_insert
ma_insert
id==>
DO==>,ptable==>
DO1==>
sql==>
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_modify.pl 主機(jī)項(xiàng)目修正執(zhí)行畫(huà)面
# 07.12.18,19
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
$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;
}
# 取出主機(jī)數(shù)據(jù)
($t{name},$t{series},$t{GR},$t{DWG},$t{memo}) = $t{dbh}->selectrow_array("select name,series,GR,DWG,memo from main_type1 where id = $t{id}");
$t{dbh}->disconnect;
@{ $t{GRs} } = split(/==/,$t{GR});
@loop = ();
for $n ( 1 .. $#{ $t{GRs} } ) {
my %row = (
id => $t{id},
NO => $n,
name => $t{GRs}[$n]
);
push(@loop, \%row);
}
$t{template} = HTML::Template->new(filename => 'ma_modify.htm');
$t{template}->param(id => $t{id});
$t{template}->param(name => $t{name});
$t{template}->param(series => $t{series});
$t{template}->param(GRLOOP => \@loop);
$t{template}->param(DWG => $t{DWG});
$t{template}->param(memo => $t{memo});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_modify
主機(jī)修正開(kāi)始畫(huà)面(ma_modify)
http://localhost/scripts/ma_start.pl
ID==>
DWG=>">
memo=>">
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_addone.pl 追加主機(jī)1項(xiàng)目
# 07.12.18
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n);
$t{q} = new CGI;
$t{name} = $t{q}->param("name");
$t{id} = $t{q}->param("id");
$t{item} = $t{q}->param("item");
# 取出最大的ID
$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{sql} = 'UPDATE main_type1 set ' . $t{item} . ' = "';
$t{sql} .= $t{name} . '" where id = ' . $t{id};
$t{DO} = $t{dbh}->do($t{sql});
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_addone.htm');
$t{template}->param(id => $t{id});
$t{template}->param(name => $t{name});
$t{template}->param(item => $t{item});
$t{template}->param(sql => $t{sql});
$t{template}->param(DO => $t{DO});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_addone
主機(jī)1項(xiàng)目追加畫(huà)面(ma_addone)
ID==>
==>
sql==>
DO==>
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_addtwo.pl 追加主機(jī)1項(xiàng)目
# 07.12.18
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
$t{group} = $t{q}->param("group");
# 取出現(xiàn)在的GR
$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;
}
if ($t{group} == 0 ) {
$t{GR} = $t{dbh}->selectrow_array("select GR from main_type1 where id = $t{id}");
if ( $t{GR} ) {
@{ $t{line} } = split(/==/,$t{GR});
$t{group} = '';
for $n ( 0 .. $#{ $t{line} } ) {
$t{group} .= $t{line}[$n];
}
} else {
$t{group} = 'Example';
}
}
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_addtwo2.htm');
$t{template}->param(id => $t{id});
$t{template}->param(group => $t{group});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_addtwo2
主機(jī)多項(xiàng)目追加畫(huà)面(ma_addtwo2)
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_mread.pl 追加主機(jī)1項(xiàng)目
# 07.12.18
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n,@fld);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
$t{group} = $t{q}->param("group");
$t{item} = $t{q}->param("item");
@{ $t{line} } = split(/\n/,$t{group});
$t{GR} = '==';
for $n ( 0 .. $#{ $t{line} } ) {
$t{GR} .= $t{line}[$n] . '==';
}
#
$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{sql} = 'UPDATE main_type1 set ' . $t{item} . ' = "';
$t{sql} .= $t{GR} . '" where id = ' . $t{id};
$t{DO} = $t{dbh}->do($t{sql});
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_mread.htm');
$t{template}->param(id => $t{id});
$t{template}->param(item => $t{item});
$t{template}->param(GR => $t{GR});
$t{template}->param(sql => $t{sql});
$t{template}->param(DO => $t{DO});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_mread
主機(jī)的GR輸入(ma_mread)
ID==>
==>
sql==>
DO==>
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_grmodify.pl 修改主機(jī)1項(xiàng)目
# 07.12.19
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n,@fld);
$t{q} = new CGI;
$t{id} = $t{q}->param("id");
$t{NO} = $t{q}->param("NO");
# 取出主機(jī)1項(xiàng)目
$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{GR} = $t{dbh}->selectrow_array("select GR from main_type1 where id = $t{id}");
@{ $t{line} } = split(/==/,$t{GR});
$t{GR1} = $t{line}[$t{NO}];
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_grmodify.htm');
$t{template}->param(id => $t{id});
$t{template}->param(NO => $t{NO});
$t{template}->param(GR => $t{GR1});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_grmodify
主機(jī)1項(xiàng)目修改畫(huà)面(ma_grmodify)
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# ma_grmodify2.pl 修改主機(jī)1項(xiàng)目
# 07.12.19
use strict;
use CGI;
use DBI;
use HTML::Template;
my (%t,@loop,@rec,$n,@fld);
$t{q} = new CGI;
$t{GR1} = $t{q}->param("GR1");
$t{id} = $t{q}->param("id");
$t{NO} = $t{q}->param("NO");
# 取出主機(jī)1項(xiàng)目
$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{GR} = $t{dbh}->selectrow_array("select GR from main_type1 where id = $t{id}");
@{ $t{line} } = split(/==/,$t{GR});
for $n ( 0 .. $#{ $t{line} } ) {
$t{G1} = $t{line}[$n];
if ( $n == $t{NO} ) {
$t{G1} = $t{GR1};
}
push(@{ $t{newline} },$t{G1});
}
$t{GR} = '';
for $n ( 0 .. $#{ $t{newline} } ) {
$t{GR} .= $t{newline}[$n] . '==';
}
$t{item} = 'GR';
$t{sql} = 'UPDATE main_type1 set ' . $t{item} . ' = "';
$t{sql} .= $t{GR} . '" where id = ' . $t{id};
$t{DO} = $t{dbh}->do($t{sql});
$t{dbh}->disconnect;
$t{template} = HTML::Template->new(filename => 'ma_grmodify2.htm');
$t{template}->param(id => $t{id});
$t{template}->param(DO => $t{DO});
$t{template}->param(sql => $t{sql});
# HTMLファイル出力
print $t{template}->output;
1;
-------------------------------------------------------------------------------
ma_grmodify2
主機(jī)1項(xiàng)目結(jié)果畫(huà)面(ma_grmodify2)
DO==>
sql==>
-------------------------------------------------------------------------------
戻る
赤水市|
登封市|
通江县|
大兴区|
九龙城区|
麻栗坡县|
贵州省|
巩义市|
延边|
依兰县|
开封市|
锡林浩特市|
浑源县|
磐安县|
巴马|
日照市|
巴林左旗|
紫云|
宕昌县|
上饶市|
延边|
漳州市|
华坪县|
玉山县|
公安县|
吉木萨尔县|
苍溪县|
蚌埠市|
明水县|
阿坝县|
卓资县|
麻江县|
高尔夫|
龙州县|
酒泉市|
米泉市|
邯郸市|
蒙城县|
德安县|
鄂托克旗|
徐水县|