vb 框架設計

   這2天一直在研究老系統,老系統是VB寫的,就把老系統的框架寫下把,就當是隨筆了


首先 <!--#include virtual="/include/Common.aspx"--> '引用文件

      <%@ Assembly Src="/code/EDI.vb"%>’程序集,可以使用edi.vb中的方法
   <%@ Import Namespace="EDI"%>‘引用空間

‘聲明全局變量

    Dim FormColl As NameValueCollection ‘NameValueCollection 是一個集合,是個1對多的集合。他有點類似hashtable 但是hashtable是一個key 對於一個value.

NameValueCollection  一個key 可以對應多個value.

NameValueCollection  方法: Get 取出全部的值 eg: FormColl .get("key")

                                                    GetValues:取出一個值。 eg: FormColl .getvalues("key")

                                                    Set 指定一個值 。eg: theColl.Set("Lock_flag", "1")

                                                   Add:增加一個值。eg: theColl.Add("Lock_flag", "1")


Page_Load 進程。主要處理提交表單的時候數據是不是正確,Ispostback函數可以讓程序更人性點。

 Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim tmpResult As String = ""
        Dim tmpEDIColl As NameValueCollection = New NameValueCollection
        FormColl = New NameValueCollection
        
        If IsPostBack = True Or Request.HttpMethod = "POST" Then
            If GetForm(FormColl) = True Then    
                Dim EDIGeneratorObj As EDI.EDIGenerator
                EDIGeneratorObj = New EDI.EDIGenerator(Core)
                tmpResult = EDIGeneratorObj.GetEDI(FormColl.Get("edi_code"), tmpEDIColl)
                If tmpResult <> "" Then
                    Session("WarningMessage") = tmpResult
                    Response.Redirect(Application("WarningPage"))
                End If

                tmpResult = EDIGeneratorObj.GenerateEDI(FormColl, tmpEDIColl.Get("Log_file"), CStr(Session("Operator_code")))
                If tmpResult <> "" Then
                    Session("WarningMessage") = tmpResult
                    Response.Redirect(Application("WarningPage"))
                End If
                ''Send successfully,then redirect to view edi log
                Response.Redirect("/Working/Sharing/EDILogSelect.aspx" & _
                "?id=" & Server.UrlEncode(tmpEDIColl.Get("Row_id")) & _
                "&type=" & Server.UrlEncode(tmpEDIColl.Get("Bill_type")))
            End If
        Else
            EDIConfigRecord = New EDI.EDIConfig(EDICode, Core)
            tmpResult = SetForm(FormColl, CargoColl)
            If tmpResult <> "" Then
                Session("WarningMessage") = tmpResult
                Response.Redirect(Application("WarningPage"))
                Return
            End If
            'check page lock condition
            If IsReadonly = True Then
                ReadonlySign = " readonly=""readonly"" "
                DisabledSign = " disabled=""disabled"" "
            End If
        End If
    End Sub

GetForm 方法驗證提交數據的正確性並格式化

SetForm 初始化數據。


Request.QueryString:頁面url傳值;

Request.Form 頁面內表單數據傳值;

Byref 傳的是地址   Byval 傳的是值

eg: ByRef  theColl  As  NameValueCollection  theColl 的值可以修改

eg:Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章