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"
Begin VB.Form order1 
   BackColor       =   &H00C0C0FF&
   Caption         =   "Place Order"
   ClientHeight    =   6225
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7410
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6225
   ScaleWidth      =   7410
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command7 
      Caption         =   "Generate Order No"
      Height          =   375
      Left            =   2760
      TabIndex        =   20
      Top             =   120
      Width           =   1815
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00C0FFC0&
      Height          =   2655
      Left            =   120
      TabIndex        =   6
      Top             =   960
      Width           =   6855
      Begin VB.TextBox txt_qty 
         Alignment       =   2  'Center
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   13.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   645
         Left            =   2400
         TabIndex        =   15
         Top             =   1320
         Width           =   855
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Add Order"
         Height          =   375
         Left            =   840
         TabIndex        =   14
         Top             =   2040
         Width           =   1815
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Clear Fields"
         Height          =   375
         Left            =   2760
         TabIndex        =   13
         Top             =   2040
         Width           =   1935
      End
      Begin VB.TextBox txt_cust_no 
         Height          =   285
         Left            =   2040
         Locked          =   -1  'True
         TabIndex        =   12
         Top             =   240
         Width           =   1935
      End
      Begin VB.TextBox txt_sup_no 
         Height          =   285
         Left            =   2040
         Locked          =   -1  'True
         TabIndex        =   11
         Top             =   600
         Width           =   1935
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Browse Customer"
         Height          =   255
         Left            =   4080
         TabIndex        =   10
         Top             =   240
         Width           =   1575
      End
      Begin VB.CommandButton Command5 
         Caption         =   "Browse Supplier"
         Height          =   255
         Left            =   4080
         TabIndex        =   9
         Top             =   600
         Width           =   1575
      End
      Begin VB.TextBox txt_prod_code 
         Height          =   285
         Left            =   2040
         Locked          =   -1  'True
         TabIndex        =   8
         Top             =   960
         Width           =   1935
      End
      Begin VB.CommandButton Command6 
         Caption         =   "Browse Product"
         Height          =   255
         Left            =   4080
         TabIndex        =   7
         Top             =   960
         Width           =   1575
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Customer No"
         Height          =   195
         Left            =   240
         TabIndex        =   19
         Top             =   240
         Width           =   915
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Supplier No"
         Height          =   195
         Left            =   240
         TabIndex        =   18
         Top             =   600
         Width           =   825
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Product Code"
         Height          =   195
         Left            =   240
         TabIndex        =   17
         Top             =   960
         Width           =   975
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Quantity"
         Height          =   195
         Left            =   1680
         TabIndex        =   16
         Top             =   1680
         Width           =   585
      End
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Order"
      Enabled         =   0   'False
      Height          =   1095
      Left            =   5760
      TabIndex        =   4
      Top             =   4560
      Width           =   1455
   End
   Begin VB.TextBox txt_date 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0C0FF&
      BorderStyle     =   0  'None
      Height          =   285
      Left            =   5640
      TabIndex        =   3
      Top             =   120
      Width           =   2175
   End
   Begin MSAdodcLib.Adodc d1 
      Height          =   375
      Left            =   7800
      Top             =   1920
      Width           =   1815
      _ExtentX        =   3201
      _ExtentY        =   661
      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    =   "container"
      Caption         =   "d1"
      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_order_no 
      BackColor       =   &H00FFFF80&
      Height          =   285
      Left            =   1080
      Locked          =   -1  'True
      TabIndex        =   1
      Top             =   120
      Width           =   1455
   End
   Begin MSDataGridLib.DataGrid dg 
      Bindings        =   "order.frx":0000
      Height          =   2415
      Left            =   240
      TabIndex        =   5
      Top             =   3720
      Width           =   5280
      _ExtentX        =   9313
      _ExtentY        =   4260
      _Version        =   393216
      AllowUpdate     =   0   'False
      BackColor       =   12640511
      ColumnHeaders   =   -1  'True
      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     =   3
      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       =   "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 Column02 
         DataField       =   "qty"
         Caption         =   "qty"
         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     =   1739.906
         EndProperty
         BeginProperty Column01 
            ColumnWidth     =   1739.906
         EndProperty
         BeginProperty Column02 
            ColumnWidth     =   1140.095
         EndProperty
      EndProperty
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      BackColor       =   &H00C0C0FF&
      Caption         =   "Date"
      Height          =   195
      Left            =   5160
      TabIndex        =   2
      Top             =   120
      Width           =   345
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackColor       =   &H00C0C0FF&
      Caption         =   "Order No."
      Height          =   195
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   690
   End
End
Attribute VB_Name = "order1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()

'Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset


rs1.Open "select * from orders where order_no='" & Trim(txt_order_no.Text) & "'", con, adOpenStatic, adLockOptimistic
If rs1.EOF <> True Then
    MsgBox "order already exists"
    rs1.Close
    Exit Sub
End If
rs1.Close

rs1.Open "select * from order_details where order_no='" & Trim(txt_order_no.Text) & "' and prod_code='" & Trim(txt_prod_code.Text) & "'", con, adOpenStatic, adLockOptimistic

If rs1.EOF <> True Then
    MsgBox "order already exists"
    rs1.Close
    Exit Sub
End If
rs1.Close





If txt_cust_no.Text = "" Or txt_order_no.Text = "" Or txt_sup_no.Text = "" Or txt_prod_code.Text = "" Or txt_qty.Text = "" Then
    MsgBox "Fields Empty"
    
    Exit Sub
End If


Dim rs As New ADODB.Recordset

rs.Open "select * from product where prod_code='" & Trim(txt_prod_code.Text) & "'", con, adOpenStatic, adLockOptimistic
If rs!prod_qty < Int(txt_qty.Text) Then
       MsgBox "this quantity is not present in stock"
       'Exit Sub
End If
'd1.RecordSource = "select * from container where order_no='" & Trim(txt_order_no.Text) & "'"
With d1.Recordset
   .AddNew
       !order_no = txt_order_no.Text
       !prod_code = txt_prod_code.Text
       !item_price = rs!item_price
       !qty = txt_qty.Text
       
    .update
d1.Refresh
End With
rs.Close
Command2.Enabled = True
End Sub

Private Sub Command2_Click()
If MsgBox("Do you really want to sell the product?", vbQuestion + vbYesNo) = vbYes Then



Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset

Dim sum As Integer
''''''''''''''
rs1.Open "select * from order_details where order_no='" & Trim(txt_order_no.Text) & "' and prod_code='" & Trim(txt_prod_code.Text) & "'", con, adOpenStatic, adLockOptimistic

If rs1.EOF <> True Then
    MsgBox "order already exists"
    rs1.Close
    Exit Sub
End If
rs1.Close
'''''''''''''''''
rs1.Open "select * from orders", con, adOpenStatic, adLockOptimistic
rs.Open "select * from order_details", con, adOpenStatic, adLockOptimistic

''======================================
Dim pmt
Dim a

rs2.Open "select * from payements order by payement_no", con, adOpenStatic, adLockOptimistic

If rs2.EOF Then
pmt = "M-1"
Else
rs2.MoveLast
a = rs2!payement_no
pmt = "M-" & Int(Mid(a, 3)) + 1
End If

'=======================================


    With d1
        .Refresh
         If .Recordset.RecordCount <> 0 Then
        .Recordset.MoveLast
        rec_count = .Recordset.RecordCount
        .Recordset.MoveFirst
                    
         rs1.AddNew
         rs1!order_no = txt_order_no.Text
         rs1!order_date = txt_date.Text
         rs1!cust_no = txt_cust_no.Text
         rs1!status = "Pending"
         rs1!sup_id = txt_sup_no.Text
         rs1.update
         

         sum = 0
         .Recordset.MoveFirst
        For i = 1 To rec_count
        '.Refresh
        
            rs.AddNew
           rs!order_no = txt_order_no.Text
            rs!prod_code = .Recordset.Fields("prod_code")
            rs!item_price = .Recordset.Fields("item_price")
            rs!quantity = .Recordset.Fields("qty")
            sum = sum + CInt(.Recordset.Fields("item_price"))
            rs.update
            
            .Recordset.MoveNext
        Next
        Dim z
         rs2.AddNew
         rs2!payement_no = pmt
         rs2!order_no = txt_order_no.Text
         rs2!status = "pending"
   
         rs2!cust_no = Trim(txt_cust_no.Text)
         rs2!amount_paid = sum
         rs2.update
        Else
        MsgBox "Sorry, but there is no product in your list to be sold.", vbCritical, "No product to purchase"
        End If
    End With



delete_aLL_In_Container
txt_cust_no.Text = ""
txt_order_no.Text = ""
txt_sup_no.Text = ""
txt_prod_code.Text = ""
txt_qty.Text = ""
Command2.Enabled = False
End If
rs.Close
rs1.Close
rs2.Close
End Sub

Private Sub Command3_Click()
txt_cust_no.Text = ""
txt_order_no.Text = ""
txt_sup_no.Text = ""
txt_prod_code.Text = ""
txt_qty.Text = ""

End Sub

Private Sub Command4_Click()
order.Enabled = False
cust.Show
End Sub

Private Sub Command5_Click()
order.Enabled = False
sup.Show
End Sub

Private Sub Command6_Click()
order.Enabled = False
prod.Show
End Sub

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

rs2.Open "select * from orders order by order_no", con, adOpenStatic, adLockOptimistic

If rs2.EOF Then
x = "O-1"
Else
rs2.MoveLast
a = rs2!order_no
x = "O-" & Int(Mid(a, 3)) + 1
End If
txt_order_no.Text = x
rs2.Close
'con.Close
End Sub

Private Sub Form_Load()
Dim rec_count As Integer

con.Open "DSN=sega"

'd1.RecordSource = "select * from container"

'delete_aLL_In_Container
txt_date.Text = CDate(Format(Now, "mm/dd/yyyy"))






'rs.Open "select * from product_category where prod_cat_code =" & Val(txt_cat_code.Text), con, adOpenStatic, adLockOptimistic

End Sub

Private Sub Form_Unload(Cancel As Integer)
delete_aLL_In_Container
Unload Me
mainform.Enabled = True
con.Close
End Sub
Private Sub delete_aLL_In_Container()
With d1
    .Refresh
    If .Recordset.RecordCount <> 0 Then
        .Recordset.MoveLast
        rec_count = .Recordset.RecordCount
       
        .Recordset.MoveFirst
        For i = 1 To rec_count
       ' While .Recordset.EOF <> True
            .Refresh
            .Recordset.MoveFirst
            .Recordset.Delete
            .Recordset.MoveNext
       ' Wend
       Next
    End If
    .Refresh
End With
End Sub

