📄 loseform.~pas
字号:
unit LoseForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, StdCtrls, Buttons, Grids, DBGrids, ExtCtrls;
type
TfrmLose = class(TForm)
Panel1: TPanel;
DBGrid1: TDBGrid;
bbnAntiLose: TBitBtn;
bbnLose: TBitBtn;
DataSource1: TDataSource;
BitBtn4: TBitBtn;
GroupBox1: TGroupBox;
lblPrompt: TLabel;
edtId: TEdit;
rbnByStudentID: TRadioButton;
rbnByCardId: TRadioButton;
procedure rbnByStudentIDClick(Sender: TObject);
procedure rbnByCardIdClick(Sender: TObject);
procedure edtIdKeyPress(Sender: TObject; var Key: Char);
procedure bbnAntiLoseClick(Sender: TObject);
procedure bbnLoseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
private
{ Private declarations }
procedure ConfigButtons();
public
{ Public declarations }
end;
var
frmLose: TfrmLose;
implementation
uses
CardDM;
{$R *.DFM}
procedure TfrmLose.rbnByStudentIDClick(Sender: TObject);
begin
if rbnByStudentId.Checked then
begin
lblPrompt.Caption := '学号:';
edtId.SetFocus;
end;
end;
procedure TfrmLose.rbnByCardIdClick(Sender: TObject);
begin
if rbnByCardId.Checked then
begin
lblPrompt.Caption := '卡号:';
edtId.SetFocus;
end;
end;
procedure TfrmLose.edtIdKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
with DMMain.tblCard do
begin
if rbnByStudentId.Checked then
begin
Filter := 'user_id = ' + '''' + edtId.Text + '''';
Filtered := True;
//没有找到相应的学号
if RecordCount < 1 then
begin
ShowMessage('学号为'+edtId.Text+ '的学生不存在!');
end;
ConfigButtons();
end
else if rbnByCardId.Checked then
begin
Filter := 'card_id = ' + '''' + edtId.Text + '''';
Filtered := True;
//没有找到相应的卡号
if RecordCount < 1 then
begin
ShowMessage('卡号为'+edtId.Text+ '的银卡不存在!');
end;
ConfigButtons();
end
else begin
ShowMessage('请选择查询的方式!');
rbnByStudentId.SetFocus;
end;
end;
end;
end;
procedure TfrmLose.ConfigButtons;
var
mLose : string;
begin
with DMMain.tblCard do
begin
if RecordCount < 1 then
begin
//禁止挂失和解挂按钮
bbnAntiLose.Enabled := False;
bbnLose.Enabled := False;
Exit;
end;
//读取卡的状态
mLose := FieldByName('state').AsString;
//卡处于未挂失状态
if mLose = '0' then
begin
bbnAntiLose.Enabled := False;
bbnLose.Enabled := True;
end
//卡处于挂失状态
else if mLose = '1' then
begin
bbnAntiLose.Enabled := True;
bbnLose.Enabled := False;
end
else begin
bbnAntiLose.Enabled := True;
bbnLose.Enabled := True;
end;
end;
end;
procedure TfrmLose.bbnAntiLoseClick(Sender: TObject);
var
mStudentId,mCardId,mStr:string;
begin
if DMMain.tblCard.RecordCount < 1 then Exit;
mStudentId := DMMain.tblCard.FieldByName('user_id').AsString;
mCardId := DMMain.tblCard.FieldByName('card_id').AsString;
if rbnByStudentId.Checked then
mStr := '要将学号为' + mStudentId + '的卡解挂吗?'
else
mStr := '要将卡号为' + mCardId + '的卡解挂吗?';
//用户取消本次操作
if MessageDlg(mStr,mtConfirmation,mbOKCancel,0) = mrCancel then
Exit;
with DMMain.tblCard do
begin
Edit;
//设置卡为非挂失状态
FieldByName('state').AsString := '0';
Post;
end;
//重新更新用户界面
ConfigButtons;
if rbnByStudentId.Checked then
mStr := '学号为' + mStudentId + '的卡解挂成功!'
else
mStr := '卡号为' + mCardId + '的卡解挂成功!';
ShowMessage(mStr);
end;
procedure TfrmLose.bbnLoseClick(Sender: TObject);
var
mStudentId,mCardId,mStr:string;
begin
if DMMain.tblCard.RecordCount < 1 then Exit;
mStudentId := DMMain.tblCard.FieldByName('user_id').AsString;
mCardId := DMMain.tblCard.FieldByName('card_id').AsString;
if rbnByStudentId.Checked then
mStr := '要将学号为' + mStudentId + '的卡挂失吗?'
else
mStr := '要将卡号为' + mCardId + '的卡挂失吗?';
//用户取消本次操作
if MessageDlg(mStr,mtConfirmation,mbOKCancel,0) = mrCancel then
Exit;
with DMMain.tblCard do
begin
Edit;
//设置卡为挂失状态
FieldByName('state').AsString := '1';
Post;
end;
//重新更新用户界面
ConfigButtons;
if rbnByStudentId.Checked then
mStr := '学号为' + mStudentId + '的卡挂失成功!'
else
mStr := '卡号为' + mCardId + '的卡挂失成功!';
ShowMessage(mStr);
end;
procedure TfrmLose.FormShow(Sender: TObject);
begin
ConfigButtons();
end;
procedure TfrmLose.DBGrid1CellClick(Column: TColumn);
begin
ConfigButtons();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -