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

📄 ucombinationquery.pas

📁 工廠採購管理系統
💻 PAS
字号:
unit UCombinationQuery;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, Buttons, StdCtrls,dateutils;

type
  TForm_CombinationQuery = class(TForm)
    GroupBox1: TGroupBox;
    ShowListBox: TListBox;
    Label1: TLabel;
    SpeedButton1: TSpeedButton;
    Label2: TLabel;
    Label3: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Edit1: TEdit;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SQLListBox: TListBox;
    edit2: TEdit;
    FieldListBox: TListBox;
    Label4: TLabel;
    Label5: TLabel;
    Edit3: TEdit;
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure ComboBox1Click(Sender: TObject);
    procedure ShowListBoxClick(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form_CombinationQuery: TForm_CombinationQuery;

implementation
uses Umain;
{$R *.dfm}

procedure TForm_CombinationQuery.SpeedButton3Click(Sender: TObject);
begin
  if (trim(edit1.text) <> '') or (Length(trim(edit1.Text)) < 25) then
  begin
    if ComboBox2.Text = '等于' then
    begin
      ShowListbox.Items.Add(copy(ComboBox1.Text + '                    ', 0, 20) + copy(ComboBox2.Text + '                    ', 0, 20) + edit1.Text);
      SQLListBox.ItemS.Add(trim(edit2.Text) + ' = ''' + trim(edit1.Text) + '''');
    end
    else
      if ComboBox2.Text = '包含' then
      begin
        ShowListbox.Items.Add(copy(ComboBox1.Text + '                    ', 0, 20) + copy(ComboBox2.Text + '                    ', 0, 20) + edit1.Text);
        SQLListBox.ItemS.Add(trim(edit2.Text) + ' like''%' + trim(edit1.Text) + '%''');
      end;
  end
  else
  begin
    beep;
    showmessage('您输入的条件不正确,请重新输入');
    edit1.SetFocus;
  end;
end;

procedure TForm_CombinationQuery.SpeedButton1Click(Sender: TObject);
var i: integer;
begin
  i := ShowListBox.ItemIndex;
  if i < 0 then
  begin
    showmessage('当前没有选中记录');
    exit;
  end;
  ShowListBox.DeleteSelected; //删除选中的条
  SQLListBox.DeleteSelected;
end;

procedure TForm_CombinationQuery.FormShow(Sender: TObject);
var i: integer;
begin
  ComboBox2.Items.Clear;
  ComboBox2.Text := '等于';
  ComboBox2.Items.Add('等于');
  ComboBox2.Items.Add('包含');
  ComboBox1.Text := '职工编号';
  edit2.Text := 'Employee_id ';
  with Form_Main.DBGridEhEmployee do
  begin
    for i := 0 to 32 do
    begin
      ComboBox1.Items.Add(Columns[i].Title.Caption);
      FieldListBox.Items.Add(Columns[i].FieldName);
    end;
  end;

end;

procedure TForm_CombinationQuery.Edit1KeyPress(Sender: TObject;
  var Key: Char);
begin
  if key = #13 then
    SpeedButton3Click(Sender);
end;

procedure TForm_CombinationQuery.ComboBox1Click(Sender: TObject);
var i: integer; //记录当前选中的combobox选项序列数
begin
  i := ComboBox1.ItemIndex + 1;
  if i < 0 then //当前没有选中记录
    exit;
  edit2.Text := FieldListbox.Items[i - 1];
end;

procedure TForm_CombinationQuery.ShowListBoxClick(Sender: TObject);
var i: integer;
begin
  i := ShowListbox.ItemIndex;
  SQLlistbox.Selected[i] := true;
end;

procedure TForm_CombinationQuery.SpeedButton2Click(Sender: TObject);
var i: integer;
begin
  if SQLListBox.Count = 0 then
  begin
    showmessage('未添加条件');
    exit;
  end;
  for i := 0 to SQLListBox.Count - 1 do
  begin
    if i = 0 then
      edit3.Text := ' WHERE ' + SQLListBox.Items[i]
    else
      edit3.text := edit3.Text + ' AND ' + SQLListBox.Items[i];
  end;
 // showmessage('等一等,先看看');
  if edit3.Text <> '' then
  begin
    with Form_Main.ADOQDBGrid do
    begin
      close;
      SQL.Clear;
      SQL.Add('SELECT * FROM EMPLOYEE');
      sql.Add(edit3.Text);
      open;
    end;
    Form_CombinationQuery.WindowState := wsMinimized;
    Form_Main.label2.Caption := '共有 ' + inttostr(Form_Main.ADOQDBGrid.RecordCount) + ' 位符合查询条件的职工';
  end;

end;

end.

⌨️ 快捷键说明

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