unit ukingfilter;
inte***ce
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, stdctrls, extctrls, db;
type
tcolparams = record
fieldname: string;
title: string;
end;
tformsetcolor = class(tform)
lbl1: tlabel;
lbl2: tlabel;
lbl3: tlabel;
cbb1: tcombobox;
cbb2: tcombobox;
edt1: tedit;
cbb3: tcombobox;
lst1: tmemo;
grp1: tgroupbox;
btn1: tbutton;
btn2: tbutton;
btn3: tbutton;
btn4: tbutton;
procedure btn4click(sender: tobject);
procedure btn3click(sender: tobject);
procedure btn2click(sender: tobject);
procedure btn1click(sender: tobject);
procedure formclose(sender: tobject; var action: tcloseaction);
procedure formdestroy(sender: tobject);
private
fdataset: tdataset;
colarray: array of tcolparams;
procedure fillfieldcombx;
procedure ok;
procedure add;
procedure clear;
function convertstr(astr: string): string;
public
end;
varformsetcolor: tformsetcolor;
procedure showfilterform(adataset:tdataset);
implementation
procedure showfilterform(adataset:tdataset);
begin
if adataset.isempty then exit;
formsetcolor:=tformsetcolor.create(nil);
tryformsetcolor.fdataset:=adataset;
formsetcolor.fdataset.filtered:=false;
formsetcolor.fillfieldcombx;
formsetcolor.showmodal;
finally
freeandnil(formsetcolor);
end;
end;
procedure tformsetcolor.fillfieldcombx;
vari: integer;
begin
with fdataset do
begin
setlength(colarray,fieldcount);
for i:=0 to fieldcount-1 do
begin
if fields[i].visible then
begin
colarray[i].fieldname:=fields[i].fieldname;
colarray[i].title:=fields[i].displaylabel;
cbb1.items.add(fields[i].displaylabel);
end;
end;
end;
cbb1.itemindex:=0;
end;
procedure tformsetcolor.formclose(sender: tobject; var action: tcloseaction);
begin
action:=cafree;
end;
procedure tformsetcolor.formdestroy(sender: tobject);
begin
formsetcolor:=nil;
end;
procedure tformsetcolor.add;
vars:string;
function getfieldname:string;
vari:integer;
begin
for i:=low(colarray) to high(colarray) do
if colarray[i].title=cbb1.text then
result:=colarray[i].fieldname;
end;
begin
if (trim(cbb1.text)='') or (trim(cbb2.text)='') then exit;
if (cbb2.text<>'包含') and (edt1.text='') then exit;
if (cbb2.text<>'不包含') and (edt1.text='') then exit;
s:=getfieldname+' '+convertstr(cbb2.text);
if lst1.lines.count<=0 then
begin
if (cbb2.text<>'包含') and (cbb2.text<>'不包含') then
lst1.lines.add(s+' '+quotedstr(edt1.text))
else lst1.lines.add(s+' '+quotedstr('%'+edt1.text+'%'));
end else
begin
if cbb3.text='' then exit;
if (cbb2.text<>'包含') and (cbb2.text<>'不包含') then
lst1.lines.add(cbb3.text+' '+s+' '+quotedstr(edt1.text))
else lst1.lines.add(cbb3.text+' '+s+' '+quotedstr('%'+edt1.text+'%'));
end;
end;
procedure tformsetcolor.ok;
begin
if lst1.lines.count=0 then
if trim(edt1.text)='' then exit else add;
fdataset.filtered:=true;
fdataset.filter:=lst1.lines.text;
self.close;
end;
function tformsetcolor.convertstr(astr: string): string;
begin
if astr='包含' then result:='like';
if astr='等於' then result:='=';
if astr='不等於' then result:='<>';
if astr='大於' then result:='>';
if astr='小於' then result:='<';
if astr='大於或等於' then result:='>=';
if astr='小於或等於' then result:='<=';
if astr='不包含' then result:='not like';
end;
procedure tformsetcolor.btn4click(sender: tobject);
begin
close;
end;
procedure tformsetcolor.btn3click(sender: tobject);
begin
ok;end;
procedure tformsetcolor.btn2click(sender: tobject);
begin
clear;
end;
procedure tformsetcolor.btn1click(sender: tobject);
begin
add;
end;
end.
VBA獲取篩選後記錄數量
excel的篩選是乙個常用功能,即使是入門不久的小白也會使用。但是在vba處理資料時,如果工作表中的資料表使用了篩選,那麼使用vba如何知道到底有多少行處於顯示狀態呢?如下圖資料表中有12行資料 不包括標題行 經過篩選後,在狀態條左側可以輕鬆地知道 有4條記錄符合篩選規則。下面看看如何使用 獲取篩選...
C 通用類 日誌記錄類
using system using system.collections.generic using system.io using system.linq using system.text using system.threading.tasks using system.web namesp...
C 通用類 日誌記錄類
using system using system.collections.generic using system.io using system.linq using system.text using system.threading.tasks using system.web namesp...