6-1 Lab Manual - Visual Programmming
6-1 Lab Manual - Visual Programmming
Visual Programming
Course Code: CSVP-368
Objective
• To acquaint students with better understanding of Visual Programing
• To familiarize students with C#, Asp.net Framework and MVC
• To equip students with hands-on experience of implementing Industrial Level projects in the field
of Desktop and Web.
Tools/ Technologies
Following tools and technologies will be used for implementing software programs in lab:
Effectiveness
• Studetns analyzed fundamental concepts of visual programming for their mapping to real
life scenarios in Software Development.
• Read, write, execute, and debug C# Console and Windows Form applications
• Understand variables and data types
• Code decision and control structures (if, if/else, switch, while, do/while, for) and use
primitive data types and non-primitive data types. Write user-defined methods
• Manipulate Arrays from collection framework
• Write programs using object-oriented programming techniques including classes, objects,
inheritance, and polymorphism
• Use graphical user interface (GUI) components
• Understand C#’s Event Handling Model
• Write code to access and manipulate database
• Understaning of Web Developent in .net framework
• Modern echniques used with Asp.net code and Various databases
• Student designed solutions for implementing given problem in terms of an underlying
design pattern with associated visual tools for windows and web app development using dot
net framework.
• Students developed complete software solutions using learned techniques and tools that may
be deployed in the relevant organizations for routine operations.
2
WEEKLY BREAKDOWN
• Create a child class and parent class for calculator and scientific Calc,
1 Create windows forms with Menus, buttons, etc.
• Create Account class with public and private variables and props,
2 Design Windows to get values and store in props and pass
• Develop a BLL and DAL using class library, Return from DAL to
5 presentation layer, Add references for namespaces
• Call functions in Application with Employee Form.
• Dynamic link libraries, Building Class Libraries, Using References
6 Using Data Set, Data Table and Data Adapter
3
• Mange the User Access Level and design appropriate Master page and
webpages.
• Session Management and State Management
• CREATE A WCF SERVICE TO PROVIDE CURRECY CONVERSION AND
12 CALLING IT ON A WEB APPLICATION
4
Lab Task 1
Description:
Create a child class and parent class for calculator and scientific Calc, Create windows forms with Menus,
buttons, etc.
Solution:
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;
namespace CalculatorProject
int opt;
public Form1(){
InitializeComponent();
5
}
txt.Text = "";
val1 = 0;
val2 = Convert.ToDouble(txt.Text);
switch(opt)
6
txt.Text = (txt.Text.Substring(0, txt.TextLength - 1));
val1 = Convert.ToDouble(txt.Text);
opt = 1;
txt.Text = "";
val1 = Convert.ToDouble(txt.Text);
opt = 3;
txt.Text = "";
val1 = Convert.ToDouble(txt.Text);
opt = 4;
txt.Text = "";
val1 = Convert.ToDouble(txt.Text);
opt = 2;
txt.Text = "";
txt.Text = "";
7
}
m = m+Convert.ToDouble(txt.Text);
txt.Text = "" + m;
m = m - Convert.ToDouble(txt.Text);
txt.Text = "" + m;
m = 0;
val1 = Convert.ToDouble(txt.Text );
val1 = val1*-1;
txt.Text = ""+val1;
8
Lab Task 2
Description:
Create Account class with public and private variables and props, Design Windows to get values and
store in props and pass
Solution:
9
Lab Task 3
Description:
Develop an employee page to perform Insert and Search the records, Design database in SQL
server 2012.
Solution:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ManagementSystem
{
public partial class Employee : Form
{
public Employee()
{
InitializeComponent();
}
10
private void Insert_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data
Source=(localdb)\v11.0;Initial Catalog=OfficeRecord;Integrated
Security=True");
SqlCommand cmd = new SqlCommand("Insert INTO
Employee VALUES(" + txtID.Text + ", '" + txtName.Text + "','" +
txtAddress.Text + "'," + txtCell.Text + ")", conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Inserted Successfully");
}
11
else
{
MessageBox.Show("Record not found");
}
12
Lab Task 4
Description:
Develop properties, presentation layer in C sharp to get data from text boxes and save in
properties object.
Solution:
Properties Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Props
{
public class EmpProps
{
public EmpProps(){}
private int code;
public int Code
{
get { return code; }
13
set { code = value; }
}
private String name;
public String Name
{
get { return name; }
set { name = value; }
}
private String cellno;
public String Cellno
{
get { return cellno; }
set { cellno = value; }
}
private String address;
public String Address
{
get { return address; }
set { address = value; }
}
}}
Application Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
14
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Props;
using Bll;
namespace Multilayermngmntsys
{
public partial class Employee : Form
{
public Employee()
{
InitializeComponent();
}
}
}
}
15
Lab Task 5
Description:
Develop a BLL and DAL using class library, Return from DAL to presentation layer, Add references
for namespaces
Solution:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Props;
using Dal;
using System.Data;
namespace Bll
{
public class EmpBll
{
public EmpBll(){ }
16
EmpDal Edal = new EmpDal();
return Edal.insertDAL(p1);
}
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Props;
namespace Dal
{
public class EmpDal
{
public EmpDal (){ }
17
sqlConn.Open();
int c1 = sqlComm.ExecuteNonQuery();
sqlConn.Close();
if ( c1 > 0 )
return true;
else
return false;
}
}
}
Application Code
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 Props;
using Bll;
namespace Multilayermngmntsys
{
public partial class Employee : Form
{
public Employee()
18
{
InitializeComponent();
}
if (b)
MessageBox.Show("Inserted
Successfully");
else
MessageBox.Show("Not inserted");
}
}
}
19
Lab Task 7
Description:
Solution:
Cmd.Parameters.Add(new SqlParameter("@id",
txtID.Text));
Cmd.Parameters.Add(new
SqlParameter("@name",txtName.Text));
Cmd.Parameters.Add(new
SqlParameter("@address",txtAdrs.Text));
Cmd.Parameters.Add(new
SqlParameter("@cell",txtCell.Text));
Cmd.Parameters.Add(new
SqlParameter("@email",txtEmail.Text));
Cmd.ExecuteNonQuery();
MessageBox.Show("Inserted Successfully");
20
}
@empCode int,
@empName VARCHAR(50),
@empCellNum VARCHAR(50),
@empAddress VARCHAR(50),
AS
INSERT INTO Employee values
(@empCode,@empName,@empCellNum,@empAddress)
return 0 //END
21
Lab Task 8
Description:
CREATE AN RDLC FILE, ADD TABLE AND SELECT COLUMNS, DESIGN HEADER AND FOOTER OF
REPORT. WRITE CODE BEHIND VIEW REPORT BUTTON TO DISPLAY LIST OF ALL EMPLOYEES AND
PRINT IT.
Solution:
public ViewReport()
InitializeComponent();
22
dataSet.CaseSensitive = true;
dataAdapter.Fill(dataSet, "customer");
dataTable = dataSet.Tables[0];
reportViewer1.Visible = true;
reportViewer1.LocalReport.ReportPath = "Report2.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",
dataTable));
this.reportViewer1.RefreshReport();
23
Lab Task 9
Description:
Develop a Calculator Application for Windows 8 Desktop and mobile using XAML.
Solution:
<Page
x:Class="firstXamlApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:firstXamlApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.Background>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="200"/>
<RowDefinition Height="Auto"/>
24
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Run Text="hello"/>
<Run Text="Application"/>
</TextBlock>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
25
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<LineBreak/>
</TextBlock>
</Grid>
<Run Text="stackpanel"/>
<LineBreak/>
<Run/>
<LineBreak/>
<Run Text="Calculator"/>
<LineBreak/>
<Run/>
</TextBlock>
</StackPanel>
<Ellipse.Fill>
26
<LinearGradientBrush EndPoint="1.0,0.5" StartPoint="2.0,0.5">
<GradientStop Color="#FFAC732F"></GradientStop>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
</Page>
27
Lab Task 10
Description:
SALES FORM, LOAD PRODUCT ON COMBO, BTN SHOW STOCK AND SELL PRODUCT.
Solution:
dataAdapter.Fill(dataSet, "Product");
if (dataSet.Tables[0].Rows.Count >= 0)
txtStock.Text = ""+Convert.ToInt32(dataSet.Tables[0].Rows[0]["prdStock"]);
28
int a = 0;
conn.Open();
cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
conn.Close();
29
Lab Task 11
"Opel Astra",
"Audi A4",
"Ford Focus",
"Seat Leon",
"VW Passat",
"VW Polo",
"Mercedes C-Class" };
select car;
sb.Append(entry + "\n");
Console.WriteLine(sb.ToString());
30
Console.ReadLine();
In the example above, an array of strings (cars) is used as a collection of objects to be queried using LINQ.
In a LINQ query, the from clause comes first in order to introduce the data source (cars) and the range
variable (car).
When the query is executed, the range variable will serve as a reference to each successive element in cars.
Because the compiler can infer the type of car, you do not have to specify it explicitly
________________________________________________________________________________________
______________________
where car.Contains("VW")
select car;
The WHERE clause is used to query the string array (cars) to find and return a subset of array which satisfies
the WHERE clause.
----------------------------------------------------------------------------------------
select car;
The orderby clause will cause the elements to be sorted according to the default comparer for the type
being sorted.
31
-------------------------------------------------------------------------------------------
Name = name;
UnitsSold = unitsSold;
class Program
32
var car7 = new Car("VW Polo", 69867);
select car.Name;
Console.WriteLine(entry);
Console.ReadLine();
33
Lab Task 12
USE [DBName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Name
-- Create date:
-- Description:
-- =============================================
AS
BEGIN
34
-- Insert statements for procedure here
return;
END
------------------------------------------------------------------------------------------------------------------------------------------------
--------------------
USE [DBName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Fariha
-- =============================================
35
AS
BEGIN
return 0;
END
________________________________________________________________________________________
____________________________________________________________________________________
USE [DBName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
36
-- Description: <Description,,>
-- =============================================
@id nvarchar(50)=null
AS
BEGIN
END
________________________________________________________________________________________
________________________________________________________________________________________
__
37
Lab Task 13
Develop a BLL and DAL using class library, Return from DAL to presentation layer, Add references for
namespaces
Solution:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Props;
using Dal;
using System.Data;
namespace Bll
public EmpBll(){ }
38
public bool insertBLL (EmpProps p1)
return Edal.insertDAL(p1);
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Props;
namespace Dal
39
SqlCommand sqlComm = new SqlCommand("INSERT INTO Employee VALUES (" + p.Code + ",'" +
p.Name + "','" + p.Cellno + "','" + p.Address + "')", sqlConn);
sqlConn.Open();
int c1 = sqlComm.ExecuteNonQuery();
sqlConn.Close();
if ( c1 > 0 )
return true;
else
return false;
Application Code
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 Props;
using Bll;
namespace Multilayermngmntsys
40
public partial class Employee : Form
public Employee()
InitializeComponent();
p.Code = Convert.ToInt32(txtCode.Text);
p.Name = txtName.Text;
p.Cellno = txtCell.Text;
p.Address = txtAdrs.Text;
bool b = ebl.insertBLL(p);
if (b)
MessageBox.Show("Inserted Successfully");
else
MessageBox.Show("Not inserted");
Lab Task 14
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace LINQ
XDocument xml;
// XDocument.Load(Server.MapPath("~XMLFile1.xml"));
xml = XDocument.Load(Server.MapPath("~/XMLFile1.xml"));
ID = p.Element("id").Value,
Name = p.Element("name").Value,
Cell = p.Element("cell").Value,
Salary = p.Element("salary").Value
EmployeeGrid.DataSource = bind;
EmployeeGrid.DataBind();
42
protected void Page_Load(object sender, EventArgs e)
BindGrid();
xml.Root.Add(emp);
xml.Save(Server.MapPath("~/XMLFile1.xml"));
BindGrid();
if (emp != null)
emp.Element("name").Value = txtName.Text;
emp.Element("cell").Value = txtCell.Text;
emp.Element("salary").Value = txtSalary.Text;
xml.Save(Server.MapPath("~/XMLFile.xml"));
BindGrid();
43
}
if (emp != null)
emp.Remove();
xml.Save(Server.MapPath("~/XMLFile.xml"));
BindGrid();
if (emp != null)
txtName.Text = emp.Element("name").Value;
txtCell.Text = emp.Element("cell").Value;
txtSalary.Text = emp.Element("salary").Value;
BindGrid();
44
}
txtID.Text = "";
txtName.Text = "";
txtCell.Text = "";
txtSalary.Text = "";
Lab Task 16
45
using (SqlCommand cmd = new SqlCommand("select title=City,lat=latitude,lng=longitude,description
from LocationDetails", con))
con.Open();
da.Fill(dt);
row.Add(col.ColumnName, dr[col]);
rows.Add(row);
return serializer.Serialize(rows);
46
string JSONresult;
JSONresult = JsonConvert.SerializeObject(dt);
Response.Write(JSONresult);
47