⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryarticleunit.~pas

📁 一个很不错的系统! 查询模块方面是我编的最好的一次.几乎完美!!!!.
💻 ~PAS
字号:
unit queryarticleunit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, ExtCtrls, DBCtrls, DB, ADODB;

type
  Tfrm_queryarticle = class(TForm)
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label1: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label4: TLabel;
    articletype: TEdit;
    articlename: TEdit;
    birthplace: TEdit;
    b_query: TButton;
    b_clear: TButton;
    articleid: TEdit;
    GroupBox2: TGroupBox;
    Label5: TLabel;
    lowPrice: TEdit;
    highPrice: TEdit;
    GroupBox3: TGroupBox;
    Label6: TLabel;
    lowStock: TEdit;
    highStock: TEdit;
    GroupBox4: TGroupBox;
    DBNavigator1: TDBNavigator;
    GroupBox8: TGroupBox;
    b_modify: TButton;
    b_del: TButton;
    GroupBox6: TGroupBox;
    asc: TRadioButton;
    desc: TRadioButton;
    GroupBox5: TGroupBox;
    id: TRadioButton;
    name: TRadioButton;
    price: TRadioButton;
    stock: TRadioButton;
    GroupBox7: TGroupBox;
    DBGrid1: TDBGrid;
    q_article: TADOQuery;
    ds_article: TDataSource;
    procedure b_clearClick(Sender: TObject);
    procedure b_queryClick(Sender: TObject);
    procedure articleidKeyPress(Sender: TObject; var Key: Char);
    procedure articlenameKeyPress(Sender: TObject; var Key: Char);
    procedure articletypeKeyPress(Sender: TObject; var Key: Char);
    procedure lowPriceKeyPress(Sender: TObject; var Key: Char);
    procedure highPriceKeyPress(Sender: TObject; var Key: Char);
    procedure lowStockKeyPress(Sender: TObject; var Key: Char);
    procedure highStockKeyPress(Sender: TObject; var Key: Char);
    procedure birthplaceKeyPress(Sender: TObject; var Key: Char);
    procedure ascClick(Sender: TObject);
    procedure descClick(Sender: TObject);
    procedure idClick(Sender: TObject);
    procedure nameClick(Sender: TObject);
    procedure priceClick(Sender: TObject);
    procedure stockClick(Sender: TObject);
    procedure b_modifyClick(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    str:string;
    function isint(s:string):boolean;
    function ismoney(s:string):boolean;
  public
    { Public declarations }
  end;

var
  frm_queryarticle: Tfrm_queryarticle;

implementation
   uses changearticleunit,datamoduleunit;
{$R *.dfm}

function tfrm_queryarticle.isint(s:string):boolean;
var i:integer;
begin
 i:=1;
 while i<=length(s) do
  begin
   if (ord(s[i])<48) or (ord(s[i])>57) then
    begin
     result:=false;
     exit;
    end;
    i:=i+1;
   end;
  result:=true;
 end;
function tfrm_queryarticle.ismoney(s:string):boolean;
var i:integer;
begin
  i:=1;
   while i<length(s) do
    begin
         if (s[i]<>'.') and((ord(s[i])<48) or (ord(s[i])>57)) then
         begin
         result:=false;
         exit;
        end;
     i:=i+1;
    end;
   result:=true;
 end;
procedure Tfrm_queryarticle.b_clearClick(Sender: TObject);
begin
articleid.Text:='';
articlename.Text:='';
articletype.Text:='';
lowprice.Clear;
highprice.Clear;
lowstock.Clear;
highstock.Clear;
birthplace.Clear;
asc.Checked:=true;
id.Checked:=true;
activecontrol:=articleid;
end;

procedure Tfrm_queryarticle.b_queryClick(Sender: TObject);
var s:string;
 i:integer;
begin
 s:='select * from foods';
 i:=0;
 if articleid.Text<>''  then
  begin
    s:=s+' where 商品编号='''+articleid.Text+'''';
    i:=i+1;
  end;
 if articlename.Text<>'' then
  begin
   if i=0  then s:=s+' where 商品姓名='''+articlename.Text+''''
          else s:=s+' and 商品姓名='''+articlename.Text+'''';
   i:=i+1;
   end;
  if articletype.Text<>'' then
   begin
    if i=0
     then s:=s+' where 商品类型='''+articletype.Text+''''
     else s:=s+' and 商品类型='''+articletype.Text+'''';
    i:=i+1;
   end;
  if lowprice.Text<>'' then
   begin
    if ismoney(lowprice.Text)=false
      then  begin
           activecontrol:=lowprice;
           exit;
           end;
    if i=0
      then s:=s+' where 单价>='+lowprice.Text
      else s:=s+' and 单价>='+lowprice.Text;
   i:=i+1;
   end;
   if highprice.Text<>'' then
   begin
    if ismoney(highprice.Text)=false
     then  begin
           activecontrol:=highprice;
           exit;
           end;
     if i=0 then
     s:=s+' where 单价<='+highprice.Text
     else s:=s+' and 单价<='+highprice.Text;
     i:=i+1;
    end;
  if lowstock.Text<>'' then
   begin
  if isint(lowstock.Text)=false
     then  begin
           activecontrol:=lowstock;
           exit;
           end;
    if i=0 then
     s:=s+' where 存货>='''+lowstock.Text+''''
     else s:=s+' and 存货>='''+lowstock.Text+'''';
     i:=i+1;
    end;
   if highstock.Text<>'' then
   begin
     if isint(highstock.Text)=false
      then  begin
           activecontrol:=highstock;
           exit;
           end;
    if i=0 then
     s:=s+' where 存货<='''+highstock.Text+''''
     else s:=s+' and 存货<='''+highstock.Text+'''';
     i:=i+1;
    end;
   if birthplace.Text<>'' then
   begin
     if i=0 then
     s:=s+' where 产地='''+birthplace.Text+''''
     else s:=s+' and 产地='''+birthplace.Text+'''';
     i:=i+1;
    end;
 q_article.Close;
 q_article.SQL.Clear;
 q_article.SQL.Add(s);
  try
   q_article.Open;
  except
   q_article.ExecSQL;
  end;
 str:=s;   
end;

procedure Tfrm_queryarticle.articleidKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.articlenameKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.articletypeKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.lowPriceKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.highPriceKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.lowStockKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.highStockKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.birthplaceKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=chr(vk_return) then frm_queryarticle.b_queryClick(nil);
end;

procedure Tfrm_queryarticle.ascClick(Sender: TObject);
var col,s:string;
begin
s:=str;
if s='' then s:='select * from foods' ;
if id.Checked then col:=' 商品编号'
 else if name.Checked then col:=' 商品姓名'
  else if price.Checked then col:=' 单价'
   else col:=' 存货';
 s:=s+ ' order by'+col+' asc';
q_article.Close;
q_article.SQL.Clear;
q_article.SQL.Add(s);
 try
  q_article.Open;
 except
  q_article.ExecSQL;
 end;

end;


procedure Tfrm_queryarticle.descClick(Sender: TObject);
var col,s:string;
begin
s:=str;
if s='' then s:='select * from foods' ;
if id.Checked then col:=' 商品编号'
 else if name.Checked then col:=' 商品姓名'
  else if price.Checked then col:=' 单价'
   else col:=' 存货';
 s:=s+ ' order by'+col+' desc';
q_article.Close;
q_article.SQL.Clear;
q_article.SQL.Add(s);
 try
  q_article.Open;
 except
  q_article.ExecSQL;
 end;


end;

procedure Tfrm_queryarticle.idClick(Sender: TObject);
var x,s:string;
begin
 if asc.Checked then x:=' asc' else x:=' desc';
 s:=str;
 if s='' then s:='select * from foods' ;
 s:=s+' order by 商品编号'+x;
 q_article.Close;
 q_article.SQL.Clear;
 q_article.SQL.Add(s);
 try
  q_article.Open;
 except
  q_article.ExecSQL;
 end;

end;

procedure Tfrm_queryarticle.nameClick(Sender: TObject);
var x,s:string;
begin
 if asc.Checked then x:=' asc' else x:=' desc';
 s:=str;
 if s='' then s:='select * from foods' ;
 s:=s+' order by 商品姓名'+x;
 q_article.Close;
 q_article.SQL.Clear;
 q_article.SQL.Add(s);
 try
  q_article.Open;
 except
  q_article.ExecSQL;
 end;

end;

procedure Tfrm_queryarticle.priceClick(Sender: TObject);
var x,s:string;
begin
 if asc.Checked then x:=' asc' else x:=' desc';
 s:=str;
 if s='' then s:='select * from foods' ;
 s:=s+' order by 单价'+x;
 q_article.Close;
 q_article.SQL.Clear;
 q_article.SQL.Add(s);
 try
  q_article.Open;
 except
  q_article.ExecSQL;
 end;

end;

procedure Tfrm_queryarticle.stockClick(Sender: TObject);
var x,s:string;
begin
 if asc.Checked then x:=' asc' else x:=' desc';
 s:=str;
 if s='' then s:='select * from foods' ;
 s:=s+' order by 存货'+x;
 q_article.Close;
 q_article.SQL.Clear;
 q_article.SQL.Add(s);
 try
  q_article.Open;
 except
  q_article.ExecSQL;
 end;
end;

procedure Tfrm_queryarticle.b_modifyClick(Sender: TObject);
begin
frm_changearticle:=tfrm_changearticle.Create(self);
if sender=b_del
  then frm_changearticle.b_modify.Visible:=false
  else  frm_changearticle.b_del.Visible:=false;
frm_changearticle.ShowModal;
frm_changearticle.Destroy;
end;

procedure Tfrm_queryarticle.DBGrid1DblClick(Sender: TObject);
begin
if b_modify.Enabled=false then exit;
frm_queryarticle.b_modifyClick(nil);
end;

procedure Tfrm_queryarticle.FormCreate(Sender: TObject);
begin
str:='';
end;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -