jessicaaguilardigitalportfolio.files.wordpress.com  · web viewcreated analytics table for sawyers...

17
Jessica Aguilar Assignment 6 MIS 325 – Summer Term 8/05/2018 Sample of program:

Upload: others

Post on 12-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

Jessica AguilarAssignment 6MIS 325 – Summer Term8/05/2018

Sample of program:

Page 2: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

Added features:

Created logo for Sons of Troy Created analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit

Karston had delivered significantly more lumber (by a looooong shot) and so it would take many many deliveries from the other sawyers to even get .01 in the ratio field.

Created an analytics table for Truckers looking at their pay and weight ratios. This information from both analytics table is useful because it helps to see how much different sawyers and truckers are bringing in of lumber and how much we are paying out to them. Emit is getting 57% of the pay ratio, but he is also delivered the most.

Removed the step (streamlined process) for the guy updating the invoices to automatically show if a trucker is VIP or not. If person updating the invoice forgets to check the VIP box, the guy doesn’t get paid his extra 1%. This prevents those errors from happening and ensures correct pay every time.

Added commentary so person inputting invoice can see comments on the trucker so they have a better idea who they are dealing with.

Page 3: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

Imports System.DataImports System.Data.SqlClient

Public Class JessicaAguilar___Assignment6 Inherits System.Web.UI.Page

Public Shared con As New SqlConnection("Data Source=cb-ot-devst03.ad.wsu.edu;Initial Catalog=featherman_analytics;Persist Security Info=True;User ID=mfstudent;Password=BIanalyst")

Public Shared totalvalue As Decimal

Public Shared sawyerspay As Decimal Public Shared truckerspay As Decimal Public Shared invadd As Integer

Public Shared dtSawyers As New DataTable Public Shared dtTruckers As New DataTable Public Shared dtLumberPrices As New DataTable Public Shared dtTest As New DataTable

Public Shared dtInvoice As New DataTable Public Shared dtSawyers2 As New DataTable Public Shared dtTruckers2 As New DataTable Public Shared dtsawyeranalytics As New DataTable Public Shared dttruckersanalytics As New DataTable

Public Shared dtVIP As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Private Sub JessicaAguilar___Assignment6_Init(sender As Object, e As EventArgs) Handles Me.Init

'creating variables

Dim daSawyers As New SqlDataAdapter("SELECT * FROM featherman.Sawyers", con) Dim daTruckers As New SqlDataAdapter("SELECT * FROM featherman.Truckers", con) Dim daLumber As New SqlDataAdapter("SELECT * FROM featherman.SvensonsLumberPrices", con)

'error checking

If dtSawyers.Rows.Count > 0 Then Exit Sub

'creating images for the header

imgSvenson.ImageUrl = "Svenson Logo.jpg" imgLumber.ImageUrl = "LumberMill.PNG"

'page maintain feature Page.MaintainScrollPositionOnPostBack = True

Page 4: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

'add date and time under the header lblDate.Text = Now.ToLongDateString & " - " & Now.ToLongTimeString

Try 'the data adapters are here running their SQL Select statements (in red text) and copying the data from the database to the in-memory webpage data structure.

daSawyers.Fill(dtSawyers) daTruckers.Fill(dtTruckers) daLumber.Fill(dtLumberPrices)

'load the retrieved data into gridview controls so it can be displayed. Show the tables of data on the webpage. For the assignment you do not need to show these datatables, until they are updated. 'GridView1.DataSource = dtSawyers 'GridView2.DataSource = dtTruckers

'GridView1.DataBind() 'GridView2.DataBind()

'This next code is very important. Once you have the data loaded into the datatables (here dtSawyers, dtTruckers, dtLumberPrices), then you can connect(bind) the list control to columns in those datatables, so you can display data in the list controls. You can also designate the column that will provide the values. Even if you create the tables yourself and load the rows of data yourself in code, you can use this next code to load the list controls.

With ddlsawyers .DataSource = dtSawyers .DataTextField = "SawyerName" .DataBind() End With

With ddltruckers .DataSource = dtTruckers .DataTextField = "TruckerName" .DataBind() End With

With ddllumbertypes .DataSource = dtLumberPrices .DataTextField = "LumberType" .DataValueField = "PricePerTon" .DataBind() End With 'catch any errors and show them at the top of the screen Catch ex As Exception Response.Write(ex.Message) Exit Sub End Try

'setting up to have columns and data in Invoice and Payments Table If dtInvoice.Columns.Count = 0 Then

'error checking If dtInvoice.Columns.Count > 0 Then

Page 5: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

dtInvoice.Columns.Clear()

End If

'adding colums to Invoice and Payments Table dtInvoice.Columns.Add("Invoice#", Type.GetType("System.Int32")) dtInvoice.Columns.Add("DeliveryDate", Type.GetType("System.String")) dtInvoice.Columns.Add("TruckerName", Type.GetType("System.String")) dtInvoice.Columns.Add("VIP", Type.GetType("System.String")) dtInvoice.Columns.Add("TruckerPayment", Type.GetType("System.Decimal")) dtInvoice.Columns.Add("SawyerName", Type.GetType("System.String")) dtInvoice.Columns.Add("SawyerPayment", Type.GetType("System.Decimal")) dtInvoice.Columns.Add("LumberType", Type.GetType("System.String")) dtInvoice.Columns.Add("TotalTonsDelivered", Type.GetType("System.Int32")) dtInvoice.Columns.Add("TotalAmount", Type.GetType("System.Decimal"))

'adding an auto numbering feature to the Invoice and Payments Table in the Invoice# column With dtInvoice.Columns("Invoice#") .AutoIncrement = True .AutoIncrementSeed = 1 .AutoIncrementStep = 1 End With

End If

'adding columns to the Sawyers Table If dtSawyers2.Columns.Count = 0 Then

'error checking If dtSawyers2.Columns.Count > 0 Then dtSawyers2.Columns.Clear() End If

With dtSawyers2.Columns .Add("SawyerID", GetType(Integer)) .Add("SawyerName", GetType(String)) .Add("Phone", GetType(Integer)) .Add("Remarks", GetType(String)) .Add("LastDelivery", GetType(String)) .Add("NumberDeliveries", GetType(Integer)) .Add("TotalPayouts", GetType(Decimal)) .Add("TotalTonsDelivered", GetType(Integer))

End With

'adding autoincrement to Sawyers Table With dtSawyers2.Columns("SawyerID") .AutoIncrement = True .AutoIncrementSeed = 1 .AutoIncrementStep = 1

End With

End If

Page 6: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

'adding a table to do analytics for sawyers If dtsawyeranalytics.Columns.Count = 0 Then

'error checking If dtsawyeranalytics.Columns.Count > 0 Then dtsawyeranalytics.Columns.Clear() End If

'adding columns With dtsawyeranalytics.Columns

.Add("SawyerName", GetType(String)) .Add("PayRatio", GetType(Decimal)) .Add("WeightRatio", GetType(Decimal))

End With

End If'adding columns to the Truckers Table If dtTruckers2.Columns.Count = 0 Then

'error checking If dtTruckers2.Columns.Count > 0 Then dtTruckers2.Columns.Clear() End If

With dtTruckers2.Columns .Add("TruckerID", GetType(Integer)) .Add("TruckerName", GetType(String)) .Add("VIP", GetType(String)) .Add("Phone", GetType(Integer)) .Add("Remarks", GetType(String)) .Add("LastDelivery", GetType(String)) .Add("NumberDeliveries", GetType(Integer)) .Add("TotalPayments", GetType(Decimal)) .Add("TotalTonsDelivered", GetType(Integer))

End With

'adding autoincrement for Truckers Table With dtTruckers2.Columns("TruckerID") .AutoIncrement = True .AutoIncrementSeed = 1 .AutoIncrementStep = 1 End With

End If

'adding table to do analytics on truckers If dttruckersanalytics.Columns.Count = 0 Then

'error checking If dttruckersanalytics.Columns.Count > 0 Then dttruckersanalytics.Columns.Clear() End If

Page 7: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

'adding columns to table With dttruckersanalytics.Columns

.Add("TruckerName", GetType(String)) .Add("PayRatio", GetType(Decimal)) .Add("WeightRatio", GetType(Decimal))

End With

End If

End Sub

Protected Sub ddllumbertypes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddllumbertypes.SelectedIndexChanged

Select Case ddllumbertypes.SelectedIndex Case 0 imgwood.ImageUrl = "PineWood.jpg" Case 1 imgwood.ImageUrl = "CedarWood.jpg" Case 2 imgwood.ImageUrl = "LodgePoleWood.jpg" Case 3 imgwood.ImageUrl = "TamarackWood.jpg"

End Select

lblwoodprice.Text = ddllumbertypes.SelectedItem.Value

End Sub

Protected Sub ddlsawyers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlsawyers.SelectedIndexChanged

End Sub

Protected Sub ddltruckers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddltruckers.SelectedIndexChanged

'setting up variables Dim remarks, trucker As String

trucker = ddltruckers.SelectedItem.Text

'setting up images based on ddl selection Select Case ddltruckers.SelectedIndex Case 0 imgtrucker.ImageUrl = "JBL.jpg" dtVIP = "VIP Status" remarks = "JBL is reliable." Case 1 imgtrucker.ImageUrl = "RawDawg.jpg" dtVIP = "not VIP" remarks = "Low rates, but unreliable on Mondays." Case 2 imgtrucker.ImageUrl = "SonsofTroy.PNG" dtVIP = "VIP Status"

Page 8: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

remarks = "High quality, but expensive."

End Select

tbTruckers.Text = "Delivering today is " & trucker & " who is " & dtVIP & "." & vbNewLine & vbNewLine & remarks

End Sub

Protected Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click

'setting up variables Dim woodton As Integer Dim woodcost As Decimal

'error checking

If IsNumeric(tbLumberWeight.Text) = False Then tbLumberWeight.Text = "Use Numbers Only" Exit Sub End If

woodton = tbLumberWeight.Text woodcost = ddllumbertypes.SelectedItem.Value

'setting up total values of lumber by ton totalvalue = (woodcost * woodton)

lbLumberTotalValue.Text = totalvalue

'setting up pay structures sawyerspay = totalvalue * 0.7

'setting up pay for VIP's and non-VIP's Select Case dtVIP Case "VIP Status" truckerspay = totalvalue * 0.31 Case "not VIP" truckerspay = totalvalue * 0.3

End Select

'setting up lable 2 and 3 to display what is to be paid to the sawyer and the trucker Label2.Text = sawyerspay.ToString("C2") Label3.Text = truckerspay.ToString("C2")

invadd += 1

End Sub

Protected Sub btnInvoice_Click(sender As Object, e As EventArgs) Handles btnInvoice.Click

Dim dr As DataRow = dtInvoice.NewRow

'adds rows to the Invoice and Payments table

Page 9: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

dr("DeliveryDate") = Now.ToLongDateString dr("TruckerName") = ddltruckers.SelectedItem.Text dr("VIP") = dtVIP dr("TruckerPayment") = truckerspay dr("SawyerName") = ddlsawyers.SelectedItem.Text dr("SawyerPayment") = sawyerspay dr("LumberType") = ddllumbertypes.SelectedItem.Text dr("TotalTonsDelivered") = tbLumberWeight.Text dr("TotalAmount") = totalvalue

dtInvoice.Rows.Add(dr)

'Setting up the gridview 4 to display details from dtInvoice With GridView4 .DataSource = dtInvoice .DataBind() Visible = True End With

'adding rows to columns on dtSawyers2 dtSawyers2.Rows.Clear()

'creating variables Dim sfilter As String Dim li As ListItem

'starting a loop to add information to the rows For Each li In ddlsawyers.Items Dim sdr As DataRow = dtSawyers2.NewRow

'defining the filter to sort through datatables to get Sawyer's name sfilter = "(SawyerName) = " & "'" & li.Text & "'"

sdr("SawyerName") = li.Text

Dim phonenumbers As Integer Dim remarks As String Dim Ddate As String Dim NumDel As Integer Dim totalpayouts As Decimal Dim totaltonsdel As Integer

'setting up cases for the rows Select Case sdr("SawyerName") Case "Tom Sawyer" phonenumbers = 2085967878 remarks = "Pulling Pine from Tekoa" Ddate = "7/1/2018 12:00:00 AM" NumDel = 15 totalpayouts = 75000.0 totaltonsdel = 8500

Case "Shandy Anderson" phonenumbers = 2085960909 remarks = "Tamarack Specialist" Ddate = "6/15/2018 12:00:00 AM" NumDel = 72 totalpayouts = 472000.0

Page 10: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

totaltonsdel = 25000

Case "Emit Karston" phonenumbers = 2093012188 remarks = "Old Timer" Ddate = "6/18/2018 12:00:00 AM" NumDel = 167 totalpayouts = 726000.0 totaltonsdel = 75000000

End Select

'setting up the data that will be put in the rows sdr("Phone") = phonenumbers sdr("Remarks") = remarks

If IsDBNull(dtInvoice.Compute("Sum(TotalAmount)", sfilter)) = True Then sdr("LastDelivery") = Ddate sdr("NumberDeliveries") = NumDel sdr("TotalPayouts") = totalpayouts sdr("TotalTonsDelivered") = totaltonsdel

Else

'add new values to the old values sdr("LastDelivery") = lblDate.Text sdr("NumberDeliveries") = NumDel + invadd sdr("TotalPayouts") = totalpayouts + (Label2.Text) sdr("TotalTonsDelivered") = totaltonsdel + tbLumberWeight.Text

End If

dtSawyers2.Rows.Add(sdr)

Next

With GridView5 .DataSource = dtSawyers2 .DataBind() Visible = True

End With

'clears out rows so it will update dtsawyeranalytics.Rows.Clear()

'variables to calculate total weight and payout as well as to filter data Dim totalweight2 As Decimal Dim payouts2 As Decimal Dim filter2 As String

'summing the total column in weight delievered and total payouts totalweight2 = Convert.ToDecimal(dtSawyers2.Compute("Sum(TotalTonsDelivered)", Nothing)) payouts2 = Convert.ToDecimal(dtSawyers2.Compute("Sum(TotalPayouts)", Nothing))

Page 11: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

'variable for list items Dim li3 As ListItem

'loop For Each li3 In ddlsawyers.Items

'variable to declair rows are being added Dim dr3 As DataRow = dtsawyeranalytics.NewRow

'defining filter filter2 = "SawyerName = " & "'" & li3.Text & "'"

'first column in the analytics PK dr3("SawyerName") = li3.Text

'variables for weight and pay Dim payouts3 As Decimal Dim weight3 As Decimal

'taking the filtered columns for weight and pay payouts3 = Convert.ToDecimal(dtSawyers2.Compute("Sum(TotalPayouts)", filter2)) weight3 = Convert.ToDecimal(dtSawyers2.Compute("Sum(TotalTonsDelivered)", filter2))

'makes sure there is a value in the row for the analytics Select Case dtSawyers2.Compute("Count(TotalPayouts)", filter2) Case 0 Case > 0

'takes filtered value and divides it by the total value for payouts and weight dr3("PayRatio") = FormatNumber(payouts3 / payouts2) dr3("WeightRatio") = FormatNumber(weight3 / totalweight2)

End Select

'comfirms we can add the rows for dr3 dtsawyeranalytics.Rows.Add(dr3)

Next

'assigns code to gridview7 With GridView7 .DataSource = dtsawyeranalytics .DataBind() Visible = True End With

'error checking dtTruckers2.Rows.Clear()

'creating a filter Dim tfilter As String

Dim li2 As ListItem

'creating a loop

Page 12: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

For Each li2 In ddltruckers.Items

Dim tdr As DataRow = dtTruckers2.NewRow

tfilter = "TruckerName = " & "'" & li2.Text & "'"

tdr("TruckerName") = li2.Text

Dim VIP2 As String Dim Phone2 As Integer Dim Remarks2 As String Dim LastDelivery2 As String Dim NumberDeliveries2 As Integer Dim TotalPayments2 As Decimal Dim TotalTonsDelivered2 As IntegerSelect Case tdr("TruckerName") Case "JBL Truckers" VIP2 = "VIP" Phone2 = "2085963333" Remarks2 = "JBL is reliable" LastDelivery2 = "7/1/2018 12:00:00 AM" NumberDeliveries2 = 27 TotalPayments2 = 140000 TotalTonsDelivered2 = 25000

Case "Raw Dawg Haulers" VIP2 = "Not VIP" Phone2 = 2085962323 Remarks2 = "Low rates but unreliable on Mondays" LastDelivery2 = "6/15/2018 12:00:00 AM" NumberDeliveries2 = 16 TotalPayments2 = 89000 TotalTonsDelivered2 = 14500

Case "Sons of Troy" VIP2 = "VIP" Phone2 = 2085961111 Remarks2 = "High Quality but expensive" LastDelivery2 = "7/5/2018 12:00:00 AM" NumberDeliveries2 = 42 TotalPayments2 = 250000 TotalTonsDelivered2 = 427000000

End Select

'these don't get updated and are kept as-is tdr("VIP") = VIP2 tdr("Phone") = Phone2 tdr("Remarks") = Remarks2

If IsDBNull(dtInvoice.Compute("Sum(TruckerPayment)", tfilter)) = True Then

tdr("LastDelivery") = LastDelivery2 tdr("NumberDeliveries") = NumberDeliveries2 tdr("TotalPayments") = TotalPayments2 tdr("TotalTonsDelivered") = TotalTonsDelivered2

Page 13: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

Else

tdr("LastDelivery") = lblDate.Text tdr("TotalPayments") = TotalPayments2 + (dtInvoice.Compute("Sum(TruckerPayment)", tfilter)) tdr("NumberDeliveries") = NumberDeliveries2 + invadd tdr("TotalTonsDelivered") = TotalTonsDelivered2 + tbLumberWeight.Text

End If

dtTruckers2.Rows.Add(tdr)

Next

With GridView6 .DataSource = dtTruckers2 .DataBind() Visible = True End With

'clears out rows so we are updating instead of adding dttruckersanalytics.Rows.Clear()

'variables for weight and pay as well as variable Dim totalweight4 As Decimal Dim payouts4 As Decimal Dim filter4 As String

'calculating total weight and payout in the column totalweight4 = Convert.ToDecimal(dtTruckers2.Compute("Sum(TotalTonsDelivered)", Nothing)) payouts4 = Convert.ToDecimal(dtTruckers2.Compute("Sum(TotalPayments)", Nothing))

'variable to start a loop Dim li4 As ListItem

'loop For Each li4 In ddltruckers.Items

'variable to add rows Dim dr4 As DataRow = dttruckersanalytics.NewRow

'defining the filter filter4 = "TruckerName = " & "'" & li4.Text & "'"

'organizing the PK by trucker name dr4("TruckerName") = li4.Text

'variables for pay and weight Dim payouts5 As Decimal Dim weight4 As Decimal

'filtered pay and weight from the total payments and weights columns payouts5 = Convert.ToDecimal(dtTruckers2.Compute("Sum(TotalPayments)", filter4))

Page 14: jessicaaguilardigitalportfolio.files.wordpress.com  · Web viewCreated analytics table for Sawyers looing at Pay Ratios and Weight Ratios. Obviously Emit Karston had delivered significantly

weight4 = Convert.ToDecimal(dtTruckers2.Compute("Sum(TotalTonsDelivered)", filter4))

'analyze data and complete analytics Select Case dtTruckers2.Compute("Count(TotalPayments)", filter4) Case 0 Case > 0

'dividing the filtered value by the total value dr4("PayRatio") = FormatNumber(payouts5 / payouts4) dr4("WeightRatio") = FormatNumber(weight4 / totalweight4)

End Select

'confirms you can add the rows dttruckersanalytics.Rows.Add(dr4)

Next

'assigns code to gridview8 With GridView8 .DataSource = dttruckersanalytics .DataBind() Visible = True End With

End Sub

End Class