Vous êtes sur la page 1sur 80

VB .

NET

Application-1: Develop an application which is similar to Notepad using menus Form Design:

Code:
Imports System.Drawing.Printing Imports System.Windows.Forms.Form Imports System.Diagnostics Imports System.String Imports System.Data Imports System.IO Public Class Form1 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Label1.Text = DateTime.Now.ToString End Sub

Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged Label2.Text = RichTextBox1.Text.Length() End Sub Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click RichTextBox1.Text = "" End Sub Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click Dim sr As StreamReader Dim p As String OpenFileDialog1.ShowDialog() p = OpenFileDialog1.FileName MessageBox.Show(p) sr = New StreamReader(p) RichTextBox1.Text = sr.ReadToEnd() End Sub Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click Dim texttosave As String = RichTextBox1.Text 'Dim save As New SaveFileDialog SaveFileDialog1.Filter = "txt.file(*.txt*)|*.text*" SaveFileDialog1.Title = "Save a text file" If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, texttosave, True) End If End Sub 3

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click End End Sub Private Sub SaveasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveasToolStripMenuItem.Click Dim texttosave As String = RichTextBox1.Text 'Dim save As New SaveFileDialog SaveFileDialog1.Filter = "txt.file(*.txt*)|*.text*" SaveFileDialog1.Title = "Save a text file" If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, texttosave, True) End If End Sub Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click RichTextBox1.Copy() End Sub Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click RichTextBox1.Paste() End Sub Private Sub SelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelToolStripMenuItem.Click RichTextBox1.SelectAll() 4

End Sub Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click RichTextBox1.Clear() End Sub Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click RichTextBox1.Undo() End Sub Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click RichTextBox1.Cut() End Sub Private Sub AboutNotepadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutNotepadToolStripMenuItem.Click Dim form As New Form2 form.Show() End Sub Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click Dim font1 As New FontDialog font1.ShowDialog() RichTextBox1.Font = font1.Font RichTextBox1.ForeColor = font1.Color End Sub

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click Dim p As New PrinterSettings() PrintDialog1.PrinterSettings() = p PrintDialog1.ShowDialog() End Sub End Class

Output Screens:

Application-2: Develop an application for facilitating purchasing order Form Design:

Code:
FORM2:

Public Class Form2 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim i As Integer = ComboBox1.SelectedIndex If (i = 0) Then Form1.Show() End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End End Sub End Class FORM1: Public Class Form1 Dim ccost As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Text = "Select One" lnum.Visible = False TextBox2.Visible = False End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim m As String m = "Gents Wear: " If c1.Checked = True Then m = m & " End If If c2.Checked = True Then m = m & " " & c2.Text & vbCr 10 " & c1.Text & vbCr

End If m = m & "Ladies Wear: " If c3.Checked = True Then m = m & " End If If c4.Checked = True Then m = m & " End If m = m & "Kids Wear: " If c5.Checked = True Then m = m & " End If If c6.Checked = True Then m = m & " End If If ccost > 0 Then m = m & "Code Dresses: " & ComboBox1.SelectedText & vbCr End If m = m & "Payment Mode: " If c7.Checked = True Then m = m & " End If If c8.Checked = True Then m = m & " End If m = m & "Total Cost: " & TextBox1.Text & vbCr & vbCr MsgBox(m, MsgBoxStyle.Information, "Order") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub Private Sub c1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c1.Click 11 " & c8.Text & vbCr " & c7.Text & vbCr & "Transaction ID: " & TextBox2.Text & vbCr " & c6.Text & vbCr " & c5.Text & vbCr " & c4.Text & vbCr " & c3.Text & vbCr

If c1.Checked = True Then TextBox1.Text = Val(TextBox1.Text) + 400 Else TextBox1.Text = Val(TextBox1.Text) - 400 End If End Sub Private Sub c2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c2.Click If c2.Checked = True Then TextBox1.Text = Val(TextBox1.Text) + 600 Else TextBox1.Text = Val(TextBox1.Text) - 600 End If End Sub Private Sub c3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c3.Click If c3.Checked = True Then TextBox1.Text = Val(TextBox1.Text) + 500 Else TextBox1.Text = Val(TextBox1.Text) - 500 End If End Sub Private Sub c4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c4.Click If c4.Checked = True Then TextBox1.Text = Val(TextBox1.Text) + 800 Else TextBox1.Text = Val(TextBox1.Text) - 800 End If End Sub Private Sub c5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c5.Click If c5.Checked = True Then 12

TextBox1.Text = Val(TextBox1.Text) + 200 Else TextBox1.Text = Val(TextBox1.Text) - 200 End If End Sub Private Sub c6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c6.Click If c6.Checked = True Then TextBox1.Text = Val(TextBox1.Text) + 300 Else TextBox1.Text = Val(TextBox1.Text) - 300 End If End Sub Private Sub c7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c7.Click lnum.Visible = True TextBox2.Visible = True TextBox2.Focus() End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim i As String = ComboBox1.SelectedIndex ccost = 0 If i < 5 Then ccost = ccost + 200 TextBox1.Text = Val(TextBox1.Text) + 200 End If End Sub End Class

Output Screens:
13

14

15

Application-3: Develop an application which is similar to login form including the progress bar controls Form Design:
Form-1:

Form-2:

16

Code:
Form-1:
Public Class Form1 Private Sub but_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_cancel.Click End End Sub Private Sub but_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_login.Click Dim x As Integer = 0 If(Txtid.Text = Txtid.Tag And Txtpwd.Text = Txtpwd.Tag) Then ProgressBar1.Visible = True ProgressBar1.Minimum = 1 ProgressBar1.Maximum = 1000 ProgressBar1.Value = 1 ProgressBar1.Step = 1 For x = 1 To 1000 Step 1 ProgressBar1.PerformStep() Next Dim f As New Form2() f.Show() Else MsgBox("Invalid username and password") Txtid.Text = "" Txtpwd.Text = "" Txtid.Focus() End If End Sub End Class

17

Output Screens:

Application-4:
18

Develop an application which is helpful for calculating the insurance Form Design:

Code:
Public Class Form1 Private Sub btnClear_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnClear.Click txtSalary.ResetText() txtRoundSalary.ResetText() txtTotalCost.ResetText() txtBiWeeklyCost.ResetText() numUnitCost.ResetText() txtSalary.Focus() End Sub Private Sub btnCalculate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCalculate.Click Dim EmpSalary As Double Dim RoundSalary As Single 19

Dim UnitCost As Double Dim TotalCost As Single Dim BiWeeklyCost As Single EmpSalary = CDbl(txtSalary.Text) UnitCost = CDbl(numUnitCost.Value) RoundSalary = Int(EmpSalary) TotalCost = UnitCost * RoundSalary BiWeeklyCost = TotalCost / 26 txtRoundSalary.Text = RoundSalary txtTotalCost.Text = TotalCost txtBiWeeklyCost.Text = BiWeeklyCost End Sub End Class

Output Screen:

Application-5(a):
20

Develop an application using font dialog control Form Design:

Code:
Public Class Form1 Private Sub btnformat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnformat.Click FontDialog1.ShowColor = True If FontDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then rtxttext.Font = FontDialog1.Font rtxttext.ForeColor = FontDialog1.Color End If End Sub End Class

Output Screen:
21

22

Application-5(b): Develop an application using color dialog control


23

Form Design:

Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ColorDialog1.ShowDialog() = DialogResult.OK Then TextBox1.BackColor = ColorDialog1.Color End If End Sub End Class

Output Screen:

24

25

ASP.NET

Application 6:Design an application for dynamically populating a checkbox list.


26

Default.aspx(Design):

Default.aspx(Source):
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <h3>Choose your favourite Colors:</h3> <asp:CheckBoxList ID="chklst" runat="server" /><br /><br /> <br /><br /> <asp:Button ID="cmdOK" Text="OK" runat="server" OnClick="cmdOK_Click" /> <br /><br /> <asp:Label ID="lblResult" runat="server" /> </div> </form> </body> </html>

27

Default.aspx.cs: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack == false) { chklst.Items.Add("Red"); chklst.Items.Add("Green"); chklst.Items.Add("Blue"); chklst.Items.Add("Yello"); chklst.Items.Add("White"); chklst.Items.Add("Pink"); } } protected void cmdOK_Click(object sender, EventArgs e) { lblResult.Text = "You have choosen:<b>"; foreach (ListItem lstItem in chklst.Items) { if (lstItem.Selected == true) { lblResult.Text += "<br />" + lstItem.Text; } } lblResult.Text += "</b>"; } } 28

Output Screen:

Application 7:Develop an application for selecting a single day in the calendar control. Default.aspx(Design):
29

Default.aspx(Source):
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged = Calender1_ SelectionChanged" Style="z-index: 100; left: 224px; position: absolute; top: 223px"></asp:Calendar> <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Italic="True" ForeColor="Red" Style="z-index: 101; left: 219px; position: absolute; top: 106px" Text="You have selected :"></asp:Label> <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Italic="True" ForeColor="#00C000" Style="z-index: 103; left: 221px; position: absolute; top: 147px"></asp:Label> </div> 30

</form> </body> </html>

Default.aspx.cs:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Calendar1_SelectionChanged(object sender, EventArgs e) { Label2.Enabled = false; Label2.Text = Calendar1.SelectedDate + "<br>" + Calendar1.SelectedDate.DayOfWeek; }

Output Screen:

31

Application 8:Design an application by using the new scroll bar feature with the panel server control.
32

Default.aspx(Design):

Default.aspx(Source):
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Panel ID="Panel1" runat="server" Height="121px" ScrollBars="Vertical" Style="z-index: 100; left: 103px; position: absolute; top: 153px" Width="269px" BorderColor="#FF80FF"> <strong>PROGRAMMING LANGUAGES&nbsp;</strong> <br /> <br /> C<br /> C++<br /> JAVA<br /> 33

.NET<br /> &nbsp; &nbsp; &nbsp; VB.NET<br /> &nbsp; &nbsp; &nbsp; C#.NET<br /> &nbsp; &nbsp; &nbsp; ASP.NET<br /> COBOL<br /> FORTRAN<br /> VISUAL BASIC 6.0<br /> <br /> <br /> </asp:Panel> </div> </form> </body> </html>

Output Screen:

Application 9:Design an application with simple bulleted list control. Default.aspx(Design):


34

Adding of items into the control panel

Default.aspx(Source):
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> 35

<body> <form id="form1" runat="server"> <div> &nbsp;&nbsp; <asp:Label ID="Label1" runat="server" Font-Bold="True" FontItalic="True" FontSize="X-Large" ForeColor="#C000C0" Style="z-index: 102; left: 303px; position: absolute; top: 25px" Text="FLOWERS"></asp:Label> &nbsp;<br /> <br /> &nbsp; &nbsp; nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:BulletedList ID="BulletedList1" runat="server" BackColor="White" BorderColor="#000040" Font-Bold="True" Font-Italic="True" Font-Size="Medium"> <asp:ListItem>Sunflower</asp:ListItem> <asp:ListItem>Lilly</asp:ListItem> <asp:ListItem>Jasmine</asp:ListItem> <asp:ListItem>Daffodiles</asp:ListItem> <asp:ListItem>Dhalia</asp:ListItem> <asp:ListItem>Daisy</asp:ListItem> <asp:ListItem>BlueBells</asp:ListItem> <asp:ListItem>Hibiscus</asp:ListItem> <asp:ListItem>Iris</asp:ListItem> <asp:ListItem>Peach Blossom</asp:ListItem> <asp:ListItem>Morning Glory</asp:ListItem> </asp:BulletedList> </div> </form> </body> </html> &nbsp; &nbsp; &nbsp; <br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

36

Output Screen:

Application 10:Design an application for uploading files using new file upload control. Default.aspx.design:

37

Default.aspx (Source 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Font-Bold="True" FontSize="Larger" ForeColor="#404000" Style="z-index: 100; left: 6px; position: absolute; top:16px" Text="Post your image : "></asp:Label> left: 102px; position: absolute; top: 88px"></asp:Label> <br /> <asp:FileUpload ID="FileUpload1" runat="server" Style="zindex: 104; left: 157px; 38 <br /> <asp:Label ID="Label2" runat="server" Style="z-index: 101;

position: absolute; top: 19px" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="z-index:

<br /><br /><br />

103;left: 37px; position: absolute; top: 216px" Text="Upload" Width="61px" /> </div> </form> </body> </html>

Default.aspx.cs:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { if(FileUpload1.HasFile) { if(FileUpload1.PostedFile.ContentType=="text/plain") { FileUpload1.PostedFile.SaveAs("D:/y10mc9/DotNet" + FileUpload1.FileName); Label2.Text = "Uploaded Successfully"; } else Label2.Text = "Upload text file"; } 39

else Label2.Text ="Upload file"; } }

Output Screens:

40

41

Application 11:
42

Design an application by using the compare validator to test values against control values. Default.aspx.design:

Default.aspx.source:
<%@ 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>Untitled Page</title> </head> <body> <h1 align = 'center'> Validator Demo</h1> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" BorderColor="#00C0C0" 43

BorderStyle="Solid" Font-Bold="True" ForeColor="Red" Style="zindex: 100; left: 168px; position: absolute; top: 114px" Text="Name : "></asp:Label> <asp:Label ID="Label2" runat="server" BorderColor="#00C0C0" BorderStyle="Solid" Font-Bold="True" ForeColor="Red" Style="zindex: 101; left: 169px; position: absolute; top: 164px"Text="Age : "></asp:Label> <asp:Label ID="Label3" runat="server" BorderColor="#00C0C0" BorderStyle="Solid" Font-Bold="True"ForeColor="Red" Style="zindex: 102; left: 169px; position: absolute; top: 217px" Text="Date of Birth :"></asp:Label> <asp:Label ID="Label4" runat="server" BorderColor="#00C0C0" BorderStyle="Solid" Font-Bold="True"ForeColor="Red" Style="zindex: 103; left: 170px; position: absolute; top: 272px" Text="Email -ID :"></asp:Label> <asp:Label ID="Label5" runat="server" BorderColor="#00C0C0" BorderStyle="Solid" Font-Bold="True" ForeColor="Red" Style="zindex: 104; left: 171px; position: absolute; top: 330px" Text="Mobile Number :"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" BackColor="#00C0C0" BorderColor="#00C0C0" BorderStyle="Double" Font-Bold="True" FontItalic="True" ForeColor="White" Style="z-index: 105;left: 365px; position: absolute; top: 112px"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"ErrorMessage="Name should not be empty...!" Style="z-index: 106; left: 532px; position: absolute; top:112px">*</asp:RequiredFieldValidator> <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox2" ErrorMessage="Age should be in limit (18-55)..!" MaximumValue="55" MinimumValue="18" Style="z-index: 44

107; left: 533px; position: absolute; top: 159px" Type="Integer">*</asp:RangeValidator> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox3" ErrorMessage="*" Style="z-index: 108; left: 531px; position: absolute; top: 219px" Type="Date" Operator="DataTypeCheck">*</asp:CompareValidator>&nbsp; <asp:TextBox ID="TextBox2" runat="server" BackColor="#00C0C0" BorderColor="#00C0C0" BorderStyle="Double" Font-Bold="True" FontItalic="True" ForeColor="White" Style="z-index: 109; left: 365px; position: absolute; top: 163px"></asp:TextBox><asp:TextBox ID="TextBox3" runat="server" BackColor="#00C0C0" BorderColor="#00C0C0" BorderStyle="Double" Font-Bold="True" FontItalic="True" ForeColor="White" Style="z-index: 110; left: 366px; position: absolute; top: 219px"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server" BackColor="#00C0C0 BorderColor="#00C0C0" BorderStyle="Double" Font-Bold="True" FontItalic="True" ForeColor="White" Style="z-index: 111; left: 368px; position: absolute; top: 273px"></asp:TextBox><asp:TextBox ID="TextBox5" runat="server" BackColor="#000C0" BorderColor="#00C0C0" BorderStyle="Double" Font-Bold="True" Font-Italic="True" ForeColor="White" Style="zindex: 112; left: 366px; position: absolute; top: 334px"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox4" ErrorMessage="Check email format..!" Style="z-index: 113; left: 534px; position: absolute;top: 270px" ValidationExpression="\w+([-+.']\w+)*@\w+ ([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator> &nbsp; <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox5" ErrorMessage="Digits must not exceed 10..!" Style="z-index: 118; left: 532px;position: absolute; top: 335px" ValidationExpression="\d{10}">*</asp:RegularExpressionValidator> <asp:Button ID="Button1" runat="server" BackColor="#00C0C0" BorderColor="#00C0C0"BorderStyle="Solid" Font-Bold="True" 45

ForeColor="Red" Style="z-index: 115; left: 251px;position: absolute; top: 403px" Text="Submit" Width="104px" />&nbsp; <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Errors Occured..!" ShowMessageBox="True" ShowSummary="False" Style="z-index: 117; left: 423px; position: absolute; top: 405px" /> </div> </form> </body> </html>

Output Screens:46

Application 12:Design an application using grid view control in an asp.net web page
47

Default.aspx(Design):-

Default.aspx(Source):
<%@ 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" Height="418px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Style="left: 81px; position: relative; top: 70px" Width="597px" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None"> 48

<FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" /> </asp:GridView> </div> </form> </body> </html>

Default.aspx.cs:using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection( "Trusted_Connection=yes;database=mca9;data source=MCA9\\SQLEXPRESS"); con.Open(); SqlCommand cmd = new SqlCommand("select * from stu_dtls", con); SqlDataAdapter da = new SqlDataAdapter("select * from stu_dtls", con); 49

DataSet ds = new DataSet(); da.Fill(ds, "stu_dtls"); GridView1.DataSource = ds.Tables["stu_dtls"]; GridView1.DataBind(); } }

Output Screen:-

Application 13:Design an application for adding an insert command to the sql data source control. Default.aspx(Design):
50

Default.aspx(Source):
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>DataSourceControl Demo</title> </head> <body> <form id="form1" runat="server"> <div>&nbsp; <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"DataKeyNames="sno" DataSourceID="SqlDataSource1" Height="170px" Width="193px"> <Fields> <asp:BoundField DataField="sno" HeaderText="sno" ReadOnly="True" SortExpression="sno" /> <asp:BoundField DataField="sname" HeaderText="sname" SortExpression="sname" /> 51

<asp:BoundField DataField="addr" HeaderText="addr" SortExpression="addr"/> <asp:BoundField DataField="dob" HeaderText="dob" SortExpression="dob"/> <asp:BoundField DataField="fee" HeaderText="fee" SortExpression="fee" /> <asp:BoundField DataField="course" HeaderText="course" SortExpression="course" /> <asp:CommandField ShowInsertButton="True" /> </Fields> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mca9ConnectionString %>" DeleteCommand="DELETE FROM [stu_dtls] WHERE [sno] = @sno" InsertCommand="INSERT INTO [stu_dtls] ([sno], [sname], [addr], [dob], [fee], [course]) VALUES (@sno, @sname, @addr, @dob, @fee, @course)" SelectCommand="SELECT * FROM [stu_dtls]" UpdateCommand="UPDATE [stu_dtls] SET [sname] = @sname, [addr] = @addr, [dob] = @dob, [fee] = @fee, [course] = @course WHERE [sno] = @sno"> <DeleteParameters> <asp:Parameter Name="sno" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="sname" Type="String" /> <asp:Parameter Name="addr" Type="String" /> <asp:Parameter Name="dob" Type="DateTime" /> <asp:Parameter Name="fee" Type="Decimal" /> <asp:Parameter Name="course" Type="String" /> <asp:Parameter Name="sno" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="sno" Type="Int32" /> <asp:Parameter Name="sname" Type="String" /> <asp:Parameter Name="addr" Type="String" /> <asp:Parameter Name="dob" Type="DateTime" /> <asp:Parameter Name="fee" Type="Decimal" /> 52

<asp:Parameter Name="course" Type="String" /> </InsertParameters> </asp:SqlDataSource> </div> </form> </body> </html>

Output Screens:-

53

Inserting New Record:

54

55

C#.NET

56

Application 14: Develop a project for demonstrating polymorphism, abstraction CODE:


namespace polymorphism_abstraction { public abstract class poly { public abstract void max(int a, int b); public abstract void max(int a, int b, int c); } public class display:poly { int big; public override void max(int a, int b) { if (a > b) big = a; else big = b; Console.WriteLine("Biggest of given two numbers is: " + big); } public override void max(int a, int b,int c) { big=((a > b) && (a > c))?a :(b > c)?b:c; Console.WriteLine("Biggest of given three numbers " big); } } class Program { static void Main(string[] args) { display d = new display(); int x,y,z; Console.WriteLine("Enter two Numbers:"); 57 +

x = int.Parse(Console.ReadLine()); y = int.Parse(Console.ReadLine()); d.max(x, y); Console.WriteLine("Enter three Numbers:"); x = int.Parse(Console.ReadLine()); y = int.Parse(Console.ReadLine()); z = int.Parse(Console.ReadLine()); d.max(x,y,z); Console.Read(); } } }

Output Screen:

Application 15:
58

Develop a project for demonstrating switch statements. Form Design:

CODE:
namespace Labcycle_2 { public partial class Form1 : Form { int num,choice; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { num = int.Parse(textBox1.Text); choice = int.Parse(textBox2.Text); 59

switch (choice) { case 1: { int d,fcnt,dnum=num; fcnt = 0; for (d = 1; d <= dnum; d++) { if (dnum%d } if (fcnt == 2) MessageBox.Show("Number is Prime"); else MessageBox.Show("Number is not Prime"); } break; case 2: { int r = 0, anum = num, sum = 0; while (anum > 0) { r = anum % 10; sum = sum + (r * r * r); anum = anum / 10; } if (sum == num) MessageBox.Show("Number is Amstrong"); else MessageBox.Show("Number is not Amstrong"); } break; case 3: { int r = 0, pnum = num, sum = 0; while (pnum > 0) 60 == 0) fcnt += 1;

{ r = pnum % 10; sum = sum * 10 + r; pnum = pnum / 10; } if (sum == num) MessageBox.Show("Number is Palindrome"); else MessageBox.Show("Number is not Palindrome"); } break; case 4: { int { if (penum % i== 0) sum += i; } if (sum == penum) MessageBox.Show("Number is Perfect"); else MessageBox.Show("Number is not Perfect"); } break; } } private void button2_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; num = 0; choice = 0; textBox1.Focus(); } 61 penum = num, sum = 0; for (int i = 1; i < penum; i++)

private void button3_Click(object sender, EventArgs e) { Application.Exit(); } private void Form1_Load(object sender, EventArgs e) { textBox1.Focus(); } } }

Output Screens:
62

63

64

Application 16: Develop a project for implementing inheritance using abstract classes CODE:
using System; using System.Collections.Generic; using System.Text; namespace abs_inheritance { public abstract class Area { public abstract void show(); public abstract void area(int x, int y); } public class Area_Rect : Area { public override void show() { Console.WriteLine("-----------------------------------"); Console.WriteLine("\t Area of Rectangle"); Console.WriteLine("-----------------------------------"); } public override void area(int x, int y) { int a; a = x * y; Console.WriteLine("The Area is:" + a); Console.Read(); } } public class Area_Tri : Area { public override void show() { Console.WriteLine("-----------------------------------"); Console.WriteLine("\t Area of a Triangle "); Console.WriteLine("-----------------------------------"); 65

Console.Read(); } public override void area(int x, int y) { double d; d = 0.5 * x * y; Console.WriteLine("The Area is:" + d); Console.Read(); } } public class Abstract_inheritence { public static void Main() { int a, b; Area_Rect r = new Area_Rect(); Area_Tri t = new Area_Tri(); r.show(); Console.WriteLine("Enter length and breadth:"); a = Int32.Parse(Console.ReadLine()) ; b = Int32.Parse(Console.ReadLine()); r.area(a, b); double m, n; t.show(); Console.WriteLine("Enter base and height:"); a = Int32.Parse(Console.ReadLine()); b = Int32.Parse(Console.ReadLine()); t.area(a, b); Console.ReadLine(); } } }

Output Screen:

66

Application 17: Develop a project for implementing interfaces using multiple inheritance
67

CODE:
using System; using System.Collections.Generic; using System.Text; namespace inheritence_multipleinterfaces { interface i1 { void show(); } interface i2 { void read(); } public class print : i1, i2 { string name, dept; public void read() { Console.WriteLine("Enter your Name: "); name = Console.ReadLine(); Console.WriteLine("Enter your Dept: "); dept = Console.ReadLine(); } public void show() { Console.WriteLine("\n\nThe entered Details are:"); Console.WriteLine("\nName:\t\t" + name); Console.WriteLine("Department:\t " + dept); } } class Program { static void Main(string[] args) { print p = new print(); 68

p.read(); p.show(); Console.Read(); } } }

Output Screen:

Application 18:Create a form that is the main window of a program using window class.
69

Form Design:-

CODE:Public Class Form1 Inherits System.Windows.Forms.Form Dim nf As Integer = 0 Dim forms(10) As Form2 Private Sub AddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToolStripMenuItem.Click nf += 1 forms(nf) = New Form2 forms(nf).Text = "document" & Str(nf) forms(nf).MdiParent = Me forms(nf).Show() End Sub Private Sub ArrangeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ArrangeToolStripMenuItem.Click Me.LayoutMdi(MdiLayout.Cascade) End Sub 70

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Me.Close() End Sub End Class

Output Screens:-

Application 19:71

Create a form which displays the given inputs in the form of a tree view structure. Form Design:

CODE:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace treeview_app { public partial class Form1 : Form { public Form1() { InitializeComponent(); } 72

public TreeNode node; private void button1_Click(object sender, EventArgs e) { node = treeView1.Nodes.Add(textBox1.Text); textBox1.Text=""; } private void button2_Click(object sender, EventArgs e) { node.Nodes.Add(textBox2.Text); textBox2.Text=""; } } }

Output Screens:

Application 20:
73

Develop a project for implementing exception handling in C#. Form Design:

CODE:
namespace ExceptionDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { textBox1.Focus(); try { int num1 = int.Parse(textBox1.Text); int num2 = int.Parse(textBox2.Text); int ch = int.Parse(textBox3.Text); switch (ch) { 74

case 1: MessageBox.Show("Addition : " + (num1 + num2)); break; case 2: MessageBox.Show("Subtraction : " + (num1 num2)); break; case 3: MessageBox.Show("Multiplication : " + (num1 * num2)); break; case 4: MessageBox.Show("Division : " + (num1 / num2)); break; } } catch (FormatException fe) { MessageBox.Show(fe.Message); } catch (Exception ee) { MessageBox.Show(ee.Message); } finally { MessageBox.Show("This is finally block!"); } } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } } 75

Output Screens:

Application 21:76

Develop a project which displays the student information in the relevant fields from the database which already exists. Form Design:-

CODE:
Imports System.Data.SqlClient Public Class Form1 Dim stu_id As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As \ System.EventArgs) Handles MyBase.Load Dim con As New SqlConnection("Trusted_Connection=YES;DataBase=mca9;Data Source=MCA9\SQLEXPRESS") con.Open() Dim cmd As New SqlCommand("select * from Student_Details", con) 77

Dim da As New sqlDataAdapter(cmd) Dim ds As New DataSet() da.Fill(ds, "Student_Details") ComboBox1.DataSource = ds.Tables("Student_Details") ComboBox1.DisplayMember = "Sid" ComboBox1.ValueMember = "Sid" TextBox1.DataBindings.Clear() TextBox1.DataBindings.Add(New Binding("text", ds, "Student_Details.Sname")) TextBox2.DataBindings.Clear() TextBox2.DataBindings.Add(New Binding("text", ds, "Student_Details.Grade")) Button1.Enabled = False End Sub Private Sub filldata() Dim con As New SqlConnection("Trusted_Connection=yes;database=mca9;data source=MCA9\SQLEXPRESS") con.Open() Dim cmd As New SqlCommand("select Sname,Grade from Student_Details where Sid=@stu_id", con) cmd.Parameters.Add("@stu_id", SqlDbType.Int) cmd.Parameters(0).Value = ComboBox1.SelectedValue() Dim da As New SqlDataAdapter(cmd) Dim ds As New DataSet() da.Fill(ds, "Student_Details") TextBox1.DataBindings.Clear() TextBox1.DataBindings.Add(New Binding("text", ds, "Student_Details.Sname")) TextBox2.DataBindings.Clear() TextBox2.DataBindings.Add(New Binding("text", ds, "Student_Details.Grade")) If (ComboBox1.SelectedIndex = 0) Then Button1.Enabled = False Else Button1.Enabled = True 78

End If If (ComboBox1.SelectedIndex = ComboBox1.Items.Count - 1) Then Button2.Enabled = False Else Button2.Enabled = True End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ComboBox1.SelectedValue -= 1 filldata() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ComboBox1.SelectedValue += 1 filldata() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted filldata() End Sub End Class

Output Screens:79

80

Vous aimerez peut-être aussi