⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sinfo.pas

📁 校园GIS系统——介绍校园个部门
💻 PAS
字号:
unit sInfo;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, Db, ADODB, StdCtrls, Buttons, MapObjects2_TLB;

type
  TSInfoFrm = class(TForm)
    Edit1: TEdit;
    CbbField: TComboBox;
    ADOConnection1: TADOConnection;
    ADODataSet1: TADODataSet;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Bbtquery: TBitBtn;
    Label1: TLabel;
    procedure connection();
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BbtqueryClick(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure DBGrid1CellClick(Column: TColumn);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  SInfoFrm: TSInfoFrm;

implementation

uses Main;

{$R *.DFM}

procedure TSInfoFrm.connection();
var
i:integer;

begin
try
  begin
      ADOConnection1.Close;
      ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+
                                    'Data Source='+ExtractFileDir(application.ExeName)+'\sInfo.mdb;'+
                                    'Persist Security Info=False';

      ADOConnection1.Connected:=true;
      ADODataSet1.Close;
      ADODataSet1.CommandText:='select * from SInfo';
      ADODataSet1.Open;
      for i:=0 to CbbField.Items.Count-1 do
        DBGrid1.Columns[i].FieldName:=CbbField.Items.Strings[i];
      CbbField.ItemIndex:=0;
    end;
except
  exit;
   end;
end;

procedure TSInfoFrm.FormShow(Sender: TObject);
begin
  connection();
end;

procedure TSInfoFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ADOConnection1.Close;
end;

procedure TSInfoFrm.BbtqueryClick(Sender: TObject);
var
Sql,ExpStr:string;
lays:ImoMaplayer;
MyStrings:ImoStrings;
i:integer;
Mypolygon:    ImoPolygon;
Myfield:      IMoField;
begin
  sql:='';
  if Edit1.Text<>''then
  begin
    try
    begin
      Sql:='Select * From sInfo Where '+ CbbField.Text+ ' like'+ chr(39)+Edit1.text+'%'+chr(39);
      ADODataSet1.Close;
      ADODataSet1.CommandText:=Sql;
      ADODataSet1.Open;
    end;  
    except
    if MessageDlg('数据库出错,或表达式错误!请重试',mtConfirmation,[mbYes],0)=mrYes then
    begin
      connection();
      exit;
      end;
    end;


    if ADODataSet1.RecordCount > 0 then
    begin
      ExpStr:='';

      lays:=CoMaplayer.Create;
      MyStrings:=CoStrings.Create;
      ADODataSet1.Recordset.MoveFirst;

      While not ADODataSet1.Recordset.EOF do
      begin
        //过滤重复值
        MyStrings.Add(ADODataSet1.Recordset.fields.item['MC'].Value);
        ADODataSet1.Recordset.MoveNext;
        
      end;

      for i:=0 to MyStrings.Count - 1 do
      begin
        //添加值
        ExpStr:=ExpStr+' '+'MC='+ chr(39)+MyStrings.Item(i)+chr(39);

        if length(ExpStr)>0 then
          ExpStr:=ExpStr+' ' +'or';
      end;

      delete(ExpStr,length(ExpStr)-2,3);
      
      lays:=ImoMapLayer(MainFrm.MainMap.Layers.Item('白龙校区建筑1:500'));
      Mainfrm.FindRecord:=lays.SearchExpression(ExpStr);
      if  not Mainfrm.FindRecord.EOF then
      begin

        Myfield:= MainFrm.FindRecord.Fields.Item('shape');
        Mypolygon := IMoPolygon(IDispatch(Myfield.value));
        mainfrm.mainmap.CenterAt(Mypolygon.Centroid.x,Mypolygon.centroid.y);
        MainFrm.Mainmap.Refresh;
        
        MainFrm.FindRecord:=nil;
        MyStrings:=nil;
      end;
    end
    else
    begin
      ShowMessage('没有符合的记录!');
      Edit1.Text:='';
    end;

  end

  else
    ShowMessage('请给出查询条件!');
   //ADOConnection1.close;
end;

procedure TSInfoFrm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
  begin
    Bbtquery.Click;
    Edit1.SelStart:=0;
    Edit1.SelLength:=Length(Edit1.Text);
  end;
end;

procedure TSInfoFrm.DBGrid1CellClick(Column: TColumn);
var
ExpStr:string;
Mypolygon:    ImoPolygon;
Myfield:      IMoField;
lays:ImoMaplayer;
begin
try
begin
  DBGrid1.DataSource.DataSet.GotoBookmark(pointer(DBGrid1.SelectedRows.Items[0]));
  ExpStr:='MC='+ chr(39)+DBGrid1.DataSource.DataSet.Fields[0].AsString+chr(39);
  lays:=ImoMapLayer(MainFrm.MainMap.Layers.Item('白龙校区建筑1:500'));
  Mainfrm.FindRecord:=lays.SearchExpression(ExpStr);
  if  not Mainfrm.FindRecord.EOF then
  begin

    Myfield:= MainFrm.FindRecord.Fields.Item('shape');
    Mypolygon := IMoPolygon(IDispatch(Myfield.value));
    mainfrm.mainmap.CenterAt(Mypolygon.Centroid.x,Mypolygon.centroid.y);
    MainFrm.Mainmap.FlashShape(MainFrm.FindRecord.Fields.Item('Shape').Value,4);
    MainFrm.FindRecord:=nil;

  end;
end;
except
exit;
end;

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -