home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap35 / frmcusta.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-11  |  8.7 KB  |  263 lines

  1. VERSION 4.00
  2. Begin VB.Form frmCustAccount 
  3.    Caption         =   "Customer Account"
  4.    ClientHeight    =   3840
  5.    ClientLeft      =   1185
  6.    ClientTop       =   1575
  7.    ClientWidth     =   7650
  8.    BeginProperty Font 
  9.       name            =   "MS Sans Serif"
  10.       charset         =   1
  11.       weight          =   700
  12.       size            =   8.25
  13.       underline       =   0   'False
  14.       italic          =   0   'False
  15.       strikethrough   =   0   'False
  16.    EndProperty
  17.    ForeColor       =   &H80000008&
  18.    Height          =   4245
  19.    Left            =   1125
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    ScaleHeight     =   3840
  23.    ScaleWidth      =   7650
  24.    Top             =   1230
  25.    Width           =   7770
  26.    Begin VB.TextBox txtCurrentBalance 
  27.       Height          =   375
  28.       Left            =   4320
  29.       Locked          =   -1  'True
  30.       TabIndex        =   3
  31.       TabStop         =   0   'False
  32.       Top             =   3240
  33.       Width           =   1575
  34.    End
  35.    Begin VB.CommandButton btnPrintStatement 
  36.       Caption         =   "&Print Account Statement"
  37.       Height          =   495
  38.       Left            =   2520
  39.       TabIndex        =   1
  40.       Top             =   240
  41.       Width           =   2295
  42.    End
  43.    Begin VB.CommandButton btnFindCust 
  44.       Caption         =   "&Close"
  45.       Height          =   495
  46.       Left            =   6240
  47.       TabIndex        =   0
  48.       Top             =   3240
  49.       Width           =   1095
  50.    End
  51.    Begin VB.Data Orders 
  52.       Appearance      =   0  'Flat
  53.       Caption         =   "Orders"
  54.       Connect         =   ""
  55.       DatabaseName    =   "C:\VBPROJ\SAMS\VB4DB.MDB"
  56.       Exclusive       =   0   'False
  57.       Height          =   270
  58.       Left            =   120
  59.       Options         =   0
  60.       ReadOnly        =   0   'False
  61.       RecordsetType   =   1  'Dynaset
  62.       RecordSource    =   "ORDERS"
  63.       Top             =   3240
  64.       Visible         =   0   'False
  65.       Width           =   1935
  66.    End
  67.    Begin Threed.SSPanel SSPanel1 
  68.       Height          =   375
  69.       Left            =   2640
  70.       TabIndex        =   2
  71.       Top             =   3240
  72.       Width           =   1575
  73.       _version        =   65536
  74.       _extentx        =   2778
  75.       _extenty        =   661
  76.       _stockprops     =   15
  77.       caption         =   "Current balance"
  78.       backcolor       =   12632256
  79.    End
  80.    Begin Crystal.CrystalReport rptBilling 
  81.       Left            =   2160
  82.       Top             =   3360
  83.       _extentx        =   741
  84.       _extenty        =   741
  85.       _stockprops     =   0
  86.       reportfilename  =   ""
  87.       destination     =   0
  88.       windowleft      =   100
  89.       windowtop       =   100
  90.       windowwidth     =   490
  91.       windowheight    =   300
  92.       windowtitle     =   ""
  93.       windowborderstyle=   2
  94.       windowcontrolbox=   -1  'True
  95.       windowmaxbutton =   -1  'True
  96.       windowminbutton =   -1  'True
  97.       copiestoprinter =   1
  98.       printfilename   =   ""
  99.       printfiletype   =   0
  100.       selectionformula=   ""
  101.       groupselectionformula=   ""
  102.       connect         =   ""
  103.       username        =   ""
  104.       reportsource    =   0
  105.       boundreportheading=   ""
  106.       boundreportfooter=   0   'False
  107.    End
  108.    Begin MSDBGrid.DBGrid OrdersGrid 
  109.       Bindings        =   "FRMCUSTA.frx":0000
  110.       Height          =   2175
  111.       Left            =   120
  112.       Negotiate       =   -1  'True
  113.       OleObjectBlob   =   "FRMCUSTA.frx":000F
  114.       TabIndex        =   4
  115.       Top             =   960
  116.       Width           =   7335
  117.    End
  118. Attribute VB_Name = "frmCustAccount"
  119. Attribute VB_Creatable = False
  120. Attribute VB_Exposed = False
  121. Private Sub btnPrintStatement_Click()
  122.     Dim Tbl As Table
  123.     response = MsgBox("Really print statement?", 4, "Print Statement")
  124.     If (response = vbNo) Then
  125.         Exit Sub
  126.     End If
  127.     On Error GoTo statement_error
  128.     ' Calculate the current balance one last time and write the amount to
  129.     ' CUSTMAIN.  If the balance is zero, prompt the user for deleting all
  130.     ' ORDERS records for the client.
  131.     Call CalculateCurrentBalance
  132.     Set Tbl = CustDB.OpenTable("CustMain")
  133.     Tbl.Index = "PrimaryKey"
  134.     Tbl.Seek "=", Customer_number
  135.     If (Tbl.NoMatch = False) Then
  136.         Tbl.Edit
  137.         Tbl.Fields("Current_Balance") = CurrentBalance
  138.         Tbl.Update
  139.     End If
  140.     Tbl.Close
  141.     rptBilling.ReportFileName = App_location + "statemnt.rpt"
  142.     rptBilling.Destination = 0    ' 1=Output to Printer, 0=Screen
  143.     rptBilling.Action = 1
  144.     Exit Sub
  145. statement_error:
  146.     MsgBox ("Error printing this statement: " & Err.Description)
  147.     MousePointer = 0
  148. End Sub
  149. Private Sub Command3D1_Click()
  150. End Sub
  151. Private Sub Form_KeyPress(KeyAscii As Integer)
  152. ' While not a Windows standard, the client
  153. ' prefers to use the enter key to move from field to field.
  154. ' This subroutine should trap the keypress and
  155. ' and process all "ENTER" keys as "TAB"
  156.     If KeyAscii = 13 Then
  157.         SendKeys "{tab}"
  158.         KeyAscii = 0
  159.     End If
  160. End Sub
  161. Private Sub btnFindCust_Click()
  162.     Me.Hide
  163.     'Unload Me
  164. End Sub
  165. Private Sub Form_Activate()
  166.     ' Reset to the default  pointer when returning to this form.
  167.     MousePointer = 0
  168.     Dim Tbl As Table
  169.     Dim CreditTbl As Table
  170.     ' Put the customer name in the title bar
  171.     If IsNull(CustmainDynaset.Fields("Last_Name")) <> True Then
  172.         frmCustAccount.Caption = "Account Information for " & CustmainDynaset.Fields("Last_Name")
  173.     Else
  174.         If IsNull(CustmainDynaset.Fields("Company")) <> True Then
  175.             frmCustAccount.Caption = "Account Information for " & CustmainDynaset.Fields("Company")
  176.         Else
  177.             frmCustAccount.Caption = "Account Information"
  178.         End If
  179.     End If
  180.     ' This SQL statement populates the grid.  I included an 'Order By'
  181.     ' so the records are displayed in order of date.
  182.     orders.RecordSource = "Select * From Orders Where CustomerNum = " & Str(Customer_number) & " Order By Date DESC;"
  183.     orders.Refresh
  184.     ' Calculate and put the current balance on the screen.
  185.     Call CalculateCurrentBalance
  186.     txtCurrentBalance = CurrentBalance
  187. End Sub
  188. Private Sub Form_Load()
  189.     Dim Tbl As Table
  190.     'Center the form
  191.     Left = (Screen.Width - Width) / 2
  192.     Top = (Screen.Height - Height) / 2
  193.     orders.DatabaseName = Database_name
  194. End Sub
  195. Private Sub OrdersGrid_Append()
  196.     orders.Recordset.AddNew
  197.     orders.Recordset.Fields("CustomerNum") = Customer_number
  198.     orders.Recordset.Update
  199. End Sub
  200. Private Sub OrdersGrid_AfterDelete()
  201.    On Error GoTo DeleteError
  202.     If (orders.Recordset.RecordCount = 0) Then
  203.         orders.Recordset.AddNew
  204.         orders.Recordset.Fields("CustomerNum") = Customer_number
  205.         CalculateCurrentBalance
  206.         OrdersGrid.SetFocus
  207.         Exit Sub
  208.     End If
  209.     orders.Recordset.MoveFirst
  210.     orders.Refresh
  211.     OrdersGrid.SetFocus
  212.     CalculateCurrentBalance
  213.     txtCurrentBalance = CurrentBalance
  214.     Exit Sub
  215. DeleteError:
  216.     MsgBox "This record is new and must be saved to the database before it can be deleted", 16, "Delete Record"
  217.     OrdersGrid.SetFocus
  218.     Exit Sub
  219. End Sub
  220. Private Sub OrdersGrid_AfterUpdate()
  221.     Call CalculateCurrentBalance
  222.     txtCurrentBalance = CurrentBalance
  223. End Sub
  224. Private Sub OrdersGrid_BeforeDelete(Cancel As Integer)
  225. Dim response As Integer
  226.     response = MsgBox("Delete the current order?", 4, "Delete Record")
  227.     If (response = IDNO) Then
  228.         OrdersGrid.SetFocus
  229.         Exit Sub
  230.     End If
  231. End Sub
  232. Private Sub OrdersGrid_BeforeUpdate(Cancel As Integer)
  233.      orders.Recordset.Fields("CustomerNum") = Customer_number
  234. End Sub
  235. Private Sub OrdersGrid_GotFocus()
  236.     Dim Tbl As Table
  237.     DoEvents
  238.     If (orders.Recordset.RecordCount = 0) Then
  239.         DoEvents
  240.         orders.Recordset.AddNew
  241.         orders.Recordset.Fields("CustomerNum") = Customer_number
  242.     End If
  243. End Sub
  244. Private Sub OrdersGrid_RowChange()
  245.     Call CalculateCurrentBalance
  246. End Sub
  247. Private Sub OrdersGrid_Validate(row As Long, Col As Integer, value As String, Cancel As Integer)
  248.     ' If the user has just changed data in the date cell, validate it it.
  249.     On Error GoTo DateError
  250.     If (Col = 1) Then
  251.         RetVal = DateValue(value)
  252.     End If
  253.     Exit Sub
  254. DateError:
  255.     MsgBox "Date is illegal", 16, "Error"
  256.     Cancel = True
  257.     Exit Sub
  258. End Sub
  259. Private Sub OrdersGrid_RowColChange1(ByVal LastRow As String, ByVal LastCol As Integer)
  260.     Call CalculateCurrentBalance
  261.     txtCurrentBalance = CurrentBalance
  262. End Sub
  263.