home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VB / OLEMSG / TIMECARD.CLI / SERVER / MAINSVR.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-06-15  |  16.2 KB  |  554 lines

  1. VERSION 5.00
  2. Begin VB.Form formmainsvr 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Time Card Server"
  6.    ClientHeight    =   6795
  7.    ClientLeft      =   1410
  8.    ClientTop       =   1515
  9.    ClientWidth     =   8880
  10.    Height          =   7200
  11.    Left            =   1350
  12.    LinkTopic       =   "Form2"
  13.    ScaleHeight     =   6795
  14.    ScaleWidth      =   8880
  15.    Top             =   1170
  16.    Width           =   9000
  17.    Begin VB.ListBox lstUsers 
  18.       Height          =   4575
  19.       Left            =   480
  20.       TabIndex        =   7
  21.       Top             =   720
  22.       Width           =   3372
  23.    End
  24.    Begin VB.CommandButton btnAddUsr 
  25.       Caption         =   "&Add"
  26.       Height          =   372
  27.       Left            =   480
  28.       TabIndex        =   6
  29.       Top             =   5880
  30.       Width           =   1212
  31.    End
  32.    Begin VB.CommandButton btnRemoveAllUsers 
  33.       Caption         =   "&Remove All"
  34.       Height          =   372
  35.       Left            =   2640
  36.       TabIndex        =   5
  37.       Top             =   5880
  38.       Width           =   1212
  39.    End
  40.    Begin VB.TextBox txtCat 
  41.       Height          =   372
  42.       Left            =   4920
  43.       TabIndex        =   3
  44.       Top             =   720
  45.       Width           =   3372
  46.    End
  47.    Begin VB.ListBox lstCat 
  48.       Height          =   3795
  49.       ItemData        =   "mainsvr.frx":0000
  50.       Left            =   4920
  51.       List            =   "mainsvr.frx":0007
  52.       TabIndex        =   2
  53.       Top             =   1500
  54.       Width           =   3372
  55.    End
  56.    Begin VB.CommandButton btnAddCat 
  57.       Caption         =   "A&dd"
  58.       Default         =   -1  'True
  59.       Enabled         =   0   'False
  60.       Height          =   372
  61.       Left            =   4920
  62.       TabIndex        =   1
  63.       Top             =   5880
  64.       Width           =   1212
  65.    End
  66.    Begin VB.CommandButton btnRemoveCat 
  67.       Caption         =   "Remo&ve"
  68.       Enabled         =   0   'False
  69.       Height          =   372
  70.       Left            =   7080
  71.       TabIndex        =   0
  72.       Top             =   5880
  73.       Width           =   1212
  74.    End
  75.    Begin VB.Label Label1 
  76.       Caption         =   "User List"
  77.       Height          =   252
  78.       Left            =   480
  79.       TabIndex        =   8
  80.       Top             =   240
  81.       Width           =   1572
  82.    End
  83.    Begin VB.Label lblName 
  84.       Caption         =   "Category to add"
  85.       Height          =   252
  86.       Left            =   4800
  87.       TabIndex        =   4
  88.       Top             =   240
  89.       Width           =   1572
  90.    End
  91.    Begin VB.Line Line1 
  92.       X1              =   4440
  93.       X2              =   4440
  94.       Y1              =   0
  95.       Y2              =   6840
  96.    End
  97.    Begin VB.Menu mnuFile 
  98.       Caption         =   "&File"
  99.       Begin VB.Menu mnuSave 
  100.          Caption         =   "&Save"
  101.       End
  102.       Begin VB.Menu mnus 
  103.          Caption         =   "-"
  104.          Index           =   1
  105.       End
  106.       Begin VB.Menu mnuExit 
  107.          Caption         =   "E&xit"
  108.       End
  109.    End
  110.    Begin VB.Menu mnuReport 
  111.       Caption         =   "&Report"
  112.       Begin VB.Menu mnuSend 
  113.          Caption         =   "&Send Requests"
  114.       End
  115.       Begin VB.Menu mnuGenerate 
  116.          Caption         =   "&Generate Report"
  117.       End
  118.       Begin VB.Menu mnuse 
  119.          Caption         =   "-"
  120.       End
  121.       Begin VB.Menu mnuCleanUp 
  122.          Caption         =   "&Clean Up Receiving Folder"
  123.       End
  124.    End
  125.    Begin VB.Menu mnuHelp 
  126.       Caption         =   "&Help"
  127.       Begin VB.Menu mnuAbout 
  128.          Caption         =   "&About"
  129.       End
  130.    End
  131. Attribute VB_Name = "formmainsvr"
  132. Attribute VB_Base = "0{CFF16A11-C697-11CF-A520-00A0D1003923}"
  133. Attribute VB_GlobalNameSpace = False
  134. Attribute VB_Creatable = False
  135. Attribute VB_TemplateDerived = False
  136. Attribute VB_PredeclaredId = True
  137. Attribute VB_Exposed = False
  138. Attribute VB_Customizable = False
  139. Option Explicit
  140. Sub GetCategoryList()
  141. ReDim CategoryList.aCats(lstCat.ListCount) As String
  142. Dim ind As Integer
  143. CategoryList.cCats = lstCat.ListCount
  144. ind = 0
  145. Do While ind < CategoryList.cCats
  146.     CategoryList.aCats(ind) = lstCat.List(ind)
  147.     ind = ind + 1
  148. End Sub
  149. Public Sub SendRequest(cCats As Integer, Cats() As String, PayPrd As Date, Reminder As Boolean)
  150. 'sends request message
  151. On Error GoTo error_olemsg
  152. Dim objmessage As Object
  153. Dim prop As Object
  154. Dim objRecip As Object
  155. Dim objRecipCol As Object
  156. Dim objFieldCol As Object
  157. Dim objAttachmentCol As Object
  158. Dim objAtt As Object
  159. Dim ind As Integer
  160. Dim msgBody As String
  161. If UserList.cUsers = 0 Then
  162.     MsgBox "User List is empty"
  163.     Exit Sub
  164. End If
  165. If cCats = 0 Then
  166.     MsgBox "Category list is empty"
  167.     Exit Sub
  168. End If
  169. If Not Reminder Then
  170.     If Not frmCalender.GetDate(PayPrd) Then
  171.         Exit Sub
  172.     End If
  173. End If
  174. If objSession Is Nothing Then
  175.     MsgBox "Not logged on"
  176.     Exit Sub
  177. End If
  178. 'create new message in the outbox
  179. Set objmessage = objSession.Outbox.Messages.Add
  180. If objmessage Is Nothing Then
  181.     MsgBox "Can't add a prop"
  182.     Exit Sub
  183. End If
  184. If Not Reminder Then
  185.     objmessage.Subject = "Time to fill out your time report"
  186.     msgBody = ""
  187.     objmessage.Subject = "SECOND NOTICE: Time to fill out your time report"
  188.     msgBody = "Your time report has not been received. "
  189. End If
  190. msgBody = msgBody & "Please run the attached application (double click on the attachment) and fill out the form"
  191. 'set the body of the message
  192. objmessage.Text = msgBody
  193. 'set the message class
  194. objmessage.Type = RequestMsgType
  195. 'open recipients collection
  196. Set objRecipCol = objmessage.Recipients
  197. If objRecipCol Is Nothing Then
  198.     MsgBox "Can't open msg's recipients"
  199.     Exit Sub
  200. End If
  201. 'add recipients
  202. For ind = 0 To UserList.cUsers - 1
  203.     If Not Reminder Then 'send to everybody
  204.         Set objRecip = objRecipCol.Add(EntryID:=UserList.aUsers(ind).EntryID, _
  205.                     Name:=UserList.aUsers(ind).DisplayName)
  206.                     
  207.     Else 'if this is a reminder, send only to the people we don't have reports from
  208.         If UserList.aUsers(ind).ReportIndex = E_NOT_FOUND Then
  209.             Set objRecip = objRecipCol.Add(EntryID:=UserList.aUsers(ind).EntryID, _
  210.                     Name:=UserList.aUsers(ind).DisplayName)
  211.         Else
  212.             GoTo continue
  213.         End If
  214.         
  215.     End If
  216.     If objRecip Is Nothing Then
  217.         MsgBox "Can't add recipient"
  218.         Exit Sub
  219.     End If
  220. continue:
  221. Next ind
  222. 'open msg's field collection
  223. Set objFieldCol = objmessage.Fields
  224. If objFieldCol Is Nothing Then
  225.     MsgBox "Can't open msg's fields collection"
  226.     Exit Sub
  227. End If
  228. 'set the report categories
  229. 'we can't write:
  230. 'Set prop = objFieldCol.Add(Name:=CatPropName, _
  231.             Class:=vbString + vbArray, _
  232.             Value:=Cats)
  233. 'because of the way VB passes array parameters
  234. 'so we first add a property and then set its value
  235. Set prop = objFieldCol.Add(Name:=CatPropName, _
  236.             Class:=vbString + vbArray)
  237. If prop Is Nothing Then
  238.         MsgBox "Can't add a prop"
  239.         Exit Sub
  240.     End If
  241. prop.Value = Cats
  242. 'set the number of report categories
  243. Set prop = objFieldCol.Add(Name:=NumCatPropName, _
  244.             Class:=vbInteger, _
  245.             Value:=cCats)
  246. If prop Is Nothing Then
  247.         MsgBox "Can't add a prop"
  248.         Exit Sub
  249.     End If
  250.             
  251. 'set the report payperiod
  252. Set prop = objFieldCol.Add(Name:=PayPeriodPropName, _
  253.             Class:=vbDate, _
  254.             Value:=PayPrd)
  255. If prop Is Nothing Then
  256.         MsgBox "Can't add a prop"
  257.         Exit Sub
  258. End If
  259. 'open msg's attachment collection
  260. Set objAttachmentCol = objmessage.Attachments
  261. If objAttachmentCol Is Nothing Then
  262.     MsgBox "Can't open attachment collection"
  263.     Exit Sub
  264. End If
  265. 'create a new attachment
  266. Set objAtt = objAttachmentCol.Add
  267. If objAtt Is Nothing Then
  268.     MsgBox "Can't add attachment"
  269.     Exit Sub
  270. End If
  271. 'send the client.exe as an attachment
  272. objAtt.Type = mapiFileData      'means the file is contained withing the message
  273. objAtt.position = 0             'no particular position
  274. objAtt.ReadFromFile ClientExePath   'read in the file
  275. objAtt.Name = ClientExeName      'set the file name
  276. objmessage.Send showDialog:=False
  277. Exit Sub
  278. error_olemsg:
  279.     MsgBox "Error " & Str(err) & ": " & Error$(err)
  280.     Resume Next
  281. End Sub
  282. Private Sub btnAddCat_Click()
  283.     lstCat.AddItem txtCat.Text  ' Add a client name to the list box.
  284.     txtCat.Text = ""            ' Clear the text box.
  285.     txtCat.SetFocus             ' Place focus back to the text box.
  286. End Sub
  287. Private Sub btnAddUsr_Click()
  288. Dim objNewUsers As Object
  289. Dim ind As Integer
  290. On Error GoTo err_btnAdd_Click
  291. If objSession Is Nothing Then
  292.     MsgBox "must first create MAPI session and logon"
  293.     Exit Sub
  294. End If
  295. Set objNewUsers = objSession.AddressBook( _
  296.         Title:="Select Users", _
  297.         forceResolution:=True, _
  298.         recipLists:=1, _
  299.         toLabel:="&New Users")  ' appears on button
  300.         
  301. ReDim Preserve UserList.aUsers(UserList.cUsers + objNewUsers.Count)
  302. With objNewUsers
  303. For ind = 0 To (objNewUsers.Count - 1) Step 1
  304.     With .Item(ind + 1)
  305.     UserList.aUsers(UserList.cUsers + ind).DisplayName = .Name
  306.     UserList.aUsers(UserList.cUsers + ind).EntryID = .addressentry.id
  307.     UserList.aUsers(UserList.cUsers + ind).ReportIndex = E_NOT_FOUND
  308.     End With
  309. Next ind
  310. End With
  311. UserList.cUsers = UserList.cUsers + objNewUsers.Count
  312. PopulateUserList
  313. Exit Sub
  314. err_btnAdd_Click:
  315.     If Not (err = 91) Then   ' object not set
  316.            MsgBox "Unrecoverable Error:" & err
  317.     End If
  318. End Sub
  319. Private Sub btnRemoveAllUsers_Click()
  320.     lstUsers.Clear                                 ' Empty the list box.
  321.     btnRemoveAllUsers.Enabled = False
  322.     UserList.cUsers = 0
  323. End Sub
  324. Private Sub btnRemoveCat_Click()
  325. Dim ind As Integer
  326.     ind = lstCat.ListIndex              ' Get index.
  327.     If ind >= 0 Then                    ' Make sure a list item is selected.
  328.         lstCat.RemoveItem ind           ' Remove the item from the list box.
  329.     Else
  330.         Beep                            ' This should never occur, because Remove is always disabled if no entry is selected.
  331.     End If
  332.     ' Disable the Remove button if no entries are selected in the list box.
  333.     btnRemoveCat.Enabled = (lstCat.ListIndex <> -1)
  334. End Sub
  335. Private Sub Form_Load()
  336. Dim bFlag As Boolean
  337. On Error GoTo error_olemsg
  338. bFlag = Util_CreateSessionAndLogon()
  339. If Not bFlag Then End
  340. InitUserList
  341. PopulateUserList
  342. InitCategorylist
  343. PopulateCatList
  344. InitPayPeriod
  345. Exit Sub
  346. error_olemsg:
  347.     If Not bFlag Then
  348.         MsgBox "Error " & Str(err) & ": " & Error$(err)
  349.         End
  350.     End If
  351. End Sub
  352. Private Sub Form_Unload(Cancel As Integer)
  353. If Not objSession Is Nothing Then
  354.         objSession.logoff
  355.     End If
  356.             
  357. End Sub
  358. Private Sub lstCat_Click()
  359.     btnRemoveCat.Enabled = (lstCat.ListIndex <> -1)
  360. End Sub
  361. Private Sub lstUsers_Click()
  362.     btnRemoveAllUsers.Enabled = (lstUsers.ListIndex <> -1)
  363. End Sub
  364. Private Sub lstUsers_DblClick()
  365. On Error GoTo err
  366. Dim ind As Integer
  367. Dim AddrEntry As Object
  368.     ind = lstUsers.ListIndex
  369.     If ind >= 0 Then
  370.         Set AddrEntry = objSession.GetAddressEntry(UserList.aUsers(ind).EntryID)
  371.         If AddrEntry Is Nothing Then Exit Sub
  372.         AddrEntry.details
  373.         
  374.     Else
  375.         Beep
  376.     End If
  377. Exit Sub
  378.     If Not (err = -2147221229) Then   ' object not set
  379.            MsgBox "Unrecoverable Error:" & err
  380.     End If
  381. End Sub
  382. Private Sub mnuAbout_Click()
  383.     formAbout.Show 1
  384. End Sub
  385. Private Sub mnuCleanUp_Click()
  386. On Error GoTo error_olemsg
  387. Dim objReceivFolder As Object
  388. Dim objmessages As Object
  389. Dim objmessage As Object
  390. If objSession Is Nothing Then
  391.     MsgBox "Not logged on"
  392.     Exit Sub
  393. End If
  394. GetReceivIPCFolder objReceivFolder
  395. If objReceivFolder Is Nothing Then
  396.     MsgBox "Can't open receive folder"
  397.     Exit Sub
  398. End If
  399. Set objmessages = objReceivFolder.Messages
  400. If objmessages Is Nothing Then
  401.     MsgBox "Failed to open folder's Messages collection"
  402.     Exit Sub
  403. End If
  404. Set objmessage = objmessages.getfirst(ReportMsgType)
  405. Do While Not objmessage Is Nothing
  406.     If Not objmessage.Unread Then
  407.         objmessage.Delete
  408.     End If
  409.     Set objmessage = objmessages.getnext
  410. Exit Sub
  411. error_olemsg:
  412.     MsgBox "Error " & Str(err) & ": " & Error$(err)
  413.     Resume Next
  414. End Sub
  415. Private Sub mnuExit_Click()
  416.     Unload Me
  417.     'End
  418. End Sub
  419. Private Sub mnuGenerate_Click()
  420. If formReport.CompileReport Then
  421.     formReport.Show 1
  422. End If
  423. 'user list may have changed
  424. PopulateUserList
  425. End Sub
  426. Private Sub SaveCats()
  427. On Error GoTo CheckError
  428. Dim ind As Integer
  429. Open CatsListFile For Output As #1
  430. Write #1, CategoryList.cCats
  431. ind = 0
  432. Do While ind < CategoryList.cCats
  433.     Print #1, CategoryList.aCats(ind)
  434.     ind = ind + 1
  435. Close #1
  436. Exit Sub
  437. CheckError:
  438. MsgBox "Error saving user list"
  439. End Sub
  440. Private Sub SaveUsers()
  441. On Error GoTo CheckError
  442. Dim ind As Integer
  443. 'If UserList.cUsers = 0 Then Exit Sub
  444. Open UserListFile For Output As #1
  445. Write #1, UserList.cUsers
  446. ind = 0
  447. Do While ind < UserList.cUsers
  448.     Print #1, UserList.aUsers(ind).DisplayName
  449.     Print #1, UserList.aUsers(ind).EntryID
  450.     ind = ind + 1
  451. Close #1
  452. Exit Sub
  453. CheckError:
  454. MsgBox "Error saving user list"
  455. End Sub
  456. Private Sub mnuSave_Click()
  457. GetUserList
  458. SaveUsers
  459. GetCategoryList
  460. SaveCats
  461. End Sub
  462. Private Sub mnuSend_Click()
  463. GetUserList
  464. GetCategoryList
  465. MousePointer = WaitCursor
  466. SendRequest CategoryList.cCats, CategoryList.aCats, PayPeriod, False
  467. MousePointer = DefaultCursor
  468. End Sub
  469. Function Util_CreateSessionAndLogon() As Boolean
  470.     On Error GoTo err_CreateSessionAndLogon
  471.     Set objSession = CreateObject("MAPI.Session")
  472.     If Not objSession Is Nothing Then
  473.         objSession.Logon
  474.     Else
  475.         Util_CreateSessionAndLogon = False
  476.         Exit Function
  477.     End If
  478.     Util_CreateSessionAndLogon = True
  479.     Exit Function
  480. err_CreateSessionAndLogon:
  481.     Set objSession = Nothing
  482.     If (err <> -2147221229) Then  ' VB4.0 uses "Err.Number"
  483.         MsgBox "Unrecoverable Error:" & err
  484.     End If
  485.     Util_CreateSessionAndLogon = False
  486.     Exit Function
  487. error_olemsg:
  488.     MsgBox "Error " & Str(err) & ": " & Error$(err)
  489.     Resume Next
  490. End Function
  491. Sub GetUserList()
  492. 'empty for now
  493. End Sub
  494. Sub InitPayPeriod()
  495.     PayPeriod = Date
  496. End Sub
  497. Sub InitUserList()
  498. On Error GoTo CheckError
  499. Dim ind As Integer
  500. Dim cSavedUsers As Integer
  501. Open UserListFile For Input As #1
  502. Input #1, cSavedUsers
  503. Debug.Print "found " & cSavedUsers & " saved users"
  504. ReDim UserList.aUsers(cSavedUsers)
  505. ind = 0
  506. Do While ind < cSavedUsers
  507.     Line Input #1, UserList.aUsers(ind).DisplayName
  508.     Line Input #1, UserList.aUsers(ind).EntryID
  509.     UserList.aUsers(ind).ReportIndex = E_NOT_FOUND
  510.     ind = ind + 1
  511. Close #1
  512. UserList.cUsers = cSavedUsers
  513. Exit Sub
  514. CheckError:
  515. UserList.cUsers = 0
  516. End Sub
  517. Sub InitCategorylist()
  518. 'Read saved cats from file
  519. On Error GoTo CheckError
  520. Dim ind As Integer
  521. Dim cSavedCats As Integer
  522. Open CatsListFile For Input As #1
  523. Input #1, cSavedCats
  524. Debug.Print "found " & cSavedCats & " saved categories"
  525. ReDim CategoryList.aCats(cSavedCats)
  526. ind = 0
  527. Do While ind < cSavedCats
  528.     Line Input #1, CategoryList.aCats(ind)
  529.     ind = ind + 1
  530. Close #1
  531. CategoryList.cCats = cSavedCats
  532. Exit Sub
  533. CheckError:
  534. CategoryList.cCats = 0
  535. End Sub
  536. Private Sub txtCat_Change()
  537.     ' Enable the Add button if at least one character in the name is entered or changed.
  538.     btnAddCat.Enabled = (Len(txtCat.Text) > 0)
  539. End Sub
  540. Sub PopulateUserList()
  541. Dim ind As Integer
  542. lstUsers.Clear
  543. For ind = 0 To UserList.cUsers - 1
  544.        lstUsers.AddItem UserList.aUsers(ind).DisplayName
  545. Next ind
  546. End Sub
  547. Private Sub PopulateCatList()
  548. Dim ind As Integer
  549. lstCat.Clear
  550. For ind = 0 To CategoryList.cCats - 1
  551.     lstCat.AddItem CategoryList.aCats(ind)
  552. Next ind
  553. End Sub
  554.