Monday 29 October 2012

silverlight basic content


•the text Hello World rotates in a 360-degree circle.

<StackPanel Margin=”4”
HorizontalAlignment=”Center”
Orientation=”Horizontal”>
<TextBlock Width=”200” Height=”150”
FontSize=”24”>Hello World
<TextBlock.Triggers>
<EventTrigger RoutedEvent=”Canvas.Loaded”>
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard BeginTime=”0”
RepeatBehavior=”Forever”>
<DoubleAnimation
Storyboard.TargetName=”rotate”
Storyboard.TargetProperty=”Angle”
To=”360”
Duration=”0:0:10”/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</TextBlock.Triggers>
<TextBlock.RenderTransform>
<RotateTransform x:Name=”rotate”
Angle=”0”
CenterX=”300”
CenterY=”200”/>
</TextBlock.RenderTransform>
</TextBlock>
</StackPanel>

•A big part of why Silverlight is an exciting technology is that it provides a rich, vector-based drawing
system as well as support for complex animations.
the following XAML displays an image
in its normal, square shape:

<Canvas>
<Image
Source=”Images/elk.jpg”
Width=”200” Height=”150”>
</Image>
</Canvas>

Using the EllipseGeometry class, you can clip the image into whatever shape you desire. This
XAML clips the image into an oval:

<Canvas>
<Image
Source=”Images/elk.jpg”
Width=”200” Height=”150”>
<Image.Clip>
<EllipseGeometry RadiusX="85" RadiusY="100" Center="100,85"/>
</Image.Clip>
</Image>
</Canvas>

Once you render your geometries or shapes into something meaningful, you can use Brushes,
VideoBrushes, or Transforms to further give life to your UI rendering. The following XAML takes
a basic TextBlock and adds a LinearGradientBrush for some nice special effects:
<TextBlock
Canvas.Top=”100”
FontFamily=”Verdana”
FontSize=”32”
FontWeight=”Bold”>
Linear Gradient Brush
<TextBlock.RenderTransform>
<ScaleTransform ScaleY=”4.0” />
</TextBlock.RenderTransform>
<TextBlock.Foreground>
<LinearGradientBrush StartPoint=”0,0” EndPoint=”1,1”>
<GradientStop Color=”Red” Offset=”0.0” />
<GradientStop Color=”Blue” Offset=”0.2” />
<GradientStop Color=”Green” Offset=”0.4” />
<GradientStop Color=”Olive” Offset=”0.6” />
<GradientStop Color=”DodgerBlue” Offset=”0.8” />
<GradientStop Color=”OrangeRed” Offset=”1.0” />
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>

Page Layouts and design
==========================
Silverlight includes several options for doing rich, resolution-independent layout using a Canvas,
DockPanel, Grid, StackPanel, and WrapPanel element.
Canvas — An absolute positioning panel that gives you an area within which you can position
child elements by coordinates relative to the Canvas area. A Canvas can parent any
number of child Canvas objects.
➤➤ DockPanel — Used to arrange a set of objects around the edges of a panel. You specify
where a child element is located in the DockPanel with the Dock property.
➤➤ Grid — Similar to an HTML table, it’s a set of columns and rows that can contain child
elements.
➤➤ StackPanel — A panel that automatically arranges its child elements into horizontal or vertical
rows
➤➤ WrapPanel — Allows the arrangement of elements in a vertical or horizontal list and has elements
automatically wrap to the next row or column when the height or width limit of the
panel is reached.
CANVAS
The following code shows a Canvas object with several child elements absolutely positioned within the Canvas:
<Canvas>
<Rectangle
Canvas.Top =”30”
Canvas.Left=”30”
Fill=”Blue”
Height=”100” Width=”100”/>
<Rectangle
Canvas.Top =”75”
Canvas.Left=”130”
Fill=”Red”
Height=”100” Width=”100”/>
<Ellipse
Canvas.Top =”100”
Canvas.Left=”30”
Fill=”Green”
Height=”100” Width=”100”/>
</Canvas>

DOCKPANEL
In the following example , you can see how a DockPanel can be confi gured to return
the results

<StackPanel x:Name=”LayoutRoot” Background=”White”>
<TextBlock Margin=”5” Text=”Dock Panel” />
<Border BorderBrush=”Red” BorderThickness=”2” >
<controls:DockPanel LastChildFill=”true”
Height=”265”>
<Button Content=”Dock: Left”
controls:DockPanel.Dock =”Left” />
<Button Content=”Dock: Right”
controls:DockPanel.Dock =”Right” />
<Button Content=”Dock: Top”
controls:DockPanel.Dock =”Top” />
<Button Content=”Dock: Bottom”
controls:DockPanel.Dock =”Bottom” />
<Button Content=”Last Child” />
</controls:DockPanel>
</Border>
</StackPanel>

Adding video to web page
<Grid x:Name=”LayoutRoot” Background=”White”>
<MediaElement Source=”Images/video1.wmv” />
</Grid>

DATaBINDING
<TextBlock x:Name=”Title”
Text=”{Binding Title, Mode=OneWay}” />

Monday 22 October 2012

Triggers in sql server


/*a trigger can be created in order to perform any action upon a DDL statement.
The scope can be database level or Server level. DDL triggers are used when you want
 a certain action to be performed when a schema change occurs*/
 create table userdata(username varchar(50),Operations varchar(30),dateandtime datetime)

 create trigger empinsert on emp
 for  insert
 as
 insert into userdata values(suser_sname(),'Inserted',getdate())

select  * from Emp
select * from UserData
insert into Emp values('DHEERAJ',16000,20)

--drop trigger <triggername>


alter trigger empinsertafter on emp
after insert
as
insert into userdata values(suser_sname(),'After Inserted',getDate())

insert into emp values('MAHADEV',8000,20)

select * from emp
select * from userdata



create trigger updateemp on emp
for Update
as
insert into UserData values(suser_sname(),'Updated',getDate())

update emp set esalary='5000' where empno='100'

select * from emp

select * from userdata


create trigger updateafter on emp
after update
as
insert into userdata values(suser_sname(),'After Updated',getdate())

update emp set ename='SHANKARP' where empno='100'

select * from userdata
select * from emp


create trigger deleteemp on emp
for delete
as
insert into userdata values(suser_sname(),'Deleted',getdate())

delete emp where empno=111
select * from userdata


create trigger deleteafter on emp
after delete
as
insert into userdata values(suser_sname(),'After deleted',getdate())

delete emp where empno=109

select * from userdata



create trigger insteadofemp on emp
instead of Insert
as
insert into UserData values(suser_sname(),'Instead of Insert',getDate())
print 'Inserted data was not saved in the table';

insert into emp values('MAHESHWAR',15000,30)
select * from emp
select * from userdata

create trigger insteadofdel on emp
instead of delete
as
insert into userdata values(suser_sname(),'Instead of delete',getdate())

delete emp where empno=108
select * from emp
select * from userdata

alter trigger insteadofupdate on emp
instead of update
as
insert into userdata values(suser_sname(),'Instead of updated',getdate())
print 'it was not updated'
update emp set esalary=8000 where ename='SHANKARP'

select * from emp
select * from userdata



View in sql server


create view flightinfo
as
select fname,finformation from flights
go

select * from flightinfo
--
create view employee
as
select emp.ename,emp.esalary,dept.dname from emp join dept on emp.deptno=dept.deptno
go

Friday 19 October 2012

Entity Data Model With Stored Procedure in Silverlight


1.Create Silverlight application with the name of   DemoEntityFrameWork,
2.Add edmx file to DemoEntityFrameWork.web and name it as DemoEntityFrameWork.edmx
3.Establish connection from sqlserver required database.
4.check required stored procedures with related tables.
5.Click on finish button. Now .edmx file generates in solution explorer under DemoEntityFrameWork.web
6.Next step is model browser. For getting model browser click on view-->Other Windows-->Entity Data Model browser.
Model Browser
1.Extract stored procedures folder ,it has stored procedures what ever we added to the .edmx file.
2.Stored procedures folder place  under the <datbasename>.store file in  ModelBrowser.
3.Right Click on required sored procedure and  take Add Function Import option.
4.Dialog box will be displayed.
5.select stored procedure name--->Click Complex Radio Button--->Create new complex type--->Ok
6.Add domain service to DemoEntityFrameWork.web and name it as DemoEntityFrameWorkDomainService.cs
7.Write the fallowing code in DemoEntityFrameWorkDomainService.cs  for connection
public IList<GetProducts_Result> GetProductDetails()
        {
            try
            {
                this.ObjectContext.Connection.Open();
                return this.ObjectContext.GetProducts().ToList();
            }
            catch (Exception exp)
            {
                // Logger.WriteLog(exp.Message);
                throw;
            }
            finally
            {
                if (this.ObjectContext.Connection.State != ConnectionState.Closed)
                    this.ObjectContext.Connection.Close();
            }
        }

8.create metadata folder under the DemoEntityFrameWork.Web and create one class with the name GetSubsidiary_Result.cs
9.Write the fallowing code in the class
[MetadataTypeAttribute(typeof(GetProducts_Result.GetProducts_ResultMetadata))]
    public partial class GetProducts_Result
    {
        internal sealed class GetProducts_ResultMetadata
        {
            [Key]
            public int ProductId { get; set; }
        }

    }
10.Write userdefine method in mainpage.xaml.cs for binding values to the comboBox
public partial class MainPage : UserControl
    {
        DemoEntityFrameWorkDomainContext _context;
        public MainPage()
        {
            InitializeComponent();
            _context=new DemoEntityFrameWorkDomainContext();
         
        }
        #region loadsubsidiary
        void LoadSubsidaries()
        {
            _context.Load(_context.GetProductDetailsQuery()
                , delegate(LoadOperation<GetProducts_Result> gSR)
                {
                    foreach (GetProducts_Result sub in _context.GetProducts_Results)
                    {
                        dgData.DataContext = sub;

                        ComboBoxItem itm = new ComboBoxItem();
                        itm.Content = sub.ModelNumber;
                        comboBox1.Items.Add(itm);
                    }
                }
            , null);
        }

        #endregion

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            LoadSubsidaries();
        }      
    }
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" Loaded="UserControl_Loaded"

Thursday 18 October 2012

Working with html5 controls in visual studio


For Working with html5 controls in visual studio we have to Download and install the extension from Web Standards Update for Microsoft Visual Studio 2010 SP1.
Before starting development of a new site, we need to change the HTML standards validation target to HTML5.
Click on Debug, Option and Settings, under Text Editor, HTML, Validation change the Target to HTML5.
Click on ok button.

comboBox selection change in silverlight


 private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var ComboBox = sender as ComboBox;
            result.Text = (ComboBox.SelectedItem as emp).EmpNo.ToString();
            result.Text += (ComboBox.SelectedItem as emp).EmpName.ToString();
        }

Wednesday 17 October 2012

Export GridView to pdf in asp.net


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;


public partial class pdf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(hw);
        GridView1.HeaderRow.Style.Add("width", "15%");
        GridView1.HeaderRow.Style.Add("font-size", "10px");
        GridView1.Style.Add("text-decoration", "none");
        GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
        GridView1.Style.Add("font-size", "8px");
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }
}

Monday 15 October 2012

Silver light basic information


Silverlight is a web application framework that runs on the client and delivers Rich Internet Applications
(RIA) capability.
Silverlight is not only an appealing canvas for displaying rich and interactive Web and media
content to end users. It is also a powerful yet lightweight platform for developing portable, crossplatform,
networked applications that integrate data and services from many sources.
Furthermore, Silverlight enables you to build user interfaces that will significantly enhance the
typical end user experience compared with traditional Web applications.
App.xaml & App.xaml.cs: This class is the entry point for the application as a whole. The class handles
application startup and has several events for handling application wide events such as startup, exit and
unhandled exceptions.
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
}.

1. "App" represents the application class. This class handles instantiation and other application level
tasks.
2. "MainPage" has xaml to describe the user interface for your application and code-behind to define the
logic.
3. After the Silverlight application is compiled, the "xap" is placed in the host web application \ClientBin
folder.
4. Standard ASP.NET or HTML test pages are automatically added to the host web application. These
pages contain "<object>" tags that reference the Silverlight plugin. The two pages are substantially the
same. Looking at the "*.html" file we can see that it contains boilerplate Javascript code for handling
Silverlight errors. In the HTML portion of the file below the Javascript, there is an "<object>" element. The
object element represents the Silverlight plugin. Notice that it has a series of parameter tags that tell it
where the "xap" file can be found and what Javascript should be run if there's an error.
"minRuntimeVersion" and "autoUpgrade" are configured to automatically update the plugin if it is out of date.. .

Silverlight Devlopment Tools
Both Visual Studio and Expression Blend can be used to build Silverlight applications. In fact, you can work
in both environments for the same project and pass the project back in forth. Both environments sense
when changes have been made outside their environments and update their interfaces accordingly. Both
environments have shortcuts to invoke each other.
Silverlight SDK
The SDK includes the necessary Silverlight assemblies, documentation, Visual Studio templates and
examples. This download is required for developing Silverlight applications. The install currently includes the
following DLL's:
System.ComponentModel.DataAnnotations.dll
System.Data.Services.Client.dll
System.Json.dll
System.Runtime.Serialization.Json.dll
System.ServiceModel.PollingDuplex.dll
System.ServiceModel.Syndication.dll
System.Windows.Controls.Data.dll
System.Windows.Controls.Data.Input.dll
System.Windows.Controls.dll
System.Windows.Controls.Input.dll
System.Windows.Controls.Navigation.dll
System.Windows.Data.dll
System.Windows.VisualStudio.Design.dll
System.Xml.Linq.dll
System.Xml.Serialization.dll
System.Xml.Utils.dll

Mainpage.xml
Your typical starting point for a XAML file is the either the App.xaml or MainPage.xaml. In App.xaml you
can define resources for the entire application. We will discuss resources a little later but for now take a
look at MainPage.xaml. The page starts out looking like the example below.
Adding and Theming RadControls
Once installed to the Toolbox, RadControls can be dragged into the XAML just as you would drag a
standard Silverlight control.
DataBinding
Path: The name of the source property to get the data from. The example below omits the "Path" attribute
in favor of the shorter syntax where the property following "Binding" is the Path, i.e. "Title".
Source: The standard CLR object that contains the data. This object is assigned to the
FrameworkElement DataContext.

Mode: The data's direction of travel. This can be OneTime where the data is set one time and is not
updated after that, OneWay where the data flows one way from the CLR object to the Silverlight element
and TwoWay where the source object updates the target element and the target element can also update
the source object.
<UserControl.Resources>
<local:Category x:Key="Category" Title="Fiction"
Description="No one is better than you,other than yourself.just believe and never be afraid." />
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<TextBox x:Name="tbTitle"
Text="{Binding Title, Source={StaticResource Category}, Mode=OneTime}"
HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="100"
></TextBox>
</Grid>

Stored Procedures in sqlserver


CREATE PROC usp_encryption
WITH ENCRIPTION
AS
BEGIN
SELECT * FROM emp
END

CREATE PROC usp_EvenOdd @i int
AS
BEGIN
IF @i%2=0
BEGIN
PRINT cast(i as varchar)+’is even number’
END
ELSE
PRINT cast(i as varchar)+’is odd number’
END


CREATE PROC usp_addition @i int,@j int
AS
BEGIN
DECLARE @res int
SET @res=@i+@j
PRINT  ‘The Addition is ‘+CAST(@res AS VARCHAR)
END

EXEC usp_addition 20,30

CREATE PROC usp_outputtest @sal money,@updatesal money output
AS
BEGIN
SET @updatesal=@sal+1500
END
CREATE PROC usp_updatesal @eno int
AS
BEGIN
DECLARE @sal money,@updatedsal money
SELECT @sal=sal FROM emp WHERE eno=@eno
EXEC usp_outputtest @sal,@updatesal output
UPDATE emp SET sal=@updatedsal WHERE eno=@eno
END

EXEC usp_updatesal 1

Thursday 11 October 2012

Entity FrameWork


What is Entity Framework?
Entity Framework is an Object Relational Mapper (ORM). It basically generates business objects and entities according to the database tables and provides the mechanism for:
1. Performing basic CRUD (Create, Read, Update, Delete) operations.
2. Easily managing "1 to 1", "1 to many", and "many to many" relationships.
3. Ability to have inheritance relationships between entities.

What are the benefits of using it Entity Framework?

• We can have all data access logic written in higher level languages.
•  The conceptual model can be represented in a better way by using relationships among entities.
•  The underlying data store can be replaced without much overhead since all data access logic is present at a higher level.

 is Entity Framework an alternative to ADO.NET?
the answer would be "yes and no".
 Yes because the developer will not be writing ADO.NET methods and classes for performing data operations
no because this model is actually written on top of ADO.NET, meaning under this framework, we are still using ADO.NET.