📄 querybook.pas
字号:
unit QueryBook;
{PUBDIST}
interface
uses
IWAppForm, IWApplication, IWTypes, Classes, Controls, IWControl, IWGrids,
IWDBGrids, IWCompEdit, IWCompLabel, IWCompButton, IWDBStdCtrls,
IWHTMLControls, DB, IWExtCtrls, DBXpress, FMTBcd, SqlExpr, IWCompMemo,
IWCompListbox, SysUtils, Graphics, Jpeg, Variants;
type
TfrmQueryBook = class(TIWAppForm)
IWDBGrid1: TIWDBGrid;
IWLabel1: TIWLabel;
edQBook: TIWEdit;
IWLabel2: TIWLabel;
edQAuthor: TIWEdit;
IWLabel3: TIWLabel;
edQPrice: TIWEdit;
btnQuery: TIWButton;
IWHRule1: TIWHRule;
IWDBNavigator1: TIWDBNavigator;
IWLabel4: TIWLabel;
IWLabel5: TIWLabel;
IWLabel6: TIWLabel;
IWLabel7: TIWLabel;
IWLabel8: TIWLabel;
IWImage1: TIWImage;
dsBook: TDataSource;
IWDBLabel1: TIWDBLabel;
IWDBLabel2: TIWDBLabel;
IWDBLabel3: TIWDBLabel;
IWDBLabel4: TIWDBLabel;
lbAuthor: TIWLabel;
IWDBMemo1: TIWDBMemo;
IWDBMemo2: TIWDBMemo;
cbCompPrice: TIWComboBox;
cbOrderField: TIWComboBox;
IWLabel9: TIWLabel;
cbOrderStyle: TIWComboBox;
IWLabel10: TIWLabel;
lbRecCount: TIWLabel;
btnAddToCarter: TIWButton;
btnCheckCarter: TIWButton;
procedure IWAppFormCreate(Sender: TObject);
procedure dsBookDataChange(Sender: TObject; Field: TField);
procedure btnQueryClick(Sender: TObject);
procedure IWDBGrid1Columns0Click(ASender: TObject;
const AValue: String);
procedure IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
procedure btnAddToCarterClick(Sender: TObject);
procedure btnCheckCarterClick(Sender: TObject);
public
end;
implementation
{$R *.dfm}
uses
ServerController, DatamoduleUnit, DIMime, Carter;
procedure TfrmQueryBook.IWAppFormCreate(Sender: TObject);
begin
dsBook.DataSet := DataModule1.cdsBook;
end;
procedure TfrmQueryBook.dsBookDataChange(Sender: TObject; Field: TField);
var
jImage:TJpegImage;
ss: TStringStream;
bSize : Integer;
begin
with DataModule1.cdsBook do
begin
if RecNo>0 then
begin
lbAuthor.Caption := FieldByName('Author1').AsString+', '+
FieldByName('Author2').AsString+', '+
FieldByName('Author3').AsString;
end;
end;
bSize :=TBlobField(DataModule1.cdsBook.FieldByName('BookCover')).BlobSize;
if bSize>0 then
begin
jImage := TJpegImage.Create;
with DataModule1 do
begin
ss := TStringStream.Create(MIMEDecodeString(cdsBook.FieldByName('BookCover').AsString));
ss.Seek(0, soFromBeginning);
jImage.LoadFromStream(ss);
IWImage1.Picture.Assign(jImage);
ss.Free;
end;
jImage.Free;
end;
end;
procedure TfrmQueryBook.btnQueryClick(Sender: TObject);
const
INFI = 999999;
var
SQLs : String;
bookname, authorname1, authorname2, authorname3, authorname4, authorname5:String;
lowbound, highbound : Real;
begin
SQLs := 'SELECT * FROM tb_book WHERE'+
'(BookName like %s) and '+
'((Author1 like %s) or '+
'(Author2 like %s) or '+
'(Author3 like %s) or '+
'(Author4 like %s) or '+
'(Author5 like %s)) and '+
'(SellPrice > %4.2f) and'+
'(SellPrice < %4.2f) '+
'ORDER BY ';
DataModule1.cdsBook.Close;
with DataModule1.qrBook do
begin
Close;
SQL.Clear;
if (cbOrderField.ItemIndex = 1) then
begin
SQLs := SQLs+'SellPrice';
end
else
begin
SQLs := SQLs+'PubDate';
end;
if (cbOrderStyle.ItemIndex = 0) then
begin
SQLs := SQLs+' ASC';
end
else
SQLs := SQLs+' DESC';
if edQBook.Text <> '' then
begin
bookname := Format('''%%%s%%''',
[edQBook.Text]);
end
else
bookname := '''%''';
if edQAuthor.Text <> '' then
begin
authorname1 := Format('''%s''',
[edQAuthor.Text]);
authorname2 := Format('''%s''',
[edQAuthor.Text]);
authorname3 := Format('''%s''',
[edQAuthor.Text]);
authorname4 := Format('''%s''',
[edQAuthor.Text]);
authorname5 := Format('''%s''',
[edQAuthor.Text]);
end
else
begin
authorname1 := '''%''';
authorname2 := '''%''';
authorname3 := '''%''';
authorname4 := '''%''';
authorname5 := '''%''';
end;
if (cbCompPrice.ItemIndex = 0) and (edQPrice.Text <> '') then
begin
lowbound := 0;
highbound := StrToInt(edQPrice.Text);
end
else if (cbCompPrice.ItemIndex = 1) and (edQPrice.Text <> '') then
begin
lowbound := StrToInt(edQPrice.Text);
highbound := INFI;
end
else
begin
lowbound := 0;
highbound := INFI;
end;
SQL.Text := Format(SQLs,[bookname, authorname1, authorname2, authorname3, authorname4, authorname5,
lowbound, highbound]);
Open;
end;
DataModule1.cdsBook.Open;
lbRecCount.Text := IntToStr(DataModule1.cdsBook.RecordCount);
end;
procedure TfrmQueryBook.IWDBGrid1Columns0Click(ASender: TObject;
const AValue: String);
begin
DataModule1.cdsBook.Locate('BookSerial',AValue, []);
end;
procedure TfrmQueryBook.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
begin
if IWDBGrid1.RowIsCurrent then
ACell.BGColor := clYellow;
end;
procedure TfrmQueryBook.btnAddToCarterClick(Sender: TObject);
begin
if UserSession.UserName = '' then
begin
WebApplication.ShowMessage('请先登录!');
Exit;
end;
with DataModule1.cdsCarter do
begin
if VarType(Lookup('BookSerial',
DataModule1.cdsBook.FieldByName('BookSerial').AsString,'BookSerial'))
in [VarNull] then
begin
Insert;
FieldByName('BookSerial').AsString :=
DataModule1.cdsBook.FieldByName('BookSerial').AsString;
FieldByName('BookCount').AsInteger := 1;
Post;
end;
WebApplication.ShowMessage('书籍已放入购物箱,请继续选购');
end;
end;
procedure TfrmQueryBook.btnCheckCarterClick(Sender: TObject);
begin
if UserSession.UserName = '' then
begin
WebApplication.ShowMessage('请先登录!');
Exit;
end;
TIWAppForm(WebApplication.ActiveForm).Release;
TfrmCarter.Create(WebApplication).Show;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -