Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8" /> <title></title> <style> h3 { text-align: center; } #TextBox1, #TextBox2, #TextBox3 { width: 150px; text-align: center; font-size: 20px; } #Label1, #Label2, #Label3, #Label4 { font-size: 20px; } #Button1, #Button2 { height: 30px; width: 155px; font-size: 20px; cursor: pointer; } .a { display: none; } .b { display: block; } </style> </head> <body> <form id="form1" runat="server"> <div> <h3>Расчет электроэнергии</h3> <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Label ID="Label1" runat="server" Text="начальные показания"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Label ID="Label2" runat="server" Text="конечные показания"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:Label ID="Label3" runat="server" Text="цена за 1 кВт/час"></asp:Label> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Расчитать" OnClick="Button1_Click" /> <br /> <br /> <asp:Button ID="Button2" runat="server" Text="Очистить" OnClick="Button2_Click" CssClass="a"/> <br /> <br /> <asp:Label ID="Label4" runat="server" Text="" CssClass="a"></asp:Label> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8" /> <title></title> <style> h3 { text-align: center; } #TextBox1, #TextBox2, #TextBox3 { width: 150px; text-align: center; font-size: 20px; } #Label1, #Label2, #Label3, #Label4 { font-size: 20px; } #Button1, #Button2 { height: 30px; width: 155px; font-size: 20px; cursor: pointer; } .a { display: none; } .b { display: block; } </style> </head> <body> <form id="form1" runat="server"> <div> <h3>Расчет электроэнергии</h3> <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Label ID="Label1" runat="server" Text="начальные показания"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Label ID="Label2" runat="server" Text="конечные показания"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:Label ID="Label3" runat="server" Text="цена за 1 кВт/час"></asp:Label> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Расчитать" OnClick="Button1_Click" /> <br /> <br /> <asp:Button ID="Button2" runat="server" Text="Очистить" OnClick="Button2_Click" CssClass="a"/> <br /> <br /> <asp:Label ID="Label4" runat="server" Text="" CssClass="a"></asp:Label> </div> </form> </body> </html>
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; class Counter { ushort showStart; ushort showEnd; decimal price; public Counter(string arg0, string arg1, string arg2) { ushort.TryParse(arg0, out showStart); ushort.TryParse(arg1, out showEnd); decimal.TryParse(arg2, out price); } public ushort ResultShow() { return (ushort)(showEnd - showStart); } public decimal Sum() { return Math.Round((decimal)(ResultShow() * price), 2); } } public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Button2.CssClass = "b"; Label4.CssClass = "b"; Counter C = new Counter(TextBox1.Text, TextBox2.Text, TextBox3.Text); Label4.Text = "Сумма = " + C.Sum().ToString(); } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = string.Empty; TextBox2.Text = string.Empty; TextBox3.Text = string.Empty; (sender as Button).CssClass = "a"; Label4.CssClass = "a"; } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; class Counter { ushort showStart; ushort showEnd; decimal price; public Counter(string arg0, string arg1, string arg2) { ushort.TryParse(arg0, out showStart); ushort.TryParse(arg1, out showEnd); decimal.TryParse(arg2, out price); } public ushort ResultShow() { return (ushort)(showEnd - showStart); } public decimal Sum() { return Math.Round((decimal)(ResultShow() * price), 2); } } public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Button2.CssClass = "b"; Label4.CssClass = "b"; Counter C = new Counter(TextBox1.Text, TextBox2.Text, TextBox3.Text); Label4.Text = "Сумма = " + C.Sum().ToString(); } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = string.Empty; TextBox2.Text = string.Empty; TextBox3.Text = string.Empty; (sender as Button).CssClass = "a"; Label4.CssClass = "a"; } }