PL/SQL ビルダーの作成(1) : 基本部品の配置 : 【VB.NET】

↓ソースコードのダウンロード

ブラウザでダウンロード

(1)基本部品の配置
(2)一覧とソーステキストの表示
(3)既存プロシージャのリビルド
(4)ファンクションの実行
(5)プロシージャの実行
縦3分割 と Dock+Splitter 3分割
最初に、MenuStrip と StatusStrip が配置され、Panel が Fill で Dock しています。
そして Panel の中に、LboxGrid と LboxEditor が配置されています。

StatusStrip は、Statuslabel が選択されています

' ******************************************************
' アプリケーションの終了
' ******************************************************
Private Sub 終了_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles 終了.Click

	Application.Exit()

End Sub

※ 参考
接続ダイアログ
フォーム側に Public な接続用の変数を定義して、
ダイアログはその変数へ入力データをセットします。

Public Server As String = Nothing
Public Service As String = Nothing
Public User As String = Nothing
Public Pass As String = Nothing


	' ******************************************************
	' 初期処理
	' ******************************************************
	Private Sub Dialog1_Load(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles MyBase.Load

		Me.KeyPreview = True
		Me.AcceptButton = Nothing
		Me.TextBox4.PasswordChar = "*"

		If Form1.Server Is Nothing Then
			Me.TextBox1.Text = System.Net.Dns.GetHostName()
		Else
			Me.TextBox1.Text = Form1.Server
		End If

		If Form1.Service Is Nothing Then
			Me.TextBox2.Text = "XE"
		Else
			Me.TextBox2.Text = Form1.Service
		End If

		If Form1.User Is Nothing Then
			Me.TextBox3.Text = "lightbox"
		Else
			Me.TextBox3.Text = Form1.User
		End If

		If Form1.Pass Is Nothing Then
			Me.TextBox4.Text = ""
		Else
			Me.TextBox4.Text = Form1.Pass
		End If

	End Sub


	' ******************************************************
	' OK
	' ******************************************************
	Private Sub OK_Button_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles OK_Button.Click
		Me.DialogResult = System.Windows.Forms.DialogResult.OK

		' 接続データセット
		Form1.Server = Me.TextBox1.Text
		Form1.Service = Me.TextBox2.Text
		Form1.User = Me.TextBox3.Text
		Form1.Pass = Me.TextBox4.Text

		Me.Close()
	End Sub

ダイアログ用の基本機能
Enter キーでフィールドを移動できるようにします。

	' ******************************************************
	' Enter キーで次のコントロールへ移動
	' ( フォームの KeyPreview : True )
	' SelectNextControl パラメータの説明
	' 【forward】
	' タブ オーダー内を前方に移動する場合は true。後方に移動する場合は false。 
	' 【tabStopOnly】
	' TabStop プロパティが false に設定されているコントロールを無視する場合は true。
	' 【nested】
	' 入れ子になった (子コントロールの子) 子コントロールを含める場合は true。 
	' 【wrap】
	' タブ オーダーの最後のコントロールに到達した後、
	' タブ オーダーの最初のコントロールから検索を続行する場合は true 
	'
	' ★ ボタンの場合は押された事になります
	' ******************************************************
	Private Sub Dialog1_KeyPress(ByVal sender As System.Object, _
	ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

		If e.KeyChar = ControlChars.Cr Then
			Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
			e.Handled = True
		End If

	End Sub

処理上の機能の調整
ダイアログは表示後に Server フィールドにフォーカスを移動します。
また、パスワードフィールドは、入力した値を見えなくする必要があります

	' ******************************************************
	' 表示後の初期処理
	' ******************************************************
	Private Sub Dialog1_Shown(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles MyBase.Shown

		Me.TextBox1.Focus()

	End Sub


Me.TextBox4.PasswordChar = "*"

ダイアログで入力後の処理
ダイアログから戻って来ると、接続用のデータが決定しているので接続処理を行ないます。
通常、接続処理は時間のかかる場合があるのでそれを考慮した処理が付加されています
  • フォーム表示の更新
  • 砂時計カーソル
  • 処理が終了するまでフォームを使用不可にする

Imports lightbox.control
Imports lightbox.db


	Public db As DbOracle


	' ******************************************************
	' 接続ダイアログ
	' ******************************************************
	Private Sub 接続_Click(ByVal sender As System.Object, _
	 ByVal e As System.EventArgs) Handles 接続.Click

		' ダイアログの呼び出し
		Dim MyDialog As New Dialog1()
		Dim ret As DialogResult = MyDialog.ShowDialog(Me)
		MyDialog.Dispose()

		' キャンセル時はなにもしない
		If ret = Windows.Forms.DialogResult.Cancel Then
			Exit Sub
		End If

		' 既に一度インスタンスが作成されている場合
		If Not db Is Nothing Then
			db.CloseAndDispose()
		End If

		' Oracle 用インスタンス作成
		db = New DbOracle( _
		 Server + "/" + Service, _
		 User, _
		 Pass _
		)

		' 接続は時間がかかるので再描画
		Me.Update()
		' ウインドウを使用不可
		Me.Enabled = False
		' 砂時計カーソル
		Me.Cursor = Cursors.WaitCursor

		' 接続
		If Not db.Connect() Then
			LboxText.MessageError("接続に失敗しました")
			Console.WriteLine(db.myError)
			' カーソルとウインドウをを元に戻す
			Me.Cursor = Cursors.Default
			Me.Enabled = True
			Exit Sub
		End If

		' 接続解除
		db.Close()

		' カーソルとウインドウをを元に戻す
		Me.Cursor = Cursors.Default
		Me.Enabled = True

	End Sub

↓※ LboxText.MessageError のコードです

	' ******************************************************
	' エラーメッセージボックス
	' ******************************************************
	Public Shared Sub MessageError(ByVal Message As String, ByVal focus As Object)

		Dim ttl As String = "エラー"
		If MessageTitle <> "" Then
			ttl = MessageTitle
		End If

		MessageBox.Show(Message + "   ", ttl, _
		MessageBoxButtons.OK, MessageBoxIcon.Error)
		Try
			focus.Focus()
			If focus.GetType().ToString() = "lightbox.control.LboxText" Then
				CType(focus, LboxText).SelectAll()
			End If
		Catch ex As Exception
		End Try

	End Sub
	Public Shared Sub MessageError(ByVal Message As String)

		Dim ttl As String = "エラー"
		If MessageTitle <> "" Then
			ttl = MessageTitle
		End If

		MessageBox.Show(Message + "   ", ttl, _
		MessageBoxButtons.OK, MessageBoxIcon.Error)

	End Sub