Enabling WCF RIA services to an existing Silverlight application is easy and straight forward. Navigate to the properties of Silverlight Project and go WCF RIA Services Link and select the ProjectName.Web.
Tuesday, May 10, 2011
Converting Silverlight Application to use WCF RIA Services
Monday, May 9, 2011
Editor - Ajax Control Toolkit
Editor control is an Html Editor in Ajax Control Toolkit control. Html Editors found extensive use in Content Mangament Systems and Blog Engines.
StreamWriter sw;
protected void Button3_Click(object sender, EventArgs e)
{
Response.Write(Editor1.Content);
sw = File.CreateText(Server.MapPath("Shalvin.txt"));
sw.WriteLine(Editor1.Content);
sw.Close();
}
Thursday, May 5, 2011
TechEd on the road - 14th May at ParkCenter, Technopark,Trivandrum
A free full day event by Kerala Microsoft User Group.
Agenda
08:45 - 09:30 Registration Confirmation
09:30 - 09:45 Opening / Welcome Note
09:45 - 10:45 Building cross browser web applications with HTML5/CSS3 by Rajasekharan Vengalil
10:45 - 11:30 Creating & Deploying Application for Azure by Amal
11:30 - 11:45 Tea Break
11:45 - 12:30 Visual Studio Productivity tools by Shoban
12:30 - 01:15 Windows Phone App development with XNA by Sreejumon
01:15 - 02:15 Lunch Break
02:15 - 03:00 Introducing Parallel Programming with .Net 4.0 by Bijith
03:00 - 03:45 Windows Work Flow 4.0 – A sneak Peek by Jeen
03:45 - 04:00 Tea break
04:00 - 05:00 Strategies for client side storage in the web world – DOM Storage and IndexedDB by Rajasekharan Vengalil
05:00 - 05:15 Closing Note
Register
Saturday, April 30, 2011
Microsoft WebCamps May 5 - June 30
Exclusive one day event on Microsoft Technologies at Mumbai, Chennai, Bangalore, Hydarabad and Pune.
http://www.microsoft.com/india/events/webcamps/default.aspx
Thursday, April 21, 2011
Microsoft Windows Azure Camp - 30th April - 2011
Zenith Hall, UST Global, Bhavani,Technopark, Trivandrum, Kerala
Agenda
Cloud Computing and Azure Overview
Azure Architecture
Azure Management Portal
Services and Tools Needed
Create and debug Azure Application
Deploy application in Azure
Lunch Break
Moving ASP.NET application to Azure
Moving SQL Express database to Azure SQL
Windows Azure App Fabric Cache
Register
Monday, April 18, 2011
WCF RIA Services with Silverlight 4
In the next dialog select Enable WCF RIA Service.
A Silverlight Solution comprises of two project one an Asp .Net Project and another the client Silverlight project.
I am creating an Ado .Net Entity Data Model for connecting to AirLines database in the Web Project.
Run the project. Add a Domain Service Class to the Web Project.
In the Add New Domain Service Class dialog you can see all the tables selected in the Ado .Net Entity Data Model. Check Enable Editing so that it will generate CUD (Create Update Delete) code.
Again run the project so that the Domain Service class will automatically generate the proxy which you can use from Silverlight.
Now I am ready consuming the Domain Service from Silverlight.
My intention is the show the contents of Locations table inside an DataGrid. I am also filling a ComboBox with LocationNames.
using SilverlightRiaShalvin.Web;
DomainService1 context = new DomainService1();
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
dataGrid1.ItemsSource = context.Locations;
comboBox1.ItemsSource = context.Locations;
comboBox1.DisplayMemberPath = "LocationName";
comboBox1.SelectedValuePath = "Locationid";
context.Load<Location>(context.GetLocationsQuery());
}
Here I am extracting the LocationId of the selected Location.
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
Here the code for inserting a value to Location Table.
private void button1_Click(object sender, RoutedEventArgs e)
{
var Loc = new Location{LocationName = "Trivandrum"};
context.Locations.Add(Loc);
context.SubmitChanges();
MessageBox.Show("Record saved");
}
Silverlight Business Application Air Lines Project
Now let's take up the AirLines project.
CREATE TABLE dbo.Locations(
LocationId int IDENTITY(1,1) PRIMARY KEY NOT NULL,
LocationName varchar(20),
Latitude numeric(6, 2),
Longitude numeric(6, 2),
Description varchar(50))
GO
CREATE TABLE dbo.Flight(
FlightId int IDENTITY(1,1) NOT NULL,
FlightNo varchar(10),
FromLocationId int,
ToLocationId int,
ArrivalTime varchar(10),
DepartureTime varchar(10),
NoofBusSeats int,
NoofEcoSeats int)
GO
CREATE TABLE dbo.FlightTrans(
TransId int IDENTITY(1,1) NOT NULL,
TransDate datetime ,
UserName varchar(20) ,
FlightId int,
EcoSeats int,
BusSeats int)
GO
CREATE TABLE dbo.FlightStatus(
FlightDetailId int IDENTITY(1,1) NOT NULL,
Flightid int,
TotalSeats int,
ExecutiveSeats int,
BuisnessSeats int,
FlightDate datetime,
BookedExecutiveSeats int,
BookedBusinessSeats int)
GO
CREATE TABLE dbo.FlightRate(
FlightRateId int IDENTITY(1,1) NOT NULL,
FlightId int,
BusStdRate numeric(8, 2),
EcoStdRate numeric(8, 2))
GO
Along the way I will also demonstrate a few Visual Studio 2010 features related to Silverlight and WPF.
I am starting a new Business Applicaiton Project. WCF Ria Services will be automatically added when you select Business Application Project.
I will get a project similar to new Asp .Net Web Site Project in Visual Studion 2010. It has a good navigation structure, nice look and feel and a few HyperlinkMenus to start with.
if you want to want to learn more about about Silverlight batabinding.
To switch off the Binding of the TextBlock that holds the Application name go to properties window click on the icon next to the Text property in the dialog select Reset settings. Then type your heading.
Like wise I am changing the Content property of Hyperlink buttons to Location and Flights respectively.
I am using Silverlight Child Window in this project. I am adding a Silverlight Child Window to the project selecting Silverlight Project from the Solution Explorer. As you know two projects will be created when you start new Silverlight project, Silverlight Project and an Asp .Net project for hosting the Silverlight Project. Earlier in the blow we saw adding Entity Data Model and Domain Service Class to the Asp .Net Project.
Insert Location
Location table holds the information about a Location. This table is referenced by Flights Table.
Here is the Xaml of the frmLocations Silverlight Child Window.
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="21,34,0,0" Name="label1" VerticalAlignment="Top" Width="120" Content="Location Name" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="21,70,0,0" Name="label2" VerticalAlignment="Top" Width="120" Content="Latitude" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="21,106,0,0" Name="label3" VerticalAlignment="Top" Width="120" Content="Longitude" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="118,26,0,0" Name="txtLocation" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="118,62,0,0" Name="txtLatitude" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="118,98,0,0" Name="txtLongitude" VerticalAlignment="Top" Width="120" />
<Button Content="Save" Height="23" HorizontalAlignment="Left" Margin="118,161,0,0" Name="btnSave" VerticalAlignment="Top" Width="75" Click="btnSave_Click" />
</Grid>
Add Entity Data Model and Domain Data Service class as demonstrated in the first part of the blog.
using ShalvinAirlines.Web;
AirLines context = new AirLines();
private void btnSave_Click(object sender, RoutedEventArgs e)
{
decimal intLatitude = decimal.Parse(txtLatitude.Text);
decimal intLongitude = decimal.Parse(txtLongitude.Text);
var Loc = new Location { LocationName = txtLocation.Text, Latitude = intLatitude, Longitude = intLongitude };
context.Locations.Add(Loc);
context.SubmitChanges();
MessageBox.Show("Location saved");
}
Numeric data type in Sql Server will be mapped to decimal data type in .Net.Insert Flight
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="72,61,0,0" Name="label1" VerticalAlignment="Top" Width="120" Content="From Location" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="181,54,0,0" Name="cboFrom" VerticalAlignment="Top" Width="120" />
<sdk:Label Content="To Location" Height="28" HorizontalAlignment="Left" Margin="72,103,0,0" Name="label2" VerticalAlignment="Top" Width="120" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="181,97,0,0" Name="cboTo" VerticalAlignment="Top" Width="120" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="72,139,0,0" Name="label3" VerticalAlignment="Top" Width="120" Content="Arrival Time" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="181,131,0,0" Name="txtArrivalTime" VerticalAlignment="Top" Width="120" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="72,175,0,0" Name="label4" VerticalAlignment="Top" Width="120" Content="Departure Time" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="181,167,0,0" Name="txtDepartureTime" VerticalAlignment="Top" Width="120" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="72,211,0,0" Name="label5" VerticalAlignment="Top" Width="120" Content="No. Economy Seats" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="181,203,0,0" Name="txtNoEconomySeats" VerticalAlignment="Top" Width="120" />
<sdk:Label Content="No. Business Seats" Height="28" HorizontalAlignment="Left" Margin="72,241,0,0" Name="label6" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="181,233,0,0" Name="txtNoBusinessSeats" VerticalAlignment="Top" Width="120" />
<Button Content="Save" Height="23" HorizontalAlignment="Left" Margin="181,277,0,0" Name="btnSave" VerticalAlignment="Top" Width="75" Click="btnSave_Click" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="72,26,0,0" Name="label7" VerticalAlignment="Top" Width="120" Content="Flight No." />
<TextBox Height="23" HorizontalAlignment="Left" Margin="181,18,0,0" Name="txtFlightNo" VerticalAlignment="Top" Width="120" />
</Grid>
using ShalvinAirlines.Web;
AirLines context = new AirLines();
private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
cboFrom.ItemsSource = context.Locations;
cboFrom.DisplayMemberPath = "LocationName";
cboFrom.SelectedValuePath = "LocationId";
cboTo.ItemsSource = context.Locations;
cboTo.DisplayMemberPath = "LocationName";
cboTo.SelectedValuePath = "LocationId";
context.Load(context.GetLocationsQuery());
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
int intFromId = Int32.Parse(cboFrom.SelectedValue.ToString());
int intToId = Int32.Parse(cboTo.SelectedValue.ToString());
int intNoBusSeats = Int32.Parse(txtNoBusinessSeats.Text);
int intNoEcoSeats = Int32.Parse(txtNoEconomySeats.Text);
var Fl = new Flight { FlightNo = txtFlightNo.Text,
FromLocationId = intFromId,
ToLocationId = intToId,
ArrivalTime = txtArrivalTime.Text,
DepartureTime = txtDepartureTime.Text,
NoofBusSeats=intNoBusSeats,
NoofEcoSeats= intNoEcoSeats };
context.Flights.Add(Fl);
context.SubmitChanges();
MessageBox.Show("Flight inserted");
}
First I filled the Combo Boxes with the LocationName and Set the SelectedValuePath to LocationId so that I an extract the LocationId of the Selected Item.Booking Module
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" Loaded="ChildWindow_Loaded">
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<sdk:Label Content="Flight" Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="label1" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="103,81,0,0" Name="txtEconomySeats" VerticalAlignment="Top" Width="120" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="103,10,0,0" Name="cboFlight" VerticalAlignment="Top" Width="120" />
<sdk:Label Content="Date" Height="28" HorizontalAlignment="Left" Margin="10,45,0,0" Name="label2" VerticalAlignment="Top" Width="120" />
<sdk:DatePicker Height="23" HorizontalAlignment="Left" Margin="103,45,0,0" Name="dtpDate" VerticalAlignment="Top" Width="120" />
<sdk:Label Content="Economy Seats" Height="28" HorizontalAlignment="Left" Margin="10,82,0,0" Name="label3" VerticalAlignment="Top" Width="120" />
<sdk:Label Content="Business Seats" Height="28" HorizontalAlignment="Left" Margin="10,131,0,0" Name="label4" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="103,123,0,0" Name="txtBusSeats" VerticalAlignment="Top" Width="120" />
<Button Content="Book" Height="23" HorizontalAlignment="Left" Margin="103,188,0,0" Name="btnBook" VerticalAlignment="Top" Width="75" Click="btnBook_Click" />
</Grid>
AirLines context = new AirLines();
private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
cboFlight.ItemsSource = context.Flights;
cboFlight.DisplayMemberPath = "FlightNo";
cboFlight.SelectedValuePath = "FlightId";
context.Load(context.GetFlightsQuery());
}
private void btnBook_Click(object sender, RoutedEventArgs e)
{
DateTime dt = DateTime.Parse(dtpDate.SelectedDate.ToString());
int intEcoSeats = Int32.Parse(txtEconomySeats.Text);
int intBusSeats = Int32.Parse(txtBusSeats.Text);
int intFlightId = Int32.Parse(cboFlight.SelectedValue.ToString());
var Book = new FlightTran { TransDate = dt, UserName = GlobalClass.UserName,
FlightId = intFlightId, EcoSeats = intEcoSeats, BusSeats = intBusSeats };
context.FlightTrans.Add(Book);
context.SubmitChanges();
MessageBox.Show("Booking completed");
}
Saturday, April 16, 2011
BarCamp Kerala 10
10th edition of BarCamp Kerala will be held at SCMS B-School at Kalamaserry on 8th May 2011.
For more details visit http://www.barcampkerala.org