Академический Документы
Профессиональный Документы
Культура Документы
1. Create Hit Counter Application in ASP.NET to find number of visitors on your site and also find how
many time page is refresh. Code:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Number of time page Refresh : "></asp:Label><asp:Label ID="Label3" runat="server" Text=""></asp:Label><br /> <asp:Label ID="Label2" runat="server" Text="Number of user : "></asp:Label><asp:Label ID="Label4" runat="server" Text=""> </asp:Label> <asp:Button ID="Button1" runat="server" Text="Button" /> </div> </form> </body> </html>
Codefile:using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { static int refresh = 0; static int numberofuser; String a; protected void Session_Start(Object sender, EventArgs e) { numberofuser++; } protected void Page_Load(object sender, EventArgs e)
{ a=Label4.Text; numberofuser =1 ; if (IsPostBack) { refresh++; } display(); } public void display() { Label3.Text = refresh.ToString(); Label4.Text = numberofuser.ToString(); } }
Output:-
2. Create a web form to collect employee information: Field Contro l Functionality EmpID TextBox Ename TextBox State ComboBox Set Autopostback to fill field City City ComboBox JoinDate TextBox Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT state FROM state"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [city] FROM [state] WHERE ([state] = @state)"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" DefaultValue="select city" Name="state" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:SqlDataSource> <asp:Label ID="Label1" runat="server" Text="EmpID "></asp:Label> : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Label ID="Label2" runat="server" style="position: relative" Text="Label" Visible="False" ForeColor="#FF3300"></asp:Label> <br /> <asp:Label ID="Label3" runat="server" Text="EmpName "></asp:Label> : <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <br />
<asp:Label ID="Label4" runat="server" Text="State"></asp:Label> : :<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="state" DataValueField="state"> </asp:DropDownList> <br /> <asp:Label ID="Label5" runat="server" Text="City"></asp:Label> : <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="city" DataValueField="city"> </asp:DropDownList> <br /> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <asp:Label ID="Label6" runat="server" Text="joindate"></asp:Label> :<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox3"> </asp:CalendarExtender> <br /> <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" /> </div> </div> </form> </body> </html>
Codefile:using using using using using using using using using using using System; System.Configuration; System.Data; System.Linq; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.HtmlControls; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Xml.Linq;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label2.Text = ""; string a = TextBox1.Text; string b = a.Substring(0, 1).ToString(); if (!(b.Equals("E")))
Output:-
3. Create a Master Page & Style Sheet to implement for your web portal. MasterPage.master page:<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="default.css" rel="stylesheet" type="text/css" /> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <div id="logo"> <h1> ASP.NET</h1> <h2> Created by computer student</h2> </div> <div id="menu"> <ul> <li class="active first"><a href="#" title="">Home</a></li> <li><a href="#" title="">Blogs</a></li> <li><a href="#" title="">Photos</a></li> <li><a href="#" title="">About</a></li> <li><a href="#" title="">Contact</a></li> </ul> </div> <div class="main"> <asp:ContentPlaceHolder ID="MainContent" runat="server"/> </div> <div id="footer"> <p id="legal">Best of luxk.....</p> <p id="links"></p> </div>
Default.aspx :<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content> <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="Server"> <div id="page"> <div id="content"> <div id="welcome" class="post"> <div class="title"> <h2> Welcome to V.G.e.C.</h2> </div> <h3 class="date"> <span class="month">Oct.</span> <span class="day">17</span><span class="year">, 2011</span></h3> <div class="meta"> <p> For demo stration only in practical 3</p> </div> <div class="story"> <p> <img src="images/logo.png" alt="" height="112" class="left" /> <em>Vishwakarma Government Engineering College,<br /> Visat Three Roads,Sabarmati - Koba Highway,<br /> Chandkheda, Ahmedabad - 382424<br /> Gujarat,India<br /> Ph. (079) 23293866, 23293006 </em> </p> </div> </div> <div id="example" class="post"> <div class="title"> <h2> faculty details :</h2> </div> <h3 class="date"> Oct<span class="month">.</span> <span class="day">2</span><span class="year">, 2011</span></h3> <p> Demosration </p> <div class="story"> <p> <asp:Image ID="Image1" runat="server" class="left" Height="150px" Width="150px" ImageUrl="~/images/27_9_11_birthday_edited-1.jpg" /> <asp:Label ID="Label1" runat="server" Text="Name : " Font-Size="Larger" ForeColor="#FF3300"></asp:Label> <asp:Label ID="Label2" runat="server" Text="Label" Font-Size="Larger" ForeColor="White"></asp:Label><br /> <asp:Label ID="Label3" runat="server" Text="Designation : " Font-Size="Medium" ForeColor="#FF3300"></asp:Label> <asp:Label ID="Label4" runat="server" Text="Label" Font-Size="Medium" ForeColor="White"></asp:Label><br /> <asp:Label ID="Label5" runat="server" Text="Qualification : " Font-Size="Medium" ForeColor="#FF3300"></asp:Label> <asp:Label ID="Label6" runat="server" Text="Label" Font-Size="Medium" ForeColor="White"></asp:Label><br /> <asp:Label ID="Label7" runat="server" Text="Area of Intrest : " Font-Size="Medium" ForeColor="#FF3300"></asp:Label> <asp:Label ID="Label8" runat="server" Text="Label" Font-Size="Medium" ForeColor="White"></asp:Label><br />
</p> </div> </div> </div> <!-- end #content --> <div id="sidebar"> <div id="login" class="boxed"> <div class="title"> <h2> Subscribe Account</h2> </div> <div class="content"> <form id="form1" method="post" action="#"> <fieldset> <legend>Sign-In</legend>f<label for="inputtext1">First name :</label> <input id="inputtext1" type="text" name="inputtext1" value="" /> <label for="inputtext2"> Email Id:</label> <input id="inputtext2" type="password" name="inputtext2" value="" /> <input id="inputsubmit1" type="submit" name="inputsubmit1" value="Subscribe" /> </fieldset> </form> </div> </div> <!-- end #login --> <div class="boxed"> <div class="title"> <h2> faculties</h2> </div> <div class="content"> <ul class="list1"> <li class="first"> <asp:Button ID="Button1" runat="server" Text="Hetal B.Pandya" BorderColor="Black" BorderStyle="None" Font-Bold="True" ForeColor="White" BackColor="Black" onclick="change" /> </li> <li> <asp:Button ID="Button2" runat="server" Text="Amita V.Shah" BorderColor="Black" BorderStyle="None" Font-Bold="True" ForeColor="White" BackColor="Black" onclick="change" /></li> <li> <asp:Button ID="Button3" runat="server" Text="Uttam D.Chauhan" BorderColor="Black" BorderStyle="None" Font-Bold="True" ForeColor="White" BackColor="Black" onclick="change" /></li> <li> <asp:Button ID="Button4" runat="server" Text="Sanjay P.Patel" BorderColor="Black" BorderStyle="None" Font-Bold="True" ForeColor="White" BackColor="Black" onclick="change" /></li> <li> <asp:Button ID="Button5" runat="server" Text="Uday A. Yadav" BorderColor="Black" BorderStyle="None" Font-Bold="True" ForeColor="White" BackColor="Black" onclick="change" /></li> <li> <asp:Button ID="Button6" runat="server" Text="Nakul R.Dave" BorderColor="Black" BorderStyle="None" Font-Bold="True" ForeColor="White" BackColor="Black" onclick="change" /></li> </ul>
default.css
* { margin: 0; padding: 0; } body { background: #000000 url(images/img1.jpg) no-repeat center top; font: normal 13px Georgia, "Times New Roman", Times, serif; color: #4E515B; } h1, h2, h3 { color: #CDCDE2; } p, blockquote, ul, ol { text-align: justify; } blockquote { margin-left: 3em; } ul { margin-left: 3em; } ul li { } .list1 { margin: 0; padding: 0; list-style: none; } .list1 li { padding: 8px 0; background: url(images/img5.gif) repeat-x left top; } .list1 .first li { background: none; } ol { margin-left: 3em; } ol li { } a { text-decoration: none; color: #CDCDE2; } a:hover { text-decoration: underline; color: #FFFFFF; } img { border: none;
} img.left { float: left; margin: 5px 5px 0 0; width: 107px; } img.right { float: right; margin: 5px 0 0 15px; } .boxed { margin-bottom: 20px; } .boxed .title { padding: 5px 0; background: url(images/img5.gif) repeat-x left bottom; } .boxed .title h2 { background: url(images/img2.gif) no-repeat right center; text-transform: uppercase; font-size: 100%; } .boxed .content { padding: 20px 20px 40px 20px; } .post { } .post .title { padding: 5px 0; background: url(images/img5.gif) repeat-x left bottom; } .post .title h2 { background: url(images/img2.gif) no-repeat right center; text-transform: uppercase; font-size: 100%; } .post .date { float: left; width: 100px; height: 25px; padding-top: 15px; background: url(images/img5.gif) repeat-y right top; text-align: center; font-size: 9px; } .post .date .month { } .post .date .day { } .post .date .year { } .post .meta { float: left; width: 300px;
height: 32px; padding: 8px 0 0 20px; font-size: 9px; } .post .meta p { } .post .story { clear: both; padding: 20px; background: url(images/img5.gif) repeat-x; } .post .story p, .post .story blockquote, .post .story ul, .post .story ol { margin-bottom: 1.5em; line-height: 180%; width: 435px; } #logo { width: 700px; height: 220px; margin: 0 auto; } #logo h1 { margin: 0; padding: 60px 0 0 325px; text-transform: uppercase; letter-spacing: -5px; font-size: 72px; font-weight: normal; } #logo h2 { margin: -10px 0 0 0; padding: 0 0 0 325px; text-transform: uppercase; letter-spacing: 2px; font-size: 18px; font-weight: normal; } #logo a { text-decoration: none; color: #000000; } #page { width: 700px; margin: 0 auto; } #content { float: right; width: 387px; padding: 0 20px; background: url(images/img4.gif) no-repeat; } #sidebar { float: left; width: 200px; padding: 0 20px; background: url(images/img3.gif) no-repeat right top; }
#login form { } #login fieldset { border: none; } #login legend { display: none; } #login label { font-size: x-small; font-weight: bold; } #login input { margin-bottom: 5px; padding: 2px 5px; border: none; font-family: Georgia, "Times New Roman", Times, serif; } #inputtext1, #inputtext2 { width: 150px; } #inputsubmit1 { width: 100px; background: transparent url(images/img2.gif) no-repeat left top; color: #CDCDE2; text-transform: uppercase; letter-spacing: 2px; font-size: 10px; font-weight: bold; text-align:right; } #menu { width: 700px; height: 95px; margin: 0 auto; } #menu ul { margin: 0; padding-left: 20px; list-style: none; } #menu li { display: inline; } #menu a { display: block; float: left; height: 34px; padding: 16px 30px 0 40px; text-decoration: none; text-transform: uppercase; font-size: 16px; color: #4E515B; } #menu a:hover { background: #000000 url(images/img2.gif) no-repeat 15px 50%; color: #CDCDE2;
} #menu .first a { border: none; } #menu .active a { color: #FFFFFF; } #footer { clear: both; width: 660px; margin: 0 auto; padding: 20px; background: url(images/img5.gif) repeat-x; } #footer p { margin: 0; text-align: right; font-size: x-small; }
Default.aspx.cs file:using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void change(object sender, EventArgs e) { if (sender.Equals(Button1)) { Image1.ImageUrl = "~/images/01.jpg"; Label2.Text=Button1.Text; Label4.Text="Assistant Professor"; Label6.Text="B.E.(Computer Engg)"; Label8.Text="DBMS"; } else if(sender.Equals(Button2)) { Image1.ImageUrl = "~/images/02.jpg"; Label2.Text=Button2.Text; Label4.Text="Assistant Professor"; Label6.Text="B.E.(Computer Engg)"; Label8.Text="Algorithm Analysis"; } else if(sender.Equals(Button3)) { Image1.ImageUrl = "~/images/03.jpg"; Label2.Text=Button3.Text; Label4.Text="Assistant Professor"; Label6.Text="M.E.(Computer Engg)";
Label8.Text = "DBMS & Data Mining"; } else if (sender.Equals(Button4)) { Image1.ImageUrl = "~/images/04.jpg"; Label2.Text = Button4.Text; Label4.Text = "Assistant Professor"; Label6.Text = "M.E.(Computer Engg)"; Label8.Text = "Artificial Intelligence and Data Mining"; } else if (sender.Equals(Button5)) { Image1.ImageUrl = "~/images/05.jpg"; Label2.Text = Button5.Text; Label4.Text = "Assistant Professor"; Label6.Text = "M.E.(Computer Engg)"; Label8.Text = "Software Architecture(SOA)"; } else if (sender.Equals(Button6)) { Image1.ImageUrl = "~/images/06.jpg"; Label2.Text = Button6.Text; Label4.Text = "Assistant Professor"; Label6.Text = "M.E.(Computer Engg)"; Label8.Text = "Network Security and Data Mining"; } } }
Output:-
4. Create a interest calculator in ASP.NET to Display the output on other page: Page1: Fields: Validation Principle Amount Numerical Value only Rate of Interest Numerical Value (Range 0 to 100) Starting Date Date Value only Ending Date Date Value only & Greater then Starting Date
Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <strong><span style="text-decoration: underline"><em>Calculate Simple Interest using the Web Service<br /> </em></span></strong> <br /> <asp:Label ID="Label1" runat="server" Text="Principal" Width="66px"></asp:Label> <asp:TextBox ID="txtPrincipal" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label2" runat="server" Text="Rate" Width="63px"></asp:Label> <asp:TextBox ID="txtRate" runat="server"></asp:TextBox><br /> <br /> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDuration"> </asp:CalendarExtender> <asp:Label ID="Label3" runat="server" Text="strat date" Width="63px"></asp:Label> <asp:TextBox ID="txtDuration" runat="server"></asp:TextBox> <br /> <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="TextBox1"> </asp:CalendarExtender> <asp:Label ID="Label6" runat="server" Text="end date" Width="63px"></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <br />
<asp:Label ID="Label4" runat="server" Text="Simple Interest" Width="105px"></asp:Label> <asp:TextBox ID="txtSimpleInterest" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label5" runat="server" Width="66px"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Calculate Simple Interest" Width="220px" OnClick="Button1_Click" /> </div> </form> </body> </html> Default.aspx.cs using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string m1 = txtDuration.Text.Substring(0, 2); string m2 = TextBox1.Text.Substring(0, 2); string y1 = txtDuration.Text.Substring(7, 9); string y2 = TextBox1.Text.Substring(7, 9); double a1=System.Convert.ToDouble(m1); double a2 = System.Convert.ToDouble(m2); double b1 = System.Convert.ToDouble(y1); double b2 = System.Convert.ToDouble(y2); if (b1>b2) { Label5.Text = "please select appropriate end date"; } else if ((b1 == b2) && (a1 > a2)) { Label5.Text = "please select appropriate end date"; } else { Double a = (b2 - b1) * 12; a += (a2 - a1); Double pri = System.Convert.ToDouble(txtPrincipal.Text); Double inte = System.Convert.ToDouble(txtRate.Text); Double b = (1 + pri / 1200); Double interest=pri*System.Math.Pow(b,inte); txtSimpleInterest.Text = interest.ToString(); } }
5. Create a Menu Driven database application in ASP.NET using SQL Server for inventory control. Table Structure: Product_Master(ProductID(Primary Key), ProductName, PackingSize, ReorderLevel) Purchse (PurchaseID, ProductID(Foreign Key), PurchaseQty, PurchaseDate, PruchasePrice) Sales(SalesID, ProductID(ForeignKey), SalesQty, SalesDate, SalesPrice) Web Form Functionality: Product Form: Add, Delete, Search(by ProductName), Update Records Purchase Form: Add, Delete, Search(by Purchase ID), Update Records Sales Form: Add, Delete, Search, Update Records. Sales.aspx
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head runat="server"> <title></title> <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" /> <asp:ContentPlaceHolder ID="HeadContent" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form runat="server"> <div class="page"> <div class="header"> <div class="title"> <h1> My ASP.NET Application </h1> </div> <div class="clear hideSkiplink"> <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal"> <Items> <asp:MenuItem Text="Practical 4" Value="File"> <asp:MenuItem Text="Product Form" NavigateUrl="proin.aspx"> </asp:MenuItem> <asp:MenuItem Text="Purchase Form" Value="Open" NavigateUrl="pur.aspx"> </asp:MenuItem> <asp:MenuItem Text="Sales Form" Value="New" NavigateUrl="Sales.aspx"> </asp:MenuItem> </asp:MenuItem> <asp:MenuItem Text="Practical 5" Value="Edit"> <asp:MenuItem Text="Sales Records Date wise" NavigateUrl="Sales Records.aspx"></asp:MenuItem> <asp:MenuItem Text="Purchase Records Date wise" NavigateUrl="~/Purchase Records.aspx"></asp:MenuItem> <asp:MenuItem Text="Product Stock Record" NavigateUrl="~/Product Stock.aspx"></asp:MenuItem> </asp:MenuItem> </Items> </asp:Menu>
</div> </div> <div class="main"> <asp:ContentPlaceHolder ID="MainContent" runat="server"> </asp:ContentPlaceHolder> </div> <div class="clear"> </div> </div> <div class="footer"> </div> </form> </body> </html>
pur.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="pur.aspx.cs" Inherits="prou" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <p> <asp:Label ID="Label5" runat="server" Text="PurchaseID"></asp:Label> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label6" runat="server" Text="PurchaseQty"></asp:Label> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label7" runat="server" Text="PurchaseDate"></asp:Label> <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label8" runat="server" Text="PruchasePrice"></asp:Label> <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox> </p> <p> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Product_Master]" DeleteCommand="DELETE FROM Purchse WHERE PurchaseID= @a)" InsertCommand="INSERT INTO Purchse(PurchaseID,PurchaseQty,PurchaseDate, PruchasePrice) VALUES (@a,@b,@c,@d)"
UpdateCommand="UPDATE Purchse SET PurchaseQty= @b, PurchaseDate= @c, PruchasePrice=@d WHERE (PurchaseID=@ a)"> <DeleteParameters> <asp:ControlParameter ControlID="TextBox5" Name="a" PropertyName="Text" </DeleteParameters> <InsertParameters> <asp:ControlParameter ControlID="TextBox5" Name="a" PropertyName="Text" <asp:ControlParameter ControlID="TextBox6" Name="b" PropertyName="Text" <asp:ControlParameter ControlID="TextBox7" Name="c" PropertyName="Text" <asp:ControlParameter ControlID="TextBox8" Name="d" PropertyName="Text"
/>
</InsertParameters> <UpdateParameters> <asp:ControlParameter <asp:ControlParameter <asp:ControlParameter <asp:ControlParameter <asp:Parameter /> </UpdateParameters> </asp:SqlDataSource> </p>
<asp:Button ID="Button1" runat="server" Text="insert" onclick="Button1_Click" /> <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="delete" /> <asp:Button ID="Button3" runat="server" Text="update" onclick="Button3_Click" style="height: 26px" /> </asp:Content>
pur.aspx
using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;
public partial class prou : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //DateTime d1=new DateTime(); //string dd = d1.Day.ToString(); //string mm = d1.Month.ToString(); //string yyyy = d1.Year.ToString(); //string d2 = dd + "/" + mm + "/" + yyyy; TextBox7.Text = System.DateTime.Today.ToShortDateString(); } protected void Button1_Click(object sender, EventArgs e) { SqlDataSource1.Insert(); } protected void Button2_Click(object sender, EventArgs e) { SqlDataSource1.Delete(); } protected void Button3_Click(object sender, EventArgs e) { SqlDataSource1.Update(); } }
Sales.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Sales.aspx.cs" Inherits="Sales" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <p> <asp:Label ID="Label5" runat="server" Text="SalesID"></asp:Label> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label6" runat="server" Text="SalesQty"></asp:Label> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label7" runat="server" Text="SalesDate"></asp:Label> <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label8" runat="server" Text="SalesPrice"></asp:Label> <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox> </p> <p> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Sales]" DeleteCommand="DELETE FROM Sales WHERE (SalesID = @a)" InsertCommand="INSERT INTO Sales(SalesID, SalesQty, SalesDate, SalesPrice) VALUES (@a,@b,@c,@d)" UpdateCommand="UPDATE Sales SET SalesQty = @b, SalesDate = @c, SalesPrice =@d WHERE (SalesID =@ a)"> <DeleteParameters> <asp:ControlParameter ControlID="TextBox5" Name="a" PropertyName="Text" /> </DeleteParameters> <InsertParameters> <asp:ControlParameter ControlID="TextBox5" Name="a" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox6" Name="b" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox7" Name="c" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox8" Name="d" PropertyName="Text" /> </InsertParameters> <UpdateParameters> <asp:ControlParameter ControlID="TextBox5" Name="a" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox6" Name="b" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox7" Name="c" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox8" Name="d" PropertyName="Text" /> <asp:Parameter /> </UpdateParameters> </asp:SqlDataSource> </p> <asp:Button ID="Button1" runat="server" Text="insert" onclick="Button1_Click" /> <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="delete" /> <asp:Button ID="Button3" runat="server" Text="update" /> </asp:Content>
Sales.aspx.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI;
using System.Web.UI.WebControls; public partial class Sales : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { TextBox7.Text = System.DateTime.Today.ToShortDateString(); } protected void Button1_Click(object sender, EventArgs e) { SqlDataSource1.Insert(); } protected void Button2_Click(object sender, EventArgs e) { SqlDataSource1.Delete(); } protected void Button3_Click(object sender, EventArgs e) { SqlDataSource1.Update(); } }
proin.aspx
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="proin.aspx.cs" Inherits="_Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <p> <asp:Label ID="Label5" runat="server" Text="ProductID"></asp:Label> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label6" runat="server" Text="ProductName"></asp:Label> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label7" runat="server" Text="PackingSize"></asp:Label> <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="Label8" runat="server" Text="ReorderLevel"></asp:Label> <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox> </p> <p> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Product_Master]" DeleteCommand="DELETE FROM Product_Master WHERE (ProductID = @a)" InsertCommand="INSERT INTO Product_Master(ProductID, ProductName, PackingSize, ReorderLevel) VALUES (@a,@b,@c,@d)" UpdateCommand="UPDATE Product_Master SET ProductName = @b, PackingSize = @c, ReorderLevel =@d WHERE (ProductID =@ a)"> <DeleteParameters> <asp:ControlParameter ControlID="TextBox5" Name="a" PropertyName="Text" />
</DeleteParameters> <InsertParameters> <asp:ControlParameter <asp:ControlParameter <asp:ControlParameter <asp:ControlParameter </InsertParameters> <UpdateParameters> <asp:ControlParameter <asp:ControlParameter <asp:ControlParameter <asp:ControlParameter <asp:Parameter /> </UpdateParameters> </asp:SqlDataSource> </p>
<asp:Button ID="Button1" runat="server" Text="insert" onclick="Button1_Click" /> <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="delete" /> <asp:Button ID="Button3" runat="server" Text="update" /> </asp:Content> proin.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data.Sql; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { SqlDataSource1.Insert(); } protected void Button2_Click(object sender, EventArgs e) { SqlDataSource1.Delete(); } }
Output:-
6. Generate the following output using above Database Structure: Sales Records Date wise Purchase Records Date wise Product Stock Record Product Stock.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Product Stock.aspx.cs" Inherits="Product_Stock" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Product_Master]"></asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> <asp:BoundField DataField="PackingSize" HeaderText="PackingSize" SortExpression="PackingSize" /> <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" /> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> </asp:Content>
Purchase Records.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Purchase Records.aspx.cs" Inherits="Purchase_Records" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Purchse] ORDER BY [PurchaseDate]"></asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:BoundField DataField="PurchaseID" HeaderText="PurchaseID" SortExpression="PurchaseID" /> <asp:BoundField DataField="PurchaseQty" HeaderText="PurchaseQty" SortExpression="PurchaseQty" /> <asp:BoundField DataField="PurchaseDate" HeaderText="PurchaseDate" SortExpression="PurchaseDate" /> <asp:BoundField DataField="PruchasePrice" HeaderText="PruchasePrice" SortExpression="PruchasePrice" /> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> </asp:Content>
Sales Records.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Sales Records.aspx.cs" Inherits="Sales_Records" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Sales] ORDER BY [SalesDate]"></asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:BoundField DataField="SalesID" HeaderText="SalesID" SortExpression="SalesID" /> <asp:BoundField DataField="SalesQty" HeaderText="SalesQty" SortExpression="SalesQty" /> <asp:BoundField DataField="SalesDate" HeaderText="SalesDate" SortExpression="SalesDate" /> <asp:BoundField DataField="SalesPrice" HeaderText="SalesPrice" SortExpression="SalesPrice" /> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> </asp:Content> Output:-
7. Create a web service to Calculate Simple and Compound Interest and implement web service in ASP.NET application WebService.asmx
<%@ WebService Language="C#" CodeBehind="~/App_Code/WebService.cs" Class="WebService" %>
WebService.cs using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class WebService : System.Web.Services.WebService { public WebService () { } [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public double CalculateSimpleInterest(double principal, double rate, int duration) { double SI;
SI = principal * rate * duration / 100; return SI; } [WebMethod] public double Calculatecompound(double principal, double rate, int duration) { double sI; rate = (1 + rate / 100); sI = principal *System.Math.Pow(rate,duration); return sI-principal; }
Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <strong><span style="text-decoration: underline"><em>Calculate Simple Interest using the Web Service<br /> </em></span></strong> <br /> <asp:Label ID="Label1" runat="server" Text="Principal" Width="66px"></asp:Label> <asp:TextBox ID="txtPrincipal" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label2" runat="server" Text="Rate" Width="63px"></asp:Label> <asp:TextBox ID="txtRate" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label3" runat="server" Text="Duration" Width="63px"></asp:Label> <asp:TextBox ID="txtDuration" runat="server"></asp:TextBox> <br /> <br /> <asp:Label ID="Label4" runat="server" Text="Simple Interest" Width="105px"></asp:Label> <asp:TextBox ID="txtSimpleInterest" runat="server"></asp:TextBox><br />
<br /> <asp:Label ID="Label5" runat="server" Width="66px"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Calculate Simple Interest" Width="220px" onclick="Button1_Click" /> </div> </form> </body> </html> Default.aspx.cs using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { localhost.WebService ws = new localhost.WebService(); ws.EnableDecompression = true; Double SI = 0; if ((txtPrincipal.Text == "") || (txtRate.Text == "") || (txtDuration.Text == "")) { Label5.Text = "Unable to calculate simple interest"; } else { SI = ws.CalculateSimpleInterest(System.Convert.ToDouble(txtPrincipal.Text), System.Convert.ToDouble(txtRate.Text), System.Convert.ToInt32(txtDuration.Text)); txtSimpleInterest.Enabled = true; txtSimpleInterest.Text = SI.ToString(); Label5.Text = ""; } } } Default2.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head>
<body> <form id="form1" runat="server"> <div> <strong><span style="text-decoration: underline"><em>Calculate<span style="fontsize:11.0pt;line-height:115%; font-family:"Calibri","sans-serif";mso-fareast-fontfamily:Calibri;mso-bidi-font-family: Calibri;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language: AR-SA"> Compound </span> Interest using the Web Service<br /> </em></span></strong> <br /> <asp:Label ID="Label1" runat="server" Text="Principal" Width="66px"></asp:Label> <asp:TextBox ID="txtPrincipal" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label2" runat="server" Text="Rate" Width="63px"></asp:Label> <asp:TextBox ID="txtRate" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label3" runat="server" Text="Duration" Width="63px"></asp:Label> <asp:TextBox ID="txtDuration" runat="server"></asp:TextBox> <br /> <br /> <asp:Label ID="Label4" runat="server" Text="coupound Interest" Width="105px"></asp:Label> <asp:TextBox ID="txtSimpleInterest" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label5" runat="server" Width="66px"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Calculate Compound Interest" Width="220px" onclick="Button1_Click" /> </div> </form> </body> </html>
Default2.aspx.cs using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;
{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { localhost.WebService ws = new localhost.WebService(); ws.EnableDecompression = true; Double SI = 0; if ((txtPrincipal.Text == "") || (txtRate.Text == "") || (txtDuration.Text == "")) { Label5.Text = "Unable to calculate simple interest"; } else { SI = ws.Calculatecompound(System.Convert.ToDouble(txtPrincipal.Text), System.Convert.ToDouble(txtRate.Text), System.Convert.ToInt32(txtDuration.Text)); txtSimpleInterest.Enabled = true; txtSimpleInterest.Text = SI.ToString(); Label5.Text = ""; } } } Output:-