Wednesday, May 27, 2009

Silverlight in Visual Studio 2010

Hello, Before I start with the article, First I would like to Thank You very much for your wonderful response and feedback to my articles over here and encouragement given time to time. Microsoft MVP Award Program made note of this at their recent blog post :

http://blogs.msdn.com/mvpawardprogram/archive/2009/05/26/indian-mvp-inspired-by-silverlight-3.aspx

Thanks to all of you once again, and I will try my best to keep the same in coming days, So now lets see how to go for Silverlight Project in VS 2010. This is very small post and idea is to get familiar with the new environment of Visual Studio 2010 along with Silverlight Project Template.

I have already wrote about Visual Studio 2010 in my last article.So to start with Silverlight in Visual Studio 2010, Open Visual Studio 2010 and choose Silverlight Template with code behind language of your choice.

Note : While selecting Silverlight Project in Visual Studio 2010, do have a look at “Multi-targeting” feature, Visual Studio 2010 supports .NET Framework 2.0,3.0,3.5 and 4.0. So by chance if you choose 4.0, Note that then it will not get open in Visual Studio 2008, In nutshell, If you want to play around Silverlight in both Visual Studio’s then you need to take care while choosing the framework.

Have a look at picture below :

NewSLPrj

This is new feature in Visual Studio 2010, Now you can “Multi-Target” your Silverlight application by choosing respective Silverlight Version.

Once you open your project with the corresponding version of Silverlight :

NewLook

On left you will find Silverlight Controls. Note that additional controls like Charting tools etc. you still need to download from CodePlex, I am not sure right now about the compatibility of them with Visual Studio 2010, but soon I am giving try for the same. On right you will find the normal design and code layout which is as-is from Visual Studio 2008.

DragDrop

I know, though I can’t see your faces, but I am sure you must be happy to know this that now Drag drop is possible !! :) So now you can do most of the common layout structure here only, Once you drag drop particular control, corresponding XAML code gets generated.

Another good thing is that,let’s say you drag drop a button, now in Visual Studio 2010, if you double-click on it in design window, it will automatically throw you to code behind with respective event of it like this :

CodeBehind

Note : This does not mean that you should stop using Blend, This feature is to provide flexibility to do the normal design which developers generally do to start with placing controls. Blend is more towards hardcore designers to build layouts, whatever it is, still both are tightly integrated.

At the end : One major thing I found missing is : Reduce XAP size option.

In Visual Studio 2008 :

InVS08XAPCache

In Visual Studio 2010 :

InVS10XAPCache

In end, Overall Visual Studio 2010 looks very promising for development of Silverlight applications, so it may not be useful for production purpose since its in early beta and RIA services etc are still missing, but still you can try it out for small applications.

I request you to kindly visit following URLs which already made few discussion on same topic :

http://timheuer.com/blog/archive/2009/05/20/silverlight-and-visual-studio-2010-beta.aspx

and

http://timheuer.com/blog/archive/2009/05/24/silverlight-blend-visual-studio-beta-confusion.aspx

I am soon starting few articles on Silverlight 3, the features which we have not discuss in earlier post, along with that I am planning to start .NET 4.0 in parallel to this so as to have variety flavors. So keep checking this place and once again thanks to all of you.

Vikram.

Wednesday, May 20, 2009

Visual Studio 2010 : A total “New” Experience

After TechEd 09 India, sort of new wave going on in community and forums here in India about .NET 4.0, and must be everywhere in the world. We all know how our forums on Internet are loaded with thread of Migration and Backward compatibility, But no one can help and neither can stop moving ahead, Its need rather than version !

Microsoft is now with us with their new Beta Product as “Visual Studio 2010” [Beta 1],While reading this post, I am sure most of you will be opening new Tab and asking Search engines to get result for “Visual Studio 2010 + download”, well I appreciate your enthusiasm, but it may be in vain since right now as far as I know, it is only available for MSDN subscribers, you need to check that for yourself, I came to know from “Twitter” via MSDN India tweet. So I downloaded that and now giving you my first review.

I have installed Visual Studio 2010 Beta 1 on Windows 7 Beta and I already have Visual Studio 2008 and SQL Server 2008 on my machine, Overall experience is smooth with one single restart required. I don’t know about Windows 7 RC and other OS, I think should not be an issue. So here we go…

splash

Let me tell you about the Visual Studio 2010 IDE, Its “WPF” based !, might shock you but this is reality ! ( Great job by both VS and WPF team ), so overall exprience is simply mind blowing and especially it become more rich with that typical “Blue” color of Microsoft all over.

home

This is the default Start Page you will get for Visual Studio 2010 Beta 1, This initial screen is then got divided into three core sections as “Welcome”,”Projects” and “Visual Studio”.

Welcome

Project  Here in “Project” section, you can find list of old/previously opened projects with a “Pin” symbol to pin that to the list and “X” to remove from list. When you click on New Project you will get the New Project window, which I will discuss here after below Visual Studio section snap.

Visual Studio

Once you click on Projects –> New Projects, you will get following New Project Template, more or less similar that we use to have in older version of Visual Studio.

NewProject If you observe carefully, In the Target Framework dropdown, now you have total 4 Frameworks to target as .NET 2.0,3.0,3.5 and new one 4.0 (In Common Man’s language “Your Visual Studio 2005 Projects can run in Visual Studio 2010”), Beside this on right hand side, you will find a small section where short information about each Project template is shown once you select a particular,like this :

prjmetadata I tried out using a New ASP.NET website ( I still love ASP.NET despite of my ongoing Silverlight work), Most amazing feature I found is “Snippets while doing HTML”, you just type “sm + Tab” and you will get <asp:ScriptManager> , well this is not only for script manager,but now you will find such snippets for all common controls like dropdownlist,Image,Hyperlink etc and even for Validation Controls. (Don’t worry, I am going to cover these in great details on my upcoming ASP.NET 4.0 posts), Coding in Visual Studio 2010 is fun and productive in terms of time saving. You now have something as “View Call Hierarchy” where you can find all calls made to that particular function/method all over project, you just need to right click on it and choose “View Call Hierarchy” functionality. I have done for Hello() in following example you can see as snap :

callhire

“Call To” and “Call From” above is very self explanatory. Beside this there are lot more improvements in search with Quick Search and Quick Replace, So hold your breath for more..I hope this must have made some rich picture of Visual Studio 2010 in your mind, keep that as it is, I will be soon covering new stunning features along with examples on each. So, In coming days you will find more stuff about .NET 4.0, ASP.NET 4.0, Visual Studio 2010 and much more along with Silverlight 3.

So don’t wait and waste your time, Grab a copy of Visual Studio 2010 Beta 1 today and start exploring it !!

Vikram.

Monday, May 18, 2009

TechEd 09 India : Something for every one…

You must be thinking why no new buzz here from last week or so, simple reason, I was at TechEd 09 India in City of Hyderabad [ City in India, Capital of Andhra Pradesh state and world famous for Microsoft IDC, Biryani and Pearl jewelry.] City is beautiful and have various flavors, people here are very helpful and co-operative.

It was major event atleast for me since my Visa request got cancelled this year [for no good reason :P] , so I was bit upset that time since I missed MVP Global Summit this year.I was under impression that I will never able to attend any big Microsoft event under my MVP period,but right then they made announcement for TechEd 09 in India which was happening after a gap of few years.I made my mind,come what may, I must attend this one.

Event started taking shape on various social network sites like FaceBook,Orkut,LinkedIn and recent craze of Twitter. Everyone putting their own idea to make this happen and most amazing way. Community being integral part of such events, was there from first moment. Unconference at TechEd 09 India was made successful by all over India Community leaders.

I arrived in Hyderabad on 12th May, I saw Satyam office [IT nightmare] from outside which was near to my hotel. My hotel was a nice place and hardly few minutes away from Venue. I saw Katrina Kaif that day along pool side of the hotel.After spending lot of time day before event, we came back to hotel.

On 13th May 2009, All entry points were loaded with heavy security, I made check in with my laptop and just entered the lobby, after taking 5 steps hardly, I saw Microsoft CEO Steve Ballmer right in front of me walking with his team.After Jazz music of Agni, Steve B took charge of everything.

P1000497

P1000512

Steve Ballmer is simply amazing person, once he started talking at keynote, I felt like I am charged with something, I wonder any of the Indian IT big personal could have same impact on people, most of them are in magazine stories, but Steve B is really Iron Man I can say.

After that, I went on attending sessions for next 2 days for ASP.NET 4.0, Silverlight 3, Windows 7 Labs etc. I am most lucky I can say since I was able to attend Stephan Walther’s session.

P1000513

Well, Technical sessions and HOLs are part of TechEd but beside that there was lot of fun we had with XBOX consoles, Kingfisher ForceIndia Sports car, Microsoft SAM Robot, Microsoft Surface and much more :

P1000517

P1000523

P1000543

P1000540 P1000588 SLCoreCLR

P1000576

Tim Sneath absence was a big loss for people like me who were almost could do anything to listen him talking on Silverlight and other stuff. but still we had fun with all sessions.

Last day was full with quizzes and takeaways, I won few Intel and INETA Caps with some Microsoft goodies and kingfisher goodies, Bag was about to blow out with those on last day ;), I interacted with many MVPs across Asia and US , Also It given me a great chance to interact with all members of Microsoft India people. Hats off to Microsoft India and Team of Organizers of this wonderful event.There is lot more to write since I experience tons of things..Thanks to Abhishek Baxi, Abhishek Kant, Pradipta Sharma, Sanjay Shetty and rest of the team who made this event “happening”..

Usually I come home from such events with loads of Technical stuff for me, but this time I am really a “Rich” person since I got those lovely new friends at TechEd 09 , God bless Microsoft !! :)

P1000589   

Well, people..make note of this picture..I am coming with fast speed here with loads of new things on .NET 4.0, ASP.NET and Silverlight, so keep looking here..Vrrrooooommmm !!! :)

Vikram.

Wednesday, May 6, 2009

Silverlight 3 : Insert & Update Data using WCF Service with DataForm and DataGrid

In my Lap around Silverlight 3 series, I have written a separate article on DataForm in Silverlight 3, This article is a basic extension to that and I am soon pushing it par with DataPager and other few things in coming days.

Now, I am discussing a simple or rather the simplest way to push new data and update existing data. Offcourse selection of data is there by default, so delete operation I left for my blog readers. In a nutshell you can treat this as CRUD demo with DataPager. For this you need 3 Major things

  • DataForm
  • DataGrid
  • WCF Service

I will start with WCF service first.Kindly note that you need to have respective SQL database as backend. I believe “DataContract” of this will be self-explanatory, so I am not giving details of SQL schema, Also I have not much given stress on Validations and authetications since I cover that in last article and priority of this is to show basic CRUD operations.

WCF Service Code :

[ServiceContract]
   public interface IService
   {
       [OperationContract]
       bool InsertEmployee(Employee emp);
       [OperationContract]
       bool UpdateEmployee(Employee emp);
       [OperationContract]
       Employee[] GetAllEmployees();
   }

[DataContract]
   public class Employee
   {
       [DataMember]
       public int EmpNo { get; set; }
       [DataMember]
       public string EmpName { get; set; }
       [DataMember]
       public int DeptNo { get; set; }
       [DataMember]
       public int Salary { get; set; }
   }

Under Service.svc.cs you need to write following code :

public class Service : IService
   {

       SqlConnection Conn;
       SqlCommand Cmd;

       #region IService Members

       public bool UpdateEmployee(Employee emp)
       {
           bool Updated = false;
           Conn = new SqlConnection("Data Source=.;Initial Catalog=Company;Integrated Security=SSPI");
           Cmd = new SqlCommand();
           Conn.Open();
           Cmd.Connection = Conn;
           Cmd.CommandText = "Update Employee Set EmpName=@EmpName,DeptNo=@DeptNo,Salary=@Salary where EmpNo=@EmpNo";

           Cmd.Parameters.AddWithValue("@EmpNo",emp.EmpNo);
           Cmd.Parameters.AddWithValue("@EmpName",emp.EmpName);
           Cmd.Parameters.AddWithValue("@DeptNo",emp.DeptNo);
           Cmd.Parameters.AddWithValue("@Salary",emp.Salary);

           int Upd = Cmd.ExecuteNonQuery();
           if (Upd > 0)
           {
               Updated = true;
           }

           Conn.Close();
           return Updated;

       }

Below will help to fetch the latest records :

       public Employee[] GetAllEmployees()
       {
           Conn = new SqlConnection("Data Source=.;Initial Catalog=Company;Integrated Security=SSPI");
           Cmd = new SqlCommand();
           Conn.Open();
           Cmd.Connection = Conn;
           Cmd.CommandText = "Select * from Employee";

           SqlDataReader Reader = Cmd.ExecuteReader();

           DataTable dtEmp = new DataTable();
           dtEmp.Load(Reader);
           int RCount =  dtEmp.Rows.Count;
           Employee[] arrEmp = new Employee[RCount];
           int i = 0;

           foreach (DataRow Dr in dtEmp.Rows)
           {
               arrEmp[i] = new Employee();
               arrEmp[i].EmpNo = Convert.ToInt32(Dr["EmpNo"]);
               arrEmp[i].EmpName = Dr["EmpName"].ToString();
               arrEmp[i].DeptNo = Convert.ToInt32(Dr["DeptNo"]);
               arrEmp[i].Salary = Convert.ToInt32(Dr["Salary"]);
               i++;
           }

           Conn.Close();

           return arrEmp;

       }

       #endregion

Below will help to Insert New records from DataForm :

       #region IService Members

       public bool InsertEmployee(Employee emp)
       {
           bool Inserted = false;
           Conn = new SqlConnection("Data Source=.;Initial Catalog=Company;Integrated Security=SSPI");
           Cmd = new SqlCommand();
           Conn.Open();
           Cmd.Connection = Conn;
           Cmd.CommandText = "Insert into  Employee Values (@EmpNo,@EmpName,@Salary,@DeptNo)";

           Cmd.Parameters.AddWithValue("@EmpNo", emp.EmpNo);
           Cmd.Parameters.AddWithValue("@EmpName", emp.EmpName);
           Cmd.Parameters.AddWithValue("@DeptNo", emp.DeptNo);
           Cmd.Parameters.AddWithValue("@Salary", emp.Salary);

           int ins = Cmd.ExecuteNonQuery();
           if (ins > 0)
           {
               Inserted = true;
           }

           Conn.Close();
           return Inserted;
       }

       #endregion
   }

Now we have our basic logic in place, So its time to go for design the UI, Before this, Let me give a URL of my fellow who is WCF Geek and he blogs at :

http://maheshsabnis.spaces.live.com/blog/

Though Mahesh blog in irregular intervals but you can buzz him if you have any queries in WCF.

Well,getting back to our demo, For design, I am putting DataForm and DataGrid Head to Head, So code will look like this :

XAML Code :

<Grid x:Name="LayoutRoot"   Width="690" Height="490" ShowGridLines="True" Background="Gainsboro">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="345"></ColumnDefinition>
            <ColumnDefinition Width="345"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <dataControls:DataForm Height="200" Grid.Column="0" x:Name="dfEmp" ItemsSource="{Binding Emp}" ItemEditEnded="dfEmp_ItemEditEnded"
                               AddingItem="dfEmp_AddingItem"
                              ></dataControls:DataForm>
        <data:DataGrid Grid.Column="1" Height="200" x:Name="dgEmp"   Width="300" ItemsSource="{Binding Emp}"></data:DataGrid>
    </Grid>

C# Code :

Some global level declarations :

MyRef.ServiceClient Proxy;

private ObservableCollection<MyRef.Employee> _Emp;

bool IsNewInsertFlag = false;

public ObservableCollection<MyRef.Employee> Emp
{
        get { return _Emp; }
        set { _Emp = value; }
}

Initial Binding of Data :

public MainPage_DataForm_DataGrid()
       {
           InitializeComponent();
           Proxy = new SILV3_DataBoundControls.MyRef.ServiceClient();
       }

       private void UserControl_Loaded(object sender, RoutedEventArgs e)
       {
           Proxy.GetAllEmployeesCompleted += new EventHandler<SILV3_DataBoundControls.MyRef.GetAllEmployeesCompletedEventArgs>(Proxy_GetAllEmployeesCompleted);
           Proxy.GetAllEmployeesAsync();         
       }

Actual Operations :

void Proxy_GetAllEmployeesCompleted(object sender, SILV3_DataBoundControls.MyRef.GetAllEmployeesCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                Emp = e.Result;
            }
            this.DataContext = this;          
        }

I was actually looking for some specific event to each CRUD operation, but finally I landed up with ItemEditEnded (Feedback most welcome if there any better way to do it here), So I did both operations in one event by using flag IsNewInsertFlag.

        private void dfEmp_ItemEditEnded(object sender, DataFormItemEditEndedEventArgs e)
        {
            if (IsNewInsertFlag)
            {
                Proxy.InsertEmployeeCompleted += new EventHandler<SILV3_DataBoundControls.MyRef.InsertEmployeeCompletedEventArgs>(Proxy_InsertEmployeeCompleted);
                Proxy.InsertEmployeeAsync((MyRef.Employee)dfEmp.CurrentItem);
            }
            else
            {
                Proxy.UpdateEmployeeCompleted += new EventHandler<MyRef.UpdateEmployeeCompletedEventArgs>(obj_UpdateEmployeeCompleted);
                Proxy.UpdateEmployeeAsync((MyRef.Employee)dfEmp.CurrentItem);
            }
        }

        void Proxy_InsertEmployeeCompleted(object sender, SILV3_DataBoundControls.MyRef.InsertEmployeeCompletedEventArgs e)
        {
            bool Res = e.Result;
        }

        void obj_UpdateEmployeeCompleted(object sender, MyRef.UpdateEmployeeCompletedEventArgs e)
        {
            bool Res = e.Result;
        }

        private void dfEmp_AddingItem(object sender, CancelEventArgs e)
        {
            IsNewInsertFlag = true;
        }

And you are done with it..Many of you might be wondering about few service calls, Let me explain, Thought we are using ObservableCollection it will surely update in Grid whatever we enter in DataForm, but since we need to push all updates to Database we are doing this service calls, I personally don’t think of any overhead here,if you feel please let me know.

So output will be look like this :

New

Screen1

I hope this will give you better idea and help you to implement in your POCs/Projects etc., do let me know your feedback.

Vikram.

Saturday, May 2, 2009

TechEd 2009 India : Join India’s Biggest Technical Event by Microsoft

Just look at this image below..do I need to say anymore?

SteveB

Yes !! Microsoft CEO Steve Ballmer is Keynote Speaker for TechEd 2009 India which is Biggest Technical event by Microsoft starting from 13 May to 15th May in Hyderabad,India.

So, you think that this keynote is only attraction of event?? then you are totally wrong..why I am saying so? look below :

TimSneath

[Tim also written an excellent article on Silverlight CoreCLR after Mix 09]  

Steven

[He wrote one of the greatest book on ASP.NET on earth till the day, yes ASP.NET Unleashed]

Beside this loads of Sessions for Developers,Designers,Architects,Managers and CXOs by Top Technical Leaders in India and outside India. Many sessions on Silverlight 3, .NET 4.0, Azure, SQL Server, Windows 7 and many more..

Adding more spice to it, Microsoft giving following which I equally find useful for attendees :

MScertifree

win7

So, what MVPs like me going to do there beside attending sessions?? ..Well, Its going to be loads of stuff for Developers and other Attendees, There will be some side sessions by MVPs, some Blogging and Live Tweeting will be there along with some informative sessions for Community too, This all you can enjoy here :

unconf.png

[So, If you are looking ahead for some Silverlight discussion with me, you can find me here from 13-15 May throughout the day, and I would love to interact with you.]

Well, this was small lap around about TechEd 2009 India by me, so I know you must have several questions in mind, so here I go :

Q) I would like to visit Official Homepage of TechEd 09 India

Ans : www.msteched.in

Q) Why I should attend such events like TechEd 09 India ??

Ans : http://blogs.msdn.com/msdnindia/archive/2009/05/01/ongoing-recession-and-why-you-should-attend-teched-india.aspx

Q) I am looking ahead for Sessions, I would like to know what sessions are there for me and my friends or my organization

Ans :http://www.microsoft.com/india/teched2009/tracks.aspx and Daily breakup at : http://www.microsoft.com/india/teched2009/agenda.aspx

Q) I was just going through this Blog post and saw About “Free Certifications”, can you give more information?

Ans : http://www.microsoft.com/india/teched2009/freecertification.aspx

Q) I heard from my friends who attended various events in US, they told me about “Technology Tents” are they going to be here?

Ans : Yes !! here : http://www.microsoft.com/india/teched2009/technologytents.aspx

Q) How to Register ? and where I can find more information ?

Ans : http://www.microsoft.com/india/teched2009/register.aspx

Q) I am very new to Hyderabad / I am first time visiting Hyderabad, can I know some Travel/Accommodations details ??

Ans : Welcome to India for those who are first time visitors here, For those who are from India as well as from outside India, you can find more information here :

TechEd 2009  Venue :

http://www.microsoft.com/india/teched2009/Venue.aspx

Travel Directions to the Venue from Airport :

http://www.microsoft.com/india/teched2009/Getting_there.aspx

Accommodations :

http://www.microsoft.com/india/teched2009/Accommodation.aspx

Q) Are there any Social Medias covering this event??

Ans : Yes, here you go !! :)

FaceBook : http://www.facebook.com/group.php?gid=62844697987

Twitter : http://twitter.com/techedindia2009

and many more you can find on Homepage of TechEd 09 India.

I hope this will be informative for you, so without thinking much,Register right now and just go ahead and drop e-mail to your Boss with Subject line “Will be Out of Office from 13-15 May 2009” ;-) , Also do share this information in your community and friends, So see you there !! :)

[Note : All Images and URLs are taken from www.msteched.in for blogging purpose only, they carry their respective copyrights]

Vikram.