修改类别 (类实现)两种方法

unit UUpdateLeiBie;

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, Vcl.Buttons;

type TUpdateLeiBie=class
  public
  class procedure updateselectedleibie(var combox:TComboBox; SAdq:TADOQuery);
  class procedure updateselectedleibierequery(var SAdq:TADOQuery);
end;

implementation
/// <summary>
/// 通过打开窗口combobox下拉选择修改
/// </summary>

uses FDataPool, Uleibie;
class procedure TUpdateLeiBie.updateselectedleibie(var combox:TComboBox; SAdq:TADOQuery);
var
MyAdoq:TADOQuery;
LeiBie,SBiao: string;
begin
  MyAdoq := TADOQuery.Create(nil);
  SBiao:=copy(SAdq.name,4,length(SAdq.name)-3);
  try
    MyAdoq.Connection := frmDataPool.ADOConnection1;
    LeiBie:=combox.text;
    with MyAdoq do
    begin
      Close;
      SQL.Text := 'UPDATE '+SBiao+' SET 类别 ='+ LeiBie.QuotedString+'where 选中 = true';
      ExecSQL;
    end;
    //防止程序假死
    Application.ProcessMessages;

    //刷新纪录
  SAdq.Requery;

  finally
    MyAdoq.Free;
  end;

end;

/// <summary>
/// 通过requery窗口询问写法类实现
/// </summary>
class procedure TUpdateLeiBie.updateselectedleibierequery(var SAdq: TADOQuery);
var
 LeiBie,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('修改类别', '请输入类别', LeiBie) then
  begin
    ShowMessage('请输入类别');
    Exit;
  end;
  with SAdoq do
  begin
    Close;
    SQL.Text:='UPDATE '+SBiao+' SET 类别 ='+LeiBie.QuotedString+'WHERE 选中 = true';
    ExecSQL;
  end;
  //防止程序假死
  Application.ProcessMessages;
  //刷新纪录显示
  SAdq.Requery();
 finally
  SAdoq.Free;
 end;
end;
end.

 

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