You are on page 1of 53

PETROL PUMP MANAGEMENT SYSTEM SOURCE CODE The project contains 8 forms to start with first open Microsoft

VB 6.0 and select a standard exe then add the 8 forms then add an ADO control to the project to link the database to the project. The database is created using MS ACCESS. Now each forms with the screen shot and the code is listed below

A picture box is added to the form to embed a picture to the project First form has 2 buttons

2 text boxes 3 labels 1 picture box The form is drawn as shown above and the following code is written to the command buttons and to the form Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset) End Sub Private Sub Command1_Click() cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT paswd,usnme FROM log ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then For i = 0 To .RecordCount - 1 If Text1.Text = !usnme Then

If Text2.Text = !paswd Then Form4.Show Form1.Hide Else MsgBox "Wrong Password.", vbCritical, "Authentication Error" Text2.Text = "" Text2.SetFocus End If Else MsgBox "Incorrect UserName.", vbCritical, "Authentication Error" Text1.Text = "" Text1.SetFocus .MoveNext End If Next i End If .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

End Sub Private Sub Command2_Click() Form8.Show End Sub Private Sub Data1_Validate(Action As Integer, Save As Integer) End Sub Private Sub Form_Unload(Cancel As Integer) End End Sub Private Sub Picture1_Click() End Sub

So from the figure form 1 is the log in page of the project. Next page is the front page of the project it is drawn as shown below

FORM 2(MENU):

Code for the second form Private Sub Command1_Click() Form5.Show End Sub Private Sub Command2_Click() Form4.Hide Form3.Show

End Sub Private Sub Command3_Click() Form7.Show Form4.Hide End Sub Private Sub Form_Unload(Cancel As Integer) End End Sub On clicking the inventory management button form 5 will appear which is as follows

This form contains two options so the command to be written under the two buttons are Private Sub Command1_Click() If Form3.Text1.Text = "" Or Form3.Text2.Text = "" Or Form3.Text3.Text = "" Or Form3.Text4.Text = "" Or Form3.Text5.Text = "" Or Form3.Text6.Text = "" Or Form3.Text7.Text = "" Or Form3.Text8.Text = "" Then MsgBox "Create Employee Details First", vbExclamation, " Error" Form3.Show Form5.Hide Form4.Hide Else Form2.Show Form5.Hide Form4.Hide End If End Sub Private Sub Command2_Click() If Form3.Text1.Text = "" Or Form3.Text2.Text = "" Or Form3.Text3.Text = "" Or Form3.Text4.Text = "" Or Form3.Text5.Text = "" Or Form3.Text6.Text = "" Or Form3.Text7.Text = "" Or Form3.Text8.Text = "" Then MsgBox "Create Employee Details First", vbExclamation, " Error" Form3.Show

Form5.Hide Form4.Hide Else Form6.Show Form5.Hide Form4.Hide End If End Sub Private Sub Form_Unload(Cancel As Integer) End End Sub

SALES FORM

CODE Dim a As Long Private Sub Command1_Click() ab = 0 cd = 0 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro", cn, adOpenDynamic, adLockOptimistic n = .RecordCount

.Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic

ab = ab + Val(!pur1) cd = cd + Val(!sal1) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i

If ab < cd Then MsgBox "There Is Not Enough Oil , Please Purchase", vbExclamation, "Sorry" Else cn.Open GetConnection cn.BeginTrans If ab = 0 Then MsgBox "Purchase petrolium first", vbExclamation, "Error 1025" Form6.Show Form2.Hide Else cn.Execute "INSERT INTO petro VALUES('" & Null & "','" & Text2.Text & "','" & Null & "','" & Text1.Text & "','" & Text3.Text & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Form3.Text1.Text &

"','" & Null & "','" & Null & "','" & Null & "','" & Form3.Text2.Text & "','" & Form3.Text4.Text & "','" & Form3.Text6.Text & "','" & Form3.Text8.Text & "','" & Text17.Text & "','" & Text18.Text & "','" & Text18.Text & "')" Text1.Text = "" Text2.Text = "" Text3.Text = "" Text1.SetFocus End If cn.CommitTrans cn.Close: Set cn = Nothing

ab = 0 cd = 0 For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic

ab = ab + Val(!pur1) cd = cd + Val(!sal1) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i End If

cn.Open GetConnection a=1 With rs .CursorLocation = adUseClient

.Open "SELECT inde FROM petro ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then For i = 0 To .RecordCount - 1 If a < !inde Then a = !inde End If .MoveNext

Next i End If .Close: Set rs = Nothing End With cn.Close: Set cn = Nothing Text18.Text = a + 1 Text15.Text = ab - cd End Sub Private Sub Command2_Click() ab = 0 cd = 0 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro", cn, adOpenDynamic, adLockOptimistic n = .RecordCount

.Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur1) cd = cd + Val(!sal1) .Close: Set rs = Nothing cn.Close: Set cn = Nothing

End With Next i

If ab < cd Then MsgBox "There Is Not Enough Oil , Please Purchase", vbExclamation, "Sorry" Else If ab = 0 Then MsgBox "Purchase petrolium first", vbExclamation, "Error 1025" Form6.Show Form2.Hide Else cn.Open GetConnection cn.BeginTrans cn.Execute "INSERT INTO petro VALUES('" & Null & "','" & Text5.Text & "','" & Null & "','" & Text4.Text & "','" & Text6.Text & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Form3.Text3.Text & "','" & Null & "','" & Null & "','" & Form3.Text2.Text & "','" & Form3.Text4.Text & "','" & Form3.Text6.Text & "','" & Form3.Text8.Text & "','" & Text17.Text & "','" & Text18.Text & "','" & Text18.Text & "')" Text4.Text = "" Text5.Text = ""

Text6.Text = "" Text4.SetFocus End If cn.CommitTrans cn.Close: Set cn = Nothing ab = 0 cd = 0 For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur1) cd = cd + Val(!sal1) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

Next i End If

cn.Open GetConnection a=1 With rs .CursorLocation = adUseClient

.Open "SELECT inde FROM petro ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then For i = 0 To .RecordCount - 1 If a < !inde Then a = !inde End If .MoveNext Next i

End If .Close: Set rs = Nothing End With cn.Close: Set cn = Nothing Text18.Text = a + 1 Text15.Text = ab - cd End Sub Private Sub Command3_Click() ab = 0 cd = 0 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro", cn, adOpenDynamic, adLockOptimistic n = .RecordCount

.Close: Set rs = Nothing

cn.Close: Set cn = Nothing End With

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur2) cd = cd + Val(!sal2) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i

If ab < cd Then

MsgBox "There Is Not Enough Oil , Please Purchase", vbExclamation, "Sorry" Else If ab = 0 Then MsgBox "Purchase petrolium first", vbExclamation, "Error 1025" Form6.Show Form2.Hide Else

cn.Open GetConnection cn.BeginTrans cn.Execute "INSERT INTO petro VALUES('" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Text11.Text & "','" & Null & "','" & Text10.Text & "','" & Text12.Text & "','" & Null & "','" & Null & "','" & Form3.Text5.Text & "','" & Null & "','" & Form3.Text2.Text & "','" & Form3.Text4.Text & "','" & Form3.Text6.Text & "','" & Form3.Text8.Text & "','" & Text17.Text & "','" & Text18.Text & "','" & Text18.Text & "')" Text10.Text = "" Text11.Text = "" Text12.Text = "" Text10.SetFocus

End If cn.CommitTrans cn.Close: Set cn = Nothing

ab = 0 cd = 0

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur2) cd = cd + Val(!sal2) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

Next i End If

cn.Open GetConnection a=1 With rs .CursorLocation = adUseClient

.Open "SELECT inde FROM petro ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then For i = 0 To .RecordCount - 1 If a < !inde Then a = !inde End If .MoveNext Next i

End If .Close: Set rs = Nothing End With cn.Close: Set cn = Nothing Text18.Text = a + 1 Text14.Text = ab - cd End Sub Private Sub Command4_Click() ab = 0 cd = 0 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro", cn, adOpenDynamic, adLockOptimistic n = .RecordCount

.Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur2) cd = cd + Val(!sal2) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i

If ab < cd Then MsgBox "There Is Not Enough Oil , Please Purchase", vbExclamation, "Sorry" Else If ab = 0 Then MsgBox "Purchase petrolium first", vbExclamation, "Error 1025" Form6.Show Form2.Hide Else

cn.Open GetConnection cn.BeginTrans cn.Execute "INSERT INTO petro VALUES('" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Text8.Text & "','" & Null & "','" & Text7.Text & "','" & Text9.Text & "','" & Null & "','" & Null & "','" & Null & "','" & Form3.Text7.Text & "','" & Form3.Text2.Text & "','" & Form3.Text4.Text & "','" & Form3.Text6.Text & "','" & Form3.Text8.Text & "','" & Text17.Text & "','" & Text18.Text & "','" & Text18.Text & "')" Text7.Text = "" Text8.Text = "" Text9.Text = "" Text7.SetFocus End If

cn.CommitTrans cn.Close: Set cn = Nothing ab = 0 cd = 0

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur2) cd = cd + Val(!sal2) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i End If

cn.Open GetConnection a=1 With rs .CursorLocation = adUseClient

.Open "SELECT inde FROM petro ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then For i = 0 To .RecordCount - 1 If a < !inde Then a = !inde End If .MoveNext Next i End If .Close: Set rs = Nothing End With cn.Close: Set cn = Nothing

Text18.Text = a + 1 Text14.Text = ab - cd End Sub Private Sub Command5_Click() Form4.Show Form2.Hide End Sub Private Sub Form_Activate() ab = 0 cd = 0 ef = 0 gh = 0 cn.Open GetConnection a=1 With rs .CursorLocation = adUseClient

.Open "SELECT inde FROM petro ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then

For i = 0 To .RecordCount - 1 If a < !inde Then a = !inde End If .MoveNext Next i End If .Close: Set rs = Nothing End With cn.Close: Set cn = Nothing Text18.Text = a + 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient

.Open "SELECT * FROM petro ", cn, adOpenDynamic, adLockOptimistic n = .RecordCount .Close: Set rs = Nothing

cn.Close: Set cn = Nothing End With

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur1) cd = cd + Val(!sal1) ef = ef + Val(!pur2) gh = gh + Val(!sal2) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i Text15.Text = ab - cd Text14.Text = ef - gh End Sub

Private Sub Form_Unload(Cancel As Integer) End End Sub Private Sub Label18_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) ab = 0 cd = 0 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro", cn, adOpenDynamic, adLockOptimistic n = .RecordCount

.Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur2) cd = cd + Val(!sal2) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i Text14.Text = ab - cd End Sub Private Sub Label19_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

ab = 0 cd = 0 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro", cn, adOpenDynamic, adLockOptimistic n = .RecordCount

.Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

For i = 2 To n - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic ab = ab + Val(!pur1) cd = cd + Val(!sal1) .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i Text15.Text = ab - cd End Sub Private Sub Option1_Click() Text3.Visible = False Label3.Visible = False End Sub Private Sub Option10_Click() Text12.Visible = False Label13.Visible = False End Sub

Private Sub Option11_Click() Text12.Visible = True Label13.Visible = True End Sub Private Sub Option12_Click() Text12.Visible = True Label13.Visible = True End Sub Private Sub Option2_Click() Text3.Visible = True Label3.Visible = True End Sub Private Sub Option3_Click() Text3.Visible = True Label3.Visible = True End Sub Private Sub Option4_Click() Text6.Visible = False Label7.Visible = False End Sub

Private Sub Option5_Click() Text6.Visible = True Label7.Visible = True End Sub Private Sub Option6_Click() Text6.Visible = True Label7.Visible = True End Sub Private Sub Option7_Click() Text9.Visible = False Label10.Visible = False End Sub Private Sub Option8_Click() Text9.Visible = True Label10.Visible = True End Sub Private Sub Option9_Click() Text9.Visible = True Label10.Visible = True End Sub EMPLOYEE ASSIGNMENT FORM

CODE Private Sub Command1_Click() cn.Open GetConnection cn.BeginTrans cn.Execute "UPDATE petro SET e1='" & Text1.Text & "',e2='" & Text3.Text & "',e3='" & Text5.Text & "',e4='" & Text7.Text & "',a1='" & Text2.Text & "',a2='" & Text4.Text & "',a3='" & Text6.Text & "',a4='" & Text8.Text & "' WHERE inde=1"

Text1.SetFocus cn.CommitTrans cn.Close: Set cn = Nothing End Sub Private Sub Command2_Click() Form3.Hide Form4.Show End Sub Private Sub Form_Activate() abc = 0 cn.Open GetConnection With rs .CursorLocation = adUseClient

.Open "SELECT * FROM petro WHERE inde=1", cn, adOpenDynamic, adLockOptimistic Text1.Text = !e1 Text2.Text = !a1 Text3.Text = !e2 Text4.Text = !a2 Text5.Text = !e3 Text6.Text = !a3

Text7.Text = !e4 Text8.Text = !a4 .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With End Sub Private Sub Form_Unload(Cancel As Integer) End End Sub

PURCHASE FORM

CODE Private Sub Command1_Click() cn.Open GetConnection cn.BeginTrans cn.Execute "INSERT INTO petro VALUES('" & Text2.Text & "','" & Null & "','" & Text3.Text & "','" & Null & "','" & Null & "','" & Text5.Text & "','" & Null & "','" & Text6.Text & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Null & "','" & Text1.Text & "','" & Text7.Text & "','" & Text7.Text & "')"

Text2.Text = "" Text3.Text = "" Text5.Text = "" Text6.Text = "" Text2.SetFocus cn.CommitTrans cn.Close: Set cn = Nothing cn.Open GetConnection

With rs .CursorLocation = adUseClient

.Open "SELECT * FROM petro ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then For i = 0 To .RecordCount - 1 Text7.Text = !inde + 1 .MoveNext Next i End If .Close: Set rs = Nothing

End With cn.Close: Set cn = Nothing End Sub Private Sub Command2_Click() Form4.Show Form6.Hide End Sub Private Sub Form_Activate() cn.Open GetConnection

With rs .CursorLocation = adUseClient

.Open "SELECT * FROM petro ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then

For i = 0 To .RecordCount - 1 If a < !inde Then a = !inde End If

.MoveNext Next i End If .Close: Set rs = Nothing End With cn.Close: Set cn = Nothing Text7.Text = a + 1 End Sub Private Sub Form_Unload(Cancel As Integer) End End Sub

FORM 7(REPORTS)

CODE

Dim i As Long Private Sub Command1_Click() Form4.Show Form7.Hide End Sub Private Sub Command2_Click() Form7.PrintForm End Sub

Private Sub Form_Activate() g=0 h=0 p=0 q=0 Print Tab(100); "SALES" Print Tab(50); "PETROL"; Tab(150); "DIESEL" Print "EMPLOYEE1"; Tab(20); "LITRE"; Tab(40); "AMOUNT"; Tab(60); "DATE"; Tab(80); "EMPLOYEE2"; Tab(100); "EMPLOYEE1"; Tab(120); "LITRE"; Tab(140); "AMOUNT"; Tab(160); "DATE"; Tab(180); "EMPLOYEE2" cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro ", cn, adOpenDynamic, adLockOptimistic

a = .RecordCount

.Close: Set rs = Nothing cn.Close: Set cn = Nothing End With For i = 2 To a - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient .Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic

Print !e1; Tab(20); !sal1; Tab(40); !amt12; Tab(60); !dat; Tab(80); ! e2; Tab(100); !e3; Tab(120); !sal2; Tab(140); !amt22; Tab(160); !dat; Tab(180); !e4

g = g + Val(!pur1) h = h + Val(!pur2) p = p + Val(!sal1) q = q + Val(!sal2) .Close: Set rs = Nothing

cn.Close: Set cn = Nothing End With Next i Text1.Text = g - p Text2.Text = h - q

Print Tab(100); "PURCHASE" Print Tab(50); "PETROL"; Tab(150); "DIESEL" Print "AMOUNT"; Tab(35); "LITRE"; Tab(70); "DATE"; Tab(105); "AMOUNT"; Tab(140); "LITRE"; Tab(175); "DATE" cn.Open GetConnection

With rs

.CursorLocation = adUseClient .Open "SELECT * FROM petro ", cn, adOpenDynamic, adLockOptimistic

a = .RecordCount

.Close: Set rs = Nothing cn.Close: Set cn = Nothing End With For i = 2 To a - 1 cn.Open GetConnection

With rs .CursorLocation = adUseClient

.Open "SELECT * FROM petro WHERE ind = '" & i & " ' ", cn, adOpenDynamic, adLockOptimistic Print !amt11; Tab(35); !pur1; Tab(70); !dat; Tab(105); !amt21; Tab(140); !pur2; Tab(175); !dat .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With Next i End Sub Private Sub Form_Unload(Cancel As Integer) End

End Sub

FORM 8( CREATE NEW USER NAME AND PASSWORD)

CODE Private Sub Command1_Click() cn.Open GetConnection

With rs .CursorLocation = adUseClient

.Open "SELECT paswd FROM log ", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then For i = 0 To .RecordCount - 1 If Text2.Text = !paswd Then If Text3.Text = Text4.Text Then cn.BeginTrans cn.Execute "DELETE FROM log WHERE paswd='" & Text2.Text & "'" cn.Execute "INSERT INTO log VALUES('" & Text4.Text & "','" & Text1.Text & "')" cn.CommitTrans Form1.Hide Form8.Hide Form4.Show Else .MoveNext MsgBox "Type Mismatch,", vbCritical, "Authentication Error" Text3.Text = "" Text4.Text = "" Text3.SetFocus End If Else

MsgBox "Password Incorrect,", vbCritical, "Authentication Error" Text2.Text = "" Text2.SetFocus End If Next i End If .Close: Set rs = Nothing cn.Close: Set cn = Nothing End With

End Sub After drawing all these forms and writing the code make a test run of the software by the play button at the top side menu bar of the Visual Basic. Now if all is correct we have to make it as a package so that it can be run on any computer which doesnt have a pre installed visual basic software. So for binding the code and all supporting files and to make it installable on WINDOWS from the file menu click make file name.exe

You might also like