Social Icons

Pages

Wednesday, November 30, 2011

Binding Silverlight DataGrid using Linq to sql

This article explain in the simple way how to bind the silverlight datagrid using linq to sql. I have tried to capture all of the important details and provide a step-by-step example here.

Note, i'm using customer table of the  AdventureWorksLT Database for this project.
We will start creating the project in Visual Studio 2010
    1. Create a new Silverlight application and name the application as “DataGrid”.

    2. Right click on your the web project, then Add->New Item, and choose “LinqToSql”.

    3. Open the Server Explorer, then open the table and drag the table onto the Designer 
        workspace.

    4. The Serialization mode to Unidirectional by right-clicking on the Designer workspace and
         using the Property.

    5. Right click on your web project, then Add->New Item, and choose “WCF Service”.

    6.Open the IService1.cs file and add the GetCustomers method.
 List<Customer> list = db.Customers.ToList<Customer>();
    7. Open the Service1.svc.cs file and implement the GetCustomers method.
public List<Customer> GetCustomers()
{
DataClasses1DataContext db = new DataClasses1DataContext();
List<Customer> list = db.Customers.ToList<Customer>();
return list;
}
    8. Add a reference to the Web Service in the Silverlight project- To do that you need to
        right-click on the references in the Silverlight project and choose the
       'Add Service Reference' item. Then add the Service1.svc.



    9. Create a new DataGrid and Button and Set the DataGrid AutoGenerateColumns
        property as true. < AutoGenerateColumns="True" >

    10. In the button's Click event, create a new instance of the WebService, subscribe to the
          GetCustomerDetails event and call the GetCustomersAsync method.
     private void button1_Click(object sender, RoutedEventArgs e)
        {
       ServiceReference1.
Service1Client webService = new     DataGrid.ServiceReference1.Service1Client();
       webService.GetCustomersCompleted += new
  EventHandler<DataGrid.ServiceReference1.GetCustomersCompletedEventArgs>(GetCustomerDetails);
      webService.GetCustomersAsync();
        }
    11. Finally, in the GetCustomerDetails event handler, bind the DataGrid. Using this code
void GetCustomerDetails(object sender, DataGrid.ServiceReference1.GetCustomersCompletedEventArgs e)
{
this.Customer_Grid.ItemsSource = e.Result;
}
    12. Now run the program and click on display button to display the details.

Tuesday, November 15, 2011

Passing value from Child window to Parent window

Child Window is a great new feature in silverlight which enables you to use benefit of a fully better popup window. In this article I will explain the simple way how to pass the information child window to parent window

I am going to create an example in which user enters his/her first name and last name in a Child Window and once submitted entered first name and last name are displayed in the main page.

     1. We will start creating new Silverlight application in Visual Studio 2010 
     Click "New   project" in the Menu bar,Select " Silverlight Application" and name the  
     application as "SilverlightChildWindow".

     2. Add a new Child Window 
    In visual Studio right click on your Silverlight project, then, Add ->New Item ->  
    Silverlight Child Window. The Child Window will have an OK and a Cancel button by 
    default  when it is created. Add two textbox controls to the page for users to enter 
    their information.

     3. Create an EventHandler in Child Window
       public event EventHandler SubmitClicked;
    4. Create public properties to save the values
    Here I create two public properties of type string to save the value of both textBox  
    controls.
private string firstName;
  public string FirstName
   {
    get { return firstName; }
    set { firstName = value; }
   }
private string lastName;
  public string LastName
   {
    get { return lastName; }
    set { lastName = value; }
   }
     5. Pass the event once ok button is clicked in Child Window
     There should already be ok button in the child window when button is pressed; it is called  
     ‘OKButton_Click’. Inside that we need to fire the event which we created earlier, so that 
     our event gets fired when the code reaches this method.
    if (SubmitClicked != null)
            {
                FirstName = txt_FirstName.Text;
                LastName = txt_LastName.Text;
                SubmitClicked(this, new EventArgs());
            }
    this.DialogResult = true;
    6. Create a new instance of the Child Window in the MainPage.xaml page
private ChildWindow1 childwindow;
    7. Call the Child Window
    To do that, use the instance, which already created just call the method for Child Window.
private void button1_Click(object sender, RoutedEventArgs e)
        {
            childwindow.Show();
        }
     8. In MainPage.xaml catch up the submit event in Child Window
     Now we have an event which will get fired up from the Child Window when we click the 
     OK  button.
childwindow.SubmitClicked += new EventHandler(childWindow_SubmitClicked);
    9. Access the properties of the Child Window
private void childWindow_SubmitClicked(object sender, EventArgs e)
      {
            txt_FirstName.Text = childwindow.FirstName;
            txt_LastName.Text = childwindow.LastName;
        }

  • Main Page
  • Child Window

    • Again Main Page

      Wednesday, November 2, 2011

      Process of creating Snapshot

           1. Open SQL Server Management Studio, connect to the publication server and expand the replication folder.

           2. Connect to the Publisher in Management Studio, and then expand the server node, expand the Replication folder, and then expand the Local Publications folder.

           3. Right-click the publication for which you want to create a snapshot, and then click Properties.

       
           4. On the publication properties, select the snapshot page.

      • To select file path thick check box “put file in the following folder”
      • To get compress snapshot file thick check box “compress snapshot files in this folder”
      • Click ok to save the modification.
           5. Right-click the publication and then click View Snapshot Agent Status.


      6. Click start button to create snapshot.

       

       

      Tuesday, November 1, 2011

      Process of creating subscription

      This article provides step by step configuring  publication in SQL Server 2008R2
           1. Open SQL Server Management Studio, connect to the publishing server and expand the Replication folder.

           2. Inside the replication folder, right click Local Subscriptions and choose New Subscription from the  pop-up menu.



           3. Inside the replication folder, right click Local Subscriptions and choose New Subscription from the pop-up menu.

           4. Click ‘Next’ on the New Subscription Wizard welcome page.

           5. Then it will display publication screen, select the publication database and click ‘Next’ button to continue.

         
           6. Then, Select whether you wish to create a push or pull subscription and Continue. Here with pull subscription.


           7. On the subscribers window, select the subscriber database and click ‘Next’ to continue


           8. On the Merge Agent Security page, click … and enter the security account settings details.

       
      Merge agent security settings 

       

           9. On the Synchronization schedule window, keep the defaults and click ‘Next’ to continue.


           10. On the Initialize Subscriptions page, keep the defaults and click ‘Next’ to continue.

       

            11. Select the Subscription type and click ‘Next’ button.


           12. Then Enter the Host_Name value and click ‘Next’ button.


           13. On the Wizard Actions window, select the action when you click finish and click ’Next’ to continue.


           14. On the Complete the Wizard page, review the subscription settings and click Finish to create the subscription. SQL Server will provide a status window informing you of its progress creating the new subscription.