Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

Removal of listbox

<asp:listbox id=ListBox1 runat="server" Height="72px" Width="90px" Font-Bold="True" ForeColor="DarkGreen" SelectionMode="Multiple"></asp:listbox></TD>



here is the class I tryied removing everything with list box but when I click add the funtion, nothing displays or get entered into the database.

Imports System
Imports System.Data
Imports System.Data.SqlClient
 
Public Class SalesTPR
    Inherits System.Web.UI.Page
 
#Region " Web Form Designer Generated Code "
 
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 
    End Sub
    'With Event Handlers posted here
    Protected WithEvents DoneButton As System.Web.UI.WebControls.Button
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    Protected WithEvents UPCCode As System.Web.UI.WebControls.TextBox
    Protected WithEvents Description As System.Web.UI.WebControls.TextBox
    Protected WithEvents Size As System.Web.UI.WebControls.TextBox
    Protected WithEvents Qty As System.Web.UI.WebControls.TextBox
    Protected WithEvents Price As System.Web.UI.WebControls.TextBox
    Protected WithEvents SizeMeasureList As System.Web.UI.WebControls.DropDownList
    Protected WithEvents WebImageButton1 As Infragistics.WebUI.WebDataInput.WebImageButton
    Protected WithEvents WebImageButton3 As Infragistics.WebUI.WebDataInput.WebImageButton
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
    Protected WithEvents cblStores As System.Web.UI.WebControls.CheckBoxList
    Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
    Protected WithEvents WebAsyncRefreshPanel1 As Infragistics.WebUI.Misc.WebAsyncRefreshPanel
    'Protected WithEvents dgParents_ItemDataBound As System.Web.UI.WebControls.CheckBoxList
 
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
 
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub
 
