VERSION 5.00 Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX" Begin VB.Form add_auther BackColor = &H00C0C0C0& Caption = "เพิ่มรายชื่อผู้แต่ง" ClientHeight = 3570 ClientLeft = 60 ClientTop = 345 ClientWidth = 7425 Icon = "add_auther.frx":0000 LinkTopic = "Form1" MDIChild = -1 'True ScaleHeight = 3570 ScaleWidth = 7425 Begin MSFlexGridLib.MSFlexGrid showauth Height = 2175 Left = 1800 TabIndex = 16 Top = 600 Visible = 0 'False Width = 4335 _ExtentX = 7646 _ExtentY = 3836 _Version = 393216 Rows = 8 Cols = 3 FixedCols = 0 BackColor = 12640511 ForeColor = 12582912 FocusRect = 0 SelectionMode = 1 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty End Begin VB.TextBox Text4 BackColor = &H00C0FFFF& BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 3600 TabIndex = 14 Top = 1920 Visible = 0 'False Width = 975 End Begin VB.CommandButton cmdsearch Caption = "Search" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 735 Left = 6240 Picture = "add_auther.frx":0E42 Style = 1 'Graphical TabIndex = 12 Top = 360 Width = 1095 End Begin VB.TextBox Text3 BackColor = &H00C0FFFF& Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00C00000& Height = 330 Left = 1800 TabIndex = 10 Top = 2400 Width = 3975 End Begin VB.Frame Frame1 BackColor = &H00C0C0C0& Caption = "Penname" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 735 Left = 600 TabIndex = 7 Top = 1440 Width = 2895 Begin VB.OptionButton Optpenname BackColor = &H00C0C0C0& Caption = "No" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 210 Index = 1 Left = 1680 TabIndex = 9 Top = 360 Width = 615 End Begin VB.OptionButton Optpenname BackColor = &H00C0C0C0& Caption = "Yes" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 195 Index = 0 Left = 480 TabIndex = 8 Top = 360 Width = 735 End End Begin VB.TextBox Text2 BackColor = &H00C0FFFF& BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00C00000& Height = 810 Left = 1800 MultiLine = -1 'True TabIndex = 6 Top = 600 Width = 3975 End Begin VB.TextBox Text1 BackColor = &H00C0FFFF& BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00C00000& Height = 330 Left = 1800 TabIndex = 5 Top = 240 Width = 1455 End Begin VB.CommandButton cmdcan Caption = "Cancel" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 5040 Picture = "add_auther.frx":114C Style = 1 'Graphical TabIndex = 4 Top = 2880 Width = 1095 End Begin VB.CommandButton cmdedit Caption = "Edit" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 3840 Picture = "add_auther.frx":1456 Style = 1 'Graphical TabIndex = 3 Top = 2880 Width = 1095 End Begin VB.CommandButton Command1 Caption = "Exit" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 6240 Picture = "add_auther.frx":1898 Style = 1 'Graphical TabIndex = 2 Top = 2880 Width = 1095 End Begin VB.CommandButton cmdadd Caption = "Add" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 2640 Picture = "add_auther.frx":1CDA Style = 1 'Graphical TabIndex = 13 Top = 2880 Width = 1095 End Begin VB.CommandButton cmdsaveadd Caption = "Save" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 2640 Picture = "add_auther.frx":2B1C Style = 1 'Graphical TabIndex = 15 Top = 2880 Visible = 0 'False Width = 1095 End Begin VB.CommandButton Cmdsaveedit Caption = "Save" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 3840 Picture = "add_auther.frx":2E26 Style = 1 'Graphical TabIndex = 17 Top = 2880 Visible = 0 'False Width = 1095 End Begin VB.Label Label3 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "ชื่อ - นามสกุล(จริง) :" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 0 TabIndex = 11 Top = 2400 Width = 1695 End Begin VB.Label Label2 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "ชื่อ - นามสุกล :" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 360 TabIndex = 1 Top = 600 Width = 1335 End Begin VB.Label Label1 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "รหัสผู้แต่ง :" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 195 Left = 600 TabIndex = 0 Top = 240 Width = 1095 End End Attribute VB_Name = "add_auther" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim Conn As New ADODB.Connection Dim add_auth As New ADODB.Recordset Dim reana As New ADODB.Recordset Dim clrtautab As New ADODB.Recordset Dim authbk As New ADODB.Recordset Dim b_edit As Boolean Private Sub Cmdcan_Click() Text1.Text = "" Text1.Enabled = True Text2.Text = "" Text3.Text = "" Text3.Enabled = False Text4.Text = "" Text2.Enabled = True Optpenname(0).Value = False Optpenname(1).Value = False Optpenname(0).Enabled = False Optpenname(1).Enabled = False Cmdadd.Visible = True Cmdadd.Enabled = True cmdsaveadd.Visible = False Cmdsearch.Enabled = True Cmdedit.Visible = True Cmdedit.Enabled = False Cmdsaveedit.Visible = False Cmdsearch.Enabled = True End Sub Private Sub Cmdadd_Click() Cmdadd.Visible = False cmdsaveadd.Visible = True Cmdsearch.Enabled = False Text2.Text = "" Text3.Text = "" Text4.Text = "" Optpenname(1).Value = True Set clrtautab = New ADODB.Recordset With clrtautab If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authctrl", Conn, adOpenForwardOnly, adLockReadOnly If Not .EOF Then Text1.Text = .Fields(0).Value .Close End With Set clrtautab = Nothing Optpenname(0).Enabled = True Optpenname(1).Enabled = True b_edit = True Text2.SetFocus End Sub Private Sub Cmdedit_Click() b_edit = True Text2.Enabled = True Optpenname(0).Enabled = True Optpenname(1).Enabled = True If Optpenname(0).Value = True Then Text3.Enabled = True Cmdedit.Visible = False Cmdsaveedit.Visible = True End Sub Private Sub Cmdsaveedit_Click() Dim ad_ctrlauth As Long Dim i As Integer Dim auth_id As String If MsgBox("ต้องการบันทึกข้อมูลหรือไม่", vbQuestion + vbYesNo, "บันทึกข้อมูลรายชื่อผู้แต่ง") = vbYes Then 'ค้นหาชื่อจริงผู้แต่ง If Optpenname(0).Value = True Then Set authbk = New ADODB.Recordset With authbk If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname where penname= '" & Trim(Text3.Text) & "'", Conn, adOpenForwardOnly, adLockReadOnly If Not .EOF Then Text4.Text = .Fields(0).Value .Close End With Set clrtautab = Nothing If Trim(Text4.Text) = "" Then Set clrtautab = New ADODB.Recordset With clrtautab If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authctrl", Conn, adOpenForwardOnly, adLockReadOnly If Not .EOF Then Text4.Text = .Fields(0).Value .Close End With Set clrtautab = Nothing Set add_auth = New ADODB.Recordset With add_auth If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname", Conn, adOpenForwardOnly, adLockOptimistic .AddNew .Fields(0).Value = Trim(Text4.Text) .Fields(1).Value = Trim(Text3.Text) .Update .Close End With Set add_auth = Nothing ad_ctrlauth = Val(Text4.Text) + 1 auth_id = Trim(Str(ad_ctrlauth)) For i = 1 To 7 - Len(Trim(Str(ad_ctrlauth))) auth_id = "0" + auth_id Next i Set clrtautab = New ADODB.Recordset With clrtautab If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authctrl", Conn, adOpenForwardOnly, adLockOptimistic If Not .EOF Then .Fields(0).Value = Trim(auth_id) .Update End If .Close End With Set clrtautab = Nothing End If Set add_auth = New ADODB.Recordset With add_auth If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname where idno= '" & Trim(Text1.Text) & "'", Conn, adOpenForwardOnly, adLockOptimistic If Not .EOF Then .Fields(1).Value = Trim(Text2.Text) If Optpenname(0).Value = True Then .Fields(2).Value = Trim(Text4.Text) .Update End If .Close End With Set add_auth = Nothing Else Set add_auth = New ADODB.Recordset With add_auth If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname where idno= '" & Trim(Text1.Text) & "'", Conn, adOpenForwardOnly, adLockOptimistic If Not .EOF Then .Fields(1).Value = Trim(Text2.Text) .Update End If .Close End With Set add_auth = Nothing End If Call Cmdcan_Click End If End Sub Private Sub cmdsearch_Click() Dim num_rec As Integer If Trim(Text1.Text) <> "" Or Trim(Text2.Text) <> "" Then Set authbk = New ADODB.Recordset With authbk If .State = adStateOpen Then .Close .CursorLocation = adUseClient If Trim(Text1.Text) <> "" Then .Open "Select * From authname where idno= '" & Trim(Text1.Text) & "'", Conn, adOpenForwardOnly, adLockReadOnly End If If Trim(Text2.Text) <> "" Then .Open "Select * From authname where left(penname,length('" & Trim(Text2.Text) & "'))='" & Trim(Text2.Text) & "'", Conn, adOpenForwardOnly, adLockReadOnly End If If Not .EOF Then showauth.Rows = .RecordCount + 1 .MoveFirst num_rec = 1 Do While Not .EOF showauth.TextMatrix(num_rec, 0) = .Fields(0).Value showauth.ColAlignment(0) = flexAlignCenterCenter showauth.TextMatrix(num_rec, 1) = .Fields(1).Value showauth.ColAlignment(1) = flexAlignLeftCenter If Trim(.Fields(2).Value) <> "" Then showauth.TextMatrix(num_rec, 2) = .Fields(2).Value .MoveNext num_rec = num_rec + 1 Loop showauth.Visible = True Else MsgBox "ไม่พบข้อมูลที่ต้องการค้นหา", vbCritical + vbOKOnly, "ผลการค้นหา" Text1.Text = "" Text2.Text = "" End If .Close End With Set authbk = Nothing Cmdsearch.Enabled = False Cmdadd.Enabled = False Cmdedit.Enabled = True Else MsgBox "กรุณาพิมพ์ข้อมูลที่ต้องการค้นหา", vbCritical + vbOKOnly, "ข้อผิดพลาด" End If End Sub Private Sub Command1_Click() If Conn.State = adStateOpen Then Conn.Close Set Conn = Nothing Unload Me End Sub Private Sub cmdsaveadd_Click() Dim ad_ctrlauth As Long Dim i As Integer Dim auth_id As String If MsgBox("ต้องการบันทึกข้อมูลหรือไม่", vbQuestion + vbYesNo, "บันทึกข้อมูลรายชื่อผู้แต่ง") = vbYes Then Set clrtautab = New ADODB.Recordset With clrtautab If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authctrl", Conn, adOpenForwardOnly, adLockReadOnly If Not .EOF Then Text1.Text = .Fields(0).Value .Close End With Set clrtautab = Nothing 'ค้นหาชื่อจริงผู้แต่ง If Optpenname(0).Value = True Then Set authbk = New ADODB.Recordset With authbk If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname where penname= '" & Trim(Text3.Text) & "'", Conn, adOpenForwardOnly, adLockReadOnly If Not .EOF Then Text4.Text = .Fields(0).Value .Close End With Set authbk = Nothing If Trim(Text4.Text) = "" Then ad_ctrlauth = Val(Text1.Text) + 1 Text4.Text = Trim(Str(ad_ctrlauth)) For i = 1 To 7 - Len(Trim(Str(ad_ctrlauth))) Text4.Text = "0" + Text4.Text Next i Set add_auth = New ADODB.Recordset With add_auth If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname", Conn, adOpenForwardOnly, adLockOptimistic .AddNew .Fields(0).Value = Trim(Text4.Text) .Fields(1).Value = Trim(Text3.Text) .Update .Close End With Set add_auth = Nothing ad_ctrlauth = Val(Text4.Text) + 1 auth_id = Trim(Str(ad_ctrlauth)) For i = 1 To 7 - Len(Trim(Str(ad_ctrlauth))) auth_id = "0" + auth_id Next i Set clrtautab = New ADODB.Recordset With clrtautab If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authctrl", Conn, adOpenForwardOnly, adLockOptimistic If Not .EOF Then .Fields(0).Value = Trim(auth_id) .Update End If .Close End With Set clrtautab = Nothing End If Set add_auth = New ADODB.Recordset With add_auth If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname", Conn, adOpenForwardOnly, adLockOptimistic .AddNew .Fields(0).Value = Trim(Text1.Text) .Fields(1).Value = Trim(Text2.Text) If Optpenname(0).Value = True Then .Fields(2).Value = Trim(Text4.Text) .Update .Close End With Set add_auth = Nothing Else Set add_auth = New ADODB.Recordset With add_auth If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname", Conn, adOpenForwardOnly, adLockOptimistic .AddNew .Fields(0).Value = Trim(Text1.Text) .Fields(1).Value = Trim(Text2.Text) .Update .Close End With Set add_auth = Nothing ad_ctrlauth = Val(Text1.Text) + 1 Text1.Text = Trim(Str(ad_ctrlauth)) For i = 1 To 7 - Len(Trim(Str(ad_ctrlauth))) Text1.Text = "0" + Text1.Text Next i Set clrtautab = New ADODB.Recordset With clrtautab If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authctrl", Conn, adOpenForwardOnly, adLockOptimistic If Not .EOF Then .Fields(0).Value = Trim(Text1.Text) .Update End If .Close End With Set clrtautab = Nothing End If Call Cmdcan_Click End If End Sub Private Sub Form_Load() Set Conn = New ADODB.Connection Conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _ & "SERVER=192.168.1.15;" _ & "DATABASE=magazine;" _ & "UID=chaiya;" _ & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384 Conn.CursorLocation = adUseClient Conn.Mode = adModeUnknown Conn.Open 'With Conn ' If .State = adStateOpen Then .Close ' .Mode = adModeUnknown ' .Open StrCon 'End With showauth.Rows = 8 With showauth .Row = 0 .ColWidth(0) = 1000 .ColWidth(1) = 3500 .ColWidth(2) = 1000 .TextMatrix(0, 0) = "รหัสผู้แต่ง" .ColAlignment(0) = flexAlignCenterCenter .TextMatrix(0, 1) = "ชื่อ - นามสกุล " .ColAlignment(1) = flexAlignCenterCenter End With b_edit = False End Sub Private Sub Form_Unload(Cancel As Integer) If Conn.State = adStateOpen Then Conn.Close Set Conn = Nothing End Sub Private Sub Optpenname_Click(Index As Integer) If Optpenname(0).Value = True Then If b_edit = True Then Text3.Enabled = True Text3.SetFocus End If Else Text4.Text = "" Text3.Text = "" Text3.Enabled = False End If End Sub Private Sub showauth_DblClick() Text1.Text = showauth.TextMatrix(showauth.Row, 0) Text2.Text = showauth.TextMatrix(showauth.Row, 1) Text1.Enabled = False Text2.Enabled = False If Trim(showauth.TextMatrix(showauth.Row, 2)) <> "" Then Text4.Text = showauth.TextMatrix(showauth.Row, 2) Optpenname(0).Value = True Set authbk = New ADODB.Recordset With authbk If .State = adStateOpen Then .Close .CursorLocation = adUseClient .Open "Select * From authname where idno= '" & Trim(Text4.Text) & "'", Conn, adOpenForwardOnly, adLockReadOnly If Not .EOF Then Text3.Text = .Fields(1).Value .Close End With Set authbk = Nothing Optpenname(0).Value = True Else Optpenname(1).Value = True End If showauth.Visible = False End Sub