📄 selectlist.pas
字号:
unit SelectList;
interface
uses
SysUtils, Classes, windows,dialogs,ExtCtrls,forms,Graphics,StdCtrls,
Controls,SelectType,ComCtrls,db,StrUtils,remotedataset,tools,DataSelect,
Buttons;
type
TSelectlist = class(TPanel)
private
FSQL:TStrings;
FSelectList:Tstringlist;
FRemoteDataSet:TRemoteDataSet;
FDataSelect:TDataSelect;
//ShowOver:boolean;
//自定义条件查询对照表
FCustomList:Tstrings;
FCalList:Tstrings;
//FPageId:string;
{
[Cus1]
yg_code=yg_code
字段=参数
}
procedure Add(FieldName:string;FieldText:string;DataSelectText:string;
SelectType:integer;IFLike:integer);
procedure setsql(value:Tstrings);
procedure setcus(value:Tstrings);
procedure setcal(value:Tstrings);
procedure setdataset(value:TRemoteDataSet);
procedure setdataselect(value:TDataSelect);
//procedure setpageid(value:string);
protected
{ Protected declarations }
public
{ Public declarations }
destructor Destroy; override;
constructor Create(AOwner: TComponent); override;
procedure ShowFieldBar(FieldList:Tstrings);
procedure ExecSQL;
procedure DeleteAll;
function GetValueFromParams(paramsname:string;paramsno:integer):variant;
published
property SQL:Tstrings read FSQL write setsql;
property CustomList:Tstrings read FCustomList write setcus;
property CalList:Tstrings read FCalList write setcal;
property RemoteDataSet:TRemoteDataSet read FRemoteDataSet write setdataset;
property DataSelect:TDataSelect read FDataSelect write setdataselect;
//property PageId:string read FPageId write setpageid;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DbAnyWhere', [TSelectList]);
end;
constructor TSelectList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FSelectList:=Tstringlist.Create;
FSQL:=TStringList.Create;
Fcustomlist:=Tstringlist.Create;
Fcallist:=Tstringlist.Create;
//ShowOver:=false;
{Yg_code=1001员工编码^yg_code
yg_name=1001员工名称^test
yg_sex=0001员工性别^sex
yg_zw=1001员工职务
yg_birth=0109员工生日
yg_phone=1001联系电话
yg_address=1001家庭住址
yg_ifczy=0205是否操作员
yg_email=1001电子邮件
yg_memo=1001备注}
//等号后的4位数字:
//第一位:表示是否要显示like 0:无like,1:有like
//第二位:0:文本框 1:日期选择框 2: 检查框
//第3、4位:字段类型
{在自定义语句的时候的标志
&代表 and
$代表 where
原理是:有[custom]则有符号所代替内容,无[custom]也无符号内容}
end;
destructor TSelectList.Destroy;
begin
inherited Destroy;
FreeandNil(FSelectList);
FreeAndNil(FSQL);
FreeAndNil(Fcustomlist);
FreeAndNil(Fcallist);
end;
{procedure TSelectList.setpageid(value:string);
begin
FPageId:=value;
end; }
function TSelectList.GetValueFromParams(paramsname:string;paramsno:integer):variant;
begin
if copy(self.FSelectList.Values[paramsname],2,1)='0' then
begin
if paramsno=1 then
result:=TFieldPanel(FindComponent(paramsname)).FLuruEdit1.Text
else if paramsno=2 then
result:=TFieldPanel(FindComponent(paramsname)).FLuruEdit2.Text;
end;
if copy(self.FSelectList.Values[paramsname],2,1)='1' then
begin
if paramsno=1 then
result:=TFieldPanel(FindComponent(paramsname)).FLuruDateTime1.DateTime
else if paramsno=2 then
result:=TFieldPanel(FindComponent(paramsname)).FLuruDateTime2.DateTime;
end;
if copy(self.FSelectList.Values[paramsname],2,1)='2' then
result:=TFieldPanel(FindComponent(paramsname)).FLuruCheck.Checked;
end;
procedure TSelectList.Add(FieldName:string;FieldText:string;DataSelectText:string;
SelectType:integer;IFLike:integer);
begin
if selecttype=0 then
begin
TFieldPanel.Create(self).Name:=FieldName;
TFieldPanel(FindComponent(Fieldname)).Parent:=self;
TFieldPanel(FindComponent(Fieldname)).Align:=altop;
TFieldPanel(FindComponent(Fieldname)).FSelectCheck.Caption:=FieldText;
TFieldPanel(FindComponent(Fieldname)).FLuruEdit1.Visible:=true;
TFieldPanel(FindComponent(Fieldname)).FLuruEdit1.Width:=230;
TFieldPanel(FindComponent(Fieldname)).FLuruEdit2.Width:=230;
if length(trim(dataselecttext))<>0 then
begin
TFieldPanel(FindComponent(Fieldname)).Fbutton1.Visible:=true;
TFieldPanel(FindComponent(Fieldname)).Fbutton2.Visible:=true;
//TFieldPanel(FindComponent(Fieldname)).FDS.DataItems:=self.FDataSelect.DataItems;
TFieldPanel(FindComponent(Fieldname)).FDS:=self.FDataSelect;
TFieldPanel(FindComponent(Fieldname)).SelectTableName:=dataselecttext;
TFieldPanel(FindComponent(Fieldname)).FLuruEdit1.Width:=194;
TFieldPanel(FindComponent(Fieldname)).FLuruEdit2.Width:=194;
end;
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('=');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('>');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('<');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('>=');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('<=');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('<>');
if iflike=1 then
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('like');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('between');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.Style:=csDropDownList;
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.ItemIndex:=0;
end;
if selecttype=1 then
begin
TFieldPanel.Create(self).Name:=FieldName;
TFieldPanel(FindComponent(Fieldname)).Parent:=self;
TFieldPanel(FindComponent(Fieldname)).Align:=altop;
TFieldPanel(FindComponent(Fieldname)).FSelectCheck.Caption:=FieldText;
TFieldPanel(FindComponent(Fieldname)).FLuruDateTime1.DateTime:=now;
TFieldPanel(FindComponent(Fieldname)).FLuruDateTime2.DateTime:=now;
TFieldPanel(FindComponent(Fieldname)).FLuruDateTime1.Time:=strtotime('00:00:00');
TFieldPanel(FindComponent(Fieldname)).FLuruDateTime2.Time:=strtotime('00:00:00');
TFieldPanel(FindComponent(Fieldname)).FLuruDateTime1.DateFormat:=dfLong;
TFieldPanel(FindComponent(Fieldname)).FLuruDateTime2.DateFormat:=dfLong;
TFieldPanel(FindComponent(Fieldname)).FLuruDateTime1.Visible:=true;
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('=');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('>');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('<');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('>=');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('<=');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('<>');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('between');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.Style:=csDropDownList;
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.ItemIndex:=0;
end;
if selecttype=2 then
begin
TFieldPanel.Create(self).Name:=FieldName;
TFieldPanel(FindComponent(Fieldname)).Parent:=self;
TFieldPanel(FindComponent(Fieldname)).Align:=altop;
TFieldPanel(FindComponent(Fieldname)).FSelectCheck.Caption:=FieldText;
TFieldPanel(FindComponent(Fieldname)).FLuruCheck.Caption:=fieldtext;
TFieldPanel(FindComponent(Fieldname)).FLuruCheck.Visible:=true;
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('=');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.items.add('<>');
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.Style:=csDropDownList;
TFieldPanel(FindComponent(Fieldname)).FCalComboBox.ItemIndex:=0;
end;
end;
procedure TSelectList.deleteall;
var
i:integer;
begin
for i:=self.ComponentCount-1 downto 0 do
begin
if self.Components[i] is Tfieldpanel then self.Components[i].Destroy;
end;
end;
procedure TSelectList.ShowFieldBar(FieldList:TStrings);
var
i,j:integer;
FieldName:string;
FieldText:string;
DataSelectText:string;
cus:boolean;
begin
//showmessage(FieldList.Text);
FSelectList.Assign(FieldList);
FieldName:='';
FieldText:='';
DataSelectText:='';
if self.FCustomList.Count>0 then cus:=true else
begin
self.FCustomList.Add('[Custom]');
cus:=false;
end;
for i:=FSelectList.Count-1 downto 0 do
begin
FieldName:=FselectList.Names[i];
if not cus then self.FCustomList.Add(fieldname+'='+fieldname);
if pos('^',FSelectList.ValueFromIndex[i])>0 then
begin
FieldText:=Copy(FSelectList.ValueFromIndex[i],5,pos('^',FSelectList.ValueFromIndex[i])-5);
DataSelectText:=copy(FSelectList.ValueFromIndex[i],pos('^',FSelectList.ValueFromIndex[i])+1,
length(FSelectList.ValueFromIndex[i])-pos('^',FSelectList.ValueFromIndex[i]));
end else
begin
FieldText:=Copy(FSelectList.ValueFromIndex[i],5,length(FSelectList.ValueFromIndex[i])-4);
DataSelectText:='';
end;
if FindComponent(FselectList.Names[i])=nil then
self.Add(fieldname,fieldtext,dataselecttext,strtoint(copy(Fselectlist.ValueFromIndex[i],2,1)),
strtoint(copy(Fselectlist.ValueFromIndex[i],1,1)));
end;
for j:=0 to self.FCalList.Count-1 do
begin
TFieldPanel(FindComponent(self.FCalList.Names[j])).FCalComboBox.ItemIndex:=
TFieldPanel(FindComponent(self.FCalList.Names[j])).FCalComboBox.Items.IndexOf(
self.FCalList.ValueFromIndex[j]);
TFieldPanel(FindComponent(self.FCalList.Names[j])).FCalComboBox.OnChange(self);
TFieldPanel(FindComponent(self.FCalList.Names[j])).FSelectCheck.Checked:=true;
TFieldPanel(FindComponent(self.FCalList.Names[j])).FSelectCheck.Enabled:=false;
TFieldPanel(FindComponent(self.FCalList.Names[j])).FCalComboBox.Enabled:=false;
end;
//showmessage(self.FCustomList.Text);
end;
procedure TSelectList.setsql(value:Tstrings);
begin
FSQL.Assign(value);
end;
procedure TSelectList.setcus(value:Tstrings);
begin
FCustomList.Assign(value);
end;
procedure TSelectList.setcal(value:Tstrings);
begin
FCalList.Assign(value);
end;
procedure TSelectList.setdataset(value:TRemoteDataSet);
begin
FRemoteDataSet:=Value;
end;
procedure TSelectList.ExecSQL;
var
i,j:integer;
str,str1,sql,temp_str:string;
tsn,ssn:integer;
//分析sql
pos1,pos2:integer;
cuslist:tstringlist;
cur_str,cur_str1:string;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -