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

📄 iwmainform.pas

📁 ODAC 5.7.0.28
💻 PAS
字号:
unit IWMainForm;
{PUBDIST}

interface

uses
  IWAppForm, IWApplication, IWTypes, Classes, Controls, IWControl,
  IWCompRectangle, IWCompButton, IWGrids, IWDBGrids, IWDBStdCtrls,
  IWCompMemo, IWCompEdit, IWCompText, IWCompLabel, DB, MemDS, DBAccess, Ora,
  OraSmart;

type
  TformMain = class(TIWAppForm)
    IWRectangle1: TIWRectangle;
    edUsername: TIWEdit;
    edPassword: TIWEdit;
    edServer: TIWEdit;
    memSQL: TIWMemo;
    IWDBNavigator: TIWDBNavigator;
    IWDBGrid: TIWDBGrid;
    IWButton1: TIWButton;
    IWButton2: TIWButton;
    IWRectangle2: TIWRectangle;
    IWLabel1: TIWLabel;
    IWLabel2: TIWLabel;
    IWLabel3: TIWLabel;
    IWLabel4: TIWLabel;
    IWRectangle3: TIWRectangle;
    OraSession1: TOraSession;
    IWLabel5: TIWLabel;
    lblStateConnection: TIWLabel;
    lblResult: TIWLabel;
    OraDataSource1: TDataSource;
    OraQuery1: TSmartQuery;
    procedure IWButton2Click(Sender: TObject);
    procedure IWButton1Click(Sender: TObject);
    procedure OraSession1AfterConnect(Sender: TObject);
  public
    procedure SetConnectionParams;
  end;

implementation
{$R *.dfm}

uses
  ServerController, Graphics, SysUtils;

{ TformMain }

procedure TformMain.SetConnectionParams;
begin
  OraSession1.Username := edUsername.Text;
  OraSession1.Password := edPassword.Text;
  OraSession1.Server := edServer.Text;
end;

procedure TformMain.IWButton2Click(Sender: TObject);
begin
  OraSession1.Close;
  SetConnectionParams;
  lblResult.Visible := False;
  IWDBGrid.Visible := False;
  IWDBNavigator.Visible := False;
  try
    OraSession1.Open;
  except
    lblStateConnection.Font.Color := clRed;
    lblStateConnection.Caption := 'Failed';
    lblStateConnection.Visible := True;
  end;
end;

procedure TformMain.IWButton1Click(Sender: TObject);
begin
  SetConnectionParams;
  OraQuery1.SQL.Assign(memSQL.Lines);
  IWDBGrid.Columns.Clear;
  try
    OraQuery1.Execute;
    if OraQuery1.Active then begin
      lblResult.Font.Color := clHighlight;
      lblResult.Caption := 'Result';
      lblResult.Visible := True;
      IWDBGrid.Visible := True;
      IWDBNavigator.Visible := True;
    end
    else begin
      lblResult.Font.Color := clHighlight;
      if OraQuery1.RowsAffected >= 0 then
        lblResult.Caption := IntToStr(OraQuery1.RowsAffected) + ' rows affected'
      else
        lblResult.Caption := 'Executed';
      lblResult.Visible := True;
      IWDBGrid.Visible := False;
      IWDBNavigator.Visible := False;
    end;
  except
    on E:Exception do begin
      lblResult.Font.Color := clRed;
      lblResult.Caption := 'Error: '+ E.Message;
      lblResult.Visible := True;
      IWDBGrid.Visible := False;
      IWDBNavigator.Visible := False;
    end;
  end;
end;

procedure TformMain.OraSession1AfterConnect(Sender: TObject);
begin
  lblStateConnection.Font.Color := clHighlight;
  lblStateConnection.Caption := 'Connected';
  lblStateConnection.Visible := True;
end;

end.

⌨️ 快捷键说明

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