您的当前位置:首页正文

dbgrid批量保存

2023-05-21 来源:榕意旅游网


unit uzcdbadd;

interface

uses

Windows, Messages, SysUtils, Controls, Forms, Dialogs, Menus, DBGridEh, ComCtrls, ExtCtrls;

type

TfrmzcdbAdd = class(TForm)

lbl1: TLabel;

pnl1: TPanel;

lbl2: TLabel;

dtp1: TDateTimePicker;

dbgrdh1: TDBGridEh;

btnOK: TBitBtn;

Variants, StdCtrls, Classes, Buttons, Graphics, GridsEh, DB,

btnclose: TBitBtn;

ds1: TDataSource;

pm1: TPopupMenu;

mniadd: TMenuItem;

mniN1: TMenuItem;

procedure btncloseClick(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure btnOKClick(Sender: TObject);

procedure dbgrdh1EditButtonClick(Sender: TObject);

procedure dbgrdh1KeyPress(Sender: TObject; var Key: procedure mniaddClick(Sender: TObject);

procedure mniN1Click(Sender: TObject);

procedure FormClose(Sender: TObject; var TCloseAction);

Char);

Action:

private

{ Private declarations }

public

{ Public declarations }

end;

var

frmzcdbAdd: TfrmzcdbAdd;

Edittag:Integer;

implementation

uses datamoule, uselectzc, frmMain;

{$R *.dfm}

procedure TfrmzcdbAdd.btncloseClick(Sender: 滚

begin

TObject); //关闭时事务回

dm.qryzcdbadd.Close;

DM.congdzc.RollbackTrans;

close;

end;

procedure TfrmzcdbAdd.FormCreate(Sender: TObject); //窗口生成时

begin

if DM.qryzcdbadd .Active then dm.qryzcdbadd.Close;

if DM.congdzc.InTransaction then dm.congdzc.RollbackTrans;

dm.qryzcdbadd.LockType := ltBatchOptimistic;{批量乐观锁定}

DM.congdzc.BeginTrans; {开启事务}

case Edittag of

0:

begin

dm.qryzcdbadd.Open;

dm.qryzcdbadd.Append;

dm.qryzcdbadd.FieldByName( '调拨日期 ').AsDateTime :=Now;

dm.qryzcdbadd.FieldByName( '登记人员 GuserName;

end;

1:

begin

dm.qryzcdbadd.SQL.Clear;

dm.qryzcdbadd.SQL.Add( 'select * from ID= '+inttostr(dm.qryzcdb.fieldbyname( 'ID ').asinteger));

DM.qryzcdbadd.open;

DM.qryzcdbadd.First;

DM.qryzcdbadd.Edit;

[调拨] := where ').AsString

end;

end;

end;

procedure TfrmzcdbAdd.btnOKClick(Sender: TObject); //单击保存

begin

dm.qryzcdbadd.UpdateBatch(); {批量保存}

dm.congdzc.CommitTrans; {提交事务}

close;

end;

procedure TfrmzcdbAdd.dbgrdh1EditButtonClick(Sender: TObject);

begin

if dbgrdh1.Col=1 then

begin

frmSelectzc:= TfrmSelectzc.Create(nil);

frmSelectzc.Tag:=2;

frmSelectzc.Show;

end;

end;

procedure TfrmzcdbAdd.dbgrdh1KeyPress(Sender: TObject; Char);

begin

if key=#13 then{ 判断是按执行键}

if dbgrdh1.Col+1 <(dbgrdh1.Columns.Count) then

dbgrdh1.Col:=dbgrdh1.col+1{ 移动到下一字段}

else

dbgrdh1.Col:=1;

end;

var Key:

procedure TfrmzcdbAdd.mniaddClick(Sender: TObject); //添加按钮

begin

DM.qryzcdbadd.Append;

dm.qryzcdbadd.FieldByName( '调拨日期 ').AsDateTime :=Now;

dm.qryzcdbadd.FieldByName( '登记人员 ').AsString := GuserName;

end;

procedure TfrmzcdbAdd.mniN1Click(Sender: TObject); //删除

begin

DM.qryzcdbadd.Delete;

end;

procedure TfrmzcdbAdd.FormClose(Sender: TObject; var Action: TCloseAction);

begin

DM.qryzcdb.Refresh;

Release;

end;

end.

因篇幅问题不能全部显示,请点此查看更多更全内容