Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > C# window app มีวิธี SELECT ข้อมูลออกมาครั้งเดียว แล้วนำค่าไปแสดงที่ TextBox หลายๆอันรึเปล่าครับ


 

[.NET] C# window app มีวิธี SELECT ข้อมูลออกมาครั้งเดียว แล้วนำค่าไปแสดงที่ TextBox หลายๆอันรึเปล่าครับ

 
Topic : 098613

Guest



สมมุติ SELECT คอลัมน์ A,B,C ออกมา

แล้วนำ A มาลง Textbox อันนึง B มาลงTextBox อันนึง C มาลง TextBox อีกอัน

ทำได้มั้ยครับในการ SELECT ภายในครังเดียว



Tag : .NET, C#, VS 2010 (.NET 4.x)

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-08-02 14:34:11 By : 510 View : 1957 Reply : 7
 

 

No. 1

Guest


อันนี้เด็กของผมเขียนตั้งแต่ปี 2004 - 2005 ผมไม่เคยได้ใช้งานเลย ครับ


Code (VB.NET)
001.Imports System.ComponentModel
002.Imports System.Windows.Forms
003.Imports System.Drawing
004. 
005.<ToolboxBitmap(GetType(DataGridView))> _
006.Public Class usrCtrGridControlExt : Inherits DataGridView   'สร้างมาจากต้นแบบ DataGridView
007. 
008.#Region "    Enumerations "
009.    Public Enum DataGridViewDisplayManager As Byte
010.        [Default] = 0
011.        Framework = 1
012.    End Enum
013. 
014.    Public Enum DataGridViewOnEnterEditModeMove As Byte
015.        Right = 0
016.        Down = 1
017.    End Enum
018. 
019.    Public Enum DataGridViewOnEnterModeMove As Byte
020.        Right = 0
021.        Down = 1
022.    End Enum
023. 
024.    Public Enum DataGridViewLastColumnVisible As Short
025.        Last = 0
026.    End Enum
027. 
028.    Public Enum DataGridViewFirstColumnVisible As Short
029.        First = 0
030.    End Enum
031. 
032.    'Public Enum DataGridViewColumnsCount As Short
033.    '    ColumnsCount = 100
034.    'End Enum
035. 
036.    Public Enum TextBoxDisplayManager As Byte
037.        TextCharacter = 0
038.        TextNumber = 1
039.        TextInteger = 2
040.    End Enum
041. 
042.    Public Enum TextBoxDisplayPrecisionScale As Byte
043.        None = 0
044.        One = 1
045.        Two = 2
046.        Tree = 3
047.        Four = 4
048.    End Enum
049. 
050.#End Region
051. 
052.#Region "    Variables "
053.    Private _DisplayManager As DataGridViewDisplayManager = DataGridViewDisplayManager.Default
054.    Private _OnEnterEditModeMove As DataGridViewOnEnterEditModeMove = DataGridViewOnEnterEditModeMove.Right
055.    Private _OnEnterModeMove As DataGridViewOnEnterModeMove = DataGridViewOnEnterModeMove.Right
056. 
057.    Private _OnSortedFindKey As String              'กรณีที่ column.Sorted.Value Duplicate เช่น  1-a , 2-a เป็นต้น เก็บค่า 1 หรือ 2 เพื่อเปรียบเทียบ
058.    Private _CellIsBeginEdit As Boolean = False     'CurrentCell มีการแก้ไข
059.    Private _CellIsBeginEditRow As Integer = -1     'CurrentCell.RowIndex ก่อนมีการแก้ไข
060.    Private _CellIsBeginEditCol As UShort           'Max 60,000 Columns
061. 
062.    Private _LastColumnVisible As UShort            'Column สุดท้ายที่ Visible
063.    Private _FirstColumnVisible As UShort           'Column แรกที่ Visible
064. 
065.    'Private _DisplayPrecisionScale As TextBoxDisplayPrecisionScale         'จำนวนจุดทศนิยม
066.    'Private _ColumnsCount As Short 'DataGridViewColumnsCount               'จำนวนคอลัมน์ที่สร้างครั้งแรก
067. 
068.    Private bsGrid As New BindingSource
069.    Private DTControlGrid As New DataTable("DTControlGrid")
070.    Private DTControlGridEnumerable As System.Data.EnumerableRowCollection(Of DataRow)  'เอาไว้ค้นหาข้อมูลในกริดโดยเฉพาะ และเพื่อเพิ่มความเร็ว
071.    Private SortPattern As New SortedList     'เอาไว้จัดเรียงข้อมูลในกริด
072.#End Region
073. 
074.#Region "    Properties "
075. 
076.    <System.ComponentModel.DefaultValue(GetType(DataGridViewDisplayManager), "Default"), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("กำหนดคุณสมบัติ")> _
077.    Public Property DisplayManager() As DataGridViewDisplayManager
078.        Get
079.            Return _DisplayManager
080.        End Get
081.        Set(ByVal value As DataGridViewDisplayManager)
082.            _DisplayManager = value
083.            If Me._DisplayManager = DataGridViewDisplayManager.Framework Then
084.                Me.DisplayManagerEnterEditModeMove = DataGridViewOnEnterEditModeMove.Right
085.                Me.DisplayManagerEnterModeMove = DataGridViewOnEnterModeMove.Right
086.            Else
087.                'Set To Default
088.                Me.DisplayManagerEnterEditModeMove = DataGridViewOnEnterEditModeMove.Down
089.                Me.DisplayManagerEnterModeMove = DataGridViewOnEnterModeMove.Down
090.            End If
091.        End Set
092.    End Property
093. 
094.    <System.ComponentModel.DefaultValue(GetType(DataGridViewOnEnterEditModeMove), "No"), System.ComponentModel.Category("Appearance")> _
095.    Public Property DisplayManagerEnterEditModeMove() As DataGridViewOnEnterEditModeMove
096.        Get
097.            Return _OnEnterEditModeMove
098.        End Get
099.        Set(ByVal Value As DataGridViewOnEnterEditModeMove)
100.            _OnEnterEditModeMove = Value
101.        End Set
102.    End Property
103. 
104.    <System.ComponentModel.DefaultValue(GetType(DataGridViewOnEnterEditModeMove), "First"), System.ComponentModel.Category("Appearance")> _
105.Public Property DisplayManagerEnterModeMove() As DataGridViewOnEnterModeMove
106.        Get
107.            Return _OnEnterModeMove
108.        End Get
109.        Set(ByVal Value As DataGridViewOnEnterModeMove)
110.            _OnEnterModeMove = Value
111.        End Set
112.    End Property
113. 
114.    <System.ComponentModel.DefaultValue(""), System.ComponentModel.Category("Appearance")> _
115.Public Property DisplayManagerSortedFindKey() As String
116.        Get
117.            Return _OnSortedFindKey
118.        End Get
119.        Set(ByVal value As String)
120.            _OnSortedFindKey = value
121.        End Set
122.    End Property
123. 
124.    <System.ComponentModel.DefaultValue(0), System.ComponentModel.Category("Appearance")> _
125.Public Property DisplayManagerFirstColumnVisible() As String
126.        Get
127.            Return _FirstColumnVisible
128.        End Get
129.        Set(ByVal value As String)
130.            _FirstColumnVisible = value
131.        End Set
132.    End Property
133. 
134.    <System.ComponentModel.DefaultValue(0), System.ComponentModel.Category("Appearance")> _
135.Public Property DisplayManagerLastColumnVisible() As String
136.        Get
137.            Return _LastColumnVisible
138.        End Get
139.        Set(ByVal value As String)
140.            _LastColumnVisible = value
141.        End Set
142.    End Property
143. 
144.#End Region
145. 
146.#Region "    Constructor "
147. 
148.    Public Sub New()
149.        '
150.        'Me.ColumnCount = 100 'กำหนดจำนวนคอลัมน์ เมื่อตอนสร้างครั้งแรก เท่ากับ 100 คอลัมน์
151.        'For i As Short = 0 To 99
152.        '    Me.Columns(i).HeaderText = i.ToString
153.        'Next
154. 
155.        Me.EnableHeadersVisualStyles = True
156.        Me.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
157.        Me.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 'ข้อความบน Header จัดเรียงตรงกลาง
158.        Me.ColumnHeadersHeight = 40     'กำหนดความสูงของ Header Grid
159. 
160.    End Sub
161. 
162.#End Region
163. 
164.    Public Sub SetNew(ByVal pDataSet As DataSet, ByVal pDataTable As DataTable, ByVal pBab As String)
165. 
166.        'Me.Cursor = Cursors.WaitCursor
167. 
168.        'Dim dbSubMgr As New DBHelper
169.        'Dim S_gbab As New DataTable("S_gbab")    'เก็บค่าต้นแบบกริด สัมพันธ์กับ Table s_field, s_file1
170.        'Dim S_field As New DataTable("S_field")  'เก็บคุณสมบัติของ pDataTable.Fieldxxx เช่น ประเภท ขนาด และการจัดเรียง C_M_NAME + C_M_SURE เป็นต้น
171. 
172.        'Dim S_fieldList As New ArrayList         'เก็บชื่อฟิลด์ของ pDataTable เอาไว้เปรียบเทียบกับ S_gbab.c_fld_xx ในกรณีที่มีการเปลี่ยนแปลงโครงสร้าง Table
173. 
174.        'DTControlGrid = pDataTable
175. 
176.        'bsGrid.DataSource = pDataSet
177.        'bsGrid.DataMember = pDataTable.TableName
178. 
179.        'DTControlGridEnumerable = From dt In pDataTable.AsEnumerable() Select dt 'เอาไว้ค้นหาข้อมูลในกริดโดยเฉพาะ (เร็วกว่า DataTable.Select)
180. 
181.        'Me.AllowUserToDeleteRows = False        'ไม่ให้ลบแถวที่เลือก
182.        'Me.AllowUserToOrderColumns = True       'อนุญาติให้ย้ายตำแหน่ง Column ได้ (Drag)
183. 
184. 
185.        'For i As UShort = 0 To pDataTable.Columns.Count - 1     'เอาไว้ตรวจสอบว่า S_gbab.C_fld_xx มีอยู่จริงใน Table หรือไม่ (อาจมีการปรับเปลี่ยนโครงสร้าง Table)
186.        '    S_fieldList.Add(pDataTable.Columns(i).ColumnName.ToUpper().Trim())
187.        '    SortPattern.Add(S_fieldList(i), "") 'เก็บรูปแบบการจัดเรียงข้อมูล ในกรณีที่จัดเรียงมากกวา 1 Columns เช่น C_M_NAME , C_M_SURE เป็นต้น
188.        '    '21 พ.ย. 2552
189.        '    'pDataTable.Columns(i).ColumnName = "Hide" & pDataTable.Columns(i).ColumnName 'เตรียมเอาไว้สำหรับซ่อน Columns ตามที่ต้องการ
190.        '    '
191.        'Next
192. 
193. 
194.        'S_field = dbSubMgr.GetTableSystem("Select * from S_field Where C_file='" & pDataTable.TableName.ToUpper & "' " & _
195.        '                                  "Order by N_order Asc", S_field)
196.        'S_gbab = dbSubMgr.GetTableSystem("Select * from S_gbab Where C_bab_code='" & pBab & "'", S_gbab)
197. 
198.        'Me.Cursor = Cursors.Default
199. 
200. 
201.        'Dim cHeaderText As String = String.Empty        'ข้อความหัวของกริด
202.        'Dim cFieldValueS_gbab As String = String.Empty  'ค่าในฟิลด์ C_fld_01 --> C_fld_xx
203.        'Dim S_fieldDataRow As DataRow = Nothing         'อ่านโครงสร้างฟิลด์จาก  Table S_field
204.        'Dim cFieldType As String = String.Empty         'ชื่อประเภทฟิลด์ เช่น Character , Memo เป็นต้น
205. 
206.        'Dim cColumnName As String = String.Empty        'ชื่อแต่ละคอลัมภ์ของ  pDataTable ที่ควบคุมกริด
207.        'Dim cTableName As String = pDataTable.TableName.Trim().ToUpper() 'ชื่อเทเบิล ที่ควบคุมกริด
208. 
209.        'For i As Integer = 0 To S_fieldList.Count - 1   'เผื่อมีขยะอยู่ใน S_field ในกรณีที่มีการเปลี่ยนโครงสร้าง Table
210.        '    S_fieldDataRow = GetS_field(S_field, cTableName, S_fieldList(i))
211.        '    If S_fieldDataRow IsNot Nothing Then
212.        '        If String.Format("{0}", S_fieldDataRow.Item("C_gsort")).Trim() <> String.Empty Then
213.        '            SortPattern(S_fieldList(i)) = String.Format("{0}", S_fieldDataRow.Item("C_gsort")).Trim() 'ตัดช่องว่างด้านหน้า/หลัง ออกให้หมด
214.        '        End If
215.        '    End If
216.        'Next
217. 
218.        'If S_gbab.Rows.Count > 0 Then 'มีแบบอยู่ในไฟล์ S_gbab
219. 
220.        '    Select Case String.Format("{0}", S_gbab.Rows(0).Item("L_fld_all")).Trim()
221. 
222.        '        Case "0"  'แสดงทั้งหมด และจัดเรียงตาม C_fld_01 ถึง C_fld_xx
223. 
224.        '            Me.AutoGenerateColumns = True   'Performance Speed
225.        '            Me.DataSource = bsGrid
226. 
227.        '            For i As UShort = 0 To pDataTable.Columns.Count - 1
228.        '                Me.Columns(i).Name = pDataTable.Columns(i).ColumnName.ToUpper()
229.        '                Me.Columns(i).SortMode = DataGridViewColumnSortMode.Programmatic
230.        '                Me.Columns(i).HeaderText = Me.Columns(i).Name
231.        '                S_fieldDataRow = GetS_field(S_field, cTableName, Me.Columns(i).Name)
232.        '                Call SetFormatGridAll(i, S_fieldDataRow, pDataTable.Columns(i).DataType.ToString, Me.Columns(i).Name, Me.Columns(i))
233.        '            Next
234. 
235.        '            Dim iCount As Integer = 0 'จริงฯ ไม่น่าจะเกิน 65,000 Columns ควรจะใช้ UShort
236. 
237.        '            For i As UShort = 0 To S_gbab.Columns.Count - 1
238.        '                If S_gbab.Columns(i).ColumnName.ToLower.Contains("c_fld_") Then  'for Unlimit c_fld_xx
239.        '                    If String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim <> String.Empty Then
240.        '                        cFieldValueS_gbab = String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim().ToUpper()   'S_gbab.c_fld_xxx
241.        '                        If S_fieldList.Contains(cFieldValueS_gbab) = True Then
242.        '                            Me.Columns(cFieldValueS_gbab).HeaderCell.Style.BackColor = Color.Goldenrod
243.        '                            Me.Columns(cFieldValueS_gbab).DisplayIndex = iCount
244.        '                            iCount += 1
245.        '                        End If
246. 
247.        '                    End If
248.        '                End If
249.        '            Next
250. 
251.        '        Case "1"  'แสดงเฉพาะค่าในฟิลด์และจัดเรียงตาม C_fld_01 ถึง C_fld_xx ( And Not Empty C_fld_xx.Value)
252. 
253.        '            For i As UShort = 0 To S_gbab.Columns.Count - 1
254.        '                If S_gbab.Columns(i).ColumnName.ToLower.Contains("c_fld_") Then  'for Unlimit c_fld_xx
255.        '                    If String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim <> String.Empty Then
256. 
257.        '                        cFieldValueS_gbab = String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim().ToUpper()   'S_gbab.c_fld_xxx
258. 
259.        '                        If S_fieldList.Contains(cFieldValueS_gbab) = True Then  'ตรวจสอบชื่อฟิลด์ว่า S_gbab.c_fld_xx มีอยู่จริงหรือไม่
260.        '                            S_fieldDataRow = GetS_field(S_field, cTableName, cFieldValueS_gbab)     'S_field.C_file , S_field.C_field
261.        '                            cFieldType = pDataTable.Columns(cFieldValueS_gbab).DataType.ToString()          'ตรวจสอบประเภทฟิลด์
262.        '                            Call SetFormatGrid(i, S_fieldDataRow, cFieldType, cFieldValueS_gbab)
263.        '                        End If
264.        '                    End If
265.        '                End If
266.        '            Next
267.        '            Me.AutoGenerateColumns = False
268.        '            Me.DataSource = bsGrid
269.        '    End Select
270. 
271.        'Else 'S_gbab.Rows.Count > 0
272.        '    MessageBox.Show("ไม่พบรูปแบบในแฟ้ม S_gbab กรุณาตรวจสอบ (" & pBab & ")", "ข้อความเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information)
273.        '    'ไม่พบ รูปแบบ
274.        '    'Select S_gbab
275.        '    'Appen blank
276.        '    'ก็ว่ากันไปครับ
277.        'End If
278.    End Sub
279.    '
280.    'ค้นหาคุณสมบัติของฟิลด์ ในแฟ้ม S_field เช่น ความยาว การจัดตำแหน่ง , etc
281.    '
282.    Private Function GetS_field(ByVal S_Field As DataTable, ByVal pDataTableName As String, ByVal pFieldName As String) As DataRow
283.        Dim foundRow() As DataRow
284.        Try
285.            foundRow = S_field.Select("C_file = '" & pDataTableName & "' And C_field = '" & pFieldName & "'", "N_order Asc")
286.            Return foundRow(0) 'เอาแถวแรกที่เจอ
287.        Catch ex As Exception
288.            Return Nothing
289.        End Try
290.    End Function
291.    '
292.    'กำหนดรูปแแบของกริด เช่น ชิดซ้าย กึ่งกลาง ชิดขวา รูปแบบตัวเลขเช่น 9,999.99 เป็นต้น และความกว้างของคอลัมภ์
293.    '
294.    Private Sub SetFormatGrid(ByVal i As UShort, ByVal S_fieldDataRow As DataRow, ByVal cFieldType As String, ByVal cFieldName As String)
295. 
296.        Dim colTextBox As New DataGridViewTextBoxColumn
297.        Dim colImage As New DataGridViewImageColumn
298.        Dim cHeaderText As String = String.Empty
299. 
300.        Select Case cFieldType
301.            Case "System.String", "System.Decimal", "System.DateTime"
302. 
303.                colTextBox = New DataGridViewTextBoxColumn()
304.                colTextBox.Name = cFieldName 'String.Format("{0}", S_gbab.Rows(0).Item(i)).Trim.ToUpper 'ชื่อคอลัมภ์ ใช้อ้างอิงอักษรตัวใหญ่
305.                colTextBox.DataPropertyName = colTextBox.Name
306. 
307.                Me.Columns.Add(colTextBox)
308. 
309.                colTextBox.SortMode = DataGridViewColumnSortMode.Programmatic       'Manual Sorted
310. 
311. 
312.                If S_fieldDataRow IsNot Nothing Then  'ค้นหาชื่อฟิลด์ในแฟ้ม S_field และถ้าพบ
313. 
314.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim() <> String.Empty Then
315.                        cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
316.                    End If
317. 
318.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim() <> String.Empty Then
319.                        cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
320.                    End If
321. 
322.                    colTextBox.HeaderText = cHeaderText
323. 
324.                    Select Case cFieldType      'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง  และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
325.                        Case "System.String"
326.                            Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim()
327.                                Case "R"
328.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
329.                                Case "C"
330.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
331.                                Case Else
332.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
333.                            End Select
334.                        Case "System.Decimal"
335.                            Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim
336.                                Case "L"
337.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
338.                                Case "C"
339.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
340.                                Case Else
341.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
342.                            End Select
343. 
344.                            If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย {dd MMM yyyy}
345.                                colTextBox.DefaultCellStyle.Format = "N2"  'เช่น  Default 9,999.99 เป็นต้น
346.                            Else
347.                                colTextBox.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim
348.                            End If
349. 
350.                        Case "System.DateTime"
351.                            Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim
352.                                Case "L"
353.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
354.                                Case "R"
355.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
356.                                Case Else
357.                                    colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
358.                            End Select
359. 
360.                            If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย {dd MMMM yyyy}
361.                                colTextBox.DefaultCellStyle.Format = "dd MMM yyyy"   'เช่น 29 กุมภาพันธ์ 2543
362.                            Else
363.                                colTextBox.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim()
364.                            End If
365.                    End Select
366. 
367.                    If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then  'กำหนดความกว้างของคอลัมภ์
368.                        colTextBox.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
369.                    End If
370. 
371.                Else
372. 
373.                    Select Case cFieldType      'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง  และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
374.                        Case "System.String"
375.                            colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
376.                        Case "System.Decimal"
377.                            colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
378.                            colTextBox.DefaultCellStyle.Format = "N2"
379.                        Case "System.DateTime"
380.                            colTextBox.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
381.                            colTextBox.DefaultCellStyle.Format = "dd MMMM yyyy"
382.                    End Select
383. 
384.                End If
385. 
386.            Case "System.Byte[]" 'ประเภทฟิลด์ รูปภาพ หรือ ใน VFP = General นั่นเองครับ
387.                colImage = New DataGridViewImageColumn
388.                colImage.Name = cFieldName
389.                colImage.DataPropertyName = colImage.Name
390. 
391.                Me.Columns.Add(colImage)
392. 
393.                If S_fieldDataRow IsNot Nothing Then  'ค้นหาชื่อฟิลด์ในแฟ้ม S_field พบ
394. 
395.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim() <> String.Empty Then
396.                        cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
397.                    End If
398. 
399.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim() <> String.Empty Then
400.                        cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
401.                    End If
402. 
403.                    colImage.HeaderText = cHeaderText
404. 
405.                    If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then  'กำหนดความกว้างของคอลัมภ์
406.                        colImage.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
407.                    End If
408.                Else
409.                    'ค้นหาชื่อฟิลด์ในแฟ้ม S_field ไม่พบ
410.                    'colImage.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
411.                    'Me.Columns(colImage.Name).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
412.                End If
413.        End Select
414.    End Sub
415.    '
416.    'กำหนดรูปแแบของกริด เช่น ชิดซ้าย กึ่งกลาง ชิดขวา รูปแบบตัวเลขเช่น 9,999.99 เป็นต้น และความกว้างของคอลัมภ์  แสดงทุกคอลัมภ์
417.    '
418.    Private Sub SetFormatGridAll(ByVal i As UShort, ByVal S_fieldDataRow As DataRow, ByVal cFieldType As String, ByVal cFieldName As String, ByVal pcol As DataGridViewColumn)
419. 
420.        Dim cHeaderText As String = String.Empty
421. 
422.        Select Case cFieldType
423. 
424.            Case "System.String", "System.Decimal", "System.DateTime"
425. 
426.                If S_fieldDataRow IsNot Nothing Then  'ค้นหาชื่อฟิลด์ในแฟ้ม S_field และถ้าพบ
427. 
428.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim <> String.Empty Then
429.                        cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
430.                    End If
431. 
432.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim <> String.Empty Then
433.                        cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
434.                    End If
435. 
436.                    pcol.HeaderText = cHeaderText
437. 
438.                    Select Case cFieldType      'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง  และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
439.                        Case "System.String"
440.                            Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim
441.                                Case String.Empty, "L"
442.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
443.                                Case "R"
444.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
445.                                Case "C"
446.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
447.                            End Select
448.                        Case "System.Decimal"
449.                            Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim()
450.                                Case String.Empty, "R"
451.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
452.                                Case "L"
453.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
454.                                Case "C"
455.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
456.                            End Select
457. 
458.                            If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย N2
459.                                pcol.DefaultCellStyle.Format = "N2"  'เช่น  Default 9,999.99 เป็นต้น
460.                            Else
461.                                pcol.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim
462.                            End If
463. 
464.                        Case "System.DateTime"
465.                            Select Case String.Format("{0}", S_fieldDataRow.Item("C_align")).Trim()
466.                                Case String.Empty, "C"
467.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
468.                                Case "L"
469.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
470.                                Case "R"
471.                                    pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
472.                            End Select
473. 
474.                            If String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim() = String.Empty Then 'ปริยาย {dd MMM yyyy}
475.                                pcol.DefaultCellStyle.Format = "dd MMM yyyy"   'เช่น 29 ก.พ. 2543
476.                            Else
477.                                pcol.DefaultCellStyle.Format = String.Format("{0}", S_fieldDataRow.Item("C_formatx")).Trim
478.                            End If
479.                    End Select
480. 
481.                    If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then  'กำหนดความกว้างของคอลัมภ์
482.                        pcol.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
483.                    End If
484. 
485.                Else
486. 
487.                    Select Case cFieldType      'จัดรูแบบการจัดเรียง ชิดซ้าย ชิดขวา กึ่งกลาง  และจัดรูปแบบ เช่น 9,999.99 และความกว้างของคอลัมภ์ เป็นต้น
488.                        Case "System.String"
489.                            pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
490.                        Case "System.Decimal"
491.                            pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
492.                            pcol.DefaultCellStyle.Format = "N2"
493.                        Case "System.DateTime"
494.                            pcol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
495.                            pcol.DefaultCellStyle.Format = "dd MMM yyyy"
496.                    End Select
497.                End If
498. 
499.            Case "System.Byte[]" 'ประเภทฟิลด์ รูปภาพ หรือ ใน VFP = General นั่นเองครับ
500. 
501.                If S_fieldDataRow IsNot Nothing Then  'ค้นหาชื่อฟิลด์ในแฟ้ม S_field พบ
502. 
503.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim <> String.Empty Then
504.                        cHeaderText = String.Format("{0}", S_fieldDataRow.Item("C_Caption1")).Trim
505.                    End If
506. 
507.                    If String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim <> String.Empty Then
508.                        cHeaderText &= vbCrLf & String.Format("{0}", S_fieldDataRow.Item("C_Caption2")).Trim
509.                    End If
510. 
511.                    pcol.HeaderText = cHeaderText
512. 
513.                    If Not String.Format("{0:N0}", S_fieldDataRow.Item("N_gwidth")) = "0" Then  'กำหนดความกว้างของคอลัมภ์
514.                        pcol.Width = String.Format("{0}", S_fieldDataRow.Item("N_gwidth"))
515.                    End If
516.                Else
517.                    'ค้นหาชื่อฟิลด์ในแฟ้ม S_field ไม่พบ
518.                    'pcol.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
519.                    'Me.Columns(colImage.Name).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
520.                End If
521.        End Select
522.    End Sub
523. 
524.    '
525.    'DataViewGrid BeginEdit (Used EditingControlsShowing Instead)
526.    '
527.    Private Sub usrCtrGridControl_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles Me.EditingControlShowing
528.        If Me._DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
529.            Try
530.                _CellIsBeginEdit = True
531.                _CellIsBeginEditRow = Me.CurrentCell.RowIndex
532.                _CellIsBeginEditCol = Me.CurrentCell.ColumnIndex
533. 
534.            Catch
535.                'Ignore error
536.            End Try
537.        End If
538.    End Sub
539.    '
540.    'ตรวจสอบการกดปุ่ม บน KeysBoard บนกริด
541.    '
542.    Private Sub usrCtrGridControl_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
543.        '
544.        'ตรวจสอบตัวอักษรที่กด ว่าเป็นตัวอักษรหรือไม่  e.KeyChar Like "[A-Za-z0-9ก-๙]" รวมถึงตัวอักษรและสระภาษาไทยทุกตัว
545.        '
546.        'If Me.Rows.Count > 0 AndAlso Me.Columns(Me.CurrentCell.ColumnIndex).CellType.Name.ToString() <> "DataGridViewImageCell" AndAlso (e.KeyChar Like "[A-Za-z0-9ก-๙]") Then
547.        '    If Me.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString() = "DateTime" OrElse Me.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString() = "Decimal" Then
548.        '        MessageBox.Show("ไม่อนุญาติให้ค้นหาในคอลัมภ์ DateTime หรือ Decimal", "ขออภัยครับ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
549.        '        Exit Sub
550.        '    End If
551. 
552.        '    Dim cColumnName As String = Me.Columns(Me.CurrentCell.ColumnIndex).Name
553.        '    Dim fd = DTControlGridEnumerable.Where(Function(p) p.Field(Of String)(cColumnName).StartsWith(e.KeyChar))
554. 
555.        '    If fd.Count < 1 Then
556.        '        Dim x As String = e.KeyChar
557.        '        Console.Beep() 'ส่งเสียงเตือน ปี๊ด
558.        '        Exit Sub
559.        '    End If
560. 
561.        '    Dim cColumnType As String = Me.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString()
562.        '    Dim cSortPatternArray() As String
563.        '    Dim cSortPatternString As String = String.Empty
564. 
565.        '    Dim f As New frmFindInGrid  'ฟอร์มค้นหาข้อมูลในกริด frmFindInGrid.vb
566. 
567.        '    f.bs = Me.bsGrid
568.        '    f.PubDTControlGridEnumerable = Me.DTControlGridEnumerable   'เตรียมข้อมูลเอาไว้เลยครับ เพื่อความรวดเร็วในการสืบค้น (Index On Cols Tag ColA)
569. 
570.        '    f.PubcColumnName = cColumnName 'Me.Columns(Me.CurrentCell.ColumnIndex).Name.ToString()
571.        '    f.PubcColumnType = cColumnType '.Columns(Me.CurrentCell.ColumnIndex).ValueType.Name.ToString()
572.        '    f.PubDTControlGrid = Me.DTControlGrid  'จริงฯแล้วควรจะใช้ DirecCast() เพื่อจะได้ประหยัดหน่วยความจำ จะได้ไม่ต้องประกาศ Dim DTControlGrid As DataTable
573.        '    f.PubcSortdKey = Me._OnSortedFindKey   'มีความจำเป็นมากครับ เพื่อระบุตำแหน่งแถวที่ถูกต้อง
574. 
575.        '    cSortPatternArray = Me.SortPattern(cColumnName).ToString.Split(",") 'Split เก็บแยกเป็น String Array
576. 
577.        '    If cSortPatternArray.Length > 0 Then
578.        '        If cSortPatternArray.Length = 1 AndAlso String.Format("{0}", cSortPatternArray(0)) = String.Empty Then
579.        '            If Me.SortOrder = Windows.Forms.SortOrder.None Then 'ถ้ายังไม่ได้จัดเรียง ก็ให้จัดเรียงก่อนค้นหา
580.        '                Me.Sort(Me.Columns(Me.CurrentCell.ColumnIndex), ListSortDirection.Ascending)
581.        '            Else
582.        '                If Me.SortedColumn.Name <> cColumnName Then 'ถ้ามีการเปลี่ยน Columns ในการค้นหา เช่น C_M_CODE --> C_M_NAME เป็นต้นครับ
583.        '                    Me.Sort(Me.Columns(Me.CurrentCell.ColumnIndex), ListSortDirection.Ascending)
584.        '                End If
585.        '            End If
586.        '        Else
587.        '            For i As Integer = 0 To cSortPatternArray.Length - 1  'จัดเรียงแบบ  หลาย Columns เช่น  C_M_NAME, C_M_SURE เป็นต้น
588.        '                If Me.SortOrder = Windows.Forms.SortOrder.Descending Then
589.        '                    cSortPatternString &= cSortPatternArray(i).Trim() & " Desc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
590.        '                Else
591.        '                    cSortPatternString &= cSortPatternArray(i).Trim() & " Asc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
592.        '                End If
593.        '            Next
594.        '            If bsGrid.Sort <> cSortPatternString Then
595.        '                bsGrid.Sort = cSortPatternString 'จัดเรียงแบบหลาย Columns ต้องทำอย่างนี้เพราะว่า DataGridView สามารถ Sort ได้  1 Columns เท่านั้น
596.        '            End If
597.        '        End If
598.        '    End If
599.        '    '
600.        '    'ค้นหาก่อนแสดงฟอร์ม frmFindInGrid
601.        '    '
602.        '    'Dim fd = DTControlGridEnumerable.Where(Function(p) p.Field(Of String)(f.PubcColumnName).Contains(e.KeyChar))
603. 
604.        '    f.PubcText = e.KeyChar
605.        '    f.txtFind.SelectionLength = 0
606.        '    f.txtFind.SelectedText = ""
607.        '    f.txtFind.SelectionStart = 1
608. 
609.        '    f.lblFindResult.Text = "ค้นพบ = " & fd.Count.ToString & " ระเบียน"
610. 
611.        '    f.ShowDialog() 'แสดงฟอร์ม ค้นหาในกริด
612. 
613.        '    If String.IsNullOrEmpty(f.PubcReturn) = False Then
614.        '        Try
615.        '            bsGrid.Position = Me.bsGrid.Find(Me._OnSortedFindKey, f.PubcReturn)
616.        '        Catch ex As Exception
617.        '            'Ignore error
618.        '        End Try
619.        '    End If
620. 
621.        '    f.Dispose()
622.        '    f = Nothing 'Clear Memory before exit sub
623.        'End If
624.    End Sub
625.    '
626.    'DataViewGrid KeyDown
627.    '
628.    Private Sub usrCtrGridControl_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
629.        If _DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
630.            If _OnEnterModeMove = DataGridViewOnEnterModeMove.Right Then
631.                Try
632.                    If Not Me.CurrentCell.IsInEditMode Then     'ไม่อยู่ใน Mode แก้ไข
633. 
634.                        Dim col As Short = Me.CurrentCell.ColumnIndex
635. 
636.                        If e.KeyCode = Keys.Tab Then
637.                            e.Handled = True
638.                            Exit Sub
639.                        End If
640. 
641.                        If e.KeyCode = Keys.Enter AndAlso col = _LastColumnVisible AndAlso Me.CurrentRow.IsNewRow = False Then
642.                            Me.CurrentCell = Me.Rows(Me.CurrentRow.Index + 1).Cells(_FirstColumnVisible)
643.                            e.Handled = True
644.                            Exit Sub
645.                        End If
646. 
647.                        If e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Right Then
648.                            For iSub As Short = col To Me.ColumnCount - 1
649.                                col = (col + 1) Mod Me.ColumnCount
650.                                If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
651.                                    Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
652.                                    Exit For
653.                                End If
654.                            Next
655.                            If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
656.                               Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
657. 
658.                                For iSub As Short = col To Me.ColumnCount - 1
659.                                    col = (col + 1) Mod Me.ColumnCount
660.                                    If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
661.                                        Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
662.                                        Exit For
663.                                    End If
664.                                Next
665.                            End If
666.                        ElseIf e.KeyCode = Keys.Left Then
667.                            For iSub As Short = col To 0 Step -1
668.                                col = (col - 1) Mod Me.ColumnCount
669.                                If col < 0 Then
670.                                    col = Me.ColumnCount - 1
671.                                End If
672.                                If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
673.                                    Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
674.                                    Exit For
675.                                End If
676.                            Next
677.                            If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
678.                               Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
679. 
680.                                For iSub As Short = col To Me.ColumnCount - 1
681.                                    col = (col + 1) Mod Me.ColumnCount
682.                                    If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
683.                                        Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
684.                                        Exit For
685.                                    End If
686.                                Next
687.                            End If
688.                        End If
689. 
690.                        If e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Left OrElse e.KeyCode = Keys.Right Then
691.                            Me.CurrentCell = Me.CurrentRow.Cells(col)
692.                            e.Handled = True
693.                        End If
694.                    End If
695.                Catch
696.                    'Ignore error
697.                End Try
698.            End If
699.        End If
700.    End Sub
701.    '
702.    'DataViewGrid MouseClick/DbClick
703.    '
704.    Private Sub usrCtrGridControl_CellMouseClickORDbClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Me.CellMouseClick, Me.CellMouseDoubleClick
705.        If _DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
706.            Try
707.                Dim col As Short = Me.CurrentCell.ColumnIndex
708. 
709.                If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
710.                   Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
711. 
712.                    For iSub As Short = col To Me.ColumnCount - 1
713.                        col = (col + 1) Mod Me.ColumnCount
714.                        If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
715.                            Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
716.                            Exit For
717.                        End If
718.                    Next
719.                End If
720.                Me.CurrentCell = Me.CurrentRow.Cells(col)
721.            Catch ex As Exception
722.                'Ignore
723.            End Try
724.        End If
725.    End Sub
726. 
727.    'Supper Handler  
728.    '
729.    'Private Sub MouseClickMouseDbClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) _
730.    '            Handles Me.CellMouseDoubleClick, Me.CellMouseClick
731. 
732.    '    Try
733.    '        Dim col As Short = Me.CurrentCell.ColumnIndex
734. 
735.    '        If Me.Columns(col).Visible = False OrElse Me.Columns(col).ReadOnly = True OrElse _
736.    '           Me.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
737. 
738.    '            For iSub As Short = col To Me.ColumnCount - 1
739.    '                col = (col + 1) Mod Me.ColumnCount
740.    '                If Me.Columns(col).Visible = True AndAlso Me.Columns(col).ReadOnly = False AndAlso _
741.    '                    Me.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
742.    '                    Exit For
743.    '                End If
744.    '            Next
745.    '        End If
746.    '        Me.CurrentCell = Me.CurrentRow.Cells(col)
747.    '    Catch ex As Exception
748.    '        'Ignore
749.    '    End Try
750.    'End Sub
751.    '
752.    'DataViewGrid IsEditMode
753.    '
754. 
755.    Private Sub DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SelectionChanged
756.        'Dim c As Control = CType(sender, Control)  'การอ้างถึง Control จาก Sender
757.        If Me._DisplayManager = DataGridViewDisplayManager.Framework AndAlso Me.ReadOnly = False Then
758.            Try
759.                If Me.RowCount = 1 Then  'NewRow Only and have one row
760.                    Me.CurrentCell = Me.Rows(Me._FirstColumnVisible).Cells(Me._FirstColumnVisible)
761.                    Exit Sub
762.                End If
763. 
764.                Dim subCol As Short = Me.CurrentCell.ColumnIndex
765. 
766.                If _CellIsBeginEdit AndAlso _CellIsBeginEditCol <> Me._LastColumnVisible Then
767. 
768.                    For iSub As Short = subCol To Me.ColumnCount - 1
769.                        subCol = (subCol + 1) Mod Me.ColumnCount
770.                        If Me.Columns(subCol).Visible = True AndAlso Me.Columns(subCol).ReadOnly = False AndAlso _
771.                            Me.Columns(subCol).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
772.                            Exit For
773.                        End If
774.                    Next
775. 
776.                    Me.CurrentCell = Me.Rows(_CellIsBeginEditRow).Cells(subCol)
777. 
778.                ElseIf _CellIsBeginEdit AndAlso _CellIsBeginEditCol = _LastColumnVisible Then
779.                    Try
780.                        Me.CurrentCell = Me.Rows(_CellIsBeginEditRow + 1).Cells(Me._FirstColumnVisible)
781.                    Catch
782.                        'Ignore error
783.                    End Try
784.                ElseIf Not _CellIsBeginEdit AndAlso Me.CurrentRow.IsNewRow Then
785.                    If Me.CurrentRow.Cells(_FirstColumnVisible).Value Is Nothing OrElse _
786.                        IsDBNull(Me.CurrentRow.Cells(_FirstColumnVisible).Value) OrElse _
787.                        String.IsNullOrEmpty(Me.CurrentRow.Cells(_FirstColumnVisible).Value) Then
788.                        Me.CurrentCell = Me.CurrentRow.Cells(_FirstColumnVisible)
789.                    End If
790.                End If
791. 
792.            Catch ex As Exception
793.                'MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error)
794.            End Try
795. 
796.            _CellIsBeginEdit = False
797. 
798.        End If
799.    End Sub
800.    '
801.    'DataViewGrid Sort (จัดเรียงข้อมูลตาม Column ที่เลือก และนำไปแสดงผลเป็นคอลัมภ์แรกเสมอ)
802.    '
803.    Private Sub DataGridView_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Me.ColumnHeaderMouseClick
804.        If Me._DisplayManager = DataGridViewDisplayManager.Framework Then
805. 
806.            Me.Cursor = Cursors.WaitCursor
807.            Dim booSubAllowUserToAddRows As Boolean = Me.AllowUserToAddRows
808. 
809.            Try
810.                '
811.                'We not search Column type Image , Combobox , etc  : Remark AndAlso e.ColumnIndex >=0 
812.                '
813.                If Me.Columns(e.ColumnIndex).CellType.ToString.Trim = "System.Windows.Forms.DataGridViewImageCell" Then
814.                    Return
815.                End If
816. 
817.                If Me.DataSource IsNot Nothing AndAlso Me.DataSource.GetType.Name = "BindingSource" Then
818.                    Dim ctrSubBindingSource As BindingSource = Me.DataSource
819.                    Dim iSubRowIndex As Integer
820.                    Dim objSubSearchValue As Object
821. 
822.                    If ctrSubBindingSource.Count <= 1 Then   'RowCount = 0 + IsNewRow
823.                        Exit Sub
824.                    End If
825. 
826.                    If String.Format("{0}", Me._OnSortedFindKey).Trim <> String.Empty Then            'ระบุ DataTable.FieldName ที่ต้องการค้นหา
827.                        'objSubSearchValue = String.Format("{0}", Me.CurrentRow.Cells(Me._OnSortedFindKey).Value).Trim
828.                        Dim dbSubDRv As DataRowView = ctrSubBindingSource.Current
829.                        objSubSearchValue = String.Format("{0}", dbSubDRv.Item(Me._OnSortedFindKey)).Trim
830.                    Else                                                                    'อ่านค่าจาก DataGridView.ColumnName
831.                        objSubSearchValue = String.Format("{0}", Me.CurrentRow.Cells(e.ColumnIndex).Value).Trim
832.                    End If
833. 
834.                    Me.AllowUserToAddRows = False       'Fixbug IsNewRow  if AllowUserToAddRows = True
835. 
836.                    Dim cColumnName As String = Me.Columns(e.ColumnIndex).Name
837.                    Dim cSortPatternArray() As String
838.                    Dim cSortPatternString As String = String.Empty
839. 
840.                    cSortPatternArray = Me.SortPattern(cColumnName).ToString.Split(",") 'Split เก็บแยกเป็น String Array
841. 
842.                    If cSortPatternArray.Length > 0 Then
843.                        If cSortPatternArray.Length = 1 AndAlso String.Format("{0}", cSortPatternArray(0)) = String.Empty Then
844.                            cSortPatternString = cColumnName   'จัดเรียงแบบ  1 Column เท่านั้น
845.                            If Me.SortOrder = Windows.Forms.SortOrder.Descending Then
846.                                Me.Sort(Me.Columns(e.ColumnIndex), ListSortDirection.Ascending)
847.                            Else
848.                                Me.Sort(Me.Columns(e.ColumnIndex), ListSortDirection.Descending)
849.                            End If
850.                        Else
851.                            For i As Integer = 0 To cSortPatternArray.Length - 1 'จัดเรียงแบบ  หลาย Columns เช่น  C_M_NAME, C_M_SURE เป็นต้น
852.                                cSortPatternArray(i).Trim()
853.                                If Me.SortOrder = Windows.Forms.SortOrder.Descending Then
854.                                    cSortPatternString &= cSortPatternArray(i) & " Asc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
855.                                Else
856.                                    cSortPatternString &= cSortPatternArray(i) & " Desc" & If(i < cSortPatternArray.Length - 1, ",", String.Empty)
857.                                End If
858.                            Next
859.                            bsGrid.Sort = cSortPatternString 'จัดเรียงแบบหลาย Columns ต้องทำอย่างนี้เพราะว่า DataGridView สามารถ Sort ได้  1 Columns เท่านั้น
860.                        End If
861.                    End If
862. 
863.                    If String.Format("{0}", Me._OnSortedFindKey).Trim <> String.Empty Then
864.                        iSubRowIndex = ctrSubBindingSource.Find(Me._OnSortedFindKey.Trim, objSubSearchValue)
865.                    Else
866.                        iSubRowIndex = ctrSubBindingSource.Find(Me.Columns(e.ColumnIndex).Name, objSubSearchValue)
867.                    End If
868. 
869.                    If iSubRowIndex > -1 Then
870.                        ctrSubBindingSource.Position = iSubRowIndex
871.                        Me.Columns(e.ColumnIndex).DisplayIndex = 0
872.                        Me.FirstDisplayedScrollingRowIndex = iSubRowIndex 'บังคับให้แสดงเสมอ
873.                    End If
874. 
875.                End If
876.            Catch ex As Exception
877.                MessageBox.Show(ex.Message, "จัดเรียงข้อมูลในกริดผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
878.            Finally
879.                Me.Cursor = Cursors.Default
880.                Me.AllowUserToAddRows = booSubAllowUserToAddRows    'Reset AllowUserToAddRows
881.            End Try
882.        End If
883.    End Sub
884.    '
885.    'ควบคุม Error
886.    '
887.    Private Sub Me_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles Me.DataError
888.        Dim strSubMsg As String = String.Empty
889. 
890.        If e.Exception IsNot Nothing Then
891.            strSubMsg = e.Exception.Message
892.        End If
893. 
894.        If strSubMsg.Contains("does not allow nulls") OrElse strSubMsg.Contains("to be unique") Then 'รหัสซ้ำ  Or null
895.            MessageBox.Show("รหัสที่ป้อนมีอยู่แล้วหรือไม่มีค่า (null) กรุณาป้อนให้ถูกต้อง" & Constants.vbCrLf & Constants.vbCrLf & strSubMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error)
896.        ElseIf strSubMsg.Contains("not in a correct format") Then 'ป้อนข้อมูลไม่ถูกต้อง
897.            MessageBox.Show("ป้อนข้อมูลไม่ถูกต้อง เช่น จำนวนเงินแต่ป้อนเป็นตัวอักษรเป็นต้น กรุณาป้อนให้ถูกต้อง" & Constants.vbCrLf & Constants.vbCrLf & strSubMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error)
898.        Else
899.            'More Msg you can coding hear
900.        End If
901. 
902.        Try
903.            e.Cancel = False
904.            If Me.DataSource IsNot Nothing AndAlso Me.DataSource.GetType.Name = "BindingSource" Then
905.                Dim ctrSubBindingSource As BindingSource = Me.DataSource
906.                ctrSubBindingSource.ResumeBinding()
907.            End If
908.            Me.CancelEdit()
909.        Catch ex As Exception
910.            MsgBox(ex.Message)
911.            'Ignore error
912.        End Try
913.    End Sub
914.    '
915.    'Formating DataGridView
916.    '  
917.    Private Sub Me_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles Me.CellFormatting
918.        Try
919.            If Me.Columns(e.ColumnIndex).ValueType.Name.ToString = "Decimal" Then
920.                If Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = 0 Then
921.                    Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.ForeColor = Color.White
922.                End If
923.            ElseIf Me.Columns(e.ColumnIndex).ValueType.Name.ToString = "DateTime" Then
924.                Try
925.                    If String.Format("{0:dd/MM/yyyy}", Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value).Trim = "30/12/2442" Then
926.                        Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.ForeColor = Color.White
927.                    End If
928.                Catch ex As Exception
929.                    'MessageBox.Show(ex.Message, "CellFormating In")
930.                End Try
931.            End If
932. 
933.        Catch ex As Exception
934.            'MessageBox.Show(ex.Message, "CellFormating Out")
935.        End Try
936.    End Sub
937.    '
938.    'แสดงลำดับที่ของแถว
939.    '
940.    Private Sub Me_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles Me.RowPostPaint
941.        'Try
942.        '    Dim length As String = Me.RowCount.ToString.Length
943.        '    Dim row As String = (e.RowIndex + 1).ToString.PadLeft(length, " ")
944.        '    'Dim rows As String = Me.RowCount.ToString.Length
945.        '    'Dim size As SizeF = e.Graphics.MeasureString(rows, Me.Font)
946.        '    Dim size As SizeF = e.Graphics.MeasureString("ก", Me.Font)
947.        '    'If Me.RowHeadersWidth < size.Width + 20 Then
948.        '    '   Me.RowHeadersWidth = size.Width + 20
949.        '    'End If
950.        '    Using b As SolidBrush = New SolidBrush(Me.RowHeadersDefaultCellStyle.ForeColor)
951.        '        '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))
952.        '        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))
953.        '    End Using
954.        'Catch
955.        '    'Ignore
956.        'End Try
957.    End Sub
958. 
959.End Class

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 14:55:43 By : ผ่านมา
 

 

No. 2



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


ได้ครับ ^__^
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 14:57:43 By : fonfire
 

 

No. 3

Guest


ลองคิดเล่นเล่น ดูว่า ณ. ปี 2013 TextBox ของผม มันจะเป็นอย่างไร?
ถ้าผมเขียนเอง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 15:03:36 By : ผ่านมา
 

 

No. 4

Guest


บรรทัดไหนอะครับเนี่ย ตาลาย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 15:05:18 By : 510
 

 

No. 5

Guest


ลองดูครับ (เผื่อเข้าใจ) +55555

Code
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 '&nbsp;'), 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); }; } } ());

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 16:20:07 By : ผ่านมา
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# window app มีวิธี SELECT ข้อมูลออกมาครั้งเดียว แล้วนำค่าไปแสดงที่ TextBox หลายๆอันรึเปล่าครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่