You are on page 1of 6

Public Sub calc() Try Dim qty, cst_Wt, weight, polish, rate, Lrate, totAmt As String Dim TotalAmt,

Fweight, Amt, LAmt As Decimal qty = "" cst_Wt = "" weight = "" polish = "" rate = "" Lrate = "" totAmt = "" TotalAmt = 0 Fweight = 0 Amt = 0 LAmt = 0 If DataGridView1.Rows.Count > 1 Then If UCase(DataGridView1.CurrentRow.Cells("ItemType").Value) = UCa se("Metal") And UCase(DataGridView1.CurrentRow.Cells("ConvertTo").Value) = UCase ("Metal") Then DataGridView1.CurrentRow.Cells("Amt").ReadOnly = True DataGridView1.CurrentRow.Cells("Labour").ReadOnly = True DataGridView1.CurrentRow.Cells("LAmt").ReadOnly = True DataGridView1.CurrentRow.Cells("LRate").ReadOnly = True DataGridView1.CurrentRow.Cells("TotalAmt").ReadOnly = True DataGridView1.CurrentRow.Cells("Amt").Value = "0" DataGridView1.CurrentRow.Cells("Labour").Value = "" DataGridView1.CurrentRow.Cells("LAmt").Value = "0" DataGridView1.CurrentRow.Cells("LAmt").Value = "0" Else DataGridView1.CurrentRow.Cells("Amt").ReadOnly = False DataGridView1.CurrentRow.Cells("Labour").ReadOnly = False DataGridView1.CurrentRow.Cells("LAmt").ReadOnly = False DataGridView1.CurrentRow.Cells("LRate").ReadOnly = False DataGridView1.CurrentRow.Cells("TotalAmt").ReadOnly = False End If qty = DataGridView1.CurrentRow.Cells("Quantity").Value cst_Wt = DataGridView1.CurrentRow.Cells("CstWt").Value weight = DataGridView1.CurrentRow.Cells("Weight").Value polish = DataGridView1.CurrentRow.Cells("polish").Value rate = DataGridView1.CurrentRow.Cells("Rate").Value Lrate = DataGridView1.CurrentRow.Cells("LRate").Value If qty Is Nothing Or qty = "" Then qty = 1 End If If rate Is Nothing Or rate = "" Then rate = 0 End If

If cst_Wt Is Nothing Or cst_Wt = "" Then cst_Wt = 1 End If If weight Is Nothing Or weight = "" Then weight = 0 End If If polish Is Nothing Or polish = "" Then polish = 0 End If If Lrate Is Nothing Or Lrate = "" Then Lrate = 0 End If '----------------- Start Fweight-----------------------------------------------------------------------------------Fweight = CDec(weight) + ((CDec(weight) * CDec(polish)) / 100) DataGridView1.CurrentRow.Cells("FWeight").Value = Fweight '----------------- end Fweight-----------------------------------------------------------------------------------'----------------- Start CstType-----------------------------------------------------------------------------------If UCase(DataGridView1.CurrentRow.Cells("ItemType").Value.ToStri ng) = UCase("Metal") And UCase(DataGridView1.CurrentRow.Cells("ConvertTo").Value .ToString) = UCase("Amt") Then If Not DataGridView1.CurrentRow.Cells("CstType").Value Is No thing Then If UCase(DataGridView1.CurrentRow.Cells("CstType").Value .ToString) = UCase("KT") Then DataGridView1.CurrentRow.Cells("Amt").Value = Math.R ound((Math.Round((cst_Wt / 24), 2) * rate) * Fweight) ElseIf UCase(DataGridView1.CurrentRow.Cells("CstType").V alue.ToString) = UCase("KT KDM") Then DataGridView1.CurrentRow.Cells("Amt").Value = Math.R ound((rate * Fweight)) ElseIf UCase(DataGridView1.CurrentRow.Cells("CstType").V alue.ToString) = UCase("TUNCH") Then DataGridView1.CurrentRow.Cells("Amt").Value = Math.R ound((Math.Round((cst_Wt / 100), 2) * rate) * Fweight) End If Else DataGridView1.CurrentRow.Cells("Amt").Value = Math.Round ((rate) * Fweight) End If ElseIf UCase(DataGridView1.CurrentRow.Cells("ItemType").Value.To String) = UCase("Cash") Then DataGridView1.CurrentRow.Cells("TotalAmt").Value = DataGridV iew1.CurrentRow.Cells("Amt").Value Else

If txtOpGoldBal.Text.Trim = "" Then txtOpGoldBal.Text = 0 If txtOpSilverBal.Text.Trim = "" Then txtOpSilverBal.Text = 0 txtCloGoldBal.Text = txtOpGoldBal.Text txtCloSilverBal.Text = txtOpSilverBal.Text End If '----------------- end CstType-----------------------------------------------------------------------------------'----------------- Start Labour-----------------------------------------------------------------------------------If Not DataGridView1.CurrentRow.Cells("Labour").Value Is Nothing Then If UCase(DataGridView1.CurrentRow.Cells("Labour").Value.ToSt ring) = UCase("Net Wt.") Then DataGridView1.CurrentRow.Cells("LAmt").Value = Lrate * F weight ElseIf UCase(DataGridView1.CurrentRow.Cells("Labour").Value. ToString) = UCase("No Pcs.") Then DataGridView1.CurrentRow.Cells("LAmt").Value = Lrate * q ty Else DataGridView1.CurrentRow.Cells("LAmt").Value = 0 End If Else DataGridView1.CurrentRow.Cells("LAmt").Value = 0 End If '----------------- End Labour-----------------------------------------------------------------------------------If UCase(DataGridView1.CurrentRow.Cells("ItemType").Value) = UCa se("Metal") And UCase(DataGridView1.CurrentRow.Cells("ConvertTo").Value) = UCase ("Metal") Then DataGridView1.CurrentRow.Cells("TotalAmt").Value = "0" Else DataGridView1.CurrentRow.Cells("TotalAmt").Value = Math.Roun d(CDec(DataGridView1.CurrentRow.Cells("LAmt").Value) + CDec(DataGridView1.Curren tRow.Cells("Amt").Value)) End If Dim ConvValue, Type As String ConvValue = "" Type = "" Dim goldBal, silverBal, cashBal, billingAmt As Decimal If txtOpGoldBal.Text.Trim = "" Then txtOpGoldBal.Text = 0 If txtOpSilverBal.Text.Trim = "" Then txtOpSilverBal.Text = 0 If txtOpCashBal.Text.Trim = "" Then txtOpCashBal.Text = 0

goldBal = txtOpGoldBal.Text silverBal = txtOpSilverBal.Text cashBal = txtOpCashBal.Text billingAmt = 0 For i As Integer = 0 To DataGridView1.Rows.Count - 2

'/////////////////////////////////////

If Not DataGridView1.Rows(i).Cells("TransType").Value Is Not hing Then If DataGridView1.Rows(i).Cells("Type").Value Is Nothing Then Type = "GOLD" Else Type = UCase(DataGridView1.Rows(i).Cells("Type").Val ue) End If If DataGridView1.Rows(i).Cells("ConvertTo").Value Is Not hing Then ConvValue = "AMT" Else ConvValue = UCase(DataGridView1.Rows(i).Cells("Conve rtTo").Value) End If If UCase(DataGridView1.Rows(i).Cells("TransType").Value. ToString) = "ISSUE" Then If Type = "GOLD" And ConvValue = "METAL" Then goldBal = goldBal + CDec(DataGridView1.Rows(i).C ells("FWeight").Value) ElseIf Type = "SILVER" And ConvValue = "METAL" Then silverBal = silverBal + CDec(DataGridView1.Rows( i).Cells("FWeight").Value) ElseIf ConvValue = "AMT" Then cashBal = cashBal + CDec(DataGridView1.Rows(i).C ells("TotalAmt").Value) billingAmt = billingAmt + CDec(DataGridView1.Row s(i).Cells("TotalAmt").Value) End If Else If Type = "GOLD" And ConvValue = "METAL" Then goldBal = goldBal - CDec(DataGridView1.Rows(i).C ells("FWeight").Value) ElseIf Type = "SILVER" And ConvValue = "METAL" Then silverBal = silverBal - CDec(DataGridView1.Rows( i).Cells("FWeight").Value) ElseIf ConvValue = "AMT" Then cashBal = cashBal - CDec(DataGridView1.Rows(i).C ells("TotalAmt").Value) billingAmt = billingAmt - CDec(DataGridView1.Row s(i).Cells("TotalAmt").Value) End If End If Else End If txtCloGoldBal.Text = goldBal txtCloSilverBal.Text = silverBal txtCloCashBal.Text = cashBal

txtMaterialValue.Text = billingAmt '///////////////////////////////////// 'totAmt = DataGridView1.Rows(i).Cells("TotalAmt").Value 'If totAmt Is Nothing Then ' totAmt = 0 'End If 'TotalAmt = TotalAmt + CDec(totAmt) TotalAmt = CDec(billingAmt) Next ''////////////////////////////////////////// If txtMaterialValue.Text.Trim = "" Then txtMaterialValue.Text = 0 End If If txtVatCostPercent.Text.Trim = "" Then txtVatCostPercent.Text = 0 End If txtVatCostAmt.Text = CDec(txtMaterialValue.Text.Trim) * CDec(txt VatCostPercent.Text.Trim) * 0.01

If txtdiscountpercent.Text.Trim = "" Then txtdiscountpercent.Text = 0 End If txtDiscAmount.Text = CDec(txtMaterialValue.Text.Trim) * CDec(txt discountpercent.Text.Trim) * 0.01

If Txtgrandtotal.Text.Trim = "" Then Txtgrandtotal.Text = 0 End If If txtCashDisc.Text.Trim = "" Then txtCashDisc.Text = 0 End If If txtOpCashBal.Text.Trim = "" Then txtOpCashBal.Text = 0 ''/////////////////////////// Txtgrandtotal.Text = TotalAmt Txtgrandtotal.Text = (CDec(Txtgrandtotal.Text) + CDec(txtVatCost Amt.Text)) - CDec(txtDiscAmount.Text) Txtroundedofftotal.Text = Math.Round(CDbl(Txtgrandtotal.Text), 0 ) Txtroundoff.Text = CDec(Txtgrandtotal.Text) - CDec(Txtroundedoff total.Text) Dim finalamt As Decimal = 0 If txtPaidAmt.Text.Trim = "" Then txtPaidAmt.Text = 0 End If txtCloCashBal.Text = CDec(txtOpCashBal.Text) + (CDec(Txtroundedo fftotal.Text) - CDec(txtPaidAmt.Text)) - CDbl(txtCashDisc.Text)

End If Catch ex As Exception End Try End Sub

You might also like