home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap35 / frmbilli.frm (.txt) < prev    next >
Visual Basic Form  |  1995-08-03  |  14KB  |  372 lines

  1. VERSION 4.00
  2. Begin VB.Form frmBilling 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Billing"
  6.    ClientHeight    =   6255
  7.    ClientLeft      =   210
  8.    ClientTop       =   420
  9.    ClientWidth     =   9270
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   6660
  21.    Left            =   150
  22.    LinkTopic       =   "Form3"
  23.    ScaleHeight     =   6255
  24.    ScaleWidth      =   9270
  25.    Top             =   75
  26.    Width           =   9390
  27.    Begin VB.TextBox CustomerNumberField 
  28.       Height          =   375
  29.       Left            =   6360
  30.       TabIndex        =   5
  31.       Top             =   5320
  32.       Width           =   1095
  33.    End
  34.    Begin VB.CommandButton btnCloseBilling 
  35.       Caption         =   "&Close"
  36.       Height          =   495
  37.       Left            =   7680
  38.       TabIndex        =   3
  39.       Top             =   5280
  40.       Width           =   1455
  41.    End
  42.    Begin VB.Data ORDERS 
  43.       Appearance      =   0  'Flat
  44.       Caption         =   "ORDERS"
  45.       Connect         =   ""
  46.       DatabaseName    =   "C:\VBPROJ\SAMS\VB4DB.MDB"
  47.       Exclusive       =   0   'False
  48.       Height          =   270
  49.       Left            =   840
  50.       Options         =   0
  51.       ReadOnly        =   0   'False
  52.       RecordsetType   =   1  'Dynaset
  53.       RecordSource    =   "ORDERS"
  54.       Top             =   5880
  55.       Visible         =   0   'False
  56.       Width           =   2055
  57.    End
  58.    Begin VB.CommandButton Command2 
  59.       Appearance      =   0  'Flat
  60.       BackColor       =   &H80000005&
  61.       Caption         =   "Print &Statements"
  62.       Height          =   495
  63.       Left            =   2520
  64.       TabIndex        =   0
  65.       Top             =   5280
  66.       Width           =   1575
  67.    End
  68.    Begin VB.Data CUSTMAIN 
  69.       Appearance      =   0  'Flat
  70.       Caption         =   "CUSTMAIN"
  71.       Connect         =   ""
  72.       DatabaseName    =   "C:\VBPROJ\SAMS\VB4DB.MDB"
  73.       Exclusive       =   0   'False
  74.       Height          =   270
  75.       Left            =   3360
  76.       Options         =   0
  77.       ReadOnly        =   0   'False
  78.       RecordsetType   =   1  'Dynaset
  79.       RecordSource    =   "CUSTMAIN"
  80.       Top             =   5880
  81.       Visible         =   0   'False
  82.       Width           =   2655
  83.    End
  84.    Begin MSDBGrid.DBGrid CustMainGrid 
  85.       Bindings        =   "FRMBILLI.frx":0000
  86.       Height          =   4935
  87.       Left            =   6960
  88.       OleObjectBlob   =   "FRMBILLI.frx":0011
  89.       TabIndex        =   4
  90.       Top             =   240
  91.       Width           =   2295
  92.    End
  93.    Begin Crystal.CrystalReport rptBilling 
  94.       Left            =   240
  95.       Top             =   5760
  96.       _extentx        =   741
  97.       _extenty        =   741
  98.       _stockprops     =   0
  99.       reportfilename  =   ""
  100.       destination     =   0
  101.       windowleft      =   100
  102.       windowtop       =   100
  103.       windowwidth     =   490
  104.       windowheight    =   300
  105.       windowtitle     =   ""
  106.       windowborderstyle=   2
  107.       windowcontrolbox=   -1  'True
  108.       windowmaxbutton =   -1  'True
  109.       windowminbutton =   -1  'True
  110.       copiestoprinter =   1
  111.       printfilename   =   ""
  112.       printfiletype   =   0
  113.       selectionformula=   ""
  114.       groupselectionformula=   ""
  115.       connect         =   ""
  116.       username        =   ""
  117.    End
  118.    Begin MSDBGrid.DBGrid OrdersGrid 
  119.       Bindings        =   "FRMBILLI.frx":1E4C
  120.       Height          =   4935
  121.       Left            =   120
  122.       OleObjectBlob   =   "FRMBILLI.frx":1E5B
  123.       TabIndex        =   2
  124.       Top             =   240
  125.       Width           =   6735
  126.    End
  127.    Begin VB.Label Label1 
  128.       Alignment       =   1  'Right Justify
  129.       Appearance      =   0  'Flat
  130.       BackColor       =   &H00C0C0C0&
  131.       Caption         =   "Find Customer #: "
  132.       ForeColor       =   &H80000008&
  133.       Height          =   255
  134.       Left            =   4680
  135.       TabIndex        =   1
  136.       Top             =   5400
  137.       Width           =   1695
  138.    End
  139. Attribute VB_Name = "frmBilling"
  140. Attribute VB_Creatable = False
  141. Attribute VB_Exposed = False
  142. Dim CurrentCustomerNumber As Double
  143. Private Sub btnCloseBilling_Click()
  144.     Unload frmBilling
  145. End Sub
  146. Private Sub CalculateCurrentBalance(CustomerNumber As Double)
  147.     Dim RecSet As Snapshot
  148.     Dim buffer As String
  149.     Dim charge
  150.     Dim credit
  151.     buffer = "Select Sum(Charge),Sum(Credit) From Orders Where CustomerNum = " & Str(CustomerNumber) & ";"
  152.     Set RecSet = CustDB.CreateSnapshot(buffer)
  153.     If (IsNull(RecSet.Fields(0))) = True Then
  154.         charge = 0
  155.     Else
  156.         charge = RecSet.Fields(0)
  157.     End If
  158.     If (IsNull(RecSet.Fields(1))) = True Then
  159.         credit = 0
  160.     Else
  161.         credit = RecSet.Fields(1)
  162.     End If
  163.     CurrentBalance = charge - credit
  164. End Sub
  165. Private Sub Command2_Click()
  166.     Dim BillingTbl As TABLE
  167.     Dim RecSet As Snapshot
  168.     Dim print_statements
  169.     Set BillingTbl = CustDB.OpenTable("BILLING")
  170.     On Error GoTo billerr
  171.     ' Retrieve all records from CUSTMAIN where the current balance is greater
  172.     ' than 0.
  173.     Set RecSet = CustDB.CreateSnapshot("Select * From CUSTMAIN Where Current_Balance > 0.0;")
  174.     If Not RecSet.RecordCount > 0 Then
  175.         MsgBox ("All accounts are up to date.  There are no outstanding balances to print statements for.")
  176.         Exit Sub
  177.     End If
  178.     RecSet.MoveLast
  179.     print_statements = MsgBox("This will print ALL (up to " & RecSet.RecordCount & ") of the statements.  Proceed? ", vbYesNo, " Print Statements ")
  180.     If print_statements <> 6 Then 'Anything but YES will exit the subroutine
  181.         Exit Sub
  182.     End If
  183.     RecSet.MoveFirst
  184.     While (RecSet.EOF = False)
  185.         Screen.MousePointer = 11
  186.         ' Remove any records existing in BILLING
  187.         CustDB.Execute ("Delete * From BILLING")
  188.         BillingTbl.AddNew
  189.         BillingTbl.Fields("CustomerNumber") = RecSet.Fields("CustomerNum")
  190.       
  191.         BillingTbl.Fields("CompanyName") = RecSet.Fields("Company")
  192.         BillingTbl.Fields("LastName") = RecSet.Fields("Last_Name")
  193.         BillingTbl.Fields("FirstName") = RecSet.Fields("First_Name")
  194.         BillingTbl.Fields("Address") = RecSet.Fields("Address")
  195.         BillingTbl.Fields("City") = RecSet.Fields("City")
  196.         BillingTbl.Fields("State") = RecSet.Fields("State")
  197.         BillingTbl.Fields("Zip") = RecSet.Fields("Zip")
  198.         BillingTbl.Fields("Apt") = RecSet.Fields("Suite_Apt")
  199.         BillingTbl.Fields("POBox") = RecSet.Fields("PO_Box")
  200.         BillingTbl.Fields("StatementDate") = Date
  201.         BillingTbl.UPDATE
  202.         rptBilling.ReportFileName = "c:\vbproj\sams\statemnt.rpt"
  203.         rptBilling.Destination = 0    ' 1=Output to Printer, 0=Screen
  204.         rptBilling.Action = 1
  205.        RecSet.MoveNext
  206.        Screen.MousePointer = 0
  207.     Wend
  208.     Exit Sub
  209. billerr:
  210.     MsgBox (Err.Description)
  211. End Sub
  212. Private Sub btnCustMain_Click()
  213.     If orders.Recordset.RecordCount = 0 Then
  214.     MsgBox ("no records to insert into.")
  215.     Exit Sub
  216.     End If
  217.     OrdersGrid.Visible = False
  218.     orders.Refresh
  219.     DoEvents
  220.     orders.Recordset.MoveLast
  221.     DoEvents
  222.     OrdersGrid.Refresh
  223.     DoEvents
  224.     OrdersGrid.Visible = True
  225.     OrdersGrid.SetFocus
  226.     SendKeys "{Down}"
  227. End Sub
  228. Private Sub CustMainGrid_RowColChange(ByVal LastRow As String, ByVal LastCol As Integer)
  229.     Dim OrdersTbl As TABLE
  230.     ' Synchronize the Orders grid with the CustMain grid
  231.     If orders.Recordset.RecordCount <> 0 Then
  232.         If custmain.Recordset.RecordCount = 0 Then
  233.             'custmain.Recordset.Refresh
  234.         End If
  235.         If (orders.Recordset.Fields("CustomerNum") <> custmain.Recordset.Fields("CustomerNum")) Then
  236.         ' Only synchronize if records exist in ORDERS for this customer
  237.             Set OrdersTbl = CustDB.OpenTable("Orders")
  238.             OrdersTbl.Index = "CustomerNum"
  239.             OrdersTbl.Seek "=", custmain.Recordset.Fields("CustomerNum")
  240.             If (OrdersTbl.NoMatch = False) Then
  241.                 buffer = "CustomerNum = " & custmain.Recordset.Fields("CustomerNum")
  242.                 orders.Recordset.FindFirst buffer
  243.             End If
  244.         End If
  245.     End If
  246. End Sub
  247. Private Sub CustomerNumberField_KeyPress(KeyAscii As Integer)
  248. ' While not a Windows standard, the client
  249. ' prefers to use the enter key to move from field to field.
  250. ' This subroutine should trap the keypress and
  251. ' and process all "ENTER" keys as "TAB"
  252.     If KeyAscii = 13 Then
  253.         SendKeys "{tab}"
  254.         KeyAscii = 0
  255.     End If
  256. End Sub
  257. Private Sub CustomerNumberField_LostFocus()
  258.     Dim buffer As String
  259.     If (IsNull(CustomerNumberField) = False And Len(CustomerNumberField) >= 1) Then
  260.         buffer = "CustomerNum = " & CustomerNumberField
  261.         custmain.Recordset.FindFirst buffer
  262.     End If
  263.     CustomerNumberField.TEXT = ""
  264. End Sub
  265. Private Sub Form_Activate()
  266.     Dim message
  267.     Dim retvalue
  268.     ' Reset to the default  pointer when returning to this form.
  269.     MousePointer = 0
  270.     orders.DatabaseName = Database_name
  271.     orders.RecordSource = "Select * from ORDERS Order By CustomerNum, Date DESC;"
  272.     custmain.DatabaseName = Database_name
  273.     custmain.RecordSource = "Select * from CUSTMAIN order by CustomerNum;"
  274.     message = "Today's date is " & Format$(Now, "mmmm dd, yyyy")
  275.     retvalue = MsgBox(message, MB_ICONINFORMATION, "")
  276.     custmain.Refresh
  277.     orders.Refresh
  278.     OrdersGrid.SetFocus
  279.     FirstTimeFocus = True
  280.     CurrentCustomerNumber = -1
  281. End Sub
  282. Private Sub Form_Load()
  283.     'Center the form
  284.     Left = (Screen.Width - Width) / 2
  285.     TOP = (Screen.Height - Height) / 2
  286. End Sub
  287. Private Sub OrdersGrid_AfterDelete()
  288.     Dim CustMainTbl As TABLE
  289.     Dim response As Integer
  290.     If (orders.Recordset.RecordCount = 0) Then
  291.         orders.Recordset.AddNew
  292.         orders.Recordset.Fields("CustomerNum") = Customer_number
  293.         OrdersGrid.SetFocus
  294.     End If
  295.     Set CustMainTbl = CustDB.OpenTable("CustMain")
  296.     CustMainTbl.Index = "PrimaryKey"
  297.     CustMainTbl.Seek "=", CurrentCustomerNumber
  298.     If (CustMainTbl.NoMatch = False) Then
  299.         CustMainTbl.Edit
  300.         CustMainTbl.Fields("Current_Balance") = CurrentBalance
  301.         CustMainTbl.UPDATE
  302.     End If
  303.     CalculateCurrentBalance (Val(Customer_number))
  304.     orders.Recordset.MoveFirst
  305.     orders.Refresh
  306.     custmain.Refresh
  307.     CustMainGrid.Refresh
  308.     OrdersGrid.SetFocus
  309.     Exit Sub
  310. DeleteError:
  311.     response = MsgBox("Error Deleting record: " & Err.Description, vbExclamation, "Delete Record")
  312.     OrdersGrid.SetFocus
  313.     Exit Sub
  314. End Sub
  315. Private Sub OrdersGrid_BeforeDelete(Cancel As Integer)
  316.     Dim response As Integer
  317.     response = MsgBox("REALLY delete the current order?", 4, "Delete Record")
  318.     If (response = IDNO) Then
  319.         OrdersGrid.SetFocus
  320.         Exit Sub
  321.     End If
  322. End Sub
  323. Private Sub OrdersGrid_GotFocus()
  324.     Dim Tbl As TABLE
  325.     If (orders.Recordset.RecordCount = 0) Then
  326.         ' The following DoEvents is necessary.
  327.         DoEvents
  328.         orders.Recordset.AddNew
  329.         orders.Recordset.Fields("CustomerNum") = Customer_number
  330.     End If
  331.     ' If this is the first time the grid has the focus, populate the billing
  332.     ' fields from an existing record or enter a new record in CustBillAddr.
  333.     If (FirstTimeFocus = True) Then
  334.         Set Tbl = CustDB.OpenTable("CustBillAddr")
  335.         Tbl.Index = "PrimaryKey"
  336.         Tbl.Seek "=", Customer_number
  337.         If (Tbl.NoMatch = True) Then
  338.             Tbl.AddNew
  339.             Tbl.Fields("CustomerNum") = Customer_number
  340.             Tbl.UPDATE
  341.         End If
  342.     End If
  343. End Sub
  344. Private Sub OrdersGrid_RowColChange(ByVal LastRow As String, ByVal LastCol As Integer)
  345.     Dim buffer As String
  346.     Dim CustMainTbl As TABLE
  347.     ' This routine is called after the user has already moved to a different
  348.     ' row.  The value of 'CurrentCustomerNumber' still contains the customer
  349.     ' number of the previous record.
  350.     CalculateCurrentBalance (CurrentCustomerNumber)
  351.     ' Update the current balance in CUSTMAIN
  352.     Set CustMainTbl = CustDB.OpenTable("CustMain")
  353.     CustMainTbl.Index = "PrimaryKey"
  354.     CustMainTbl.Seek "=", CurrentCustomerNumber
  355.     If (CustMainTbl.NoMatch = False) Then
  356.         CustMainTbl.Edit
  357.         CustMainTbl.Fields("Current_Balance") = CurrentBalance
  358.         CustMainTbl.UPDATE
  359.         custmain.Refresh
  360.     End If
  361.     ' Synchronize the CustMain grid with the Orders grid
  362.     If orders.Recordset.RecordCount <> 0 Then
  363.         If (IsNull(orders.Recordset.Fields("CustomerNum")) = False) Then
  364.             CurrentCustomerNumber = orders.Recordset.Fields("CustomerNum")
  365.             buffer = "CustomerNum = " & orders.Recordset.Fields("CustomerNum")
  366.             custmain.Recordset.FindFirst buffer
  367.             CustMainGrid.Refresh
  368.         End If
  369.     End If
  370.     NewRecord = False
  371. End Sub
  372.