从文本框捕获多个值并存储以创建PDF

时间:2016-03-24 16:36:34

标签: asp.net vb.net

我是今天的stackoverflow的新手,我是一名新手程序员。我从这个社区学到了很多东西,感谢你给我的任何建议或帮助。

我想要做的是使用VB在asp.net中使用web表单,以便在用户单击按钮时存储文本框的值。我正在使用itextsharp为库存表单创建一个PDF,该表单只能在我的组织内部使用。我想要做的是编写一个按钮,该按钮将捕获表单的值,清除表单,然后允许新条目(对于库存表上的新行)。例如,如果我们在库存表上有多个条目,我想存储这些值,然后编写一个按钮来生成表单。

我真的试图帮助自己,并为我迄今取得的进展感到自豪。我知道我可以在你的帮助下完成这项工作!

原谅我的代码,因为它没有标准化,甚至没有适当的评论。

我也明白我可能要修改我的程序,但我没关系。目前,该代码适用于单行输入。这是代码

    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 = ""
        txtbxToRoom.Text = ""
        ddlFromBuilding.SelectedIndex = "0"
        txtbxFromCampus.Text = ""
        txtbxFromRoom.Text = ""
        txtbxNotes.Text = ""
        lblItemAdded.Text = ""
    End Sub

End Class

即使无法提供解决方案,我也非常感谢任何指向正确的方向。非常感谢你的时间!

0 个答案:

没有答案