⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repairgrid.ctl

📁 汽车维修管理软件。其中包含三个编辑控件。
💻 CTL
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.UserControl RepairGrid 
   ClientHeight    =   3600
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   4800
   HasDC           =   0   'False
   ScaleHeight     =   3600
   ScaleWidth      =   4800
   Begin VB.CommandButton FindButton 
      Caption         =   "┉"
      Height          =   255
      Left            =   1080
      TabIndex        =   2
      Top             =   3360
      Width           =   255
   End
   Begin VB.TextBox InputText 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   270
      Left            =   1320
      TabIndex        =   1
      Top             =   2160
      Visible         =   0   'False
      Width           =   975
   End
   Begin MSFlexGridLib.MSFlexGrid Grid 
      Height          =   3135
      Left            =   0
      TabIndex        =   0
      Top             =   240
      Width           =   4815
      _ExtentX        =   8493
      _ExtentY        =   5530
      _Version        =   393216
      Cols            =   4
      FixedCols       =   0
      BackColorFixed  =   -2147483639
      BackColorBkg    =   -2147483639
      AllowBigSelection=   0   'False
      FocusRect       =   2
      HighLight       =   0
      AllowUserResizing=   1
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
End
Attribute VB_Name = "RepairGrid"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private m_IsPopup As Boolean
Private m_DataList As Collection
Private m_IsColChange As Boolean
'Private m_IsRowChange As Boolean
Private m_EditCol As Long
Private m_EditRow As Long
Private m_WorkMianId As Long
Public Event PopupFind(ByRef pComm As String, ByRef pVal As TextBox)
Public Event ChangeSum()
Private Sub FindButton_Click()
Dim t_find As String
t_find = vbNullString
If InputText.Text <> "" Then t_find = "WHERE Name LIKE '" & Trim$(InputText.Text) & "%'"
m_IsPopup = True
RaiseEvent PopupFind("SELECT Code as 维修项目代码,Name as 维修项目名称 FROM RepairItem " & t_find, _
                     InputText)
InputText.SetFocus
End Sub



Private Sub Grid_DblClick()
If Grid.Row > 0 And Grid.Col <> 0 Then
ShowEdit
InputText.Text = Grid.Text
InputText.SetFocus
InputText.SelStart = Len(InputText)

End If
End Sub
Public Property Let WorkMianId(ByVal vData As Long)
m_WorkMianId = vData
End Property


Private Sub Grid_KeyPress(KeyAscii As Integer)
Dim t_char As String
m_IsPopup = True
ShowEdit
If Grid.Col = 2 Then
   If KeyAscii > 47 And KeyAscii < 58 Then
      t_char = Chr$(KeyAscii) & vbNullString
   Else
      Exit Sub
   End If
Else
  If (KeyAscii < vbKeyA Or KeyAscii > vbKeyZ) And (KeyAscii < 97 Or KeyAscii > 122) Then Exit Sub
   t_char = Chr$(KeyAscii) & vbNullString
End If
InputText.Text = t_char
InputText.SetFocus
InputText.SelStart = 2

End Sub


Private Sub Grid_SelChange()
'选择变化
Dim t_repair As RepairItem

If m_EditRow < 1 Then Exit Sub
Set t_repair = m_DataList.Item(m_EditRow)

   If m_IsColChange Then
       
        If m_EditCol = 1 Then '如果正在编辑项目档案
     
            If Not t_repair.Repair.Find(Trim$(InputText.Text)) Then
                 MsgBox "该维修项目不存在,请重输", vbCritical Or vbOKOnly, "错误"
                 Grid.Row = m_EditRow
                 Grid.Col = 1
                 Grid_DblClick
             End If
             Grid.TextMatrix(m_EditRow, 1) = t_repair.Repair.RepairName
        Else
            Dim chechstring As String
            checkstring = Trim$(InputText.Text)
            If m_EditCol = 2 Then
                 If Not IsNumeric(checkstring) Then
                      MsgBox "请输入正确的数字", vbCritical Or vbOKOnly, "错误"
                      Grid.Row = m_EditRow
                      Grid.Col = 2
                      Grid_DblClick
                      Exit Sub
                  End If
                  t_repair.Price = CDbl(checkstring)
                  checkstring = FormatNumber(checkstring)
                  Grid.TextMatrix(m_EditRow, 2) = checkstring
                  RaiseEvent ChangeSum
            Else
                  If m_EditCol = 3 Then
                        t_repair.Memo = checkstring
                        Grid.TextMatrix(m_EditRow, 3) = checkstring
                  End If
            End If
           
         End If
  
  End If
  If m_EditRow <> Grid.Row Then
      If t_repair.Repair.Id < 0 Then
      MsgBox "请输入维修项目", vbCritical Or vbOKOnly, "错误"
      Grid.Col = 1
      m_EditCol = 1
      Grid.Row = m_EditRow
      Exit Sub
      End If
      If t_repair.Price <= 0 Then
      MsgBox "请输入金额", vbCritical Or vbOKOnly, "错误"
      Grid.Col = 2
      m_EditCol = 2
      Grid.Row = m_EditRow
      Exit Sub
      End If
 '     InputText.Text = vbNullString
'      t_repair.Save g_Conn, m_WorkMianId
     
  End If

If t_repair.Repair.Id > 0 And t_repair.Price > 0 And m_IsColChange Then
   t_repair.Save g_Conn, m_WorkMianId
   
