4 Replies - 750 Views - Last Post: 02 April 2016 - 04:35 AM Rate Topic: -----

#1 wardo.exe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 16

Capturing multiple values to an array with a single textbox

Posted 01 April 2016 - 10:31 AM

Hello everyone.

I am trying to develop a program for my company that uses an inventory form for computer equipment. I currently have written a program that will transmit values entered into a series of textboxes to a data table and then outputs the values to a PDF file using the itextsharp library. After a lot of trial I have it working.

However, I want to extend my program to now save the values that are entered into the textboxes (store in an array or listbox??) and then generate multiple entries into my inventory sheet. For example, there are multiple lines on the PDF form, but my program only currently allows for one line to be input into the PDF file.

I am having trouble wrapping my non programmer mind around how to do this. I know I will need to rework a large part of my code, and that is fine. I just want to make some progress. I am not asking for you to do this for me, but I have tried to create an array and also store the items to a listbox with little success. Also, I am stuck on where to go from there. Any help or suggestions, new way of doing this, or pointing in the right direction would be great. If possible, I would love some code examples just to see what I may be able to try.

Here is my code, and thank you!

Imports iTextSharp.text.pdf
Imports System.IO

Partial Class _Default
    Inherits System.Web.UI.Page

    Dim reader As New PdfReader(Server.MapPath("pdfs\InventoryForm.pdf"))
    Dim output As New MemoryStream()
    Dim stamper As New PdfStamper(reader, output)


    Protected Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        

        Dim fromBuilding As String = CStr(ddlFromBuilding.Text)
        Select Case fromBuilding

            Case "Art/Receiving"
                fromBuilding = 220

            Case "Administration"
                ddlFromBuilding.Text = 221

            Case "Classrooms"
                ddlFromBuilding.Text = 222

            Case "Ball Fields"
                ddlFromBuilding.Text = 223

            Case "Business Education"
                ddlFromBuilding.Text = 224

            Case "West Annex Complex"
                ddlFromBuilding.Text = 225

            Case "Day Care Center"
                ddlFromBuilding.Text = 226

            Case "Gymnasium"
                ddlFromBuilding.Text = 227

            Case "Guadalupe Center"
                ddlFromBuilding.Text = 228

            Case "Carpenter Center"
                ddlFromBuilding.Text = 229

            Case "Liberal Arts"
                ddlFromBuilding.Text = 230

            Case "Learning Resource Center"
                ddlFromBuilding.Text = 231

            Case "Life Science"
                ddlFromBuilding.Text = 232

            Case "Mechanical Plant"
                ddlFromBuilding.Text = 233

            Case "Ahwatukee - Horizon Center"
                ddlFromBuilding.Text = 234

            Case "M&O Storage"
                ddlFromBuilding.Text = 235

            Case "Music"
                ddlFromBuilding.Text = 236

            Case "Physical Science"
                ddlFromBuilding.Text = 237

            Case "Student Services Center"
                ddlFromBuilding.Text = 238

            Case "Student Union"
                ddlFromBuilding.Text = 239

            Case "Classrooms - IKON/Marketing"
                ddlFromBuilding.Text = 240

            Case "AZ Agricultural Education Center"
                ddlFromBuilding.Text = 241

            Case "Student Enrollment Services"
                ddlFromBuilding.Text = 242

            Case "Performing Arts Center"
                ddlFromBuilding.Text = 243

            Case "Library"
                ddlFromBuilding.Text = 247
        End Select

        Dim toBuilding As String = CStr(ddlToBuilding.Text)
        Select Case toBuilding

            Case "Art/Receiving"
                fromBuilding = 220

            Case "Administration"
                ddlFromBuilding.Text = 221

            Case "Classrooms"
                ddlFromBuilding.Text = 222

            Case "Ball Fields"
                ddlFromBuilding.Text = 223

            Case "Business Education"
                ddlFromBuilding.Text = 224

            Case "West Annex Complex"
                ddlFromBuilding.Text = 225

            Case "Day Care Center"
                ddlFromBuilding.Text = 226

            Case "Gymnasium"
                ddlFromBuilding.Text = 227

            Case "Guadalupe Center"
                ddlFromBuilding.Text = 228

            Case "Carpenter Center"
                ddlFromBuilding.Text = 229

            Case "Liberal Arts"
                ddlFromBuilding.Text = 230

            Case "Learning Resource Center"
                ddlFromBuilding.Text = 231

            Case "Life Science"
                ddlFromBuilding.Text = 232

            Case "Mechanical Plant"
                ddlFromBuilding.Text = 233

            Case "Ahwatukee - Horizon Center"
                ddlFromBuilding.Text = 234

            Case "M&O Storage"
                ddlFromBuilding.Text = 235

            Case "Music"
                ddlFromBuilding.Text = 236

            Case "Physical Science"
                ddlFromBuilding.Text = 237

            Case "Student Services Center"
                ddlFromBuilding.Text = 238

            Case "Student Union"
                ddlFromBuilding.Text = 239

            Case "Classrooms - IKON/Marketing"
                ddlFromBuilding.Text = 240

            Case "AZ Agricultural Education Center"
                ddlFromBuilding.Text = 241

            Case "Student Enrollment Services"
                ddlFromBuilding.Text = 242

            Case "Performing Arts Center"
                ddlFromBuilding.Text = 243

            Case "Library"
                ddlFromBuilding.Text = 247
        End Select

        Dim InventoryAdapter As New DataSet2TableAdapters.TableTableAdapter
        InventoryAdapter.Insert(ReasonForTransfer:=ddlReason.Text, Serial:=txtbxSerialNumber.Text, Tag:=txtbxTagNumber.Text, Description:=txtbxDescription.Text, FromCampus:=txtbxFromCampus.Text, FromBuilding:=fromBuilding, FromRoom:=txtbxFromRoom.Text, ToCampus:=txtbxToCampus.Text, ToBuilding:=ddlToBuilding.Text, ToRoom:=txtbxToRoom.Text, AcceptedBy:=txtbxAcceptedBy.Text, AccepteeEmail:=txtbxAccepteeEmail.Text, ReleasedBy:=txtbxReleasedBy.Text, ReleaseeEmail:=txtbxReleaseeEmail.Text, Notes:=txtbxNotes.Text)
        lblItemAdded.Text = "Item Added Successfully!"
        GridView1.DataBind()


        If ddlReason.Text = "Location Transfer" Then
            stamper.AcroFields.SetField("cbLocation", "Yes")
        ElseIf ddlReason.Text = "Trade-In/Replacement" Then
            stamper.AcroFields.SetField("cbTradeIn", "Yes")
        ElseIf ddlReason.Text = "Surplus" Then
            stamper.AcroFields.SetField("cbSurplus", "Yes")
        ElseIf ddlReason.Text = "Trashed" Then
            stamper.AcroFields.SetField("cbTrashed", "Yes")
        ElseIf ddlReason.Text = "Cannibalized" Then
            stamper.AcroFields.SetField("cbCannibalized", "Yes")
        ElseIf ddlReason.Text = "Destroyed/Damaged" Then
            stamper.AcroFields.SetField("cbDestroyed", "Yes")
        ElseIf ddlReason.Text = "Computer Repair" Then
            stamper.AcroFields.SetField("cbComputerRepair", "Yes")
        ElseIf ddlReason.Text = "External Donation" Then
            stamper.AcroFields.SetField("cbExternalDonation", "Yes")
        End If

        stamper.AcroFields.SetField("Description1", txtbxDescription.Text)
        stamper.AcroFields.SetField("Tag1", txtbxTagNumber.Text)
        stamper.AcroFields.SetField("Serial1", txtbxSerialNumber.Text)
        stamper.AcroFields.SetField("FromCampus1", txtbxFromCampus.Text)
        stamper.AcroFields.SetField("FromBuilding1", fromBuilding)
        stamper.AcroFields.SetField("FromRoom1", txtbxFromRoom.Text)
        stamper.AcroFields.SetField("ToCampus1", txtbxToCampus.Text)
        stamper.AcroFields.SetField("ToBuilding1", toBuilding)
        stamper.AcroFields.SetField("ToRoom1", txtbxToRoom.Text)
        stamper.AcroFields.SetField("Date", Date.Today())
        stamper.AcroFields.SetField("ReleaseDate", Date.Today())
        stamper.AcroFields.SetField("AcceptedDate", Date.Today())
        stamper.AcroFields.SetField("ReleasedName", txtbxReleasedBy.Text)
        stamper.AcroFields.SetField("AcceptedName", txtbxAcceptedBy.Text)
        stamper.AcroFields.SetField("ReleasedSignature", txtbxReleaseeEmail.Text)
        stamper.AcroFields.SetField("AcceptedSignature", txtbxAccepteeEmail.Text)

        stamper.FormFlattening = True

        stamper.Close()
        reader.Close()

        Response.AddHeader("Content-Disposition", "attachment; filename=InventoryForm.pdf")
        Response.ContentType = "application/pdf"

        Response.BinaryWrite(output.ToArray())
        Response.End()
    End Sub

    Protected Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        ddlReason.SelectedIndex = "0"
        txtbxSerialNumber.Text = ""
        txtbxDescription.Text = ""
        txtbxTagNumber.Text = ""
        ddlToBuilding.SelectedIndex = "0"
        txtbxToCampus.Text = "400"
        txtbxToRoom.Text = ""
        ddlFromBuilding.SelectedIndex = "0"
        txtbxFromCampus.Text = "400"
        txtbxFromRoom.Text = ""
        txtbxNotes.Text = ""
        lblItemAdded.Text = ""
    End Sub

End Class




I have also attached a blank inventory form template so you can see what I am talking about by multiple entries. There are many instances where we replace a computer, and that requires 2 lines at a minimum (1 for the outgoing computer, 1 for the incoming old computer)

I really appreciate any help that could be given. Thank you so much in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Capturing multiple values to an array with a single textbox

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14089
  • View blog
  • Posts: 56,440
  • Joined: 12-June 08

Re: Capturing multiple values to an array with a single textbox

Posted 01 April 2016 - 11:25 AM

I am lost on the setup. If you have more than one item in a screen shot then a collection object like a grid would be best. From there it's an issue using a loop to add to the PDF.
Was This Post Helpful? 0
  • +
  • -

#3 PeterH   User is offline

  • D.I.C Regular

Reputation: 58
  • View blog
  • Posts: 282
  • Joined: 03-September 09

Re: Capturing multiple values to an array with a single textbox

Posted 01 April 2016 - 01:01 PM

Couple of things,

Why are you creating a string variable and then populating it from a string variable, using Cstr() e.g.

Dim fromBuilding As String = CStr(ddlFromBuilding.Text)


You could do your 'Select/Case' based directly on ddlFromBuilding.Text or ddlToBuilding.Text.

Do you have Option strict turned on?

You are setting some numeric values to string values ddlToBuilding.SelectedIndex = "0", = 0

As Mod123_1 suggests, for multiple line entries you could either replace your textboxes with a datagrid, or keep them and add the data to a listview. In either case you could then iterate through the rows adding them to your database or pdf report.
Was This Post Helpful? 0
  • +
  • -

#4 wardo.exe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 16

Re: Capturing multiple values to an array with a single textbox

Posted 01 April 2016 - 02:20 PM

Thank you both for replying. Mod123_1, I would like to provide you with what you need to assist me, but I'm unclear on what it is. Are you asking for screenshots? Thanks for the reply.

PeterH, to answer your questions, it is because I am not a good programmer and this has been a struggle to even eek this out. Either way I think I am doing somewhat okay so far. I will take your recommendations and see what I can manage to put together. I'm definitely not against trying, but is there a sample that you could provide on your idea of the best method to pursue?

Thank you both again.
Was This Post Helpful? 0
  • +
  • -

#5 PeterH   User is offline

  • D.I.C Regular

Reputation: 58
  • View blog
  • Posts: 282
  • Joined: 03-September 09

Re: Capturing multiple values to an array with a single textbox

Posted 02 April 2016 - 04:35 AM

I have used this method when creating customer invoices. This allowed the invoice to be reviewed as it was entered, line by line.

Add a listview control to your form. Format the listview property as 'View' and add column titles etc.
when the 'Add' button is clicked, add the contents of your validated textbox fields to the relevant listview columns e.g.

Dim item As New ListViewItem(ddlReason.Text)' add first item column 0
item.SubItems.Add(txtbxDescription.Text) ' add next column 1 data
item.SubItems.Add(txtbxTagNumber.Text) ' add next column 2 data
Lvw_List.Items.Insert(Lvw_List.Items.Count, item)'add the row to the listview



When entries are complete, probably use a button click event, then read through the listview rows to perform your update process.

For a = 0 To Lvw_List.Items.Count - 1
   ' retrieve data from listview columns,  = Lvw_List.Items(a).SubItems(0).Text etc.
   ' update
Next
'Clear the listview, before the starting the next entry.
Lvw_List.Items.Clear()


This is just one way to do this, I am sure others will probably suggest different ways.

This post has been edited by PeterH: 02 April 2016 - 05:09 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1