📄 u_user.pas
字号:
unit U_User;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, Buttons, Mask, DBCtrls,
ActnList, XPStyleActnCtrls, ActnMan, ComCtrls,strutils;
type
TFrm_User = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Image1: TImage;
Edt_cfkl: TEdit;
btn_ok: TSpeedButton;
SpeedButton4: TSpeedButton;
ActionManager1: TActionManager;
Action1: TAction;
Action4: TAction;
Edt_kl: TEdit;
Edt_xm: TEdit;
GroupBox2: TGroupBox;
Rd1: TRadioButton;
Rd2: TRadioButton;
Rd3: TRadioButton;
Lvw_lb: TListView;
Action5: TAction;
Edt_bh: TEdit;
Action2: TAction;
procedure Action4Execute(Sender: TObject);
procedure Action5Execute(Sender: TObject);
procedure Action1Execute(Sender: TObject);
procedure Lvw_lbSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure Action2Execute(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Frm_User: TFrm_User;
implementation
uses U_Data,u_data_update;
{$R *.dfm}
procedure TFrm_User.Action4Execute(Sender: TObject);
begin
close;
end;
procedure TFrm_User.Action5Execute(Sender: TObject);
var
A1,A2,A3:string;
begin
data.G_con.Open();
data.G_Rst_use.SQL.Clear;
data.G_Rst_use.SQL.Add('select * from user1');
data.G_Rst_use.ExecSQL;
data.G_Rst_use.Open;
self.Lvw_lb.Items.Clear;
while not data.G_rst_use.Eof do
begin
a1:=data.G_Rst_use.FieldValues['name_id'];
a2:=data.G_Rst_use.FieldValues['name'];
a3:=data.G_Rst_use.FieldValues['name_password'];
data.G_Rst_use.Next;
with lvw_lb.Items.Add do
begin
caption:=a1;
subitems.Add(a2);
end;
end;
data.G_Rst_use.Close;
data.G_Rst_use.Close;
end;
procedure TFrm_User.Action1Execute(Sender: TObject);
begin
if rd1.Checked then
begin
edt_bh.Enabled:=true;
edt_bh.Text:='';
edt_xm.Text:='';
edt_kl.Text:='';
edt_cfkl.Text:='';
btn_ok.Caption:='保存';
end
else if rd2.Checked then
begin
edt_bh.Enabled:=false;
btn_ok.Caption:='保存';
end
else if rd3.Checked then
begin
edt_bh.Enabled:=false;
btn_ok.Caption:='删除';
end;
//
end;
procedure TFrm_User.Lvw_lbSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
if selected then
begin
edt_bh.Text :=lvw_lb.Selected.Caption;
edt_xm.Text:=lvw_lb.Selected.SubItems[0];
btn_ok.Caption :='保存';
end;
end;
procedure TFrm_User.Action2Execute(Sender: TObject);
var
P_Str_lj:string;
begin
if trim(edt_bh.Text)='' then
begin
application.MessageBox('编号不能为空!','明日科技');
exit;
end;
if trim(edt_xm.Text)='' then
begin
application.MessageBox('姓名不能为空!','明日科技');
exit;
end;
if rd1.Checked then
begin
if trim(edt_kl.Text)='' then
begin
application.MessageBox('口令不能为空!','明日科技');
exit;
end;
if trim(edt_kl.Text)<>trim(edt_cfkl.Text) then
begin
application.MessageBox('口令不一致','明日科技');
exit;
end;
P_Str_lj := 'select * from user1 where name_id=' +quotedstr(trim(edt_bh.Text));
data.G_con.Open();
data.G_Rst_use.SQL.Clear;
data.G_Rst_use.SQL.Add(p_str_lj);
data.G_Rst_use.ExecSQL;
data.G_Rst_use.Open;
if not data.G_Rst_use.Eof then
begin
application.MessageBox('用户编号不能相同,请重新输入','明日科技');
data.G_Rst_use.Close;
// data.G_con.Close;
exit;
end;
data.G_Rst_use.Close;
// data.G_con.Close;
P_Str_lj :='insert into user1(name_id,name,name_password) values(';
p_str_lj:=p_str_lj+quotedstr(edt_bh.Text)+',';
p_str_lj:=p_str_lj+quotedstr(edt_xm.Text)+',';
p_str_lj:=p_str_lj+quotedstr(edt_kl.Text)+')';
data.G_con.Open();
data.G_Rst_use.SQL.Clear;
data.G_Rst_use.SQL.Add(p_str_lj);
data.G_Rst_use.ExecSQL;
// data.G_con.Close;
Action5Execute(Sender);
end
else if rd2.Checked then
begin
if trim(edt_kl.Text)='' then
begin
application.MessageBox('口令不能为空!','明日科技');
exit;
end;
P_Str_lj := 'select * from user1 where name_password=' +quotedstr(trim(edt_kl.Text))+' and name_id='+quotedstr(trim(edt_bh.text));
data.G_con.Open();
data.G_Rst_use.SQL.Clear;
data.G_Rst_use.SQL.Add(p_str_lj);
data.G_Rst_use.ExecSQL;
data.G_Rst_use.Open;
if data.G_Rst_use.Eof then
begin
application.MessageBox('原口令错误,请重新输入','明日科技');
data.G_Rst_use.Close;
data.G_con.Close;
exit;
end;
data.G_Rst_use.Close;
// data.G_con.Close;
P_Str_lj := 'update user1 set name=';
P_Str_lj := P_Str_lj + quotedstr(edt_xm.Text) + ',name_password=';
P_Str_lj := P_Str_lj + quotedstr(edt_cfkl.Text) + ' where name_id=';
P_Str_lj := P_Str_lj + quotedstr(edt_bh.Text);
data.G_con.Open();
data.G_Rst_use.SQL.Clear;
data.G_Rst_use.SQL.Add(p_str_lj);
data.G_Rst_use.ExecSQL;
// data.G_con.Close;
Action5Execute(Sender);
end
else if rd3.Checked then
begin
P_Str_lj :='delete user1 where name_id='+quotedstr(edt_bh.Text);
data.G_con.Open();
data.G_Rst_use.SQL.Clear;
data.G_Rst_use.SQL.Add(p_str_lj);
data.G_Rst_use.ExecSQL;
//data.G_con.Close;
Action5Execute(Sender);
end;
application.MessageBox('数据更新成功','明日科技');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -