Three layer of learning has been in contact for four or five months, the first in the learning vb.net video, began to contact, then followed the video knocked two examples. Later, when the personal computer room was reconstructed, it progressed from three to seven, and then felt that we could not just be confined to the three floor. However, those are programming under the C/S mode. To now, contact with B/s mode also one months, the first beef Brisket news release system feel is very interesting, or from the most basic start, below to look at the B/S mode, three layer is how to apply. This blog is summed up as an example of adding news. for the three layer of the whole process is very familiar to everyone, then here will not repeat, directly layer by layer to analyze. I. Thinking and finishing. u layer: Assign a value to the parameter, instantiate the method of adding news in layer B, and finally make the corresponding prompt. Layer B: Instantiate the method of adding news in layer d. Layer D: Use SqlHelper to perform parameter increment operations. two. Writing code U-Layer:
protected void btnAdd_Click (object sender, EventArgs e) { //assigns a value to the parameter string title = TxtTitle.Text.Trim (); String content = FtbContent.Text.Trim (); string caid = Ddlcategory.selectedvalue; Instantiate news entity class news n = new News (title, content, caid); Instantiate the B-tier Add News method bool B = new Newsmanager (). Insert (n); Make the appropriate judgment and prompt if (b) { Page.ClientScript.RegisterStartupScript (Page.gettype (), "message", "< Script language= ' javascript ' Defer>alert (' news added successfully! ');</script> "); } else { Page.ClientScript.RegisterStartupScript (Page.gettype (), "message", "<script language=" JavaScript ' Defer>alert (' News add failed, please contact admin! ');</script> "); } Empty title and content Txttitle.text = ""; Ftbcontent.text = ""; }
b layer :
public bool Insert (News N) { return Ndao. Insert (n); } Layer D: public bool Insert (news N) { //todo: Increase news BOOL flag = FALSE; String cmdtext = "News_insert"; Instantiation parameter sqlparameter[] paras = new sqlparameter[] { new SqlParameter ("@title", N.title), new SqlParameter ("@content", n.content), new SqlParameter ("@caid", N.caid) }; Executes the stored procedure with parameters to increase the news int res = SqlHelper. ExecuteNonQuery (Cmdtext, paras, commandtype.storedprocedure); if (res > 0) { flag = true; } return flag; }
The above are the same as our C/s mode, if the C/S mode, this will be completed. and b/S mode, we also need to further design the front page. Here are the appropriate actions for Web design: This part of the code is relatively simple, just because the first contact, may feel strange. Here is a simple explanation of the meaning of several code snippets:
1.<--Add a page title-- <%@ page title= "Add News _ admin _ Beef Brisket Press Release system" >2.<--show title-
Note: The H1, H2, H3, H4, H5, and H6 tags have the function of displaying the title (the H here is the "title (heading)" meaning). Where H1 is a first-class title, the font is the largest, H2 is a level two title, the font is slightly smaller than the first-level title, and H6 is a six-level title, which is the last level title and the smallest font .
3.<--News category drop-down list control settings-<p> news Category: <asp:dropdownlist id= "Ddlcategory" ru nat= "Server" datasourceid= "SqlDataSource1" datatextfield= "name" datavaluefield= "name" ></asp:dropdownlist > <asp:sqldatasource id= "SqlDataSource1" runat= "Server" connectionstring= "<%$ Connectionstrings:newssy Stemconnectionstring%> "selectcommand=" SELECT [Name] from [Category] "></asp:SqlDataSource> </p>4. <--News title text box control Settings-<p> News title: <asp:textbox id= "Txttitle" runat= "Server" cssclass= "Newstitle" ></ Asp:textbox></p> 5.<--News Content external controls settings-<p> news content:</p> <p> <ftb:freete Xtbox text= "" language= "ZH-CN" toolbarstyleconfiguration= "Officemac" id= "ftbcontent" width= "" Height= "" runat= " Server > </FTB:FreeTextBox> </p>
Note: The label <p> P is "paragraph (paragraph)" Meaning, that is, a text paragraph. when the front desk is well designed, we can see it through the browser part of:
Learning Experience: Although learning three layers for a long time, but in a different mode, and found a lot of fresh things, which also inspired their interest in learning. Similarly, our study still needs to accumulate, b/S study continues.
Press release system, three-tier application in B/S mode