Self-study "2. Web pop-up calculation of commodity prices

Source: Internet
Author: User

/// <summary>///Goods is a commodity class/// </summary> Public classgoods{ PublicGoods () {//        //TODO: Add constructor logic here//    }     PublicGoods (stringNamedecimalpricedecimal) {         This. Pricedecimal =Pricedecimal;  This. Name =name; }     PublicGoods (stringNamedecimalPricedecimal,stringHtmlurl) {         This. Pricedecimal =Pricedecimal;  This. Name =name; Htmlurl=Htmlurl; }     Public decimalPricedecimal {Get;Set; }  Public stringName {Get;Set; }  Public stringHtmlurl {Get;Set; }}

First write a product class, there is a product name, price, page link address (this example is useless).

usingSystem.Collections.Generic;usingSystem.Text;/// <summary>///Order/// </summary> Public classIndent:list<goods>{     PublicIndent () {//        //TODO: Add constructor logic here//    }    /// <summary>    ///Number of orders/// </summary>     Public intNumber {Get{returnCount;} }    /// <summary>    ///Order Amount/// </summary>     Public decimalGetmoneydecimal () {decimalMoney =0; foreach(Goods Goodsinch  This) { money+=goods.        Pricedecimal; }     returnMoney ; }    /// <summary>    ///Print Order/// </summary>    /// <returns></returns>     Public Override stringToString () {StringBuilder sb=NewStringBuilder (); Sb. Append ("Order Details"); foreach(Goods Goodsinch  This) {sb. Append (goods. Name). Append ("Unit Price:"). Append (goods. Pricedecimal). Append (", "); } sb. Append ("Total:"). Append ( This.        Getmoneydecimal ()); returnsb.    ToString (); }}

Then there is an order class, the order is made up of goods, with list<goods>.

   protected voidButton1_Click (Objectsender, EventArgs e) {Indent myindent=NewIndent (); Goods goods1=NewGoods ("Sickle",2.8m); Goods Goods2=NewGoods ("Axe",5.2m);        Myindent.add (GOODS2);       Myindent.add (GOODS1); stringStr=myindent.tostring (); Response.Write ("<script>alert ('"+ str +"') </script>"); }

The last button test, just fine, haha ^_^

Note: Do this toss me for more than half an hour, is because the last alert, the middle of the string is not a newline character, I used to stringbuilder.appendline (); This method causes the string to have a newline, has been unable to alert out.

Self-study "2. Web pop-up calculation of commodity prices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.