📄 unit13.pas
字号:
unit Unit13;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, ADODB, Mask, DBCtrls,
ComCtrls;
type
TForm13 = class(TForm)
GroupBox1: TGroupBox;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ListView1: TListView;
Button1: TButton;
GroupBox2: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
GroupBox3: TGroupBox;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure ListView1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form13: TForm13;
implementation
{$R *.dfm}
procedure TForm13.RadioButton1Click(Sender: TObject);
begin
Edit1.Text := '';
Edit2.Text := '';
Edit3.Text := '';
Edit4.Text := '';
end;
procedure TForm13.Button1Click(Sender: TObject);
begin
try
with ADOQuery1 do
begin
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from Table6 order by spnum');
ADOQuery1.Open;
ListView1.Items.Clear;
while not Eof do
begin
with ListView1.Items.Add do
begin
Caption:=FieldByName('spnum').AsString;
SubItems.Add(FieldByName('spname').AsString);
SubItems.Add(FieldByName('kindnum').AsString);
SubItems.Add(FieldByName('price').AsString);
end;
Next;
end; Close;
end;
except
ListView1.Items.Clear;
MessageDlg('刷新出错',mtError,[mbok],0);
end; end;
procedure TForm13.ListView1Click(Sender: TObject);
var
i : integer;
begin
for i :=0 to ListView1.Items.Count-1 do
if ListView1.Items[ i ].Selected then
begin
RadioButton3.Checked:=True;
Edit1.Text:=ListView1.Items[i].Caption;
Edit2.Text:=ListView1.Items[i].SubItems.Strings[0];
Edit3.Text:=ListView1.Items[i].SubItems.Strings[1];
Edit4.Text:=ListView1.Items[i].SubItems.Strings[2];
end;
end;
procedure TForm13.Button2Click(Sender: TObject);
begin
if RadioButton1.Checked then
begin
if Length(Edit1.Text)<> 3 then
begin
MessageDlg('商品号不正确',mtError,[mbok],0);
Exit;
end;
with ADOQuery1 do
begin
ADOQuery1.SQL.Clear;
ADOQuery1.SQl.Add('select spnum from Table6 where spnum=:spnum');
Parameters.ParamByName('spnum').Value :=Edit1.Text;
Open;
if RecordCount <> 0 then
begin
MessageDlg('商品号<'+Edit1.Text+'>已经存在',mtError,[mbok],0);
Exit;
end;
Close;
end;
try
with ADOQuery1 do
begin
ADOQuery1.SQL.Clear;
SQl.Add('insert into Table6(spnum,spname,kindnum,price) values(:spnum,:spname,:kindnum,:price)');
Parameters.ParamByName('spnum').Value :=Edit1.Text;
Parameters.ParamByName('spname').Value :=Edit2.Text;
Parameters.ParamByName('kindnum').Value := Edit3.Text;
Parameters.ParamByName('price').Value :=Edit4.Text;
ADOQuery1.ExecSQL;
end;
except
MessageDlg('添加<'+Edit1.Text+'>失败',mtError,[mbok],0);
Exit;
end;
end;
if RadioButton2.Checked then
begin
try
with ADOQuery1 do
begin
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('delete from Table6 where spnum='''+edit1.text+'''');
ADOQuery1.ExecSQL;
end;
except
MessageDlg('删除<'+Edit1.Text+'>失败',mtError,[mbok],0);
Exit;
end;
end;
if RadioButton3.Checked then
begin
if Length(Edit1.Text)<> 10 then
begin
MessageDlg('商品号不正确',mtError,[mbok],0);
Exit;
end;
try
with ADOQuery1 do
begin
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('update Table6 set spname=:spname,kindnum=:kindnum,price=:price where spnum= :spnum');
Parameters.ParamByName('spnum').Value :=Edit1.Text;
Parameters.ParamByName('spname').Value :=Edit2.Text;
Parameters.ParamByName('kindnum').Value :=Edit3.Text;
Parameters.ParamByName('price').Value :=Edit4.Text;
ADOQuery1.ExecSQL;
end;
except
MessageDlg('修改<'+Edit1.Text+'>失败',mtError,[mbok],0);
Exit;
end;
end;
Edit1.Text := '';
Edit2.Text := '';
Edit3.Text := '';
Edit3.Text := '';
end;
procedure TForm13.Button3Click(Sender: TObject);
begin
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -