Working with RadNumericBox in JavaScript Windows 8 Application

In this post we will take a look on working with RadNumericBox. If first time you are working with RadControls in JavaScript based Windows 8 Application, I recommend you to read this post .

To work with RadNumericBox simply set data-win-control property of a div or span as Telerik.UI.RadNumericBox


You will get RadNumericBox configured with default values as following,

You can work with RadNumericBox from JavaScript as well.


Here agebox is id of span.

You can set different options for RadNumericBox. Some of those options are as following,

Options can be set as following,

Now when you run the application, you should get RadNumericBox configured with default value 40, minimum value 0, maximum value 255 and step as 10. While working with RadNumericBox there are two important events,

In code behind you can attach event to RadNumericBox as following,

You can work with spin event as following

And showmessage function is written as below,


For your reference code is given below,

Default.html

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8" />
 <title>javascriptAutoComplete</title>

<!-- WinJS references -->
 <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
 <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
 <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>

<!--Telerik references -->
 <script src="///Telerik.UI/js/jquery.js"></script>
 <script src="/Telerik.UI/js/ui.js"></script>
 <link href="/Telerik.UI/css/dark.css" rel="stylesheet" />
 <link href="/Telerik.UI/css/common.css" rel="stylesheet" />

<!-- javascriptAutoComplete references -->
 <link href="/css/default.css" rel="stylesheet" />
 <script src="/js/default.js"></script>
</head>
<body>
 <h1>Numeric Box Demo</h1>
 <div id="agebox"
 data-win-control="Telerik.UI.RadNumericBox"
 data-win-options="{value: 40,
 min: 0,
 max: 255,
 step: 10,
 decimals: 2,
 format: 'n0',
 }">
 </div>
 <br />
 <span id="output" >

 </span>
</body>
</html>

&nbsp;

Default.js


if (args.detail.kind === activation.ActivationKind.launch) {
 if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
 // TODO: This application has been newly launched. Initialize
 // your application here.
 } else {
 // TODO: This application has been reactivated from suspension.
 // Restore application state here.
 }
 args.setPromise(WinJS.UI.processAll());
 var nbage = document.getElementById("agebox").winControl;
 nbage.addEventListener("spin", showmessage);
 nbage.addEventListener("change", function (e) {
 document.getElementById("output").innerText = "You have selected" + nbage.value;
 });
 }
 };

 function showmessage(e) {

document.getElementById("output").innerText = "You have selected" + e.target.value;
 }

I hope you find this post useful. Thanks for reading.

Working with LINQ to SQL Class and AJAX RadGrid

In this post we will take a look on working with RadGrid and LINQ to SQL Class. We will display data in RadGrid using LINQ to SQL Class from SQL Server database.

image

Very first let us create DataSource to be used with RadGrid. We will use LINQ to SQL class to create data model here. To create data model using LINQ to SQL class right click on the project and select Add then New Item. From Data tab, choose LINQ to SQL Classes

image

If you want you can change name of the LINQ to SQL class, however I am leaving default name and clicking on the Add button. Choose Server Explorer on the design surface to create data classes.

image

In Server Explorer right click on the Data Connection and Add Connection. In Add Connection dialog box provide database server name and choose the database to create data model. Click on Ok to add a new Data Connection in Server Explorer.

image

On successfully adding of data connection , you can see that in server explorer

image

Next drag and drop Tables, Views , Stored Procedures and Functions from Server Explorer on dbml design surface to make a part of data model. In this case , I am going ahead with only one table Person. Now you can see that Person is added on dbml file.

image

As of now we have added the data model in the project. Now let us go ahead and add a RadGrid on the page. To add RadGrid on the page drag and drop it from Toolbox on the page. If you don’t find RadControls in toolbox then right click on the General tab in tool box and select Add Tab

image

Give name of the tab . Right click on newly created tab and selecte Choose Items. Then browse to

C:\Program Files (x86)\Telerik\RadControls for ASP.NET AJAX Q1 2012 SP1\Bin40

and choose Telerik.Web.UI.dll and after selecting dll click on Ok button to add the controls in toolbox.

image

In toolbox you can see that RadControls are successfully added.

image

 

Next from the Telerik AJAX Data Component tab , drag and drop RadGrid on the page.

<pre><asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True">

</telerik:RadGrid>
</asp:Content>

 

As of now we have added RadGrid on the page . Next we need to create data source from the data model and bind to the RadGrid. Below is the function returning List of Person.


