📄 gq_uquerymain.pas
字号:
end;
{---------------------------Button Work------------------------------}
procedure TGQ_FQueryMain.InitQuery;
begin
combobox1.Items.Add(GetTableCName(TableName));
combobox2.Items.Assign(TableNameList);
if not OpenSource then
begin
MessageDlg('指定的数据库或表不能打开,请与系统管理员联系!', mtInformation,
[mbOk], 0);
DataBaseName := '';
TableName := '';
Exit;
end;
if DataBaseName <> '' then
StatusBar1.Panels[1].Text := '当前选择的数据库为' + DataBaseName
else
StatusBar1.Panels[1].Text := '当前尚未选择数据库';
if TableName <> '' then
StatusBar1.Panels[1].Text := StatusBar1.Panels[1].Text + ' 当前选择的表为' +
TableName
else
StatusBar1.Panels[1].Text := StatusBar1.Panels[1].Text + ' 当前尚未选择表';
FldNameBox.Items.Assign(FldCNames);
FldValueBox.Clear;
Combobox2.Items.Add('空');
ComboBox1.Text := GetTableCName(TableName);
ComboBox1.Enabled := false;
if trim(ComboBox1.text) <> '' then
begin
combobox5.Items.assign(FldCNames);
CheckListBox1.Items.Assign(FldCnames);
speedbutton1click(Self);
end;
// for tempcount:=0 to GroupingFlds.Count-1 do
// GroupingCFlds.add(FldCNames.items[FldNames.indexof(GroupingFlds.items[tempcount])]);
Shape7.Brush.Color := clLime;
Shape2.Brush.Color := clSilver;
Shape3.Brush.Color := clSilver;
Shape4.Brush.Color := clSilver;
Shape5.Brush.Color := clSilver;
Shape6.Brush.Color := clSilver;
previewstep.Enabled := false;
selectbox.items.clear;
orderbox.items.clear;
listbox1.Items.Clear;
wherebox.Items.Clear;
NoteBook1.PageIndex := 5;
checkbox1click(Self);
nextstep.enabled := true;
laststep.enabled := false;
groupbox.Items.Clear;
groupfieldbox.items.clear;
fieldchoosebox.Items.Clear;
//checkbox1.Enabled:=false; //为了用户方便查询
//此处已经固定好了,无法修改·!!
groupingbox.items.clear;
listbox3.items.clear;
listbox2.items.clear;
end;
procedure TGQ_FQueryMain.SaveClick(Sender: TObject);
var
GQ_FSaveView: TGQ_FSaveView;
begin
Application.CreateForm(TGQ_FSaveView, GQ_FSaveView);
GQ_FSaveView.ShowModal;
GQ_FSaveView.Free;
end;
{---------------------------------NoteBook Work --------------------------------------}
{--------------------Select Page----------------------------------}
procedure TGQ_FQueryMain.WhereSelClick(Sender: TObject);
var
FNameC, FOper, FValue, Temp: string;
TempB, IsDateMonth: Boolean;
begin
TempB := True;
if ((FldNameBox.Text = '') or (OperateBox.Text = '') or (trim(operatebox.text)
= '空') or (FldValueBox.Text = '')) then
begin
MessageDlg('查询表达式有漏选项', mtInformation, [mbOk], 0);
Exit;
end;
FNameC := viewfieldnames[FldNameBox.ItemIndex];
if (trim(OperateBox.Text) = '开头是') or (trim(OperateBox.Text) = '结尾是')
or (trim(OperateBox.Text) = '包括') or (trim(OperateBox.Text) = '类似') then
FOper := ' Like ';
if trim(OperateBox.text) = '在...中' then
Foper := ' in ';
if (StringType = Strings) or (StringType = Logical) then
FValue := DealLBCE(Self);
IsDateMonth := False;
if (trim(OperateBox.Text) = '在...中') or (trim(OperateBox.Text) =
'从...到...之间') then
else if StringType = Date then
begin
try
FValue := '''' + ForMatDateTime('yyyy/mm/dd', StrToDate(FldValueBox.Text))
+ '''';
if OperateBox.Text = ' 包括 ' then
begin
IsDateMonth := True;
FValue := '''' + DealDateMonth(SelectList.Items[FldNameBox.ItemIndex]) +
'''';
end;
except FValue := DealLBCE(Self);
end;
end
else if StringType = Number then
FValue := FldValueBox.Text;
if trim(Foper) = '' then
foper := operatebox.Text;
if not IsDateMonth then
Temp := '(' + FNameC + FOper + FValue + ')'
else
Temp := '(' + FNameC + '属于' + FormatDateTime('mm',
strtoDate(FldValueBox.Text)) + '月)';
if trim(operatebox.Text) = '空' then
temp := '(' + FNamec + 'is null' + ')';
if trim(Operatebox.text) = '从...到...之间' then
temp := '(' + Fnamec + ' ' + FldValueBox.text + ')';
if trim(Operatebox.text) = '在...中' then
temp := '(' + FNameC + ' in ' + Fldvaluebox.text + ')';
whereBox.Items.Add(temp);
whereBox.ItemIndex := whereBox.Items.IndexOf(temp);
operatebox.ItemIndex := -1;
Fldvaluebox.Enabled := true;
end;
procedure TGQ_FQueryMain.AndWorkClick(Sender: TObject);
var
thefirst: boolean;
tempcount: integer;
nowpos: integer;
begin
thefirst := true;
if wherebox.SelCount + listbox1.SelCount <> 2 then
begin
// messagedlg(
messageDlg('请在列表框中选择你需要的两行进行该操作', mtInformation, [mbOK],
0);
exit;
end;
if wherebox.SelCount = 2 then
for tempcount := 0 to wherebox.Items.Count - 1 do
if wherebox.Selected[tempcount] then
if thefirst then
begin
nowpos := tempcount;
thefirst := false;
end
else
begin
listbox1.Items.Add('(' + wherebox.items[nowpos] + ' and ' +
wherebox.items[tempcount] + ')');
wherebox.Selected[nowpos] := false;
wherebox.Selected[tempcount] := false;
exit;
end;
if wherebox.SelCount = 1 then
begin
for tempcount := 0 to wherebox.Items.Count - 1 do
if wherebox.Selected[tempcount] then
begin
nowpos := tempcount;
break;
end;
for tempcount := 0 to listbox1.Items.Count - 1 do
if listbox1.Selected[tempcount] then
begin
listbox1.Items[tempcount] := ' (' + wherebox.items[nowpos] + ' and ' +
listbox1.items[tempcount] + ') ';
wherebox.Selected[nowpos] := false;
listbox1.Selected[tempcount] := false;
exit;
end;
end;
if listbox1.SelCount = 2 then
begin
for tempcount := 0 to listbox1.selcount do
if listbox1.Selected[tempcount] then
if thefirst then
begin
nowpos := tempcount;
thefirst := false;
end
else
begin
listbox1.Items[nowpos] := '(' + listbox1.Items[nowpos] + ' and ' +
listbox1.Items[tempcount] + ')';
listbox1.Selected[nowpos] := false;
listbox1.items.Delete(tempcount);
exit;
end;
end;
end;
procedure TGQ_FQueryMain.OrWorkClick(Sender: TObject);
var
thefirst: boolean;
tempcount: integer;
nowpos: integer;
begin
thefirst := true;
if wherebox.SelCount + listbox1.SelCount <> 2 then
begin
messagedlg('请在列表框中选择你需要的两行进行该操作', mtInformation, [mbOK],
0);
exit;
end;
if wherebox.SelCount = 2 then
for tempcount := 0 to wherebox.Items.Count - 1 do
if wherebox.Selected[tempcount] then
if thefirst then
begin
nowpos := tempcount;
thefirst := false;
end
else
begin
listbox1.Items.Add('(' + wherebox.items[nowpos] + ' or ' +
wherebox.items[tempcount] + ')');
wherebox.Selected[nowpos] := false;
wherebox.Selected[tempcount] := false;
exit;
end;
if wherebox.SelCount = 1 then
begin
for tempcount := 0 to wherebox.Items.Count - 1 do
if wherebox.Selected[tempcount] then
begin
nowpos := tempcount;
break;
end;
for tempcount := 0 to listbox1.Items.Count - 1 do
if listbox1.Selected[tempcount] then
begin
listbox1.Items[tempcount] := '( ' + wherebox.items[nowpos] + ' or ' +
listbox1.items[tempcount] + ' )';
wherebox.Selected[nowpos] := false;
listbox1.Selected[tempcount] := false;
exit;
end;
end;
if listbox1.SelCount = 2 then
begin
for tempcount := 0 to listbox1.selcount do
if listbox1.Selected[tempcount] then
if thefirst then
begin
nowpos := tempcount;
thefirst := false;
end
else
begin
listbox1.Items[nowpos] := '(' + listbox1.Items[nowpos] + ' or ' +
listbox1.Items[tempcount] + ')';
listbox1.Selected[nowpos] := false;
listbox1.items.Delete(tempcount);
exit;
end;
end;
end;
procedure TGQ_FQueryMain.NotWorkClick(Sender: TObject);
var
tempCount: Integer;
begin
if (listbox1.selcount + wherebox.selcount) <> 1 then
begin
messagedlg('请只选择一行进行该操作', mtInformation, [mbOK], 0);
exit;
end;
if wherebox.selcount = 1 then
for tempcount := 0 to wherebox.items.Count - 1 do
if wherebox.Selected[tempcount] then
begin
listbox1.Items.Add('(not ' + wherebox.Items[tempcount] + ')');
wherebox.Selected[tempcount] := false;
exit;
end;
if listbox1.SelCount = 1 then
for tempcount := 0 to listbox1.items.Count - 1 do
if listbox1.Selected[tempcount] then
begin
listbox1.Items[tempcount] := '(not ' + listbox1.Items[tempcount] + ')';
listbox1.Selected[tempcount] := false;
exit;
end;
end;
procedure TGQ_FQueryMain.WhereDelClick(Sender: TObject);
var
i: Integer;
begin
if (WhereBox.Items.Count = 0) and (listbox1.items.count = 0) then
Exit;
if (whereBox.SelCount + listbox1.SelCount) = 0 then
begin
messagedlg('请选中你想删除的行', mtInformation, [mbOK], 0);
exit;
end;
if (whereBox.SelCount + listbox1.SelCount) > 1 then
begin
messagedlg('一次删除一行', mtInformation, [mbOK], 0);
exit;
end;
if MessageDlg('你确定吗?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then
exit;
if wherebox.SelCount = 1 then
begin
for i := 0 to wherebox.items.count - 1 do
if wherebox.Selected[i] = true then
begin
wherebox.Items.Delete(i);
exit;
end;
end
else
for i := 0 to listbox1.items.count - 1 do
if listbox1.Selected[i] = true then
begin
listbox1.Items.Delete(i);
exit;
end;
end;
procedure TGQ_FQueryMain.ClearWorkClick(Sender: TObject);
begin
if MessageDlg('这样做你将清空你所选定的条件框,要这样吗?', mtConfirmation,
[mbYes, mbNo], 0) = mrNo then
exit;
WhereBox.Clear;
end;
procedure TGQ_FQueryMain.FldValueBoxDropDown(Sender: TObject);
var
PreText, Temp: string;
Len, tempcount: Integer;
begin
if trim(FldNameBox.Text) = '' then
Exit;
Screen.Cursor := crHourGlass;
PreText := FldValueBox.Text;
Len := Length(PreText);
FldValueBox.Clear;
if not GQ_FDataModule.OpenSql('Select * From ' + TableName) then
begin
ShowMessage('不能打开当前的信息表,查询不能继续!');
Exit;
end;
GQ_FDataModule.ADOQuery1.First;
tempcount := 0;
while (not GQ_FDataModule.ADOQuery1.Eof) and (tempcount < 50) do
begin
Temp := GQ_FDataModule.ADOQuery1.Fields[NowFldPos].AsString;
if (Copy(Temp, 1, Len) = PreText) and (Temp <> '') then
begin
if FldValueBox.Items.IndexOf(Trim(Temp)) = -1 then
begin
FldValueBox.Items.Add(Trim(Temp));
tempCount := tempcount + 1;
end;
end;
GQ_FDataModule.ADOQuery1.Next;
end;
Screen.Cursor := crDefault;
end;
{-----------------------Select Field Page------------------------}
procedure TGQ_FQueryMain.SelectFldClick(Sender: TObject);
var
i: integer;
begin
if SelectList.ItemIndex = -1 then
Exit;
for i := 0 to SelectList.Items.Count - 1 do
if SelectList.Selected[i] then
if SelectBox.Items.IndexOf(SelectList.Items[i]) = -1 then
SelectBox.Items.Add(SelectList.Items[i]);
end;
procedure TGQ_FQueryMain.SelectListDblClick(Sender: TObject);
begin
if SelectList.ItemIndex = -1 then
Exit;
if SelectBox.Items.IndexOf(SelectList.Items[SelectList.ItemIndex]) = -1 then
SelectBox.Items.Add(SelectList.Items[SelectList.ItemIndex]);
end;
procedure TGQ_FQueryMain.AllSelFldClick(Sender: TObject);
begin
if SelectList.Items.Count = 0 then
Exit;
SelectBox.Items.Assign(SelectList.Items);
end;
procedure TGQ_FQueryMain.AllDelFldClick(Sender: TObject);
begin
if SelectBox.Items.Count = 0 then
Exit;
SelectBox.Items.Clear;
end;
procedure TGQ_FQueryMain.DeleteFldClick(Sender: TObject);
var
i: integer;
begin
if SelectBox.ItemIndex = -1 then
Exit;
for i := SelectBox.Items.Count - 1 downto 0 do //在删除后列表项目减少,
if SelectBox.Selected[i] then //所以要用"downto"结构
begin //保证不会重复删除某一位置
SelectBox.Items.Delete(i);
end;
end;
procedure TGQ_FQueryMain.FldNameBoxClick(Sender: TObject);
begin
if FldNameBox.ItemIndex = -1 then
Exit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -