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

📄 selproduct.pas

📁 企业商品管理系统
💻 PAS
字号:
unit SelProduct;

interface

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

type
  TFrm_SelProduct = class(TBaseForm)
    GroupBox1: TGroupBox;
    StatusBar1: TStatusBar;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Notebook1: TNotebook;
    Edit1: TEdit;
    DateTimePicker1: TDateTimePicker;
    Label4: TLabel;
    ComboBox3: TComboBox;
    Memo1: TMemo;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    ADODataSet1: TADODataSet;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    procedure FormShow(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
    BaseCon:TStrings;
    SelStr:string;
  public
    { Public declarations }
  end;

var
  Frm_SelProduct: TFrm_SelProduct;

implementation
uses DM;
{$R *.dfm}

procedure TFrm_SelProduct.FormShow(Sender: TObject);
var
  i:Integer;
begin
  ADODataSet1.Close;
  ADODataSet1.Open;

  ComboBox2.Clear;
  BaseCon:=ComboBox2.Items;
  BaseCon.BeginUpdate;
  BaseCon.Add(' < ');
  BaseCon.Add(' > ');
  BaseCon.Add(' <> ');
  BaseCon.Add(' = ');
  BaseCon.Add(' >= ');
  BaseCon.Add(' <= ');
  BaseCon.EndUpdate;

  ComboBox3.Items.Add(' and ');
  ComboBox3.Items.Add(' or ');
  
  Notebook1.PageIndex:=0;

  ComboBox1.Clear;
  for i:=0 to DBGrid1.Columns.Count-1 do
  begin
    with DBGrid1 do
    begin
      if Columns[i].Field.DataType in [ftString, ftSmallint, ftInteger, ftWord,
                    ftFloat, ftCurrency,ftWideString,ftLargeint,
                    ftDate, ftTime, ftDateTime] then
      ComboBox1.Items.Add(Columns[i].Title.Caption);
      Next;
    end;
  end;
end;

procedure TFrm_SelProduct.SpeedButton4Click(Sender: TObject);
var
  SQLStr,Temp:string;
begin
  if ComboBox1.Text='' then
  begin
    Application.MessageBox('查询字段不能为空!','明日科技');
    ComboBox1.SetFocus;
    Exit;
  end;
  if ComboBox2.Text='' then
  begin
    Application.MessageBox('查询条件不能为空!','明日科技');
    ComboBox2.SetFocus;
    Exit;
  end;
  
  case Notebook1.PageIndex of
  0 :begin
      if Edit1.Text='' then
      begin
        Application.MessageBox('查询的值不能为空!','明日科技');
        Edit1.SetFocus;
        Exit;
      end;
     end;
  1 :begin
        //什么也不用做
     end;
  end;

  if (Trim(ComboBox2.Text)='Like') or (Trim(ComboBox2.Text)='Not Like') then
  begin
    SQLStr:=DBGrid1.Columns[ComboBox1.ItemIndex].Title.Caption+ComboBox2.Text+Quotedstr(Edit1.Text);
    Temp:=DBGrid1.Columns[ComboBox1.ItemIndex].FieldName+ComboBox2.Text+Quotedstr(Edit1.Text);
  end
  else if (Notebook1.PageIndex=1) then
  begin
    SQLStr:=DBGrid1.Columns[ComboBox1.ItemIndex].Title.Caption+ComboBox2.Text+QuotedStr(DateTimeToStr(DateTimePicker1.DateTime));
    Temp:=DBGrid1.Columns[ComboBox1.ItemIndex].FieldName+ComboBox2.Text+QuotedStr(DateTimeToStr(DateTimePicker1.DateTime));
  end
  else
  begin
    SQLStr:=DBGrid1.Columns[ComboBox1.ItemIndex].Title.Caption+ComboBox2.Text+Edit1.Text;
    Temp:=DBGrid1.Columns[ComboBox1.ItemIndex].FieldName+ComboBox2.Text+Edit1.Text;
  end;
  if (Memo1.Lines.Text<>'') then
  begin
    if ComboBox3.Text='' then
    begin
      Application.MessageBox('查询关系不能为空!','明日科技');
      ComboBox3.SetFocus;
      Exit;
    end;
    SQLStr:=ComboBox3.Text+SQLStr;
    Temp:=ComboBox3.Text+Temp;
  end;
  Memo1.Lines.Add(SQLStr);
  SelStr:=SelStr+Temp;
end;

procedure TFrm_SelProduct.SpeedButton1Click(Sender: TObject);
begin
  ADODataSet1.Filtered:=False;
  ADODataSet1.Filter:=SelStr;
  ADODataSet1.Filtered:=True;
  SelStr:='';
end;

procedure TFrm_SelProduct.SpeedButton2Click(Sender: TObject);
begin
  ADODataSet1.Filtered:=False;
  ADODataSet1.Filter:='';
  ADODataSet1.Filtered:=True;
  SelStr:='';
end;

procedure TFrm_SelProduct.SpeedButton5Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  SelStr:='';
end;

procedure TFrm_SelProduct.SpeedButton3Click(Sender: TObject);
begin
  Close;
  SelStr:='';
end;

procedure TFrm_SelProduct.ComboBox1Change(Sender: TObject);
begin
  inherited;
  ComboBox2.Clear;
  BaseCon:=ComboBox2.Items;
  BaseCon.BeginUpdate;
  BaseCon.Add(' < ');
  BaseCon.Add(' > ');
  BaseCon.Add(' <> ');
  BaseCon.Add(' = ');
  BaseCon.Add(' >= ');
  BaseCon.Add(' <= ');
  BaseCon.EndUpdate;
  with DBGrid1.Columns[ComboBox1.itemIndex].Field do
  if DataType in [ftSmallint, ftInteger, ftWord,
            ftFloat, ftCurrency,ftLargeint] then
  begin
      Notebook1.PageIndex:=0;
  end
  else if DataType in [ftString,ftWideString] then
  begin
      BaseCon.BeginUpdate;
      BaseCon.Add(' Like ');
      BaseCon.Add(' Not Like ');
      BaseCon.EndUpdate;
      Notebook1.PageIndex:=0;
  end
  else if DataType in [ftDate, ftTime, ftDateTime] then
  begin
      Notebook1.PageIndex:=1;
  end;
end;

end.

⌨️ 快捷键说明

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