Thesis in Computerized Payroll System for Brangay Hall, Dita

5,349 views

Published on

1 Comment
2 Likes
Statistics
Notes
  • sir can you please send me the actual program. i need it for my future studies pls add me on facebook. or yahoo. malcolmgraves2016@yahoo.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
5,349
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
164
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Thesis in Computerized Payroll System for Brangay Hall, Dita

  1. 1. A Computerized Payroll System for the Barangay Dita 1.1 Background of the study HISTORY OF PAYROLL SYSTEM A computerized payroll system, the employer invests in a computerized payroll software. Using a software such as quickbooks allows the employer to enter the wages into the system after he has manually calculated them. The payroll and check printing are processed through the system. The employer has access to payroll reports that he/she can print and use to double-check against what she has entered before printing the checks. This allows his/her to correct any detectable errors beforehand. Computerized payroll system allow you to process all your normal payroll task via a computerized system, rather than by hand. Essentials like name, address, Social Security number and withholding rate for each employee are automatically filled in for every pay period until you make an employee’s record inactive. Many different vendors offer computerized payroll system. Like different word processors or other computer programs, they largely offer the same types of features with slightly different interfaces. Payroll is essentially how employees are paid. It’s the legal paperwork involved. There's more to payroll than just handing out cash or checks. However, after gathering data on what the employees did and compared it to their salaries, some simple payday mathematics will let the employer hand out the dough. 1.2 Objectives 1.2.1 General Objective The main objective of the study is to design and develop a Computerizes Payroll System for Barangay Hall, Dita that fast transactions, minimize the manual checking of employees, monitor the status of employee’s charges, deductions and generate the essential reports.A computerized payroll system must be able to keep and generate accurate reports on employee income.An equally important objective of any payroll system is to generate paychecks and pay stubs. Computerizing this task saves managers and business owners time and money; rather than reviewing time cards manually and calculating a check amount based on the hours worked, the payroll system should be designed to automatically calculate these figures.A computerized payroll system must automatically factor in the overtime pay. This helps employers stay within the law when it comes time to pay overtime. Additionally, since an employer can use the system to check the number of hours an employee works, the employer can shift schedules to avoid paying additional overtime. 1.2.2 Specific Objectives To minimize the manual checking of each daily time record.
  2. 2. To develop a module that will generate essentials reports. To develop that will monitor the status of employee’s loan and other deductions such as cash advance and charges. 1.3 Significance of the study This part of the study discusses about the importance of creating computerized Payroll System. It provides sample discussed how to run a Computerized Payroll System and here are some examples of how it run. Many employers use a timekeeping system, such as clock time, to track work hours employees '. Can separate this system regular hours from overtime hours worked. Payroll all people will do is make edits / adjustments, if necessary. If time employees are imported into the computerized Payroll system, the latter rounds up and down time employees appropriately, as the nearest quarter hour. It calculates the total hours worked and paid. It is saving the time spent manually calculating time and reduces errors. If the person enters Payroll time system itself, automatically calculates its income, based on its input. The system calculates all pay frequencies, such as weekly, biweely, and twice a month. Only people attended Payroll data which the reduction is based, such as form for withholding information federal income tax.Necessary you a manual payroll system to print paychecks on a typewriter or by hand. A computerized Payroll system has direct deposit capability, which saves money spent on live checks and reconciliation. Moreover, paycheck and pay stub generation occurs rapidly, regardless of the quantity. developing a computerized system and Prints Payroll reports . If you want to double - check before printing Payroll stubs paychecks / pay, just refer to the corresponding report. A computerized payroll system allows hard - copy printing of Payroll registers pertaining to each pay period. Also saves its information systems without boundaries .The system generates reports to ensure compliance with tax Payroll tax. This includes quarterly and annual wage reporting and development of employee forms. If a related departments such as accounting office holding Payroll taxes and reconciliation of the company, print the required reports would require the department through the computerized system. Furthermore, these days, such as vacation and personal time, taken and paid to benefit the track system . 1.4 Scope The study will covers the process of preparing the pay slip of each employee, monitors loans, cash advances, charges, keeping the records and easily computers the basic pay, regular overtime pay, pay during day off, special and legal holiday pay, gross pay, SSS contributions, PhilHealth contributions, Pag-Ibig contributions, cash advances, charges, deductions, lates, and net pay. 1.5 Delimitation The study does not cover any other not employee of the Barangay Hall,Dita.This is not a group pay slip.This system is not cover by any deduction that may not belong to the pay slip. And also the other income that not belong in Barangay Hall, Dita.
  3. 3. 1.6 Definition of Terms 1.6.1 Operational Terms Computerized Payroll System- A computerized payroll system has many prominent advantages over paper systems. They prevent clerical error in calculating hours and a gross payment. They also automatically deduct taxes based on the gross payment. Work Hours- is the period of time that an individual spends at paid occupational labor. Unpaid labors such as personal housework or caring for children/pets are not considered part of the working week. Overtime hours- is the amount of time someone works beyond normal working hours. Normal hours may be determined in several ways. Regular Hours- is usually when a store opens and closes. Total Hours- compute the number of hours you work every week counting overtime and then average these hours over a set period. Income Tax- is a government levy (tax) imposed on individuals or entities (taxpayers) that varies with the income or profits (taxable income) of the taxpayer. Details vary widely by jurisdiction. Many jurisdictions refer to income tax on business entities as companies tax or corporation tax. Deposit- account is a savings account, current account, or other type of bank account, at a banking institution that allows money to be deposited and withdrawn by the account holder. Paychecks- is traditionally a paper document (a cheque) issued by an employer to pay an employee for services rendered. In recent times, the physical paycheck has been increasingly replaced by electronic to bank accounts. Such employees may still receive a pay slip, but any attached cheque is marked as non-negotiable and cannot be cashed. Payslip- a slip of paper included with your pay that records how much money you have earned and how much tax or insurance etc. has been taken out. 1.6.2 Technical Terms Data- is a set of value of qualitative or quantitative variables; restated, dataare individual pieces of information. Data in computing or data processing are represented in a structure.Data consists of a series of facts or statements that may have been collected, stored, processed and/or manipulated but have not been organized or placed into context. When data is organized, it becomes information. Information can be processed and used to draw generalized conclusions or knowledge.
  4. 4. 1.7 Methodology Used in Developing the Software Product Data Gathering : Conducting of 5 interview, involving of 30 personnel of the Barangay Hall, Dita to understand the roles, the procedures, issues, opportunities, and challenges of payroll process. VB orVisual Basic is a Programming tool that user to develop Windows or GUI(Graphical User Interface) applications. It means that rather than writing numerous line for code to describe the appearance and location for interface elements like C, C++, or Basic. User can simply drag and drop pre-built objects into the form window on computer screen. VB is a enhanced version of BASIC programming language(NASIC is Predecessor of VB)/ The main difference is that the VB can create windows programs by just Drag & Drop where as BASIC could only create DOS programs or work only in CUI (Command User Interface) 1.8 User’s Manual PublicClass dbSelect Inherits System.Windows.Forms.Form PublicShared StartUp As dbSelect PrivateSub btnNSM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNSM.Click Dim Login AsNew Login
  5. 5. CompDB = "NSM" Login.Show() Me.Hide() EndSub PrivateSub btnPPE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPPE.Click Dim Login AsNew Login CompDB = "PPE" Login.Show() Me.Hide() EndSub PrivateSub btnSW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSW.Click Dim Login AsNew Login CompDB = "S&W" Login.Show() Me.Hide() EndSub PrivateSub btnSDOM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSDOM.Click Dim Login AsNew Login CompDB = "SDOM" Login.Show() Me.Hide() EndSub PrivateSub btnSSN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSSN.Click Dim Login AsNew Login CompDB = "SSn" Login.Show() Me.Hide() EndSub PrivateSub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Application.Exit() EndSub PrivateSub dbSelect_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Load dbSelect.StartUp = Me EndSub PrivateSub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint EndSub PrivateSub Panel3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel3.Paint EndSub EndClass
  6. 6. PublicClass Menu Inherits System.Windows.Forms.Form PrivateSub Menu_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Load SelectCase CompDB Case"NSM" Label2.Text = "Admin" Case"PPE" Label2.Text = "Lupon" Case"S&W" Label2.Text = "Barangay Health Worker" Case"SDOM" Label2.Text = "Barangay Tanod" Case"SSN" Label2.Text = "Security Aide" EndSelect EndSub PrivateSub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click Me.Close() EndSub PrivateSub btnCompProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompProfile.Click Dim Company AsNew Company Company.Show() EndSub PrivateSub btnEmployees_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmployees.Click Dim Employees AsNew Employees Employees.Show() EndSub PrivateSub btnPayroll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPayroll.Click Dim Payroll AsNew Payroll Payroll.Show() EndSub PrivateSub btnReports_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReports.Click Dim ReportDialog AsNew ReportDialog
  7. 7. ReportDialog.Show() EndSub PrivateSub btnSecurity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSecurity.Click Dim Password AsNew Password Password.Show() EndSub PrivateSub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click Dim About AsNew About About.ShowDialog() EndSub PrivateSub Menu_Closed(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Closed dbSelect.StartUp.Show() EndSub PrivateSub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint EndSub PrivateSub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click EndSub EndClass
  8. 8. PublicClass Company Inherits System.Windows.Forms.Form ProtectedOverridesFunction ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) AsBoolean SelectCase msg.WParam.ToInt32() Case 13 ' enter Key IfTypeOfMe.ActiveControl Is TextBox Then SendKeys.Send("{Tab}") ReturnTrue EndIf EndSelect ReturnMyBase.ProcessCmdKey(msg, keyData) EndFunction'ProcessCmdKey PrivateSub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() EndSub PrivateSub Company_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Load cnPayroll.ConnectionString = cnSettings() daCompany.Fill(DsPayroll) Me.BindingContext(DsPayroll, "Company").Position = 0 EndSub PrivateSub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Me.BindingContext(DsPayroll, "Company").EndCurrentEdit() daCompany.Update(DsPayroll) EndSub EndClass
  9. 9. PublicClass Employees Inherits System.Windows.Forms.Form
  10. 10. Dim oldcbDivision AsString ProtectedOverridesFunction ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) AsBoolean SelectCase msg.WParam.ToInt32() Case 13 ' enter Key IfTypeOfMe.ActiveControl Is TextBox OrTypeOfMe.ActiveControl Is ComboBox Then SendKeys.Send("{Tab}") ReturnTrue EndIf EndSelect ReturnMyBase.ProcessCmdKey(msg, keyData) EndFunction'ProcessCmdKey PrivateSub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() EndSub PrivateSub Employees_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Load cnPayroll.ConnectionString = cnSettings() daEmployees.Fill(DsPayroll) daDivision.Fill(DsPayroll) With cbStatus .Items.Add("ACTIVE") .Items.Add("RESIGNED") .Items.Add("RETIRED") EndWith With cbDivision .DataSource = DsPayroll .DisplayMember = "Division.Division" .ValueMember = "Division.DivisionID" .DataBindings.Add("Tag", DsPayroll.Tables("Employees"), "Division") .DataBindings.Add(New Binding("SelectedValue", _ DsPayroll, "Employees.Division")) EndWith With cbPayMethod .Items.Add("MONTHLY") .Items.Add("DAILY") EndWith BindEmpList() Me.BindingContext(DsPayroll, "Employees").Position = 0 AddHandlerMe.BindingContext(DsPayroll, "Employees").PositionChanged, _ AddressOf Employee_PositionChanged DisplayNav(sender, e) EndSub Sub BindEmpList() With grdEmpList .CaptionText = "Employees" .DataMember = "Employees" .DataSource = DsPayroll EndWith ' You must clear out the TableStyles collection before grdEmpList.TableStyles.Clear() Dim grdTableStyle1 AsNew DataGridTableStyle
  11. 11. With grdTableStyle1 .MappingName = "Employees" EndWith Dim grdColStyle1 AsNew DataGridTextBoxColumn With grdColStyle1 .MappingName = "AssignCode" .HeaderText = "Assign Code" .Width = 140 EndWith Dim grdColStyle2 AsNew DataGridTextBoxColumn With grdColStyle2 .MappingName = "LastName" .HeaderText = "Last Name" .Width = 140 EndWith Dim grdColStyle3 AsNew DataGridTextBoxColumn With grdColStyle3 .MappingName = "FirstName" .HeaderText = "First Name" .Width = 140 EndWith Dim grdColStyle4 AsNew DataGridTextBoxColumn With grdColStyle4 .MappingName = "MiddleName" .HeaderText = "M.I." .Width = 75 EndWith Dim grdColStyle5 AsNew DataGridTextBoxColumn With grdColStyle5 .MappingName = "Section" .HeaderText = "Section" .Width = 75 EndWith Dim grdColStyle6 AsNew DataGridTextBoxColumn With grdColStyle6 .MappingName = "DateHired" .HeaderText = "Date Hired" .Width = 75 EndWith Dim grdColStyle7 AsNew DataGridTextBoxColumn With grdColStyle7 .MappingName = "Phone" .HeaderText = "Phone" .Width = 75 EndWith Dim grdColStyle8 AsNew DataGridTextBoxColumn With grdColStyle8 .MappingName = "Status" .HeaderText = "Status" .Width = 75 EndWith grdTableStyle1.GridColumnStyles.AddRange _ (New DataGridColumnStyle() {grdColStyle1, grdColStyle2, _ grdColStyle3, grdColStyle4, grdColStyle5, _ grdColStyle6, grdColStyle7, grdColStyle8}) grdEmpList.TableStyles.Add(grdTableStyle1)
  12. 12. EndSub PrivateSub DisplayNav(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click, btnPrev.Click, btnNext.Click, btnLast.Click, btnDelete.Click 'Update record position when Update & Delete events lblNavLocation.Text = Me.BindingContext(DsPayroll, "Employees").Position + 1 &" of "&Me.BindingContext(DsPayroll, "Employees").Count EndSub PrivateSub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click Save_Record() Me.BindingContext(DsPayroll, "Employees").Position += 1 EndSub PrivateSub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click Save_Record() Me.BindingContext(DsPayroll, "Employees").Position -= 1 EndSub PrivateSub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click Save_Record() Me.BindingContext(DsPayroll, "Employees").Position = Me.BindingContext(DsPayroll, "Employees").Count - 1 EndSub PrivateSub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click Save_Record() Me.BindingContext(DsPayroll, "Employees").Position = 0 EndSub PrivateSub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If btnAdd.Text = "&Add"Then Me.BindingContext(DsPayroll, "Employees").AddNew() Else Me.BindingContext(DsPayroll, "Employees").CancelCurrentEdit() Change_Button(True) btnAdd.Text = "&Add" DisplayNav(sender, e) EndIf EndSub PrivateSub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Try If btnAdd.Text = "&Revert"Then If txtCode.Text = ""Then MessageBox.Show("Please don't leave assign code field blank.", "Error", MessageBoxButtons.OK) ExitSub EndIf EndIf Save_Record() Change_Button(True) btnAdd.Text = "&Add" DisplayNav(sender, e)
  13. 13. Catch ex As Exception MsgBox(ex.Message) EndTry EndSub PrivateSub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Try If MsgBox("Are you sure you want to delete this record?", MsgBoxStyle.YesNo) = MsgBoxResult.No ThenExitSub Me.BindingContext(DsPayroll, "Employees").RemoveAt(Me.BindingContext(DsPayroll, "Employees").Position) Save_Record() DisplayNav(sender, e) Catch ex As Exception MsgBox(ex.Message) EndTry EndSub PrivateSub Save_Record() Try Me.BindingContext(DsPayroll, "Employees").EndCurrentEdit() daEmployees.Update(DsPayroll) Catch ex As Exception MsgBox(ex.Message) EndTry EndSub PrivateSub Change_Button(ByVal bval AsBoolean) btnFirst.Enabled = bval btnPrev.Enabled = bval btnNext.Enabled = bval btnLast.Enabled = bval btnDelete.Enabled = bval btnExit.Enabled = bval EndSub PrivateSub txtDailyRate_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtDailyRate.LostFocus If IsValidTextbox(txtDailyRate) = FalseThenExitSub EndSub PrivateSub txtAllowance_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtAllowance.LostFocus If IsValidTextbox(txtAllowance) = FalseThenExitSub EndSub PrivateSub txtIncentives_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtIncentives.LostFocus If IsValidTextbox(txtIncentives) = FalseThenExitSub EndSub PrivateSub cbDivision_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDivision.SelectedIndexChanged oldcbDivision = cbDivision.Text EndSub PrivateSub cbDivision_SelectionChangeCommitted(ByVal sender AsObject, ByVal e As System.EventArgs) Handles cbDivision.SelectionChangeCommitted
  14. 14. If cbDivision.Text = "Add Division"Then Dim Division AsNew Division cbDivision.Text = oldcbDivision Division.ShowDialog() daDivision.Fill(DsPayroll) EndIf EndSub PrivateSub Employee_PositionChanged(ByVal sender AsObject, ByVal e As System.EventArgs) DisplayNav(sender, e) EndSub PrivateSub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click EndSub PrivateSub lblNavLocation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblNavLocation.Click EndSub PrivateSub Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint EndSub PrivateSub Panel3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel3.Paint EndSub PrivateSub TabData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabData.Click EndSub PrivateSub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter EndSub EndClass
  15. 15. OptionExplicitOn Imports System.Data.OleDb PublicClass Payroll Inherits System.Windows.Forms.Form Dim ACCESS_CONNECTION_STRING AsString = cnSettings() Dim strSelectedAssignCode AsString Dim dblAllowance AsDouble Dim dblIncentives AsDouble Dim intIndex AsInteger ProtectedOverridesFunction ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) AsBoolean SelectCase msg.WParam.ToInt32() Case 13 ' enter Key IfTypeOfMe.ActiveControl Is TextBox Then SendKeys.Send("{Tab}") ReturnTrue EndIf EndSelect ReturnMyBase.ProcessCmdKey(msg, keyData) EndFunction'ProcessCmdKey PrivateSub Payroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load PopulateNameList() EndSub PrivateSub PopulateNameList() Dim Connection AsNew OleDbConnection(ACCESS_CONNECTION_STRING) lvName.Items.Clear() lvName.Sorting = SortOrder.Ascending Dim cmdfill AsNew OleDbCommand("SELECT AssignCode, LastName & ', ' & FirstName & ' ' & MiddleName as Name FROM Employees", Connection) Try Connection.Open()
  16. 16. Dim datareader As OleDbDataReader datareader = cmdfill.ExecuteReader While datareader.Read Dim lvi AsNew ListViewItem lvi.Text = CStr(datareader("AssignCode")) lvi.SubItems.Add(CStr(datareader("Name"))) lvName.Items.Add(lvi) EndWhile If datareader.HasRows Then lvName.TopItem.Selected = True lvName.TopItem.Focused = True lvName.TopItem.EnsureVisible() lvName.Select() 'lvName.Items(0).Selected = True 'strSelectedAssignCode = lvName.Items(0).SubItems(0).Text lvName_SelectedIndexChanged(Nothing, Nothing) EndIf Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error") Finally Connection.Close() EndTry EndSub PrivateSub lvName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvName.SelectedIndexChanged Dim cnOleDb As OleDbConnection Dim cmSQL As OleDbCommand Dim drSQL As OleDbDataReader Dim strSQL AsString 'Dim strID As String Dim ThisItem As ListViewItem If IsNothing(lvName.FocusedItem) ThenExitSub ForEach ThisItem In lvName.SelectedItems strSelectedAssignCode = lvName.Items(ThisItem.Index).SubItems(0).Text Next 'strSelectedAssignCode = lvName.FocusedItem.Text Try strSQL = "SELECT AssignCode, "& _ "DailyRate, "& _ "Allowance, "& _ "Incentives "& _ "FROM Employees "& _ "WHERE AssignCode = '"& strSelectedAssignCode &"'" cnOleDb = New OleDbConnection(ACCESS_CONNECTION_STRING) cnOleDb.Open() cmSQL = New OleDbCommand(strSQL, cnOleDb) drSQL = cmSQL.ExecuteReader() drSQL.Read() txtDailyRate.Text = Format(Convert.ToDouble(drSQL.Item("DailyRate").ToString()), "0.00") dblAllowance = Format(Convert.ToDouble(drSQL.Item("Allowance").ToString()), "0.00") txtAllowance.Text = dblAllowance dblIncentives = Format(Convert.ToDouble(drSQL.Item("Incentives").ToString()), "0.00") txtIncentives.Text = dblIncentives
  17. 17. ' Close and Clean up objects drSQL.Close() cnOleDb.Close() cmSQL.Dispose() cnOleDb.Dispose() GetPayslip() txtTotal.Text = Format(txtWorkDays.Text * txtDailyRate.Text, "0.00") Calc_Gross() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub GetPayslip() Dim cnOleDb As OleDbConnection Dim cmSQL As OleDbCommand Dim drSQL As OleDbDataReader Dim strSQL AsString 'Dim strID As String If IsNothing(lvName.FocusedItem) ThenExitSub 'strSelectedAssignCode = lvName.FocusedItem.Text Try strSQL = "SELECT * "& _ "FROM Payroll "& _ "WHERE AssignCode = '"& strSelectedAssignCode &"' And FromPay = #"& dtpFromPay.Text &"# And ToPay = #"& dtpToPay.Text &"#" cnOleDb = New OleDbConnection(ACCESS_CONNECTION_STRING) cnOleDb.Open() cmSQL = New OleDbCommand(strSQL, cnOleDb) drSQL = cmSQL.ExecuteReader() If drSQL.HasRows Then drSQL.Read() txtWorkDays.Text = drSQL.Item("NoWorkDays").ToString() txtWorkDays.Text = Format(CDbl(txtWorkDays.Text), "0.0000") txtRegOT.Text = Format(CDbl(drSQL.Item("RegOT").ToString()), "0.0000") txtSunOT.Text = Format(CDbl(drSQL.Item("SunOT").ToString()), "0.0000") txtHolPay.Text = Format(Convert.ToDouble(drSQL.Item("HolOT").ToString()), "0.00") txtAdd1.Text = Format(Convert.ToDouble(drSQL.Item("Add1").ToString()), "0.00") txtAdd2.Text = Format(Convert.ToDouble(drSQL.Item("Add2").ToString()), "0.00") txtAdd3.Text = Format(Convert.ToDouble(drSQL.Item("Add3").ToString()), "0.00") txtAddDesc1.Text = drSQL.Item("AddDesc1").ToString() txtAddDesc2.Text = drSQL.Item("AddDesc2").ToString() txtAddDesc3.Text = drSQL.Item("AddDesc3").ToString() txtSSS.Text = Format(Convert.ToDouble(drSQL.Item("SSS_MCR").ToString()), "0.00") txtTax.Text = Format(Convert.ToDouble(drSQL.Item("WTax").ToString()), "0.00")
  18. 18. txtSSSLoan.Text = Format(Convert.ToDouble(drSQL.Item("SSS_Loans").ToString()), "0.00") txtLates.Text = Format(Convert.ToDouble(drSQL.Item("Lates").ToString()), "0.00") txtDed1.Text = Format(Convert.ToDouble(drSQL.Item("Ded1").ToString()), "0.00") txtDed2.Text = Format(Convert.ToDouble(drSQL.Item("Ded2").ToString()), "0.00") txtDed3.Text = Format(Convert.ToDouble(drSQL.Item("Ded3").ToString()), "0.00") txtDedDesc1.Text = drSQL.Item("DedDesc1").ToString() txtDedDesc2.Text = drSQL.Item("DedDesc2").ToString() txtDedDesc3.Text = drSQL.Item("DedDesc3").ToString() ' Close and Clean up objects drSQL.Close() cnOleDb.Close() cmSQL.Dispose() cnOleDb.Dispose() EndIf txtRegOTTotal.Text = Format(((txtDailyRate.Text / 8) * 1.25) * txtRegOT.Text, "0.00") txtSunOTTotal.Text = Format(((txtDailyRate.Text / 8) * 1.3) * txtSunOT.Text, "0.00") txtHolPayTotal.Text = Format(txtDailyRate.Text * txtHolPay.Text, "0.00") txtIncentives.Text = Format(txtIncentives.Text * txtWorkDays.Text, "0.00") txtAllowance.Text = Format(txtAllowance.Text * txtWorkDays.Text, "0.00") Calc_Gross() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() EndSub PrivateSub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click If strSelectedAssignCode = ""Then MsgBox("Please select employee", MsgBoxStyle.OKOnly) ExitSub EndIf If txtWorkDays.Text > 0 Then Dim ReturnValue AsString = isRecordExist() If ReturnValue = "Exist"Then If MsgBox("Payslip already exist for this employee."& vbCrLf & vbCrLf &"Do you want to overight existing record?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then UpdatePaySlip() EndIf SelectIndex() lvName_SelectedIndexChanged(sender, e) ElseIf ReturnValue <>"Error"Then AddPaySlip() SelectIndex()
  19. 19. lvName_SelectedIndexChanged(sender, e) EndIf Else MsgBox("Please enter No. of Working days.", MsgBoxStyle.OKOnly) EndIf EndSub PrivateFunction isRecordExist() AsString Dim Connection AsNew OleDbConnection(ACCESS_CONNECTION_STRING) Dim cmdfill AsNew OleDbCommand("SELECT AssignCode, FromPay, ToPay FROM Payroll Where AssignCode = '"& strSelectedAssignCode &"' And FromPay = #"& dtpFromPay.Text &"# And ToPay = #"& dtpToPay.Text &"#", Connection) Try Connection.Open() Dim datareader As OleDbDataReader datareader = cmdfill.ExecuteReader If datareader.HasRows ThenReturn"Exist" Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error") Return"Error" Finally Connection.Close() Connection.Dispose() EndTry EndFunction PrivateSub AddPaySlip() Try 'Dim dbCommand As OleDbCommand Dim DBConn As OleDbConnection Dim DBInsert AsNew OleDbCommand DBConn = New OleDbConnection(ACCESS_CONNECTION_STRING) DBInsert.CommandText = "INSERT INTO Payroll VALUES (" _ &"'"& dtpFromPay.Text &"', " _ &"'"& dtpToPay.Text &"', " _ &"'"& strSelectedAssignCode &"', " _ &"'"& txtWorkDays.Text &"', " _ &"'"& txtDailyRate.Text &"', " _ &"'"& txtTotal.Text &"', " _ &"'"& txtRegOT.Text &"', " _ &"'"& txtSunOT.Text &"', " _ &"'"& txtHolPay.Text &"', " _ &"'"& txtRegOTTotal.Text &"', " _ &"'"& txtSunOTTotal.Text &"', " _ &"'"& txtHolPayTotal.Text &"', " _ &"'"& txtAdd1.Text &"', " _ &"'"& txtAdd2.Text &"', " _ &"'"& txtAdd3.Text &"', " _ &"'"& txtAddDesc1.Text &"', " _ &"'"& txtAddDesc2.Text &"', " _ &"'"& txtAddDesc3.Text &"', " _ &"'"& txtIncentives.Text &"', " _ &"'"& txtAllowance.Text &"', " _ &"'"& txtGross.Text &"', " _ &"'"& txtSSS.Text &"', " _ &"'"& txtTax.Text &"', " _ &"'"& txtSSSLoan.Text &"', " _ &"'"& txtLates.Text &"', " _ &"'"& txtDed1.Text &"', " _
  20. 20. &"'"& txtDed2.Text &"', " _ &"'"& txtDed3.Text &"', " _ &"'"& txtDedDesc1.Text &"', " _ &"'"& txtDedDesc2.Text &"', " _ &"'"& txtDedDesc3.Text &"', " _ &"'"& txtTotalDed.Text &"', " _ &"'"& txtNetIncome.Text &"', " _ &"'"& DateTime.Now.ToString &"')" DBInsert.Connection = DBConn DBInsert.Connection.Open() DBInsert.ExecuteNonQuery() MsgBox("Payslip created successfully.", MsgBoxStyle.OKOnly) DBConn.Close() DBConn.Dispose() Catch ex As System.Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub UpdatePaySlip() Try 'Dim dbCommand As OleDbCommand Dim DBConn As OleDbConnection Dim DBUpdate AsNew OleDbCommand DBConn = New OleDbConnection(ACCESS_CONNECTION_STRING) DBUpdate.CommandText = "UPDATE Payroll SET "& _ "FromPay = #"& dtpFromPay.Text &"#, "& _ "ToPay = #"& dtpToPay.Text &"#, "& _ "AssignCode = '"& strSelectedAssignCode &"', "& _ "NoWorkDays = '"& txtWorkDays.Text &"', "& _ "Rate = '"& txtDailyRate.Text &"', "& _ "RegWage = '"& txtTotal.Text &"', "& _ "RegOT = '"& txtRegOT.Text &"', "& _ "SunOT = '"& txtSunOT.Text &"', "& _ "HolOT = '"& txtHolPay.Text &"', "& _ "RegOTTotal = '"& txtRegOTTotal.Text &"', "& _ "SunOTTotal = '"& txtSunOTTotal.Text &"', "& _ "HolOTTotal = '"& txtHolPayTotal.Text &"', "& _ "Add1 = '"& txtAdd1.Text &"', "& _ "Add2 = '"& txtAdd2.Text &"', "& _ "Add3 = '"& txtAdd3.Text &"', "& _ "AddDesc1 = '"& txtAddDesc1.Text &"', "& _ "AddDesc2 = '"& txtAddDesc2.Text &"', "& _ "AddDesc3 = '"& txtAddDesc3.Text &"', "& _ "Incentives = '"& txtIncentives.Text &"', "& _ "Allowance = '"& txtAllowance.Text &"', "& _ "GrossPay = '"& txtGross.Text &"', "& _ "SSS_MCR = '"& txtSSS.Text &"', "& _ "WTax = '"& txtTax.Text &"', "& _ "SSS_Loans = '"& txtSSSLoan.Text &"', "& _ "Lates = '"& txtLates.Text &"', "& _ "Ded1 = '"& txtDed1.Text &"', "& _ "Ded2 = '"& txtDed2.Text &"', "& _ "Ded3 = '"& txtDed3.Text &"', "& _ "DedDesc1 = '"& txtDedDesc1.Text &"', "& _ "DedDesc2 = '"& txtDedDesc2.Text &"', "& _ "DedDesc3 = '"& txtDedDesc3.Text &"', "& _ "TotalDed = '"& txtTotalDed.Text &"', "& _
  21. 21. "NetPay = '"& txtNetIncome.Text &"' "& _ "WHERE AssignCode = '"& strSelectedAssignCode &"' And "& _ "FromPay = #"& dtpFromPay.Text &"# And "& _ "ToPay = #"& dtpToPay.Text &"#" DBUpdate.Connection = DBConn DBUpdate.Connection.Open() DBUpdate.ExecuteNonQuery() MsgBox("Payslip created successfully.", MsgBoxStyle.OKOnly) DBConn.Close() DBConn.Dispose() Catch ex As System.Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub Calc_Gross() Try txtGross.Text = Convert.ToDouble(IIf(txtTotal.Text = "", "0.00", txtTotal.Text)) _ + Convert.ToDouble(IIf(txtRegOTTotal.Text = "", "0.00", txtRegOTTotal.Text)) _ + Convert.ToDouble(IIf(txtSunOTTotal.Text = "", "0.00", txtSunOTTotal.Text)) _ + Convert.ToDouble(IIf(txtHolPayTotal.Text = "", "0.00", txtHolPayTotal.Text)) _ + Convert.ToDouble(IIf(txtAllowance.Text = "", "0.00", txtAllowance.Text)) _ + Convert.ToDouble(IIf(txtIncentives.Text = "", "0.00", txtIncentives.Text)) _ + Convert.ToDouble(IIf(txtAdd1.Text = "", "0.00", txtAdd1.Text)) _ + Convert.ToDouble(IIf(txtAdd2.Text = "", "0.00", txtAdd2.Text)) _ + Convert.ToDouble(IIf(txtAdd3.Text = "", "0.00", txtAdd3.Text)) txtGross.Text = Format(CDbl(txtGross.Text), "0.00") Calc_Deductions() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub Calc_Deductions() Try txtTotalDed.Text = Convert.ToDouble(IIf(txtSSS.Text = "", "0.00", txtSSS.Text)) _ + Convert.ToDouble(IIf(txtTax.Text = "", "0.00", txtTax.Text)) _ + Convert.ToDouble(IIf(txtSSSLoan.Text = "", "0.00", txtSSSLoan.Text)) _ + Convert.ToDouble(IIf(txtLates.Text = "", "0.00", txtLates.Text)) _ + Convert.ToDouble(IIf(txtDed1.Text = "", "0.00", txtDed1.Text)) _ + Convert.ToDouble(IIf(txtDed2.Text = "", "0.00", txtDed2.Text)) _ + Convert.ToDouble(IIf(txtDed3.Text = "", "0.00", txtDed3.Text)) txtTotalDed.Text = Format(CDbl(txtTotalDed.Text), "0.00")
  22. 22. txtNetIncome.Text = Convert.ToDouble(IIf(txtGross.Text = "", "0.00", txtGross.Text) - IIf(txtTotalDed.Text = "", "0.00", txtTotalDed.Text)) txtNetIncome.Text = Format(CDbl(txtNetIncome.Text), "0.00") Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub txtWorkDays_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtWorkDays.LostFocus If IsNumeric(txtWorkDays.Text) = FalseThen MsgBox("Please enter correct information", MsgBoxStyle.OKOnly) txtWorkDays.Focus() txtWorkDays.SelectAll() ExitSub EndIf txtWorkDays.Text = Format(CDbl(txtWorkDays.Text), "0.0000") txtAllowance.Text = Format(dblAllowance * txtWorkDays.Text, "0.00") txtIncentives.Text = Format(dblIncentives * txtWorkDays.Text, "0.00") txtTotal.Text = Format(txtWorkDays.Text * txtDailyRate.Text, "0.00") Calc_Gross() EndSub PrivateSub txtRegOT_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRegOT.LostFocus If IsNumeric(txtRegOT.Text) = FalseThen MsgBox("Please enter correct information", MsgBoxStyle.OKOnly) txtRegOT.Focus() txtRegOT.SelectAll() ExitSub EndIf txtRegOT.Text = Format(CDbl(txtRegOT.Text), "0.0000") txtRegOTTotal.Text = Format(((txtDailyRate.Text / 8) * 1.25) * txtRegOT.Text, "0.00") Calc_Gross() EndSub PrivateSub txtSunOT_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSunOT.LostFocus If IsNumeric(txtSunOT.Text) = FalseThen MsgBox("Please enter correct information", MsgBoxStyle.OKOnly) txtSunOT.Focus() txtSunOT.SelectAll() ExitSub EndIf txtSunOT.Text = Format(CDbl(txtSunOT.Text), "0.0000") txtSunOTTotal.Text = Format(((txtDailyRate.Text / 8) * 1.3) * txtSunOT.Text, "0.00") Calc_Gross() EndSub PrivateSub txtHolPay_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHolPay.LostFocus If IsNumeric(txtHolPay.Text) = FalseThen MsgBox("Please enter correct information", MsgBoxStyle.OKOnly) txtHolPay.Focus() txtHolPay.SelectAll() ExitSub EndIf If IsValidTextbox(txtHolPay) = FalseThenExitSub
  23. 23. txtHolPayTotal.Text = Format(txtDailyRate.Text * txtHolPay.Text, "0.00") Calc_Gross() EndSub rivateSub txtAllowance_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtAllowance.LostFocus If IsValidTextbox(txtAllowance) = FalseThenExitSub Calc_Gross() EndSub PrivateSub txtIncentives_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtIncentives.LostFocus If IsValidTextbox(txtIncentives) = FalseThenExitSub Calc_Gross() EndSub PrivateSub txtAdd1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAdd1.LostFocus If IsValidTextbox(txtAdd1) = FalseThenExitSub Calc_Gross() EndSub PrivateSub txtAdd2_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAdd2.LostFocus If IsValidTextbox(txtAdd2) = FalseThenExitSub Calc_Gross() EndSub PrivateSub txtAdd3_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAdd3.LostFocus If IsValidTextbox(txtAdd3) = FalseThenExitSub Calc_Gross() EndSub PrivateSub txtSSS_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSSS.LostFocus If IsValidTextbox(txtSSS) = FalseThenExitSub Calc_Deductions() EndSub PrivateSub txtTax_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTax.LostFocus If IsValidTextbox(txtTax) = FalseThenExitSub Calc_Deductions() EndSub PrivateSub txtSSSLoan_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSSSLoan.LostFocus If IsValidTextbox(txtSSSLoan) = FalseThenExitSub Calc_Deductions() EndSub PrivateSub txtLates_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLates.LostFocus If IsValidTextbox(txtLates) = FalseThenExitSub Calc_Deductions() EndSub PrivateSub txtDed1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDed1.LostFocus If IsValidTextbox(txtDed1) = FalseThenExitSub Calc_Deductions() EndSub PrivateSub txtDed2_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDed2.LostFocus If IsValidTextbox(txtDed2) = FalseThenExitSub
  24. 24. Calc_Deductions() EndSub PrivateSub txtDed3_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDed3.LostFocus If IsValidTextbox(txtDed3) = FalseThenExitSub Calc_Deductions() EndSub PrivateSub SelectIndex() Dim ThisItem As ListViewItem Dim intNumRows AsInteger Try ForEach ThisItem In lvName.SelectedItems intNumRows = lvName.Items.Count If ThisItem.Index + 1 <> intNumRows Then lvName.Items(ThisItem.Index + 1).Selected = True strSelectedAssignCode = lvName.Items(ThisItem.Index + 1).SubItems(0).Text EndIf Next Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OKOnly) EndTry EndSub PrivateSub dtpFromPay_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpFromPay.ValueChanged lvName_SelectedIndexChanged(sender, e) EndSub PrivateSub dtpToPay_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpToPay.ValueChanged lvName_SelectedIndexChanged(sender, e) EndSub PrivateSub Label22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label22.Click EndSub PrivateSub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter EndSub PrivateSub GroupBox4_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox4.Enter EndSub PrivateSub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click EndSub PrivateSub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click EndSub PrivateSub Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint EndSub PrivateSub Label21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label21.Click EndSub PrivateSub txtDailyRate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDailyRate.TextChanged EndSub EndClass
  25. 25. PublicClass ReportDialog Inherits System.Windows.Forms.Form PrivateSub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.Close() EndSub PrivateSub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click Dim frmReport As Reports If optVoucher.Checked = TrueThen frmReport = New Reports(Me, "Voucher.rpt") frmReport.Show() ElseIf optPayrollSum.Checked = TrueThen frmReport = New Reports(Me, "PayrollSum.rpt") frmReport.Show() Else Dim frmListofEmpReport As ListofEmpReport frmListofEmpReport = New ListofEmpReport(Me, "EmployeesList.rpt") frmListofEmpReport.Show() EndIf EndSub PrivateSub optVoucher_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optVoucher.CheckedChanged If optVoucher.Checked = TrueThen GroupBox1.Enabled = True EndIf EndSub PrivateSub optPayrollSum_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optPayrollSum.CheckedChanged If optPayrollSum.Checked = TrueThen GroupBox1.Enabled = True EndIf EndSub PrivateSub optListofEmp_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optListofEmp.CheckedChanged If optListofEmp.Checked = TrueThen GroupBox1.Enabled = False EndIf EndSub PrivateSub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint EndSub PrivateSub Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint EndSub
  26. 26. PrivateSub ReportDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load EndSub EndClass
  27. 27. Imports System.Data.OleDb PublicClass Password Inherits System.Windows.Forms.Form Dim ACCESS_CONNECTION_STRING AsString = cnSettings() Dim strSelectedAssignCode AsString Dim strOldPassword AsString ProtectedOverridesFunction ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) AsBoolean SelectCase msg.WParam.ToInt32() Case 13 ' enter Key IfTypeOfMe.ActiveControl Is TextBox Then SendKeys.Send("{Tab}") ReturnTrue EndIf EndSelect ReturnMyBase.ProcessCmdKey(msg, keyData) EndFunction'ProcessCmdKey PrivateSub Password_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Load PopulateUser() EndSub PrivateSub PopulateUser() Dim Connection AsNew OleDbConnection(ACCESS_CONNECTION_STRING)
  28. 28. lvUserName.Items.Clear() lvUserName.Sorting = SortOrder.Ascending Dim cmdfill AsNew OleDbCommand("SELECT UserName, [Password] FROM [Password]", Connection) Try Connection.Open() Dim datareader As OleDbDataReader datareader = cmdfill.ExecuteReader While datareader.Read Dim lvi AsNew ListViewItem lvi.Text = CStr(datareader("UserName")) lvUserName.Items.Add(lvi) EndWhile If datareader.HasRows Then lvUserName.TopItem.Selected = True lvUserName.TopItem.Focused = True lvUserName.TopItem.EnsureVisible() lvUserName.Select() EndIf Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error") Finally Connection.Close() EndTry EndSub PrivateSub RetrieveUser() Dim Connection AsNew OleDbConnection(ACCESS_CONNECTION_STRING) Dim cmdfill AsNew OleDbCommand("SELECT UserName, [Password] FROM [Password] Where UserName = '"& strSelectedAssignCode &"'", Connection) Try Connection.Open() Dim datareader As OleDbDataReader datareader = cmdfill.ExecuteReader datareader.Read() txtUserName2.Text = CStr(datareader("UserName")) strOldPassword = CStr(datareader("Password")) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error") Finally Connection.Close() EndTry EndSub PrivateSub AddUser() Try 'Dim dbCommand As OleDbCommand Dim DBConn As OleDbConnection Dim DBInsert AsNew OleDbCommand DBConn = New OleDbConnection(ACCESS_CONNECTION_STRING) DBInsert.CommandText = "INSERT INTO [Password] VALUES (" _ &"'"& txtUserName1.Text &"', " _ &"'"& txtPassword1.Text &"')" Dim lvi AsNew ListViewItem lvi.Text = txtUserName1.Text lvUserName.Items.Add(lvi) clearTxtBox() DBInsert.Connection = DBConn DBInsert.Connection.Open()
  29. 29. DBInsert.ExecuteNonQuery() DBConn.Close() DBConn.Dispose() Catch ex As System.Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub UpdateUser() Try 'Dim dbCommand As OleDbCommand Dim DBConn As OleDbConnection Dim DBUpdate AsNew OleDbCommand DBConn = New OleDbConnection(ACCESS_CONNECTION_STRING) DBUpdate.CommandText = "UPDATE [Password] SET "& _ "[Password] = '"& txtPassword2.Text &"' "& _ "WHERE UserName = '"& txtUserName2.Text &"'" clearTxtBox() DBUpdate.Connection = DBConn DBUpdate.Connection.Open() DBUpdate.ExecuteNonQuery() DBConn.Close() DBConn.Dispose() Catch ex As System.Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") EndTry EndSub PrivateSub DeleteUser() Try Dim DBConn As OleDbConnection Dim dbCommand AsNew OleDbCommand 'Dim strPath As String DBConn = New OleDbConnection(cnSettings()) dbCommand.CommandText = "DELETE FROM [Password] " _ &"WHERE UserName = '"& strSelectedAssignCode &"'" dbCommand.Connection = DBConn dbCommand.Connection.Open() dbCommand.ExecuteNonQuery() lvUserName.Items.Remove(lvUserName.FocusedItem) DBConn.Close() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error") EndTry EndSub PrivateSub clearTxtBox() txtUserName1.Text = "" txtUserName2.Text = "" txtPassword1.Text = "" txtPassword2.Text = "" txtConfirmPassword1.Text = "" txtConfirmPassword2.Text = "" txtOldPassword.Text = "" EndSub PrivateSub lvUserName_MouseDown(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvUserName.MouseDown Try If IsNothing(lvUserName.FocusedItem) ThenExitSub strSelectedAssignCode = lvUserName.FocusedItem.Text
  30. 30. If e.Button = MouseButtons.Right Then If lvUserName.SelectedItems.Count > 0 Then ContextMenu1.Show(lvUserName, New Point(e.X, e.Y)) EndIf EndIf Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OKOnly) EndTry EndSub PrivateSub lvUserName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvUserName.SelectedIndexChanged Try 'If IsNothing(lvUserName.FocusedItem) Then Exit Sub Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OKOnly) EndTry EndSub PrivateSub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() EndSub PrivateSub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) grpEdit.Hide() grpAdd.Show() EndSub PrivateSub mnuAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdd.Click grpAdd.Visible = True grpEdit.Visible = False btnUpdate.Text = "&Save" EndSub PrivateSub mnuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEdit.Click grpEdit.Visible = True grpAdd.Visible = False btnUpdate.Text = "&Update" RetrieveUser() EndSub PrivateSub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click If btnUpdate.Text = "&Save"Then If txtPassword1.Text <> txtConfirmPassword1.Text Then MsgBox("Password does not match.", MsgBoxStyle.OKOnly) ExitSub EndIf AddUser() Else If txtOldPassword.Text <> strOldPassword Then MsgBox("Please enter the correct password in the Old Password field.", MsgBoxStyle.OKOnly) ExitSub EndIf If txtPassword2.Text <> txtConfirmPassword2.Text Then MsgBox("Password does not match.", MsgBoxStyle.OKOnly) ExitSub EndIf
  31. 31. UpdateUser() EndIf EndSub PrivateSub mnuDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDelete.Click If strSelectedAssignCode = "Admin"Then MsgBox("Sorry you can't delete this account.", MsgBoxStyle.OKOnly) ExitSub EndIf If MsgBox("Are you sure you want to delete this user?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then _ DeleteUser() EndSub PrivateSub Label23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label23.Click EndSub EndClass

×