www.pudn.com > Doe.rar > FrmBuildFac.frm
VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form FrmBuildFac
BorderStyle = 1 '單線固定
Caption = "建立控制因子"
ClientHeight = 6585
ClientLeft = 45
ClientTop = 330
ClientWidth = 7710
Icon = "FrmBuildFac.frx":0000
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 6585
ScaleWidth = 7710
Begin VB.TextBox txtName
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3000
TabIndex = 6
Top = 3000
Visible = 0 'False
Width = 1335
End
Begin VB.TextBox txtID
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Left = 1320
TabIndex = 5
Top = 2880
Visible = 0 'False
Width = 615
End
Begin VB.CommandButton cmdExit
Caption = "離開"
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 6120
TabIndex = 4
Top = 5880
Width = 1215
End
Begin VB.CommandButton cmdUpdate
Caption = "修改"
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4200
TabIndex = 3
Top = 5880
Width = 1215
End
Begin VB.CommandButton cmdDel
Caption = "刪除"
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2280
TabIndex = 2
Top = 5880
Width = 1215
End
Begin VB.CommandButton cmdAdd
Caption = "新增"
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 360
TabIndex = 1
Top = 5880
Width = 1215
End
Begin MSDataGridLib.DataGrid DGFac
Height = 5295
Left = 360
TabIndex = 0
Top = 360
Width = 6975
_ExtentX = 12303
_ExtentY = 9340
_Version = 393216
AllowUpdate = 0 'False
HeadLines = 2
RowHeight = 20
FormatLocked = -1 'True
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "新細明體"
Size = 12
Charset = 136
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "新細明體"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = "控制因子代號"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 1028
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = "控制因子名稱"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 1028
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
ColumnWidth = 1995.024
EndProperty
BeginProperty Column01
ColumnWidth = 4004.788
EndProperty
EndProperty
End
End
Attribute VB_Name = "FrmBuildFac"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rsFacBuild As Recordset
Dim newCellText As String
Dim priCellValue As String
Dim cnFac As New Connection
Private Sub cmdAdd_Click()
Dim iAns As Integer
With cmdAdd
If .Caption = "新增" Then
DGFac.AllowAddNew = True
' DGFac.AllowUpdate = True
.Caption = "完成"
cmdDel.Enabled = False
cmdUpdate.Enabled = False
Call MoveTxt
ElseIf .Caption = "完成" Then
If txtID.Text <> "" And txtName.Text <> "" Then
iAns = MsgBox("是否儲存資料 ? ", vbYesNo + vbQuestion, "詢問訊息")
If iAns = vbYes Then
Call SaveFun
End If
End If
DGFac.AllowAddNew = False
.Caption = "新增"
cmdDel.Enabled = True
cmdUpdate.Enabled = True
DGFac.AllowUpdate = False
txtID = ""
txtID.Visible = False
txtName.Text = ""
txtName.Visible = False
End If
End With
End Sub
Private Sub cmdDel_Click()
On Error GoTo RR
Dim iAns As Integer
If rsFacBuild.RecordCount > 0 Then
If Not IsNull(rsFacBuild.Fields(0).Value) Then
iAns = MsgBox("請問是否真的刪除控制因子 ' " & rsFacBuild.Fields(0).Value & " - " & rsFacBuild.Fields(1).Value & " ' ? ", vbQuestion + vbYesNo, "詢問訊息")
If iAns = vbYes Then
rsFacBuild.Delete
End If
Else
MsgBox "無資料可刪除", vbOKOnly + vbCritical, "錯誤訊息"
End If
DGFac.Refresh
End If
Exit Sub
RR:
Select Case Err.Number
Case Else
MsgBox "Error : " & Err.Number & " - " & Err.Description
End Select
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdUpdate_Click()
With cmdUpdate
If .Caption = "修改" Then
DGFac.AllowUpdate = True
' DGFac.AddNewMode
.Caption = "完成"
cmdDel.Enabled = False
cmdAdd.Enabled = False
Else
.Caption = "修改"
cmdDel.Enabled = True
cmdAdd.Enabled = True
DGFac.AllowUpdate = False
End If
End With
End Sub
Private Sub DGFac_AfterColUpdate(ByVal ColIndex As Integer)
If DGFac.Col = 0 Then
If DGFac.Columns(0).Text <> "" Then
DGFac.Col = 1
DGFac.SetFocus
Else
MsgBox "資料不可為空, 請輸入", vbOKOnly + vbInformation, "通知訊息"
DGFac.Col = 0
DGFac.SetFocus
End If
ElseIf DGFac.Col = 1 Then
If DGFac.Columns(1).Text <> "" Then
DGFac.Col = 0
DGFac.SetFocus
Else
MsgBox "資料不可為空, 請輸入", vbOKOnly + vbInformation, "通知訊息"
DGFac.Col = 1
DGFac.SetFocus
End If
End If
End Sub
Private Sub DGFac_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
Dim rsBack As Recordset, fldName As String
fldName = DGFac.Columns(ColIndex).DataField
Set rsBack = rsFacBuild.Clone
If priCellValue = "" Then
MsgBox "控制因子代號不可為空, 請輸入", vbOKOnly + vbInformation, "通知訊息"
Cancel = True
DGFac.Col = 0
DGFac.SetFocus
Exit Sub
End If
If rsBack.RecordCount > 1 Then
rsBack.MoveFirst
rsBack.Find fldName & " = '" & newCellText & "'"
If Not rsBack.EOF Then
MsgBox "資料重複", vbOKOnly + vbInformation, "通知訊息"
Cancel = True
Exit Sub
End If
End If
DGFac.Text = UCase(DGFac.Text)
End Sub
Private Sub DGFac_Change()
newCellText = DGFac.Text
priCellValue = DGFac.Columns(0).Text
End Sub
Private Sub DGFac_KeyPress(KeyAscii As Integer)
If DGFac.Row <> -1 Then
Select Case KeyAscii '按確定
Case vbKeyReturn
If DGFac.Text = "" Then
MsgBox "資料不可為空", vbOKOnly + vbInformation, "通知訊息"
DGFac.SetFocus
Exit Sub
End If
Case 96 To 122 '小寫轉大寫
KeyAscii = KeyAscii - 32
End Select
End If
End Sub
Private Sub DGFac_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
' On Error GoTo RR
' If LastCol = 0 Then
' If DGFac.Columns(0).Text <> "" Then
' DGFac.Col = 1
' DGFac.SetFocus
' Else
' MsgBox "請輸入控制因子代號", vbOKOnly + vbInformation, "通知訊息"
' DGFac.Col = 0
' DGFac.SetFocus
' End If
' ElseIf LastCol = 1 Then
' If DGFac.Columns(1).Text <> "" Then
' DGFac.Col = 0
' DGFac.SetFocus
' Else
' MsgBox "請輸入控制因子名稱", vbOKOnly + vbInformation, "通知訊息"
' DGFac.Col = 1
' DGFac.SetFocus
' End If
' End If
' Exit Sub
'RR:
' Err.Clear
End Sub
Private Sub Form_Load()
' '判斷 Key
' gnWhatVersion = goKeyCheck.WhatVersion
' gnSpecialCust = goKeyCheck.SpecialCustomer
' If gnWhatVersion <> 16 And gnSpecialCust <> 1000 Then
' MsgBox "Key Error ", vbOKOnly + vbCritical, "錯誤訊息"
' End
' End If
'進行連結
Set cnFac = New Connection
Set cnFac = Nothing
If cnFac.State <> adStateClosed Then cnFac.Close
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & _
"\DOE.msp;Persist Security Info=False"
cnFac.ConnectionString = connStr
cnFac.Open
Set rsFacBuild = New Recordset
If rsFacBuild.State <> adStateClosed Then rsFacBuild.Close
strSQL = "select * from FactorType"
rsFacBuild.CursorLocation = adUseClient
rsFacBuild.Open strSQL, cnFac, adOpenDynamic, adLockOptimistic
With DGFac
.Columns(0).DataField = "FactorID"
.Columns(1).DataField = "FactorName"
Set .DataSource = rsFacBuild
End With
End Sub
Private Sub Form_Resize()
'設定 Form 位置
Me.Top = (ODEMDIForm.ScaleHeight - Me.Height) / 2
Me.Left = (ODEMDIForm.ScaleWidth - Me.Width) / 2
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set cnFac = Nothing
Set rsFacBuild = Nothing
End Sub
Private Sub MoveTxt()
Dim gcolId As MSDataGridLib.Column
Dim gcolName As MSDataGridLib.Column
Dim NowRow As Integer
NowRow = rsFacBuild.RecordCount
Set gcolId = DGFac.Columns(0)
Set gcolName = DGFac.Columns(1)
txtID.Move DGFac.Left + gcolId.Left, DGFac.Top + DGFac.RowTop(NowRow), gcolId.Width, DGFac.RowHeight
txtName.Move DGFac.Left + gcolName.Left, DGFac.Top + DGFac.RowTop(NowRow), gcolName.Width, DGFac.RowHeight
txtID.Visible = True
txtName.Visible = True
txtID.SetFocus
End Sub
Private Sub txtID_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn '確定
If txtID.Text = "" Then
MsgBox "請輸入控制因子代號", vbOKOnly + vbInformation, "通知訊息"
txtID.SetFocus
Exit Sub
ElseIf txtName.Text = "" Then
MsgBox "請輸入控制因子名稱", vbOKOnly + vbInformation, "通知訊息"
txtName.SetFocus
Exit Sub
Else
Call SaveTxt
End If
Case 97 To 122 '小寫轉大寫
KeyAscii = KeyAscii - 32
End Select
End Sub
Private Sub SaveTxt()
Dim rsBack As Recordset
Set rsBack = rsFacBuild.Clone
If rsBack.RecordCount > 1 Then
rsBack.MoveFirst
rsBack.Find "FactorID = '" & txtID.Text & "'"
If Not rsBack.EOF Then
MsgBox "資料重複", vbOKOnly + vbInformation, "通知訊息"
txtID.SetFocus
Exit Sub
End If
End If
With rsFacBuild
.AddNew
.Fields(0).Value = txtID.Text
.Fields(1).Value = txtName.Text
.Update
txtID.Text = ""
txtName.Text = ""
txtID.Visible = False
txtName.Visible = False
End With
' DGFac.AllowAddNew = False
Set DGFac.DataSource = rsFacBuild
Call MoveTxt
End Sub
Private Sub txtName_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn '確定
If txtID.Text = "" Then
MsgBox "請輸入控制因子代號", vbOKOnly + vbInformation, "通知訊息"
txtID.SetFocus
Exit Sub
ElseIf txtName.Text = "" Then
MsgBox "請輸入控制因子名稱", vbOKOnly + vbInformation, "通知訊息"
txtName.SetFocus
Exit Sub
Else
Call SaveTxt
End If
Case 97 To 122 '小寫轉大寫
KeyAscii = KeyAscii - 32
End Select
End Sub
Private Sub SaveFun()
'判斷是否重複
Dim rsBack As Recordset
Set rsBack = rsFacBuild.Clone
If rsBack.RecordCount > 1 Then
rsBack.MoveFirst
rsBack.Find "FactorID = '" & txtID.Text & "'"
If Not rsBack.EOF Then
MsgBox "資料重複", vbOKOnly + vbInformation, "通知訊息"
Exit Sub
End If
End If
'進行存入動作
With rsFacBuild
.AddNew
.Fields(0).Value = txtID.Text
.Fields(1).Value = txtName.Text
.Update
End With
' DGFac.AllowAddNew = False
Set DGFac.DataSource = rsFacBuild
End Sub