mscenq1
戻る
######################################
# mscenq1_p.pl==>(パーツ選択テストプログラム)
# mscenq1_p.htmに出力する
######################################
use strict;
use DBI;
use CGI qw/:standard/;
use HTML::Template;
my(%t,$n,$n1,@loop1,@loop2,@loop3,@loop4,@loop5,@engine_loop);
# データベースに連結
$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;
}
# enq1テーブルのourrefを読む
$t{enq1_maxid} = $t{dbh}->selectrow_array("select max(id) from enq1");
@{ $t{list} } = $t{dbh}->selectrow_array("select name1id, type1id, maker1id,
dwg1id,partsid,NUid,memo from enq1 where id = $t{enq1_maxid}");
$t{template} = HTML::Template->new(filename => 'mscenq1_p.htm');
$t{template}->param(pro => "mscenq1_p.pl");
$t{template}->param(enq1_id => $t{enq1_maxid});
$t{name1id} = $t{list}[0]; # name1id
$t{type1id} = $t{list}[1]; # type1id
$t{maker1id} = $t{list}[2]; # maker1id
$t{dwg1id} = $t{list}[3]; # dwg1id
# 主機名の処理
@loop1 = ();
$t{NO}=0;
if ( $t{name1id} != 0 ) {
@{ $t{name1id_list} } = split(/==/,$t{name1id});
for $n ( 0 .. $#{ $t{name1id_list} } ) {
$t{name1id1} = $t{name1id_list}[$n];
($t{id1},$t{name1}) = $t{dbh}->selectrow_array("select id, name from main_name1 where id = $t{name1id1}");
$t{NO}++;
my %row = (
enq1_id => $t{enq1_maxid},
NO1 => $t{NO},
id1 => $t{id1},
name1 => $t{name1}
);
push(@loop1, \%row);
}
}
$t{template}->param(LOOP1 => \@loop1);
$t{template}->param(ENGINE_LOOP => \@engine_loop);
# 主機タイプの処理
@loop2 = ();
@engine_loop = ();
$t{NO}=0;
if ( $t{type1id} != 0 ) {
@{ $t{type1id_list} } = split(/==/,$t{type1id});
for $n ( 0 .. $#{ $t{type1id_list} } ) {
$t{type1id1} = $t{type1id_list}[$n];
($t{id1},$t{type1}) = $t{dbh}->selectrow_array("select id, name from main_type1 where id = $t{type1id1}");
$t{NO}++;
my %row = (
enq1_id => $t{enq1_maxid},
NO1 => $t{NO},
id1 => $t{id1},
type1 => $t{type1}
);
push(@loop2, \%row);
my %row = (
NO1 => $t{NO},
main_type1id => $t{id1}
);
# put this row into the loop by reference
push(@engine_loop, \%row);
}
}
$t{template}->param(LOOP2 => \@loop2);
$t{template}->param(ENGINE_LOOP => \@engine_loop);
# パーツの処理
$t{partsid} = $t{list}[4]; # partsid
$t{NUid} = $t{list}[5]; # NUid
if ( $t{partsid} ) {
@loop5 = ();
@{ $t{partsid_list0} } = split(/==/,$t{partsid});
@{ $t{NUid_list0} } = split(/==/,$t{NUid});
for $n (0 .. $#{ $t{partsid_list0} } ) {
$t{p_list1} = $t{partsid_list0}[$n];
$t{N_list1} = $t{NUid_list0}[$n];
@{ $t{partsid_list} } = split(/=/,$t{p_list1});
@{ $t{NUid_list} } = split(/=/,$t{N_list1});
$t{NO} = $n + 1;
for $n1 ( 0 .. $#{ $t{partsid_list} } ) {
$t{partsid1} = $t{partsid_list}[$n1];
$t{NUid1} = $t{NUid_list}[$n1];
@{ $t{parts} } = $t{dbh}->selectrow_array("select name, code from parts1 where id = $t{partsid1}");
$t{NU1} = $t{dbh}->selectrow_array("select parts_Unit from parts_nu where id = $t{NUid1}");
$t{NO2} = $n1 + 1;
my %row = (
enq1_id => $t{enq1_maxid},
NO1 => $t{NO},
NO2 => $t{NO2},
parts_id => $t{partsid1},
parts_name => $t{parts}[0],
parts_code => $t{parts}[1],
NU1 => $t{NU1}
);
# put this row into the loop by reference
push(@loop5, \%row);
}
}
$t{template}->param(LOOP5 => \@loop5);
}
# メモデータの処理
$t{memo} = $t{list}[6]; # memo
$t{template}->param(memo => $t{memo});
$t{dbh}->disconnect;
print $t{template}->output;
1;
-------------------------------------------------------------------------------
mscenq1_p
mscenq1_p
http://localhost/index.html
目的:船主からのENQ情報をデータベースに入力する。
mode:mscenq1_p;table:enq1;Perl:
ENQ_ID==>
主機名(main_name1)追加
主機名(main_type1)追加
パーツ追加
name,code,unit
メモ(memo)==>
戻る