📄 inventorygrid.ctl
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.UserControl InventoryGrid
ClientHeight = 3600
ClientLeft = 0
ClientTop = 0
ClientWidth = 5730
HasDC = 0 'False
ScaleHeight = 3600
ScaleWidth = 5730
Begin VB.CommandButton FindButton
Caption = "┉"
Height = 255
Left = 1080
TabIndex = 0
Top = 2640
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 = 1920
Visible = 0 'False
Width = 975
End
Begin MSFlexGridLib.MSFlexGrid Grid
Height = 3135
Left = 0
TabIndex = 2
Top = 0
Width = 4815
_ExtentX = 8493
_ExtentY = 5530
_Version = 393216
Rows = 3
Cols = 6
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 = "InventoryGrid"
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 Inventory " & t_find, _
InputText)
InputText.SetFocus
End Sub
Private Sub Grid_SelChange()
Dim t_Inventory As InventoryItem
If m_EditRow < 1 Then Exit Sub
Set t_Inventory = m_DataList.Item(m_EditRow)
If m_IsColChange Then
If m_EditCol = 1 Then '如果正在编辑项目档案
If Not t_Inventory.Inventor.Find(Trim$(InputText.Text), Find_From_Code) Then
MsgBox "该存货不存在,请重输", vbCritical Or vbOKOnly, "错误"
Grid.Row = m_EditRow
Grid.Col = 1
Grid_DblClick
End If
Grid.TextMatrix(m_EditRow, 1) = t_Inventory.Inventor.InventorName
Grid.TextMatrix(m_EditRow, 2) = t_Inventory.Inventor.Unit
Else
Dim chechstring As String
checkstring = Trim$(InputText.Text)
If m_EditCol = 5 Or m_EditCol = 3 Or m_EditCol = 4 Then
If Not IsNumeric(checkstring) Then
MsgBox "请输入正确的数字", vbCritical Or vbOKOnly, "错误"
Grid.Row = m_EditRow
Grid.Col = 2
Grid_DblClick
Exit Sub
End If
Select Case m_EditCol
Case 3
t_Inventory.Quantity = CDbl(checkstring)
Case 4
t_Inventory.Cost = CDbl(checkstring)
Case 5
t_Inventory.Price = CDbl(checkstring)
End Select
Grid.TextMatrix(m_EditRow, 3) = FormatNumber(t_Inventory.Quantity)
Grid.TextMatrix(m_EditRow, 4) = FormatNumber(t_Inventory.Cost)
Grid.TextMatrix(m_EditRow, 5) = FormatNumber(t_Inventory.Price)
If t_Inventory.Price > 0 Then RaiseEvent ChangeSum
End If
End If
End If
If m_EditRow <> Grid.Row Then
If t_Inventory.Inventor.Id < 0 Then
MsgBox "请输入维修项目", vbCritical Or vbOKOnly, "错误"
Grid.Col = 1
m_EditCol = 1
Grid.Row = m_EditRow
Exit Sub
End If
If t_Inventory.Quantity <= 0 Then
MsgBox "请输入数量", vbCritical Or vbOKOnly, "错误"
Grid.Col = 3
m_EditCol = 3
Grid.Row = m_EditRow
Exit Sub
End If
If t_Inventory.Price <= 0 Then
MsgBox "请输入金额", vbCritical Or vbOKOnly, "错误"
Grid.Col = 3
m_EditCol = 3
Grid.Row = m_EditRow
Exit Sub
End If
' t_Inventory.Save g_Conn, m_WorkMianId
' m_IsRowChange = False
End If
'如果数据完整,保存
If t_Inventory.Inventor.Id > 0 And t_Inventory.Quantity > 0 _
And t_Inventory.Price > 0 And m_IsColChange Then
t_Inventory.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 UserControl_Initialize()
Set m_DataList = New Collection
m_IsRowChange = False
m_IsColChange = False
m_IsPopup = False
m_EditCol = 0
m_EditRow = 0
m_WorkMianId = -1
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.Cols = 6
Grid.ColAlignment(1) = 5
Grid.ColAlignment(2) = 5
Grid.ColAlignment(3) = 5
Grid.ColAlignment(4) = 5
Grid.ColAlignment(5) = 5
Grid.TextMatrix(0, 1) = "存货名称"
Grid.TextMatrix(0, 2) = "单位"
Grid.TextMatrix(0, 3) = "数量"
Grid.TextMatrix(0, 4) = "单价"
Grid.TextMatrix(0, 5) = "金额"
Grid.ColWidth(0) = 300
Grid.ColWidth(1) = 3000
Grid.ColWidth(2) = 600
Grid.ColWidth(3) = 1500
Grid.ColWidth(4) = 1500
Grid.ColWidth(5) = 1500
End Sub
Public Sub LoadRepairItem(ByRef pConn As ADODB.Connection, ByVal MainId As Long)
Dim re As ADODB.Recordset
Dim t_InvItem As InventoryItem
Dim t_InvData As TInventor
m_WorkMianId = MainId
Set re = pConn.Execute("SELECT * FROM WorkSub_2 WHERE MainId=" & CStr(MainId))
If Not (re.BOF And re.EOF) Then re.MoveFirst
While Not re.EOF
Set t_InvData = New TInventor
If t_InvData.FindAsId(re.Fields(2).Value) Then
Set t_InvItem = New InventoryItem
t_InvItem.Id = re.Fields(0).Value
Set t_InvItem.Inventor = t_InvData
t_InvItem.Quantity = re.Fields(3).Value
t_InvItem.Cost = re.Fields(4).Value
' t_InvItem.Price = re.Fields(5).Value
m_DataList.Add t_InvItem, CStr(t_InvItem.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_InvItem As InventoryItem
Grid.Rows = m_DataList.COUNT + 1
For i = 1 To m_DataList.COUNT
Set t_InvItem = m_DataList.Item(i)
Grid.Row = i
Grid.Col = 1
Grid.CellAlignment = vbAlignLeft
Grid.Text = t_InvItem.Inventor.InventorName
Grid.Col = 2
Grid.CellAlignment = vbAlignRight
Grid.Text = t_InvItem.Inventor.Unit
Grid.Col = 3
Grid.CellAlignment = vbAlignLeft
Grid.Text = FormatNumber(t_InvItem.Quantity)
Grid.Col = 4
Grid.CellAlignment = vbAlignLeft
Grid.Text = FormatNumber(t_InvItem.Cost)
Grid.Col = 5
Grid.CellAlignment = vbAlignLeft
Grid.Text = FormatNumber(t_InvItem.Price)
Next i
End Sub
Private Sub ShowEdit()
If Grid.Col = 0 Or Grid.Col = 2 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_Invair As InventoryItem
Set t_Invair = New InventoryItem
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_Invair
'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
Private Sub InputText_GotFocus()
m_IsPopup = True
End Sub
Private Sub Grid_DblClick()
If Grid.Col = 2 Then Exit Sub
If Grid.Row > 0 And Grid.Col <> 0 Then
ShowEdit
InputText.Text = Grid.Text
InputText.SetFocus
InputText.SelStart = Len(InputText)
End If
End Sub
Private Sub InputText_Change()
If m_IsPopup Then
m_IsColChange = True
Grid.TextMatrix(m_EditRow, 0) = "*"
End If
End Sub
Private Sub Grid_KeyPress(KeyAscii As Integer)
Dim t_char As String
'MsgBox KeyAscii
ShowEdit
If Grid.Col = 3 Or Grid.Col = 4 Or Grid.Col = 5 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) _
And (KeyAscii < 48 Or KeyAscii > 57) Then Exit Sub
t_char = Chr$(KeyAscii) & vbNullString
End If
InputText.Text = t_char
InputText.SetFocus
InputText.SelStart = 2
End Sub
Public Property Let WorkMianId(ByVal vData As Long)
m_WorkMianId = vData
End Property
Public Property Get InventorySum() As Double
Dim i As InventoryItem
Dim sum As Double
sum = 0
For Each i In m_DataList
sum = sum + i.Price
Next i
InventorySum = sum
End Property
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -