Click on how to close out, just save that if there are data changes in the DBGrid, the question is why not also will be prompted to save the modified data, the code is as follows, please advice, thank you!
The unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids StdCtrls, DB, the ADODB library;
Type
TForm1=class (TForm)
Edit1: TEdit;
Edit2: TEdit;
For: TButton;
Button2: TButton;
Button3: TButton;
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
ADODataSet1: TADODataSet;
Label1: TLabel;
Label2: TLabel;
Procedure Button3Click (Sender: TObject);
Procedure Button1Click (Sender: TObject);
Procedure Edit1KeyPress (Sender: TObject; Var Key: Char);
Procedure Edit2KeyPress (Sender: TObject; Var Key1: Char);
Procedure Button2Click (Sender: TObject);
Procedure FormCloseQuery (Sender: TObject; Var CanClose: Boolean);
Private
{Private declarations}
Public
{Public declarations}
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
Procedure TForm1. Button3Click (Sender: TObject);
The begin
close;
end;
Procedure TForm1. Edit1KeyPress (Sender: TObject; Var Key: Char);
The begin
If (edit1. Text<> ") and (key=# 13) then edit2. SetFocus;
end;
Procedure TForm1. Edit2KeyPress (Sender: TObject; Var Key1: Char);
The begin
If (edit2. Text<> ") and (key1=# 13) then button1click (sender);
end;
Procedure TForm1. Button1Click (Sender: TObject);
The begin
ADOQuery1. Close;
ADOQuery1. SQL. The Clear;
ADOQuery1. SQL. The Add (' select TD001 don't alone, TD002 purchase order number, TD003 serial number, TD027 purchase requisition, TD004 article number, TD008 quantity, TD012 delivery, TD005 name FROM PURTD where TD001='" + form1. Edit1. Text +' ' 'and TD002=' "+ form1. Edit2. Text +" '");
ADOQuery1. Open;
ADOQuery1. ExecSQL;
ADOQuery1. FieldByName (' single don't ') ReadOnly:=true;
ADOQuery1. FieldByName (' purchase order number.) ReadOnly:=true;
ADOQuery1. FieldByName (' serial number.) ReadOnly:=true;
ADOQuery1. FieldByName (' product number) ReadOnly:=true;
ADOQuery1. FieldByName (' name ') ReadOnly:=true;
ADOQuery1. FieldByName (' number ') ReadOnly:=true;
ADOQuery1. FieldByName (' purchase requisition number.) ReadOnly:=true;
end;
Procedure TForm1. Button2Click (Sender: TObject);
The begin
ADOQuery1. Refresh;
end;
Procedure TForm1. FormCloseQuery (Sender: TObject; Var CanClose: Boolean);
The begin
If MessageDlg (' and save the file, not closed? ', mtWarning, [mbYes, mbNo], 0)=6 then
CanClose:=true
The else
CanClose:=false;
end;
end.
CodePudding user response:
ReadOnly does not change in the DataSet, should be in the DataSource. AutoEdit:=False and DBGrid. ReadOnlyCodePudding user response:
1, your code:ADOQuery1. Open;
ADOQuery1. ExecSQL;
ADOQuery1 already OPEN, do not need to again ExecSQL, SQL statement using the select, only need OPEN,
2, CloseQuery the code there is no tube is the data you have modified, you this is directly prompted "and save the file, not close?" , even if you don't have the data, is an empty form, he should be prompt,
3, the modified method: ADOQuery1. State in [dsInsert dsEdit]//the data set is new or edit State
If ADOQuery1. State in [dsInsert dsEdit] then
The begin
If MessageDlg (' and save the file, not closed? ', mtWarning, [mbYes, mbNo], 0)=6 then
CanClose:=true
The else
CanClose:=false;
end;
end;