CGI プログラム10
戻る
# mscenq1_c.pl==>(mscenq1.plのテストプログラム)
use strict;
use DBI;
use CGI qw/:standard/;
use HTML::Template;
my(%t,$n,$n1,@loop1,@loop2);
# データベースに連結
$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を読む
#@loop = (); # initialize an array to hold your loop
$t{enq1_maxid} = $t{dbh}->selectrow_array("select max(id) from enq1");
@{ $t{list} } = $t{dbh}->selectrow_array("select time,ourref,owner,ownerno,hullnoid,name1id, type1id, maker1id,
dwg1id,partsid,NUid,memo from enq1 where id = $t{enq1_maxid}");
$t{dbh}->disconnect;
$t{owner1_id} = $t{list}[2];
$t{owner1} = $t{dbh}->selectrow_array("select company from owners where id = $t{owner1_id}");
$t{hullnoid1} = $t{list}[4];
$t{hullno1} = $t{dbh}->selectrow_array("select HULL_NO from hull_no where id = $t{hullnoid1}");
$t{template} = HTML::Template->new(filename => 'mscenq1_c.htm');
$t{template}->param(pro => "mscenq1_c.pl");
$t{template}->param(enq1_id => $t{enq1_maxid});
$t{template}->param(time1 => $t{list}[0]);
$t{template}->param(ourref1 => $t{list}[1]);
$t{template}->param(owner1 => $t{owner1});
$t{template}->param(ownerno1 => $t{list}[3]);
$t{template}->param(hullno1 => $t{hullno1});
$t{name1id} = $t{list}[5]; # name1id
$t{type1id} = $t{list}[6]; # type1id
$t{maker1id} = $t{list}[7]; # maker1id
$t{dwg1id} = $t{list}[8]; # dwg1id
@loop1 = ();
if ( $t{name1id} != 0 ) {
@{ $t{name1id_list} } = split(/==/,$t{name1id});
@{ $t{type1id_list} } = split(/==/,$t{type1id});
@{ $t{maker1id_list} } = split(/==/,$t{maker1id});
@{ $t{dwg1id_list} } = split(/==/,$t{dwg1id});
for $n ( 0 .. $#{ $t{name1id_list} } ) {
$t{name1id1} = $t{name1id_list}[$n];
$t{type1id1} = $t{type1id_list}[$n];
$t{maker1id1} = $t{maker1id_list}[$n];
$t{dwg1id1} = $t{dwg1id_list}[$n];
$t{name1} = $t{dbh}->selectrow_array("select name from main_name1 where id = $t{name1id1}");
$t{type1} = $t{dbh}->selectrow_array("select name from main_type1 where id = $t{type1id1}");
$t{maker1} = $t{dbh}->selectrow_array("select name from main_maker1 where id = $t{maker1id1}");
$t{dwg1} = $t{dbh}->selectrow_array("select name from main_dwg1 where id = $t{dwg1id1}");
my %row = (
name1 => $t{name1},
type1 => $t{type1},
maker1 => $t{maker1},
dwg1 => $t{dwg1}
);
# put this row into the loop by reference
push(@loop1, \%row);
}
}
$t{template}->param(LOOP1 => \@loop1);
$t{partsid} = $t{list}[9]; # partsid
$t{NUid} = $t{list}[10]; # NUid
@loop2 = ();
@{ $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});
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}");
my %row = (
parts_list => $t{p_list1},
parts_name => $t{parts}[0],
parts_code => $t{parts}[1],
NU1 => $t{NU1}
);
# put this row into the loop by reference
push(@loop2, \%row);
}
}
$t{template}->param(LOOP2 => \@loop2);
$t{memo} = $t{list}[11]; # memo
$t{template}->param(memo => $t{memo});
print $t{template}->output;
1;
------------------------------------------------------------------------------
enq1(From 船主)
http://localhost/index.html
目的:船主からのENQ情報をデータベースに入力する。
mode:mscenq1;table:enq1;Perl:
ENQ_ID==>
TIME==>
OURREF==>
船主==>
船主データが存在しない場合,データベース管理=>船主データ(owners)=>船主テーブルの項目を追加
船主ENQ番号==>
HULL_NO==>
主機名(main_name1),主機タイプ(main_type1),主機メーカー(main_maker1),図面番号(main_dwg1)
,,,
パーツ
name,code,unit
,,,
メモ(memo)==>
戻る