LboxText

  プロパティ用列挙定数



  
Public Enum LboxDataType As Integer

	文字列 = 0
	日付型 = 1
	先行ゼロ = 2
	カンマ編集 = 3

End Enum

Public Enum LboxDbType As Integer

	文字列または日付 = 0
	数値 = 1
	数値としてNULLの時0 = 2
	数値としてNULLの値のDefalut = 3
	文字列または日付としてNULLの時のDefalut = 4

End Enum
  



  プロパティ一覧



  
1) Group
	グループ化して、グループに対する一括処理( プロテクト、クリア ) を可能にする
	( 開発支援クラスメソッド の一括メソッドを参照 : ClearField、Protect )
	※ Protect されている LboxText からは、Validate イベントはユーザで発生しません

2) DataType,DataTypeJ
	編集指定
	※ DataTypeの値がデフォルトの場合のみ、DataTypeJで変更できます
	0:文字列" & Chr(10) & _
	1:YYYY/MM/DD
	2:先行ゼロ文字列(長さはMaxLengthで指定
	3:カンマ編集(String.Formatで使用する文字列を EditFormat で指定


3) CheckType
	0:なし、1:必須入力

4) AllowChar
	セットした文字列のみ入力可能とする

5) CheckValue
	カンマで区切られたそれぞれの文字列以外入力不可とする
	
6) EditFormat
	String.Format の文字列を指定する( DataType 参照 )

7) DbType
	0:シングルクォートで囲む、空ならばNULL
	1:そのまま、空ならばNULL
	2:そのまま、空ならば0
	3:シングルクォートで囲む、空ならばDefalutをシングルクォートで囲む
	4:そのまま、空ならばDefalutをそのまま


8) DbDefault
	SQL 作成時に必要となる未入力データの扱いを決定する

9) DbText
	SQL 作成用の文字列( DbType、DbDefault によって決まる )

10) InnerText
	Text プロパティには編集されたテキストが設定されているので
	内部処理は通常こちらで行う
  



  プロパティ

  
' ****************************************************** 
' 同一処理支援
' ****************************************************** 
Private _Group As Integer = 1
<System.ComponentModel.DefaultValue(1)> _
  Public Property Group() As Integer
	Get
		Return _Group
	End Get
	Set(ByVal value As Integer)
		_Group = value
	End Set
End Property

' ****************************************************** 
' カスタムデータ型
' ****************************************************** 
Private _DataType As Integer = 0
<System.ComponentModel.Description( _
 "DataTypeの値がデフォルトの場合のみ" & Chr(10) & _
 " DataTypeJで変更できます" & Chr(10) & _
 "0:文字列" & Chr(10) & _
 "1:YYYY/MM/DD" & Chr(10) & _
 "2:先行ゼロ文字列(長さはMaxLengthで指定)" & Chr(10) & _
 "3:カンマ編集(String.Formatで使用する文字列を EditFormat で指定)" _
 ), _
 System.ComponentModel.DefaultValue(0)> _
  Public Property DataType() As Integer
	Get
		Return _DataType
	End Get
	Set(ByVal value As Integer)
		_DataType = value
	End Set
End Property
<System.ComponentModel.Description( _
 "DataTypeの値がデフォルトの場合のみ" & Chr(10) & _
 " DataTypeJで変更できます" & Chr(10) & _
 "1:YYYY/MM/DD" & Chr(10) & _
 "2:先行ゼロ文字列(長さはMaxLengthで指定)" & Chr(10) & _
 "3:カンマ編集(String.Formatで使用する文字列を EditFormat で指定)" _
 ), _
 System.ComponentModel.DefaultValue(0)> _
  Public Property DataTypeJ() As LboxDataType
	Get
		Return CType(_DataType, LboxDataType)
	End Get
	Set(ByVal value As LboxDataType)
		If _DataType = 0 Then
			_DataType = CType(value, Integer)
		End If
	End Set
End Property

' ****************************************************** 
' カスタムチェックタイプ
' ****************************************************** 
Private _CheckType As Integer = 0
<System.ComponentModel.Description("0:なし" & Chr(10) & "1:必須入力"), _
 System.ComponentModel.DefaultValue(0)> _
Public Property CheckType() As Integer
	Get
		Return _CheckType
	End Get
	Set(ByVal value As Integer)
		_CheckType = value
	End Set
End Property

' ****************************************************** 
' カスタム入力制限
' ****************************************************** 
Private _AllowChar As String = ""
<System.ComponentModel.Description("セットした文字列のみ入力可能とする"), _
  System.ComponentModel.DefaultValue("")> _
 Public Property AllowChar() As String
	Get
		Return _AllowChar
	End Get
	Set(ByVal value As String)
		_AllowChar = value
	End Set
