Tuesday, 20 August 2013

Some Queries using Language integrated Query ( LINQ ).

Let Us perform some queries using Linq:

1. Retrieve all records from database
   sampleDataContext sdc = new sampleDataContext();
   //var data = from d in sdc.ToyShops select d ;(retrieve all records)
   var data = from d in sdc.ToyShops select new { id=d.toyId,name=d.toyname};// retrieve selected column
   dataGridView1.DataSource = data;

2. Update records from database
    sampleDataContext sdc = new sampleDataContext();
    ToyShop ts = sdc.ToyShops.Single(c => c.toyId == Convert.ToInt32(textBox1.Text));
    ts.toyname = textBox2.Text;
    sdc.SubmitChanges();
    MessageBox.Show("records Updated successfully !!");

3. Delete records from database
    sampleDataContext sdc = new sampleDataContext();
    ToyShop ts = sdc.ToyShops.Single(c => c.toyId == Convert.ToInt32(textBox1.Text));
    sdc.ToyShops.DeleteOnSubmit(ts);
    sdc.SubmitChanges();
    MessageBox.Show("records deleted  successfully !!");

4. Delete records from database
    sampleDataContext sdc = new sampleDataContext();
     ToyShop ts = new ToyShop();
     ts.toyId = Convert.ToInt32(textBox1.Text);
     ts.toyname = textBox2.Text;
     sdc.ToyShops.InsertOnSubmit(ts);
     sdc.SubmitChanges();
     MessageBox.Show("data inserted successfully ");

5. Skip() and Take()
     sampleDataContext sdc = new sampleDataContext();
     var data = (from d in sdc.ToyShops select d).Skip(1).Take(2);
     dataGridView1.DataSource = data;


6. Generate Computable fields using Linq
      sampleDataContext sdc = new sampleDataContext();
      //var data = from d in sdc.ToyShops select d ;(retrieve all records)
      var data = from d in sdc.ToyShops select new { id = d.toyId, name = d.toyname,price=d.price,quantity=d.nofQuantity,netPrice=d.price*d.nofQuantity };

      dataGridView1.DataSource = data;


Note :
Where Toyshop is the name of the Table in your database .

Retrieve all records from database

sampleDataContext sdc = new sampleDataContext();
   //var data = from d in sdc.ToyShops select d ;(retrieve all records)
   var data = from d in sdc.ToyShops select new { id=d.toyId,name=d.toyname};// retrieve selected column

   dataGridView1.DataSource = data;

Datagrid Binding implementation with selected column:

On Page_Load:
Var data=from d in <dbmlFileContextObj>.tableName select d;
Just set :
this.dataContext=d;

  after setting context come on markup code:
 
<DataGrid  HorizontalScrollBarVisibility="Auto"  VerticalScrollBarVisibility="Visible"  ItemsSource="{Binding }"  AutoGenerateColumns="False">
            <DataGrid.Columns>
             <DataGridTextColumn Header="CardId" Binding="{Binding cardId, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" />
             <DataGridTextColumn Header="StudentName" Binding="{Binding tudentName,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" />
            </DataGrid.Columns>

  </DataGrid>

Thursday, 9 May 2013

“ Let Us Learn Php “



  • Display simple message on php page using 'echo' :

echo 'hello php';
echo "hello php";
       but,it is quite confusing to use single quotes and double quotes .let us   clear that issue
echo 'hello \n php';
echo "hello \n php";

clarification :
 single quotes does not consume '\n' and print as it is on php page . while double quotes consumes and does not shows '\n' on page .


  • Simple Variabe usage :

$name='ashwani';       //declaration of variable prefix with $ symbol
echo "hi !! dear, $name";     // display alue stored in name variable .


  • Remove data from variable

$name='ashwani';      //declaration of variable prefix with $ symbol
echo "hi !! dear, $name"

unset($name);

echo "after unset , $name"

Note : unset() gives an exception that is based on the error level of php page which can be modified as per requirement.


  • Display the type of data using var_dump()

$age=32;
var_dump($age);    //output: int
$name="ashwani\n";
var_dump($name);   //output:'string' with length in trems of characters
$name='ashwani\n';
var_dump($name);   //output:'string' with length in trems of characters
$percentage=78.65;
var_dump($percentage);   //output: float
$result=true;
var_dump($result);   //output:boolean


  • Defining constants in php using define()

define('pi','mathematical pie');//declaration of constant value with name 'pi'
echo "define usage ".pi // display value of 'pi' constants


  • Specify the type of data

$name="ashwani";
echo gettype($name); //output:string


  • Display table using for loop in php

for($i=0;$i<=10;$i++)
{
echo "<li>2 * $i = 2*$i</li>";
}


  • Arrays in php

$fruits=array('orange','mango','banana','apple');      //declaration of array with name fruits
echo "size of array name fruit is :".count($fruits);    //counts the size of array
for($i=0;$i<=4;$i++)
{
echo $fruits[$i]."\r\n";//display each and every elements of array .
}


  • foreach loop usage :


foreach($fruits as $f)
{
echo $f."\r\n";
}


  • Array inside array using keys

$directory=array(
array('name'=>'ashy','phone'=>'5674'),
array('name'=>'ashwani','phone'=>'56')
);
echo "the first array element phone number is :".$directory[1]['phone'];
By using echo command we have display the value stored in array at index position 1 and with key ‘phone’.


  • Remove the first element from array

array_shift($names); //$names is the name of array


  • Remove the last element from array

array_pop($movies);    //$movies is the name of array


  • add element at the last in array

array_push($movies, 'Ratatouille');


  • add element at the begining in array

array_unshift($movies, 'The Incredibles');


  • Transfer data from one form to another form

We are going to transfer a value entered in a atext box and selected from a list
and transfer them on then next page .
Let us create an form in php using html
<html>
<head></head>
<body>
<form action="page2.php" method="post">
Enter name <input type="text" name="name"\><br>
Select month name :<select name="mnthname">
<option>January</option>
<option>February</option>
</select><br>
<input type="submit" value="transfer value onb next page ";
</form>
</body>
Save this file page1.php
Now create another file with name page2.php
<?php
$monthname=$_POST['mnthname']; //retrieve value from parameter
$Name=$_POST['name']; //retrieve value from parameter
if(empty($Name))
{
die('error please provide us a name'); //raise exception if Name is empty
}
else
{
}
?>
Now run page1.php and verifies the result.

Saturday, 16 March 2013

DYNAMIC RESOURCE BINDING


1. Open vs 2010->File->New->Project
2. Select Windows Template->Wpf(WIndowBased)/Wpf(XBAPs) as per your requirement
3. You will find default code like this.


<Window x:Class="programically.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
      <Grid>
     </Grid>
</Window>


4. Create a Window Resource using <Window.Resources> Tag under <Window> Tag

<Window x:Class="programically.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Window.Resources>
        <SolidColorBrush x:Key="red" Color="red" />
    </Window.Resources>
     <Grid>

     </Grid>
</Window>

5. Replace the <Grid></Grid> tag with <StackPanel></StackPanel> and put a DockPanel  with name "myDock" under StackPanel Tag.

<Window x:Class="programically.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Window.Resources>
        <SolidColorBrush x:Key="red" Color="red" />
    </Window.Resources>

     <Grid>
         <StackPanel>
                <DockPanel x:Name="mydock" Height="90">
                </DockPanel>
         </StackPanel>
     </Grid>


</Window>



6. Now, we are going to access this resource Key from code behind file,switch to the code behind file
and paste the following coding under the load event of page .

 this.mydock.SetResourceReference(DockPanel.BackgroundProperty, "red");


7. Press F5 and test the result .



Tuesday, 5 March 2013

JAVAFX


 What Is JavaFX?

The JavaFX platform is the evolution of the Java client platform designed to enable application developers to easily create and deploy rich internet applications (RIAs) that behave consistently across multiple platforms. Built on Java technology, the JavaFX platform provides a rich set of graphics and media API with high-performance hardware-accelerated graphics and media engines that simplify development of data-driven enterprise client applications.
Investing in the JavaFX platform provides the following advantages to Java developers and companies that are part of the Java ecosystem:
Because the JavaFX platform is written in Java, Java developers can leverage their existing skills and tools to develop JavaFX applications.
Because Java is widely used, it is easy to find experienced Java developers who can quickly become productive building JavaFX applications.
By using a homogenous set of Java technologies for both the server and the client platforms, the JavaFX platform reduces the risk of investment by reducing the complexity of the business solutions.
Development costs are also reduced because of the aforementioned advantages.
The JavaFX platform provides developers with a development framework and runtime environment to create enterprise and business applications that run across multiple platforms that support Java.
See the JavaFX Architecture and Framework document to learn about the JavaFX platform's architecture and key concepts.

Key Features Of JavaFx

The main focus areas for the JavaFX 2 release include the following features, many of which are also described in the JavaFX Architecture and Framework document:
Full integration with JDK 7 is now available. As of the release of JavaFX SDK 2.2 and Java SE 7 update 6, the JavaFX SDK is fully integrated with the Java SE 7 Runtime Environment (JRE) and Development Kit (JDK). A standalone download of JavaFX 2 SDK for Windows will remain available for users of JDK 6 until Oracle releases the last Java SE 6 public update on November 2012. This integration with the JDK 7 removes the need to download and install JavaFX 2 SDK separately.
Java APIs for JavaFX that provide all the familiar language features (such as generics, annotations, and multithreading) that Java developers are accustomed to using. The APIs are designed to be friendly to alternative JVM languages, such as JRuby and Scala. Because the JavaFX capabilities are available through Java APIs, you can continue to use your favorite Java developer tools (such as IDEs, code refactoring, debuggers, and profilers) to develop JavaFX applications.

A new graphics engine to handle modern graphics processing units (GPUs). The basis of this new engine is a hardware accelerated graphics pipeline, called Prism, that is coupled with a new windowing toolkit, called Glass. This graphics engine provides the foundation for current and future advancements for making rich graphics simple, smooth, and fast.

FXML, a new declarative markup language that is XML-based and is used for defining the user interface in a JavaFX application. It is not a compiled language and, hence, does not require you to recompile the code every time you make a change to the layout.

A new media engine that supports playback of the web multimedia content. It provides a stable, low latency media framework that is based on the GStreamer multimedia framework.

A web component that gives the capability of embedding web pages within a JavaFX application using the WebKit HTML rendering technology. Hardware accelerated rendering is made available using Prism.
A wide variety of built-in UI controls, which include Charts, Tables, Menus, and Panes. Additionally, an API is provided to allow third parties to contribute UI controls that the user community can use.
An application packager that takes the guess out of building an easy to deploy standalone desktop application containing all the Java runtime libraries needed to install and run a JavaFX application.
Available on Windows, Mac OS X, and Linux platforms. As of JavaFX 2.2 release, JavaFX is available on all major desktop platforms, ensuring a consistent runtime experience for developers and end users alike. Oracle ensures synchronized releases and updates on all three platforms, and offers an extensive support program for companies running mission-critical applications.

Monday, 11 February 2013

TRANSFORMATIONS


Render Transformation with the help of a slider.

1. Open visual studio (above ver. 2.0 )->File->New->Project
2. Select appropiate application type (Window/Page).
3. Create a root tag <stackPanel> under Window/Page tag , remove already given <grid> tag
4. Create a grid with 3 rows and 3 columns under Border Tag like this.
<StackPanel>
<Border BorderThickness="8"  BorderBrush="SkyBlue" CornerRadius="20">
            <Grid Width="275" Margin="2.5" Height="77">
                <Grid.RowDefinitions>
                    <RowDefinition Height="28*" />
                    <RowDefinition Height="23*" />
                    <RowDefinition Height="26*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="66*" />
                    <ColumnDefinition Width="128*" />
                    <ColumnDefinition Width="81*" />
                </Grid.ColumnDefinitions>
</Grid>
 </Border>  
4. Now, place three labels,three sliders and three textBoxes in between the closing tag  </grid.ColumnDefinitions> and </grid>
where,
label1 with text "For Rotate Transform" under first row and first column i.e grid.Row=0,grid.Column=0.
label2 with text "set x axis" under fsecond row and first column i.e grid.Row=1,grid.Column=0.
label2 with text "set y axis" under third row and first column i.e grid.Row=2,grid.Column=0.
               
e.g.
 <Label Content="For rotate transform" Grid.ColumnSpan="2" Margin="0,0,74,0" />
                <Slider  TickFrequency="2" Name="slider" Maximum="360" Minimum="-360" Grid.Column="1" />
                <TextBox Text="{Binding ElementName=slider,Path=Value}"  Grid.Column="2" Grid.ColumnSpan="2" Margin="20,0,0,0" />
                <Label Content="Set X Axis" Grid.Row="1" Margin="0,0,28,0" />
                <Slider IsSnapToTickEnabled="True" TickFrequency="2" Name="xslider" Maximum="360" Minimum="-360" Grid.Row="1" Grid.Column="1" />
                <TextBox Grid.Row="1" Text="{Binding ElementName=xslider,Path=Value}"  Grid.Column="2" Grid.ColumnSpan="2" Margin="20,0,0,0" />
                <Label Content="Set Y Axis" Grid.Row="2" Margin="0,0,28,0" />
                <Slider IsSnapToTickEnabled="True" TickFrequency="2" Name="yslider" Maximum="360" Minimum="-360" Grid.Row="2" Grid.Column="1" />
                <TextBox Grid.Row="2" Text="{Binding ElementName=yslider,Path=Value}"  Grid.Column="2" Grid.ColumnSpan="2" Margin="20,0,0,0" />
            </Grid>
Grid.Row="2" Text="{Binding ElementName=yslider,Path=Value}"  Grid.Column="3" />
            </Grid>
note:
Slider's attribute :
IsSnapToTickEnabled="True" , if u make this property false then you will get decimal values for cordinate in textbox
TickFrequency="2" ,  specifies the step value(increment value ) .


5. Place the following component under closing </border> Tag and   </StackPanel>tag. Two Labels , one for showing demo of RotateTransform ( rotate acc to the value specified by sliders) and other shows TranslateTransform ( to move label acc to x cordinate and y cordinate provided by slider) and the last one is ellipse to demostrate the example of skew Transformation.

 RotateTransform:

<Label Content="RotateTransform " FontFamily="Bell MT" FontSize="20" Height="33" Width="178">
            <Label.RenderTransform>
                <RotateTransform CenterY="{Binding ElementName=xslider,Path=Value}" CenterX="{Binding ElementName=xslider,Path=Value}" Angle="{Binding ElementName=slider,Path=Value}"/>
            </Label.RenderTransform>
        </Label>

TransLateTransform:

<Label Content="TranslateTransform " FontFamily="Bell MT" FontSize="20" Height="33" Width="178">
            <Label.RenderTransform>
                <TranslateTransform X="{Binding Path=Value, ElementName=xslider}" Y="{Binding Path=Value, ElementName=yslider}"/>
                </Label.RenderTransform>
        </Label>

SkewTransform:

<Ellipse Fill="pink" Height="85" Width="241">
            <Ellipse.Effect>
                <DropShadowEffect BlurRadius="10" ShadowDepth="11" Color="CadetBlue">       </DropShadowEffect>
            </Ellipse.Effect>
            <Ellipse.RenderTransform>
                <SkewTransform
CenterX="{Binding Path=Value, ElementName=xslider}"
CenterY="{Binding Path=Value, ElementName=yslider}"
AngleX="{Binding Path=Value, ElementName=xslider}"
AngleY="{Binding Path=Value, ElementName=yslider}"
/>
            </Ellipse.RenderTransform>
        </Ellipse>
</Window>

6.Now run (F5) to see  the effects by moving the sliders.




Note :

The TranslateTransform is one of the simplest transformations you can perform.The TranslateTransform simply moves (translates)
an element along a two-dimensional X and Y axis. A positive X value moves the element to the right; a negative value moves it to the left. Similarly, a positive Y value moves the element down, and a negative value moves it up. This is really an offset from the element’s original position. TranslateTransform is really just a convenience wrapper for setting the OffsetX and OffsetY properties
of the transform Matrix structure.