📄 cls_layercontrol.~pas
字号:
procedure TMapControl.bitShowClick(Sender: TObject);
var
strMessage:string;
strSqlString:string;
cDataPubMain,cDataPubRel:TDataPub;
sRelTableName:string;
sConditonValue:array of array of string;
iRelColumnCount:integer;
pTableInfo:pTable;
iLoop,jLoop:integer;
iPos:integer;
begin
//取得主表关联字段的值
SetLength(sConditonValue,m_lvResult.Items.Count);
cDataPubMain:=TDataPub.create(systemDM.Glb_BasicDataOperate,m_ShowTableName);
iRelColumnCount:=length(cDataPubMain.msOriginalField[m_cbRelateSource.ItemIndex]);
for iLoop:=0 to m_lvResult.Items.Count -1 do
begin
pTableInfo:=m_lvResult.Items[iLoop].Data;
SetLength(sConditonValue[iLoop],iRelColumnCount);
for jLoop:=0 to iRelColumnCount-1 do
begin
sConditonValue[iLoop][jLoop]:=pTableInfo^.DataValue[cDataPubMain.iGetColumnIndex(cDataPubMain.msOriginalField[m_cbRelateSource.ItemIndex][jLoop])];
end;
end;
//根据选择的关联资源形成SQl语句
cDataPubRel:=TDataPub.create(systemDM.Glb_BasicDataOperate,TButton(sender).Name);
strSqlString:='select ';
for iLoop:= 0 to high(cDataPubRel.msArrColumnName) do
begin
strSqlString:=strSqlString + cDataPubRel.msArrColumnName[iLoop] + ',';
end;
strSqlString:=copy(strSqlString,1,length(strSqlString)-1);
strSqlString:= strSqlString + ' from ' + TButton(sender).Name;
strSqlString:=strSqlString + ' where ';
//where 条件
for iLoop:=0 to m_lvResult.Items.Count -1 do
begin
for jLoop:=0 to iRelColumnCount-1 do
begin
if cDataPubMain.msRelType[m_cbRelateSource.ItemIndex][jLoop]= 0 then
begin
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + '=' + sConditonValue[iLoop][jLoop] + ' and ';
end
else if cDataPubMain.msRelType[m_cbRelateSource.ItemIndex][jLoop]= 1 then
begin
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + '=''' + sConditonValue[iLoop][jLoop] + ''' and ';
end
else if cDataPubMain.msRelType[m_cbRelateSource.ItemIndex][jLoop]= 2 then
begin
if (pos('甲',sConditonValue[iLoop][jLoop])<>0) or (pos('乙',sConditonValue[iLoop][jLoop])<>0) or
(pos('丙',sConditonValue[iLoop][jLoop])<>0) or (pos('丁',sConditonValue[iLoop][jLoop])<>0) or
(pos('戊',sConditonValue[iLoop][jLoop])<>0) then
begin
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + ' like ''' + sConditonValue[iLoop][jLoop] + '%'' and ';
end
else
begin
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + ' like ''' + sConditonValue[iLoop][jLoop] + '%'' and ';
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + ' not like ''%甲%''' + ' and ';
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + ' not like ''%乙%''' + ' and ';
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + ' not like ''%丙%''' + ' and ';
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + ' not like ''%丁%''' + ' and ';
strSqlString:=strSqlString + cDataPubMain.msRelField[m_cbRelateSource.ItemIndex][jLoop] + ' not like ''%戊%''' + ' and ';
end;
end;
end;
strSqlString:=copy(strSqlString,1,length(strSqlString)-6);
strSqlString:=strSqlString + ' or ';
end;
strSqlString:=copy(strSqlString,1,length(strSqlString)-3);
cDataPubMain.Free;
cDataPubRel.Free;
with TForm_Basic.create(systemDM.Glb_BasicDataOperate,TButton(sender).Name,strSqlString,1) do
try
ShowModal;
finally
free;
end;
end;
//***************************************//
// 图元选中时设置属性表 //
//***************************************//
function TMapControl.SetKeyBySelect(LayerName: string): Boolean;
var
ftr: CMapxFeature;
ftrs: CMapxFeatures;
ds: CMapXDataSet;
i,j:Integer;
sSqlString,sTableName:string;
adoQue:Tadoquery;
cGrid:TGridListView;
pMaInfo: pMapInfo;
arrSelect,arrFrom: array of string;
arrWhereCol,arrWhereValue: array of string;
arrLayerIndex:MyArray;
cDataPub:TDataPub;
iLoop:integer;
begin
try
for i:=0 to m_tvLayerControl.Items.Count -1 do
begin
pMaInfo:=m_tvLayerControl.Items[i].Data;
if (pMaInfo^.SpaceTableName)=LayerName then
begin
sTableName:=pMaInfo^.TableName;
m_ShowTableName:=sTableName;
arrLayerIndex:=arrGetIndexField(pMaInfo^.sIndexField);
Break;
end;
end;
cDataPub:=TDataPub.create(systemDM.Glb_BasicDataOperate,sTableName);
cGrid:=TGridListView.Create(cDataOperate);
SetLength(arrSelect,1);
arrSelect[0]:='';
for iLoop:= 0 to high(cDataPub.msArrColumnName) do
begin
arrSelect[0]:=arrSelect[0] + cDataPub.msArrColumnName[iLoop] + ',';
end;
arrSelect[0]:=copy(arrSelect[0],1,length(arrSelect[0])-1);
SetLength(arrFrom,1);
arrFrom[0]:=sTableName;
SetLength(arrWhereCol,0);
SetLength(arrWhereValue,0);
ds:=m_Map.DataSets.Item[LayerName];
ftrs := m_Map.Layers.Item [LayerName].Selection.Clone;
//m_Map.Layers.Item [LayerName].Selection.ClearSelection;
for i:=1 to ftrs.Count do
begin
ftr := ftrs.Item[i];
for j:= 0 to Length(arrLayerIndex)-1 do
begin
SetLength(arrWhereCol,Length(arrWhereCol)+1);
SetLength(arrWhereValue,Length(arrWhereValue)+1);
arrWhereCol[High(arrWhereCol)]:=arrLayerIndex[j];
arrWhereValue[High(arrWhereValue)]:=ds.Value[ftr,ds.Fields.Item[arrLayerIndex[j]]];
end;
end;
sSqlString:=sGeneralSQLSelect(arrSelect,arrEmpty,arrFrom)+
sGeneralSQLWhere(arrWhereCol,arrWhereValue,arrEmpty,arrTwoDegreeEmpty,'Or');
adoQue:=cDataOperate.adoGetAdoQuery(sSqlString);
cGrid.AddDatatoListView(sTableName,adoQue,m_lvResult,True);
cDataPub.sChangeListCaption(TBase_ListView(m_lvresult));
cDataPub.sChangeListData(TBase_ListView(m_lvresult));
m_cbRelateSource.Clear;
cDataPub.SpecialRelResource(m_cbRelateSource);
cGrid.Free;
cDataPub.Free;
except on E: Exception do
begin
cGrid.Free;
cDataPub.Free;
ShowMessage(E.Message);
Result := False;
end;
end;
end;
//***************************************
// 生成Select语句
//***************************************
function TMapControl.sGeneralSQLSelect(arrSelect,
arrAs, arrFrom: array of string): string;
var
i:Integer;
bHaveAs:Boolean;
sSelect:string;
begin
if Length(arrSelect)=Length(arrAs) then
bHaveAs:=true
else
bHaveAs:=false;
for i:= 0 to Length(arrSelect)-1 do
begin
sSelect:='Select '+arrSelect[i];
if bHaveAs then
sSelect:=sSelect+' As '+arrAs[i];
if i< Length(arrSelect)-1 then
sSelect:=sSelect+',';
end;
sSelect:=sSelect+' From ';
for i:= 0 to Length(arrFrom)-1 do
begin
sSelect:=sSelect+arrFrom[i];
if i< Length(arrFrom)-1 then
sSelect:=sSelect+',';
end;
Result:=sSelect;
end;
//***************************************
// 生成Where语句
//***************************************
function TMapControl.sGeneralSQLWhere(arrCol, arrValue, arrLink: array of string;
arrOperate: ArrayTwoDegree; sLink: string): string;
var
i,j,k,m:Integer;
bOnlyEqual:Boolean;
bOnlyOneLink:Boolean;
bAddBracket:Boolean;
sWhere:string;
begin
bOnlyOneLink:=(Length(arrLink)=0);
bOnlyEqual:=(Length(arrOperate)=0);
sWhere:=' Where ';
j:=0;
k:=0;
if not bOnlyEqual then
sWhere:=sWhere+'(';
for i:= 0 to Length(arrCol)-1 do
begin
sWhere:=sWhere+arrCol[i];
if bOnlyEqual then
begin
sWhere:=sWhere+'=';
sWhere:=sWhere+arrValue[i];
bAddBracket:=false;
end
else
begin
sWhere:=sWhere+arrOperate[j,k];
if k<Length(arrOperate[j])-1 then
begin
k:=k+1;
bAddBracket:=false;
end
else
begin
j:=j+1;
k:=0;
bAddBracket:=true;
end;
sWhere:=sWhere+QuotedStr(arrValue[i]);
end;
if bAddBracket then
begin
sWhere:=sWhere+')';
end;
if i<Length(arrCol)-1 then
begin
if bOnlyOneLink then
sWhere:=sWhere+' '+sLink+' '
else
begin
sWhere:=sWhere+' '+arrLink[i]+' ';
if bAddBracket then
sWhere:=sWhere+'(';
end;
end;
end;
Result:=sWhere;
end;
//***********************************************
// 取得索引列数组
//***********************************************
function TMapControl.arrGetIndexField(sIndex: string): MyArray;
var
arrTemp:MyArray;
sTemp:string;
iPos:Integer;
begin
try
SetLength(arrTemp,0);
sTemp:=Trim(sIndex);
if sTemp='' then
begin
Result:=arrTemp;
Exit;
end;
iPos:=Pos(',',sTemp);
while iPos>0 do
begin
SetLength(arrTemp,Length(arrTemp)+1);
arrTemp[High(arrTemp)]:=Copy(sTemp,1,iPos-1);
sTemp:=Trim(Copy(sTemp,iPos+1,Length(sTemp)-iPos));
iPos:=Pos(',',sTemp);
end;
SetLength(arrTemp,Length(arrTemp)+1);
arrTemp[High(arrTemp)]:=sTemp;
Result:=arrTemp;
except
on E: Exception do
begin
ShowMessage(E.Message);
SetLength(arrTemp,0);
Result:=arrTemp;
end;
end;
end;
//*********************************************
// 取得图层控制树当前选中的item的空间表名
//*********************************************
function TMapControl.sGetTvSelectSpace: string;
var
pTempInfo:pMapInfo;
begin
try
if m_tvLayerControl.Selected<>nil then
begin
pTempInfo:=m_tvLayerControl.Selected.Data;
if pTempInfo^.SpaceTableName<>'' then
Result:=pTempInfo^.SpaceTableName
else
Result:='';
end;
except on E: Exception do
begin
Result:='';
ShowMessage(E.Message);
end;
end;
end;
//*********************************************
// 取得图层控制树当前选中的item的表名
//*********************************************
function TMapControl.sGetTvSelectTableName: string;
var
pTempInfo:pMapInfo;
begin
try
if m_tvLayerControl.Selected<>nil then
begin
pTempInfo:=m_tvLayerControl.Selected.Data;
if pTempInfo^.SpaceTableName<>'' then
Result:=pTempInfo^.TableName
else
Result:='';
end;
except on E: Exception do
begin
Result:='';
ShowMessage(E.Message);
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -