P
pst
Unregistered / Unconfirmed
GUEST, unregistred user!
虽然这个话题已经讨论了N次了,但我还是有问题。
在三层中,APPSERVER使用一个ADOTABLE,而客户端的CDS无论是CLOSE;OPEN都无法
看到自己刚才输入的信息。
程序如下:
unit Oper_User;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, Db, DBTables, ExtCtrls, DBCtrls, ComCtrls, DBCGrids,
StdCtrls, Mask, CheckLst, DBClient;
type
TFormOperator = class(TForm)
DataSource1: TDataSource;
Label1: TLabel;
Label2: TLabel;
DBGrid1: TDBGrid;
Button_Add: TButton;
Button_Delete: TButton;
Label3: TLabel;
Label4: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Table_user: TClientDataSet;
QuerySetUserRight: TClientDataSet;
QueryGetUserRight: TClientDataSet;
Button_Modify: TButton;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button_CloseClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button_AddClick(Sender: TObject);
procedure Button_DeleteClick(Sender: TObject);
procedure Button_ModifyClick(Sender: TObject);
procedure Table_UserPostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
procedure Button_AddKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBEdit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBEdit1Change(Sender: TObject);
procedure DBEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormOperator: TFormOperator;
const
{Declare constants we're interested in}
eKeyViol = 9729;
eRequiredFieldMissing = 9732;
implementation
{$R *.DFM}
procedure TFormOperator.FormCreate(Sender: TObject);
begin
end;
procedure TFormOperator.FormActivate(Sender: TObject);
var
i : Integer;
begin
Table_user.Close;
Table_User.Open;
end;
procedure TFormOperator.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case KEY of
VK_ESCAPE : Button_CloseClick(Sender);
end;
end;
procedure TFormOperator.DBGrid1CellClick(Column: TColumn);
begin
LabelUserID.Caption := Table_User.FieldByName('UserID').AsString;
if QueryGetUserRight.Active then QueryGetUserRight.Close;
QueryGetUserRight.Params.ParamByName('UserID').AsString := Table_User.FieldByName('UserID').AsString;
QueryGetUserRight.Open;
MenuName.Clear ;
while not QueryGetUserRight.Eof do
begin
MenuName.Add(Trim(QueryGetUserRight.FieldByName('MenuName').AsString));
QueryGetUserRight.Next;
end;
end;
//增加数据,当时可以见到数据已经在DBGRID中,但是如果退出该子系统,则又看不到了
//而我在FormActive事件中也进行了Close;Open啊!
procedure TFormOperator.Button_AddClick(Sender: TObject);
begin
Table_User.Append ;
DBEdit1.SetFocus ;
end;
//删除数据,删除后,在DBGRID中还是可以见到原来的数据!
procedure TFormOperator.Button_DeleteClick(Sender: TObject);
begin
if Table_User.RecordCount > 0 then
if MessageDlg('是否删除光标所在行记录?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
with QuerySetUserRight do
begin
if Active then Close;
CommandText := 'delete t_users where userid='''+ Table_User.FieldValues['UserID']+'''';
Execute;
Close;
end;
Table_User.Close;
Table_User.Open;
end;
end;
procedure TFormOperator.Button_ModifyClick(Sender: TObject);
begin
try
Table_User.ApplyUpdates(0);
Button_OK.Enabled := True;
except
end;
end;
procedure TFormOperator.Table_UserPostError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
var
iDBIError: Integer;
begin
if (E is EDBEngineError) then
begin
iDBIError := (E as EDBEngineError).Errors[0].Errorcode;
case iDBIError of
eRequiredFieldMissing:
begin
MessageDlg('操作员号和操作员姓名不能为空!', mtWarning, [mbOK], 0);
Abort;
end;
eKeyViol:
begin
MessageDlg('操作员号重复!请重输入.', mtWarning, [mbOK], 0);
Abort;
end;
end;
end;
end;
procedure TFormOperator.Button_AddKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
DBEdit1.SetFocus ;
end;
end;
procedure TFormOperator.DBEdit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
begin
if DBEdit1.Text ='' then DBEdit1.SetFocus
else
try
Table_User.ApplyUpdates(-1);
except
end;
end;
end;
end;
procedure TFormOperator.DBEdit1Change(Sender: TObject);
begin
Button_OK.Enabled := True;
end;
procedure TFormOperator.DBEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
begin
if DBEdit1.Text ='' then DBEdit1.SetFocus
else DBEdit2.SetFocus;
end;
end;
end;
end.
谁帮我测试一下,还可以加分!
在三层中,APPSERVER使用一个ADOTABLE,而客户端的CDS无论是CLOSE;OPEN都无法
看到自己刚才输入的信息。
程序如下:
unit Oper_User;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, Db, DBTables, ExtCtrls, DBCtrls, ComCtrls, DBCGrids,
StdCtrls, Mask, CheckLst, DBClient;
type
TFormOperator = class(TForm)
DataSource1: TDataSource;
Label1: TLabel;
Label2: TLabel;
DBGrid1: TDBGrid;
Button_Add: TButton;
Button_Delete: TButton;
Label3: TLabel;
Label4: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Table_user: TClientDataSet;
QuerySetUserRight: TClientDataSet;
QueryGetUserRight: TClientDataSet;
Button_Modify: TButton;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button_CloseClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button_AddClick(Sender: TObject);
procedure Button_DeleteClick(Sender: TObject);
procedure Button_ModifyClick(Sender: TObject);
procedure Table_UserPostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
procedure Button_AddKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBEdit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBEdit1Change(Sender: TObject);
procedure DBEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormOperator: TFormOperator;
const
{Declare constants we're interested in}
eKeyViol = 9729;
eRequiredFieldMissing = 9732;
implementation
{$R *.DFM}
procedure TFormOperator.FormCreate(Sender: TObject);
begin
end;
procedure TFormOperator.FormActivate(Sender: TObject);
var
i : Integer;
begin
Table_user.Close;
Table_User.Open;
end;
procedure TFormOperator.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case KEY of
VK_ESCAPE : Button_CloseClick(Sender);
end;
end;
procedure TFormOperator.DBGrid1CellClick(Column: TColumn);
begin
LabelUserID.Caption := Table_User.FieldByName('UserID').AsString;
if QueryGetUserRight.Active then QueryGetUserRight.Close;
QueryGetUserRight.Params.ParamByName('UserID').AsString := Table_User.FieldByName('UserID').AsString;
QueryGetUserRight.Open;
MenuName.Clear ;
while not QueryGetUserRight.Eof do
begin
MenuName.Add(Trim(QueryGetUserRight.FieldByName('MenuName').AsString));
QueryGetUserRight.Next;
end;
end;
//增加数据,当时可以见到数据已经在DBGRID中,但是如果退出该子系统,则又看不到了
//而我在FormActive事件中也进行了Close;Open啊!
procedure TFormOperator.Button_AddClick(Sender: TObject);
begin
Table_User.Append ;
DBEdit1.SetFocus ;
end;
//删除数据,删除后,在DBGRID中还是可以见到原来的数据!
procedure TFormOperator.Button_DeleteClick(Sender: TObject);
begin
if Table_User.RecordCount > 0 then
if MessageDlg('是否删除光标所在行记录?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
with QuerySetUserRight do
begin
if Active then Close;
CommandText := 'delete t_users where userid='''+ Table_User.FieldValues['UserID']+'''';
Execute;
Close;
end;
Table_User.Close;
Table_User.Open;
end;
end;
procedure TFormOperator.Button_ModifyClick(Sender: TObject);
begin
try
Table_User.ApplyUpdates(0);
Button_OK.Enabled := True;
except
end;
end;
procedure TFormOperator.Table_UserPostError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
var
iDBIError: Integer;
begin
if (E is EDBEngineError) then
begin
iDBIError := (E as EDBEngineError).Errors[0].Errorcode;
case iDBIError of
eRequiredFieldMissing:
begin
MessageDlg('操作员号和操作员姓名不能为空!', mtWarning, [mbOK], 0);
Abort;
end;
eKeyViol:
begin
MessageDlg('操作员号重复!请重输入.', mtWarning, [mbOK], 0);
Abort;
end;
end;
end;
end;
procedure TFormOperator.Button_AddKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
DBEdit1.SetFocus ;
end;
end;
procedure TFormOperator.DBEdit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
begin
if DBEdit1.Text ='' then DBEdit1.SetFocus
else
try
Table_User.ApplyUpdates(-1);
except
end;
end;
end;
end;
procedure TFormOperator.DBEdit1Change(Sender: TObject);
begin
Button_OK.Enabled := True;
end;
procedure TFormOperator.DBEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
begin
if DBEdit1.Text ='' then DBEdit1.SetFocus
else DBEdit2.SetFocus;
end;
end;
end;
end.
谁帮我测试一下,还可以加分!