操作数据库中的数据

    unit FFData;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables;

type
  TFFDatamodule = class(TDataModule)
    Session1: TSession;
    qeryMain: TQuery;
    qeryMainSpeciesNo: TFloatField;
    qeryMainCategory: TStringField;
    qeryMainCommon_Name: TStringField;
    qeryMainSpeciesName: TStringField;
    qeryMainLengthcm: TFloatField;
    qeryMainLength_In: TFloatField;
    qeryMainNotes: TMemoField;
    qeryMainGraphic: TGraphicField;
    dsrcMain: TDataSource;
    procedure DataModuleCreate(Sender: TObject);
  private
  public
    procedure GoFish(const ASpeciesNo: integer);
    procedure MovePage(const APageSize: integer);
    procedure SortBy(const AFieldname: string);
  end;

// Procs
  function FFDatamodule: TFFDatamodule;

implementation
{$R *.DFM}

uses
  IWServer, IWInit,
  ServerController;

// Since we are threaded we cannot use global variables to store form / datamodule references
// so we store them in WebApplication.Data and we could reference that each time, but by creating
// a function like this our other code looks "normal" almost as if its referencing a global.
// This function is not necessary but it makes the code in the main form which references this
// datamodule a lot neater.
// Without this function ever time we would reference this datamodule we would use:
//   TFFSession(WebApplication.Data).FFDatamodule.<method / component>
// By creating this procedure it becomes:
//   FFDatamodule.<method / component>
// Which is just like normal Delphi code.
function FFDatamodule: TFFDatamodule;
begin
  Result := TFFSession(RWebApplication.Data).FFDatamodule;
end;

procedure TFFDatamodule.DataModuleCreate(Sender: TObject);
begin
  qeryMain.Open;
end;

procedure TFFDatamodule.GoFish(const ASpeciesNo: integer);
begin
  qeryMain.Locate('Species No', ASpeciesNo, []);
end;

procedure TFFDatamodule.MovePage(const APageSize: integer);
begin
  qeryMain.MoveBy(APageSize);
end;

procedure TFFDatamodule.SortBy(const AFieldname: string);
var
  LSpeciesNo: integer;
begin
  LSpeciesNo := Trunc(qeryMainSpeciesNo.Value);
  qeryMain.Close; try
    qeryMain.SQL.Text := 'select * from biolife order by biolife."' + AFieldName + '"';
  finally qeryMain.Open; end;
  GoFish(LSpeciesNo);
end;

end.

unit Main;

interface

uses
  IWAppForm, Db, DBTables, Classes, Controls,
  IWExtCtrls, IWDBExtCtrls, IWDBStdCtrls, IWDBGrids, IWGrids,
  IWCompButton, IWCompEdit, IWCompLabel, IWControl, IWCompMemo;

type
  TformMain = class(TIWAppForm)
    IWDBImage1: TIWDBImage;
    dgrdFish: TIWDBGrid;
    IWLabel4: TIWLabel;
    IWDBMemo1: TIWDBMemo;
    IWLabel2: TIWLabel;
    IWDBEdit2: TIWDBEdit;
    IWLabel3: TIWLabel;
    IWDBEdit3: TIWDBEdit;
    IWDBEdit1: TIWDBEdit;
    IWLabel1: TIWLabel;
    IWButton1: TIWButton;
    IWButton2: TIWButton;
    IWDBNavigator1: TIWDBNavigator;
    procedure IWDBGrid1Columns0Click(ASender: TObject;
      const AValue: String);
    procedure IWDBGrid1Columns0TitleClick(Sender: TObject);
    procedure dgrdFishRenderCell(ACell: TIWGridCell; const ARow,
      AColumn: Integer);
    procedure IWButton2Click(Sender: TObject);
    procedure IWButton1Click(Sender: TObject);
  protected
  public
  end;

implementation
{$R *.dfm}

uses
  FFData,
  Graphics,
  ServerController, SysUtils;

procedure TformMain.IWDBGrid1Columns0Click(ASender: TObject; const AValue: String);
begin
  FFDatamodule.GoFish(StrToInt(AValue));
end;

procedure TformMain.IWDBGrid1Columns0TitleClick(Sender: TObject);
begin
  FFDatamodule.SortBy(TIWDBGridColumn(Sender).DataField);
end;

procedure TformMain.dgrdFishRenderCell(ACell: TIWGridCell; const ARow, AColumn: Integer);
begin
  // -1 is Footer Row
  if ARow = -1 then begin
    ACell.BGColor := clSilver;
    if AColumn = 0 then begin
      ACell.Font.Color := clRed;
      ACell.Text := IntToStr(dgrdFish.RecordCount) + ' fish found.';
    end;
  end else begin
    if dgrdFish.RowIsCurrent then begin
      ACell.BGColor := clYellow;
    end;
  end;
end;

procedure TformMain.IWButton2Click(Sender: TObject);
begin
  FFDatamodule.MovePage(-dgrdFish.RowLimit);
end;

procedure TformMain.IWButton1Click(Sender: TObject);
begin
  FFDatamodule.MovePage(dgrdFish.RowLimit);
end;

end.


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值