106 lines
3.8 KiB
VB.net
106 lines
3.8 KiB
VB.net
Public Class lov
|
|
Dim Dt As New DataTable
|
|
Dim A As New System.Text.StringBuilder
|
|
|
|
Public Msg As String = "" '//lov가 반환한 메세지 : O일경우를 제외하고 반환된다.
|
|
Public Row As DataRowView = Nothing '//반환된 데이터로우 : O 이거나 1 일때만 반환된다.
|
|
Public StatusE As rStatus
|
|
Public Enum rStatus
|
|
NotFound = 1 '//검색어에대한 데이터가 없다
|
|
OneRow = 2 '//하나밖에없었다(ok)
|
|
Multirow = 3 '//여러개의 데이터가 조재한다.
|
|
Canceld = 4 '//취소되었다.
|
|
End Enum
|
|
#Region "New Function"
|
|
Public Sub New()
|
|
InitializeComponent()
|
|
End Sub
|
|
Public Sub New(ByVal Dtable As DataTable, Optional ByVal ImeMode As System.Windows.Forms.ImeMode = Windows.Forms.ImeMode.Hangul)
|
|
' 이 호출은 Windows Form 디자이너에 필요합니다.
|
|
Dt = Dtable
|
|
InitializeComponent()
|
|
Me.BindingSource1.DataSource = Dt
|
|
Me.DataGridView1.DataSource = Me.BindingSource1
|
|
Me.tb_searchtext.ImeMode = ImeMode
|
|
End Sub
|
|
#End Region
|
|
|
|
#Region "OK/CANCEL 버튼"
|
|
Private Sub Prc_OK()
|
|
Msg = "사용자선택"
|
|
Row = Me.BindingSource1.Current
|
|
StatusE = rStatus.OneRow
|
|
Me.DialogResult = System.Windows.Forms.DialogResult.OK
|
|
Me.Close()
|
|
End Sub
|
|
|
|
Private Sub Prc_CalCel()
|
|
Msg = "사용자취소"
|
|
Row = Nothing
|
|
StatusE = rStatus.Canceld
|
|
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
|
Me.Close()
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
|
|
''' <summary>
|
|
''' where 절을 생성한후 리턴(모든 열에대한 같은 where like 절
|
|
''' </summary>
|
|
''' <returns></returns>
|
|
''' <remarks></remarks>
|
|
Private Function WhereState() As String
|
|
A.Remove(0, A.Length)
|
|
For i As Integer = 0 To Me.Dt.Columns.Count - 1
|
|
|
|
If Dt.Columns(i).DataType.Name.ToUpper = "STRING" Then
|
|
A.Append(IIf(i = 0, "", Space(1) & "or ") & Dt.Columns(i).Caption & " like '" & Me.tb_searchtext.Text & "%'")
|
|
End If
|
|
Next
|
|
Return A.ToString
|
|
End Function
|
|
|
|
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tb_searchtext.TextChanged
|
|
Me.BindingSource1.Filter = Me.WhereState
|
|
End Sub
|
|
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tb_searchtext.KeyDown
|
|
Select Case e.KeyCode
|
|
Case Keys.Down, Keys.Enter
|
|
Me.DataGridView1.Focus()
|
|
If Me.datagridview1.ActiveSheet.RowCount = 1 Then Me.Prc_OK()
|
|
Case Keys.Escape
|
|
Me.Prc_CalCel()
|
|
End Select
|
|
End Sub
|
|
|
|
|
|
Private Sub datagridview1_CellDoubleClick(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles datagridview1.CellDoubleClick
|
|
Me.Prc_OK()
|
|
End Sub
|
|
|
|
Private Sub datagridview1_KeyDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles datagridview1.KeyDown
|
|
Select Case e.KeyCode
|
|
Case Keys.F5
|
|
Case Keys.Escape
|
|
Me.tb_searchtext.Focus()
|
|
Case Keys.Enter
|
|
Me.Prc_OK()
|
|
End Select
|
|
End Sub
|
|
|
|
Private Sub datagridview1_KeyUp1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles datagridview1.KeyUp
|
|
Select Case e.KeyCode
|
|
Case Keys.Escape
|
|
Me.tb_searchtext.Focus()
|
|
End Select
|
|
End Sub
|
|
|
|
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
|
|
Me.Prc_OK()
|
|
End Sub
|
|
|
|
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
|
|
Me.Prc_CalCel()
|
|
End Sub
|
|
End Class |