private List<Person> GetStudents()
{
DataClasses1DataContext context = new DataClasses1DataContext();
return  context.Persons.ToList();
}

In function we are creating instance of DataContext class and returning list of person on that. Now we need to bind data returning from this function to RadGrid. We can do that as following


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;

namespace GridSample
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
RadGrid1.AllowPaging = true;
RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;



}

void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = GetStudents();
}




private List<Person> GetStudents()
{
DataClasses1DataContext context = new DataClasses1DataContext();
// return context.Persons.SortBy("FirstName").ToList();
return context.Persons.ToList();
}
}
}

Now when you press F5 to run the application , you should get data in RadGrid using LINQ to SQL class.

image

In this way you can pull data from database using LINQ to SQL class and bind to a RadGrid. I hope you find this post useful. Thanks for reading.

Rendering Report Designed in Standalone End User Report Designer

Overview:

In this post we will take a look at how a report designed in Standalone End User Report Designer, can be rendered from your applications – be it WPF, WinForms, SilverLight or ASP.NET. One of the customer I was working with had this requirement of end users to design the report and that report should be rendered within the application. The end users who design the report will have the flexibility to upload the designed report to the application. The application had to render the uploaded report in a reporting module. So we will see how to achieve this. If this requirement has excited you, then read through rest of this post.

Pre Requisites:

In order to design reports using the standalone end user report designer, you will need to first download the Telerik Reporting solution. This is available as a free 30 day trial download. Here is the download link:

in order to mimic the scenario of End User connecting to a staging DB and designing the report on their desktop – I will be making use of 2 Databases. So you will need a RDBMS product of your choice. In my example I will be using SQL Server 2012.

Creating Staging and Production DB:

For the sake of the demo, I will create 2 database and name them as StagingDB and ProductionDB respectively. The database will have only one table named Contacts. It will have 2 columns an Id and Name. Here is the code snippet for the table:

So at his time, if you are following along, you should have created 2 databases – StagingDB and ProductionDB and in both the DB you should have 1 table named Contacts. In staging DB contacts table I will fill some dummy data and it looks like below:

image

Similarly in the Contacts table of production DB, I have inserted the following data:

image

We will mimic a scenario where in the end users will connect to the StagingDB->Contacts table and design the report using the Standalone Report Designer. After designing it they will upload to the application. And application will connect to production DB and render the report.

Designing the report:

when you install the Telerik Reporting suite, we will also install the Standalone report designer for end users. This is an executable which can be run on any system. It can be in a folder named Report Designer at the root of Telerik Reporting installation folder. When you launch the ReportDesigner,exe, you will see the following interface:

SNAGHTML11b7d9

Click on New Report, give a name for the report and select a path to save the report.

image

Next, we will be presented with a Report Wizard. In the “Choose Data Source” dialog, create a new data source and connect to the Staging DB we have created earlier. In order to connect to our SQL Server database, select SQL Data Source in the data source selection dialog and give it a name.

SNAGHTML16b193

In the data connection selection page, configure the connection settings to your Staging DB.

SNAGHTML183745SNAGHTML19189e

Next we configure the command i.e. the select query to fetch the report data. For this demo it’s a simple statement – “Select * from Contacts”.  Next you can preview the results of the query

SNAGHTML1aa821SNAGHTML1b276d

Click on finish to finish the connection settings configuration.

Now you will see that we have set up a data source for the report and following dialog shows the details:

SNAGHTML1cebe4

Click next to select the report type. I have select a standard report typeSNAGHTML1d87e4

Next we will configure the data layout of the report, In this example, we have only two columns in the table and I will show both the column in the body of the report.

SNAGHTML1ef7b7

Next select the report layout i.e. is the report a stepped report or outline or left aligned. I have selected Stepped report i.e. items are arranges in columns and they don’t overlap vertically.

SNAGHTML20e87b

Next you can select a report style and finish the wizard.

SNAGHTML258555

At this point we have successfully designed a report using the report designer. In order to preview the report, click the Preview button on the Home tab. The report will be executed and shown as below:

SNAGHTML2706d3

As you can see we have connected to our staging db and pulling data from the contacts table.I have named the report as DemoReport and is saved as DemoReport.trdx. The TRDX is a custom file format that Telerik Reporting uses. It stands for Telerik Reporting Definition XML. Next we will see how we can upload this file to a application and render the report inside the application.

Building a WPF client:

