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.
操作数据库中的数据
最新推荐文章于 2025-07-21 09:01:34 发布
1920

被折叠的 条评论
为什么被折叠?



