Chapter 7 The implementation of Doking's BLOG user login page
has completed user registration. Users can now log in to the website and post notes and reply to notes.
User login, after verification is correct, the page changes to the appearance after user login.
(1) Open the template bkblog.dwt.aspx, insert the table yhtab in the left column, and design it as shown in the black circle in Figure 7-1.
(2) Insert the data set yhlog about the YH table query to verify that the user login is correct.
①Set the data set yhlog to filter, as shown in Figure 7-2.
Figure 7-1 Design drawing of table yhtab
Figure 7-2 Insert the data set yhlog
② Click the "Advanced" button to switch to the advanced data set mode, as shown in Figure 7-3.
Figure 7-3 Insert the data set yhlog
③ Click the parameter "+" to pop up the "Edit Parameters" dialog box, fill in the name as "@Logpas", and select "WChar" as the type, as shown in Figure 7-4.
Figure 7-4 Add to participate in Logpass
④Click the "Create" button to pop up the "Generate Value" dialog box, named "Logpass", and select "Form Variable" as the source, as shown in Figure 7-5.
Figure 7-5 Generate value dialog box
⑤ Click "OK" to save the settings and return to the data set yhlog dialog box. Modify the SQL statement and the modification result is shown in Figure 7-6.
Figure 7-6 Modify the data set yhlog
(3) Before the <html> tag, insert the code shown in the red circle in Figure 7-7.
Figure 7-7 Define function uselog
(4) Drag the field YHNAME under the data set yhlog in the template bkblog.dwt.aspx to any position on the page, and then drag the field YHID under the data set yhlog after it. The code is as follows:
<%# yhlog.FieldValue("YHNAME", Container) %><%# yhlog.FieldValue("YHID", Container) %>
Change the above code to:
<%# uselog(yhlog.FieldValue("YHNAME", Container),yhlog .FieldValue("YHID", Container)) %>
(5) Insert the data set bjre about the ZT table query and return the total number of study notes published by the user.
① Set the data set to "Filter", the filter field is: YHID, and the filter method is: input value, as shown in Figure 7-8.
Figure 7-8 Insert the data set bjre
② Click "Advanced", switch to the advanced data set mode, and modify the SQL as shown in Figure 7-9.
Figure 7-9 Modify the data set bjre
③Click the "Edit" button and change YHID to session("USEID") in the text field. The result is shown in Figure 7-10.
Figure 7-10 Edit the parameters of the data set bire
④ Press the "OK" key, and then press the "OK" key to complete the data set bire.
(6) Insert the data set plre about the HF table query and return the total number of study notes published by the user. Except for the different query tables, other settings are the same as the data set bjre (you can copy and paste the data set plre first, and then modify it).
(7) Drag the field Eprl100 under the data set bjre to behind the "Post a note:" in the table yhtab; drag the field Eprl100 under the data set plre to behind the "Post a reply:" in the table yhtab.
(8) Move the cursor before "User Information" in the yhtab table, and click "Bind Data" under the ASP.NET shortcut menu. The result is shown in Figure 7-11.
Figure 7-11 Insert bound data.
Keep the cursor at the red vertical line in Figure 71 and enter: session("USENAME")
(9) Return to the design view and create a hyperlink to "Publish New Notes" in the table yhtab: .. /ztfb.aspx
Create a hyperlink to "Modify Information" in table yhtab: ../yhsg.aspx
The result is shown in Figure 7-12.
Figure 7-12 Modification of table yhtab
(10) Select table yhtab, return to the code view, press "Ctrl+X" or select "Cut" in the [Edit] menu, the old method: paste it into the newly created notepad or in a Word document.
(11) Return to the design view, select the table logtab, and move the cursor to the position of the red vertical line as shown in Figure 7-13.
Figure 7-13 Move to the cursor position
(12) and enter the code, as shown in the red circle in Figure 7-14.
Figure 7-14 Insert code before the label <form>
(13) Move the cursor after the Yhlogfrm end tag </form> and enter the code, as shown in the red circle in Figure 7-15.
Figure 7-15 Insert code after tag </form>
(14) Paste the table yhtab cut in step 7 before the code <%end if%> and after <% else %>.
(15) Save the template bkblog.dwt.aspx. Open all web pages based on the bkblog.dwt.aspx template, and copy and paste the newly added data sets yhlog, bjre, and plre in the bkblog.dwt.aspx template in [Server Behavior]. Then insert the code as in step 3, and it’s OK!
(16) Browse index.aspx in IE browser, as shown in Figure 7-16 before user login, and as shown in Figure 7-17 after successful user login. Remember that ASP.NET does not support gb2312 encoding transmission. It needs to be modified. It has been mentioned in the previous chapter, so don’t tremble in the future.
Figure 7-16 Before user login
Figure 7-17
Reminder after user login: In order to facilitate readers' learning, the tutorial is divided into modules. In fact, all functions must be done in the template from the beginning, especially the data set and header loader that must be inserted into the template, because these cannot update the web page after subsequent modifications.
After logging in, users can post reply messages to each study note.
(1) Open hf.aspx, insert the form yhplfrm, and then insert the table Hftab. Insert the server text box control in the table with the ID HFNAME; insert the server text area control with the ID HFTEXT; insert the "Publish" button with the ID plbottom. Set it to disabled, and the result is shown in Figure 7-18.
Figure 7-18 Relevant design of table Hftab
(3) Bind data session ("usename") to after "name:" in table Hftab (the method is as shown in step 8 of 7.1 to bind the user name before "user information").
(4) Drag the field ZTNAME under the data set Ztre to the text box HFNAME. In the properties window of the text box HFNAME, change the initial value:
<%# Ztre.FieldValue("ZTNAME", Container) %>
to:
<%# "RE:"&Ztre.FieldValue("ZTNAME", Container) %>
(5) Select the button plbottom, right-click and select the status bar <input # plbottom>, and select "Edit Label" in the pop-up shortcut menu, as shown in Figure 7-19 Show.
Figure 7-19 Select the <input # plbottom> quick editing tag
(6) In the pop-up <input # plbottom> quick editing tag, change:
disabled="true"
to:
disabled=<%# iif((session("USENAME ")<>nothing),false,true) %>
The result is shown in Figure 7-20.
Figure 7-20 The shortcut <input # plbottom> edit label
sets the button plbottom. It is disabled before the user logs in and becomes available after the user logs in.
(4) Add the insert record server behavior, submit the value from the form yhplfrm, select the insert table as HF, and other settings are shown in Figure 7-21.
Figure 7-21 Add insert record server behavior
In Figure 7-21, you can see that the fields HFID, HFTIME, YHID, and ZTID do not get values. The field HFID is an automatic number, and the database will automatically add a value to the record; the field HFTIME has a default value set to date() in Access, so the database will automatically add today's date to the newly added record. The field YHID is the ID code of the logged in user, and the field ZTID is the ID of the note to be published. Therefore, the ID code of the logged-in user must be added to the field YHID, and the ID code of the note to be published must be added to the field ZTID.
(5) Return to the code view and find the code for inserting the record (dkconn, HF), as shown in the black selected part in Figure 7-22.
Figure 7-22 Find the code for inserting records (dkconn, HF)
(6) Change the code:
CommandText='<%# "INSERT INTO HF (HFNAME, HFTEXT) VALUES (?, ?,)" %>'
to:
CommandText ='<%# "INSERT INTO HF (HFNAME, HFTEXT, ZTID, YHID) VALUES (?, ?, ?, ?)" %>'
(7) Add parameters in order:
<Parameter Name="@ZTID" Value= '<%# Ztre.FieldValue("ZTID", Container) %>' Type="Integer" />
<Parameter Name="@YHID" Value='<%# SESSION("USEID") %>' Type=" Integer" />
The result is shown in Figure 7-23.
Figure 7-23 Modification results of inserting record (dkconn, HF) code
(8) Before publishing the reply message, the reply title and reply content must be verified to prevent the publishing of reply messages with empty titles or empty content. Refer to the method of inserting the RequiredFieldValidato validation control in Section 6.2, and add the RequiredFieldValidato validation control to the text box HFNAME and the text area control HFTEXT respectively.
(9) When the user posts a reply message, the total number of replies in the study notes must be automatically increased by 1, that is, the HFZS field under the ZT table must be automatically increased by 1.
① In the [Server Behavior] panel, insert the "Update Record" server behavior, set the update table to ZT, temporarily set the submitted value from the form yhplfrm, temporarily set: 'HFZS' gets the value from 'HFTEXT' (as 'Integer') ;Temporary assumption: 'ZTID' uses 'HFTEXT' as 'Integer' to select records
② Why are they all temporary? That is to let Dreamweaver automatically generate some code first, so that it can be modified later. First switch to the code view, find the original code of the update record (dkconn,ZT), and find the code:
<Parameter Name="@HFZS" Value='<%# IIf((Request.Form("HFTEXT") <> Nothing ), Request.Form("HFTEXT"), "") %>' Type="Integer" />
<Parameter Name="@ZTID" Value='<%# IIf((Request.Form("HFTEXT") < > Nothing), Request.Form("HFTEXT"), "") %>' Type="Integer" />
Change it to:
<Parameter Name="@HFZS" Value='<%# Ztre.FieldValue(" HFZS", Container)+1 %>' Type="Integer" />
<Parameter Name="@ZTID" Value='<%# session("ztanw") %>' Type="Integer" />
(10) Save hf.aspx.
After logging in, users can publish new study notes in addition to reply messages.
(1) Create a new dynamic web page ztfb.aspx generated from the template bkblog.dwt.aspx, and insert a table ztfb with one column and five rows in the mainbody editable area.
(2) Add the data set zthb, set the filter to YHID, and set the parameter to the stage variable USENAME. The design is shown in Figure 7-24.
Figure 7-24 Adding the data set zthb
(3) Drag the relevant fields under the data set to the table ztfb. For the method, refer to the method in Section 4.2.
(4) Open hf.aspx, copy the form yhplfrm, paste it into the fifth row of table zthb in the web page ztfb.aspx, clear the text box HFNAME, and make the necessary modifications. The result is shown in Figure 7-25.
Figure 7-25 Design of table ztfb
(2) Rename the text box HFNAME to ZTNAME and the text area HFTEXT to ZTTEXT.
(3) Let the first, second, and third rows of the table zthb be the repeated areas of the data set zthb, and then insert the data set navigation in the fourth row of the table.
(4) Insert the list/menu LMID, click the list value in its properties window, and in the pop-up list value dialog box, enter the project label as: design item; the value as: 1, press the "OK" key, as shown in Figure 7- 26 shown.
Figure 7-26 LMID list value dialog box
(5) Keep list/menu LMIDl selected, switch to the code view, find the original code of list/menu LMID, drag the field LMID under the data set menuda, and replace the data with value equal to 1 , as shown in Figure 7-27.
Figure 7-27 Drag and drop the field LMID under the data set menuda
(6) Drag the field LM under the data set menuda and replace the "design item". The result is shown in Figure 7-28.
Figure 7-28 Drag the field LM under the data set menuda
(7) Select the code in the red circle in Figure 7-3-5 and define it as a repeating area of the data set menuda. The result is shown in Figure 7-29.
Figure 7-29 Define the data set menuda repeating area in the list
(8) to add the "Insert Record" server behavior, and its settings are shown in Figure 7-30.
Figure 7-30 Add "Insert Record" server behavior
(9) Switch to the code view, find the original code of insert record (dkconn, ZT), find the code:
CommandText='<%# "INSERT INTO ZT (LMID, ZTNAME, ZYTEXT) ) VALUES (?, ?, ?)" %>'
Change to:
CommandText='<%# "INSERT INTO ZT (LMID, ZTNAME, ZYTEXT,YHID) VALUES (?, ?, ?, ?)" %>'
( 10) Add parameters:
<Parameter Name="@YHID" Value='<%# session("USEID") %>' Type="Integer" />
The result is shown in Figure 7-31.
Figure 7-31 The original code for inserting record (dkconn, ZT) modification
The design of the page for modifying user information is basically the same as the design of the user registration page.
(1) Open the registration page yhlogok.aspx, save it as yhsg.aspx, and make appropriate modifications. The result is shown in Figure 7-32.
Figure 7-32 yhsg.aspx page design
(2) Delete the "Insert record (dkconn, YH)" server behavior and add the data set yhsg, as shown in Figure 7-33.
Figure 7-33 Insert the data set yhsg
(3) Bind the relevant fields under the data set yhsg to the corresponding text box. The result is shown in Figure 7-34.
Figure 7-34 Bind dynamic text to the relevant text box
(4) Add update record server behavior, temporarily set: 'YHID' and 'YHNAME' as 'Integer' to select records, the result is shown in Figure 7-35.
Figure 7-35 Add update record server behavior
(5) In the original code of update record, find the code:
<Parameter Name="@YHID" Value='<%# IIf((Request.Form("YHNAME") <> Nothing), Request.Form("YHNAME"), "") %>' Type="Integer" />
Change it to:
<Parameter Name="@YHID" Value='<%# IIf((Not Session( "USEID") Is Nothing), Session("USEID"), "") %>' Type="Integer" />
(6) Save yhsg.aspx.