Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing
<ToolboxBitmap(GetType(DataGridView))> _
Public Class usrCtrGridControlExt : Inherits DataGridView 'สร้างมาจากต้นแบบ DataGridView
#Region " Enumerations "
Public Enum DataGridViewDisplayManager As Byte
[Default] = 0
Framework = 1
End Enum
Public Enum DataGridViewOnEnterEditModeMove As Byte
Right = 0
Down = 1
End Enum
Public Enum DataGridViewOnEnterModeMove As Byte
Right = 0
Down = 1
End Enum
Public Enum DataGridViewLastColumnVisible As Short
Last = 0
End Enum
Public Enum DataGridViewFirstColumnVisible As Short
First = 0
End Enum
'Public Enum DataGridViewColumnsCount As Short
' ColumnsCount = 100
'End Enum
Public Enum TextBoxDisplayManager As Byte
TextCharacter = 0
TextNumber = 1
TextInteger = 2
End Enum
Public Enum TextBoxDisplayPrecisionScale As Byte
None = 0
One = 1
Two = 2
Tree = 3
Four = 4
End Enum
#End Region
#Region " Variables "
Private _DisplayManager As DataGridViewDisplayManager = DataGridViewDisplayManager.Default
Private _OnEnterEditModeMove As DataGridViewOnEnterEditModeMove = DataGridViewOnEnterEditModeMove.Right
Private _OnEnterModeMove As DataGridViewOnEnterModeMove = DataGridViewOnEnterModeMove.Right
Private _OnSortedFindKey As String 'กรณีที่ column.Sorted.Value Duplicate เช่น 1-a , 2-a เป็นต้น เก็บค่า 1 หรือ 2 เพื่อเปรียบเทียบ
Private _CellIsBeginEdit As Boolean = False 'CurrentCell มีการแก้ไข
Private _CellIsBeginEditRow As Integer = -1 'CurrentCell.RowIndex ก่อนมีการแก้ไข
Private _CellIsBeginEditCol As UShort 'Max 60,000 Columns
Private _LastColumnVisible As UShort 'Column สุดท้ายที่ Visible
Private _FirstColumnVisible As UShort 'Column แรกที่ Visible
'Private _DisplayPrecisionScale As TextBoxDisplayPrecisionScale 'จำนวนจุดทศนิยม
'Private _ColumnsCount As Short 'DataGridViewColumnsCount 'จำนวนคอลัมน์ที่สร้างครั้งแรก
Private bsGrid As New BindingSource
Private DTControlGrid As New DataTable("DTControlGrid")
Private DTControlGridEnumerable As System.Data.EnumerableRowCollection(Of DataRow) 'เอาไว้ค้นหาข้อมูลในกริดโดยเฉพาะ และเพื่อเพิ่มความเร็ว
Private SortPattern As New SortedList 'เอาไว้จัดเรียงข้อมูลในกริด
#End Region
#Region " Properties "
<System.ComponentModel.DefaultValue(GetType(DataGridViewDisplayManager), "Default"), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("กำหนดคุณสมบัติ")> _
Public Property DisplayManager() As DataGridViewDisplayManager
Get
Return _DisplayManager
End Get
Set(ByVal value As DataGridViewDisplayManager)
_DisplayManager = value
If Me._DisplayManager = DataGridViewDisplayManager.Framework Then
Me.DisplayManagerEnterEditModeMove = DataGridViewOnEnterEditModeMove.Right
Me.DisplayManagerEnterModeMove = DataGridViewOnEnterModeMove.Right
Else
'Set To Default
Me.DisplayManagerEnterEditModeMove = DataGridViewOnEnterEditModeMove.Down
Me.DisplayManagerEnterModeMove = DataGridViewOnEnterModeMove.Down
End If
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(DataGridViewOnEnterEditModeMove), "No"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayManagerEnterEditModeMove() As DataGridViewOnEnterEditModeMove
Get
Return _OnEnterEditModeMove
End Get
Set(ByVal Value As DataGridViewOnEnterEditModeMove)
_OnEnterEditModeMove = Value
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(DataGridViewOnEnterEditModeMove), "First"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayManagerEnterModeMove() As DataGridViewOnEnterModeMove
Get
Return _OnEnterModeMove
End Get
Set(ByVal Value As DataGridViewOnEnterModeMove)
_OnEnterModeMove = Value
End Set
End Property
<System.ComponentModel.DefaultValue(""), System.ComponentModel.Category("Appearance")> _
Public Property DisplayManagerSortedFindKey() As String
Get
Return _OnSortedFindKey
End Get
Set(ByVal value As String)
_OnSortedFindKey = value
End Set
End Property
<System.ComponentModel.DefaultValue(0), System.ComponentModel.Category("Appearance")> _
Public Property DisplayManagerFirstColumnVisible() As String
Get
Return _FirstColumnVisible
End Get
Set(ByVal value As String)
_FirstColumnVisible = value
End Set
End Property
<System.ComponentModel.DefaultValue(0), System.ComponentModel.Category("Appearance")> _
Public Property DisplayManagerLastColumnVisible() As String
Get
Return _LastColumnVisible
End Get
Set(ByVal value As String)
_LastColumnVisible = value
End Set
End Property
#End Region
#Region " Constructor "
Public Sub New()
'
'Me.ColumnCount = 100 'กำหนดจำนวนคอลัมน์ เมื่อตอนสร้างครั้งแรก เท่ากับ 100 คอลัมน์
'For i As Short = 0 To 99
' Me.Columns(i).HeaderText = i.ToString
'Next
Me.EnableHeadersVisualStyles = True
Me.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
Me.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 'ข้อความบน Header จัดเรียงตรงกลาง
Me.ColumnHeadersHeight = 40 'กำหนดความสูงของ Header Grid
End Sub
#End Region
Public Sub SetNew(ByVal pDataSet As DataSet, ByVal pDataTable As DataTable, ByVal pBab As String)
'Me.Cursor = Cursors.WaitCursor
'Dim dbSubMgr As New DBHelper
'Dim S_gbab As New DataTable("S_gbab") 'เก็บค่าต้นแบบกริด สัมพันธ์กับ Table s_field, s_file1
'Dim S_field As New DataTable("S_field") 'เก็บคุณสมบัติของ pDataTable.Fieldxxx เช่น ประเภท ขนาด และการจัดเรียง C_M_NAME + C_M_SURE เป็นต้น
'Dim S_fieldList As New ArrayList 'เก็บชื่อฟิลด์ของ pDataTable เอาไว้เปรียบเทียบกับ S_gbab.c_fld_xx ในกรณีที่มีการเปลี่ยนแปลงโครงสร้าง Table
'DTControlGrid = pDataTable
'bsGrid.DataSource = pDataSet
'bsGrid.DataMember = pDataTable.TableName
'DTControlGridEnumerable = From dt In pDataTable.AsEnumerable() Select dt 'เอาไว้ค้นหาข้อมูลในกริดโดยเฉพาะ (เร็วกว่า DataTable.Select)
'Me.AllowUserToDeleteRows = False 'ไม่ให้ลบแถวที่เลือก
'Me.AllowUserToOrderColumns = True 'อนุญาติให้ย้ายตำแหน่ง Column ได้ (Drag)
'For i As UShort = 0 To pDataTable.Columns.Count - 1 'เอาไว้ตรวจสอบว่า S_gbab.C_fld_xx มีอยู่จริงใน Table หรือไม่ (อาจมีการปรับเปลี่ยนโครงสร้าง Table)
' S_fieldList.Add(pDataTable.Columns(i).ColumnName.ToUpper().Trim())
' SortPattern.Add(S_fieldList(i), "") 'เก็บรูปแบบการจัดเรียงข้อมูล ในกรณีที่จัดเรียงมากกวา 1 Columns เช่น C_M_NAME , C_M_SURE เป็นต้น
' '21 พ.ย. 2552
' 'pDataTable.Columns(i).ColumnName = "Hide" & pDataTable.Columns(i).ColumnName 'เตรียมเอาไว้สำหรับซ่อน Columns ตามที่ต้องการ
' '
'Next
'S_field = dbSubMgr.GetTableSystem("Select * from S_field Where C_file='" & pDataTable.TableName.ToUpper & "' " & _
' "Order by N_order Asc", S_field)
'S_gbab = dbSubMgr.GetTableSystem("Select * from S_gbab Where C_bab_code='" & pBab & "'", S_gbab)
'Me.Cursor = Cursors.Default
'Dim cHeaderText As String = String.Empty 'ข้อความหัวของกริด
'Dim cFieldValueS_gbab As String = String.Empty 'ค่าในฟิลด์ C_fld_01 --> C_fld_xx
'Dim S_fieldDataRow As DataRow = Nothing 'อ่านโครงสร้างฟิลด์จาก Table S_field
'Dim cFieldType As String = String.Empty 'ชื่อประเภทฟิลด์ เช่น Character , Memo เป็นต้น
'Dim cColumnName As String = String.Empty 'ชื่อแต่ละคอลัมภ์ของ pDataTable ที่ควบคุมกริด
'Dim cTableName As String = pDataTable.TableName.Trim().ToUpper() 'ชื่อเทเบิล ที่ควบคุมกริด
'For i As Integer = 0 To S_fieldList.Count - 1 'เผื่อมีขยะอยู่ใน S_field ในกรณีที่มีการเปลี่ยนโครงสร้าง Table
' S_fieldDataRow = GetS_field(S_field, cTableName, S_fieldList(i))
' If S_fieldDataRow IsNot Nothing Then
' If String.Format("{0}", S_fieldDataRow.Item("C_gsort")).Trim() <> String.Empty Then
' SortPattern(S_fieldList(i)) = String.Format("{0}", S_fieldDataRow.Item("C_gsort")).Trim() 'ตัดช่องว่างด้านหน้า/หลัง ออกให้หมด
' End If
' End If
'Next
'If S_gbab.Rows.Count > 0 Then 'มีแบบอยู่ในไฟล์ S_gbab
' Select Case String.Format("{0}", S_gbab.Rows(0).Item("L_fld_all")).Trim()
' Case "0" 'แสดงทั้งหมด และจัดเรียงตาม C_fld_01 ถึง C_fld_xx
' Me.AutoGenerateColumns = True 'Performance Speed
' Me.DataSource = bsGrid
' For i As UShort = 0 To pDataTable.Columns.Count - 1
' Me.Columns(i).Name = pDataTable.Columns(i).ColumnName.ToUpper()
' Me.Columns(i).SortMode = DataGridViewColumnSortMode.Programmatic
' Me.Columns(i).HeaderText = Me.Columns(i).Name
' S_fieldDataRow = GetS_field(S_field, cTableName, Me.Columns(i).Name)
' Call SetFormatGridAll(i, S_fieldDataRow, pDataTable.Columns(i).DataType.ToString, Me.Columns(i).Name, Me.Columns(i))
' Next
' Dim iCount As Integer = 0 'จริงฯ ไม่น่าจะเกิน 65,000 Columns ควรจะใช้ UShort
' For i As UShort = 0 To S_gbab.Columns.Count - 1
' If S_gbab.Columns(i).ColumnName.ToLower.Contains("c_fld_") Then 'for Unlimit c_fld_xx
' If String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim <> String.Empty Then
' cFieldValueS_gbab = String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim().ToUpper() 'S_gbab.c_fld_xxx
' If S_fieldList.Contains(cFieldValueS_gbab) = True Then
' Me.Columns(cFieldValueS_gbab).HeaderCell.Style.BackColor = Color.Goldenrod
' Me.Columns(cFieldValueS_gbab).DisplayIndex = iCount
' iCount += 1
' End If
' End If
' End If
' Next
' Case "1" 'แสดงเฉพาะค่าในฟิลด์และจัดเรียงตาม C_fld_01 ถึง C_fld_xx ( And Not Empty C_fld_xx.Value)
' For i As UShort = 0 To S_gbab.Columns.Count - 1
' If S_gbab.Columns(i).ColumnName.ToLower.Contains("c_fld_") Then 'for Unlimit c_fld_xx
' If String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim <> String.Empty Then
' cFieldValueS_gbab = String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim().ToUpper() 'S_gbab.c_fld_xxx
' If S_fieldList.Contains(cFieldValueS_gbab) = True Then 'ตรวจสอบชื่อฟิลด์ว่า S_gbab.c_fld_xx มีอยู่จริงหรือไม่
' S_fieldDataRow = GetS_field(S_field, cTableName, cFieldValueS_gbab) 'S_field.C_file , S_field.C_field
' cFieldType = pDataTable.Columns(cFieldValueS_gbab).DataType.ToString() 'ตรวจสอบประเภทฟิลด์
' Call SetFormatGrid(i, S_fieldDataRow, cFieldType, cFieldValueS_gbab)
' End If
' End If
' End If
' Next
' Me.AutoGenerateColumns = False
' Me.DataSource = bsGrid
' End Select
'Else 'S_gbab.Rows.Count > 0
' MessageBox.Show("ไม่พบรูปแบบในแฟ้ม S_gbab กรุณาตรวจสอบ (" & pBab & ")", "ข้อความเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information)
' 'ไม่พบ รูปแบบ
' 'Select S_gbab
' 'Appen blank
' 'ก็ว่ากันไปครับ
'End If
End Sub
'
'ค้นหาคุณสมบัติของฟิลด์ ในแฟ้ม S_field เช่น ความยาว การจัดตำแหน่ง , etc
'
Private Function GetS_field(ByVal S_Field As DataTable, ByVal pDataTableName As String, ByVal pFieldName As String) As DataRow
Dim foundRow() As DataRow
Try
foundRow = S_field.Select("C_file = '" & pDataTableName & "' And C_field = '" & pFieldName & "'", "N_order Asc")
Return foundRow(0) 'เอาแถวแรกที่เจอ
Catch ex As Exception
Return Nothing
End Try
End Function
'
'กำหนดรูปแแบของกริด เช่น ชิดซ้าย กึ่งกลาง ชิดขวา รูปแบบตัวเลขเช่น 9,999.99 เป็นต้น และความกว้างของคอลัมภ์
'
Private Sub SetFormatGrid(ByVal i As UShort, ByVal S_fieldDataRow As DataRow, ByVal cFieldType As String, ByVal cFieldName As String)
Dim colTextBox As New DataGridViewTextBoxColumn
Dim colImage As New DataGridViewImageColumn
Dim cHeaderText As String = String.Empty
Select Case cFieldType
Case "System.String", "System.Decimal", "System.DateTime"
colTextBox = New DataGridViewTextBoxColumn()
colTextBox.Name = cFieldName 'String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim.ToUpper 'ชื่อคอลัมภ์ ใช้อ้างอิงอักษรตัวใหญ่
colTextBox.DataPropertyName = colTextBox.Name
Me.Columns.Add(colTextBox)
colTextBox.SortMode = DataGridViewColumnSortMode.Programmatic 'Manual Sorted
If S_fieldDataRow IsNot Nothing Then 'ค้นหาชื่อฟิลด์ในแฟ้ม S_field และถ้าพบ
If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim() <> String.Empty Then
cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
End If
If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim() <> String.Empty Then
cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
End If
colTextBox.HeaderText = cHeaderText
Select Case cFieldType 'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
Case "System.String"
Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim()
Case "R"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Case "C"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Case Else
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
End Select
Case "System.Decimal"
Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim
Case "L"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
Case "C"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Case Else
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End Select
If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย {dd MMM yyyy}
colTextBox.DefaultCellStyle.Format = "N2" 'เช่น Default 9,999.99 เป็นต้น
Else
colTextBox.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim
End If
Case "System.DateTime"
Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim
Case "L"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
Case "R"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Case Else
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End Select
If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย {dd MMMM yyyy}
colTextBox.DefaultCellStyle.Format = "dd MMM yyyy" 'เช่น 29 กุมภาพันธ์ 2543
Else
colTextBox.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim()
End If
End Select
If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then 'กำหนดความกว้างของคอลัมภ์
colTextBox.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
End If
Else
Select Case cFieldType 'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
Case "System.String"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
Case "System.Decimal"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
colTextBox.DefaultCellStyle.Format = "N2"
Case "System.DateTime"
colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
colTextBox.DefaultCellStyle.Format = "dd MMMM yyyy"
End Select
End If
Case "System.Byte[]" 'ประเภทฟิลด์ รูปภาพ หรือ ใน VFP = General นั่นเองครับ
colImage = New DataGridViewImageColumn
colImage.Name = cFieldName
colImage.DataPropertyName = colImage.Name
Me.Columns.Add(colImage)
If S_fieldDataRow IsNot Nothing Then 'ค้นหาชื่อฟิลด์ในแฟ้ม S_field พบ
If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim() <> String.Empty Then
cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
End If
If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim() <> String.Empty Then
cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
End If
colImage.HeaderText = cHeaderText
If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then 'กำหนดความกว้างของคอลัมภ์
colImage.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
End If
Else
'ค้นหาชื่อฟิลด์ในแฟ้ม S_field ไม่พบ
'colImage.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
'Me.Columns(colImage.Name).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
End If
End Select
End Sub
'
'กำหนดรูปแแบของกริด เช่น ชิดซ้าย กึ่งกลาง ชิดขวา รูปแบบตัวเลขเช่น 9,999.99 เป็นต้น และความกว้างของคอลัมภ์ แสดงทุกคอลัมภ์
'
Private Sub SetFormatGridAll(ByVal i As UShort, ByVal S_fieldDataRow As DataRow, ByVal cFieldType As String, ByVal cFieldName As String, ByVal pcol As DataGridViewColumn)
Dim cHeaderText As String = String.Empty
Select Case cFieldType
Case "System.String", "System.Decimal", "System.DateTime"
If S_fieldDataRow IsNot Nothing Then 'ค้นหาชื่อฟิลด์ในแฟ้ม S_field และถ้าพบ
If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim <> String.Empty Then
cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
End If
If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim <> String.Empty Then
cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
End If
pcol.HeaderText = cHeaderText
Select Case cFieldType 'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
Case "System.String"
Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim
Case String.Empty, "L"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
Case "R"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Case "C"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End Select
Case "System.Decimal"
Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim()
Case String.Empty, "R"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Case "L"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
Case "C"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End Select
If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย N2
pcol.DefaultCellStyle.Format = "N2" 'เช่น Default 9,999.99 เป็นต้น
Else
pcol.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim
End If
Case "System.DateTime"
Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim()
Case String.Empty, "C"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Case "L"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
Case "R"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End Select
If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย {dd MMM yyyy}
pcol.DefaultCellStyle.Format = "dd MMM yyyy" 'เช่น 29 ก.พ. 2543
Else
pcol.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim
End If
End Select
If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then 'กำหนดความกว้างของคอลัมภ์
pcol.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
End If
Else
Select Case cFieldType 'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
Case "System.String"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
Case "System.Decimal"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
pcol.DefaultCellStyle.Format = "N2"
Case "System.DateTime"
pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
pcol.DefaultCellStyle.Format = "dd MMM yyyy"
End Select
End If
Case "System.Byte[]" 'ประเภทฟิลด์ รูปภาพ หรือ ใน VFP = General นั่นเองครับ
If S_fieldDataRow IsNot Nothing Then 'ค้นหาชื่อฟิลด์ในแฟ้ม S_field พบ
If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim <> String.Empty Then
cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
End If
If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim <> String.Empty Then
cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
End If
pcol.HeaderText = cHeaderText
If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then 'กำหนดความกว้างของคอลัมภ์
pcol.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
End If
Else
'ค้นหาชื่อฟิลด์ในแฟ้ม S_field ไม่พบ
'pcol.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
'Me.Columns(colImage.Name).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
End If
End Select
End Sub
'
'DataViewGrid BeginEdit (Used EditingControlsShowing Instead)
'
Private Sub usrCtrGridControl_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles Me.EditingControlShowing
If Me._DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
Try
_CellIsBeginEdit = True
_CellIsBeginEditRow = Me.CurrentCell.RowIndex
_CellIsBeginEditCol = Me.CurrentCell.ColumnIndex
Catch
'Ignore error
End Try
End If
End Sub
'
'ตรวจสอบการกดปุ่ม บน KeysBoard บนกริด
'
Private Sub usrCtrGridControl_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
'
'ตรวจสอบตัวอักษรที่กด ว่าเป็นตัวอักษรหรือไม่ e.KeyChar Like "[A-Za-z0-9ก-๙]" รวมถึงตัวอักษรและสระภาษาไทยทุกตัว
'
'If Me.Rows.Count > 0 AndAlso Me.Columns(Me.CurrentCell.ColumnIndex).CellType.Name.ToString() <> "DataGridViewImageCell" AndAlso (e.KeyChar Like "[A-Za-z0-9ก-๙]") Then
' If Me.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString() = "DateTime" OrElse Me.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString() = "Decimal" Then
' MessageBox.Show("ไม่อนุญาติให้ค้นหาในคอลัมภ์ DateTime หรือ Decimal", "ขออภัยครับ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
' Exit Sub
' End If
' Dim cColumnName As String = Me.Columns(Me.CurrentCell.ColumnIndex).Name
' Dim fd = DTControlGridEnumerable.Where(Function(p) p.Field(Of String)(cColumnName).StartsWith(e.KeyChar))
' If fd.Count < 1 Then
' Dim x As String = e.KeyChar
' Console.Beep() 'ส่งเสียงเตือน ปี๊ด
' Exit Sub
' End If
' Dim cColumnType As String = Me.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString()
' Dim cSortPatternArray() As String
' Dim cSortPatternString As String = String.Empty
' Dim f As New frmFindInGrid 'ฟอร์มค้นหาข้อมูลในกริด frmFindInGrid.vb
' f.bs = Me.bsGrid
' f.PubDTControlGridEnumerable = Me.DTControlGridEnumerable 'เตรียมข้อมูลเอาไว้เลยครับ เพื่อความรวดเร็วในการสืบค้น (Index On Cols Tag ColA)
' f.PubcColumnName = cColumnName 'Me.Columns(Me.CurrentCell.ColumnIndex).Name.ToString()
' f.PubcColumnType = cColumnType '.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString()
' f.PubDTControlGrid = Me.DTControlGrid 'จริงฯแล้วควรจะใช้ DirecCast() เพื่อจะได้ประหยัดหน่วยความจำ จะได้ไม่ต้องประกาศ Dim DTControlGrid As DataTable
' f.PubcSortdKey = Me._OnSortedFindKey 'มีความจำเป็นมากครับ เพื่อระบุตำแหน่งแถวที่ถูกต้อง
' cSortPatternArray = Me.SortPattern(cColumnName).ToString.Split(",") 'Split เก็บแยกเป็น String Array
' If cSortPatternArray.Length > 0 Then
' If cSortPatternArray.Length = 1 AndAlso String.Format("{0}", cSortPatternArray(0)) = String.Empty Then
' If Me.SortOrder = Windows.Forms.SortOrder.None Then 'ถ้ายังไม่ได้จัดเรียง ก็ให้จัดเรียงก่อนค้นหา
' Me.Sort(Me.Columns(Me.CurrentCell.ColumnIndex), ListSortDirection.Ascending)
' Else
' If Me.SortedColumn.Name <> cColumnName Then 'ถ้ามีการเปลี่ยน Columns ในการค้นหา เช่น C_M_CODE --> C_M_NAME เป็นต้นครับ
' Me.Sort(Me.Columns(Me.CurrentCell.ColumnIndex), ListSortDirection.Ascending)
' End If
' End If
' Else
' For i As Integer = 0 To cSortPatternArray.Length - 1 'จัดเรียงแบบ หลาย Columns เช่น C_M_NAME, C_M_SURE เป็นต้น
' If Me.SortOrder = Windows.Forms.SortOrder.Descending Then
' cSortPatternString &= cSortPatternArray(i).Trim() & " Desc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
' Else
' cSortPatternString &= cSortPatternArray(i).Trim() & " Asc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
' End If
' Next
' If bsGrid.Sort <> cSortPatternString Then
' bsGrid.Sort = cSortPatternString 'จัดเรียงแบบหลาย Columns ต้องทำอย่างนี้เพราะว่า DataGridView สามารถ Sort ได้ 1 Columns เท่านั้น
' End If
' End If
' End If
' '
' 'ค้นหาก่อนแสดงฟอร์ม frmFindInGrid
' '
' 'Dim fd = DTControlGridEnumerable.Where(Function(p) p.Field(Of String)(f.PubcColumnName).Contains(e.KeyChar))
' f.PubcText = e.KeyChar
' f.txtFind.SelectionLength = 0
' f.txtFind.SelectedText = ""
' f.txtFind.SelectionStart = 1
' f.lblFindResult.Text = "ค้นพบ = " & fd.Count.ToString & " ระเบียน"
' f.ShowDialog() 'แสดงฟอร์ม ค้นหาในกริด
' If String.IsNullOrEmpty(f.PubcReturn) = False Then
' Try
' bsGrid.Position = Me.bsGrid.Find(Me._OnSortedFindKey, f.PubcReturn)
' Catch ex As Exception
' 'Ignore error
' End Try
' End If
' f.Dispose()
' f = Nothing 'Clear Memory before exit sub
'End If
End Sub
'
'DataViewGrid KeyDown
'
Private Sub usrCtrGridControl_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If _DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
If _OnEnterModeMove = DataGridViewOnEnterModeMove.Right Then
Try
If Not Me.CurrentCell.IsInEditMode Then 'ไม่อยู่ใน Mode แก้ไข
Dim col As Short = Me.CurrentCell.ColumnIndex
If e.KeyCode = Keys.Tab Then
e.Handled = True
Exit Sub
End If
If e.KeyCode = Keys.Enter AndAlso col = _LastColumnVisible AndAlso Me.CurrentRow.IsNewRow = False Then
Me.CurrentCell = Me.Rows(Me.CurrentRow.Index + 1).Cells(_FirstColumnVisible)
e.Handled = True
Exit Sub
End If
If e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Right Then
For iSub As Short = col To Me.ColumnCount - 1
col = (col + 1) Mod Me.ColumnCount
If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
Exit For
End If
Next
If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
For iSub As Short = col To Me.ColumnCount - 1
col = (col + 1) Mod Me.ColumnCount
If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
Exit For
End If
Next
End If
ElseIf e.KeyCode = Keys.Left Then
For iSub As Short = col To 0 Step -1
col = (col - 1) Mod Me.ColumnCount
If col < 0 Then
col = Me.ColumnCount - 1
End If
If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
Exit For
End If
Next
If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
For iSub As Short = col To Me.ColumnCount - 1
col = (col + 1) Mod Me.ColumnCount
If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
Exit For
End If
Next
End If
End If
If e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Left OrElse e.KeyCode = Keys.Right Then
Me.CurrentCell = Me.CurrentRow.Cells(col)
e.Handled = True
End If
End If
Catch
'Ignore error
End Try
End If
End If
End Sub
'
'DataViewGrid MouseClick/DbClick
'
Private Sub usrCtrGridControl_CellMouseClickORDbClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Me.CellMouseClick, Me.CellMouseDoubleClick
If _DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
Try
Dim col As Short = Me.CurrentCell.ColumnIndex
If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
For iSub As Short = col To Me.ColumnCount - 1
col = (col + 1) Mod Me.ColumnCount
If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
Exit For
End If
Next
End If
Me.CurrentCell = Me.CurrentRow.Cells(col)
Catch ex As Exception
'Ignore
End Try
End If
End Sub
'Supper Handler
'
'Private Sub MouseClickMouseDbClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) _
' Handles Me.CellMouseDoubleClick, Me.CellMouseClick
' Try
' Dim col As Short = Me.CurrentCell.ColumnIndex
' If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
' Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
' For iSub As Short = col To Me.ColumnCount - 1
' col = (col + 1) Mod Me.ColumnCount
' If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
' Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
' Exit For
' End If
' Next
' End If
' Me.CurrentCell = Me.CurrentRow.Cells(col)
' Catch ex As Exception
' 'Ignore
' End Try
'End Sub
'
'DataViewGrid IsEditMode
'
Private Sub DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SelectionChanged
'Dim c As Control = CType(sender, Control) 'การอ้างถึง Control จาก Sender
If Me._DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
Try
If Me.RowCount = 1 Then 'NewRow Only and have one row
Me.CurrentCell = Me.Rows(Me._FirstColumnVisible).Cells(Me._FirstColumnVisible)
Exit Sub
End If
Dim subCol As Short = Me.CurrentCell.ColumnIndex
If _CellIsBeginEdit AndAlso _CellIsBeginEditCol <> Me._LastColumnVisible Then
For iSub As Short = subCol To Me.ColumnCount - 1
subCol = (subCol + 1) Mod Me.ColumnCount
If Me.Columns(subCol).Visible = True AndAlso Me.Columns(subCol).ReadOnly = False AndAlso _
Me.Columns(subCol).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
Exit For
End If
Next
Me.CurrentCell = Me.Rows(_CellIsBeginEditRow).Cells(subCol)
ElseIf _CellIsBeginEdit AndAlso _CellIsBeginEditCol = _LastColumnVisible Then
Try
Me.CurrentCell = Me.Rows(_CellIsBeginEditRow + 1).Cells(Me._FirstColumnVisible)
Catch
'Ignore error
End Try
ElseIf Not _CellIsBeginEdit AndAlso Me.CurrentRow.IsNewRow Then
If Me.CurrentRow.Cells(_FirstColumnVisible).Value Is Nothing OrElse _
IsDBNull(Me.CurrentRow.Cells(_FirstColumnVisible).Value) OrElse _
String.IsNullOrEmpty(Me.CurrentRow.Cells(_FirstColumnVisible).Value) Then
Me.CurrentCell = Me.CurrentRow.Cells(_FirstColumnVisible)
End If
End If
Catch ex As Exception
'MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
_CellIsBeginEdit = False
End If
End Sub
'
'DataViewGrid Sort (จัดเรียงข้อมูลตาม Column ที่เลือก และนำไปแสดงผลเป็นคอลัมภ์แรกเสมอ)
'
Private Sub DataGridView_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Me.ColumnHeaderMouseClick
If Me._DisplayManager = DataGridViewDisplayManager.Framework Then
Me.Cursor = Cursors.WaitCursor
Dim booSubAllowUserToAddRows As Boolean = Me.AllowUserToAddRows
Try
'
'We not search Column type Image , Combobox , etc : Remark AndAlso e.ColumnIndex >=0
'
If Me.Columns(e.ColumnIndex).CellType.ToString.Trim = "System.Windows.Forms.DataGridViewImageCell" Then
Return
End If
If Me.DataSource IsNot Nothing AndAlso Me.DataSource.GetType.Name = "BindingSource" Then
Dim ctrSubBindingSource As BindingSource = Me.DataSource
Dim iSubRowIndex As Integer
Dim objSubSearchValue As Object
If ctrSubBindingSource.Count <= 1 Then 'RowCount = 0 + IsNewRow
Exit Sub
End If
If String.Format("{0}", Me._OnSortedFindKey).Trim <> String.Empty Then 'ระบุ DataTable.FieldName ที่ต้องการค้นหา
'objSubSearchValue = String.Format("{0}", Me.CurrentRow.Cells(Me._OnSortedFindKey).Value).Trim
Dim dbSubDRv As DataRowView = ctrSubBindingSource.Current
objSubSearchValue = String.Format("{0}", dbSubDRv.Item(Me._OnSortedFindKey)).Trim
Else 'อ่านค่าจาก DataGridView.ColumnName
objSubSearchValue = String.Format("{0}", Me.CurrentRow.Cells(e.ColumnIndex).Value).Trim
End If
Me.AllowUserToAddRows = False 'Fixbug IsNewRow if AllowUserToAddRows = True
Dim cColumnName As String = Me.Columns(e.ColumnIndex).Name
Dim cSortPatternArray() As String
Dim cSortPatternString As String = String.Empty
cSortPatternArray = Me.SortPattern(cColumnName).ToString.Split(",") 'Split เก็บแยกเป็น String Array
If cSortPatternArray.Length > 0 Then
If cSortPatternArray.Length = 1 AndAlso String.Format("{0}", cSortPatternArray(0)) = String.Empty Then
cSortPatternString = cColumnName 'จัดเรียงแบบ 1 Column เท่านั้น
If Me.SortOrder = Windows.Forms.SortOrder.Descending Then
Me.Sort(Me.Columns(e.ColumnIndex), ListSortDirection.Ascending)
Else
Me.Sort(Me.Columns(e.ColumnIndex), ListSortDirection.Descending)
End If
Else
For i As Integer = 0 To cSortPatternArray.Length - 1 'จัดเรียงแบบ หลาย Columns เช่น C_M_NAME, C_M_SURE เป็นต้น
cSortPatternArray(i).Trim()
If Me.SortOrder = Windows.Forms.SortOrder.Descending Then
cSortPatternString &= cSortPatternArray(i) & " Asc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
Else
cSortPatternString &= cSortPatternArray(i) & " Desc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
End If
Next
bsGrid.Sort = cSortPatternString 'จัดเรียงแบบหลาย Columns ต้องทำอย่างนี้เพราะว่า DataGridView สามารถ Sort ได้ 1 Columns เท่านั้น
End If
End If
If String.Format("{0}", Me._OnSortedFindKey).Trim <> String.Empty Then
iSubRowIndex = ctrSubBindingSource.Find(Me._OnSortedFindKey.Trim, objSubSearchValue)
Else
iSubRowIndex = ctrSubBindingSource.Find(Me.Columns(e.ColumnIndex).Name, objSubSearchValue)
End If
If iSubRowIndex > -1 Then
ctrSubBindingSource.Position = iSubRowIndex
Me.Columns(e.ColumnIndex).DisplayIndex = 0
Me.FirstDisplayedScrollingRowIndex = iSubRowIndex 'บังคับให้แสดงเสมอ
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "จัดเรียงข้อมูลในกริดผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
Me.Cursor = Cursors.Default
Me.AllowUserToAddRows = booSubAllowUserToAddRows 'Reset AllowUserToAddRows
End Try
End If
End Sub
'
'ควบคุม Error
'
Private Sub Me_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles Me.DataError
Dim strSubMsg As String = String.Empty
If e.Exception IsNot Nothing Then
strSubMsg = e.Exception.Message
End If
If strSubMsg.Contains("does not allow nulls") OrElse strSubMsg.Contains("to be unique") Then 'รหัสซ้ำ Or null
MessageBox.Show("รหัสที่ป้อนมีอยู่แล้วหรือไม่มีค่า (null) กรุณาป้อนให้ถูกต้อง" & Constants.vbCrLf & Constants.vbCrLf & strSubMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf strSubMsg.Contains("not in a correct format") Then 'ป้อนข้อมูลไม่ถูกต้อง
MessageBox.Show("ป้อนข้อมูลไม่ถูกต้อง เช่น จำนวนเงินแต่ป้อนเป็นตัวอักษรเป็นต้น กรุณาป้อนให้ถูกต้อง" & Constants.vbCrLf & Constants.vbCrLf & strSubMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'More Msg you can coding hear
End If
Try
e.Cancel = False
If Me.DataSource IsNot Nothing AndAlso Me.DataSource.GetType.Name = "BindingSource" Then
Dim ctrSubBindingSource As BindingSource = Me.DataSource
ctrSubBindingSource.ResumeBinding()
End If
Me.CancelEdit()
Catch ex As Exception
MsgBox(ex.Message)
'Ignore error
End Try
End Sub
'
'Formating DataGridView
'
Private Sub Me_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles Me.CellFormatting
Try
If Me.Columns(e.ColumnIndex).ValueType.Name.ToString = "Decimal" Then
If Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = 0 Then
Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.ForeColor = Color.White
End If
ElseIf Me.Columns(e.ColumnIndex).ValueType.Name.ToString = "DateTime" Then
Try
If String.Format("{0:dd/MM/yyyy}", Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value).Trim = "30/12/2442" Then
Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.ForeColor = Color.White
End If
Catch ex As Exception
'MessageBox.Show(ex.Message, "CellFormating In")
End Try
End If
Catch ex As Exception
'MessageBox.Show(ex.Message, "CellFormating Out")
End Try
End Sub
'
'แสดงลำดับที่ของแถว
'
Private Sub Me_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles Me.RowPostPaint
'Try
' Dim length As String = Me.RowCount.ToString.Length
' Dim row As String = (e.RowIndex + 1).ToString.PadLeft(length, " ")
' 'Dim rows As String = Me.RowCount.ToString.Length
' 'Dim size As SizeF = e.Graphics.MeasureString(rows, Me.Font)
' Dim size As SizeF = e.Graphics.MeasureString("ก", Me.Font)
' 'If Me.RowHeadersWidth < size.Width + 20 Then
' ' Me.RowHeadersWidth = size.Width + 20
' 'End If
' Using b As SolidBrush = New SolidBrush(Me.RowHeadersDefaultCellStyle.ForeColor)
' 'e.Graphics.DrawString(e.RowIndex + 1, Me.DefaultCellStyle.Font, b, e.RowBounds.Location.X + ((Me.RowHeadersWidth - size.Width) / 2), e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
' e.Graphics.DrawString(row, Me.DefaultCellStyle.Font, b, e.RowBounds.Location.X + ((Me.RowHeadersWidth - size.Width) / 2), e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
' End Using
'Catch
' 'Ignore
'End Try
End Sub
End Class
DO CASE
CASE M.PR3LEVEL<>'Y'
IF (PRICE<0 .OR. PRICE_QTY2="1") .AND. Q_P_U>0
M.BUF_AMT = (QTY*ABS(PRICE))+(ITEM*ABS(PRICE)/Q_P_U)
ELSE
M.BUF_AMT = (Q_P_U*QTY*PRICE)+(ITEM*PRICE)
ENDIF
CASE M.PR3LEVEL='Y'
IF (PRICE<0 .OR. PRICE_QTY2="1") .AND. Q_P_U>0
IF Q_P_BOX<=0
IF QTY2>0
REPLACE QTY WITH QTY2
REPLACE QTY2 WITH 0
KEYBOARD '{ENTER}'
ENDIF
IF Q_P_U=1 .AND. QTY>0
REPLACE ITEM WITH QTY
REPLACE QTY WITH 0
KEYBOARD '{ENTER}'
ENDIF
M.BUF_AMT = (QTY*ABS(PRICE))+(ITEM*ABS(PRICE)/Q_P_U)
ELSE
M.BUF_AMT = (QTY2*ABS(PRICE))+(QTY*ABS(PRICE)/Q_P_BOX)+(ITEM*ABS(PRICE)/(Q_P_U*Q_P_BOX))
ENDIF
ELSE
IF PRICE_QTY2="+" .AND. Q_P_U>0
M.BUF_AMT = (Q_P_BOX*QTY2*ABS(PRICE))+(QTY*ABS(PRICE))+(ITEM*ABS(PRICE)/(Q_P_U))
ELSE
M.BUF_AMT = (Q_P_BOX*Q_P_U*QTY2*PRICE)+(Q_P_U*QTY*PRICE)+(ITEM*PRICE)
ENDIF
ENDIF
ENDCASE
IF QTY2_FG="Y" .AND. PRICE_QTY2="2"
M.BUF_AMT = QTY2*ABS(PRICE)
ENDIF
REPLACE AMT WITH M.BUF_AMT
IF M.CURR_PROG<>'IC' .AND. M.CURR_PROG<>'ER'
M.W_T_AMT = M.W_T_AMT-AMT+M.BUF_AMT
REPLACE L_VAT_IN WITH 0
SHOW GET M.W_T_AMT DISABLE
ENDIF
M.MSGERR = IIF(M.SCR_CODE>1, F_MSG("10132"), "บรรทัดไหนอะครับเนี่ย ตาลาย ")
SET MESSAGE TO M.MSGERR LEFT
M.MSGERR = " "
DO RECAL_DSC
RETURN
ENDPROC
Date :
2013-08-02 15:18:03
By :
ผ่านมา
No. 6
Guest
มึนตึ๊บครับ
ผมมือใหม่อยู่
เดี๋ยวผมทำคิวรี่ทีละอันก่อนดีกว่า 555+
Date :
2013-08-02 16:11:20
By :
510
No. 7
Guest
ึผมคือคนบ้า ไม่มีบรรทัดไหนที่ผมต้องจดจำ (อ่าน)
Code
/*
json.js
2011-08-30
Public Domain
No warranty expressed or implied. Use at your own risk.
This file has been superceded by http://www.JSON.org/json2.js
See http://www.JSON.org/js.html
This code should be minified before deployment.
See http://javascript.crockford.com/jsmin.html
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
NOT CONTROL.
This file adds these methods to JavaScript:
object.toJSONString(whitelist)
This method produce a JSON text from a JavaScript value.
It must not contain any cyclical references. Illegal values
will be excluded.
The default conversion for dates is to an ISO string. You can
add a toJSONString method to any date object to get a different
representation.
The object and array methods can take an optional whitelist
argument. A whitelist is an array of strings. If it is provided,
keys in objects not found in the whitelist are excluded.
string.parseJSON(filter)
This method parses a JSON text to produce an object or
array. It can throw a SyntaxError exception.
The optional filter parameter is a function which can filter and
transform the results. It receives each of the keys and values, and
its return value is used instead of the original value. If it
returns what it received, then structure is not modified. If it
returns undefined then the member is deleted.
Example:
// Parse the text. If a key contains the string 'date' then
// convert the value to a date.
myData = text.parseJSON(function (key, value) {
return key.indexOf('date') >= 0 ? new Date(value) : value;
});
This file will break programs with improper for..in loops. See
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/
This file creates a global JSON object containing two methods: stringify
and parse.
JSON.stringify(value, replacer, space)
value any JavaScript value, usually an object or array.
replacer an optional parameter that determines how object
values are stringified for objects. It can be a
function or an array of strings.
space an optional parameter that specifies the indentation
of nested structures. If it is omitted, the text will
be packed without extra whitespace. If it is a number,
it will specify the number of spaces to indent at each
level. If it is a string (such as '\t' or ' '),
it contains the characters used to indent at each level.
This method produces a JSON text from a JavaScript value.
When an object value is found, if the object contains a toJSON
method, its toJSON method will be called and the result will be
stringified. A toJSON method does not serialize: it returns the
value represented by the name/value pair that should be serialized,
or undefined if nothing should be serialized. The toJSON method
will be passed the key associated with the value, and this will be
bound to the object holding the key.
For example, this would serialize Dates as ISO strings.
Date.prototype.toJSON = function (key) {
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
return this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z';
};
You can provide an optional replacer method. It will be passed the
key and value of each member, with this bound to the containing
object. The value that is returned from your method will be
serialized. If your method returns undefined, then the member will
be excluded from the serialization.
If the replacer parameter is an array of strings, then it will be
used to select the members to be serialized. It filters the results
such that only members with keys listed in the replacer array are
stringified.
Values that do not have JSON representations, such as undefined or
functions, will not be serialized. Such values in objects will be
dropped; in arrays they will be replaced with null. You can use
a replacer function to replace those with JSON values.
JSON.stringify(undefined) returns undefined.
The optional space parameter produces a stringification of the
value that is filled with line breaks and indentation to make it
easier to read.
If the space parameter is a non-empty string, then that string will
be used for indentation. If the space parameter is a number, then
the indentation will be that many spaces.
Example:
text = JSON.stringify(['e', {pluribus: 'unum'}]);
// text is '["e",{"pluribus":"unum"}]'
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
text = JSON.stringify([new Date()], function (key, value) {
return this[key] instanceof Date ?
'Date(' + this[key] + ')' : value;
});
// text is '["Date(---current time---)"]'
JSON.parse(text, reviver)
This method parses a JSON text to produce an object or array.
It can throw a SyntaxError exception.
The optional reviver parameter is a function that can filter and
transform the results. It receives each of the keys and values,
and its return value is used instead of the original value.
If it returns what it received, then the structure is not modified.
If it returns undefined then the member is deleted.
Example:
// Parse the text. Values that look like ISO date strings will
// be converted to Date objects.
myData = JSON.parse(text, function (key, value) {
var a;
if (typeof value === 'string') {
a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
if (a) {
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
+a[5], +a[6]));
}
}
return value;
});
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
var d;
if (typeof value === 'string' &&
value.slice(0, 5) === 'Date(' &&
value.slice(-1) === ')') {
d = new Date(value.slice(5, -1));
if (d) {
return d;
}
}
return value;
});
This is a reference implementation. You are free to copy, modify, or
redistribute.
*/
/*jslint evil: true, regexp: true, unparam: true */
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
lastIndex, length, parse, parseJSON, prototype, push, replace, slice,
stringify, test, toJSON, toJSONString, toString, valueOf
*/
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
var JSON;
if (!JSON) {
JSON = {};
}
(function () {
'use strict';
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function (key) {
return isFinite(this.valueOf()) ?
this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z' : null;
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
return this.valueOf();
};
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
indent,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
},
rep;
function quote(string) {
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c :
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
function str(key, holder) {
// Produce a string from holder[key].
var i, // The loop counter.
k, // The member key.
v, // The member value.
length,
mind = gap,
partial,
value = holder[key];
// If the value has a toJSON method, call it to obtain a replacement value.
if (value && typeof value === 'object' &&
typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
}
// What happens next depends on the value's type.
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
// JSON numbers must be finite. Encode non-finite numbers as null.
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.
return String(value);
// If the type is 'object', we might be dealing with an object or an array or
// null.
case 'object':
// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.
if (!value) {
return 'null';
}
// Make an array to hold the partial results of stringifying this object value.
gap += indent;
partial = [];
// Is the value an array?
if (Object.prototype.toString.apply(value) === '[object Array]') {
// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.
length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
v = partial.length === 0 ? '[]' : gap ?
'[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
'[' + partial.join(',') + ']';
gap = mind;
return v;
}
// If the replacer is an array, use it to select the members to be stringified.
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
k = rep[i];
if (typeof k === 'string') {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
} else {
// Otherwise, iterate through all of the keys in the object.
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
}
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
v = partial.length === 0 ? '{}' : gap ?
'{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
'{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
// If the JSON object does not yet have a stringify method, give it one.
if (typeof JSON.stringify !== 'function') {
JSON.stringify = function (value, replacer, space) {
// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.
var i;
gap = '';
indent = '';
// If the space parameter is a number, make an indent string containing that
// many spaces.
if (typeof space === 'number') {
for (i = 0; i < space; i += 1) {
indent += ' ';
}
// If the space parameter is a string, it will be used as the indent string.
} else if (typeof space === 'string') {
indent = space;
}
// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
return str('', { '': value });
};
}
// If the JSON object does not yet have a parse method, give it one.
if (typeof JSON.parse !== 'function') {
JSON.parse = function (text, reviver) {
// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.
var j;
function walk(holder, key) {
// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}
// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.
text = String(text);
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
});
}
// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.
// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
if (/^[\],:{}\s]*$/
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
j = eval('(' + text + ')');
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
return typeof reviver === 'function' ?
walk({ '': j }, '') : j;
}
// If the text is not JSON parseable, then a SyntaxError is thrown.
throw new SyntaxError('JSON.parse');
};
}
// Augment the basic prototypes if they have not already been augmented.
// These forms are obsolete. It is recommended that JSON.stringify and
// JSON.parse be used instead.
if (!Object.prototype.toJSONString) {
Object.prototype.toJSONString = function (filter) {
return JSON.stringify(this, filter);
};
Object.prototype.parseJSON = function (filter) {
return JSON.parse(this, filter);
};
}
} ());