Imports OracleInProcServer

Public Class frmParamOO4O
    Inherits System.Windows.Forms.Form

#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    ' Form は dispose をオーバーライドしてコンポーネント一覧を消去します。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Windows フォーム デザイナで必要です。
    Private components As System.ComponentModel.IContainer

    ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。
    ' Windows フォーム デザイナを使って変更してください。  
    ' コード エディタは使用しないでください。
    Friend WithEvents tmrLoad As System.Windows.Forms.Timer
    Friend WithEvents cmdGetSQLAREA As System.Windows.Forms.Button
    Friend WithEvents cmdUpdate As System.Windows.Forms.Button
    Friend WithEvents txtDEPTNO As System.Windows.Forms.TextBox
    Friend WithEvents lblDEPTNO As System.Windows.Forms.Label
    Friend WithEvents txtSAL As System.Windows.Forms.TextBox
    Friend WithEvents lblSAL As System.Windows.Forms.Label
    Friend WithEvents txtHIREDATE As System.Windows.Forms.TextBox
    Friend WithEvents lblHIREDATE As System.Windows.Forms.Label
    Friend WithEvents txtJOB As System.Windows.Forms.TextBox
    Friend WithEvents lblJOB As System.Windows.Forms.Label
    Friend WithEvents txtENAME As System.Windows.Forms.TextBox
    Friend WithEvents lblENAME As System.Windows.Forms.Label
    Friend WithEvents txtEMPNO As System.Windows.Forms.TextBox
    Friend WithEvents lblEMPNO As System.Windows.Forms.Label
    Friend WithEvents cmdQuery As System.Windows.Forms.Button
    Friend WithEvents lblSQL As System.Windows.Forms.Label
    Friend WithEvents txtParam As System.Windows.Forms.TextBox
    Friend WithEvents lblParam As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.tmrLoad = New System.Windows.Forms.Timer(Me.components)
        Me.cmdGetSQLAREA = New System.Windows.Forms.Button()
        Me.cmdUpdate = New System.Windows.Forms.Button()
        Me.txtDEPTNO = New System.Windows.Forms.TextBox()
        Me.lblDEPTNO = New System.Windows.Forms.Label()
        Me.txtSAL = New System.Windows.Forms.TextBox()
        Me.lblSAL = New System.Windows.Forms.Label()
        Me.txtHIREDATE = New System.Windows.Forms.TextBox()
        Me.lblHIREDATE = New System.Windows.Forms.Label()
        Me.txtJOB = New System.Windows.Forms.TextBox()
        Me.lblJOB = New System.Windows.Forms.Label()
        Me.txtENAME = New System.Windows.Forms.TextBox()
        Me.lblENAME = New System.Windows.Forms.Label()
        Me.txtEMPNO = New System.Windows.Forms.TextBox()
        Me.lblEMPNO = New System.Windows.Forms.Label()
        Me.cmdQuery = New System.Windows.Forms.Button()
        Me.lblSQL = New System.Windows.Forms.Label()
        Me.txtParam = New System.Windows.Forms.TextBox()
        Me.lblParam = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'tmrLoad
        '
        Me.tmrLoad.Interval = 1
        '
        'cmdGetSQLAREA
        '
        Me.cmdGetSQLAREA.Location = New System.Drawing.Point(8, 254)
        Me.cmdGetSQLAREA.Name = "cmdGetSQLAREA"
        Me.cmdGetSQLAREA.Size = New System.Drawing.Size(72, 24)
        Me.cmdGetSQLAREA.TabIndex = 14
        Me.cmdGetSQLAREA.Text = "&SQLAREA"
        '
        'cmdUpdate
        '
        Me.cmdUpdate.Location = New System.Drawing.Point(312, 255)
        Me.cmdUpdate.Name = "cmdUpdate"
        Me.cmdUpdate.Size = New System.Drawing.Size(72, 24)
        Me.cmdUpdate.TabIndex = 15
        Me.cmdUpdate.Text = "&Update"
        '
        'txtDEPTNO
        '
        Me.txtDEPTNO.Location = New System.Drawing.Point(112, 220)
        Me.txtDEPTNO.MaxLength = 2
        Me.txtDEPTNO.Name = "txtDEPTNO"
        Me.txtDEPTNO.Size = New System.Drawing.Size(272, 19)
        Me.txtDEPTNO.TabIndex = 13
        Me.txtDEPTNO.Text = "txtDEPTNO"
        '
        'lblDEPTNO
        '
        Me.lblDEPTNO.Location = New System.Drawing.Point(8, 221)
        Me.lblDEPTNO.Name = "lblDEPTNO"
        Me.lblDEPTNO.Size = New System.Drawing.Size(96, 16)
        Me.lblDEPTNO.TabIndex = 12
        Me.lblDEPTNO.Text = "DEPTNO:"
        Me.lblDEPTNO.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'txtSAL
        '
        Me.txtSAL.Location = New System.Drawing.Point(112, 189)
        Me.txtSAL.Name = "txtSAL"
        Me.txtSAL.Size = New System.Drawing.Size(272, 19)
        Me.txtSAL.TabIndex = 11
        Me.txtSAL.Text = "txtSAL"
        Me.txtSAL.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'lblSAL
        '
        Me.lblSAL.Location = New System.Drawing.Point(8, 190)
        Me.lblSAL.Name = "lblSAL"
        Me.lblSAL.Size = New System.Drawing.Size(96, 16)
        Me.lblSAL.TabIndex = 10
        Me.lblSAL.Text = "SAL:"
        Me.lblSAL.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'txtHIREDATE
        '
        Me.txtHIREDATE.Location = New System.Drawing.Point(112, 158)
        Me.txtHIREDATE.Name = "txtHIREDATE"
        Me.txtHIREDATE.Size = New System.Drawing.Size(272, 19)
        Me.txtHIREDATE.TabIndex = 9
        Me.txtHIREDATE.Text = "txtHIREDATE"
        '
        'lblHIREDATE
        '
        Me.lblHIREDATE.Location = New System.Drawing.Point(8, 159)
        Me.lblHIREDATE.Name = "lblHIREDATE"
        Me.lblHIREDATE.Size = New System.Drawing.Size(96, 16)
        Me.lblHIREDATE.TabIndex = 8
        Me.lblHIREDATE.Text = "HIREDATE:"
        Me.lblHIREDATE.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'txtJOB
        '
        Me.txtJOB.Location = New System.Drawing.Point(112, 127)
        Me.txtJOB.MaxLength = 9
        Me.txtJOB.Name = "txtJOB"
        Me.txtJOB.Size = New System.Drawing.Size(272, 19)
        Me.txtJOB.TabIndex = 7
        Me.txtJOB.Text = "txtJOB"
        '
        'lblJOB
        '
        Me.lblJOB.Location = New System.Drawing.Point(8, 128)
        Me.lblJOB.Name = "lblJOB"
        Me.lblJOB.Size = New System.Drawing.Size(96, 16)
        Me.lblJOB.TabIndex = 6
        Me.lblJOB.Text = "JOB:"
        Me.lblJOB.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'txtENAME
        '
        Me.txtENAME.Location = New System.Drawing.Point(112, 96)
        Me.txtENAME.MaxLength = 10
        Me.txtENAME.Name = "txtENAME"
        Me.txtENAME.Size = New System.Drawing.Size(272, 19)
        Me.txtENAME.TabIndex = 5
        Me.txtENAME.Text = "txtENAME"
        '
        'lblENAME
        '
        Me.lblENAME.Location = New System.Drawing.Point(8, 97)
        Me.lblENAME.Name = "lblENAME"
        Me.lblENAME.Size = New System.Drawing.Size(96, 16)
        Me.lblENAME.TabIndex = 4
        Me.lblENAME.Text = "ENAME:"
        Me.lblENAME.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'txtEMPNO
        '
        Me.txtEMPNO.Location = New System.Drawing.Point(112, 65)
        Me.txtEMPNO.MaxLength = 4
        Me.txtEMPNO.Name = "txtEMPNO"
        Me.txtEMPNO.ReadOnly = True
        Me.txtEMPNO.Size = New System.Drawing.Size(272, 19)
        Me.txtEMPNO.TabIndex = 3
        Me.txtEMPNO.Text = "txtEMPNO"
        '
        'lblEMPNO
        '
        Me.lblEMPNO.Location = New System.Drawing.Point(8, 66)
        Me.lblEMPNO.Name = "lblEMPNO"
        Me.lblEMPNO.Size = New System.Drawing.Size(96, 16)
        Me.lblEMPNO.TabIndex = 2
        Me.lblEMPNO.Text = "EMPNO:"
        Me.lblEMPNO.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'cmdQuery
        '
        Me.cmdQuery.Location = New System.Drawing.Point(312, 31)
        Me.cmdQuery.Name = "cmdQuery"
        Me.cmdQuery.Size = New System.Drawing.Size(72, 24)
        Me.cmdQuery.TabIndex = 1
        Me.cmdQuery.Text = "&Query"
        '
        'lblSQL
        '
        Me.lblSQL.Location = New System.Drawing.Point(8, 2)
        Me.lblSQL.Name = "lblSQL"
        Me.lblSQL.Size = New System.Drawing.Size(296, 22)
        Me.lblSQL.TabIndex = 0
        Me.lblSQL.Text = "SELECT * FROM SCOTT.EMP WHERE EMPNO=:VAR"
        Me.lblSQL.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'txtParam
        '
        Me.txtParam.Location = New System.Drawing.Point(112, 34)
        Me.txtParam.MaxLength = 10
        Me.txtParam.Name = "txtParam"
        Me.txtParam.Size = New System.Drawing.Size(184, 19)
        Me.txtParam.TabIndex = 17
        Me.txtParam.Text = "txtParam"
        '
        'lblParam
        '
        Me.lblParam.Location = New System.Drawing.Point(8, 35)
        Me.lblParam.Name = "lblParam"
        Me.lblParam.Size = New System.Drawing.Size(96, 16)
        Me.lblParam.TabIndex = 16
        Me.lblParam.Text = "パラメタ(&P):"
        Me.lblParam.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'frmParamOO4O
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(392, 294)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtParam, Me.lblParam, Me.cmdUpdate, Me.txtDEPTNO, Me.lblDEPTNO, Me.txtSAL, Me.lblSAL, Me.txtHIREDATE, Me.lblHIREDATE, Me.txtJOB, Me.lblJOB, Me.txtENAME, Me.lblENAME, Me.txtEMPNO, Me.lblEMPNO, Me.cmdQuery, Me.lblSQL, Me.cmdGetSQLAREA})
        Me.Name = "frmParamOO4O"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Parameter OO4O"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmParmOO4O_Load(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) Handles MyBase.Load
        Me.txtParam.Text = "7876"
        Me.txtEMPNO.Text = ""
        Me.txtENAME.Text = ""
        Me.txtJOB.Text = ""
        Me.txtHIREDATE.Text = ""
        Me.txtSAL.Text = ""
        Me.txtDEPTNO.Text = ""
        Me.cmdUpdate.Enabled = False
        tmrLoad.Enabled = True
    End Sub

    Private Sub tmrLoad_Tick(ByVal sender As System.Object, _
                             ByVal e As System.EventArgs) Handles tmrLoad.Tick
        Dim frmLogon As Form = New frmLogonOO4O()
        Dim intRet As MsgBoxResult

        tmrLoad.Enabled = False
        Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()
        intRet = frmLogon.ShowDialog()
        frmLogon.Dispose()
        frmLogon = Nothing
        Me.Cursor = System.Windows.Forms.Cursors.Default
        If intRet = MsgBoxResult.Cancel Then
            Me.Close()
        End If
    End Sub

    Private Sub cmdQuery_Click(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) Handles cmdQuery.Click
        Dim oraDs As OraDynaset
        Dim strSQL As String = Me.lblSQL.Text.Trim
        Dim strErrText As String

        Try
            Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()
            Me.cmdUpdate.Enabled = False
            '
            p_oraDb.Parameters.add("VAR", _
                                   Me.txtParam.Text.Trim, _
                                   paramMode.ORAPARM_INPUT)
            oraDs = p_oraDb.CreateDynaset(strSQL, _
                                          dynOption.ORADYN_READONLY)
            If Not oraDs.EOF Then
                Me.txtEMPNO.Text = Format(CLng(oraDs.Fields("EMPNO").value), "0000")
                Me.txtENAME.Text = oraDs.Fields("ENAME").value
                Me.txtJOB.Text = oraDs.Fields("JOB").value
                Me.txtHIREDATE.Text = Format(CDate(oraDs.Fields("HIREDATE").value), "yyyy/MM/dd")
                Me.txtSAL.Text = Format(CSng(oraDs.Fields("SAL").value), "####0.00")
                Me.txtDEPTNO.Text = Format(CLng(oraDs.Fields("DEPTNO").value), "00")
                Me.cmdUpdate.Enabled = True
                Me.txtParam.Enabled = False
            Else
                Me.txtEMPNO.Text = ""
                Me.txtENAME.Text = ""
                Me.txtJOB.Text = ""
                Me.txtHIREDATE.Text = ""
                Me.txtSAL.Text = ""
                Me.txtDEPTNO.Text = ""
                Me.txtParam.Enabled = True
            End If
        Catch
            strErrText = ErrorToString()
            MsgBox(strErrText, _
                   MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, _
                   Me.Text)
        Finally
            p_oraDb.Parameters.remove("VAR")
            Me.Cursor = System.Windows.Forms.Cursors.Default
        End Try
    End Sub

    Private Sub cmdUpdate_Click(ByVal sender As System.Object, _
                                ByVal e As System.EventArgs) Handles cmdUpdate.Click
        Dim oraDs As OraDynaset
        Dim strSQL As String = Me.lblSQL.Text.Trim
        Dim strErrText As String

        Try
            Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()
            '
            p_oraDb.Parameters.add("VAR", _
                                   Me.txtParam.Text.Trim, _
                                   paramMode.ORAPARM_INPUT)
            oraDs = p_oraDb.CreateDynaset(strSQL, _
                                          dynOption.ORADYN_ORAMODE)
            If Not oraDs.EOF Then
                oraDs.Edit()
            Else
                oraDs.AddNew()
                oraDs.Fields("EMPNO").value = CLng(Me.txtEMPNO.Text)

            End If
            oraDs.Fields("ENAME").value = Me.txtENAME.Text.Trim
            oraDs.Fields("JOB").value = Me.txtJOB.Text.Trim
            oraDs.Fields("HIREDATE").value = Me.txtHIREDATE.Text
            oraDs.Fields("SAL").value = Me.txtSAL.Text.Trim
            oraDs.Fields("DEPTNO").value = Me.txtDEPTNO.Text.Trim
            oraDs.Update()
            '
            Me.cmdUpdate.Enabled = False
            Me.txtParam.Enabled = True
        Catch
            strErrText = ErrorToString()
            MsgBox(strErrText, _
                   MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, _
                   Me.Text)
        Finally
            p_oraDb.Parameters.remove("VAR")
            Me.Cursor = System.Windows.Forms.Cursors.Default
        End Try
    End Sub

    Private Sub cmdGetSQLAREA_Click(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs) Handles cmdGetSQLAREA.Click

        Dim frmSQLArea As Form = New frmSQLAreaOO4O()

        frmSQLArea.Show()
    End Sub
End Class
