VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form addproduct 
   BackColor       =   &H00C0C0FF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "  Add Product"
   ClientHeight    =   8865
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8025
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   8865
   ScaleWidth      =   8025
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command3 
      Caption         =   "Generate Product Code"
      Height          =   495
      Left            =   5040
      TabIndex        =   18
      Top             =   120
      Width           =   2535
   End
   Begin MSAdodcLib.Adodc d 
      Height          =   330
      Left            =   10440
      Top             =   2400
      Width           =   3015
      _ExtentX        =   5318
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   3
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "DSN=sega"
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   "sega"
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "product"
      Caption         =   "db_prod"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "addproduct.frx":0000
      Height          =   4215
      Left            =   120
      TabIndex        =   15
      Top             =   4560
      Width           =   7815
      _ExtentX        =   13785
      _ExtentY        =   7435
      _Version        =   393216
      BackColor       =   12640511
      HeadLines       =   1
      RowHeight       =   15
      FormatLocked    =   -1  'True
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   7
      BeginProperty Column00 
         DataField       =   "prod_code"
         Caption         =   "Prod Code"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   "prod_name"
         Caption         =   "Prod_name"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column02 
         DataField       =   "item_price"
         Caption         =   "item_price"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column03 
         DataField       =   "prod_qty"
         Caption         =   "prod_qty"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column04 
         DataField       =   "prod_cat_code"
         Caption         =   "prod_cat_code"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column05 
         DataField       =   "reorder_level"
         Caption         =   "reorder_level"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column06 
         DataField       =   "max_per_day_prod"
         Caption         =   "max_per_day_prod"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
            ColumnWidth     =   1140.095
         EndProperty
         BeginProperty Column01 
            ColumnWidth     =   1140.095
         EndProperty
         BeginProperty Column02 
            ColumnWidth     =   945.071
         EndProperty
         BeginProperty Column03 
            ColumnWidth     =   840.189
         EndProperty
         BeginProperty Column04 
            ColumnWidth     =   1140.095
         EndProperty
         BeginProperty Column05 
            ColumnWidth     =   1140.095
         EndProperty
         BeginProperty Column06 
            ColumnWidth     =   1035.213
         EndProperty
      EndProperty
   End
   Begin MSAdodcLib.Adodc db_cat 
      Height          =   330
      Left            =   10440
      Top             =   3000
      Width           =   3015
      _ExtentX        =   5318
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   3
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "DSN=sega"
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   "sega"
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "product_category"
      Caption         =   "db_cat"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.TextBox txt_prod_code 
      BackColor       =   &H00FFFFC0&
      Height          =   285
      Left            =   1560
      Locked          =   -1  'True
      TabIndex        =   14
      Top             =   240
      Width           =   3135
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00C0FFC0&
      Height          =   3855
      Left            =   120
      TabIndex        =   0
      Top             =   600
      Width           =   4935
      Begin MSDataListLib.DataCombo dc_prod_cat 
         Bindings        =   "addproduct.frx":0010
         DataField       =   "prod_cat_code"
         DataSource      =   "db_cat"
         Height          =   315
         Left            =   1920
         TabIndex        =   17
         Top             =   1800
         Width           =   2415
         _ExtentX        =   4260
         _ExtentY        =   556
         _Version        =   393216
         ListField       =   "cat_name"
         Text            =   ""
      End
      Begin VB.TextBox txt_prod_qty 
         Height          =   285
         Left            =   1920
         TabIndex        =   16
         Top             =   1320
         Width           =   2415
      End
      Begin VB.CommandButton Command2 
         Caption         =   "&Add"
         Height          =   375
         Left            =   840
         TabIndex        =   12
         Top             =   3240
         Width           =   1455
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Clear Fields"
         Height          =   375
         Left            =   2520
         TabIndex        =   11
         Top             =   3240
         Width           =   1695
      End
      Begin VB.TextBox txt_perday_prod 
         Height          =   285
         Left            =   1920
         TabIndex        =   10
         Top             =   2280
         Width           =   2415
      End
      Begin VB.TextBox txt_reorder_level 
         Height          =   285
         Left            =   1920
         TabIndex        =   8
         Top             =   2760
         Width           =   2415
      End
      Begin VB.TextBox txt_item_price 
         Height          =   285
         Left            =   1920
         TabIndex        =   5
         Top             =   840
         Width           =   2415
      End
      Begin VB.TextBox txt_prod_name 
         Height          =   285
         Left            =   1920
         TabIndex        =   2
         Top             =   360
         Width           =   2415
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Reorder Level"
         Height          =   195
         Left            =   360
         TabIndex        =   9
         Top             =   2880
         Width           =   1005
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "max per day production"
         Height          =   195
         Left            =   240
         TabIndex        =   7
         Top             =   2400
         Width           =   1650
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Category"
         Height          =   195
         Left            =   480
         TabIndex        =   6
         Top             =   1920
         Width           =   630
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Quantity"
         Height          =   195
         Left            =   480
         TabIndex        =   4
         Top             =   1440
         Width           =   585
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Item Price"
         Height          =   195
         Left            =   480
         TabIndex        =   3
         Top             =   960
         Width           =   705
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Product Name"
         Height          =   195
         Left            =   480
         TabIndex        =   1
         Top             =   480
         Width           =   1020
      End
   End
   Begin VB.Label l1 
      AutoSize        =   -1  'True
      BackColor       =   &H00C0C0FF&
      Caption         =   "Product Code"
      Height          =   195
      Left            =   480
      TabIndex        =   13
      Top             =   240
      Width           =   975
   End
