1、VB 进销存管理信息系统(1)添加 Module 模块,编写 Main 过程:声明全局对象变量 ADOcn,用于创建与数据库的连接Public ADOcn As Connection声明全局变量 strQuery1 用于存储查询条件Pubic strQuery1 As StringPublic Sub Main()定义数据库连接字符串Dim strSQLServer As String用于连接 SQL Server 数据库,其中 :Server 为服务器名称User ID 为登录账号, Password 为登录口令Database 为具体的数据库名请根据具体的实验环境修改这些参数strSQLS
2、erver = “Provider=SQLOLEDB;Server=bigdog;Us_er ID=sa;Password=sa;Database=进销存“连接 SQL Server 数据库ADOcn.Open strSQLServer显示主窗体frmMain.ShowEnd Sub将 Main 过程设为工程启动对象。(2)FrmMain 窗体主要代码。该窗体的代码主要用于调度其他各窗体,起串接作用。Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.But_ton)Select Case ButtonCase “物资台账管
3、理 “frm 台账.Show 1Case “物资入库管理 “frm 入库.Show 1Case “物资出库管理 “frm 出库.Show 1Case “退出系统 “Unload Me 或者使用 End 命令End SelectEnd Sub(3)“frm 台账 ”窗体代码。“通用”部分声明一个 Sub 过程,用于在 MSFlexGrid 中显示记录。Private Sub DisplayGrid()声明变量Dim strGrid As StringDim i As IntegerDim ADOrs As New RecordsetADOrs.ActiveConnection = ADOcn打开
4、物资台账If strQuery1 “ ThenADOrs.Open “Select * From 物资台账 Where “ + strQuery1 +“Order By 物资编码“ElseADOrs.Open “Select * From 物资台账 Order By 物资编码“End If设置报表窗体的 DataSource 和 DataMember 属性Set frmReport 台账.DataSource = ADOrs.DataSourceFrmReport 台账.DataMember = ADOrs.DataMemberFrmReport 台账.Show 1End SubPrivate
5、 Sub Command6_Click()退出本窗体Unload MeEnd Sub(4)“frmAdd 台账”窗体代码。Private Sub Command1_Click()Dim strSQL As StringDim ADOrs As New RecordsetSet ADOrs.ActiveConnection = ADOcn首先查询主关键字“物资编码”是否重复ADOrs.Open “Select 物资编码 From 物资台账 Where 物资编码=“ + Text1(0) + “If Not ADOrs.EOF ThenMsgBox “物资编码已存在,请重新输入“, vbQuest
6、ion + vbOKOnly, “信息提示“Exit Sub 退出本过程End If增加一条新记录strSQL = “Insert Into 物资台账(物资编码,物资名称,计量单位,单价,期初库存) “strSQL = strSQL + “ Values(“ + Text1(0) + “,“ + Text1(1) + “,“ + Combo1.Text + “,“strSQL = strSQL + Text1(2) + “,“ + Text1(3) + “)“ADOcn.Execute strSQLMsgBox “增加成功,请继续!“, vbQuestion + vbOKOnly, “信息提示
7、“End SubPrivate Sub Command2_Click()退出本窗体Unload MeEnd SubPrivate Sub Form_Load()赋初值Text1(0) = “Text1(1) = “Text1(2) = “0“Text1(3) = “0“Combo1.ListIndex = 0End SubPrivate Sub Text1_Change(Index As Integer)当 “单价”和“期初库存”值发生变化时,自动计算“期初金额 ”If Index = 2 Or Index = 3 ThenText1(4) = Trim(Str(Val(Text1(2) *
8、Val(Text1(3)End IfEnd SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)将用户输入的回车键转换为 Tab 键,使焦点自动下移If KeyAscii = 13 ThenSendKeys “Tab“End If对于“单价”和“期初库存”文本框只允许输入数字、小数点和退格键If Index = 2 Or Index = 3 ThenIf Not (Chr(KeyAscii) = “0“ And Chr(KeyAscii) “ Thenstr1 = “物资编码“ + Combo1.Text + “ + Text1(0) + “End IfIf Text1(1) “ ThenstrQuery1 = str2ElseIf str1 =“Combo1.AddItem “Combo1.AddItem “Combo2.ClearCombo2.AddItem “=“Combo2.AddItem “=“Combo2.AddItem “Combo2.AddItem “Text1(0).Text = “Text1(1).Text = “End Sub