I was hoping to ask you a question about a formatted alert message. I'm currently working on a project where a user makes a bunch of selections from dropdownlists (vehicle year, make, model, mobility device manufacturer, mobility device and mobility device lift) which will be inserted into a sql table as a single record. These selections are for a vehicle compatibility database. In order to eliminate duplicate entries, upon the user clicking the submit button, the code behind is querying the table to ensure the same configuration does not exist. If it does, I want to create an alert message in a red font so it stands out to the user that the configuration already exist. If it does not exist, I still need the alert message but in black font.
Now, I already create the alerts which are highlighted below in yellow, it's the font/color change which I can't figure out how to make it work.
Would you by any chance happen to have any suggestions I could use to make this work?
I greatly appreciate any suggestions you can offer.
Below is my current code. The web page is vb.net 4.0
Thanks
Matt Evans
Protected Sub Yes_Click(sender As Object, e As EventArgs) Handles Yes.Click
If DropDownList1.Text = "" Or DropDownList2.Text = "" Or DropDownList3.Text = "" Or ListBox1.SelectedIndex = -1 Or DropDownList6.Text = "" Or DropDownList7.Text = "" Then
Response.Write("<script>alert('FIELD VALIDATION FAILURE - MAKE SURE THE FOLLOWING FIELDS HAVE VALUES\n\n - Year\n - Make\n - Model\n - Pride Lift\n - Mobility Device Manufacturer\n - Mobility Device');</script>")
Else
For Each listitem As ListItem In ListBox1.Items
If listitem.Selected Then
Dim myConnection1 As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServicesVeh_Comp_Db_Proj").ConnectionString)
Dim DBCmd1 As New SqlCommand
Dim DBAdap1 As New SqlDataAdapter
Dim DS1 As New DataSet
DBCmd1.CommandTimeout = 45
myConnection1.Open()
DBCmd1 = New SqlCommand("SELECT ID FROM VEHICLEINFO WHERE YEAR=@YEAR AND MAKE=@MAKE AND MODEL=@MODEL AND BODY=@BODY", myConnection1)
DBCmd1.Parameters.Add("@year", SqlDbType.Float).Value = DropDownList1.Text
DBCmd1.Parameters.Add("@make", SqlDbType.NVarChar).Value = DropDownList2.Text
DBCmd1.Parameters.Add("@model", SqlDbType.NVarChar).Value = DropDownList3.Text
DBCmd1.Parameters.Add("@body", SqlDbType.NVarChar).Value = DropDownList4.Text
Dim dr1 As SqlDataReader = DBCmd1.ExecuteReader()
If dr1 IsNot Nothing AndAlso dr1.HasRows = True Then
While dr1.Read()
Veh_Id.Value = dr1("ID").ToString()
'Label34.Text = dr1("ID").ToString()
End While
dr1.Close()
myConnection1.Close()
End If
Dim myConnection3 As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServicesVeh_Comp_Db_Proj").ConnectionString)
Dim DBCmd3 As New SqlCommand
Dim DBAdap3 As New SqlDataAdapter
Dim DS3 As New DataSet
DBCmd3.CommandTimeout = 45
myConnection3.Open()
DBCmd3 = New SqlCommand("SELECT ID FROM MOBILITYDEVICEINFO WHERE MANUFACTURER=@MANUFACTURER AND MOBILITYDEVICE=@MOBILITYDEVICE", myConnection3)
DBCmd3.Parameters.Add("@MANUFACTURER", SqlDbType.NVarChar).Value = DropDownList6.Text
DBCmd3.Parameters.Add("@MOBILITYDEVICE", SqlDbType.NVarChar).Value = DropDownList7.Text
Dim dr3 As SqlDataReader = DBCmd3.ExecuteReader()
If dr3 IsNot Nothing AndAlso dr3.HasRows = True Then
While dr3.Read()
Mob_Dev_Id.Value = dr3("ID").ToString()
'Label36.Text = dr3("ID").ToString()
End While
dr3.Close()
myConnection3.Dispose()
End If
Dim myConnection2 As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServicesVeh_Comp_Db_Proj").ConnectionString)
Dim DBCmd2 As New SqlCommand
Dim DBAdap2 As New SqlDataAdapter
Dim DS2 As New DataSet
DBCmd2.CommandTimeout = 45
myConnection2.Open()
DBCmd2 = New SqlCommand("SELECT ID FROM LIFTINFO WHERE LIFT=@LIFT", myConnection2)
DBCmd2.Parameters.Add("@LIFT", SqlDbType.NVarChar).Value = listitem.Value
Dim dr2 As SqlDataReader = DBCmd2.ExecuteReader()
If dr2 IsNot Nothing AndAlso dr2.HasRows = True Then
While dr2.Read()
Lif_Id.Value = dr2("ID").ToString()
'Label35.Text = dr2("ID").ToString()
End While
dr2.Close()
myConnection2.Close()
End If
Dim myConnection4 As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServicesVeh_Comp_Db_Proj").ConnectionString)
Dim DBCmd4 As New SqlCommand
Dim DBAdap4 As New SqlDataAdapter
Dim DS4 As New DataSet
DBCmd4.CommandTimeout = 45
myConnection4.Open()
DBCmd4 = New SqlCommand("SELECT ID FROM FINAL_Veh_Lif_Mob_Dev_Comp WHERE veh_id=@veh_id AND lif_id=@lif_id AND mob_dev_id=@mob_dev_id", myConnection4)
DBCmd4.Parameters.Add("@veh_id", SqlDbType.Float).Value = Veh_Id.Value
DBCmd4.Parameters.Add("@lif_id", SqlDbType.NVarChar).Value = Lif_Id.Value
DBCmd4.Parameters.Add("@mob_dev_id", SqlDbType.NVarChar).Value = Mob_Dev_Id.Value
Dim dr4 As SqlDataReader = DBCmd4.ExecuteReader()
If dr4 IsNot Nothing AndAlso dr4.HasRows = True Then
Response.Write("<script>alert('DUPLICATE ENTRY WARNING - THE CONFIGURATION OF:\n\n * Vehicle Year - " + DropDownList1.Text + "\n * Vehicle Make - " + DropDownList2.Text + "\n * Vehicle Model - " + DropDownList3.Text + "\n * Vehical Body - " + DropDownList4.Text + "\n * Mobility Device Manufacturer - " + DropDownList6.Text + "\n * Mobility Device - " + DropDownList7.Text + "\n * Pride Lift - " + listitem.Value + "\n\n ALREADY EXISTS IN THE DATABASE.\n AND HAS NOT BEEN SUBMITTED" + "');</script>")
dr4.Close()
myConnection4.Close()
Else
Dim myConnection5 As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServicesVeh_Comp_Db_Proj").ConnectionString)
Dim DBCmd5 As New SqlCommand
Dim DBAdap5 As New SqlDataAdapter
Dim DS5 As New DataSet
DBCmd5.CommandTimeout = 45
myConnection5.Open()
Try
'Add Insert Statement
DBCmd5 = New SqlCommand("INSERT INTO [FINAL_Veh_Lif_Mob_Dev_Comp] (Veh_Id, Lif_Id, Mob_Dev_Id, Comments, Compatible, UpdatedOn, UpdatedBy) VALUES (@Veh_Id, @Lif_Id, @Mob_Dev_Id, @Comments, @Compatible, @UpdatedOn, @UpdatedBy)", myConnection5)
'Add Database Parameters
DBCmd5.Parameters.Add("@Veh_Id", SqlDbType.Float).Value = Veh_Id.Value
DBCmd5.Parameters.Add("@Lif_Id", SqlDbType.Float).Value = Lif_Id.Value
DBCmd5.Parameters.Add("@Mob_Dev_Id", SqlDbType.Float).Value = Mob_Dev_Id.Value
DBCmd5.Parameters.Add("@comments", SqlDbType.NVarChar).Value = Comments.Text
DBCmd5.Parameters.Add("@compatible", SqlDbType.VarChar).Value = "Yes"
DBCmd5.Parameters.Add("@updatedon", SqlDbType.DateTime).Value = System.DateTime.Now.ToShortDateString()
DBCmd5.Parameters.Add("@updatedby", SqlDbType.VarChar).Value = Page.User.Identity.Name
DBCmd5.ExecuteNonQuery()
Catch exp As Exception
Response.Write(exp)
End Try
DBCmd5.Dispose()
myConnection5.Close()
Response.Write("<script>alert('ENTRY SUCCESSFUL - THE CONFIGURATION OF:\n\n * Vehicle Year - " + DropDownList1.Text + "\n * Vehicle Make - " + DropDownList2.Text + "\n * Vehicle Model - " + DropDownList3.Text + "\n * Vehical Body - " + DropDownList4.Text + "\n * Mobility Device Manufacturer - " + DropDownList6.Text + "\n * Mobility Device - " + DropDownList7.Text + "\n * Pride Lift - " + listitem.Value + "\n\n HAS BEEN SUBMITTED INTO THE DATABASE" + "');</script>")
End If
End If
Next
End If
End Sub