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

📄 unitqcgisproject.pas

📁 此代码是关于mapgis的在
💻 PAS
📖 第 1 页 / 共 5 页
字号:

procedure TqcGISProject.DoAfterUserConnect;
var
  AModuleRight:TModuleRight;
begin
  if Connected then
  begin
    //设置主窗口权限//
    CanEnterModule(Form_Main.ClassType, AModuleRight);
    if AModuleRight=nil then
    begin
      MyWarning('用户权限遭到破坏,请系统管理员修复该用户的权限配置!');
      Application.Terminate;
      Exit;
    end;
    Form_Main.ModuleRight:=AModuleRight;
    DebugLog.Add('DB500TS-C', ['允许用户登陆系统主界面']);
    //加载变电所列表//
    ReInitServerPart;
    DebugLog.Add('DB500TS-C', ['系统加载变电所列表成功']);
    //如果该用户是调度室人员,则可以查看所有变电所的地图,因此,设置第一个
    //变电所为默认变电所;如果该用户是变电所人员,则只能查看自己所在变电所
    //的地图
    case UserUnitType of
      1:begin
        Form_Main.cb_Maps.Enabled:=True;
        Form_Main.cb_Maps.Color:=clWindow;
        if Form_Main.cb_Maps.Items.Count>0 then
        begin
          Form_Main.cb_Maps.ItemIndex:=0;
          Form_Main.cb_Maps.OnChange(Form_Main.cb_Maps);
        end;
      end;
      2:begin
        FCurUnitID:=TQCUserInfo(App_UserInfo).UnitID;
        Form_Main.cb_Maps.Enabled:=False;
        Form_Main.cb_Maps.Color:=clBtnFace;
        Form_Main.cb_Maps.ItemIndex:=Form_Main.cb_Maps.Items.IndexOf(TQCUserInfo(App_UserInfo).UnitName);
        Form_Main.cb_Maps.OnChange(Form_Main.cb_Maps);        
      end;
    end;
    DebugLog.Add('DB500TS-C', ['系统加载默认变电所地图成功']);
    //设置用户权限//
    DoApplayFunctions;
    DebugLog.Add('DB500TS-C', ['应用用户权限成功']);
  end;
end;

procedure TqcGISProject.DoBeforeDelete(Ft:Feature; ActionId:Integer);
begin
  if Trim(Ft.KeyValue)='' then Exit;
  case GetLayerFeatureId(Ft.Layer) of
    LAYER_SYS_SUBSTATION:
      GDBPoster.DeleteRecord('t_SubStationLayer', 'StationID='+Ft.KeyValue);
    LAYER_SYS_POWER:begin
      {如果是合并,为了尽量保留属性数据,将合并前的第一个开关记录作为合并后的开关
      记录,合并前各个开关关联的线路都将被保留下来,并关联到合并后的开关上。
      下面代码就是将合并前开关的保存起来的方法。}
      if ActionId=ID_ACTION_COMBINE then
      begin
        if FirstFeature and IsNumber(Ft.KeyValue) then
        begin
          FirstFeatureKeyValue:=Ft.KeyValue;
          FirstFeature:=False;
        end
        else if IsNumber(Ft.KeyValue) then
        begin
          GDBPoster.DeleteRecord('t_CtrlDotsLayer', 'DotId='+Ft.KeyValue);
          GDBPoster.TableName:='t_DotLines';
          GDBPoster.SetModifyFields('DotId');
          GDBPoster.WhereSQL.Text:='DotId=:DotId';
          GDBPoster.SetCustomValue('DotId', StrToInt(FirstFeatureKeyValue));
          GDBPoster.SetParamValue('DotId', StrToInt(Ft.KeyValue));
          GDBPoster.EditPost;
        end;
      end
      else
      begin
        GDBPoster.DeleteRecord('t_CtrlDotsLayer', 'DotId='+Ft.KeyValue);
        GDBPoster.DeleteRecord('t_DotLines', 'DotId='+Ft.KeyValue);
      end;
    end;
    LAYER_SYS_LINE:begin
      if ActionId=ID_ACTION_COMBINE then
      begin
        if FirstFeature and IsNumber(Ft.KeyValue) then
        begin
          FirstFeatureKeyValue:=Ft.KeyValue;
          FirstFeature:=False;
        end
        else if IsNumber(Ft.KeyValue) then
        begin
          //不是第一个,则删除线路记录//
          GDBPoster.DeleteRecord('t_LinesLayer', 'LineId='+Ft.KeyValue);
          //修改线路-开关表中相应记录的线路号为FirstFeatureKeyValue//
          GDBPoster.TableName:='t_DotLines';
          GDBPoster.SetModifyFields('LineId');
          GDBPoster.WhereSQL.Text:='LineId=:LineId';
          GDBPoster.SetCustomValue('LineId', StrToInt(FirstFeatureKeyValue));
          GDBPoster.SetParamValue('LineId', StrToInt(Ft.KeyValue));
          GDBPoster.EditPost;
        end;
      end
      else
      begin
        GDBPoster.DeleteRecord('t_LinesLayer', 'LineId='+Ft.KeyValue);
        GDBPoster.DeleteRecord('t_DotLines', 'LineId='+Ft.KeyValue);
      end;
    end;
  end;
end;

function TqcGISProject.GetLayerFeatureId(ALyr: Layer): Integer;
begin
  if ALyr=FSubStationLayer then
    Result:=LAYER_SYS_SUBSTATION
  else if ALyr=FDotLayer then
    Result:=LAYER_SYS_POWER
  else if ALyr=FLineLayer then
    Result:=LAYER_SYS_LINE
  else if ALyr=FUserLayer then
    Result:=LAYER_SYS_USER
  else if ALyr=FRoadLayer then
    Result:=LAYER_SYS_ROAD
  else if ALyr=FBTLayer then
    Result:=LAYER_SYS_BT
  else
    Result:=0;
end;

function TqcGISProject.GetConnected: Boolean;
begin
  Result:=App_UserInfo.UserExists;
end;

procedure TqcGISProject.GetUnits(List: TStrings);
begin
  List.Clear;
  with dm_MainLinkObjects.PublicQuery do
  begin
    Close;
    SQL.Text:='select UnitID, UnitName from t_Units order by UnitID';
    Open;
    while not Eof do
    begin
      List.Add(Fields[0].AsString+'='+Fields[1].AsString);
      Next;
    end;
    Close;
  end;
end;

function TqcGISProject.GetUserUnitType: Integer;
begin
  Result:=TQCUserInfo(App_UserInfo).UnitType;
end;

procedure TqcGISProject.InitLineLayerRecords;
var
  i,j:Integer;
  Fts:Features;
  newrvs:RowValues;
begin
  GDBPoster.DeleteRecord('t_LinesLayer', 'UnitID='+IntToStr(CurUnitID));
  GDBPoster.TableName:='t_LinesLayer';
  GDBPoster.SetInsertFields('UnitID,LineID,LineName,Length,Script');
  newrvs:=CreateRowValuesFromStruct(FLineLayer.DataSets.Item[1].Fields, FLineLayer.DataSets.Item[1]);
  Fts:=FLineLayer.AllFeatures;
  j:=1;
  for i:=1 to Fts.Count do
  begin
    try
      if Fts.Item[i].type_=miFeatureTypeLine then
      begin
        newrvs.Item['LineID'].Value:=j;
        newrvs.Item['LineName'].Value:=IntToStr(j)+'号线';
        newrvs.Item['Length'].Value:=0;
        newrvs.Item['Script'].Value:='';
        Fts.Item[i].Update(EmptyParam, newrvs);

        GDBPoster.SetCustomValue('UnitID',CurUnitID);
        GDBPoster.SetCustomValue('LineID', j);
        GDBPoster.SetCustomValue('LineName',IntToStr(j)+'号线');
        GDBPoster.SetCustomValue('Length','0');
        GDBPoster.SetCustomValue('Script','');
        GDBPoster.InsertPost;
      end;
      Inc(j);
    except
    end;
  end;
end;

procedure TqcGISProject.InitDotLayerRecords;
var
  i,j:Integer;
  Fts:Features;
  newrvs:RowValues;
begin
  GDBPoster.DeleteRecord('t_CtrlDotsLayer', 'UnitID='+IntToStr(CurUnitID));
  GDBPoster.TableName:='t_CtrlDotsLayer';
  GDBPoster.SetInsertFields('UnitID,DotID,DotName,Type,KgState,Script');
  newrvs:=CreateRowValuesFromStruct(FDotLayer.DataSets.Item[1].Fields, FDotLayer.DataSets.Item[1]);
  Fts:=FDotLayer.AllFeatures;
  j:=1;
  for i:=1 to Fts.Count do
  begin
    try
      if Fts.Item[i].type_=miFeatureTypeLine then
      begin
        newrvs.Item['DotID'].Value:=j;
        newrvs.Item['DotName'].Value:=IntToStr(j)+'号开关';
        newrvs.Item['Type'].Value:=1;
        newrvs.Item['KgState'].Value:=True;
        newrvs.Item['Script'].Value:='';
        Fts.Item[i].Update(EmptyParam, newrvs);

        GDBPoster.SetCustomValue('UnitID',CurUnitID);
        GDBPoster.SetCustomValue('DotID', j);
        GDBPoster.SetCustomValue('DotName',IntToStr(j)+'号开关');
        GDBPoster.SetCustomValue('Type',1);
        GDBPoster.SetCustomValue('KgState',1);
        GDBPoster.SetCustomValue('Script','');
        GDBPoster.InsertPost;
      end;
      Inc(j);
    except
    end;
  end;
end;

procedure TqcGISProject.LinkToPowerClick(Sender: TObject);
var
  AToolObj:TLinkToPowerMapTool;
begin
  EditSystemLayer(LAYER_SYS_LINE);
  AToolObj:=SetCurrentMapTool('TLinkToPowerMapTool', OnTurnTool) as TLinkToPowerMapTool;
  AToolObj.Project:=Self;
end;

procedure TqcGISProject.AnalyzeSubStationClick(Sender: TObject);
var
  Fts:Features;
begin
  if FSubStationLayer=nil then Exit;
  Fts:=FSubStationLayer.AllFeatures;
  AnalyzeFeatures(FSubStationLayer, Fts, miFeatureTypeSymbol, clBlue);
  if FSubStationLayer.Selection.Count=0 then
    MyDefInformation('所有子站都已有记录!');
end;

procedure TqcGISProject.AnalyzePowerClick(Sender: TObject);
var
  Fts:Features;
begin
  if FDotLayer=nil then Exit;
  Fts:=FDotLayer.AllFeatures;
  AnalyzeFeatures(FDotLayer, Fts, miFeatureTypeLine, clGreen);
  if FDotLayer.Selection.Count=0 then
    MyDefInformation('所有开关都已有记录!');
end;

procedure TqcGISProject.AnalyzeLinkPowerClick(Sender: TObject);
var
  Fts:Features;
begin
  if FLineLayer=nil then Exit;
  FLineLayer.Selection.ClearSelection;
  with dm_MainLinkObjects.PublicQuery do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT LineID FROM t_LinesLayer');
    SQL.Add('WHERE UnitID=1 and NOT (LineID IN');
    SQL.Add('(SELECT a.LineID FROM t_LinesLayer a');
    SQL.Add('INNER JOIN t_DotLines b ON a.LineID = b.LineID))');
    Open;
    while not Eof do
    begin
      Fts:=FLineLayer.Search('LineID='+Fields[0].AsString, EmptyParam);
      if Fts.Count=1 then
      begin
        Fts.Item[1].Style.LineColor:=clRed;
        Fts.Item[1].Update(EmptyParam, EmptyParam);
        FLineLayer.Selection.Add(Fts.Item[1]);
      end;
      Next;
    end;
    Close;
  end;
  if FLineLayer.Selection.Count=0 then
    MyDefInformation('所有线路都有开关!');
end;

procedure TqcGISProject.AnalyzeSDLineClick(Sender: TObject);
var
  Fts:Features;
begin
  if FLineLayer=nil then Exit;
  Fts:=FLineLayer.AllFeatures;
  AnalyzeFeatures(FLineLayer, Fts, miFeatureTypeLine, clRed);
  if FLineLayer.Selection.Count=0 then
    MyDefInformation('所有线路都已有记录!');
end;

procedure TqcGISProject.AnalyzeFeatures(ALyr:Layer; Fts: Features;
  FtType:TOLEEnum; WarningColor:TColor);
var
  i:Integer;
  str:string;
begin
  ALyr.Selection.ClearSelection;
  for i:=1 to Fts.Count do
  begin
    try
      if Fts.Item[i].type_=FtType then
      begin
        str:=Trim(Fts.Item[i].KeyValue);
        if (str='')or(not IsNumber(str))or(StrToInt(str)<=0) then
        begin
          Fts.Item[i].Style.LineColor:=WarningColor;
          Fts.Item[i].Update(EmptyParam, EmptyParam);
          ALyr.Selection.Add(Fts.Item[i]);
        end;
      end;
    except
    end;
  end;
end;

procedure TqcGISProject.LoadDLControlDataClick(Sender: TObject);
var
  OldEnabled:Boolean;
begin
  OldEnabled:=FPowerTimer.Enabled;
  try
    FPowerTimer.Enabled:=False;
    DLCtrl.LoadFromDataBase(dm_MainLinkObjects.PublicQuery);
    DLCtrl.AnalyzeState;
    RefreshAllDotState;
    RefreshLineLayerState(True);
  finally
    FPowerTimer.Enabled:=OldEnabled;
  end;
end;

procedure TqcGISProject.RandomPowerStateClick(Sender: TObject);
begin
  FPowerTimer.Enabled:=not FPowerTimer.Enabled;
  if FPowerTimer.Enabled then
    TMenuItem(Sender).Caption:='停止开关状态随机模拟'
  else
    TMenuItem(Sender).Caption:='启动开关状态随机模拟';
end;

procedure TqcGISProject.PowerTimerOnTimer(Sender: TObject);
var
  aDot:TDot;
  Index:Integer;
begin
  FPowerTimer.Enabled:=False;
  try
    with TqcGISProject(MyGIS) do
    begin
      Index:=Random(DLCtrl.Dots.ItemCount-1);
      if (Index>-1)and(Index<DLCtrl.Dots.ItemCount) then
      begin
        aDot:=DLCtrl.Dots.Items[Index];
        if aDot.BDSDot then Exit;
        if (Random(100) mod 2)=1 then
          DLCtrl.SetDotState(aDot, dsBreak, False)
        else
          DLCtrl.SetDotState(aDot, dsLink, False);
        DLCtrl.AnalyzeState;
        RefreshDotState(aDot);
        RefreshLineLayerState(True);
      end;
    end;
  finally
    FPowerTimer.Enabled:=True;
  end;
end;

function TqcGISProject.IsOldLayer(aUnitID: Integer; aTableName: string): Boolean;
var
  INIF:TIniFile;
  LocalDate:TDateTime;
  UpLoadDate: TDateTime;
begin
  with dm_MainLinkObjects.PublicQuery do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select ModifyTime f

⌨️ 快捷键说明

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