还是要问问刷新的问题(50分)

  • 主题发起人 主题发起人 pst
  • 开始时间 开始时间
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.
谁帮我测试一下,还可以加分!
 
这样试一试
unit GPVOperatorU;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, Db, DBTables, ExtCtrls, DBCtrls, ComCtrls, DBCGrids,
StdCtrls, Mask, CheckLst,SendMessage,DBClient;

type
TFormOperator_1 = class(TForm)
DataSource1: TDataSource;
Label1: TLabel;
Label2: TLabel;
Button_Close: TButton;
LabelUserID: 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 DBEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBEdit3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
SendMessage : TSendMessage;
SubMenuIndex : TStringList;
MenuName : TStringList;
public
{ Public declarations }
end;

var
FormOperator_1: TFormOperator_1;

const
{Declare constants we're interested in}
eKeyViol = 9729;
eRequiredFieldMissing = 9732;

implementation

uses Fee_Main;

{$R *.DFM}

procedure TFormOperator_1.FormCreate(Sender: TObject);
begin
SendMessage := TSendMessage.Create ;
MenuName := TStringList.Create ;
SubMenuIndex := TStringList.Create ;

end;

procedure TFormOperator_1.FormActivate(Sender: TObject);
var
i : Integer;
begin
if Table_User.ChangeCount >0 then Table_User.ApplyUpdates(-1);
if Table_User.Active then Table_User.Close;
Table_User.Open;
end;

procedure TFormOperator_1.Button_CloseClick(Sender: TObject);
begin
Close;
end;


procedure TFormOperator_1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case KEY of
VK_ESCAPE : Button_CloseClick(Sender);
end;
end;

procedure TFormOperator_1.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;


procedure TFormOperator_1.Button_AddClick(Sender: TObject);
begin
if Table_User.ChangeCount >0 then Table_User.ApplyUpdates(-1);
Table_User.Append ;
DBEdit1.SetFocus ;
end;

procedure TFormOperator_1.Button_DeleteClick(Sender: TObject);
begin
if Table_User.RecordCount > 0 then
if Table_User.FieldValues['UserID'] = '00' then
begin
MessageDlg('超级用户不能删除!', mtConfirmation, [mbOK], 0);
Exit;
end;

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_1.Button_ModifyClick(Sender: TObject);
begin
try
Table_User.ApplyUpdates(-1);
except
end;
end;

procedure TFormOperator_1.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_1.Button_AddKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
DBEdit1.SetFocus ;
end;
end;

procedure TFormOperator_1.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(0);
except
end;
end;
end;
end;

procedure TFormOperator_1.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;

procedure TFormOperator_1.DBEdit3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN :
begin
try
Table_User.ApplyUpdates(0);
except
end;
end;
end;
end;

end.
 
接受答案了.
 

Similar threads

I
回复
0
查看
566
import
I
I
回复
0
查看
709
import
I
I
回复
0
查看
462
import
I
I
回复
0
查看
601
import
I
后退
顶部