#End Region
    Dim strselecteditems As String = Nothing
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            RetrieveSalesTPRItems()
            SetFocus(UPCCode, Me)
            LoadSizeMeasure()
 
            With lblMessage
                lblMessage.Visible = True
                .CssClass = "labelGreen"
                .Text = "Total Pages: " & DataGrid1.PageCount.ToString
            End With
 
            Dim StoreList() As String
            Dim I As Integer = 0
 
            StoreList = Session("Stores")
 
            For I = 0 To UBound(StoreList)
                'ListBox1.Items.Add(AddIntoDataStructureofStorelist(StoreList(I)).StoreId.ToString)
                ListBox1.Items.Add(StoreList(I).ToString)
            Next
 
            Me.UPCCode.BackColor = System.Drawing.Color.White
            Me.Description.BackColor = System.Drawing.Color.White
            Me.Size.BackColor = System.Drawing.Color.White
            Me.Qty.BackColor = System.Drawing.Color.White
            Me.Price.BackColor = System.Drawing.Color.White
        End If
    End Sub
 
    Private Sub UPCCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UPCCode.TextChanged
        'Searching for UPC code
        If Me.UPCCode.Text <> "" And IsValidIntegerRequired(Me.UPCCode.Text) Then
 
            Dim NameValueOut As String
            Dim SizeValueOut As String
            Dim UOMValueOut As String
 
            Dim conn As New SqlConnection(Application("A1SConnString"))
            Dim cmd As New SqlCommand("spA1SGetUPCCode", conn)
            cmd.CommandType = CommandType.StoredProcedure
            Dim sqlDR As SqlDataReader
            Dim prm As SqlParameter
 
            conn.Open()
            prm = cmd.Parameters.Add("@UPC", SqlDbType.Text)
            prm.Value = UPCCode.Text
            sqlDR = cmd.ExecuteReader
 
            While sqlDR.Read
                NameValueOut = sqlDR("Name")
                SizeValueOut = sqlDR("Size")
                UOMValueOut = sqlDR("UOM")
            End While
 
            If sqlDR.HasRows Then
 
                Me.Description.Text = NameValueOut
                Me.Size.Text = SizeValueOut
                'SizeMeasureList.Items.Clear()
                'SizeMeasureList.Items.Add(UOMValueOut)
                LoadSizeMeasure(UOMValueOut) 'Giving the user option to change SizeMeasureID
 
 
                lblMessage.Visible = False
                Me.Description.ReadOnly = True
                Me.Size.ReadOnly = True
                Me.UPCCode.ReadOnly = True
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
 
            Else
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The UPC Code could not be found matching the search term  '" & UPCCode.Text & "' . Please Enter Item Description."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.PeachPuff
                Me.Size.BackColor = System.Drawing.Color.White
            End If
 
            'Clean Up
            If (Not sqlDR Is Nothing) Then
                If (sqlDR.IsClosed) Then
                    sqlDR.Close()
                End If
            End If
            If (Not conn Is Nothing) Then
                If conn.State <> ConnectionState.Closed Then conn.Close()
                conn.Dispose()
            End If
            If Not cmd Is Nothing Then cmd.Dispose()
            'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            ' Searching for Manual(non-Krasdale ID) code
        ElseIf CheckIfManualID(Me.UPCCode.Text.Chars(0)) Then
 
            Dim conn As New SqlConnection(Application("A1SConnString"))
            Dim cmd As New SqlCommand("spA1SGetWHCode", conn)
            cmd.CommandType = CommandType.StoredProcedure
            Dim sqlDR As SqlDataReader
            Dim prm As SqlParameter
 
            conn.Open()
            prm = cmd.Parameters.Add("@WHCode", SqlDbType.Text)
            prm.Value = UPCCode.Text
 
            prm = cmd.Parameters.Add("@UserID", SqlDbType.VarChar, 15)
            prm.Value = Request.Cookies("A1S")("UID")
 
            sqlDR = cmd.ExecuteReader
            sqlDR.Read()
 
            If sqlDR.HasRows Then
 
                Me.Description.Text = SqlDR("Description")
                SizeMeasureList.Items.Clear()
                Me.SizeMeasureList.Enabled = False
                'Me.DeleteBtn.Enabled = False
 
                lblMessage.Visible = False
                Me.Description.ReadOnly = True
                Me.Size.ReadOnly = True
                Me.UPCCode.ReadOnly = True
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = Nothing
 
            Else
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The warehouse code could not be found matching the search term  '" & UPCCode.Text & "' . Please reenter your warehouse code."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
            End If
 
            'Clean Up
            If (Not sqlDR Is Nothing) Then
                If (sqlDR.IsClosed) Then
                    sqlDR.Close()
                End If
            End If
            If (Not conn Is Nothing) Then
                If conn.State <> ConnectionState.Closed Then conn.Close()
                conn.Dispose()
            End If
            If Not cmd Is Nothing Then cmd.Dispose()
            'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            'If UPC code and WHCode code were not found display error message
        Else
            With lblMessage
                lblMessage.Visible = True
                .CssClass = "labelRed"
                .Text = "The UPC Code must have only whole numbers. Please reenter your UPC Code."
            End With
        End If
    End Sub
    Public Function LoadSizeMeasure(Optional ByVal SelectedVal As String = Nothing)
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As SqlCommand
        Dim prm As SqlParameter
 
        cmd = New SqlCommand("spA1SGetSizeMeasure", conn)
        cmd.CommandType = CommandType.StoredProcedure
 
        Dim oRDR As SqlDataReader
        cmd.CommandTimeout = 120 'Number of seconds to wait for a response.
 
        conn.Open()
        oRDR = cmd.ExecuteReader(CommandBehavior.Default)
 
        SizeMeasureList.Items.Clear()
 
        While oRDR.Read
            SizeMeasureList.Items.Add(oRDR("ABRV"))
            If SelectedVal = oRDR("ABRV") Then SizeMeasureList.SelectedValue = oRDR("ABRV")
            SizeMeasureList.Items(SizeMeasureList.Items.Count - 1).Value = oRDR("SizeMeasureID")
        End While
 
        'Clean Up
        If (Not oRDR Is Nothing) Then
            If Not (oRDR.IsClosed) Then
                oRDR.Close()
            End If
        End If
        oRDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
    End Function
 
    Private Sub WebImageButton1_Click(ByVal sender As System.Object, ByVal e As Infragistics.WebUI.WebDataInput.ButtonEventArgs) Handles WebImageButton1.Click
        If Me.UPCCode.Text <> "" Then
            'If UPC Code is entered then validate and save
            If ValidatingInputForUPCCode() = True Then
                If ListBox1.SelectedIndex <> -1 Then
                    If VerifyStores() = 1 Then
                        UpdateSalesTPRTable()
                        RetrieveSalesTPRItems()
                        InitializeForm()
                        With lblMessage
                            lblMessage.Visible = True
                            .CssClass = "labelGreen"
                            .Text = "The Sale Item was inserted successfully."
                        End With
                        Me.UPCCode.BackColor = System.Drawing.Color.White
                        Me.Description.BackColor = System.Drawing.Color.White
                        Me.Size.BackColor = System.Drawing.Color.White
                        Me.Qty.BackColor = System.Drawing.Color.White
                        Me.Price.BackColor = System.Drawing.Color.White
                        Me.ListBox1.BackColor = System.Drawing.Color.White
                    Else
                        DisplayErrorMessage(7)
                    End If
                Else
                    DisplayErrorMessage(8)
                End If
            End If
        Else
            DisplayErrorMessage(0)
        End If
    End Sub
 
    Private Sub WebImageButton3_Click(ByVal sender As System.Object, ByVal e As Infragistics.WebUI.WebDataInput.ButtonEventArgs) Handles WebImageButton3.Click
        InitializeForm()
    End Sub
    Private Sub InitializeForm()
        Me.lblMessage.Text = Nothing
        Me.UPCCode.Text = Nothing
        Me.Description.Text = Nothing
        Me.Size.Text = Nothing
        Me.Qty.Text = Nothing
        Me.Price.Text = Nothing
        Me.UPCCode.ReadOnly = False
        Me.Description.ReadOnly = False
        Me.Size.ReadOnly = False
 
        Me.UPCCode.BackColor = System.Drawing.Color.White
        Me.Description.BackColor = System.Drawing.Color.White
        Me.Size.BackColor = System.Drawing.Color.White
        Me.Qty.BackColor = System.Drawing.Color.White
        Me.Price.BackColor = System.Drawing.Color.White
        Me.SizeMeasureList.Enabled = True
        SetFocus(UPCCode, Me)
        SizeMeasureList.Items.Clear()
        LoadSizeMeasure()
    End Sub
    Private Function ValidatingInputForUPCCode() As Boolean
 
        Dim bChecking(6) As Boolean
 
        If Me.UPCCode.Text <> "" And IsValidIntegerRequired(Me.UPCCode.Text) Then bChecking(0) = True Else bChecking(0) = False
        If Me.Description.Text <> "" Then bChecking(1) = True Else bChecking(1) = False
        If Me.Size.Text <> "" And IsValidDoubleRequired(Me.Size.Text) Then bChecking(2) = True Else bChecking(2) = False
        If Me.SizeMeasureList.SelectedValue <> "" Then bChecking(3) = True Else bChecking(3) = False
        If Me.Qty.Text <> "" And IsValidIntegerRequired(Me.Qty.Text) Then bChecking(4) = True Else bChecking(4) = False
        If Me.Price.Text <> "" And IsValidDoubleRequired(Me.Price.Text) Then bChecking(5) = True Else bChecking(5) = False
        If VerifyUnicUPCCode(Me.UPCCode.Text) Then bChecking(6) = True Else bChecking(6) = False
 
        Dim i As Integer
        For i = 0 To 6
 
            If bChecking(i) = True Then
                ValidatingInputForUPCCode = True
            Else : ValidatingInputForUPCCode = i
                DisplayErrorMessage(i)
                ValidatingInputForUPCCode = False
                Exit For
            End If
 
        Next
        Return ValidatingInputForUPCCode
    End Function
    Private Function DisplayErrorMessage(ByVal MsgIndex As Integer)
 
        Select Case MsgIndex
            Case 0
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "UPC Code is a required field and must be a whole number. Please reenter your UPC Code."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.PeachPuff
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 1
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Description is a required field. Please reenter your Description."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.PeachPuff
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 2
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Size is a required field and must be numeric. Please reenter your Size."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.PeachPuff
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 3
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Size Measure is a required field. Please reenter your Size Measure."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 4
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Sale Quantity is a required field and must be a whole number other than 0. Please reenter your Sale Quantity."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.PeachPuff
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 5
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Sale Price is a required field and must be a number other than 0. Please reenter your Sale Price."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.PeachPuff
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 6
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The UPCCode that was entered already exists. Please reenter your UPCCode."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.PeachPuff
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 7
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The Stores that you have selected do not belong to the same Program. Please reselect your Stores."
                End With
 
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.PeachPuff
 
            Case 8
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Please select at least one Store from the list."
                End With
 
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.PeachPuff
        End Select
    End Function
    Public Function UpdateSalesTPRTable()
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SInsertSalesTPRItems", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim prm As SqlParameter
 
        prm = New SqlParameter("@UPC", SqlDbType.VarChar, 50)
        prm.Direction = ParameterDirection.Input
        prm.Value = Me.UPCCode.Text 'If UPC is not found Adding to SalesTPR and upc.dbo.uProduct
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Description", SqlDbType.VarChar, 60)
        prm.Direction = ParameterDirection.Input
        prm.Value = Me.Description.Text     'If UPC is not found Adding to SalesTPR and upc.dbo.uProduct
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@SizeUnit", SqlDbType.VarChar, 8)
        prm.Direction = ParameterDirection.Input
        prm.Value = Me.Size.Text            'If UPC is not found Adding to SalesTPR and upc.dbo.uProduct
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@SizeMeasureID", SqlDbType.BigInt)
        prm.Direction = ParameterDirection.Input
        prm.Value = CheckSizeMeasureID()
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Quantity", SqlDbType.Decimal)
        prm.Direction = ParameterDirection.Input
        prm.Value = Convert.ToDecimal(Me.Qty.Text)
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Price", SqlDbType.Decimal)
        prm.Direction = ParameterDirection.Input
        prm.Value = Convert.ToDecimal(Me.Price.Text)
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Active", SqlDbType.TinyInt)
        prm.Direction = ParameterDirection.Input
        prm.Value = 1
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@CreatedDate", SqlDbType.DateTime)
        prm.Direction = ParameterDirection.Input
        prm.Value = Now.ToLongTimeString
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@ModifiedDate", SqlDbType.DateTime)
        prm.Direction = ParameterDirection.Input
        prm.Value = Now.ToLongTimeString
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@ActiveDate", SqlDbType.DateTime)
        prm.Direction = ParameterDirection.Input
        prm.Value = Now.ToLongTimeString
        cmd.Parameters.Add(prm)
 
        'prm = New SqlParameter("@UOM", SqlDbType.VarChar, 4)
        'prm.Direction = ParameterDirection.Input
        'prm.Value = Me.SizeMeasureList.SelectedItem.Text    'Adding to upc.dbo.uProduct if UPC doesn't exist
        'cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@UserID", SqlDbType.VarChar, 50)
        prm.Direction = ParameterDirection.Input
        prm.Value = ReadCookie(Tokens.UserId)
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Stores", SqlDbType.VarChar, 150)
        prm.Direction = ParameterDirection.Input
        prm.Value = strselecteditems
        cmd.Parameters.Add(prm)
 
 
        conn.Open()
        cmd.ExecuteNonQuery()
 
        If conn.State <> ConnectionState.Closed Then conn.Close()
        If Not conn Is Nothing Then conn.Dispose()
        If Not cmd Is Nothing Then cmd.Dispose()
        prm = Nothing
 
    End Function
    Private Function CheckSizeMeasureID(Optional ByVal SizeMeasureID As String = Nothing) As Integer
 
        Dim SzMeasureID As Integer
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SCheckSizeMeasure", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
        Dim prm As SqlParameter
 
        conn.Open()
        prm = cmd.Parameters.Add("@ABRV", SqlDbType.VarChar)
        If SizeMeasureID = Nothing Then
            prm.Value = Me.SizeMeasureList.SelectedItem.Text
        Else
            prm.Value = SizeMeasureID
        End If
        sqlDR = cmd.ExecuteReader
 
        While sqlDR.Read
            SzMeasureID = sqlDR("SizeMeasureID")
        End While
 
        If sqlDR.HasRows Then
            CheckSizeMeasureID = SzMeasureID
        Else
            CheckSizeMeasureID = -1
        End If
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If Not (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        sqlDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        Return CheckSizeMeasureID
 
    End Function
    Private Function RetrieveSalesTPRItems()
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SGetSalesTPR", conn)
        Dim sqlDR As New SqlDataAdapter
        Dim ds As New DataSet
 
        Dim prm As New SqlParameter("@UserID", SqlDbType.VarChar, 50)
        cmd.CommandType = CommandType.StoredProcedure
        prm.Value = ReadCookie(Tokens.UserId)
        cmd.Parameters.Add(prm)
 
        conn.Open()
        sqlDR.SelectCommand = cmd
        sqlDR.Fill(ds)
 
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then sqlDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
 
    End Function
    Public Sub DeleteItems(ByVal sender As Object, ByVal e As CommandEventArgs)
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SDeleteSalesTPRItem", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
 
        Dim p As New SqlParameter("@ItemID", SqlDbType.BigInt)
        p.Value = e.CommandArgument
        cmd.Parameters.Add(p)
 
        conn.Open()
        cmd.ExecuteNonQuery()
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        RetrieveSalesTPRItems()
 
        With lblMessage
            lblMessage.Visible = True
            .CssClass = "labelGreen"
            .Text = "The Sale Item was successfully deleted ."
        End With
 
    End Sub
    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        RetrieveSalesTPRItems()
 
        With lblMessage
            lblMessage.Visible = True
            .CssClass = "labelGreen"
            .Text = "Page: " & DataGrid1.CurrentPageIndex + 1 & " of " & DataGrid1.PageCount.ToString
        End With
    End Sub
 
    Private Sub DoneButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DoneButton.Click
        Response.Redirect("MainMenu.aspx")
    End Sub
    Private Function VerifyUnicUPCCode(ByVal UPCCode As String) As Boolean
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SCheckUnicUPCforTPR", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
        Dim prm As SqlParameter
 
        conn.Open()
        sqlDR = cmd.ExecuteReader
 
        VerifyUnicUPCCode = True
 
        While sqlDR.Read
            If UPCCode = sqlDR("UPC") Then
                VerifyUnicUPCCode = False
                Exit While
            Else
                VerifyUnicUPCCode = True
            End If
        End While
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If Not (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        sqlDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        Return VerifyUnicUPCCode
 
    End Function
    Public Function VerifyStores() As Integer
        Dim i As Integer = 0
        Dim Count As Integer = 0
        Dim TempChain As Integer = -1
        Dim TempRegion As Integer = -1
        Dim TempCustomerLoyalty As Integer = -1
        Try
            For i = 0 To ListBox1.Items.Count - 1
                If ListBox1.Items(i).Selected Then
                    If Count = 0 Then
 
                        TempChain = GetChainNumber(ListBox1.Items(i).ToString)
                        TempRegion = GetRegionNumber(ListBox1.Items(i).ToString)
                        TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString)
                        strselecteditems = ListBox1.Items(i).Text
                        Count = Count + 1
 
                    Else
                        If TempChain = GetChainNumber(ListBox1.Items(i).ToString) And TempRegion = GetRegionNumber(ListBox1.Items(i).ToString) And TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString) Then
                            strselecteditems = strselecteditems & "," & ListBox1.Items(i).Text
                        Else
                            Return 0
                        End If
                    End If
                End If
            Next
            Return 1
        Catch ex As ApplicationException
 
        End Try
 
    End Function
    Public Sub ChangeItemStatus(ByVal sender As Object, ByVal e As CommandEventArgs)
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SChangeTPRItemStatus", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
 
        Dim p As New SqlParameter("@ItemID", SqlDbType.BigInt)
        p.Value = e.CommandArgument
        cmd.Parameters.Add(p)
 
        conn.Open()
        cmd.ExecuteNonQuery()
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        RetrieveSalesTPRItems()
 
    End Sub
 
    Private Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cblStores.SelectedIndexChanged
 
        Dim CBL As CheckBoxList = CType(sender, CheckBoxList)
 
        Dim YourConnectionString As String = "A1SConnString" 'this should be connection string text
 
        'Create Connection String
        Dim conn As New SqlConnection(Application("StoreList"))
 
        'Open the connection
        conn.Open()
 
        'Create  Update Sql Command
        Dim UpdateCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand("Update YourTable set Active = @Active" + _
        " where ItemId = @ItemId", conn)
 
        'Add the parameters to  Update Command
        UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("Active", CType(CBL.SelectedItem.Selected, Integer)))
        UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("ItemId", CBL.SelectedItem.Value))
 
        'Execute the Update Command
        UpdateCommand.ExecuteNonQuery()
 
        'Close the connection
        conn.Close()
 
    End Sub
 
 
 
    ' This is for the checkbox self not using this at all below ******************************
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
 
 
        Dim CBL As CheckBoxList = CType(sender, CheckBoxList)
 
        Dim YourConnectionString As String = "A1SConnString" 'this should be connection string text
 
        'Create Connection String
        Dim conn As New SqlConnection(Application("SalesTPRTable"))
 
        'Open the connection
        conn.Open()
 
        'Create  Update Sql Command
        Dim UpdateCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand("Update YourTable set Active = @Active" + _
        " where ItemId = @ItemId", conn)
 
        'Add the parameters to Update Command
        UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("Active", CType(CBL.SelectedItem.Selected, Integer)))
        UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("ItemId", CBL.SelectedItem.Value))
 
        'Execute the Update Command
        UpdateCommand.ExecuteNonQuery()
 
        'Close the connection
        conn.Close()
 
    End Sub
    '/************************************************************************************************
 
 
 
 
 
 
    Protected Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        'Add if not IsPostBack here
 
        Dim Connection As New SqlConnection(Application("A1SConnString"))
 
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
 
 
            Dim CBL As CheckBoxList = CType(e.Item.FindControl("cblStores"), CheckBoxList)
            Dim Command As New SqlCommand("spA1SGetUserStores", Connection)
            Command.CommandType = CommandType.StoredProcedure
            Dim Param As New SqlParameter("@UserID", SqlDbType.VarChar, 50)
            'Dim Value As New SqlParameter("@ItemID", SqlDbType.BigInt, 8)
 
            Param.Value = ReadCookie(Tokens.UserId)
            Command.Parameters.Add(Param)
            Dim SDA As New SqlDataAdapter(Command)
 
            Dim StoreTable As New DataTable("Stores")
 
            If Connection.State <> ConnectionState.Open Then
                Connection.Open()
            End If
            SDA.Fill(StoreTable)
 
            CBL.DataSource = StoreTable
            CBL.DataTextField = "StoreID"
            CBL.DataBind()
            Connection.Close()
 
 
        End If
 
 
 
 
        'Dim Connection As New SqlConnection(Application("A1SConnString"))
        ' this sets up our Checkboxlist telling us to grab it
        'If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
 
        'Dim CBL As CheckBoxList = CType(e.Item.FindControl("cblStores"), CheckBoxList)
        'Dim Command As New SqlCommand("spA1SGetStoreTPR", Connection)
        'Command.CommandType = CommandType.StoredProcedure
        'Dim Param As New SqlParameter("@UserID", SqlDbType.VarChar, 50)
        'Param.Value = ReadCookie(Tokens.UserId)
        ' Command.Parameters.Add(Param)
 
        'If Connection.State <> ConnectionState.Open Then
        'Connection.Open()
        'End If
        'CBL.DataSource = Command.ExecuteReader()
        ' CBL.DataBind()
        'Connection.Close()
 
        'End If
    End Sub
    Protected Sub cblStores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cblStores.Load
        If Not IsPostBack Then
            ' **FIRST**
            Dim Connection As New SqlConnection(Application("A1SConnString"))
            Dim cmd As New SqlCommand("select Active from StoreTPR where UPC = @UPC and Store = @Store", Connection)
 
            ' **SECOND**
            Dim CBL As CheckBoxList = CType(sender, CheckBoxList)
            Dim Lbl As Label
            Dim ctrl As Control
 
 
 
            ' **THIRD**
            For Each ctrl In CBL.Parent.Controls
                If TypeOf ctrl Is Label Then
                    Lbl = CType(ctrl, Label)
                End If
            Next
 
            ' **FOURTH**
            Dim i As Integer
            Connection.Open()
 
            ' **FIFTH**
            For i = 0 To CBL.Items.Count - 1
                Dim cb As ListItem = CBL.Items(i)
 
                cmd.Parameters.Clear()
                cmd.Parameters.Add(New SqlClient.SqlParameter("@UPC", Lbl.Text))
                cmd.Parameters.Add(New SqlClient.SqlParameter("@Store", cb.Text))
 
                cb.Selected = Convert.ToBoolean(cmd.ExecuteScalar())
 
            Next i
 
            Connection.Close()
        End If
    End Sub
 
    Protected Sub cblStores_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cblStores.SelectedIndexChanged
        'If Not IsPostBack Then
        Dim Connection As New SqlConnection(Application("A1SConnString"))
        Dim UpdateCommand As New SqlCommand("update StoreTPR set active = @Active where UPC = @UPC and Store = @Store", Connection)
 
        Dim CBL As CheckBoxList = CType(sender, CheckBoxList)
        Dim Lbl As Label
        Dim ctrl As Control
 
        For Each ctrl In CBL.Parent.Controls
            If TypeOf ctrl Is Label Then
                Lbl = CType(ctrl, Label)
            End If
        Next
 
        If Connection.State <> ConnectionState.Open Then
            Connection.Open()
        End If
 
        Dim ActiveValue As Integer
        Dim CB As New ListItem
 
        For Each CB In CBL.Items
 
            If CB.Selected Then
                ActiveValue = 1
            Else
                ActiveValue = 0
            End If
 
            UpdateCommand.Parameters.Clear()
            UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Active", ActiveValue))
            UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@UPC", Lbl.Text))
            UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Store", CB.Text))
 
            UpdateCommand.ExecuteNonQuery()
 
        Next
 
        Connection.Close()
        'End If
    End Sub
End Class

Open in new window

Avatar of DotNetThinker
DotNetThinker
Flag of United States of America image

Want to just cheat? You could set the ListBox to Visible="false".
Avatar of Seven price

ASKER

I know i tryied that but it ask me Please select at least one Store from the list.
these two are keeping me from adding or showing up when removed I know they are asscoiated with the listbox
Private Sub WebImageButton1_Click(ByVal sender As System.Object, ByVal e As Infragistics.WebUI.WebDataInput.ButtonEventArgs) Handles WebImageButton1.Click
        If Me.UPCCode.Text <> "" Then
            'If UPC Code is entered then validate and save
            If ValidatingInputForUPCCode() = True Then
                If ListBox1.SelectedIndex <> -1 Then
                    If VerifyStores() = 1 Then
                        UpdateSalesTPRTable()
                        RetrieveSalesTPRItems()
                        InitializeForm()
                        With lblMessage
                            lblMessage.Visible = True
                            .CssClass = "labelGreen"
                            .Text = "The Sale Item was inserted successfully."
                        End With
                        Me.UPCCode.BackColor = System.Drawing.Color.White
                        Me.Description.BackColor = System.Drawing.Color.White
                        Me.Size.BackColor = System.Drawing.Color.White
                        Me.Qty.BackColor = System.Drawing.Color.White
                        Me.Price.BackColor = System.Drawing.Color.White
                        Me.ListBox1.BackColor = System.Drawing.Color.White
                    Else
                        DisplayErrorMessage(7)
                    End If
                Else
                    DisplayErrorMessage(8)
                End If
            End If
        Else
            DisplayErrorMessage(0)
        End If
    End Sub
 
 
 
 
 
Public Function VerifyStores() As Integer
        Dim i As Integer = 0
        Dim Count As Integer = 0
        Dim TempChain As Integer = -1
        Dim TempRegion As Integer = -1
        Dim TempCustomerLoyalty As Integer = -1
        Try
            For i = 0 To ListBox1.Items.Count - 1
                If ListBox1.Items(i).Selected Then
                    If Count = 0 Then
 
                        TempChain = GetChainNumber(ListBox1.Items(i).ToString)
                        TempRegion = GetRegionNumber(ListBox1.Items(i).ToString)
                        TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString)
                        strselecteditems = ListBox1.Items(i).Text
                        Count = Count + 1
 
                    Else
                        If TempChain = GetChainNumber(ListBox1.Items(i).ToString) And TempRegion = GetRegionNumber(ListBox1.Items(i).ToString) And TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString) Then
                            strselecteditems = strselecteditems & "," & ListBox1.Items(i).Text
                        Else
                            Return 0
                        End If
                    End If
                End If
            Next
            Return 1
        Catch ex As ApplicationException
 
        End Try
 
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DotNetThinker
DotNetThinker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
well i just need the listbox gone because we created the checkboxlist and that is what is associated with the stores
Yeah I get that. Is that a yes or no?
yes if you are referring to all the stores will load up same as before. All the functions are the same except without the list box so no would be the answer
ok, the problem is that you're still referring to the listboxes in these functions. In the first function you could probably get away with just commenting out the section that's referring to the ListBox. The second function is going to need some more changes. For now just comment out the code from the first function and see if you still get errors in it.


Private Sub WebImageButton1_Click(ByVal sender As System.Object, ByVal e As Infragistics.WebUI.WebDataInput.ButtonEventArgs) Handles WebImageButton1.Click
        If Me.UPCCode.Text <> "" Then
            'If UPC Code is entered then validate and save
            If ValidatingInputForUPCCode() = True Then
                'If ListBox1.SelectedIndex <> -1 Then
                    If VerifyStores() = 1 Then
                        UpdateSalesTPRTable()
                        RetrieveSalesTPRItems()
                        InitializeForm()
                        With lblMessage
                            lblMessage.Visible = True
                            .CssClass = "labelGreen"
                            .Text = "The Sale Item was inserted successfully."
                        End With
                        Me.UPCCode.BackColor = System.Drawing.Color.White
                        Me.Description.BackColor = System.Drawing.Color.White
                        Me.Size.BackColor = System.Drawing.Color.White
                        Me.Qty.BackColor = System.Drawing.Color.White
                        Me.Price.BackColor = System.Drawing.Color.White
                        Me.ListBox1.BackColor = System.Drawing.Color.White
                    Else
                        DisplayErrorMessage(7)
                    End If
                'Else
                    'DisplayErrorMessage(8)
                'End If
            End If
        Else
            DisplayErrorMessage(0)
        End If
    End Sub
 
 
 
 
 
