📄 gq_uquerymain.pas
字号:
FldValueBox.Clear;
NowFldPos := FldNameBox.ItemIndex;
with GQ_FDataModule.ADOQuery1 do
begin
Close;
Sql.Clear;
Sql.Add('Select *');
Sql.Add('From ' + TableName);
Open;
case Fields[NowFldPos].DataType of
ftString: StringType := Strings;
ftBoolean: StringType := Logical;
ftDate, ftDateTime, ftTime: StringType := Date;
else
StringType := Number;
end;
Close;
end;
if ((StringType = Number) or (StringType = Logical) or (StringType = Date))
then
begin
OperateBox.Items.Clear;
OperateBox.Items.Add('=');
OperateBox.Items.Add('<');
OperateBox.Items.Add('<=');
OperateBox.Items.Add('>');
OperateBox.Items.Add('>=');
OperateBox.Items.Add('<>');
OperateBox.Items.Add('在...中');
OperateBox.Items.Add('从...到...之间');
end;
if StringType = Strings then
begin
OperateBox.Items.Clear;
OperateBox.Items.Add('=');
OperateBox.Items.Add('<');
OperateBox.Items.Add('<=');
OperateBox.Items.Add('>');
OperateBox.Items.Add('>=');
OperateBox.Items.Add('<>');
OperateBox.Items.Add('在...中');
OperateBox.Items.Add('类似');
OperateBox.Items.Add('包括');
OperateBox.Items.Add('开头是');
OperateBox.Items.Add('结尾是');
OperateBox.Items.add('空');
end;
end;
procedure TGQ_FQueryMain.SelectBoxDblClick(Sender: TObject);
begin
if SelectBox.ItemIndex <> -1 then
SelectBox.Items.Delete(SelectBox.ItemIndex);
end;
{---------------------Order Page---------------------------------}
procedure TGQ_FQueryMain.OrderListDblClick(Sender: TObject);
begin
if OrderList.ItemIndex = -1 then
Exit;
if OrderBox.Items.IndexOf(OrderList.Items[OrderList.ItemIndex]) = -1 then
OrderBox.Items.Add(OrderList.Items[OrderList.ItemIndex]);
end;
procedure TGQ_FQueryMain.OrderFldSelClick(Sender: TObject);
var
i: integer;
temp, temp1: string;
begin
if RadioGroup1.ItemIndex = 0 then
temp := ' ASC'
else
temp := ' DESC';
if OrderList.ItemIndex = -1 then
Exit;
for i := 0 to OrderList.Items.Count - 1 do
if OrderList.Selected[i] then
begin
temp1 := OrderList.Items[i] + temp;
if OrderBox.Items.IndexOf(temp1) = -1 then
OrderBox.Items.Add(OrderList.Items[i] + temp);
end;
end;
procedure TGQ_FQueryMain.OrderFldDelClick(Sender: TObject);
var
i: integer;
begin
if OrderBox.ItemIndex = -1 then
Exit;
for i := OrderBox.Items.Count - 1 downto 0 do //在删除后列表项目减少,
if OrderBox.Selected[i] then //所以要用"downto"结构
begin //保证不会重复删除某一位置
OrderBox.Items.Delete(i);
end;
end;
procedure TGQ_FQueryMain.OrderBoxDblClick(Sender: TObject);
begin
OrderBox.Items.Delete(OrderBox.ItemIndex);
end;
{----------------------Group page--------------------------------------}
procedure TGQ_FQueryMain.GroupFldAddClick(Sender: TObject);
var
i: integer;
begin
if grouplist.selcount = 0 then
exit;
if groupbox.Items.Count = 0 then
enablegrouping;
for i := 0 to GroupList.Items.Count - 1 do
if GroupList.Selected[i] then
if GroupBox.Items.IndexOf(GroupList.Items[i]) = -1 then
GroupBox.Items.Add(GroupList.Items[i]);
end;
procedure TGQ_FQueryMain.GroupFldDelClick(Sender: TObject);
var
i: integer;
begin
if GroupBox.ItemIndex = -1 then
Exit;
for i := GroupBox.Items.Count - 1 downto 0 do //在删除后列表项目减少,
if GroupBox.Selected[i] then //所以要用"downto"结构
begin //保证不会重复删除某一位置
GroupBox.Items.Delete(i);
end;
if groupbox.Items.Count = 0 then
disablegrouping;
end;
procedure TGQ_FQueryMain.GroupDelAllClick(Sender: TObject);
begin
disablegrouping;
GroupBox.Clear;
end;
procedure TGQ_FQueryMain.GroupAddAllClick(Sender: TObject);
begin
if groupbox.Items.Count = 0 then
enablegrouping;
GroupBox.Items.Assign(GroupList.Items);
end;
procedure TGQ_FQueryMain.GroupListDblClick(Sender: TObject);
begin
if GroupList.ItemIndex = -1 then
Exit;
if GroupBox.Items.IndexOf(GroupList.Items[GroupList.ItemIndex]) = -1 then
GroupBox.Items.Add(GroupList.Items[GroupList.ItemIndex]);
end;
procedure TGQ_FQueryMain.GroupBoxDblClick(Sender: TObject);
begin
GroupBox.Items.Delete(GroupBox.ItemIndex);
end;
{----------------------Grouping page-----------------------------------}
procedure TGQ_FQueryMain.GroupingFldDelClick(Sender: TObject);
begin
GroupingBox.Items.Delete(GroupingBox.ItemIndex);
end;
procedure TGQ_FQueryMain.GroupingBoxDblClick(Sender: TObject);
begin
GroupingBox.Items.Delete(GroupingBox.ItemIndex);
end;
{----------------------Main Process------------------------------------}
procedure TGQ_FQueryMain.NextStepClick(Sender: TObject);
var
currentPos: integer;
GoAhead: boolean;
begin
if TableName = '' then
begin
MessageDlg('请先确定需要查询的库表!', mtInformation, [mbOk], 0);
Exit;
end;
if NoteBook1.PageIndex = 0 then
if listbox1.Items.Count > 1 then
begin
messagedlg('对不起你所选定的条件还未达配完全' + #10#13 +
' 请使下框中只有一行', mtInformation, [mbOK], 0);
exit;
end;
if NoteBook1.pageIndex = 3 then
begin
listbox3.items.clear;
if groupbox.Items.count <> 0 then
begin
if fieldchoosebox.Items.count > 1 then
begin
messagedlg('对不起你所选定的条件还未达配完全' + #10#13 +
' 请使下框中只有一行', mtInformation, [mbOK], 0);
exit;
end;
listbox2.items.clear;
listbox3.items.Assign(groupbox.items);
groupingbox.items.Clear;
end
end;
if NoteBook1.PageIndex = 5 then
if ((ComboBox2.Text <> '空') and (ComboBox2.Text <> '')) then
begin
with GQ_FDataModule.ADOQuery1 do
begin
Close;
Sql.Clear;
Sql.Add('drop view ' + MyViewName);
try
ExecSql;
except on E: Exception do
end;
end;
Goahead := CreateMyView;
if not GoAhead then
exit;
checkbox1.Checked := false;
end
else
begin
Fldnamebox.Items.Assign(FldNames);
selectList.Items.Assign(FldNames);
selectBox.Items.assign(FldNames);
OrderList.Items.Assign(FldNames);
GroupList.Items.Assign(FldNames);
groupbox.items.Clear;
disablegrouping;
end;
previewstep.Enabled := true;
currentPos := NoteBook1.PageIndex + 1;
NoteBook1.PageIndex := NoteBook1.PageIndex + 1;
if currentPos = 6 then
NoteBook1.PageIndex := 0;
case NoteBook1.PageIndex of
0: currentPos := 1;
1: currentPos := 2;
2: currentPos := 3;
3: currentPos := 4;
4: currentPos := 5;
5: currentPos := 0;
end;
if currentPos = 5 then
nextStep.Enabled := false;
LastStep.Enabled := True;
case currentPos of
1:
begin
Shape2.Brush.Color := clLime;
Shape7.Brush.Color := clGray;
end;
2:
begin
Shape3.Brush.Color := clLime;
Shape2.Brush.Color := clGray;
end;
3:
begin
Shape4.Brush.Color := clLime;
Shape3.Brush.Color := clGray;
end;
4:
begin
Shape5.Brush.Color := clLime;
Shape4.Brush.Color := clGray;
end;
5:
begin
Shape6.Brush.Color := clLime;
Shape5.Brush.Color := clGray;
end;
end;
end;
procedure TGQ_FQueryMain.LastStepClick(Sender: TObject);
var
currentPos: integer;
begin
currentPos := NoteBook1.PageIndex - 1;
NoteBook1.PageIndex := NoteBook1.PageIndex - 1;
if currentPos = -1 then
NoteBook1.PageIndex := 5;
case NoteBook1.PageIndex of
0: currentPos := 1;
1: currentPos := 2;
2: currentPos := 3;
3: currentPos := 4;
4: currentPos := 5;
5: currentPos := 0;
end;
if currentPos = 0 then
begin
LastStep.Enabled := False;
previewstep.Enabled := false;
end;
NextStep.Enabled := True;
case currentPos of
0:
begin
Shape7.Brush.Color := clLime;
Shape2.Brush.Color := clGray
end;
1:
begin
Shape2.Brush.Color := clLime;
Shape3.Brush.Color := clGray
end;
2:
begin
Shape3.Brush.Color := clLime;
Shape4.Brush.Color := clGray
end;
3:
begin
Shape4.Brush.Color := clLime;
Shape5.Brush.Color := clGray
end;
4:
begin
Shape5.Brush.Color := clLime;
Shape6.Brush.Color := clGray
end;
end;
end;
{-------------------------------Form SQL Statement---------------------------------}
function TGQ_FQueryMain.NullAndOr(Sender: TObject): Boolean;
var
Temp: string;
begin
if WhereBox.Items.Count = 0 then
begin
Result := False;
Exit;
end;
Result := False;
Temp := WhereBox.Items[WhereBox.Items.Count - 1];
if (Temp = ' And ') or (Temp = ' Or ') then
Result := True;
end;
procedure TGQ_FQueryMain.DelMulItem(Sender: TObject);
var
i, j, m: Integer;
TempP, TempN: string;
begin
i := 0;
m := FldValueBox.Items.Count;
if m = 0 then
Exit;
while i <= (m - 1) do
begin
TempP := FldValueBox.Items[i];
for j := i + 1 to FldValueBox.Items.Count - 1 do
begin
TempN := FldValueBox.Items[j];
if TempP = TempN then
FldValueBox.Items.Delete(j)
else
Break;
end;
i := i + 1;
end;
end;
function TGQ_FQueryMain.DealLBCE(Sender: TObject): string;
var
Temp: string;
begin
Temp := FldValueBox.Text;
if not (trim(OperateBox.Text) = '类似') and
not (trim(OperateBox.Text) = '开头是') and
not (trim(OperateBox.Text) = '结尾是') and
not (trim(OperateBox.Text) = '包括') and
not (trim(OperateBox.text) = '在...中') then
Temp := '''' + Temp + '''';
if (trim(OperateBox.Text) = '类似') or
(trim(OperateBox.Text) = '开头是') then
Temp := '''' + Temp + '%' + '''';
if trim(OperateBox.Text) = '包括' then
Temp := '''' + '%' + Temp + '%' + '''';
if trim(OperateBox.Text) = '结尾是' then
Temp := '''' + '%' + Temp + '''';
DealLBCE := Temp;
end;
function TGQ_FQueryMain.DealDateMonth(S1: string): string;
var
Temp: string;
ADate: TDatetime;
AYear, AMonth, ADay: Word;
begin
DecodeDate(StrtoDate(FldValueBox.Text), AYear, AMonth, ADay);
ADate := EncodeDate(AYear, AMonth, 1);
Temp := '(' + S1 + '>=' + '''' + ForMatDateTime('mm/dd/yyyy', ADate) + '''' +
') And ';
if AMonth = 12 then
begin
ADate := EncodeDate(AYear, AMonth, 31);
Result := Temp + '(' + S1 + '<=' + '''' + ForMatDateTime('mm/dd/yyyy', ADate)
+ '''' + ')';
end
else
begin
ADate := EncodeDate(AYear, AMonth + 1, 1);
Result := Temp + '(' + S1 + '<' + '''' + ForMatDateTime('mm/dd/yyyy', ADate)
+ '''' + ')';
end;
end;
{-----------------------------initialization work------------------------}
procedure TGQ_FQueryMain.InitForm;
begin
FldNameBox.Clear;
OperateBox.Text := '';
FldValueBox.Clear;
SelectList.Clear;
SelectBox.Clear;
WhereBox.Clear;
end;
{----------------------------some procedure and function-------------------}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -