码农的笔记

Delphi虽好,但已不流行; 博客真好,可以做笔记

博客园 首页 新随笔 联系 订阅 管理

---------------做下笔记

这个算不上真的项目代码,但也十分接近了,但这个是核心代码,项目代码只是尽可能往多共用(继承)少重复考虑、尽可能把方法写小点,来提高程序的可读性!

----------------------------------------------------------------

如果有人想写类似的功能,又没有太好的思路,请结合 【DBGrid的字体颜色用户自定义】,一共三篇;只提供思路,个人能力有限,写的比较乱;

只是为了实现用户自定义DBGrid的背景颜色和字体,把用户设定的条件(比如:(ID=10 OR ID<8 AND ID=100)  OR(NAME<>'' AND NAME >'AA') AND (DATETIME<'2021-03-09 14:20:33'))读取出来,

把条件读取出来,然后再解析,这个条件怎么解析:这里设置了三个栏位的条件,栏位之间的条件(ID...)  OR(NAME...) AND (DATETIME...'),栏位内部的条件(ID=10 OR ID<8 AND ID=100),

先计算栏位内部的条件:需要先拆分,拆分好了后,需要进行逻辑判断,分别判断ID=10 , ID<8 , ID=100    这个的真假值,不要以为真的就这样了,(ID=10 OR ID<8 AND ID=100)   AND的运算级高过OR,描述的有点看不懂了;

..........不多说了,上代码...........

本人技术有限,只想通过简单而又繁杂的代码达到自己的目的,本人只提供思路,算法多,会用才是王道;

 

使用了superobject(JSON),第三方控件用到了Ehlib,其他就没啥的感觉!

项目代码不会提供,谢谢!

---------------------------贴上部分代码-----------------

----------------1------开始---------------------------------------------

procedure TFrmSysPubModle.DBGridEh_PubAdvDrawDataCell(Sender: TCustomDBGridEh;
Cell, AreaCell: TGridCoord; Column: TColumnEh; const ARect: TRect;
var Params: TColCellParamsEh; var Processed: Boolean);
var
vGridColorSetFlag,vGridFontSetFlag:Integer;
vSectionName,vFilterFieldAndValue,vFilterTerms,vGridSetFieldName:string;

Vtest,Vtest01,VtestSub,VtestSub01:string;
Bool_FieldOut,Bool_FieldIn,vResultBool:Boolean;
pos_i,i,j,m,Pos_or,Pos_and,Pos_CurrOrAnd:Integer;
ANDOR_FieldsOUT:array[0..150] of Integer ; //OR为0 ,AND为1 //字段之间的 //(COMM<''999'' AND COMM=''999'' OR COMM<''999'') AND (Test_boolean=1 OR Test_boolean<0)
ANDOR_FieldsIN:array[0..150,0..9] of Integer ; //OR为0 ,AND为1 //单个字段的 //(COMM<''999'' AND COMM=''999'' OR COMM<''999'')
Where_FieldsOUT:array[0..151] of String ;
Where_FieldsIN:array[0..151,0..10] of String ;
vTerms:string;
TermsArray:array of string;
ArrayHaveValueCount:Integer; // ') OR (' 和 ') AND ('的总数量
TermsPos:Integer;//当前应该用哪个符号
vKeyValue,vKey,vValue:String;
FieldWhereBoolOut_TFStr,FieldWhereBoolIn_TFStr:string;
FieldWhereBoolOut_ANDORStr,FieldWhereBoolIn_ANDORStr:string;

vFont:TFont;
vFontIjson:ISuperObject;
vFontStyleStrs:string;
begin
inherited;
if not Processed then
begin
if FSectionNames.Count >0 then //当有自定义设置Dbgrid的颜色和字体时
begin
//暂时测试整行的
for m:=0 to FSectionNames.Count-1 do
begin
vResultBool:=False;
vSectionName:=FSectionNames.Strings[m];
vGridSetFieldName:='';
vGridColorSetFlag:=FFormIniFile.ReadInteger(vSectionName,'GridColorSetFlag',0);
vGridFontSetFlag:=FFormIniFile.ReadInteger(vSectionName,'GridFontSetFlag',0);
if (vGridColorSetFlag>0)or(vGridFontSetFlag>0) then //行或者单元格要设置
begin
vFilterFieldAndValue:=FFormIniFile.ReadString(vSectionName,'FilterFieldAndValue',''); ;
vFilterTerms:=FFormIniFile.ReadString(vSectionName,'FilterTerms','');

vTerms:=vFilterTerms;
Vtest:= vFilterFieldAndValue;
ArrayHaveValueCount:=-1;
Vtest:=StringReplace(Vtest,'''''','',[rfReplaceAll]);
if Vtest='' then
Exit;
SetLength(TermsArray,1600);
for i:=Low(TermsArray) to High(TermsArray) do
begin
pos_i:=Pos(',',vTerms);
TermsArray[i]:=Copy(vTerms,1,pos_i-1);
Delete(vTerms,1,pos_i);
end;
for i:=0 to 150 do
begin
ANDOR_FieldsOUT[i]:=-1;
for j:=0 to 9 do
begin
ANDOR_FieldsIN[i][j]:=-1;
end;
end;

for i:=0 to 151 do
begin
Where_FieldsOUT[i]:='';
for j:=0 to 10 do
begin
Where_FieldsIN[i][j]:='';
end;
end;


//ANDOR_FieldsOUT
while Vtest<>'' do
begin
//Pos_or,Pos_and,Pos_CurrOrAnd
inc(ArrayHaveValueCount);
if Pos(') AND (',Vtest)>0 then
begin
pos_i:=Pos(') AND (',Vtest);
Vtest01:=Copy(Vtest,1,pos_i);
Vtest:=Copy(Vtest,pos_i+6,20000);
VtestSub:=Vtest01;
if Pos(') OR (',VtestSub)>0 then
begin
while VtestSub<>'' do
begin
pos_i:=Pos(') OR (',VtestSub);
if pos_i>0 then
begin
VtestSub01:=Copy(VtestSub,1,pos_i);
VtestSub:=Copy(VtestSub,pos_i+5,20000);
ANDOR_FieldsOUT[ArrayHaveValueCount]:=0;
Where_FieldsOUT[ArrayHaveValueCount]:=VtestSub01;
Inc(ArrayHaveValueCount);
end
else
begin
Vtest01:=VtestSub;
ANDOR_FieldsOUT[ArrayHaveValueCount]:=1;
VtestSub:='';//计算到最后要把这个置为空
end;
end;
end
else
begin
ANDOR_FieldsOUT[ArrayHaveValueCount]:=1;
end;
end
else
if Pos(') OR (',Vtest)>0 then
begin
pos_i:=Pos(') OR (',Vtest);
Vtest01:=Copy(Vtest,1,pos_i);
Vtest:=Copy(Vtest,pos_i+5,20000);
ANDOR_FieldsOUT[ArrayHaveValueCount]:=0;
end
else
begin
Vtest01:=Vtest;
Vtest:='';//计算到最后要把这个置为空
end;
Where_FieldsOUT[ArrayHaveValueCount]:=Vtest01;
end;

//ANDOR_FieldsIN
for i:=Low( Where_FieldsOUT) to High(Where_FieldsOUT) do
begin
Vtest:=Where_FieldsOUT[i];
if Vtest='' then
Break;
Delete(Vtest,1,1);//删除左括号
Vtest:=Copy(Vtest,1,Length(Vtest)-1); //删除右括号
ArrayHaveValueCount:=-1;
while Vtest<>'' do
begin
inc(ArrayHaveValueCount);
if Pos(' AND ',Vtest)>0 then
begin
pos_i:=Pos(' AND ',Vtest);
Vtest01:=Copy(Vtest,1,pos_i);
Vtest:=Copy(Vtest,pos_i+5,20000);
VtestSub:=Vtest01;
if Pos(' OR ',VtestSub)>0 then
begin
while VtestSub<>'' do
begin
pos_i:=Pos(' OR ',VtestSub);
if pos_i>0 then
begin
VtestSub01:=Copy(VtestSub,1,pos_i);
VtestSub:=Copy(VtestSub,pos_i+4,20000);
ANDOR_FieldsIN[i][ArrayHaveValueCount]:=0;
Where_FieldsIN[i][ArrayHaveValueCount]:=VtestSub01;
Inc(ArrayHaveValueCount);
end
else
begin
Vtest01:=VtestSub;
ANDOR_FieldsIN[i][ArrayHaveValueCount]:=1;
VtestSub:='';//计算到最后要把这个置为空
end;
end;
end
else
begin
ANDOR_FieldsIN[i][ArrayHaveValueCount]:=1;
end;
end
else
if Pos(' OR ',Vtest)>0 then
begin
pos_i:=Pos(' OR ',Vtest);
Vtest01:=Copy(Vtest,1,pos_i);
Vtest:=Copy(Vtest,pos_i+4,20000);
ANDOR_FieldsIN[i][ArrayHaveValueCount]:=0;
end
else
begin
Vtest01:=Vtest;
Vtest:='';//计算到最后要把这个置为空
end;
Where_FieldsIN[i][ArrayHaveValueCount]:=Vtest01;
end;
end;
end
else
Break;

/////////
//Memo1.Clear;
TermsPos:=-1;
FieldWhereBoolOut_TFStr:='';
FieldWhereBoolOut_ANDORStr:='';
for i:=0 to 151 do //栏位数
begin
if Where_FieldsOut[i]='' then
Break;
Bool_FieldIn:=True;//初始化时为真
FieldWhereBoolIn_TFStr:='';
FieldWhereBoolIn_ANDORStr:='';
for j:=0 to 10 do //单个栏位的逻辑运算个数
begin
if Where_FieldsIN[i][j]='' then
Break;
Inc(TermsPos);
pos_i:=pos('=',Where_FieldsIN[i][j]);
vKey:=Copy(Where_FieldsIN[i][j],1,pos_i-1);
vValue:=Copy(Where_FieldsIN[i][j],pos_i+1,300);
if DBGridEh_Pub.DataSource.DataSet.FindField(vKey)<>nil then
begin
if j>0 then
FieldWhereBoolIn_ANDORStr:=FieldWhereBoolIn_ANDORStr+Inttostr(ANDOR_FieldsIN[i][j-1]);

if (TermsArray[TermsPos]='ISNULL') or (TermsArray[TermsPos]='ISNOTNULL') then
begin
if TermsArray[TermsPos]='ISNULL' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsString='' then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else //ISNOTNULL
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsString<>'' then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;
end
else if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).DataType = ftBoolean then
begin
if Pos('LIKE',TermsArray[TermsPos] )>0 then
begin
if TermsArray[TermsPos]='NOTLIKE' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean<>StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean=StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;
end
else if TermsArray[TermsPos]='=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean=StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean<StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean<=StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean>StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean>=StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<>' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsBoolean<>StrToBool(vValue) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;

end
else if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).DataType in[ftSmallint,ftInteger,ftWord,
ftLongWord, ftShortint, ftByte, ftExtended,ftFloat, ftCurrency, ftBCD, ftDate, ftDateTime, //, ftTime
ftLargeint,ftByte] then
begin
if Pos('LIKE',TermsArray[TermsPos] )>0 then
begin
if TermsArray[TermsPos]='NOTLIKE' then
begin
if Pos(vValue,DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring)=0 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='LIKE' then
begin
if Pos(vValue,DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring)>0 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='LLIKE' then
begin
if Copy(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring,1,Length(vValue))=vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='RLIKE' then
begin
if Copy(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring,Length(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring)-Length(vValue)+1,Length(vValue))=vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;
end;

if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).DataType in[ftByte,ftSmallint,ftInteger,ftWord,
ftLongWord, ftShortint,ftLargeint] then
begin

if TermsArray[TermsPos]='=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsInteger=StrToInt64Def(vValue,0) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsInteger<StrToInt64Def(vValue,0) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsInteger<=StrToInt64Def(vValue,0) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsInteger>StrToInt64Def(vValue,0) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsInteger>=StrToInt64Def(vValue,0) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<>' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsInteger<>StrToInt64Def(vValue,0) then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;
end
else if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).DataType in [ftFloat, ftCurrency, ftBCD,ftDate, ftDateTime] then
begin
if TermsArray[TermsPos]='=' then
begin
//LessThanValue = -1;
//EqualsValue = 0;
//GreaterThanValue = 1;
if CompareValue(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsFloat,StrToFloatDef(vValue,0.0))=0 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<' then
begin
if CompareValue(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsFloat,StrToFloatDef(vValue,0.0))=-1 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<=' then
begin
if CompareValue(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsFloat,StrToFloatDef(vValue,0.0))<1 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>' then
begin
if CompareValue(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsFloat,StrToFloatDef(vValue,0.0))=1 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>=' then
begin
if CompareValue(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsFloat,StrToFloatDef(vValue,0.0))>-1 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<>' then
begin
if CompareValue(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).AsFloat,StrToFloatDef(vValue,0.0))<>0 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;
end;
end
else
begin
//再用了一次LIKE,先不优化,赶时间
if Pos('LIKE',TermsArray[TermsPos] )>0 then
begin
if TermsArray[TermsPos]='NOTLIKE' then
begin
if Pos(vValue,DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring)=0 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='LIKE' then
begin
if Pos(vValue,DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring)>0 then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='LLIKE' then
begin
if Copy(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring,1,Length(vValue))=vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='RLIKE' then
begin
if Copy(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring,Length(DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring)-Length(vValue)+1,Length(vValue))=vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;
end
else if TermsArray[TermsPos]='=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring=vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring<vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring<=vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring>vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='>=' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring>=vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end
else if TermsArray[TermsPos]='<>' then
begin
if DBGridEh_Pub.DataSource.DataSet.FieldByName(vKey).Asstring<>vValue then
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'1'
else
FieldWhereBoolIn_TFStr:=FieldWhereBoolIn_TFStr+'0';
end;
end;
end;
end;
//Memo1.Lines.Add('ANDOR:'+FieldWhereBoolIn_ANDORStr+' WhereValue:'+FieldWhereBoolIn_TFStr);
if i=0 then
begin
if GetWhereANDORBool(FieldWhereBoolIn_ANDORStr,FieldWhereBoolIn_TFStr) then
FieldWhereBoolOut_TFStr:=FieldWhereBoolOut_TFStr+'1'
else
FieldWhereBoolOut_TFStr:=FieldWhereBoolOut_TFStr+'0';
end
else
begin
FieldWhereBoolOut_ANDORStr:=FieldWhereBoolOut_ANDORStr+Inttostr(ANDOR_FieldsOUT[i-1]);
if GetWhereANDORBool(FieldWhereBoolIn_ANDORStr,FieldWhereBoolIn_TFStr) then
FieldWhereBoolOut_TFStr:=FieldWhereBoolOut_TFStr+'1'
else
FieldWhereBoolOut_TFStr:=FieldWhereBoolOut_TFStr+'0';
end;
end;
////////////
vResultBool:= GetWhereANDORBool(FieldWhereBoolOut_ANDORStr,FieldWhereBoolOut_TFStr);
if (vGridColorSetFlag>0) or (vGridFontSetFlag>0 ) then
begin
vGridSetFieldName:=FFormIniFile.ReadString(vSectionName,'GridSetFieldName','');
if vGridSetFieldName<>'' then
vGridSetFieldName:=Copy(vGridSetFieldName,1,Pos('==',vGridSetFieldName)-1);
if vGridColorSetFlag>0 then //颜色设置 ,0就是不设置,1表单元格颜色,2表整行颜色
begin
if vResultBool then
begin
if vGridColorSetFlag=1 then //单元格颜色
begin
//if DBGridEh_Pub.FieldColumns[vGridSetFieldName]<>nil then
if Column.FieldName = vGridSetFieldName then
Params.Background :=FFormIniFile.ReadInteger(vSectionName,'GridColorSet',clWindow);
end
else if vGridColorSetFlag=2 then //行颜色
Params.Background :=FFormIniFile.ReadInteger(vSectionName,'GridColorSet',clWindow);
end;
end;
if vGridFontSetFlag>0 then //字体设置 ,0就是不设置,1表单元格,2 表整行
begin
vFontIjson:=superobject.so(FFormIniFile.ReadString(vSectionName,'GridFontSet','{}'));
try
vFont:=TFont.Create; //有时间这个可以想下,怎么优化
vFont.Charset:=DEFAULT_CHARSET;
//GridFontSet={"Size":11,"Name":"Tahoma","Style":"fsBold,","Color":-16777208}
vFont.Size:=vFontIjson.I['Size'];
vFont.Name:=vFontIjson.S['Name'];
vFont.Color:=vFontIjson.I['Color'];
vFontStyleStrs:=vFontIjson.S['Style'];
if vFontStyleStrs<>'' then
begin
vFontStyleStrs:=','+vFontStyleStrs;
if Pos(',fsBold,',vFontStyleStrs)>0 then
vFont.Style:=vFont.Style+[fsBold] ;
if Pos(',fsItalic,',vFontStyleStrs)>0 then
vFont.Style:=vFont.Style+[fsItalic] ;
if Pos(',fsUnderline,',vFontStyleStrs)>0 then
vFont.Style:=vFont.Style+[fsUnderline] ;
if Pos(',fsStrikeOut,',vFontStyleStrs)>0 then
vFont.Style:=vFont.Style+[fsStrikeOut] ;
end;
if vResultBool then
begin
if vGridFontSetFlag=1 then //单元格字体
begin
if Column.FieldName = vGridSetFieldName then
begin
//Params.Font:=vFont;
Params.Font.Size:=vFont.Size;
Params.Font.Name:=vFont.Name;
Params.Font.Color:=vFont.Color;
Params.Font.Style:=vFont.Style;
end;

end
else if vGridFontSetFlag=2 then //行字体
begin
//Params.Font:=vFont; //不能这样写
Params.Font.Size:=vFont.Size;
Params.Font.Name:=vFont.Name;
Params.Font.Color:=vFont.Color;
Params.Font.Style:=vFont.Style;
end;
end;
finally
FreeAndNil(vFont);
end;
end;
end;

 

end;
end;
end;

end;

 

---------1------结束----------------------------------------------

 

-----------2------开始--------------------------------

function TFrmSysPubModle.GetWhereANDORBool(WhereANDORStr,
WhereTFStr: string): Boolean;
var
vValueString,ANDORString:string;
ANDORS,vStringValues:array of Integer;
ANDORCount,i:Integer;
TF_AND,TF_OR,TF_ANDOR,TF_ANDORCurr,TF_ANDORNext:Integer;//0和1代表的是False和True
ANDORCurr,ANDORNext:Integer;//0和1代表的是OR和AND//ANDORPrevious
begin
Result:=False;
if WhereTFStr='' then
Exit;

if (WhereANDORStr='') then
begin
Result:=WhereTFStr='1';
Exit;
end;
vValueString:=WhereTFStr;
ANDORString:=WhereANDORStr ;

ANDORCount:=Length(ANDORString);
SetLength(ANDORS,ANDORCount);
SetLength(vStringValues,ANDORCount+1);
for i:=0 to ANDORCount-1 do
begin
ANDORS[i]:=StrToInt(ANDORString[i+1]);
vStringValues[i]:=StrToInt(vValueString[i+1]);
end;
//vStringValues元素比 ANDORS多一个
vStringValues[ANDORCount]:=StrToInt(vValueString[ANDORCount+1]);

if ANDORCount<2 then //只有一个AND或者OR的时候
begin
if ANDORS[0]=1 then
begin
TF_ANDOR:=vStringValues[0] and vStringValues[1];
end
else //当前是OR
begin
TF_ANDOR:=vStringValues[0] or vStringValues[1]
end;
Result:=TF_ANDOR=1;
Exit;
end;
TF_AND:=-1;
TF_OR:=-1;
TF_ANDOR:=1;
TF_ANDORCurr:=-1;
TF_ANDORNext:=-1;
ANDORCurr:=-1;
ANDORNext:=-1;
for i:=0 to ANDORCount-1 do //ANDORS循环
begin
ANDORCurr:=ANDORS[i]; //当前操作的ANDOR
if i=0 then
begin
ANDORNext:=ANDORS[i+1];
if ANDORCurr=1 then
begin
TF_ANDOR:=vStringValues[i] and vStringValues[i+1];
end
else //当前是OR
begin
if ANDORCurr=ANDORNext then //下一个也是OR
begin
TF_ANDOR:=vStringValues[i] or vStringValues[i+1];
end
else//下一个是AND
begin
TF_OR:=vStringValues[i];
end;
end;
end
else if i<>ANDORCount-1 then //ANDORCurr不是最后一个
begin
ANDORNext:=ANDORS[i+1];
TF_ANDORCurr:=vStringValues[i];
TF_ANDORNext:=vStringValues[i+1];
if ANDORCurr=ANDORNext then
begin
if ANDORCurr=1 then //当前操作的是AND
begin
if TF_OR>-1 then //保存真假值
begin
if TF_AND>-1 then//有值了
begin
TF_AND:= TF_AND and TF_ANDORNext;
end
else
begin
TF_AND:=TF_ANDORCurr and TF_ANDORNext;
end;
end
else
begin
TF_ANDOR:=TF_ANDOR and TF_ANDORNext;
end;
end
else
begin
TF_ANDOR:=TF_ANDOR or TF_ANDORNext;
end;
end
else
begin
if ANDORCurr=1 then //当前是AND
begin
if TF_OR>-1 then //上一个有保存
begin
//if then
TF_AND:= TF_AND and TF_ANDORNext;
TF_ANDOR:=TF_OR or TF_AND;
TF_OR:=-1;
TF_AND:=-1;
end
else
begin
TF_ANDOR:=TF_ANDOR and TF_ANDORNext;
end;
end
else//当前的OR
begin
TF_OR:=TF_ANDOR;//TF_ANDORCurr;
end;
end;
end
else //最后一个ANDOR的处理
begin
ANDORNext:=-1;
if ANDORCurr=1 then
begin
if TF_OR>-1 then //上一个有保存
begin
if TF_AND>-1 then
begin
TF_AND:= TF_AND and vStringValues[i+1];
TF_ANDOR:=TF_OR or TF_AND;
TF_OR:=-1;
TF_AND:=-1;
end
else
begin
TF_AND:=vStringValues[i] and vStringValues[i+1];
TF_ANDOR:=TF_OR or TF_AND;
TF_OR:=-1;
TF_AND:=-1;
end;
end
else
begin
//这个不存在的
end;
end
else
begin
TF_ANDOR:=TF_ANDOR or vStringValues[i+1];
end;
end;
end;
Result:= TF_ANDOR=1;
end;

 

 

-----------2-------结束-----------------------------------

posted on 2021-03-09 14:44  码农的笔记  阅读(60)  评论(0编辑  收藏  举报