End Property

' ****************************************************** 
' カスタム入力文字列値チェック
' ****************************************************** 
Private _CheckValue As String = ""
<System.ComponentModel.Description("カンマで区切られたそれぞれの文字列以外入力不可とする"), _
 System.ComponentModel.DefaultValue("")> _
Public Property CheckValue() As String
	Get
		Return _CheckValue
	End Get
	Set(ByVal value As String)
		_CheckValue = value
	End Set
End Property

' ****************************************************** 
' カスタム編集フォーマット
' ****************************************************** 
Private _EditFormat As String = ""
<System.ComponentModel.Description("String.Format の文字列を指定する"), _
  System.ComponentModel.DefaultValue("")> _
  Public Property EditFormat() As String
	Get
		Return _EditFormat
	End Get
	Set(ByVal value As String)
		_EditFormat = value
	End Set
End Property

' ****************************************************** 
' SQL編集用のDBデータ型
' ****************************************************** 
Private _DbDataType As Integer = 0
<System.ComponentModel.Description( _
 "0:文字列・日付" & Chr(10) & _
 "1:数値" & Chr(10) & _
 "2:NULL 時 0(数値)" & Chr(10) & _
 "3:NULL 時 Defalut(数値)" & Chr(10) & _
 "4:NULL 時 Defalut(文字列・日付)" _
 ), _
 System.ComponentModel.DefaultValue(0)> _
  Public Property DbType() As LboxDbType
	Get
		Return _DbDataType
	End Get
	Set(ByVal value As LboxDbType)
		_DbDataType = value
	End Set
End Property

' ****************************************************** 
' SQL用デフォルトデータ
' ****************************************************** 
Private _DbDefault As String = "0"
Public Property DbDefault() As String

	Get
		Return _DbDefault
	End Get
	Set(ByVal value As String)
		_DbDefault = value
	End Set

End Property

' ****************************************************** 
' SQL用文字列としてのデータ
' ****************************************************** 
<System.ComponentModel.Description( _
 "DbTypeにあわせてデータからSQL用文字列を取得" & Chr(10) & _
 "0:シングルクォートで囲む、空ならばNULL" & Chr(10) & _
 "1:そのまま、空ならばNULL" & Chr(10) & _
 "2:そのまま、空ならば0" & Chr(10) & _
 "3:シングルクォートで囲む、空ならばDefalutをシングルクォートで囲む" & Chr(10) & _
 "4:そのまま、空ならばDefalutをそのまま" _
 )> _
Public ReadOnly Property DbText() As String

	Get
		If _DbDataType = 0 Then
			If Me.InnerText = "" Then
				Return "NULL"
			Else
				Return "'" + Me.InnerText + "'"
			End If
		End If
		If _DbDataType = 1 Then
			If Me.InnerText = "" Then
				Return "NULL"
			Else
				Return Me.InnerText
			End If
		End If
		If _DbDataType = 2 Then
			If Me.InnerText = "" Then
				Return "0"
			Else
				Return Me.InnerText
			End If
		End If
		If _DbDataType = 3 Then
			If Me.InnerText = "" Then
				Return _DbDefault
			Else
				Return Me.InnerText
			End If
		End If
		If _DbDataType = 4 Then
			If Me.InnerText = "" Then
				Return _DbDefault
			Else
				Return "'" + Me.InnerText + "'"
			End If
		End If
		Return Me.InnerText
	End Get

End Property

' ****************************************************** 
' 編集されたテキストの処理
' ****************************************************** 
Public Property InnerText() As String

	Get
		If Me._DataType = 3 Then
			Dim str As String = Me.Text
			str = str.Replace(",", "")
			Return str
		Else
			Return Me.Text
		End If
	End Get
	Set(ByVal value As String)

		Dim str As String = ""

		If Me._DataType = 3 Then
			If value <> "" Then
				Try
					str = _
					 String.Format("{0:" + _EditFormat + "}", _
					 Integer.Parse(value))
					Me.Text = str
				Catch ex As Exception
					Me.Text = ""
				End Try
			End If
		Else
			Me.Text = value
		End If
	End Set

End Property
  



  埋め込みイベント

  
Public Shared validateNone As Boolean = False

' ****************************************************** 
' validate コントロール用
' ****************************************************** 
Protected Overloads Overrides Sub OnValidating( _
  ByVal e As System.ComponentModel.CancelEventArgs)

	' ****************************************************** 
	' validateNone が True ならば、Valdating は発生しない 
	' ****************************************************** 
	If Not validateNone Then
		If Me.ReadOnly = False And Me.Enabled = True Then
			MyBase.OnValidating(e)
		End If
	End If

End Sub

Protected Overloads Overrides Sub OnValidated( _
 ByVal e As System.EventArgs)

	' ****************************************************** 
	' validateNone が True ならば、Validated は発生しない 
	' ****************************************************** 
	If Not validateNone Then
		If Me.ReadOnly = False And Me.Enabled = True Then
			MyBase.OnValidated(e)
		End If
	End If

End Sub

' ****************************************************** 
' 編集文字列を省く 
' ****************************************************** 
Private Sub LboxText_Enter(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Enter

	' YYYY/MM/DD
	If Me._DataType = 1 Then
		Me.MaxLength = 8
		Dim str As String = Me.Text
		str = str.Replace("/", "")
		Me.Text = str
	End If

	' カンマ編集
	If Me._DataType = 3 Then
		Dim str As String = Me.Text
		str = str.Replace(",", "")
		Me.Text = str
	End If

End Sub

' ****************************************************** 
' 編集する 
' ****************************************************** 
Private Sub LboxText_Leave(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles MyBase.Leave

	' YYYY/MM/DD
	If Me._DataType = 1 Then
		If Me.Text <> "" Then
			Dim str As String = _
			 Integer.Parse(Me.Text).ToString("0000/00/00")
			Me.Text = str
		End If
	End If

	' 先行ゼロ
	If Me._DataType = 2 Then
		If Me.Text <> "" Then
			' デフォルト 4桁
			If Me.MaxLength > 100 Then
				Me.MaxLength = 4
			End If
			Dim formatString = ""
			For i As Integer = 1 To Me.MaxLength
				formatString += "0"
			Next
			Dim str As String = _
			 Integer.Parse(Me.Text).ToString(formatString)
			Me.Text = str
		End If
	End If

	' カンマ編集
	If Me._DataType = 3 Then
		If Me.Text <> "" Then
			Try
				Dim str As String = _
				 String.Format("{0:" + _EditFormat + "}", _
				 Integer.Parse(Me.Text))
				Me.Text = str
			Catch ex As Exception
				Me.Text = ""
			End Try
		End If
	End If

End Sub

' ****************************************************** 
' 対象文字列以外は入力不可にする
' ****************************************************** 
Private Sub LboxText_KeyPress(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

	' YYYY/MM/DD と先行ゼロは仕様的に数字入力
	If Me._DataType = 1 Or Me._DataType = 2 Then
		If (ControlChars.Back + _
		 "0123456789").IndexOf(e.KeyChar.ToString()) < 0 Then
			e.Handled = True
		Else
			Return
		End If
	End If

	' 正の数以外が仕様に加わった時の為に処理を分ける
	If Me._DataType = 3 Then
		If (ControlChars.Back + _
		 "0123456789").IndexOf(e.KeyChar.ToString()) < 0 Then
			e.Handled = True
		Else
			Return
		End If
	End If

	If Me._AllowChar <> "" Then
		If (ControlChars.Back + _
		 Me._AllowChar).IndexOf(e.KeyChar.ToString()) < 0 Then
			e.Handled = True
		End If
	End If

End Sub

' ****************************************************** 
' 全体のチェック
' ****************************************************** 
Private Sub LboxText_Validating(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Validating

	' 必須入力
	If Me._CheckType = 1 Then
		If (Me.Text).Trim() = "" Then
			Me.Text = ""
		End If
		If Me.Text = "" Then
			MessageBox.Show("必須入力です   ", _
			"エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
			e.Cancel = True
		End If
	End If

	' YYYY/MM/DD
	If Me._DataType = 1 Then
		If Me.Text <> "" Then
			Try
				Dim dt As Date = Date.Parse(Me.Text)
			Catch ex As Exception
				MessageBox.Show("日付を正しく入力して下さい   ", _
				  "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
				Me.SelectAll()
				e.Cancel = True
			End Try
		End If
	End If

	' チェック対象リストでチェック
	If Me.Text <> "" And Me._CheckValue <> "" Then
		Dim delimStr As String = ","
		Dim delimiter As Char() = delimStr.ToCharArray()
		Dim split As String() = Me._CheckValue.Split(delimiter)
		Dim strValue As String
		Dim flg As Boolean = False

		For Each strValue In split
			If Me.Text = strValue Then
				flg = True
			End If
		Next
		If Not flg Then
			MessageBox.Show("入力された値は正しくありません   ", _
			"エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Me.SelectAll()
			e.Cancel = True
		End If

	End If

End Sub
  



  開発支援クラスメソッド

  
Public Shared MessageTitle As String = ""

' ******************************************************
' OK/CANCEL 選択メッセージボックス
' ******************************************************
Public Shared Function MessageOkCancel(ByVal Message As String) As Boolean

	Dim ttl As String = "選択"
	If MessageTitle <> "" Then
		ttl = MessageTitle
	End If

	If MessageBox.Show(Message + "   ", ttl, _
	MessageBoxButtons.OKCancel, MessageBoxIcon.Question,  _
		MessageBoxDefaultButton.Button2) = DialogResult.OK Then
		Return True
	Else
		Return False
	End If

End Function

' ******************************************************
' YES/NO 選択メッセージボックス
' ******************************************************
Public Shared Function MessageYesNo(ByVal Message As String) As Boolean

	Dim ttl As String = "選択"
	If MessageTitle <> "" Then
		ttl = MessageTitle
	End If

	If MessageBox.Show(Message + "   ", ttl, _
	MessageBoxButtons.YesNo, MessageBoxIcon.Question,  _
		MessageBoxDefaultButton.Button2) = DialogResult.Yes Then
		Return True
	Else
		Return False
	End If

End Function

' ******************************************************
' 単純確認メッセージボックス
' ******************************************************
Public Shared Sub MessageOk(ByVal Message As String)

	Dim ttl As String = "確認"
	If MessageTitle <> "" Then
		ttl = MessageTitle
	End If

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

End Sub

' ******************************************************
' エラーメッセージボックス
' ******************************************************
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

' ******************************************************
' ダイアログ呼び出し
' ******************************************************
Public Shared Function OpenDialog(ByRef target As Form, _
ByVal Owner As Object) As DialogResult

	Dim ret As DialogResult = target.ShowDialog(Owner)
	target.Dispose()
	Return ret

End Function

' ******************************************************
' 一括クリア
' ******************************************************
Public Shared Sub ClearField(ByVal top As Object, ByVal target As Integer)

	ClearFieldSetting(top, target)

End Sub

Private Shared Sub ClearFieldSetting( _
 ByVal targetObj As Object, _
 ByVal target As Integer)

	Dim obj As Object

	For Each obj In targetObj.Controls
		Try
			ClearFieldSetting(obj, target)
			If obj.GetType().ToString() = "lightbox.control.LboxText" Then
				If CType(obj, LboxText).Group = target Then
					CType(obj, LboxText).Clear()
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxCombo" Then
				If CType(obj, LboxCombo).Group = target Then
					CType(obj, LboxCombo).SelectedIndex = -1
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxCheck" Then
				If CType(obj, LboxCheck).Group = target Then
					CType(obj, LboxCheck).Checked = False
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxRadio" Then
				If CType(obj, LboxRadio).Group = target Then
					CType(obj, LboxRadio).Checked = False
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxDate" Then
				If CType(obj, LboxDate).Group = target Then
					CType(obj, LboxDate).Checked = False
					CType(obj, LboxDate).Value = Date.Today
				End If
			End If
		Catch ex As Exception

		End Try
	Next

End Sub

' ******************************************************
' 一括プロテクト
' ******************************************************
Public Shared Sub Protect(ByVal top As Object, _
ByVal target As Integer, ByVal flg As Boolean)

	ProtectSetting(top, target, flg)

End Sub

Private Shared Sub ProtectSetting( _
 ByVal targetObj As Object, _
 ByVal target As Integer, _
 ByVal flg As Boolean)

	Dim obj As Object

	For Each obj In targetObj.Controls
		Try
			ProtectSetting(obj, target, flg)
			If obj.GetType().ToString() = "lightbox.control.LboxText" Then
				If obj.Group = target Then
					obj.ReadOnly = flg
					obj.TabStop = Not flg
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxCombo" Then
				If obj.Group = target Then
					obj.Enabled = Not flg
					obj.TabStop = Not flg
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxButton" Then
				If obj.Group = target Then
					obj.Enabled = Not flg
					obj.TabStop = Not flg
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxRadio" Then
				If obj.Group = target Then
					obj.Enabled = Not flg
					obj.TabStop = Not flg
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxCheck" Then
				If obj.Group = target Then
					obj.Enabled = Not flg
					obj.TabStop = Not flg
				End If
			End If
			If obj.GetType().ToString() = "lightbox.control.LboxDate" Then
				If obj.Group = target Then
					obj.Enabled = Not flg
					obj.TabStop = Not flg
				End If
			End If
		Catch ex As Exception

		End Try
	Next

End Sub
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