📄 frmresoure.frm
字号:
b.MouseTracking = ddTSBevel
b.GrabHandleStyle = ddGSNormal
Set t = Abar.Tools.Add(GetUniqueToolID(), "m_add")
With t
.Caption = "增加"
.SetPicture ddITNormal, LoadResPicture(101, vbResBitmap)
.ControlType = ddTTButton
keys(0) = "Control+A"
.ShortCuts = keys
.ToolTipText = "增加原料"
.CaptionPosition = ddCPBelow
.Style = ddSIconText
End With
Set t = Abar.Tools.Add(GetUniqueToolID(), "m_modify")
With t
.Caption = "修改"
.SetPicture ddITNormal, LoadResPicture(200, vbResBitmap)
.ControlType = ddTTButton
keys(0) = "Control+E"
.ShortCuts = keys
.ToolTipText = "修改原料信息"
.CaptionPosition = ddCPBelow
.Style = ddSIconText
End With
Set t = Abar.Tools.Add(GetUniqueToolID(), "m_del")
With t
.Caption = "删除"
.SetPicture ddITNormal, LoadResPicture(102, vbResBitmap)
.ControlType = ddTTButton
keys(0) = "Control+D"
.ShortCuts = keys
.ToolTipText = "删除原料"
.CaptionPosition = ddCPBelow
.Style = ddSIconText
End With
Set t = Abar.Tools.Add(GetUniqueToolID(), "m_print")
With t
.Caption = "打印"
.SetPicture ddITNormal, LoadResPicture(106, vbResBitmap)
.ControlType = ddTTButton
keys(0) = "Control+Q"
.ShortCuts = keys
.ToolTipText = "打印"
.CaptionPosition = ddCPBelow
.Style = ddSIconText
End With
Set t = Abar.Tools.Add(GetUniqueToolID(), "m_exit")
With t
.Caption = "关闭": Tool.Category = "m_sys"
.SetPicture ddITNormal, LoadResPicture(103, vbResBitmap)
.ControlType = ddTTButton
keys(0) = "Control+C"
.ShortCuts = keys
.ToolTipText = "关闭本窗口"
.CaptionPosition = ddCPBelow
.Style = ddSIconText
End With
With b.Tools
.Insert .Count, Abar.Tools("m_add")
.Insert .Count, Abar.Tools("m_del")
.Insert .Count, Abar.Tools("m_modify")
.Insert .Count, Abar.Tools("Separator")
.Insert .Count, Abar.Tools("m_print")
.Insert .Count, Abar.Tools("Separator")
.Insert .Count, Abar.Tools("m_exit")
End With
Abar.RecalcLayout
Abar.Refresh
Set dbs = OpenDatabase(ConData, False, False, Constr)
Set rst = dbs.OpenRecordset("Select 名称,损耗率,单位,每份数量 From resource", dbOpenDynaset)
Set siteData.Recordset = rst
fpsp.OperationMode = OperationModeRow
fpsp.SelBackColor = &HFFC0C0
InitGrid
Debug.Print Me.Width
End Sub
Private Sub InitGrid()
With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
Tname.Text = !名称
Tnum(0).Text = !损耗率
Tnum(1).Text = !单位
Tnum(2).Text = !每份数量
End If
End With
With fpsp
.UnitType = UnitTypeTwips
.RowHeight(0) = 500
.MaxRows = rst.RecordCount
.MaxCols = rst.Fields.Count
.Row = 0
.Row2 = .MaxRows
.Col = 1
.Col2 = .MaxCols
.BlockMode = True
.Protect = True
.FontName = "宋体"
.FontSize = "9.25"
.Lock = True
.BlockMode = False
.Row = 0
.Row2 = 0
.Col = 1
.Col2 = .MaxCols
.Clip = "原料名称" & Chr(9) & "损耗率" & Chr(9) & "单位" & Chr(9) & "每份数量"
.ColWidth(1) = 1200
.ColWidth(2) = 1000
.ColWidth(3) = 1000
.ColWidth(4) = 1000
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
SaveFormSet Me
End Sub
Private Sub ccancle_Click()
Fredit.Enabled = False
fpsp.Enabled = True
With fpsp
.Row = .ActiveRow
.Col = 1
Tnum(0).Text = .Text
.Col = 2
Tnum(1).Text = .Text
.Col = 3
Tnum(2).Text = .Text
End With
Abar.Tools("m_add").Enabled = True
Abar.Tools("m_modify").Enabled = True
Abar.Tools("m_del").Enabled = True
Abar.Tools("m_print").Enabled = True
End Sub
Private Sub cok_Click()
'On Error GoTo er
If CheckOK() Then
If CurrOp = "add" Then
sqlstr = "Insert into resource (名称,损耗率,单位,每份数量) values('" & Trim(Tname.Text) & "'," & Trim(Tnum(0).Text) & ",'" & Trim(Tnum(1).Text) & "'," & Tnum(2).Text & ")"
dbs.Execute sqlstr
Else
fpsp.Row = fpsp.ActiveRow
fpsp.Col = 1
t = fpsp.Text
dbs.Execute "update resource set 名称 ='" & Tname.Text & "'" & _
",损耗率=" & Trs.Text & _
",单位='" & Trs.Text & _
"',每份数量=" & Tsp.Text & " where 名称 = '" & t & "';"
End If
rst.Requery
InitGrid
Fredit.Enabled = False
fpsp.Enabled = True
Abar.Tools("m_add").Enabled = True
Abar.Tools("m_modify").Enabled = True
Abar.Tools("m_del").Enabled = True
Abar.Tools("m_print").Enabled = True
End If
Exit Sub
er:
ErrorHandle ""
Fredit.Enabled = False
fpsp.Enabled = True
Abar.Tools("m_add").Enabled = True
Abar.Tools("m_modify").Enabled = True
Abar.Tools("m_del").Enabled = True
Abar.Tools("m_print").Enabled = True
End Sub
Private Sub fpsp_LeaveRow(ByVal Row As Long, ByVal RowWasLast As Boolean, ByVal RowChanged As Boolean, ByVal AllCellsHaveData As Boolean, ByVal NewRow As Long, ByVal NewRowIsLast As Long, Cancel As Boolean)
With fpsp
.Row = NewRow
.Col = 1
Tname.Text = .Text
.Col = 2
Trs.Text = .Text
.Col = 3
Tsp.Text = .Value
End With
End Sub
Private Sub Pic_Resize()
'On Error Resume Next
fpsp.Left = 0
fpsp.Top = 0
fpsp.Height = Pic.Height - 50
Fredit.Height = fpsp.Height - Fredit.Top
Fredit.Left = Pic.Width - Fredit.Width - 100
fpsp.Width = Fredit.Left - 50
cok.Top = Fredit.Top + Fredit.Height - 350 - cok.Height
ccancle.Top = cok.Top
End Sub
Private Function CheckOK() As Boolean
CheckOK = False
If Len(Tname.Text) > 0 Then
If Not IsNumeric(Tnum(0).Text) Then
MsgBox Tnum(0).Text & "不是有效的损耗率,‘损耗率’必须为数字!", vbCritical, "提示"
Tnum(0).SetFocus
Exit Function
End If
If Len(Tnum(1).Text) = 0 Then
MsgBox Tnum(0).Text & "原料名称不能为空!", vbCritical, "提示"
Tnum(1).SetFocus
Exit Function
End If
If Not IsNumeric(Tnum(2).Text) Then
MsgBox Tnum(2).Text & "不是有效的数量,‘数量’必须为数字!", vbCritical, "提示"
Tnum(2).SetFocus
Exit Function
End If
Else
MsgBox Tname.Text & "原料名称不能为空!", vbCritical, "提示"
Tname.SetFocus
Exit Function
End If
CheckOK = True
End Function
Private Sub Tname_GotFocus()
SendKeys "{Home}+{End}"
End Sub
Private Sub Tnum_GotFocus(Index As Integer)
SendKeys "{Home}+{End}"
End Sub
Private Sub Tnum_Validate(Index As Integer, Cancel As Boolean)
If Index = 0 Then
If Not IsNumeric(Tnum(0).Text) Then
MsgBox Tnum(0).Text & "不是有效的损耗率,‘损耗率’必须为数字!", vbCritical, "提示"
End If
End If
If Index = 2 Then
If Not IsNumeric(Tnum(2).Text) Then
MsgBox Tnum(2).Text & "不是有效的数量,‘数量’必须为数字!", vbCritical, "提示"
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -