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)


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