Public Function VerifyStores() As Integer
        Dim i As Integer = 0
        Dim Count As Integer = 0
        Dim TempChain As Integer = -1
        Dim TempRegion As Integer = -1
        Dim TempCustomerLoyalty As Integer = -1
        Try
            For i = 0 To ListBox1.Items.Count - 1
                If ListBox1.Items(i).Selected Then
                    If Count = 0 Then
 
                        TempChain = GetChainNumber(ListBox1.Items(i).ToString)
                        TempRegion = GetRegionNumber(ListBox1.Items(i).ToString)
                        TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString)
                        strselecteditems = ListBox1.Items(i).Text
                        Count = Count + 1
 
                    Else
                        If TempChain = GetChainNumber(ListBox1.Items(i).ToString) And TempRegion = GetRegionNumber(ListBox1.Items(i).ToString) And TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString) Then
                            strselecteditems = strselecteditems & "," & ListBox1.Items(i).Text
                        Else
                            Return 0
                        End If
                    End If
                End If
            Next
            Return 1
        Catch ex As ApplicationException
 
        End Try
 
    End Function

Open in new window

I got it to work
one problem i need you to show me. why does all the checkboxes show checked but when refreshed
they are all check can you help me with this last problem
That's great.
Are they all checked before or after you refresh?
after I refresh
How about your database? Does it show all the items as Active = 1?
yes it does
that's your problem. Try setting a few to Active = 0 and see what happens?
cool but i want them all set to 1 which is correct in the database but is there a way without refreshing for them to show all checked.
For Each CB In CBL.Items
 
            If CB.Selected Then
                ActiveValue = 1
            Else
                ActiveValue = 0
            End If

Open in new window

oh, I get what you're saying. You could do a Response.Redirect to the same page. It's essentially just a refresh but you don't have to manually refresh that way.
well i manually refresh when adding a upc code but in the database active is set to 1 but i have to manually refresh to see the active take effect
that's where I'm saying you could use the Response.Redirect(...) at the very end of the function you use to add an item.
Locks up everything have logoff and come back then everything is there
Ok I think below will work how would i modify this to add that below
Dim Connection As New SqlConnection(Application("A1SConnString"))
        Dim UpdateCommand As New SqlCommand("update StoreTPR set active = @Active where UPC = @UPC and Store = @Store", Connection)

        Dim CBL As CheckBoxList = CType(sender, CheckBoxList)
        Dim Lbl As Label
        Dim ctrl As Control

        For Each ctrl In CBL.Parent.Controls
            If TypeOf ctrl Is Label Then
                Lbl = CType(ctrl, Label)
            End If
        Next

        If Connection.State <> ConnectionState.Open Then
            Connection.Open()
        End If

        Dim ActiveValue As Integer
        Dim CB As New ListItem

        For Each CB In CBL.Items
           
            If CB.Selected Then
                ActiveValue = 1
            Else
                ActiveValue = 0
            End If

            UpdateCommand.Parameters.Clear()
            UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Active", ActiveValue))
            UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@UPC", Lbl.Text))
            UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Store", CB.Text))

            UpdateCommand.ExecuteNonQuery()

        Next
'Loop through the dataset and check whether staus is completed if so just set  selected property of the the corresponding ' checkbox in the list to True
        For itemCounter As Integer = 0 To myDataSet.Tables(0).Rows.Count - 1
            With myDataSet.Tables(0).Rows(itemCounter)
                If .Item("Status").ToString.ToLower = "completed" Then chkStatus.Items(itemCounter).Selected = True

Open in new window

you know even if a checkbox is checked when a delete a row the checkboxes disapear then i refresh they come back so its not on the backend its on the frontend.