1 2 Emit This 2 Pages For Certificates 3 INDEX Practical. No Experiments Teacher Sign. 1. Write AWT program using console to Add Two Numbers 2. Write AWT program using console to implement string 3. Write AWT program using console to implement structure 4. Design a Windows Application Form 5. Design a UI based application using basic Web Application Forms Controls 6. Design a UI based application using basic validations controls 7. Write AWT program to create a database 8. Write AWT program to create a database using methods 4 Practical 1 Aim: Write AWT program using console to Add Two Numbers Program: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AWT_Practical_New { class AddTwoNumbers { static void Main( string [] args) { int NumberOne, NumberTwo, Result; Console.WriteLine( "Please Enter First Number" ); NumberOne = Convert.ToInt32(Console.ReadLine()); Console.WriteLine( "Please Enter Second Number" ); NumberTwo = Convert.ToInt32(Console.ReadLine()); Result = NumberOne + NumberTwo; Console.WriteLine( "Sum Of {0} And {1} is {2}" , NumberOne, NumberTwo, Result); Console.WriteLine( "Press Any Key To Close Console Window" ); Console.ReadKey(); //To Prevent Key From closing automatically... } } } Output: 5 Practical 2 Aim: Write AWT program using console to implement string Program: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AWT_Practical_New { class StringImplementation { static void Main( string [] args) { string FirstName = string .Empty; string LastName = string .Empty; Console.WriteLine( "Enter Your First Name : " ); FirstName = Console.ReadLine(); Console.WriteLine( "Enter Your Last Name : " ); LastName = Console.ReadLine(); Console.WriteLine( "Hello {0} {1} ....!!" , FirstName, LastName); Console.WriteLine( "Press Any Key To Close Console Window" ); Console.ReadKey(); } } } Output: 6 Practical 3 Aim: Write AWT program using console to implement structure Program: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AWT_Practical_New { public struct TeamMember { private int SrNo; private string Name; private string Designation; public int Id { get => SrNo; set => SrNo = value; } public string EmployeeName { get => Name; set => Name = value; } public string EmpDesignation { get => Designation; set => Designation = value; } public TeamMember ( int srNo, string name, string designation) { this .SrNo = srNo; this .Name = name; this .Designation = designation; } public void DisplayTeamMembers() { Console.WriteLine( "Id : {0}" , this .SrNo); Console.WriteLine( "Employee Name : {0}" , this .Name); Console.WriteLine( "Designation : {0}" , this .Designation); Console.WriteLine(); } } public class StructureImplementation { public static void Main( string [] args) { TeamMember Hod = new TeamMember(); Console.WriteLine( "This is Payroll Team" ); Hod.Id = 1; Hod.EmployeeName = "Anand Vishwakarma" ; Hod.EmpDesignation = "Head Of Department" ; Hod.DisplayTeamMembers(); 7 TeamMember TL = new TeamMember(2, "Javed Khan" , "Team Leader" ); TL.DisplayTeamMembers(); TeamMember ATL = new TeamMember(3, "Arbaz Shaikh" , "Assistant Team Leader" ); ATL.DisplayTeamMembers(); TeamMember Senior = new TeamMember(4, "Pranali Suryavanshi" , "Senior Software Developer" ); Senior.DisplayTeamMembers(); TeamMember JuniorOne = new TeamMember(5, "Rick Show" , "Junior Software Developer" ); JuniorOne.DisplayTeamMembers(); TeamMember JuniorTwo = new TeamMember(6, "Kaushik Singh" , "Junior Software Developer" ); JuniorTwo.DisplayTeamMembers(); Console.WriteLine( "Press Any Key To Close Console Window" ); Console.ReadKey(); } } } Output: 8 Practical 4 Aim: Design a Windows Application Form Program: • Form1.cs public partial class MyApp : Form { public MyApp () { InitializeComponent(); } private void Btn_Click_Click( object sender, EventArgs e) { string Name = txt_Name.Text; MessageBox.Show( "Hello " + Name + ", \ r \ nWelcome to My First Windows Application" ); } } • Frorm1.cs[Design] Output: 9 Practical 5 Aim: Design a UI based application using basic Web Application Forms Controls Program: • My Calculator.aspx <% @ Page Language ="C#" AutoEventWireup ="true" CodeBehind ="My Calculator.aspx.cs" Inherits ="Calculator.WebForm1" %> <! DOCTYPE html > < html xmlns ="http://www.w3.org/1999/xhtml"> < head runat ="server"> < title ></ title > < style > .input { margin : 25px ; border : 2px solid black ; border - radius : 10px ; font - size : xx - large ; } .button { margin : 15px 10px ; width : 70px ; padding : 10px ; border - radius : 5px ; background - color : aliceblue ; border - radius : 5px ; font - weight : bold ; font - size : large ; cursor : pointer ; } .btn - div { border : none ; height : 58px ; width : 400px ; transform : translate(10px, 10px) ; } .container { position : absolute ; height : 520px ; width : 400px ; transform : translate(250px, 100px) ; border : 2px solid black ; border - radius : 20px ; } </ style > </ head > < body > < form id ="form1" runat ="server"> < div > < div class ="container"> < div class ="input"> < div style =" width : 400px; padding : 5px 0px"> < asp : TextBox runat ="server" ID ="txt_Input" Height ="57px" Width ="343px" BorderStyle ="None" ReadOnly ="true"> </ asp : TextBox > </ div > < div style =" height : 80px"> < asp : TextBox runat ="server" ID ="txt_Display" Height ="41px" Style =" margin - top : 7px; border : none" Width ="340px" ReadOnly ="true"></ asp : TextBox > </ div > </ div > < div class ="btn - div"> 10 < asp : Button runat ="server" Text ="AC" ID ="Btn_AC" class ="button" OnClick ="Btn_AC_Click" /> < asp : Button runat ="server" Text ="%" ID ="Btn_Percentage" class ="button" OnClick ="Btn_Percentage_Click" /> < asp : Button runat ="server" Text ="C" ID ="Btn_Clear" class ="button" OnClick ="Btn_Clear_Click" /> < asp : Button runat ="server" Text ="/" ID ="Btn_Divide" class ="button" OnClick ="Btn_Divide_Click" /> </ div > < div class ="btn - div"> < asp : Button runat ="server" Text ="7" ID ="Btn_Seven" class ="button" OnClick ="Btn_Seven_Click" /> < asp : Button runat ="server" Text ="8" ID ="Btn_Eight" class ="button" OnClick ="Btn_Eight_Click" /> < asp : Button runat ="server" Text ="9" ID ="Btn_Nine" class ="button" OnClick ="Btn_Nine_Click" /> < asp : Button runat ="server" Text ="*" ID ="Btn_Multiply" class ="button" OnClick =" Btn_Multiply_Click" /> </ div > < div class ="btn - div"> < asp : Button runat ="server" Text ="4" ID ="Btn_Four" class ="button" OnClick ="Btn_Four_Click" /> < asp : Button runat ="server" Text ="5" ID ="Btn_Five" class ="button" OnClick ="Btn_Five_Click" /> < asp : Button runat ="server" Text ="6" ID ="Btn_Six" class ="button" OnClick ="Btn_Six_Click" /> < asp : Button runat ="server" Text =" - " ID ="Btn_Subtract" class ="button" OnClick ="Btn_Subtract_Click" /> </ div > < div class ="btn - div"> < asp : Button runat ="server" Text ="1" ID ="Btn_One" class ="button" OnClick ="Btn_One_Click" /> < asp : Button runat ="server" Text ="2" ID ="Btn_Two" class ="button" OnClick ="Btn_Two_Click" /> < asp : Button runat ="server" Text ="3" ID ="Btn_Three" class ="button" OnClick ="Btn_Three_Click" /> < asp : Button runat ="server" Text ="+" ID =" Btn_Add" class ="button" OnClick ="Btn_Add_Click" /> </ div > < div class ="btn - div"> < asp : Button runat ="server" Text ="00" ID ="Btn_DoubleZero" class ="button" OnClick ="Btn_DoubleZero_Click" /> < asp : Button runat ="server" Text ="0" ID ="Btn_Zero" class ="button" OnClick ="Btn_Zero_Click" /> < asp : Button runat ="server" Text ="." ID ="Btn_Decimal" class ="button" OnClick ="Btn_Decimal_Click" /> < asp : Button runat ="server" Text ="=" ID ="Btn_Equals" class ="button" OnClick ="Btn_Equals_Click" /> </ div > </ div > </ div > </ form > < asp : TextBox runat ="server" Visible ="false" ID ="txt_Num1"></ asp : TextBox > < asp : TextBox runat ="server" Visible ="false" ID ="txt_Num2"></ asp : TextBox > < asp : TextBox runat ="server" Visible ="false" ID ="txt_Operator"></ asp : TextBox > </ body > </ html > • My Calculator.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Calculator { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } decimal Ans; protected void Btn_AC_Click( object sender, EventArgs e) { txt_Input.Text = null ; txt_Operator.Text = null ; txt_Display.Text = null ; txt_Num1.Text = null ; txt_Num2.Text = null ; } 11 protected void Btn_Add_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + " + " ; txt_Operator.Text = "+" ; } protected void Btn_Subtract_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + " - " ; txt_Operator.Text = " - " ; } protected void Btn_Multiply_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + " * " ; txt_Operator.Text = "*" ; } protected void Btn_Divide_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + " / " ; txt_Operator.Text = "/" ; } protected void Btn_Decimal_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "." ; } protected void Btn_Percentage_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + " % " ; txt_Operator.Text = "%" ; } protected void Btn_Clear_Click( object sender, EventArgs e) { if (txt_Input.Text != "" ) { txt_Input.Text = txt_Input.Text.Substring(0, txt_Input.Text.Length - 1); } if (txt_Num1.Text != "" ) { txt_Num1.Text = txt_Num1.Text.Substring(0, txt_Num1.Text.Length - 1); } if (txt_Num2.Text != "" ) { txt_Num2.Text = txt_Num2.Text.Substring(0, txt_Num2.Text.Length - 1); } if (txt_Operator.Text != "" ) { txt_Operator.Text = "" ; } if (txt_Display.Text != "" ) { txt_Display.Text = "" ; } } protected void Btn_Equals_Click( object sender, EventArgs e) { this .Compute(); } protected void Btn_DoubleZero_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "00" ; this .Validates( "00" ); } protected void Btn_Zero_Click( object sender, EventArgs e) { 12 txt_Input.Text = txt_Input.Text + "0" ; this .Validates( "0" ); } protected void Btn_One_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "1" ; this .Validates( "1" ); } protected void Btn_Two_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "2" ; this .Validates( "2" ); } protected void Btn_Three_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "3" ; this .Validates( "3" ); } protected void Btn_Four_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "4" ; this .Validates( "4" ); } protected void Btn_Five_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "5" ; this .Validates( "5" ); } protected void Btn_Six_ Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "6" ; this .Validates( "6" ); } protected void Btn_Seven_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "7" ; this .Validates( "7" ); } protected void Btn_Eight_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "8" ; this .Validates( "8" ); } protected void Btn_Nine_Click( object sender, EventArgs e) { txt_Input.Text = txt_Input.Text + "9" ; this .Validates( "9" ); } public void Validates( string Number) { if (txt_Num1.Text != "" && txt_Operator.Text != "" ) { txt_Num2.Text = Number; this .Compute(); } else { txt_Num1.Text = txt_Num1.Text + Number.ToString(); } } 13 public void Compute() { switch (txt_Operator.Text) { case "+" : Ans = Convert.ToDecimal(txt_Num1.Text) + Convert.ToDecimal(txt_Num2.Text); break ; case " - " : Ans = Convert.ToDecimal(txt_Num1.Text) - Convert.ToDecimal(txt_Num2.Text); break ; case "*" : Ans = Convert.ToDecimal(txt_Num1.Text) * Convert.ToDecimal(txt_Num2.Text); break ; case "/" : Ans = Convert.ToDecimal(txt_Num1.Text) / Convert.ToDecimal(txt_Num2.Text); break ; case "%" : Ans = Convert.ToDecimal(txt_Num1.Text) % Convert.ToDecimal(txt_Num2.Text); break ; } txt_Display.Text = Ans.ToString(); } } } Output: 14 Practical 6 Aim: Design a UI based application using basic validations controls Program: • Registration Form.aspx <% @ Page Language ="C#" AutoEventWireup ="true" CodeBehind ="Registration Form.aspx.cs" Inherits =" Form_Validation.Registration_Form" %> <! DOCTYPE html > < html xmlns ="http://www.w3.org/1999/xhtml"> < head runat ="server"> < title ></ title > </ head > < body > < form id ="form1" runat ="server"> < div > < asp : Label runat ="server" ID ="lbl_Name"> Full Name : </ asp : Label > < asp : TextBox runat ="server" ID ="txt_Name"></ asp : TextBox > < asp : RequiredFieldValidator ID ="RequiredName" runat ="server" ControlToValidate ="txt_Name" ErrorMessage ="Please Provide Name"> * </ asp : RequiredFieldValidator > </ div >< br /> < div > < asp : Label runat ="server" ID ="lbl_Age"> Age : </ asp : Label > < asp : TextBox runat ="server" ID ="txt_age"></ asp : TextBox > < asp : RequiredFieldValidator ID ="RequiredAge" runat ="server" ControlToValidate ="txt_age" ErrorMessage ="Please Provide Age"> * </ asp : RequiredFieldValidator > < asp : RangeValidator ID ="AgeValidator" runat ="server" ControlToValidate ="txt_age" ErrorMessage ="Age Should Be Between 18 To 60" MaximumValue ="60" MinimumValue ="18" Type ="Integer"> </ asp : RangeValidator > </ div >< br /> < div > < asp : Label runat ="server" ID ="lbl_Mobile"> Mobile Number : </ asp : Label > < asp : TextBox runat ="server" ID ="txt_Mobile"></ asp : TextBox > < asp : RequiredFieldValidator runat ="server" ID =" RequiredMobile" ControlToValidate ="txt_Mobile" ErrorMessage ="Please provide Mobile Number"> * </ asp : RequiredFieldValidator > < asp : RegularExpressionValidator runat ="server" ID ="RegularMobile" ErrorMessage ="Must be 10 digits" ValidationExpression =" \ d{10}" ControlToValidate ="txt_Mobile"></ asp : RegularExpressionValidator > </ div >< br /> < div > < asp : Label runat ="server" ID ="lbl_Income"> Family Income : </ asp : Label > < asp : TextBox runat ="server" ID ="txt_Income"></ asp : TextBox > < asp : RequiredFieldValidator ID ="RequiredIncome" runat ="server" ControlToValidate ="txt_Income" ErrorMessage ="Please Provide Income"> * </ asp : RequiredFieldValidator > < asp : CompareValidator runat ="server" ID ="Compare_Income" ControlToValidate ="txt_Income" ErrorMessage ="Family Income Should be more than 1000" Type ="Currency" ValueToCompare ="1000"></ asp : CompareValidator > </ div >< br /> < div > < asp : Label runat ="server" ID ="lbl_Password"> Password : </ asp : Label > < asp : TextBox runat ="server" ID ="txt_Passowrd" TextMode ="Password"></ asp : TextBox > < asp : RequiredFieldValidator ID =" RequiredPassowrd" runat ="server" ControlToValidate ="txt_Passowrd" ErrorMessage ="Please Provide Passowrd"> * </ asp : RequiredFieldValidator > </ div >< br /> < div > < asp : Label runat ="server" ID ="lbl_CPassword"> Confirm Password : </ asp : Label > < asp : TextBox runat ="server" ID ="txt_CPassowrd" TextMode ="Password"></ asp : TextBox > 15 < asp : RequiredFieldValidator ID ="RequiredCPassoword" runat ="server" ControlToValidate ="txt_CPassowrd" ErrorMessage ="Please Re - Enter Passowrd"> * </ asp : RequiredFieldValidator > < asp : CompareValidator runat ="server" ID ="ComparePassword" ControlToCompare ="txt_Passowrd" ControlToValidate ="txt_CPassowrd" ErrorMessage ="Password Are Not Matching.."></ asp : CompareValidator > </ div > < br /> < div > < asp : Button runat ="server" ID ="Btn_Submit" OnClick ="Btn_Submit_Click" Text ="Submit" ToolTip ="Click Me To Submit..!!!" /> < br /> < br /> </ div > < asp : ValidationSummary ID ="ValidationSummary1" runat ="server" /> </ form > </ body > </ html > • Registration Form.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Form_Validation { public partial class Registration_Form : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected void Btn_Submit_Click( object sender, EventArgs e) { ClientScript.RegisterStartupScript( this .GetType(), "PopUp" , "Registerd Successfully" ); } } } Output: 16 Practical 7 Aim: Write AWT program to create a database Program: using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Create_DataBase { class Program { static void Main( string [] args) { Console.WriteLine( "Enter the name of the database:" ); string dbName = Console.ReadLine(); string connectionString = @"Server=RICK \ SQLEXPRESS;integrated security=SSPI;database=master" ; if (CreateDatabase(dbName, connectionString)) { Console.WriteLine( $"Database ' {dbName} ' created successfully." ); } else { Console.WriteLine( $"Error creating database ' {dbName} '." ); } Console.ReadKey(); } static bool CreateDatabase( string dbName, string connectionString) { try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string createDatabaseQuery = $"CREATE DATABASE {dbName} " ; using (SqlCommand command = new SqlCommand(createDatabaseQuery, connection)) { command.ExecuteNonQuery(); } } return true ; } catch (Exception ex) { Console.WriteLine( $"Error: {ex.Message} " ); return false ; } } } } Output: 17 Practical 8 Aim: Write AWT program to create a database using methods Program: • For m1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace Create_DB_Using_Windows_Form { public partial class Form1 : Form { public Form1 () { InitializeComponent(); } private void btn_CreateDataBase_Click( object sender, EventArgs e) { string DBName = txt_DBName.Text; CreateDataBase(DBName); } private void CreateDataBase( string DBName) { string ConnectionStr = @"Server=RICK \ SQLEXPRESS;integrated security=SSPI;database=master" ; using (SqlConnection con = new SqlConnection(ConnectionStr)) { try { con.Open(); string QryStr = " CREATE DATABASE " + DBName; SqlCommand command = new SqlCommand(QryStr, con); command.ExecuteNonQuery(); MessageBox.Show( $"Database ' {DBName} ' created successfully." , "Success" , MessageBoxButtons.OK, MessageBoxIcon.Information); con.Close(); } catch (Exception ex) { MessageBox.Show( $"Error creating database: {ex.Message} " , "Error" , MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } 18 • F orm1.cs[ Design] Output: