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

📄 global.pas

📁 BOM表
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          FGroupID := -1
        else
          FGroupID := FieldByName('ObjectParentID').AsInteger;
        //  设置Params属性
        //FParams.Text := FieldByName('OptParams').AsString;
      end;
    finally
      Close;
    end;
    Free;
  end;

  with ADOQueryPerm do
  begin
    Active := False;
    Connection := FADOConnection;
    SQL.Clear;
    SQL.Add('select * from Sys_Permission');
    SQL.Add(' where PermissionOptrID in ');
    SQL.Add('  (select GroupID from Sys_OptrGroup where OptID = ' + IntToStr(FOperatorID) + ')');
    try
      Open;
    except
      MessageBox(Application.Handle, '无法建立该用户的权限列表,这将会使你以后的操作无法进行,请和系统管理员联系解决。',
                 '错误', MB_OK or MB_ICONERROR);
    end;
  end;

end;

function TEnv.TodayPromptStr: String;
begin

  Result := '<无>';
  if (FADOConnection = nil) or (FOperatorID = -1) then
  begin
    MessageBox(Application.Handle,
       'TEnv: 在执行此方法(IsAdmin)之前,请设置ADOConnection和OperatorID属性。',
       '错误', MB_OK or MB_ICONERROR);
    Exit;
  end;

  with TADOQuery.Create(FADOConnection) do
  begin
    Connection := FADOConnection;
    SQL.Text := 'select SchedulContent from App_Schedule ' +
                ' where (SchedulBeginDate <= getDate()) and (SchedulEndDate >= getDate()) and ' +
                ' (SchedulTo = ' + IntToStr(FOperatorID) + ')';
    ExecuteOptions := ExecuteOptions - [eoExecuteNoRecords];
    try
      Open;
      Result := '';
      while not Eof do
      begin
        Result := Result + Fields[0].AsString + #13 + #10;
        Next;
      end;
    finally
      Close;
    end;
    Free;
  end;

end;

function TEnv.HasPermission(AType, AID, DataOwnerID: Integer; Action: String): Boolean;
begin

  Result := False;
  if not ADOQueryPerm.Active then
  begin
    MessageBox(Application.Handle, '没有该用户的权限列表。', '错误', MB_OK or MB_ICONERROR);
    Exit;
  end;

  with ADOQueryPerm do
  begin
    Filter := '(PermissionBusiType = ' + IntToStr(AType) + ') and (PermissionBusiID = ' + IntToStr(AID) + ')';
    Filtered := True;
    First;
    while not EOF do
    begin
      case FieldByName(Action).AsInteger of
        nx_opDeny:     Result := False;
        nx_opAllow:    Result := True;
        nx_opOnlySelf: Result := FOperatorID = DataOwnerID;
      end;
      if Result then Break;
      Next;
    end;
  end;

end;

procedure TEnv.AddLogRecord(AObjectID: Integer; AOperation, ARemark: String);
begin

  if not Assigned(FADOConnection) then Exit;

  with TADOQuery.Create(nil) do
  begin
    Connection := FADOConnection;
    SQL.Text := 'select * from Log_Opt where 1 = 2';
    try
      Open;
    except
      MessageBox(Application.Handle,
         '无法记录操作日志!原因:打开操作日志表出错!',
         '错误', MB_OK or MB_ICONERROR);
      Free;
      Exit;
    end;
    Append;
    FieldByName('LogDateTime').AsDateTime := Now;
    FieldByName('LogObjectID').AsInteger := AObjectID;
    FieldByName('LogOptrID').AsInteger := FOperatorID;
    FieldByName('LogAction').AsString := AOperation;
    FieldByName('LogContent').AsString := ARemark;
    Post;
    Close;
    Free;
  end;

end;

{ TncDSList }

constructor TncDSList.Create(BusiClasses: array of Integer;
                             Connection: TADOConnection; ObjectDS: TDataSource);

  function AddDSItem(Connection: TADOConnection;
    ObjTypeID, ObjTypeDataType: Integer;
    TableName, KeyField: String; LinkTree, IsInsp: Boolean;
    ObjDS: TDataSource): TADOQuery;
  begin

    if (TableName = '') {or (KeyField = '')} then
    begin
      Result := nil;
      Exit;
    end;

    Result := TADOQuery.Create(Connection);
    Result.Connection := Connection;
    with Result do
    begin
      ExecuteOptions := ExecuteOptions - [eoExecuteNoRecords];
      Tag := ObjTypeID;
      case ObjTypeDataType of
        otdTable:
        begin
          SQL.Add('select * from ' + Trim(TableName));
          if LinkTree then
          begin
            if IsInsp then SQL.Add(' where ' + KeyField + ' = :ObjectFID')
            else
            begin
              SQL.Add(' where ' + KeyField + ' = :ObjectID');
              BeforePost := SQLDataSetBeforePost; //  修复外键
              //  BatchUpdate 模式
              LockType := ltBatchOptimistic;
            end;
          end;
        end;

        otdSQL:
        begin
          SQL.Text := TableName;
          if LinkTree then BeforePost := SQLDataSetBeforePost; //  修复外键
          //  BatchUpdate 模式
          LockType := ltBatchOptimistic;
        end;
      end;

      if LinkTree then DataSource := ObjDS;
      with Parameters do
      begin
        if FindParam('ObjectID') <> nil then
          ParamByName('ObjectID').DataType := ftInteger;
        if FindParam('ObjectFID') <> nil then
          ParamByName('ObjectFID').DataType := ftInteger;
      end;

      try
        Open;
      except
        Free;
        Result := nil;
      end;
    end;

  end;

var
  I: Integer;
begin

  FADOConnection := Connection;
  FDSItems := TList.Create;

  if FADOConnection = nil then
  begin
    MessageBox(Application.Handle,
       'TncDSList: 在执行此方法(IsAdmin)之前,请设置ADOConnection属性。',
       '错误', MB_OK or MB_ICONERROR);
    Exit;
  end;

  FObjectTypeDS := TADOQuery.Create(FADOConnection);
  with TADOQuery(FObjectTypeDS) do
  begin
    Connection := FADOConnection;
    ExecuteOptions := ExecuteOptions - [eoExecuteNoRecords];
    for I := Low(BusiClasses) to High(BusiClasses) do
      SQL.Text := SQL.Text + ',' + IntToStr(BusiClasses[I]);
    if Length(SQL.Text) <= 1 then
    begin
      Free;
      Exit;
    end;
    SQL.Text := 'select * from Pub_ObjectType where ObjectTypeClass in (' +
                Copy(SQL.Text, 2, Length(SQL.Text) - 1) + ')';
    try
      Open;
    except
      Free;
      Exit;
    end;
    while not Eof do
    begin
      if FieldByName('ObjectTypeDataType').AsInteger in [otdTable, otdSQL] then
        FDSItems.Add(AddDSItem(FADOConnection,
                             FieldByName('ObjectTypeID').AsInteger,
                             FieldByName('ObjectTypeDataType').AsInteger,
                             FieldByName('ObjectTypeData').AsString,
                             FieldByName('ObjectTypeKeyField').AsString,
                             FieldByName('ObjectTypeTreeView').AsBoolean,
                             FieldByName('ObjectTypeInsp').AsBoolean,
                             ObjectDS));
      Next;
    end;
    First;
  end;

end;

destructor TncDSList.Destroy;
var
  I: Integer;
begin

  for I := FDSItems.Count - 1 downto 0 do
    if Assigned(FDSItems.Items[I]) then TADOQuery(FDSItems.Items[I]).Free;
  FDSItems.Free;
  if Assigned(FObjectTypeDS) then FObjectTypeDS.Free;
  inherited;
  
end;

function TncDSList.FindItem(ObjectTypeID: Integer): TDataSet;
var
  I: Integer;
begin

  for I := 0 to FDSItems.Count - 1 do
    if (FDSItems.Items[I] <> nil) and
       (TADOQuery(FDSItems.Items[I]).Tag = ObjectTypeID) then
    begin
      Result := TDataSet(FDSItems.Items[I]);
      Exit;
    end;

  Result := nil;

end;

function TncDSList.GetItem(Index: Integer): TADOQuery;
begin

  Result := TADOQuery(FDSItems.Items[Index]);

end;

function TncDSList.GetItemCount: Integer;
begin

  Result := FDSItems.Count;
  
end;

