我的代码似乎有些不对劲。感觉很麻烦,不太合乎逻辑。
有人可以让我摆脱痛苦,让我知道我写的这个有点好吗?
这很简单,当页面加载时,它会检查用户是否正在尝试更新现有书籍或创建新书籍。
这是代码:
Public Property modID As Int32
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim bookID = Request.QueryString("bookID")
If Not String.IsNullOrWhiteSpace(bookID) Then
newBook = False
Else
newBook = True
Create() 'create a new book
bookID = modID.ToString
End If
If Not newBook Then
commitData() 'saves data on form
End If
If Not IsPostBack And Not newBook Then
Page.DataBind()
populateControls() 'populate my dropdown lists and radio/checkbox controls
populateDatasets() 'load datasets to be used later
End If
End Sub
Public Sub Create()
'create a new book
newBook = False
Using dbcon As New SqlConnection(DBUtilities.ConnectionStringDefault)
dbcon.Open()
Dim cmd As New SqlCommand(CreateSQL, dbcon)
cmd.Parameters.Add(New SqlParameter("@authorID", currentUser))
modID = DirectCast(cmd.ExecuteScalar(), Int32)
End Using
navmod = NavbookFactory.Getbook(CInt(modID))
populateNewBook()
End Sub