In order to mimic a production application, I have built the following WPF app.

SNAGHTML3c5c82

Although I have selected WPF app for this demo, it can be anything in real world – ASP.NET Web App, WinForms or SL. Here is the work flow of this app:

  • An end user uploads the .TRDX report file he designed using the Standalone Report Designer, in the app.
  • The app saves the file in the application folder.
  • App will list the uploaded report file in a list box.
  • When the report is selected in the list box, the report will be rendered in the report viewer.

For the sake of the time, I will not be describing the portion of the app which allows us to browse and select a .TRDX file, Saves the uploaded .TRDX file in one of the application folder and listing of the uploaded report in list box. Those are pretty straight forward code that you will be familiar with. We will pay our attention to how do we render the .TRDX file inside the Report Viewer in the coming sections.

TRDX Report Rendering using URI:

The report viewer has the capability to just take a URI of a .TRDX file and render it. The ReportViewer exposes a property called ReportSource. One of the supported report source is UriReportSource. As the name goes, we are supposed to create an instance of UriReportSource and set the URI to the .TRDX file. Be it a WPF app as the one we are dealing with now or a web scenario – you just need to get the complete URI of the .TRDX file. Here is the code snippet to achieve this:

TRDX Report Rendering Using XML Source:

In previous section we saw UriReportSource as the report source for the report viewer. The report viewer also supports XML as a report source. We can pretty much give a XML literal string which confronts to Teelrik Reporting Definition XML schema and the report viewer will be able to parse and render the same. The .TRDX report file is nothing but a XML in itself. Here is the content of the DemoReport we designed in its XML form:

Here is the code snippet to prepare the XmlReportSource and bind that to ReportViewer ReportSource.

Wait, What about the data source?

Well, if you followed the post so far, you will probably be getting this question for sure. Well remember that when we designed the report using Standalone Report Designer we did set up a data source and a connection string. But that points to our staging database. Meaning the schema of the staging db and the production db are the same but they will be two different environments when it comes to reality. You will never allow somebody to work with a production environment for design. Instead you will allow people to play around in the staging or local setup and finally deploy the code to production. So when we rendered the report using the URI Report Source or XML Report Source – the report does contain the data source object embed within the report and will use that when executing in the production. Remember that the connection string set up during design points to our staging or local setup. So when the report is rendered in the production, report viewer will search for the connection string name given during the design. It may be there or may not be there – whatever it is, this is not ideal scenario to support. So how can we overcome this. In the next section, we will see what is the solution for this.

Report Xml Serializer:

when we looked at XmlReportSource, we understood the .TRDX file is nothing but a XML content. It is nothing but the report definition. The Telerik Reporting solution comes with a ready made XmlSerializer which can read this XML definition and gives us an instance of Telerik.Reporting.Report – an object representation of the Report we designed. The Report class exposes the Data Source we set up and the Connection String on that data source. So the solution to render a .TRDX file in production environment will be as follows:

  • Read the content of the .TRDX file as XML string
  • Use ReportXmlSerializer to serialize the XML to Report object
  • On the report object, get the SqlDataSource and change the connection string of the data source to match your production. You can either provide the complete connection string itself or the name of the connection string element from your configuration file.

Here is the code snippet on how to use the Report Xml Serializer:

Summary:

Standalone Report Designer is a great tool for end users who just create reports and are not technical people. Telerik Reporting Solution has provisions to use the designed report i.e. .TRDX file and render that inside the report viewer. Since it supports both URI Report Source and XML Report Source, you can decide the way you want to store the report i.e. either store it as a physical file in your app in a separate folder or store the content of the .TRDX file in a database column. In both the cases you will be able to use the Report XML Serializer to serialize the XML as a Report instance, update the connection  string to match your production and set it to the report viewer.

With Telerik Reporting Solution, you now have the power in your apps to let the end user design adhoc reports, upload it in your app and render the same in a report viewer. Hope this post gave you some insights into Telerik Reporting capabilities.

Till next time – Happy Coding!

Using RadControls in JavaScript based Windows 8 Application

In this post we will set up project to use RadControls for Windows 8 in JavaScript based Application. Before you go ahead with this post, read here

Getting Started with Rad Controls for Windows 8

Once you have done with downloading and installing Rad Control for Windows 8, create a new JavaScript based Windows Store project

image

Right click on the reference in solution explorer and add a new reference. Choose Windows Library for JavaScript and add to the project.

image

After adding references, verify in solution explorer that you have successfully added the references

image

Once references are successfully added in the project, you need to add references of Rad Control JS files and CSS files on the HTML page. You can refer them as following listing,

image

Now you are all set to use RadControls for Windows 8 in your application. To test that whether we have added all the references correctly or not ,let us put a RadSlider control on HTML

image

Now when you run the application you should get a RadSlider control on the page successfully.

image

In this way you can get it started with Rad Controls for Windows 8 in JavaScript based application for Windows Store. I hope you find this post useful. Thanks for reading.

Nokia Lumia loves Telerik

In a recent gathering of many tech enthusiasts on mobile devices, the discussion steered towards Nokia (how could it not?). People tended to like the new Lumia phones due to its colourful interface, wireless charging and deep social networking integration. The next question was on how to develop mobile apps for these devices?  Nokia has come up with new new programs that enable developers to make the most of the new devices coming out of Nokia. They are:

  1. Nokia Ad Exchange
  2. Nokia Premium Developer Program

The Nokia Ad Exchange (NAX) is a simple way of generating revenue from the in app advertising (banners, full-screen ads, text etc). From one of the my Nokia developer friends, this is the most lucrative way of generating the revenue for mobile developers. The NAX is not a single network but aggregates over 120 advertising networks worldwide with options to choose the type of ads that you want to receive in your app. You will also be able to monitor the stats (e.g. CTR, impressions) for your app. The best of it all is that the same NAX can be used on various platforms (i.e. including Series 40 and Symbian, iOS, Android and Blackberry).

I say that every Nokia Lumia developer needs to be on the Nokia Premium Developer Program. The subscription will set you back by USD 99 or approx INR 5200. As we will see, the value far outweighs the cost of this program. This program is focused on providing the Nokia developers the tools to make their app stand out in the marketplace. So, what are the tools included in the toolkit that are going to make your app pop?

  1. Yearly subscription to Microsoft Developer Center. This $99 subscription is quintessential in case you want to put up your application in the Windows Phone marketplace (duh!). This falls in the category of MUST Have.
  2. Telerik RadControls for Windows Phone. The real win for you is in the user experience of your application. RadControls gives you wonderful user experience widgets that will make your app standout in the crowded marketplace. Not only are RadControls good for user experience but also they give you the enhanced capabilities with least amount of code. Extensive learning resources are available that would get you to a flying start.
    And in case you get stuck at anything, Telerik support staff would answer it within 24 hrs. Raise a support ticket if you face any issue (via your telerik.com account).
  3. 12 months subscription to Buddy Cloud APIs. If you want to integrate functionalities like global user accounts, photo albums, messaging, friends/groups functionality, push notifications Buddy cloud quickly gets you started with it. Developers are advised to watch for the no. of API calls that they make. Over 1,000,000 calls/ month will be charged.
  4. 2 Nokia support tickets. For those difficult days when things are not going quite right

telerikLogo-web-450x180pxIf you are a Nokia Developer, you can now make truly world class application with the resources available to you. In addition, if you are in India and have an issue getting started with the Telerik RadControls for Nokia Lumia, you can call us on +91-124-4300987 and speak to Dhananjay on ext 201. He already has a video ready for you on this.

In the meantime, I am off to hunt for a Lumia 920 in India.

Working with Github and Icenium

Cloud based IDE Icenium allows you to develop cross platform mobile applications. When you create a project in Icenium IDE , it saves that project in cloud and allow you to do version control. Aprat from cloud integration , Icenium allows you to push and pull your project with Github Repositiry as well.

image

To integrate project from Icenium to Github repository, first create a repository in guthib. You can create that on Github site by clicking on New Repository link button

image

To create new repository, you need to provide following information. I am symbolically providing information here to create a new repository.

image


Once repository got created, you will get a URL to work with that repository.

image

As of now you have created a repository in Github. Now let us switch to Icenium IDE. Right click on the project then select Version Control. In Version Control select the option of Configure Remote Repository

image

Next you need to provide URL of Github repository.

image

Next again right click on the project and from Version Control select the option of Pull

image

You will see that you have pulled the repository.

image  

Now to push the project to github repository right click on project and select version control then Push option

image

When you start pushing you need to authorize yourself to the repository.

image

On successful completion of the push, you will get a message at bottom of IDE as following    

image


So in this way you can integrate project from Icenium to Github repository.  I hope this post was useful. Thanks for reading.