修改完成比例

方法1:独立事件单独写法

procedure TForm3.N21Click(Sender: TObject);
var
 BiLi:string;
 SAdoq:TADOQuery;
begin
 SAdoq:=TADOQuery.Create(nil);
 SAdoq.Connection:=frmDataPool.ADOConnection1;
 try
  //或许比例数值
  if not InputQuery('输入比例', '请输入比例值', BiLi) then
  begin
    ShowMessage('请输入完成比例值');
    Exit;
  end;
  with SAdoq do
  begin
    Close;
    SQL.Text:='UPDATE 需要做的事 SET 已完成百分比 ='+BiLi.QuotedString+'WHERE 选中 = true';
    ExecSQL;
  end;
  //防止程序假死
  Application.ProcessMessages;
  //刷新纪录显示
  frmDataPool.qry需要做的事.Close;
  frmDataPool.qry需要做的事.Open;
 finally
  SAdoq.Free;
 end;
end;

 

方法2:类写法

unit UUpdateBiLi;

interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Data.DB, Data.Win.ADODB,
  Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Clipbrd, Vcl.Menus,
  Vcl.StdCtrls, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh,
  EhLibVCL, GridsEh, DBAxisGridsEh, DBGridEh,EhLibADO,DBGridEhImpExp;
type TUpdateBiLi=class
public
class procedure selectedupdatebili (var SAdq:TADOQuery);
end;

implementation

uses FDataPool;
class procedure TUpdateBiLi.selectedupdatebili(var SAdq: TADOQuery);
var
 BiLi,SBiao: string;
 SAdoq:TADOQuery;
begin
 SAdoq:=TADOQuery.Create(nil);
 SAdoq.Connection:=frmDataPool.ADOConnection1;
 SBiao:=copy(SAdq.name,4,length(SAdq.name)-3);
 try
  //或许比例数值
  if not InputQuery('输入比例', '请输入比例值', BiLi) then
  begin
    ShowMessage('请输入完成比例值');
    Exit;
  end;
  with SAdoq do
  begin
    Close;
    SQL.Text:='UPDATE '+SBiao+' SET 已完成百分比 ='+BiLi.QuotedString+'WHERE 选中 = true';
    ExecSQL;
  end;
  //防止程序假死
  Application.ProcessMessages;
  //刷新纪录显示
  SAdq.Requery();
 finally
  SAdoq.Free;
 end;
end;

end.

 

 

类引用,记住在use里面添加引用类单元的名字UUpdateBiLi

procedure TForm3.N21Click(Sender: TObject);
begin
//批量修改选中记录的完成比例
TUpdateBiLi.selectedupdatebili(frmDataPool.qry需要做的事);
end;

 

posted @ 2017-06-23 14:22  delphi学习交流吧  阅读(255)  评论(0编辑  收藏  举报