一千萬個為什麽

搜索

VB.NET - 將WinForm應用程序導出/轉換為Web ASP.NET應用程序的最簡單方法

背景:我有一個用VB.NET編寫的winform應用程序,它使用WebService根據他們選擇的營銷公司向用戶發送不同的邀請,以進行不同的訪談。 winform應用程序從各種文本框,列表框和下拉列表中提取字符串值以創建一些XML並將其推送到名為AcompServiceClient的Web服務

問題:

  • 是否有向導或第三方應用程序將winform數據導出到webform asp.net,還是應該從頭開始構建一個aspx頁面,與winform應用程序的所有控件具有相同的名稱空間?
  • 除了AcompServiceClient Web服務和代碼隱藏的vb之外,我需要傳輸或設置哪些文件才能使其工作? (查看項目文件的屏幕截圖)
  • 我是否必須復制app.config文件的任何部分並將其調整為web.config文件?

我剛在想:

  • 我可以將Acomp_Invitation_Form.vb復制到頁面後面的AComp_Invitation_Web_App.aspx.vb代碼。
  • 從網絡服務器添加現有的網絡服務
  • 使用相同的名稱/ id
  • 手動重新添加前端aspx頁面上的格式,文本框,列表框和下拉列表

這是WinForm應用程序的屏幕截圖:

ACOMP Screenshot

這是項目文件的屏幕截圖:

enter image description here

這是我在Acomp_Invitation_Form.vb上的代碼:

Imports TestClient.aCompService
Imports System.Text
Public Class Form1

Private proxy As New AcompServiceClient
Private Sub stuff()

    Dim splitContractingBundle() As String
    splitContractingBundle = Split(cb2.SelectedItem, "|")
    Dim splitMarketingCompany() As String
    splitMarketingCompany = Split(cb3.SelectedItem, "|")
    Dim strDate As String = System.DateTime.Now.ToString
    Dim strOpData As String = String.Format("{0}~{1}~{2}~{3}~{4}~{5}~{6}~{7}~{8}~{9}~{10}",
                                            Trim(splitMarketingCompany(0)), txtFirstName.Text, "", txtLastName.Text,
                                            txtEmail.Text, txtEmail.Text, "1", strDate,
                                            "Pending", "1/1/1900", Trim(splitContractingBundle(0)))

    Dim int1 As Boolean = proxy.AddContractOpportunity(strOpData, "test", "test")
    txtEmail.Text = ""
    txtFirstName.Text = ""
    txtLastName.Text = ""
    lbCarriers.Items.Clear()
    cb2.Items.Clear()
    cb3.Items.Clear()
    cb2.SelectedItem = ""
    cb3.SelectedText = ""
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    'TODO Add code to validate that all selections that are reaquired are met.
    'ccemail and the additional message are not required
    Dim firstname As String = txtFirstName.Text
    Dim lastname As String = txtLastName.Text
    Dim ccEmail As String = txtccEmail.Text
    Dim sb As New StringBuilder
    sb.AppendLine("<?xml version=""1.0"" encoding=""utf-8""?>")
    sb.AppendLine("")
    sb.AppendLine("")
    sb.AppendLine("")
    ''Get Marketing Company Short Name
    Dim splitMC As String() = Split(cb3.SelectedItem, "|")
    Dim MCShort As String = Trim(splitMC(0))
    sb.AppendLine(String.Format("{0}", MCShort))
    'sb.AppendLine(String.Format("{0}", My.Settings.MarketingCompanyShortName))
    sb.AppendLine(String.Format("{0}", txtccEmail.Text))
    sb.AppendLine(String.Format("{0}", txtMessage.Text))
    sb.AppendLine(String.Format("{0}", txtMarketerName.Text))
    sb.AppendLine("")
    sb.AppendLine(String.Format("{0}", txtFirstName.Text))
    sb.AppendLine(String.Format("{0}", txtLastName.Text))
    sb.AppendLine(String.Format("{0}", txtEmail.Text))
    sb.AppendLine("123456")
    Dim spltBundles() As String

    For Each item In cb2.SelectedItems
        If Trim(item) <> "" Then
            spltBundles = Split(item, "|")
            sb.AppendLine("")
            sb.AppendLine(String.Format("{0}", Trim(spltBundles(0))))
            sb.AppendLine(String.Format("{0}", Trim(spltBundles(1))))
            sb.AppendLine("")
        End If
    Next
    sb.AppendLine("")
    sb.AppendLine("")
    sb.AppendLine(" ")
    sb.AppendLine(" ")
    Dim xmlStr = sb.ToString
    Dim int1 As Boolean = proxy.AddContractOpportunity(xmlStr.ToString, "test", "test")
    MsgBox("Made It")
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    GetCarriers()
    GetMarketingCompanies()
End Sub

Private Sub GetCarriers()
    Try
        Dim ac1 As Array
        ac1 = proxy.GetCarrierNames("test", "test")

        For Each item In ac1
            lbCarriers.Items.Add(String.Format("{0} | {1} | {2}", item.CarrierID, item.CarrierNameLong, item.CarrierNameShort))

        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
Private Sub GetMarketingCompanies()
    Try
        Dim ac1 As Array
        ac1 = proxy.GetMarketingCompanyNames("test", "test")

        For Each item In ac1
            cb3.Items.Add(String.Format("{0}   |   {1}", item.MarketingCompanyShort, item.MarketingCompanyName))
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

Private Sub lbCarriers_LostFocus(sender As Object, e As System.EventArgs) Handles lbCarriers.LostFocus
    Dim splt() As String
    Dim ac1 As Array
    cb2.Items.Clear()

    For Each item In lbCarriers.SelectedItems
        splt = Split(item, "|")
        ac1 = proxy.GetContractingBundles("test", "test", Trim(splt(0)))
        For Each Pitem In ac1
            cb2.Items.Add(Trim(splt(2)) & " | " & Pitem.FormBundleName)
        Next
    Next
End Sub
End Class

最佳答案

要非常小心簡單的方法。雖然ASP.NET Web窗體可能看起來類似於Windows窗體(連接到事件的控件),但底層機制卻非常不同。如果您還沒有這樣做,我建議您閱讀HTTP的工作原理和ASP.NET頁面的生命周期。

轉載註明原文: VB.NET - 將WinForm應用程序導出/轉換為Web ASP.NET應用程序的最簡單方法