procedure TncDSList.SQLDataSetBeforePost(Sender: TDataSet);
begin

  with TADOQuery(Sender) do
  begin
    if not FObjectTypeDS.Locate('ObjectTypeID', Tag, []) then Exit;
    if not FObjectTypeDS.FieldByName('ObjectTypeTreeView').AsBoolean then Exit;
    if FObjectTypeDS.FieldByName('ObjectTypeKeyField').AsString = '' then Exit;
    if not Assigned(DataSource) then Exit;
    if not Assigned(DataSource.DataSet) then Exit;
    if not DataSource.DataSet.Active then Exit;
    if DataSource.DataSet.FindField('ObjectID') = nil then Exit;

    //  修补外键连接
    //if FObjectTypeDS.FieldByName('ObjectTypeDataType').AsInteger = odtSQL then
    FieldByName(FObjectTypeDS.FieldByName('ObjectTypeKeyField').AsString).AsString :=
       DataSource.DataSet.FieldByName('ObjectID').AsString;
  end;

end;

{ TisParameters }

constructor TisParameters.Create(AConnection: TADOConnection);
begin

  FADOQuery := TADOQuery.Create(AConnection);
  FADOQuery.Connection := AConnection;
  FADOQuery.SQL.Add('select * from Sys_Parameters');
  try
    FADOQuery.Open;
  except
    raise Exception.Create('无法获得系统参数。请与系统管理员联系。');
  end;

end;

destructor TisParameters.Destroy;
begin

  if Assigned(FADOQuery) then FADOQuery.Free;
  inherited;

end;

function TisParameters.GetParamByIndex(AParamIndex: Integer): Boolean;
begin

  if not FADOQuery.Active then
  begin
    raise Exception.Create('无法获得系统参数。请与系统管理员联系。');
    Exit;
  end;
  if not FADOQuery.Locate('ParamID', AParamIndex, []) then
  begin
    raise Exception.CreateFmt('系统中没有指定的参数。[%d]', [AParamIndex]);
    Exit;
  end;
  Result := FADOQuery.FieldByName('ParamValue').AsBoolean;

end;

function TisParameters.GetParamByName(AParam: String): Boolean;
begin

  if not FADOQuery.Active then
  begin
    raise Exception.Create('无法获得系统参数。请与系统管理员联系。');
    Exit;
  end;
  if not FADOQuery.Locate('ParamName', AParam, []) then
  begin
    raise Exception.CreateFmt('系统中没有指定的参数。[%s]', [AParam]);
    Exit;
  end;
  Result := FADOQuery.FieldByName('ParamValue').AsBoolean;

end;

{ TIPenseeObject }

constructor TIPenseeObject.Create(AConnection: TADOConnection);
begin

  FQry := nil;
  if not Assigned(AConnection) then Exit;
  FQry := TADOQuery.Create(AConnection);
  with FQry do
  begin
    Connection := AConnection;
    SQL.Add('select * from Pub_Objects');
    SQL.Add('left outer join Pub_ObjectType on Pub_Objects.ObjectTypeID = Pub_ObjectType.ObjectTypeID');
    SQL.Add('where Pub_Objects.ObjectID = :ObjectID');
  end;

end;

destructor TIPenseeObject.Destroy;
begin

  if Assigned(FQry) then FQry.Free;
  inherited;

end;

procedure TIPenseeObject.SetObjectID(Value: Integer);
begin

  if not Assigned(FQry) then Exit;

  FObjectID := Value;

  with FQry do
  begin
    Active := False;
    Parameters.ParamByName('ObjectID').Value := Value;
    Open;
    FObjectTypeID := FieldByName('ObjectTypeID').AsInteger;
    FObjectParentID := FieldByName('ObjectParentID').AsInteger;
    FObjectFID := FieldByName('ObjectFID').AsInteger;
    FObjectName := FieldByName('ObjectName').AsString;
    FObjectShortName := FieldByName('ObjectShortName').AsString;
    FObjectTypeName := FieldByName('ObjectTypeName').AsString;
    FObjectOwnerID := FieldByName('ObjectOwnerID').AsInteger;
  end;

end;


//--------------------------------------------------
procedure SendMsgToIPensee(AMsg: String);
var
  I, AHandle: Integer;
begin

  AHandle := FindWindow('TfrmMain', nil);

  SendMessage(AHandle, WM_IPENSEE, 1, 0);
  for I := 1 to Length(AMsg) do
  begin
    SendMessage(AHandle, WM_IPENSEE, Ord(AMsg[I]), 0);
  end;
  SendMessage(AHandle, WM_IPENSEE, 0, 0);

end;

end.

⌨️ 快捷键说明

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