End If
'通过检查,如果编辑行改变,并进行保存
FindButton.Visible = False

InputText.Visible = False
m_IsPopup = False
InputText.Text = vbNullString

Grid.TextMatrix(m_EditRow, 0) = vbNullString
m_EditCol = Grid.Col
m_EditRow = Grid.Row
'Grid.TextMatrix(m_EditRow, 0) = "*"

m_IsColChange = False
End Sub

Private Sub InputText_Change()

If m_IsPopup Then
   m_IsColChange = True
   Grid.TextMatrix(m_EditRow, 0) = "*"
End If

End Sub

Private Sub InputText_GotFocus()
m_IsPopup = True
End Sub




Private Sub InputText_KeyPress(KeyAscii As Integer)
'回车后,移动编辑位置
If KeyAscii = 13 Then
Grid.SetFocus
  Select Case m_EditCol
         Case 1
           
           Grid.ColSel = 2
           Grid.Col = 2
           m_EditCol = 2
        Case 2
         
         Grid.ColSel = 3
         Grid.Col = 3
         m_EditCol = 3
        Case 3
   End Select
End If
End Sub

Private Sub UserControl_Initialize()
Set m_DataList = New Collection
m_IsRowChange = False
m_IsColChange = False
m_IsPopup = False
m_EditCol = 0
m_EditRow = 0
m_IsPopup = False
End Sub



Private Sub UserControl_Resize()
Grid.Move 0, 0, UserControl.Width, UserControl.Height
End Sub

Private Sub UserControl_Show()
InputText.Visible = False
FindButton.Visible = False
DrawTable
End Sub
Private Sub DrawTable()
Grid.ColAlignment(1) = 5
Grid.ColAlignment(2) = 5
Grid.ColAlignment(3) = 5

Grid.TextMatrix(0, 1) = "维修项目"
Grid.TextMatrix(0, 2) = "维修工时费"
Grid.TextMatrix(0, 3) = "备注"
Grid.ColWidth(0) = 300
Grid.ColWidth(1) = 3500
Grid.ColWidth(2) = 2000
Grid.ColWidth(3) = 2500
End Sub
Public Sub LoadRepairItem(ByRef pConn As ADODB.Connection, ByVal MainId As Long)
Dim re As ADODB.Recordset
Dim t_RepItem As RepairItem
Dim t_RepData As TRepair
m_WorkMianId = MainId
Set re = pConn.Execute("SELECT * FROM WorkSub_1 WHERE MainId=" & CStr(MainId))
If Not (re.BOF And re.EOF) Then re.MoveFirst
While Not re.EOF
     Set t_RepData = New TRepair
     If t_RepData.FindAsId(re.Fields(2).Value) Then
        Set t_RepItem = New RepairItem
        t_RepItem.Id = re.Fields(0).Value
        Set t_RepItem.Repair = t_RepData
        t_RepItem.Price = re.Fields(3).Value
        t_RepItem.Memo = re.Fields(4).Value
        m_DataList.Add t_RepItem, CStr(t_RepItem.Id)
     End If
     re.MoveNext
Wend
m_EditRow = m_DataList.COUNT
Set rere = Nothing
End Sub
Public Sub ShowData()
Dim i As Integer ', j As Integer
Dim t_RepItem As RepairItem
Grid.Rows = m_DataList.COUNT + 1
For i = 1 To m_DataList.COUNT
Set t_RepItem = m_DataList.Item(i)
Grid.Row = i
Grid.Col = 1
Grid.CellAlignment = vbAlignLeft
Grid.Text = t_RepItem.Repair.RepairName
Grid.Col = 2
Grid.CellAlignment = vbAlignRight
Grid.Text = FormatNumber(t_RepItem.Price)
Grid.Col = 3
Grid.CellAlignment = vbAlignLeft
Grid.Text = t_RepItem.Memo
Next i
End Sub
Private Sub ShowEdit()
If Grid.Col = 0 Then Exit Sub
InputText.Move Grid.CellLeft, Grid.CellTop, Grid.CellWidth, Grid.CellHeight

InputText.Visible = True
If Grid.Col = 1 Then
   FindButton.Move InputText.Left + InputText.Width - FindButton.Width, InputText.Top
   FindButton.Visible = True
Else
   FindButton.Visible = False
End If
End Sub

Private Sub UserControl_Terminate()
Set m_DataList = Nothing
'Set m_EditRep = Nothing
End Sub

Public Property Get Enabled() As Boolean
Enabled = UserControl.Enabled
End Property

Public Property Let Enabled(ByVal vNewValue As Boolean)
UserControl.Enabled = vNewValue
End Property
Public Sub AddRow()
Dim t_repair As RepairItem
Set t_repair = New RepairItem

Grid.Rows = Grid.Rows + 1
Grid.Row = Grid.Rows - 1
Grid_SelChange


Grid.SetFocus

'Grid.RowSel = m_EditRow
m_EditCol = 1
Grid.Col = 1

m_EditRow = Grid.Rows - 1
m_DataList.Add t_repair
'Grid_SelChange
m_IsRowChange = True
End Sub
Public Sub ClearData()
Dim i As Long
For i = m_DataList.COUNT To 1 Step -1
   m_DataList.Remove (i)
Next i
End Sub
Public Property Get RepairSum() As Double
Dim i As RepairItem
Dim sum As Double
sum = 0
For Each i In m_DataList
sum = sum + i.Price
Next i
RepairSum = sum
End Property

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -