📄 gq_uhavingform.pas
字号:
{
代码单元名称:通用综合查询工具分组统计条件输入窗口
从属软件:大连资金清算中心打码机管理信息系统
开发单位:大连理工大学计算机技术研究所软件工程研究室
作者:袁源
时间:2001,1,30
}
unit GQ_UHavingForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, GQ_UQueryMain;
type
Thavingform = class(TForm)
Button1: TButton;
Button2: TButton;
Panel2: TPanel;
ListBox3: TListBox;
Label4: TLabel;
Label9: TLabel;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
CanGroupBox: TListBox;
RadioGroup1: TRadioGroup;
ListBox2: TListBox;
GroupBox2: TGroupBox;
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
Edit1: TEdit;
Label5: TLabel;
GroupBox3: TGroupBox;
ListBox4: TListBox;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label10: TLabel;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure SpeedButton10Click(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure SpeedButton13Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure Label3Click(Sender: TObject);
procedure Label5Click(Sender: TObject);
procedure Label6Click(Sender: TObject);
procedure Label9Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Label10Click(Sender: TObject);
private
{ Private declarations }
public
ss: tstrings;
Complex: Boolean;
procedure inithavingForm(getchoose: boolean; thestringtype: FldType);
{ Public declarations }
end;
var
choose: boolean;
Mystringtype: FldType;
implementation
{$R *.DFM}
{-------------------------------------------------------------------------------}
procedure Thavingform.FormCreate(Sender: TObject);
begin
ss := tstringList.Create;
Complex := False;
end;
procedure Thavingform.FormShow(Sender: TObject);
begin
if Choose then
begin
ListBox4.Items.Clear;
ListBox4.Items.Add(' + ');
ListBox4.Items.Add(' - ');
ListBox4.Items.Add(' * ');
ListBox4.Items.Add(' / ');
ListBox4.Items.Add(' ( ');
ListBox4.Items.Add(' ) ');
ListBox4.Items.Add(' > ');
ListBox4.Items.Add(' < ');
ListBox4.Items.Add(' = ');
ListBox4.Items.Add(' <> ');
ListBox4.Items.Add(' >= ');
ListBox4.Items.Add(' <= ');
end
else
begin
ListBox4.Items.Clear;
ListBox4.Items.Add(' + ');
ListBox4.Items.Add(' - ');
ListBox4.Items.Add(' * ');
ListBox4.Items.Add(' / ');
ListBox4.Items.Add(' ( ');
ListBox4.Items.Add(' ) ');
end;
ListBox2.Items.Clear;
ListBox3.Items.Clear;
Edit1.Text := '';
if Mystringtype = Date then
SpeedButton13.Enabled := True
else
SpeedButton13.Enabled := False;
ListBox3.Items.Clear;
ListBox3.Items.Add('');
end;
procedure Thavingform.FormDestroy(Sender: TObject);
begin
ss.Free;
end;
{-------------------------------------------------------------------------------}
procedure Thavingform.BitBtn1Click(Sender: TObject);
var
selectedIndex: integer;
s: string;
begin
if canGroupBox.selcount = 0 then
begin
ShowMessage('请先选中一行');
exit;
end;
for selectedIndex := 0 to CanGroupBox.Items.count - 1 do
if CanGroupBox.selected[selectedIndex] then
break;
if (ss[selectedIndex] = 'Strings') or (ss[selectedIndex] = 'Logical') then
if radioGroup1.ItemIndex <> 3 then
begin
ShowMessage('对不起,你所选中的字段不适数字类型,不能进行该运算');
exit;
end;
case radioGroup1.itemIndex of
0: s := ' max(' + trim(CanGroupBox.Items[selectedIndex]) + ')';
1: s := ' min(' + trim(CanGroupBox.Items[selectedIndex]) + ')';
2: s := ' avg(' + trim(CanGroupBox.Items[selectedIndex]) + ')';
3: s := ' count(' + trim(CanGroupBox.Items[selectedIndex]) + ')';
4: s := ' sum(' + trim(CanGroupBox.Items[selectedIndex]) + ')';
end;
if ListBox2.Items.indexof(s) = -1 then
begin
ListBox2.Items.Add(s);
CanGroupBox.Selected[selectedIndex] := False;
end
else
ShowMessage('对不起,你已经选取了该项');
end;
procedure Thavingform.BitBtn2Click(Sender: TObject);
var
i: integer;
begin
if ListBox2.itemindex = -1 then
begin
ShowMessage('请先选取一行');
exit;
end;
for i := 0 to ListBox2.Items.count - 1 do
if ListBox2.selected[i] = True then
begin
ListBox2.Items.delete(i);
exit;
end;
end;
procedure Thavingform.SpeedButton1Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '1';
end;
procedure Thavingform.SpeedButton2Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '2';
end;
procedure Thavingform.SpeedButton3Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '3';
end;
procedure Thavingform.SpeedButton4Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '4';
end;
procedure Thavingform.SpeedButton5Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '5';
end;
procedure Thavingform.SpeedButton6Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '6';
end;
procedure Thavingform.SpeedButton7Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '7';
end;
procedure Thavingform.SpeedButton8Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '8';
end;
procedure Thavingform.SpeedButton9Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '9';
end;
procedure Thavingform.SpeedButton10Click(Sender: TObject);
var
i: integer;
begin
i := length(Edit1.Text);
if i = 0 then
begin
ShowMessage('你不能在此时输入.号');
exit;
end;
if (Edit1.Text[i] > '9') or (Edit1.Text[i] < '0') then
begin
ShowMessage('你不能在此时输入.号');
exit;
end;
Edit1.Text := Edit1.Text + '.';
end;
procedure Thavingform.SpeedButton11Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '0';
end;
procedure Thavingform.SpeedButton13Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '/';
end;
procedure Thavingform.SpeedButton12Click(Sender: TObject);
begin
if length(Edit1.Text) <> 0 then
Edit1.Text := copy(Edit1.Text, 1, length(Edit1.Text) - 1);
end;
procedure Thavingform.Label3Click(Sender: TObject);
var
i: integer;
begin
i := length(ListBox3.Items[0]);
if i <> 0 then
if (ListBox3.Items[0][i] >= '0') and (ListBox3.Items[0][i] <= '9') or
(ListBox3.Items[0][i] = ')') then
begin
ShowMessage('你应输入运算符或左扩号');
exit;
end;
for i := 0 to ListBox2.Items.count - 1 do
if ListBox2.selected[i] then
begin
ListBox3.Items[0] := ListBox3.Items[0] + ListBox2.Items[i];
ListBox2.selected[i] := False;
exit;
end;
end;
procedure Thavingform.Label5Click(Sender: TObject);
var
i: integer;
begin
if length(Edit1.Text) = 0 then
exit;
if Edit1.Text[length(Edit1.Text)] = '.' then
begin
ShowMessage('数值项有错');
exit;
end;
i := length(ListBox3.Items[0]);
if i <> 0 then
if (ListBox3.Items[0][i] >= '0') and (ListBox3.Items[0][i] <= '9') or
(ListBox3.Items[0][i] = ')') then
begin
ShowMessage('你应输入运算符或左扩号');
exit;
end;
ListBox3.Items[0] := ListBox3.Items[0] + Edit1.Text;
Edit1.Text := '';
end;
procedure Thavingform.Label6Click(Sender: TObject);
var
i: integer;
begin
if ListBox4.itemIndex = -1 then
exit;
i := length(ListBox3.Items[0]);
if (i = 0) then
begin
if (trim(ListBox4.Items[ListBox4.ItemIndex]) = '(') then
ListBox3.Items[0] := '('
else
ShowMessage('输入错误');
exit;
end;
if trim(ListBox4.Items[ListBox4.itemIndex]) <> '(' then
begin
if (ListBox3.Items[0][i] > '9') or (ListBox3.Items[0][i] < '0') and
(ListBox3.Items[0][i] <> ')') then
begin
ShowMessage('现在不能输入该项');
exit;
end
end
else if (ListBox3.Items[0][i] >= '0') and (ListBox3.Items[0][i] <= '9') or
(ListBox3.Items[0][i] = ')') then
begin
ShowMessage('现在不能输入该项');
exit;
end;
ListBox3.Items[0] := ListBox3.Items[0] +
trim(ListBox4.Items[ListBox4.itemIndex]);
ListBox4.ItemIndex := -1;
end;
procedure Thavingform.Label9Click(Sender: TObject);
begin
ListBox3.Items[0] := '';
end;
procedure Thavingform.Button1Click(Sender: TObject);
var
i: integer;
tempflag: integer;
over: boolean;
begin
over := False;
if choose then
begin
if Pos('<>', ListBox3.Items[0]) <> 0 then
over := True;
if Pos('>', ListBox3.Items[0]) <> 0 then
over := True;
if Pos('<', ListBox3.Items[0]) <> 0 then
over := True;
if Pos('<=', ListBox3.Items[0]) <> 0 then
over := True;
if Pos('>=', ListBox3.Items[0]) <> 0 then
over := True;
if Pos('=', ListBox3.Items[0]) <> 0 then
over := True;
if not over then
begin
ShowMessage('你应该输入关系运算符');
exit;
end;
end;
if length(ListBox3.Items[0]) = 0 then
begin
ShowMessage('不能为空');
exit;
end;
tempflag := 0;
for i := 1 to length(ListBox3.Items[0]) do
begin
if ListBox3.Items[0][i] = '(' then
tempflag := tempflag + 1;
if ListBox3.Items[0][i] = ')' then
tempflag := tempflag - 1;
end;
if tempflag <> 0 then
begin
ShowMessage('你输入的括号不搭配');
exit;
end;
if (ListBox3.Items[0][length(ListBox3.Items[0])] <> ')') and
((ListBox3.Items[0][length(ListBox3.Items[0])] < '0') or
(ListBox3.Items[0][length(ListBox3.Items[0])] > '9')) then
begin
ShowMessage('输入不正确');
exit;
end;
modalresult := mrOK;
end;
procedure Thavingform.Button2Click(Sender: TObject);
begin
modalResult := mrCancel;
end;
procedure Thavingform.inithavingForm(getchoose: boolean;
thestringtype: FldType);
begin
choose := getchoose;
Mystringtype := thestringtype;
end;
procedure Thavingform.Label10Click(Sender: TObject);
begin
if Complex then
Complex := False
else
Complex := True;
if Complex then
begin
Width := 441;
Button1.Left := 353;
Button2.Left := 353;
end
else
begin
Width := 355;
Button1.Left := 248;
Button2.Left := 248;
end;
GroupBox3.Visible := Complex;
GroupBox2.Visible := Complex;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -