数据库零件表管理程序与界面

戻る

显示所有零件,mscshowparts.pl

sub mscshowparts { my $self = shift; my(%t,$template,$n,@rec,@loop); # Get CGI query object $t{q} = $self->query(); # 连接数据库 $t{tname} = $t{q}->param("tname"); $t{id} = $t{q}->param("id"); $t{DB} = $t{q}->param("DB"); # HTMLファイルに出力 $t{html} = $t{q}->param("tmpl"); $t{html} = $t{html} . '.htm'; $template = $self->load_tmpl("$t{html}") || die "error loading tmpl"; # 以下处理是关键。因为有两个地方(ENQ输入时和DB管理)来访问。 # 通过这个处理,实现了"从哪儿来,回哪儿去。" if ( $t{DB} == 1 ) { $template->param(DB1 => 1); $template->param(ENQ1 => 0); } else { $t{enq1_id} = $t{q}->param("enq1_id"); $template->param(DB1 => 0); $template->param(ENQ1 => 1); $template->param(enq1_id => $t{enq1_id}); } $t{ptable} = sprintf("%06d",$t{id}); $t{ptable} = 'a' . $t{ptable}; @loop = (); $t{sth} = $self->dbh->prepare("SELECT * FROM $t{ptable}"); $t{sth}->execute; while ( @rec = $t{sth}->fetchrow_array ) { my $row_ref = (); # この初期化はとても重要! $$row_ref{DB} = $t{DB}; if ( $t{DB} == 0 ) { $$row_ref{enq1_id} = $t{enq1_id}; } $$row_ref{tid} = $t{id}; $$row_ref{tname} = $t{tname}; $$row_ref{ptable} = $t{ptable}; $$row_ref{id} = $rec[0]; $$row_ref{name} = $rec[1]; $$row_ref{code} = $rec[2]; $$row_ref{group_id} = $rec[3]; $$row_ref{dwg_id} = $rec[4]; $$row_ref{Nuid} = $rec[5]; $$row_ref{weight} = $rec[6]; $$row_ref{price1} = $rec[7]; $$row_ref{memo} = $rec[15]; # 排位注意! push(@loop, $row_ref); } $t{sth}->finish; $template->param(DB => $t{DB}); $template->param(ptable => $t{ptable}); $template->param(tname => $t{tname}); $template->param(THIS_LOOP => \@loop); return $template->output; } 1;

mscparts1.htm

<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>零件表格管理</TITLE> </HEAD> <BODY bgcolor="#FFFFFF"> <center> <h2>零件表格管理</h2></center> mode:mscparts1 <TMPL_IF NAME="DB1"> <form action="" method="post"> <input type="submit" value="Equipment Types管理へ戻る"><p> <input type="hidden" name="tmpl" value="msc261"> <input type="hidden" name="table" value="main_type1"> <input type="hidden" name="DB" value="<TMPL_VAR NAME="DB">"> <input type="hidden" name="items" value="id,name,gname_id,maker_id"> <input type="hidden" name="rm" value="modeshowall"> </form> </TMPL_IF> <TMPL_IF NAME="ENQ1"> <form action="" method="post"> <input type="submit" value="パーツ入力へ戻る"><p> <input type="hidden" name="id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="rm" value="modeenq1_parts"> </form> enq1_id=><TMPL_VAR NAME="enq1_id"> </TMPL_IF> Equipment Type=><TMPL_VAR NAME="tname">,表格名=><TMPL_VAR NAME="ptable">,DB=><TMPL_VAR NAME="DB"><br> <hr color="#003366"> <center> <table width=80% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=10%>ID</th> <th width=10%>Name</th> <th width=10%>Code</th> <th width=10%>group_id</th> <th width=10%>dwg_id</th> <th width=10%>Nuid</th> <th width=10%>weight</th> <th width=10%>price</th> <th width=10%>memo</th> <th width=10%>修正釦</th> </tr> <TMPL_LOOP NAME="this_loop"> <tr bgcolor="lightcyan" align="left"> <td><TMPL_VAR NAME="id"></td> <td><TMPL_VAR NAME="name"></td> <td><TMPL_VAR NAME="code"></td> <td><TMPL_VAR NAME="group_id"></td> <td><TMPL_VAR NAME="dwg_id"></td> <td><TMPL_VAR NAME="Nuid"></td> <td><TMPL_VAR NAME="weight"></td> <td><TMPL_VAR NAME="price1"></td> <td><TMPL_VAR NAME="memo"></td> <td> <form action="" method="post"> <input type="submit" value="修正"> <input type="hidden" name="tmpl" value="mscparts2"> <input type="hidden" name="ptable" value="<TMPL_VAR NAME="ptable">"> <input type="hidden" name="tname" value="<TMPL_VAR NAME="tname">"> <input type="hidden" name="items" value="id,name,code,group_id,dwg_id,Nuid,weight,price1,memo"> <input type="hidden" name="id" value="<TMPL_VAR NAME="id">"> <input type="hidden" name="tid" value="<TMPL_VAR NAME="tid">"> <input type="hidden" name="DB" value="<TMPL_VAR NAME="DB">"> <input type="hidden" name="enq1_id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="rm" value="modeshowpartsone"> </form> </td> </tr> </TMPL_LOOP> </table> </center> <hr color="#003366"> </BODY> </HTML>

显示一个零件(mscshowpartsone.pl)

sub mscshowpartsone { my $self = shift; my(%t,@arr,@arr1,$n); # Get CGI query object $t{q} = $self->query(); $t{DB} = $t{q}->param("DB"); $t{html} = $t{q}->param("tmpl"); $t{html} = $t{html} . '.htm'; $t{template} = $self->load_tmpl("$t{html}") || die "error loading tmpl"; $t{tid} = $t{q}->param("tid"); $t{tname} = $t{q}->param("tname"); $t{ptable} = $t{q}->param("ptable"); $t{id} = $t{q}->param("id"); $t{items} = $t{q}->param("items"); @arr = split(/,/,$t{items}); $t{items} = $arr[0]; for $n ( 1 .. $#arr ) { $t{items} = $t{items} . ',' . $arr[$n]; } @arr1 = (); @arr1 = $self->dbh->selectrow_array("SELECT $t{items} FROM $t{ptable} WHERE id = $t{id}"); for $n ( 0 .. $#arr ) { $t{name} = $arr[$n]; $t{value} = $arr1[$n]; $t{template}->param($t{name} => $t{value}); } if ( $t{DB} == 0 ) { $t{enq1_id} = $t{q}->param("enq1_id"); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(ENQ1 => 1); } $t{template}->param(DB => $t{DB}); $t{template}->param(tid => $t{tid}); $t{template}->param(tname => $t{tname}); $t{template}->param(ptable => $t{ptable}); return $t{template}->output; } 1;

mscparts2.htm

<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>零件表格项目的修改</TITLE> </HEAD> <BODY bgcolor="#FFFFFF"> <center> <h2>零件表格项目的修改</h2></center> mode:mscparts2 <form action="" method="post"> <input type="submit" value="返回零件表管理"><p> <input type="hidden" name="tmpl" value="mscparts1"> <input type="hidden" name="DB" value="<TMPL_VAR NAME="DB">"> <input type="hidden" name="id" value="<TMPL_VAR NAME="tid">"> <input type="hidden" name="tname" value="<TMPL_VAR NAME="tname">"> <input type="hidden" name="enq1_id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="rm" value="modeshowparts"> </form> <TMPL_IF NAME="ENQ1"> enq1_id=><TMPL_VAR NAME="enq1_id"> </TMPL_IF> <hr color="#003366"> Equipment Type=><TMPL_VAR NAME="tname">,表格名=><TMPL_VAR NAME="ptable">,DB=><TMPL_VAR NAME="DB"><br> <form action="" method="post"> <table> <tr><td>ID</td><td><TMPL_VAR NAME="id"></td></tr> <input type="hidden" name="id" value="<TMPL_VAR NAME="id">"> <tr><td>name</td><td><input type=text size=100 name=name value="<TMPL_VAR NAME="name">"></td></tr> <input type="hidden" name="name" value="<TMPL_VAR NAME="name">"> <tr><td>code</td><td><input type=text size=100 name=code value="<TMPL_VAR NAME="code">"></td></tr> <input type="hidden" name="code" value="<TMPL_VAR NAME="code">"> <tr><td>group_id</td><td><input type=text size=100 name=group_id value="<TMPL_VAR NAME="group_id">"></td></tr> <input type="hidden" name="group_id" value="<TMPL_VAR NAME="group_id">"> <tr><td>dwg_id</td><td><input type=text size=100 name=dwg_id value="<TMPL_VAR NAME="dwg_id">"></td></tr> <input type="hidden" name="dwg_id" value="<TMPL_VAR NAME="dwg_id">"> <tr><td>Nuid</td><td><input type=text size=100 name=Nuid value="<TMPL_VAR NAME="Nuid">"></td></tr> <input type="hidden" name="Nuid" value="<TMPL_VAR NAME="Nuid">"> <tr><td>weight</td><td><input type=text size=100 name=weight value="<TMPL_VAR NAME="weight">"></td></tr> <input type="hidden" name="weight" value="<TMPL_VAR NAME="weight">"> <tr><td>price1</td><td><input type=text size=100 name=price1 value="<TMPL_VAR NAME="price1">"></td></tr> <input type="hidden" name="price1" value="<TMPL_VAR NAME="price1">"> <tr><td>memo</td><td><input type=text size=100 name=memo value="<TMPL_VAR NAME="memo">"></td></tr> <input type="hidden" name="memo" value="<TMPL_VAR NAME="memo">"> </table> <input type="submit" value="入力"><p> <input type="hidden" name="tmpl" value="mscparts3"> <input type="hidden" name="tid" value="<TMPL_VAR NAME="tid">"> <input type="hidden" name="tname" value="<TMPL_VAR NAME="tname">"> <input type="hidden" name="DB" value="<TMPL_VAR NAME="DB">"> <input type="hidden" name="ptable" value="<TMPL_VAR NAME="ptable">"> <input type="hidden" name="items" value="id,name,code,group_id,dwg_id,Nuid,weight,price1,memo"> <input type="hidden" name="enq1_id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="rm" value="modepartsupdate"> </form> </BODY> </HTML>

更新数据(mscpartsupdate.pl)

sub mscpartsupdate { my $self = shift; my(%t,$items,@arr,@arr1,$n); # Get CGI query object $t{q} = $self->query(); $t{DB} = $t{q}->param("DB"); $t{html} = $t{q}->param("tmpl"); $t{html} = $t{html} . '.htm'; $t{template} = $self->load_tmpl("$t{html}") || die "error loading tmpl"; $t{tid} = $t{q}->param("tid"); $t{tname} = $t{q}->param("tname"); $t{ptable} = $t{q}->param("ptable"); $t{id} = $t{q}->param("id"); $items = $t{q}->param("items"); @arr = split(/,/,$items); @arr1 = (); for $n ( 0 .. $#arr ) { $t{name} = $arr[$n]; $t{one} = $t{q}->param($t{name}); push(@arr1,$t{one}); } $t{sql} = "UPDATE $t{ptable} SET "; for $n ( 1 .. ($#arr1-1) ) { $t{sql} .= $arr[$n] . '="' . $arr1[$n] . '",'; } $t{sql} .= $arr[$#arr1] . '="' . $arr1[$#arr1] . '" '; $t{sql} .= "where id =" . $t{id}; $t{update} = $self->dbh->do("$t{sql}"); for $n ( 0 .. $#arr ) { $t{name} = $arr[$n]; $t{value} = $arr1[$n]; $t{template}->param($t{name} => $t{value}); } $t{template}->param(DO => $t{update}); $t{template}->param(sql => $t{sql}); $t{template}->param(DB => $t{DB}); if ( $t{DB} == 0 ) { $t{enq1_id} = $t{q}->param("enq1_id"); $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(ENQ1 => 1); } $t{template}->param(tid => $t{tid}); $t{template}->param(tname => $t{tname}); $t{template}->param(ptable => $t{ptable}); return $t{template}->output; } 1;

mscparts3.htm

<HTML> <HEAD> <TITLE>零件表格项目修改的确认</TITLE> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> </HEAD> <BODY bgcolor="#FFFFFF"> <center> <h2>零件表格项目修改的确认</h2></center> <hr color="#003366"> mode:mscparts3<br> <TMPL_IF NAME="ENQ1"> enq1_id=><TMPL_VAR NAME="enq1_id">, </TMPL_IF> Equipment Type=><TMPL_VAR NAME="tname">,表格名=><TMPL_VAR NAME="ptable">,DB=><TMPL_VAR NAME="DB"><br> <center> <table width=80% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=10%>ID</th> <th width=10%>Name</th> <th width=10%>Code</th> <th width=10%>group_id</th> <th width=10%>dwg_id</th> <th width=10%>Nuid</th> <th width=10%>weight</th> <th width=10%>price</th> <th width=10%>memo</th> <th width=10%>終了釦</th> </tr> <tr bgcolor="lightcyan" align="left"> <td><TMPL_VAR NAME="id"></td> <td><TMPL_VAR NAME="name"></td> <td><TMPL_VAR NAME="code"></td> <td><TMPL_VAR NAME="group_id"></td> <td><TMPL_VAR NAME="dwg_id"></td> <td><TMPL_VAR NAME="Nuid"></td> <td><TMPL_VAR NAME="weight"></td> <td><TMPL_VAR NAME="price1"></td> <td><TMPL_VAR NAME="memo"></td> <td><form action="" method="post"> <input type="submit" value="終了"><p> <input type="hidden" name="tmpl" value="mscparts1"> <input type="hidden" name="id" value="<TMPL_VAR NAME="tid">"> <input type="hidden" name="DB" value="<TMPL_VAR NAME="DB">"> <input type="hidden" name="tname" value="<TMPL_VAR NAME="tname">"> <input type="hidden" name="enq1_id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="rm" value="modeshowparts"> </form> </td> </tr> </table> </center> DO==><TMPL_VAR NAME="DO"><br> SQL==><TMPL_VAR NAME="sql"><br> <hr color="#003366"> </BODY> </HTML>
戻る