1、1)登陆窗体代码设计窗体代码主要实现了连接数据库的功能,这里用于连接用户信息表。其程序如下:Private Sub Form_Load()Dim i As IntegerIf App.PrevInstance ThenMsgBox (“程序已经运行,不能再次装载。“), vbExclamationUnload MeEnd If本段代码用于判定本程序是否已经装载于内存中,以避免程序的多重启动i = 0Open App.Path + “user.ini“ For Input As #1Do While Not EOF(1)Input #1, user(i), pws(i), state(i), E
2、mplo(i)If state(i) = “A“ ThenCombo1.AddItem user(i)End Ifi = i + 1Loop Close #1Combo1.ListIndex = 1在窗口装载阶段读取用户设置文件获取用户信息 并装载于用户列表框中End Sub(2) “取消”按钮是退出登录界面,退出系统的。其代码如下:Private Sub CmdCancel_Click()Unload MeEndEnd Sub(3) “确定”按钮代码设计“确定”按钮代码主要实现了用户登陆时,用户名和密码的认证,当用户名或密码错误时,系统提示错误。其程序如下:Private Sub cmdOK
3、_Click()If txtPassword = pws(Combo1.ListIndex) ThenCurId = Combo1.ListIndexEmploID = Emplo(CurId)CurUser = user(CurId)CurPsw = pws(CurId)Me.HideLoad FrmMainFrmMain.ShowElse MsgBox “Invalid Password, try again!“, , “Login“txtPassword.SetFocusSendKeys “Home+End“End If End Sub(1)窗体选择的单击事件代码设计窗体选择的单击事件代
4、码主要实现了进入本系统所有模块的功能,这里有以下几个模块,它们分别是员工信息模块,假条信息模块,工资管理模块,用户设置模块等/其程序如下:Private Sub Toolbar2_ButtonClick(ByVal Button As MSComctlLib.Button)Select Case Button.IndexCase 1Call showemployee 显示员工信息模块Case 2Call showleave 显示假条信息模块Case 3Call showsalary 显示工资信息模块 Case 4If frmLogin.CurUser = “root“ ThenFrmSys.S
5、howElseFrmPsw.ShowPwin = “Frmmain“FrmMain.Enabled = FalseEnd IfEnd SelectEnd Sub(2)命令按钮的单击事件代码设计命令按钮的代码主要实现了进入本系统部分主要模块的功能,这里有以下几个功能,它们分别是编辑,删除,查询,设置。其程序如下:Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)Select Case Button.IndexCase 1 editFrmEdit.ShowFrmMain.Enabled = FalseCase 2
6、 delIf DBGA.SelBookmarks.Count = 1 ThenIf MsgBox(“确定要删除吗? “, vbOKCancel, “确定“) = vbOK Then DataA.Recordset.Delete cuAp = 0Else MsgBox “请选择要删除的条目!“End IfCase 3 seekFrmSearch.ShowCase 4 setupFrmSetup.ShowEnd SelectEnd Sub(3)口令修改的主要代码设计“确定”按钮的代码主要实现了用户密码的修改功能,当旧密码错误或两次新密码输入不一致时,系统会提示错误。其程序如下:Private Su
7、b cmdOK_Click()Dim fil, i, Usercount As IntegerIf TxtNew1.Text frmLogin.CurPsw ThenMsgBox “old password wrong“Txtold.SetFocusTxtNew1.Text = “TxtNew2.Text = “SendKeys “Home+End“Exit SubElse fil = FreeFile()Open App.Path + “user.ini“ For Input As #fili = 0Do While Not EOF(fil)Input #fil, user(i), pws(
8、i)Input #fil, state(i), Emplo(i)i = i + 1LoopUsercount = iClose #filpws(frmLogin.CurId) = TxtNew1.TextfrmLogin.CurPsw = TxtNew1.Textfil = FreeFile()Open App.Path + “user.ini“ For Output As #filFor i = 0 To Usercount - 1Print #fil, user(i); “,“; pws(i); “,“; state(i); “,“; Emplo(i)Next iClose #filTxtold.Text = “TxtNew1.Text = “TxtNew2.Text = “Me.HideIf FrmMain.Pwin = “Frmmain“ ThenFrmMain.Enabled = TrueFrmMain.SetFocusElse Call FrmSys.ActiveAllFrmSys.SetFocus End If End If End Sub