数据库零件表管理程序与界面
戻る
显示所有零件,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
零件表格管理
零件表格管理
mode:mscparts1
enq1_id=>
Equipment Type=>,表格名=>,DB=>
ID |
Name |
Code |
group_id |
dwg_id |
Nuid |
weight |
price |
memo |
修正釦 |
|
|
|
|
|
|
|
|
|
|
显示一个零件(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
零件表格项目的修改
零件表格项目的修改
mode:mscparts2
enq1_id=>
Equipment Type=>,表格名=>,DB=>
更新数据(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
零件表格项目修改的确认
零件表格项目修改的确认
mode:mscparts3
enq1_id=>,
Equipment Type=>,表格名=>,DB=>
ID |
Name |
Code |
group_id |
dwg_id |
Nuid |
weight |
price |
memo |
終了釦 |
|
|
|
|
|
|
|
|
|
|
DO==>
SQL==>
戻る