End
Attribute VB_Name = "addproduct"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
txt_prod_code.Text = ""
txt_prod_name.Text = ""
txt_item_price.Text = ""
txt_prod_qty.Text = ""
dc_prod_cat.Text = ""
txt_perday_prod.Text = ""
txt_reorder_level.Text = ""

   
End Sub

Private Sub Command2_Click()
If txt_prod_code.Text = "" Or txt_prod_name.Text = "" Or txt_item_price.Text = "" Or txt_prod_qty.Text = "" Or dc_prod_cat.Text = "" Or txt_perday_prod.Text = "" Or txt_reorder_level.Text = "" Then
    MsgBox "Fields Empty"
    Exit Sub
End If
con.Open "DSN=sega"
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset


rs.Open "select * from product where prod_code='" & Trim(txt_prod_code.Text) & "'", con, adOpenStatic, adLockOptimistic


If rs.EOF Then
    rs.Close
    rs.Open "select * from product", con, adOpenStatic, adLockOptimistic
    rs.AddNew
    rs1.Open "select * from product_category where cat_name = '" & dc_prod_cat.Text & "'", con, adOpenStatic, adLockOptimistic
    
    If rs1.EOF Then
    
        MsgBox "product category mismatch "
        rs1.Close
        con.Close
        Exit Sub
    Else
        rs!prod_cat_code = rs1!prod_cat_code
        rs1.Close
    End If


    rs!prod_code = Trim(txt_prod_code.Text)
    rs!prod_name = Trim(txt_prod_name.Text)
    rs!item_price = Trim(txt_item_price.Text)
    rs!prod_qty = Trim(txt_prod_qty.Text)
    rs!max_per_day_prod = Trim(txt_perday_prod.Text)
    rs!reorder_level = Trim(txt_reorder_level.Text)

    rs.Update
    MsgBox "record added"
    rs.Close
Else

    MsgBox "region code already exists: "

End If

d.Refresh

con.Close
End Sub

Private Sub Command3_Click()
con.Open "DSN=sega"
Dim rs2 As New ADODB.Recordset
Dim cust
Dim a

rs2.Open "select * from product order by prod_code", con, adOpenStatic, adLockOptimistic

If rs2.EOF Then
x = "P-1"
Else
rs2.MoveLast
a = rs2!prod_code
x = "P-" & Int(Mid(a, 3)) + 1
End If

txt_prod_code.Text = x
con.Close
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Exit_Click
    mainform.Enabled = True
End Sub

