📄 frm_khxxwh_ywwl.frm
字号:
Left = 0
TabIndex = 0
Top = 0
Width = 6135
_ExtentX = 10821
_ExtentY = 1244
ButtonWidth = 1138
ButtonHeight = 1191
Appearance = 1
Style = 1
ImageList = "ImageList1"
_Version = 393216
BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628}
NumButtons = 9
BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = " 增加 "
Key = "add"
ImageIndex = 1
EndProperty
BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = "修改"
Key = "modify"
ImageIndex = 2
EndProperty
BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = "删除"
Key = "delete"
ImageIndex = 3
EndProperty
BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = "保存"
Key = "save"
ImageIndex = 4
EndProperty
BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = "取消"
Key = "cancel"
ImageIndex = 5
EndProperty
BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = "查找"
Key = "find"
ImageIndex = 6
EndProperty
BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628}
Enabled = 0 'False
EndProperty
BeginProperty Button8 {66833FEA-8583-11D1-B16A-00C0F0283628}
Enabled = 0 'False
Style = 3
EndProperty
BeginProperty Button9 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = "关闭"
Key = "close"
ImageIndex = 7
EndProperty
EndProperty
BorderStyle = 1
End
End
Attribute VB_Name = "Frm_Khxxwh_Ywwl"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rs1 As New ADODB.Recordset
Public blnAdd As Boolean
Dim mybookmark
Dim Mystr As String '定义字符串变量
Dim Myrs As New ADODB.Recordset
Sub view_data() '显示数据信息
Dim i As Integer
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To 4
Txt1(i).Text = Dgr_Ywwl.Columns(i)
Next i
Cbx_Khbh.Text = Dgr_Ywwl.Columns(5)
Dtp_Xsrq.Value = Dgr_Ywwl.Columns(6)
Txt1(5).Text = Dgr_Ywwl.Columns(7)
End If
End Sub
Private Sub Cbx_Khbh_GotFocus()
Cbx_Khbh.BackColor = &HFFFF80
End Sub
Private Sub Cbx_Khbh_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Dtp_Xsrq.SetFocus
End Sub
Private Sub Cbx_Khbh_LostFocus()
Cbx_Khbh.BackColor = &HFFFFFF
Myrs.Open "select * from tb_khxx where khxx_mc='" + Cbx_Khbh.Text + "'", cnn, adOpenKeyset
If Myrs.RecordCount <= 0 Then
MsgBox "该企业不是本公司的客户!", , "信息提示"
Cbx_Khbh.ListIndex = 0
Cbx_Khbh.SetFocus
Myrs.Close
Exit Sub
End If
Myrs.Close
End Sub
Private Sub Dgr_Ywwl_Click()
view_data
End Sub
Private Sub Dtp_Xsrq_GotFocus()
Dtp_Xsrq.CalendarBackColor = &HFFFF80
End Sub
Private Sub Dtp_Xsrq_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Txt1(5).SetFocus
End Sub
Private Sub Dtp_Xsrq_LostFocus()
Dtp_Xsrq.CalendarBackColor = &HFFFFFF
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = PublicStr
Call Dgr_Title '调用过程
Dim rs2 As New ADODB.Recordset
rs2.Open "select * from tb_khxx ", cnn, adOpenKeyset
If rs2.RecordCount > 0 Then
For i = 0 To rs2.RecordCount - 1
Cbx_Khbh.AddItem Trim(rs2.Fields("khxx_mc"))
rs2.MoveNext
Next i
Cbx_Khbh.ListIndex = 0
End If
tlbState Toolbar1, False
Call view_data '调用过程
'设置控件状态
For i = 0 To Txt1.UBound
Txt1(i).Enabled = False
Next i
Cbx_Khbh.Enabled = False
Dtp_Xsrq.Enabled = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
sql = ""
End Sub
Sub Dgr_Title() '设置DataGrid控件的标题信息
Dgr_Ywwl.Columns(0).Caption = "产品销售编号"
Dgr_Ywwl.Columns(1).Caption = "产品名称"
Dgr_Ywwl.Columns(2).Caption = "产品单价"
Dgr_Ywwl.Columns(3).Caption = "销售数量"
Dgr_Ywwl.Columns(4).Caption = "业务量"
Dgr_Ywwl.Columns(5).Caption = "客户名称"
Dgr_Ywwl.Columns(6).Caption = "产品销售日期"
Dgr_Ywwl.Columns(7).Caption = "备注信息"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Frm_Main.Enabled = True
End Sub
Private Sub Txt1_Change(Index As Integer)
If Index = 3 Then
If IsNumeric(Txt1(2).Text) And IsNumeric(Txt1(3).Text) Then
Txt1(4).Text = Val(Txt1(2).Text) * Val(Txt1(3).Text)
End If
End If
End Sub
Private Sub Txt1_GotFocus(Index As Integer)
'Txt1控件数组获得焦点
Txt1(Index).BackColor = &HFFFF80
Txt1(Index).SelStart = 0
Txt1(Index).SelLength = Len(Txt1(Index))
End Sub
Private Sub Txt1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
'Txt1控件数据按回车键
If KeyCode = vbKeyReturn And Index < 5 Then
If Index = 4 Then
Cbx_Khbh.SetFocus
Exit Sub
End If
If Index = 5 Then Exit Sub
Txt1(Index + 1).SetFocus
End If
End Sub
Private Sub Txt1_LostFocus(Index As Integer)
'Txt1控件数据失去焦点
Txt1(Index).BackColor = &HFFFFFF
If Index = 3 Then
If Not IsNumeric(Txt1(2).Text) Or Not IsNumeric(Txt1(3).Text) Then
MsgBox "请输入正确的产品单价或销售数量信息", , "信息提示"
Exit Sub
Else
Txt1(4).Text = Val(Txt1(2).Text) * Val(Txt1(3).Text)
End If
End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Call Dgr_Title
Select Case Button.key
Case "add" '添加
blnAdd = True
tlbState Toolbar1, True
rs1.Open "select * from tb_Client_cpxs order by cpxs_id", cnn, adOpenStatic
If rs1.RecordCount > 0 Then
rs1.MoveLast
Txt1(0) = "XS" + Format(Val(Right(Trim(rs1.Fields("cpxs_id")), 3)) + 1, "###000") '编号自动加1
Else
Txt1(0) = "XS001"
End If
rs1.Close
For i = 1 To Txt1.UBound
Txt1(i) = ""
Txt1(i).Locked = False
Next i
Txt1(4).Locked = True
For i = 1 To Txt1.UBound
Txt1(i).Enabled = True
Next i
Cbx_Khbh.Enabled = True
Cbx_Khbh.Text = ""
Dtp_Xsrq.Enabled = True
Dtp_Xsrq.Value = Date
Txt1(1).SetFocus
Case "modify" '修改
If Adodc1.Recordset.RecordCount > 0 Then
blnAdd = False
tlbState Toolbar1, True
For i = 1 To Txt1.UBound
Txt1(i).Locked = False
Next i
view_data
mybookmark = Dgr_Ywwl.Bookmark
For i = 1 To Txt1.UBound
Txt1(i).Enabled = True
Next i
Cbx_Khbh.Enabled = True
Dtp_Xsrq.Enabled = True
Txt1(4).Locked = True
Else
MsgBox "系统没有要修改的数据!", , "提示窗口"
End If
Case "delete" '删除
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Adodc1.Refresh
For i = 0 To Txt1.UBound
Txt1(i).Text = ""
Next i
Call view_data
Call Dgr_Title
Else
MsgBox "系统没有要删除的数据!", , "提示窗口"
End If
Case "save" '保存
On Error GoTo SaveErr
If Txt1(0).Text = "" Then
MsgBox "系统不允许" & Label1 & "为空!", , "提示窗口"
Exit Sub
End If
If Not IsNumeric(Txt1(2).Text) Then
MsgBox "请输入正确的产品单价信息", , "提示窗口"
Exit Sub
End If
If Not IsNumeric(Txt1(3).Text) Then
MsgBox "请输入正确的销售数量信息", , "提示窗口"
Exit Sub
End If
If blnAdd = True Then '添加新记录
cnn.Execute ("insert into tb_Client_cpxs(cpxs_id,cpxs_mc,cpxs_cpdj,cpxs_xssl,cpxs_ywl,cpxs_khmc,cpxs_xsrq,cpxs_bz) values('" + Txt1(0) + _
"','" + Txt1(1) + "','" + Txt1(2) + "','" + Txt1(3) + "','" + Txt1(4) + "','" + Cbx_Khbh.Text + "','" + Str(Dtp_Xsrq.Value) + "','" + Txt1(5) + "' )")
Adodc1.Refresh
Call Dgr_Title
tlbState Toolbar1, False
For i = 1 To Txt1.UBound
Txt1(i).Locked = True
Next i
Else '修改原有记录
cnn.Execute ("update tb_Client_cpxs set cpxs_mc ='" + Txt1(1) + "',cpxs_cpdj ='" + Txt1(2) + "',cpxs_xssl='" + Txt1(3) + "',cpxs_ywl='" + Txt1(4) + "',cpxs_khmc='" + Cbx_Khbh.Text + "',cpxs_xsrq='" + Str(Dtp_Xsrq.Value) + "', cpxs_bz='" + Txt1(5).Text + "' where cpxs_id='" + Txt1(0).Text + "'")
Adodc1.Refresh
' Dgr_Ywwl.Bookmark = mybookmark
tlbState Toolbar1, False
Call Dgr_Title
For i = 1 To Txt1.UBound
Txt1(i).Locked = True
Next i
End If
Exit Sub
SaveErr: '出错处理
MsgBox Err.Description, , "信息提示"
Case "cancel" ' 取消
tlbState Toolbar1, False
For i = 1 To Txt1.UBound
Txt1(i).Locked = True
Next i
Call view_data
Case "find" ' 查询
Mystr = InputBox("请输入要查询的产品销售编号", "业务往来查询", "XS001")
rs1.Open "select * from tb_Client_cpxs where cpxs_id ='" + Mystr + "'", cnn, adOpenKeyset
If rs1.RecordCount > 0 Then
For i = 0 To 4
If rs1.Fields(i) <> "" Then
Txt1(i).Text = rs1.Fields(i)
Else
Txt1(i).Text = ""
End If
Next i
Cbx_Khbh.Text = rs1.Fields(5)
Dtp_Xsrq.Value = rs1.Fields(6)
Txt1(5).Text = rs1.Fields(7)
End If
rs1.Close
Case "close" '关闭
Unload Me
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -