Store code line in a string? - asp.net

I need to store code in a string so that if a value is true, it is in the code line if not true its not in the code line. When I populate summarytextbox if consulting amount is "" then dont use this code if is does have an amount include the code. Is this possible? Other wise I would have to do a bunch if then statements. When I do the following below it cant convert to double.
Dim ConsultingFee As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("ConsultingFeeAmount") = "" Then
Else
'Store the following line in a string????
ConsultingFee = +Environment.NewLine + Session("ConsultingFee") + " Amount: " + Session("ConsultingFeeAmount")
End If
SummaryTextBox.Text = Session("TeachingHospital") + Environment.NewLine + Session("HospitalAddress") + Environment.NewLine + Session("HospitalCity") + Environment.NewLine + Session("HospitalState") + Environment.NewLine + Session("HospitalZip") + Environment.NewLine + Session("HospitalTIN") + ConsultingFee
End Sub

You need to concatenate onto the ConsultingFee string variable, like this:
ConsultingFee = ConsultingFee & Environment.NewLine & Session("ConsultingFee") & " Amount: " & Session("ConsultingFeeAmount")
OR
ConsultingFee &= Environment.NewLine & Session("ConsultingFee") & " Amount: " + Session("ConsultingFeeAmount")

Related

Redline errors in ASP.NET

Below is my Code, it just was working pretty much completely and I made one wrong click and now everything entirely is redlined. Did the system.web.UI.Page malfunction? What happened and how do I fix it?
For reference this is my first coding class in college in ASP.NET. We use Visual Studio.
Code Displaying BC30652
Partial Class Assingments_HW3_VehicleConfigurator
Inherits System.Web.UI.Page
'assigned global variables
Public Shared GdecTotalCharger, gdecTotalChallenger, gdecTotalDart, gdecTotalDurango, GdecTotalViper As Decimal
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim DecCarQuote, DecCommission As Decimal
'error checking for if any of the options are not selected in a message displays
If VehicleDropDownList.SelectedIndex = 0 OrElse PackageRBL.SelectedIndex = -1 OrElse WheelsTireRBL.SelectedIndex = -1 OrElse
NavRBL.SelectedIndex = -1 OrElse AudioRBL.SelectedIndex = -1 OrElse PaintRBL.SelectedIndex = -1 OrElse
UpPaintRBL.SelectedIndex = -1 OrElse stateRBL.SelectedIndex = -1 Then
TxtOutput.Text = "Please make sure there is a selection for meach option"
Exit Sub
End If
'selecte case for each individual vehichle
'if charger or durango added then 10% reduction nadded
'other cars normal priced
'the case tals all options listed for a vehicle and adds themand sets the price for variable decCarQuote
'global variables that keep count of quotes are there
Select Case VehicleDropDownList.SelectedItem.Text
Case "Charger (Promotion Deal)"
DecCarQuote = (VehicleDropDownList.SelectedValue + PackageRBL.SelectedValue + WheelsTireRBL.SelectedValue +
NavRBL.SelectedValue + AudioRBL.SelectedValue + UpPaintRBL.SelectedValue + PaintRBL.SelectedValue) * 0.9
GdecTotalCharger += 1
Case "Challenger (Promotion Deal) "
DecCarQuote = (VehicleDropDownList.SelectedValue + PackageRBL.SelectedValue + WheelsTireRBL.SelectedValue +
NavRBL.SelectedValue + AudioRBL.SelectedValue + UpPaintRBL.SelectedValue + PaintRBL.SelectedValue) * 0.9
Case "Dart"
DecCarQuote = (VehicleDropDownList.SelectedValue + PackageRBL.SelectedValue + WheelsTireRBL.SelectedValue +
NavRBL.SelectedValue + AudioRBL.SelectedValue + UpPaintRBL.SelectedValue + PaintRBL.SelectedValue)
gdecTotalDart += 1
Case "Durango"
DecCarQuote = (VehicleDropDownList.SelectedValue + PackageRBL.SelectedValue + WheelsTireRBL.SelectedValue +
NavRBL.SelectedValue + AudioRBL.SelectedValue + UpPaintRBL.SelectedValue + PaintRBL.SelectedValue)
gdecTotalDurango += 1
Case "Viper"
DecCarQuote = (VehicleDropDownList.SelectedValue + PackageRBL.SelectedValue + WheelsTireRBL.SelectedValue +
NavRBL.SelectedValue + AudioRBL.SelectedValue + UpPaintRBL.SelectedValue + PaintRBL.SelectedValue)
GdecTotalViper += 1
End Select
'take the car quoute and mulitpy by commision ammount. in this case 0.1%
DecCommission = (DecCarQuote * 0.01)
' Create a VIP Checkbox for those that sell more
If VIP.Checked = True Then
DecCommission = (DecCarQuote * 0.015)
End If
'Outut to main textBox
'shows message with car quoute and seletced values
'gives total +tax
TxtOutput.Text = "Quote for Selected vehichles and Incl Accesories" & FormatCurrency(DecCarQuote * stateRBL.SelectedValue) &
vbNewLine & "Total Commision" & FormatCurrency(DecCommission) & vbNewLine &
vbNewLine & "Car Model" & VehicleDropDownList.SelectedItem.Text & vbNewLine &
"Package" & PackageRBL.SelectedItem.Text & vbNewLine &
"Wheels and Tires" & WheelsTireRBL.SelectedItem.Text & vbNewLine &
"Navigation" & NavRBL.SelectedItem.Text & vbNewLine &
"Audio System" & AudioRBL.SelectedItem.Text & vbNewLine &
"Car Color" & PaintRBL.SelectedItem.Text & vbNewLine &
"Upgraded Paint" & UpPaintRBL.SelectedItem.Text
'Manager Running Totals
'fpr each vehichle
TxtRunningTotal.Text = "TotalQuotes" & vbNewLine &
"Charger" & GdecTotalCharger & vbNewLine &
"Challenger" & gdecTotalChallenger & vbNewLine &
"Dart" & gdecTotalDart & vbNewLine &
"Durango" & gdecTotalDurango & vbNewLine &
"Viper" & GdecTotalViper
End Sub
End Class

my code is as shown and i get this error "The remaining text does not appear to be part of the formula">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
reportdoc1.Load(Server.MapPath("~\RepVoucherchq.rpt"))
CrystalReportViewer1.ReportSource = reportdoc1
ConnectionInfo()
Dim user_brno As String = CType(Session("userBrn"), String)
Dim date_from As String = CType(Session("date_from"), String)
Dim date_to As String = CType(Session("date_to"), String)
reportdoc1.RecordSelectionFormula = "{VEWVoucherchq.vocdate} between '" + date_from + "' and '" + date_to + "' and {VEWVoucherchq.chqbrNo} = " + user_brno
CrystalReportViewer1.RefreshReport()
End Sub
I don't have Visual Studio on this computer to test this completely, but I think your syntax is off in your Record Selection Formula.
Try this instead:
reportdoc1.RecordSelectionFormula = "{VEWVoucherchq.vocdate} in '" + date_from + "' to '" + date_to + "' and {VEWVoucherchq.chqbrNo} = " + user_brno
The between/and syntax you used isn't supported in Crystal Reports for evaluating a date the way you want. The supported syntax is {eval_date} IN {start_Date} to {end_Date}.
You may also run into an issue with your date_from and date_to fields being string data types instead of the Date or DateTime datatype. If that is an issue, you will want to pass the values through a function to convert them to dates properly.
Something like this should suffice:
reportdoc1.RecordSelectionFormula = "{VEWVoucherchq.vocdate} in Date('" + date_from + "') to Date('" + date_to + "') and {VEWVoucherchq.chqbrNo} = " + user_brno
If you need DateTime instead of Date data types, replace the Date() functions with DateTime() functions.

Cannot apply indexing to an expression of type 'dtInventory_v10_r1' error in c#

I have some code in c# that was converted over from vb.net. I am getting this error on the codebehind page of an aspx page. One of the errors reads
Cannot apply indexing to an expression of type 'dtInventory_v10_r1'
the error that I am receiving from visual studio reads this however
Argument missing
The line of code that this references is as follows:
objInv = objMan.GetInventoryObject(mInventory_ID, , , true);
The GetInventoryObject is written in VB and looks like this
Public Function GetInventoryObject(ByVal vInventory_ID As Integer, _
Optional ByVal vVIN As String = "", _
Optional ByVal vSelectedTrim As String = "", _
Optional ByVal vIncludeDetail As Boolean = False, _
Optional ByVal vIncludeValuations As Boolean = False, _
Optional ByVal vIncludeEquipment As Boolean = False, _
Optional ByVal vIncludeTitle As Boolean = False, _
Optional ByVal vIncludeBuyersGuide As Boolean = False, _
Optional ByVal vIncludeImages As Boolean = False, _
Optional ByVal vIncludeFinance As Boolean = False, _
Optional ByVal vIncludeExpenses As Boolean = False, _
Optional ByVal vIncludeTransactions As Boolean = False, _
Optional ByVal vIncludeInternetMarketing As Boolean = False, _
Optional ByVal vIncludeFlags As Boolean = False, _
Optional ByVal vIncludeSupportingFiles As Boolean = False, _
Optional ByVal vYearModel As Integer = 0, _
Optional ByVal vMake As String = "", _
Optional ByVal vModel As String = "", _
Optional ByVal vBodyStyle As String = "", _
Optional ByVal vExtTrim As String = "", _
Optional ByVal vExtColor As String = "", _
Optional ByVal vIntColor As String = "", _
Optional ByVal vTransmission As String = "", _
Optional ByVal vDriveType As String = "", _
Optional ByVal vEngine As String = "", _
Optional ByVal vWeight As Integer = 0, _
Optional ByVal vFuelType As String = "", _
Optional ByVal vLot_ID As Integer = 0
) As Inventory
Dim strParameters As String = ""
Dim dsTempDataSet As DataSet
Dim strXML As String = ""
If vLot_ID = 0 Then
'if an autosave occurs and a lot is not enterd
'pass in the uses branch
vLot_ID = mobjSecurity.Branch_ID
End If
strParameters = "#SessionGUID='" & mobjSecurity.SecuritySession & "', "
strParameters &= "#Inst_ID=" & mobjSecurity.Inst_ID.ToString & ", "
strParameters += "#Inventory_ID=" & vInventory_ID.ToString & ", "
strParameters += "#VIN='" & vVIN.ToString & "', "
strParameters += "#IncludeDetail=" & mobjFormat.FormatBooleanToInteger(vIncludeDetail) & ", "
strParameters += "#IncludeValuations=" & mobjFormat.FormatBooleanToInteger(vIncludeValuations) & ", "
strParameters += "#IncludeEquipment=" & mobjFormat.FormatBooleanToInteger(vIncludeEquipment) & ","
strParameters += "#IncludeTitle=" & mobjFormat.FormatBooleanToInteger(vIncludeTitle) & ", "
strParameters += "#IncludeBuyersGuide=" & mobjFormat.FormatBooleanToInteger(vIncludeBuyersGuide) & ", "
strParameters += "#IncludeImages=" & mobjFormat.FormatBooleanToInteger(vIncludeImages) & ", "
strParameters += "#IncludeFinance=" & mobjFormat.FormatBooleanToInteger(vIncludeFinance) & ", "
strParameters += "#IncludeExpenses=" & mobjFormat.FormatBooleanToInteger(vIncludeExpenses) & ", "
strParameters += "#IncludeTransactions=" & mobjFormat.FormatBooleanToInteger(vIncludeTransactions) & ", "
strParameters += "#IncludeInternetMarketing=" & mobjFormat.FormatBooleanToInteger(vIncludeInternetMarketing) & ", "
strParameters += "#IncludeFlags=" & mobjFormat.FormatBooleanToInteger(vIncludeFlags) & ", "
strParameters += "#IncludeSupportingFiles=" & mobjFormat.FormatBooleanToInteger(vIncludeSupportingFiles) & ", "
strParameters += "#YearModel=" & vYearModel.ToString & ", "
strParameters += "#Make='" & vMake.ToString & "', "
strParameters += "#Model='" & vModel.ToString & "', "
strParameters += "#BodyStyle='" & vBodyStyle.ToString & "', "
strParameters += "#ExtTrim='" & vExtTrim.ToString & "', "
strParameters += "#ExtColor='" & vExtColor.ToString & "', "
strParameters += "#IntColor='" & vIntColor.ToString & "', "
strParameters += "#Transmission='" & vTransmission.ToString & "', "
strParameters += "#DriveType='" & vDriveType.ToString & "', "
strParameters += "#Engine='" & vEngine.ToString & "', "
strParameters += "#Weight=" & vWeight.ToString & ", "
strParameters += "#FuelType='" & vFuelType.ToString & "', "
strParameters += "#Lot_ID=" & vLot_ID.ToString & " "
dsTempDataSet = Fetch("pr_Inventory_v10_FetchObject_r1", strParameters, mobjSecurity.SQLDatabase)
Dim dsComplete As New DataSet
Dim objExport As New dtDataTools_v10_r1.ExportData
Dim iTable As Integer = 0
Dim sDataTableName As String = ""
Dim sRelatedTableName As String = ""
Dim sRelatedFieldName As String = ""
'-- Loop all returned tables
For iTable = 0 To dsTempDataSet.Tables.Count - 1
If sDataTableName = "" Then
'-- Make sure we have rows
If dsTempDataSet.Tables(iTable).Rows.Count > 0 Then
'-- Read first column...
If dsTempDataSet.Tables(iTable).Columns(0).ColumnName.ToLower = "datatablename" Then
'-- Get table info
sDataTableName = dsTempDataSet.Tables(iTable).Rows(0).Item("datatablename")
sRelatedTableName = dsTempDataSet.Tables(iTable).Rows(0).Item("RelatedTableName")
sRelatedFieldName = dsTempDataSet.Tables(iTable).Rows(0).Item("RelatedFieldName")
End If
End If
Else
'-- Name and store the table
dsTempDataSet.Tables(iTable).TableName = sDataTableName
dsComplete.Tables.Add(dsTempDataSet.Tables(iTable).Copy)
Try
'-- Add Relationship?
If sRelatedTableName.Trim <> "" Then
With dsComplete
.Relations.Add("rel_" & sDataTableName, _
.Tables(sRelatedTableName).Columns(sRelatedFieldName), _
.Tables(sDataTableName).Columns(sRelatedFieldName))
End With
End If
Catch ex As Exception
End Try
sDataTableName = "" '-- Reset
sRelatedTableName = ""
sRelatedFieldName = ""
End If
Next
'-- Generate and strip the XML
strXML = objExport.ConvertDatasetToXML(dsComplete.Copy, "dealtrace", MappingType.Attribute, 1)
'-- Load XML into Report object
Return LoadInventory_XML(strXML)
End Function
The mInventory_ID is an int variable and is declared like this
protected Int32 mInventory_ID = 0;
I am not sure how to fix the error that I am getting I have tried to change the parenthesis to square brackets to no avail. I have tried adding extra commas for the remaining declarations in the function but that also yielded the same errors.
Are there any suggestions on what may be causing this error and how to fix this
Thank you in advance
These are optional parameters, and should be called with following syntax
objInv = objMan.GetInventoryObject(vVIN=mInventory_ID, vIncludeValuations=true);
Basically you explicitly name parameters default values of which you would like to override. Skipping param with , , is indeed incorrect syntax.

sending email in from asp.net page

I want to add this to my email body and i want it to look like this but it doesnt work.
Tour: lotour.text
Date: loddate.text
Party: lolnumparty.text
first name: locfname.text
last name: loclname.text
as you see i want them right after another and it doesnt work when i use a </br>
this is my email body.
objEmail.Body = "There was a booking rquest made by " & Request.QueryString("comp") & " to see more details click the link " + x
this is my full code
If Page.IsValid And ValidateCCNumber(cardnumber.Text) = True Then
SqlDataSource1.Insert()
Dim x As String
x = "http://www.clubabc.com/bookingrequest/confirm.aspx?date=" & HttpUtility.UrlEncode(now.Text) & "&tfname=" & HttpUtility.UrlEncode(p1fname.Text) & "&tlname=" & HttpUtility.UrlEncode(p1lname.Text) & "&comp=" & HttpUtility.UrlEncode(Request.QueryString("comp") & "&land=" & HttpUtility.UrlEncode(land.Text))
Dim objEmail As New MailMessage()
objEmail.To = "cnna#BC.com"
objEmail.From = "page#bc.com"
objEmail.Cc = memail.Text
objEmail.Subject = "Booking for " + p1fname.Text + " " + p1lname.Text + " made by " & Request.QueryString("comp")
objEmail.Body = "There was a booking rquest made by " & Request.QueryString("comp") & " to see more details click the link " + x
SmtpMail.SmtpServer = "mail.bc.com"
Try
SmtpMail.Send(objEmail)
Catch exc As Exception
Response.Write("Send failure: " + exc.ToString())
End Try
Response.Redirect("http://www.clubabc.com/bookingrequest/confirm.aspx?date=" + now.Text + "&tfname=" + p1fname.Text + "&tlname=" + p1lname.Text + "&comp=" + Request.QueryString("comp") & "&land=" & HttpUtility.UrlEncode(land.Text))
ElseIf ValidateCCNumber(cardnumber.Text) = False Then
invalidcard.Visible = True
End If
I guess you are searching for (MSDN):
Environment.NewLine
The <br> tag will only work in HTML Emails.
Update
This would be a very simple example, how you could use Environment.NewLine:
Imports System
Class Sample
Public Shared Sub Main()
Dim firstName As String = "John"
Dim lastName As String = "Doe"
Dim city As String = "Brooklyn"
Console.WriteLine("First name: " + firstName + Environment.NewLine + "Last name: " + lastName + Environment.NewLine + "City: " + city + Environment.NewLine)
End Sub
End Class
Try to set IsHtml property for objEmail variable to get some more formatting possibilities.
Do not use Enviornment.NewLine, instead use vbCrLf
Environment.NewLine may only output Cr or Lf, which may cause your email to either:
a)Be blocked because it's not RFC complient
or
b)Be marked as spammy
To have new lines in email, always use CrLf.
--Dave

DataTable Filter mystery

could you please help me find the reason of the mystery I've found?
In the below code, I create a DataTable and filter it. When I use filter1, everything works as expected.
When I use filter2, everything works as expected only if the SubsectionAmount variable is less than 10.
As soon as I set SubsectionAmount=10, the dr2 array returns Nothing.
I can't find what is wrong. Here is the code:
Imports System.Data
Partial Class FilterTest
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call FilterTable()
End Sub
Sub FilterTable()
Dim dtSubsections As New DataTable
Dim SectionID As Integer, SubsectionID As Integer
Dim SubsectionAmount As Integer
Dim filter1 As String, filter2 As String
Dim rowID As Integer
Dim dr1() As DataRow, dr2() As DataRow
With dtSubsections
.Columns.Add("Section")
.Columns.Add("Subsection")
.Columns.Add("FieldString")
SectionID = 1
SubsectionAmount = 10 '9
For SubsectionID = 1 To SubsectionAmount
.Rows.Add(SectionID, SubsectionID, "abcd" & CStr(SubsectionID))
Next SubsectionID
For rowID = 0 To .Rows.Count - 1
Response.Write(.Rows(rowID).Item(0).ToString & " " _
& .Rows(rowID).Item(1).ToString & " " _
& .Rows(rowID).Item(2).ToString & "<BR>")
Next
SubsectionID = 1
filter1 = "Section=" & SectionID & " AND " & "Subsection=" & SubsectionID
filter2 = "Section=" & SectionID & " AND " & "Subsection=" & SubsectionID + 1
dr1 = .Select(filter1)
dr2 = .Select(filter2)
Response.Write(dr1.Length & "<BR>")
Response.Write(dr2.Length & "<BR>")
If dr1.Length > 0 Then
Response.Write(dr1(0).Item("FieldString").ToString & "<BR>")
End If
If dr2.Length > 0 Then
Response.Write(dr2(0).Item("FieldString").ToString & "<BR>")
End If
End With
End Sub
End Class
The line
"Section=" & SectionID & " AND " & "Subsection=" & SubsectionID + 1
looks dodgy to me (?)
Consider this snippet of code:
var i = 2;
string j = "Hello " + i + 1;
when you print j you will get "Hello21" and not "Hello3". The + operator applied on a string will accept any object on the right-hand side and uses them by calling ToString() on the object, hence making your int effectively a string. Now, I assume that in VB.Net it is quite similar, which may not be what you want.
Update
Apparently VB.Net does things differently, so happily ignore...
change your column add statements to the following so it does the comparisons correctly.
.Columns.Add("Section", GetType(Integer))
.Columns.Add("Subsection", GetType(Integer))
.Columns.Add("FieldString")

Resources