📄 frm_zclassinfo.pas
字号:
{
***************************************************************
* 说明:班级基本信息维护 *
* 时间:2003/02/20 *
* 作者:杨泉清 *
***************************************************************
}
unit Frm_ZClassInfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ModalForm, DB, ADODB, ComCtrls, Grids, DBGrids, StdCtrls,
YLabelButton, ChangeImage, Menus, ExtCtrls, UErrDisplay;
type
TZClassInfo = class(TMyModalForm)
BtnNew: TChangeImg;
LbtnNew: TLabelB;
BtnEdit: TChangeImg;
LBtnEdit: TLabelB;
BtnDelete: TChangeImg;
LBtnDelete: TLabelB;
BtnRefresh: TChangeImg;
LBtnRefresh: TLabelB;
BtnHelp: TChangeImg;
LBtnHelp: TLabelB;
BtnFind: TChangeImg;
LBtnFind: TLabelB;
Label1: TLabel;
Edtbjbh: TEdit;
Label2: TLabel;
Edtbjmc: TEdit;
DBGrid1: TDBGrid;
StatusBar1: TStatusBar;
DataSource1: TDataSource;
ADOQry: TADOQuery;
GroupBox1: TGroupBox;
ADOStp: TADOStoredProc;
Label3: TLabel;
CBzybh: TComboBox;
Label4: TLabel;
Label5: TLabel;
CBxqbh: TComboBox;
CByxbh: TComboBox;
procedure BtnNewClick(Sender: TObject);
procedure BtnEditClick(Sender: TObject);
procedure BtnDeleteClick(Sender: TObject);
procedure BtnRefreshClick(Sender: TObject);
procedure BtnFindClick(Sender: TObject);
procedure BtnHelpClick(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure EdtbjbhKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure CBzybhKeyPress(Sender: TObject; var Key: Char);
procedure FormDestroy(Sender: TObject);
procedure CBxqbhExit(Sender: TObject);
procedure CByxbhExit(Sender: TObject);
procedure CBxqbhKeyPress(Sender: TObject; var Key: Char);
procedure CByxbhKeyPress(Sender: TObject; var Key: Char);
procedure CBzybhExit(Sender: TObject);
private
{ Private declarations }
procedure InitValue; //初始化窗体数据
procedure SetEditValue; //设置各显示框的数据值
function CheckValue: boolean; //检查各个输入框值的准确性
procedure ExecStore(optmode: integer); //执行存储过程
function ReturnSqlValue(Str: string; bz: string): string; //返回字段名称
public
{ Public declarations }
end;
var
ZClassInfo: TZClassInfo;
implementation
uses
DM_DataModal, Uglobal, UgeneralFunc;
{$R *.dfm}
procedure TZClassInfo.InitValue;
var
xqbh: string;
begin
Edtbjbh.Text := '';
Edtbjmc.Text := '';
cbyxbh.Text := '';
cbzybh.Text := '';
Cbxqbh.ItemIndex := 0;
cbxqbh.SetFocus;
statusbar1.Panels[2].Text := 'Insert';
xqbh := trim(ReturnSqlValue(cbxqbh.Text, 'xq'));
with AdoQry do
begin
sql.Clear;
sql.Add('select * from vZx_S_bjxx where xqbh=''' + xqbh + '''');
open;
end;
end;
procedure TZClassInfo.SetEditValue;
begin
if AdoQry.RecordCount > 0 then
begin
Cbxqbh.Text := AdoQry.fieldbyname('xqmc').Value;
Cbyxbh.Text := AdoQry.fieldbyname('yxmc').Value;
Cbzybh.Text := AdoQry.fieldbyname('zymc').Value;
Edtbjbh.Text := AdoQry.fieldbyname('bjbh').Value;
Edtbjmc.Text := AdoQry.fieldbyname('bjmc').Value;
end;
end;
function TZClassInfo.CheckValue: boolean;
begin
result := false;
if Cbxqbh.Text = '' then
begin
statusbar1.Panels[1].Text := '校区名称不可为空值,请选择!';
Cbxqbh.SetFocus;
Cbxqbh.SelectAll;
exit;
end;
if Cbyxbh.Text = '' then
begin
statusbar1.Panels[1].Text := '院系名称不可为空值,请选择!';
Cbyxbh.SetFocus;
Cbyxbh.SelectAll;
exit;
end;
if Cbzybh.Text = '' then
begin
statusbar1.Panels[1].Text := '专业名称不可为空值,请选择!';
Cbzybh.SetFocus;
Cbzybh.SelectAll;
exit;
end;
if Edtbjbh.Text = '' then
begin
statusbar1.Panels[1].Text := '班级编号不可为空值,请输入!';
Edtbjbh.SetFocus;
Edtbjbh.SelectAll;
exit;
end;
if Edtbjmc.Text = '' then
begin
statusbar1.Panels[1].Text := '班级名称不可为空值,请输入!';
Edtbjmc.SetFocus;
Edtbjmc.SelectAll;
exit;
end;
Result := true;
end;
procedure TZClassInfo.ExecStore(OptMode: integer);
begin
with AdoStp do
begin
parameters.ParamByName('@czdx').Value := 4;
parameters.ParamByName('@czfs').Value := OptMode;
parameters.ParamByName('@zybh').Value := ReturnSqlValue(Cbzybh.Text, 'zy');
parameters.ParamByName('@bjbh').Value := Edtbjbh.Text;
Parameters.ParamByName('@mc').Value := Edtbjmc.Text;
try
Execproc;
Statusbar1.Panels[1].Text := parameters.paramByName('@retmsg').Value;
InitValue;
except
Statusbar1.Panels[1].Text := '维护班级信息资料时出现意外!';
end;
end;
end;
procedure TZClassInfo.BtnNewClick(Sender: TObject);
begin
inherited;
if CheckValue then ExecStore(1);
end;
procedure TZClassInfo.BtnEditClick(Sender: TObject);
begin
inherited;
if CheckValue then ExecStore(3);
end;
procedure TZClassInfo.BtnDeleteClick(Sender: TObject);
var
msg: string;
begin
inherited;
msg := '请确认要删除该笔院系信息!';
if showmsg(msg, 0, 2) then
begin
ExecStore(2);
end
else
statusbar1.Panels[1].Text := '删除操作已取消!';
end;
procedure TZClassInfo.BtnRefreshClick(Sender: TObject);
begin
inherited;
InitValue;
statusbar1.Panels[1].Text := '';
end;
procedure TZClassInfo.BtnFindClick(Sender: TObject);
var
Sqlstr, xqbh, yxbh, Zybh: string;
iRec: integer;
begin
inherited;
irec := 0;
xqbh := ReturnSqlValue(Cbxqbh.Text, 'xq');
yxbh := ReturnSqlValue(Cbyxbh.Text, 'yx');
Zybh := ReturnSqlValue(Cbzybh.Text, 'zy');
Sqlstr := 'select * from vZx_S_bjxx';
if (length(trim(xqbh)) > 0) then
begin
if irec < 1 then
begin
SqlStr := Sqlstr + ' where (xqbh like ''' + trim(xqbh) + ''')';
inc(irec);
end
else begin
SqlStr := Sqlstr + ' and (xqbh like ''' + trim(xqbh) + ''')';
inc(irec);
end;
end;
if (length(trim(yxbh)) > 0) then
begin
if irec < 1 then
begin
SqlStr := Sqlstr + ' where (yxbh like ''' + trim(yxbh) + ''')';
inc(irec);
end
else begin
SqlStr := Sqlstr + ' and (yxbh like ''' + trim(yxbh) + ''')';
inc(irec);
end;
end;
if (length(trim(Zybh)) > 0) then
begin
if irec < 1 then
begin
SqlStr := Sqlstr + ' where (zybh like ''' + trim(Zybh) + ''')';
inc(irec);
end
else begin
SqlStr := Sqlstr + ' and (zybh like ''' + trim(Zybh) + ''')';
inc(irec);
end;
end;
if (length(trim(Edtbjbh.Text)) > 0) then
begin
if irec < 1 then
begin
SqlStr := Sqlstr + ' where (bjbh like ''' + trim(edtbjbh.text) + ''')';
inc(irec);
end
else begin
SqlStr := Sqlstr + ' and (bjbh like ''' + trim(edtbjbh.text) + ''')';
inc(irec);
end;
end;
if (length(trim(Edtbjmc.Text)) > 0) then
begin
if irec < 1 then
begin
SqlStr := Sqlstr + ' where (bjmc like ''' + trim(Edtbjmc.text) + ''')';
inc(irec);
end
else begin
SqlStr := Sqlstr + ' and (bjmc like ''' + trim(Edtbjmc.text) + ''')';
inc(irec);
end;
end;
if irec = 0 then
begin
statusbar1.Panels[1].Text := '请输入查询条件';
exit;
end;
with Adoqry do
begin
sql.Clear;
sql.Add(sqlstr);
open;
end;
if Adoqry.RecordCount > 0 then
begin
SetEditValue;
cbxqbh.SetFocus;
cbxqbh.SelectAll;
statusbar1.Panels[1].Text := '查找到' + inttostr(Adoqry.RecordCount) + '笔符合条件的记录!';
statusbar1.Panels[2].Text := 'Modify'
end
else begin
InitValue;
statusbar1.Panels[1].Text := '无符合条件的院系信息!';
end;
end;
procedure TZClassInfo.BtnHelpClick(Sender: TObject);
begin
inherited;
//帮助信息
HtmlHelp(Handle, gtSyscs.sHelpFileName, $0001, DWORD(PChar('Introduction.htm')));
end;
procedure TZClassInfo.DBGrid1CellClick(Column: TColumn);
begin
inherited;
SetEditValue;
statusbar1.Panels[2].Text := 'Modify';
end;
procedure TZClassInfo.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := Cafree;
end;
procedure TZClassInfo.EdtbjbhKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Sqlstr: string;
begin
inherited;
if key = 13 then
begin
if Edtbjbh.Text = '' then
begin
statusbar1.Panels[1].Text := '班级编号不可为空值,请输入!';
exit;
end;
SqlStr := 'select * from vZx_S_bjxx where bjbh like ''' + trim(edtbjbh.text) + '''';
with Adoqry do
begin
sql.Clear;
sql.Add(sqlstr);
open;
end;
if Adoqry.RecordCount > 0 then
begin
SetEditValue;
statusbar1.Panels[1].Text := '查找到' + inttostr(Adoqry.RecordCount) + '笔符合条件的记录!';
statusbar1.Panels[2].Text := 'Modify'
end;
Edtbjmc.SetFocus;
edtbjmc.SelectAll;
end;
end;
procedure TZClassInfo.FormShow(Sender: TObject);
var
Sqlstr: string;
begin
inherited;
Sqlstr := 'select * from zx_s_xqxx ';
SetComboxItems(WindData.AdoConn, CbXqbh, sqlstr, 'xqmc');
InitValue;
end;
procedure TZClassInfo.CBzybhKeyPress(Sender: TObject; var Key: Char);
begin
inherited;
key := #0;
end;
procedure TZClassInfo.FormDestroy(Sender: TObject);
begin
inherited;
ZClassInfo := nil;
end;
function TZClassInfo.ReturnSqlValue(Str: string; bz: string): string; //返回字段名称
var
Qry: TAdoQuery;
begin
Qry := TAdoQuery.Create(nil);
Qry.Connection := WindData.AdoConn;
with Qry do
begin
sql.Clear;
if bz = 'yx' then
sql.Add('select yxbh from zx_s_yxxx where yxmc like ''' + trim(str) + '''')
else if bz = 'xq' then
sql.Add('select xqbh from zx_s_xqxx where xqmc like ''' + trim(str) + '''')
else if bz = 'zy' then
sql.Add('select zybh from zx_s_zyxx where zymc like ''' + trim(str) + '''');
open;
end;
if Qry.RecordCount > 0 then
begin
if bz = 'yx' then
Result := Qry.fieldbyname('yxbh').AsString
else if bz = 'xq' then
Result := Qry.fieldbyname('xqbh').AsString
else if bz = 'zy' then
Result := Qry.fieldbyname('zybh').AsString
end
else
Result := '';
end;
procedure TZClassInfo.CBxqbhExit(Sender: TObject);
var
Sqlstr, xqbh: string;
begin
inherited;
xqbh := trim(ReturnSqlValue(cbxqbh.Text, 'xq'));
Sqlstr := 'select * from zx_s_yxxx where xqbh=''' + xqbh + '''';
SetComboxItems(WindData.AdoConn, Cbyxbh, sqlstr, 'yxmc');
with adoqry do
begin
sql.Clear;
sql.Add('select * from vzx_s_bjxx where xqbh=''' + xqbh + '''');
open;
end;
end;
procedure TZClassInfo.CByxbhExit(Sender: TObject);
var
Sqlstr, xqbh, yxbh: string;
begin
inherited;
xqbh := trim(ReturnSqlValue(cbxqbh.Text, 'xq'));
yxbh := trim(ReturnSqlValue(cbyxbh.Text, 'yx'));
Sqlstr := 'select * from zx_s_zyxx where yxbh=''' + yxbh + '''';
SetComboxItems(WindData.AdoConn, Cbzybh, sqlstr, 'zymc');
with adoqry do
begin
sql.Clear;
sql.Add('select * from vzx_s_bjxx where xqbh=''' + xqbh + ''' and yxbh=''' + yxbh + '''');
open;
end;
end;
procedure TZClassInfo.CBxqbhKeyPress(Sender: TObject; var Key: Char);
begin
inherited;
key := #0;
end;
procedure TZClassInfo.CByxbhKeyPress(Sender: TObject; var Key: Char);
begin
inherited;
key := #0;
end;
procedure TZClassInfo.CBzybhExit(Sender: TObject);
var
Sqlstr, xqbh, yxbh, zybh: string;
begin
inherited;
xqbh := trim(ReturnSqlValue(cbxqbh.Text, 'xq'));
yxbh := trim(ReturnSqlValue(cbyxbh.Text, 'yx'));
zybh := trim(ReturnSqlValue(cbzybh.Text, 'zy'));
with adoqry do
begin
sql.Clear;
sql.Add('select * from vzx_s_bjxx where xqbh=''' + xqbh + ''' and yxbh=''' + yxbh
+ ''' and zybh=''' + zybh + '''');
open;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -