22 November 2011

Creating Crystal Report in ASP.NET


The entire solution (source code) for this article is available as a free download (in the form of a zip). The source code in this article has been developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Vista Ultimate Edition with Microsoft SQL Server 2005 Express Edition. I used the same version of Crystal Reports which comes with Visual Studio 2005 Professional Edition. I didn't really test any of the code in any other tools/IDEs/servers/editions/versions. If you have any problems, please feel free to post in the discussion area.
I contributed two articles focusing on the capabilities of ASP.NET 2.0's built-in reporting. If you are new to the built-in reporting (also called local reporting), you can find the articles here:
Starting an ASP.NET 2.0 Web Site Project
The following are the steps necessary to create a new ASP.NET 2.0 web site:
  • Open Microsoft Visual Studio 2005 Professional Edition
  • Open File || New || Web Site
  • Select "ASP.NET Web Site" in templates, select "File System" as the location, provide the website name "SampleWebSite01"  and finally click on OK.
  • Right click on "SampleWebSite01" available in Solution Explorer and select "Add New Item."
The next section walks you through adding a Crystal report to the project.

Adding a Crystal Report to the Project

In the previous section, a new ASP.NET web site was created. In this section, we shall walk through the creation of a Crystal report. The following are the steps you need to take; they pick up from where we left off in the previous section:
In the "Add New Item" dialog box, select "Crystal Report" as the template, provide the name "SampleRpt01.rpt" and click on the "Add" button.
You should see "SampleRpt01.rpt" added to the "Solution Explorer" and the "Crystal Reports Gallery" dialog will be shown (Fig 05). Select "Standard" in "Choose an Expert" and click OK (Fig 05).
Next, you will be taken to provide details for the Data Source. In the "Available Data Sources," open "Create New Connection" and open "OLE DB (ADO)." It brings up another dialog box to let you select the OLEDB Provider. Select "Microsoft OLEDB Provider for SQL Server" in the list of Providers and click on "Next" as shown below.
Provide the db connection information to connect to the Northwind database and click on "Finish."
A new connection gets added to the "OLEDB (ADO)" group. Open the added connection and further drill down to Northwind || dbo || Tables, add the "Orders" table to the "Selected Tables" list (by selecting it and clicking on the greater than arrow), and click on "Next" as shown below.
In the next screen of the wizard, you will be provided with all the fields (or columns) to include in the report. Add OrderID, CustomerID, EmployeeID and OrderDate to the "Fields to Display" section by double clicking each of those fields in the "Available Fields" list and click on "Finish" as shown below.

Crystal Report Components

In the previous section, we added a new Crystal Report to the web site. Once the report gets added, you should be able to see the Visual Studio layout with "Field Explorer," the new "Crystal Reports" menu and an "Embedded Crystal Report Designer" with two modes ("Main Report" and "Main Report Preview" at the bottom) as shown below.
The "Field Explorer" can be used to drag and drop the columns onto the report, add new, add new tables to the report, add new formula oriented columns, running totals, and so on.
The report designer is initially divided into five sections (Report Header, Report Footer, Page Header, Page Footer and Details). Report Header gets displayed only on the first page. Report Footer gets displayed only on the last page. Page Header gets displayed on top of every page. Page Footer gets displayed at the bottom of every page. The Detail section is the body of the report where all of the rows get displayed.
Using the formatting toolbar, properties windows and tools in toolbox, we can format the report in the required manner. Try playing with formatting the report (and preview it simultaneously without executing the project).
Displaying Crystal Report on the ASP.NET 2.0 web page
To display the report on the web page, we need to work with Crystal Report Viewer control. The following are the steps required to attach the Crystal Report to the ASP.NET 2.0 web page:
Using the ToolBox, drag and drop the CrystalReportViewer control.
Using the Smart tag of the CrystalReportViewer control, select "New Report Source."
This leads you to a new dialog box, "Crystal Report Source." Every CrystalReportViewer gets associated with the CrystalReportSource control. You can directly drag and drop the CrystalReportSource control from the toolbox as well and assign the same in a smart tag. Provide the details and click OK.
The moment you hit OK, you should be previewing the report. Just hit F5 to execute your web site. Once the web page gets displayed, provide logon information for the report and click on "Logon."

Providing Login information for the CrystalReportViewer control dynamically

The CrystalReportViewer control needs to be provided with database logon information to execute and show the report. At the same time, it is a bit awkward to have the database login page displayed for every Crystal Report. No end user likes it (and of course, it is dangerous too!).
To solve this problem, we can provide database logon information to the CrystalReportViewer control dynamically at runtime. The following is the code to achieve the same:
Imports CrystalDecisions.Shared

Partial Class _Default
  Inherits System.Web.UI.Page

  Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
    Dim ConnInfo As New ConnectionInfo
    With ConnInfo
      .ServerName = ".sqlexpress"
      .DatabaseName = "Northwind"
      .UserID = "sa"
      .Password = "eXpress2005"
    End With

    For Each cnInfo As TableLogOnInfo In Me.CrystalReportViewer1.LogOnInfo
cnInfo.ConnectionInfo = ConnInfo
    Next
  End Sub

End Class
You must observe that the CrystalDecisions.Shared namespace is added to the top. In the above code, the database connection information is stored in ConnInfo and is defined as follows:
Dim ConnInfo As New ConnectionInfo
With ConnInfo
  .ServerName = ".sqlexpress"
  .DatabaseName = "Northwind"
  .UserID = "sa"
  .Password = "eXpress2005"
End With
The above connection information is assigned to CrystalReportViewer control using the following code:
For Each cnInfo As TableLogOnInfo In Me.CrystalReportViewer1.LogOnInfo
  cnInfo.ConnectionInfo = ConnInfo
Next

Hiding the toolbar and adding First, Last, Next and Previous page buttons to the report

By default, CrystalReportViewer automatically displays toolbar at the top. Not every end user uses all features. At the same time, some end users may not like the toolbar.
To hide the toolbar, modify the CrystalReportViewer code (in Source mode) as follows:
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True"ReuseParameterValuesOnRefresh="True" DisplayToolbar="False" EnableDatabaseLogonPrompt="False"EnableParameterPrompt="False" DisplayGroupTree="False"
Height="1064px" ReportSourceID="CrystalReportSource1" Width="928px" />
Add First, Last, Next and Previous page buttons to the web page and modify the code behind with new events as follows:
Protected Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirst.Click
  Me.CrystalReportViewer1.ShowFirstPage()
End Sub

Protected Sub btnLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLast.Click
  Me.CrystalReportViewer1.ShowLastPage()
End Sub

Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
  Me.CrystalReportViewer1.ShowNextPage()
End Sub

Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
  Me.CrystalReportViewer1.ShowPreviousPage()
End Sub

Enhancing the report with run-time binding along with session handling

In all of the above sections, the CrystalReportViewer worked with CrystalReportSource. Now, let us dynamically add a report source to the CrystalReportViewer and bind it at runtime. This gives us the flexibility to use the same viewer for different reports (showing one at a time).
Add a new web page to the project, add the four buttons (First, Previous, Next and Last) and a CrystalReportViewer control. Modify the CrystalReportViewer control, so that it looks like the following:
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True"ReuseParameterValuesOnRefresh="True" DisplayToolbar="False" EnableDatabaseLogonPrompt="False"EnableParameterPrompt="False" DisplayGroupTree="False"
Height="1064px" Width="928px" />
In the code-behind, add the following at the top:
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Add a new method as follows:
Private Sub BindReport()

  If Session("Rep") Is Nothing Then
    Dim ConnInfo As New ConnectionInfo
    With ConnInfo
      .ServerName = ".sqlexpress"
      .DatabaseName = "Northwind"
      .UserID = "sa"
      .Password = "eXpress2005"
    End With

    Dim rep As New ReportDocument
    rep.Load(Server.MapPath("SampleRpt01.rpt"))
    Me.CrystalReportViewer1.ReportSource = rep
    Dim RepTbls As Tables = rep.Database.Tables
    For Each RepTbl As Table In RepTbls
      Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo
      RepTblLogonInfo.ConnectionInfo = ConnInfo
      RepTbl.ApplyLogOnInfo(RepTblLogonInfo)
    Next
    Session("Rep") = rep
  End If

  Me.CrystalReportViewer1.ReportSource = Session("Rep")
  Me.CrystalReportViewer1.DataBind()
End Sub
Add the following code to bind the report for every button click and also during the page load event:
Protected Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirst.Click
  BindReport()
  Me.CrystalReportViewer1.ShowFirstPage()
End Sub

Protected Sub btnLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLast.Click
  BindReport()
  Me.CrystalReportViewer1.ShowLastPage()
End Sub

Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
  BindReport()
  Me.CrystalReportViewer1.ShowNextPage()
End Sub

Protected Sub btnPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrev.Click
  BindReport()
  Me.CrystalReportViewer1.ShowPreviousPage()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If Not IsPostBack Then
    BindReport()
  End If
End Sub
I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated athttp://jagchat.spaces.live.com

Creating a Simple Image Slide Show Using ASP.NET Client Callbacks


In this post I will explain how to make a very simple image slide show using ASP.NET Client Callbacks. The pictures are stored in the Pictures folder which reside in the web application project. The first step when using the ASP.NET is to register the callbacks. Take a look at the code below which registers the callbacks to the ASP.NET page.
private void RegisterCallbacks()
{
string callbackRef = ClientScript.GetCallbackEventReference(this"arg""recieveServerData""context");
string script = String.Empty;
if (!ClientScript.IsClientScriptBlockRegistered("callServer"))
{
script = "function callServer(arg,context) { " + callbackRef + "}";
ClientScript.RegisterClientScriptBlock(this.GetType(), "callServer", script, true);
}
}
You must also implement the ICallbackEventHandler interface for your page.
public partial class _Default : System.Web.UI.PageICallbackEventHandler
And implement the GetCallbackResult() and RaiseCallbackEvent methods.
public string GetCallbackResult()
{
return SlideShowHelper.GetImage(index);
}
public void RaiseCallbackEvent(string eventArgument)
{
index = Int32.Parse(eventArgument);
}
index is a class level private variable.
private int index = -1;

The SlideShowHelper class is responsible for getting the correct image for the slide show or when the user presses the "Next" or "Previous" buttons.
public static string IMAGES_FOLDER = @"Pictures/";
public static string GetImage(int index)
{
// You can cache the
string[] files =Directory.GetFiles(HttpContext.Current.Server.MapPath(SiteConfiguration.GetImagesFolderPath()));
if (index > files.Length)
return "DEC";
if (index < 0)
return "INC";
return CreateImageTags(IMAGES_FOLDER,System.IO.Path.GetFileName(files[index]));
}
The important thing to remember is that the IMAGES_FOLDER path should contain a backward slash and not the forward slash. If you use forward slash it will not work for the FireFox browser.
The CreateImageTags is used to create the image tags which can then be assigned to the DIV element.
private static string CreateImageTags(string folderName,string fileName)
{
return "<img width=\"300px\" height=\"300px\" src=\"" + folderName + fileName + "\"/>";
}

Now, let's take a look at the UI (Default.aspx) code.
<div id="display">
</div>
<input type="button" value="Previous" onclick="loadPreviousImage()" />
<input type="button" value="Stop" onclick="stopSlideShow()" />
<input type="button" value="Play" onclick="startSlideShow()" />
<input type="button" value="Next" onclick="loadNextImage()" />
And finally the Javascript functions:
<script language="javascript" type="text/javascript">
var index = -1;
var timerId = null;
function stopSlideShow()
{
window.clearInterval(timerId);
}
function startSlideShow()
{
timerId = window.setInterval(loadNextImage,2000);
}
function loadPreviousImage()
{
index--;
callServer(index,'');
}
function loadNextImage()
{
index++;
callServer(index,'');
}
function recieveServerData(response)
{
if(response == "DEC")
index--;
if(response == "INC")
index++;
if(response != "DEC" && response != "INC")
{
document.getElementById("display").innerHTML = response;
}
}

Here is the effect show below:

powered by ; http://aspadvice.com

18 November 2011

How to Configure Cisco IOS VLANs

Apa itu BSC (Base Station Controller) & BTS (Base Transceiver Station)?


Apa itu BSC (Base Station Controller) & BTS (Base Transceiver Station)?


beberapa waktu lalu ada yang tanya ke penulis:
mksd aku, kalo HLR kan biasany berupa server fujitsu / sun dgn OS solaris. Nah kalo BSC itu sama juga nga? Oiya, letak router2nya biasany dimana ya? Saya jd mengawang2 nga jelas tentang arsitektur seluler nih :)
Dari namanya (Base Station Controller), BSC adalah peralatan untuk mengontol BTS (Base Transceiver Station). BSC itu seperti otak/commander dari BTS-BTS, tanpa BSC, BTS-BTS itu seperti orang o’on, ngak bisa ngapa2in.
BSC diletakkan dimana?
tidak seperti BTS yang letaknya outdoor, BSC letaknya indoor. biasanya satu gedung dengan peralatan core network lainnya.
BSC bisa handle berapa BTS?
tergantung modelnya, sebuah BSC dapat mengandle sampai ratusan BTS.
Berarti BSC barang penting dong?
ya eyalah… penting. bayangin aja kalo 1 BSC down, ratusan BTS jadi pada begong semua dong? pelanggan ngak bisa kirim SMS/nelpon/unreachable, dan bakal mencak2 ke customer service (CS). heheheh :-p (eh ngak bisa mencak2 ke CS ding, kan ngak dapet sinyal? :-p)
Apa saja yang di kontrol oleh BSC?
Beberapa fungsi penting yang dihandle BSC:
  • Handover (ini penting banget, kalo ngak ada ini ya bukan mobile communication namanya)
  • Timeslot dari BSC ke BTS & BSC ke TRAU (ini apa lagi, penting bgt)
  • Radio channel allocation (ini juga penting)
  • Measurements ini buat ngukur quality dari sebuah call process (ini penting)
Seperti apa hardware BSC?
BSC adalah komponen critical, sehingga komponen2nya adalah redundant: redundant power supply, modules, cables, dll. sayangnya BSC adalah barang propietary, jadi ngak dijual bebas di mall atau supermarket. jugatidak menggunakan komponen seperti PC biasa yang bisa dirakit seenaknya. juga tidak menggunakan server dari sun/fujitsu atau vendor IT lainnya. kalo mau liat BSC, ya datang ke vendornya atau operator telco. contoh barangnya seperti dibawah ini:
http://www.motorola.com/Business/XC-EN/Business+Product+and+Services/Cellular+Networks/GSM+RAN/Motorola+BSC2_Loc_XU-EN_XC-EN_XM-EN_XE-EN_XN-EN_PK-EN_XF-EN  .
BSC kliatannya rumit deh, bagaimana belajarnya?
Karena barangnya mahal, dan jarang dipasaran, maka orang2 yang ngerti ini pun tidak banyak. biasanya diperlukan training khusus untuk menguoperasikan hardware tsb. namun sebelumnya engineer yang bersangkutan juga harus belajar konsep GSM beserta operationnya yang sifatnya non-hardware.
Bagaimana untuk monitoring BSC?
Dalam organisasi telco ada department yang khusus untuk melakukan monitoring terhadap Network element (MSC, HLR, BSC, dll). jadi monitoringnya terpusat. BSC ini biasanya punya interface khusus untuk monitoring sehingga monitoring devices dapat mengakses parameter apa saja yang ada disana.
Ohya, kalo BTS itu apa? yang tower itu yah?
BTS adalah equipment paling luar yang berhubungan langsung dengan mobile station (handphone/mobilephone). jadi BTS inilah yang menyediakan wireless access ke mobile station kamu. BTS itu bukan tower. BTS itu terdiri dari beberapa komponen dan tower tidak termasuk komponen tersebut.
Kalo bukan tower, BTSnya yang mana dong?
kalo kamu lihat tower telco, biasanya ada rumah kecil (shelter) yang berada dekatnya toh? nah didalamnya terletak komponen inti BTS tsb.
apa saja komponen BTS?
beberapa komponennya adalah:
  • Transceiver/Receiver. buat nerima/kirim sinyal
  • Power supply. ya iyalah… :-p
  • Combiner. supaya bisa nerima beberapa sinyal dengan menggunakan 1 antenna.
  • Duplexer. supaya bisa ngomong fullduplex.
  • Antenna. jelas dong… antenna ini yang di cantolkan ke tower.
  • Alarms
  • software things gitu deh… BTS kan bisa di flash gitu firmwarenya. kemudian fungsi ini juga menyediakan parameter untuk monitoring.
Kalo antenna, apa harus di tower?
tentu saja tidak. ada yang outdoor, ada yang indoor seperti gambar dibawah ini:

biasanya sih dipasang di langit2. jadi kalo kamu lihat ada yang nongol seperti gambar, bisa jadi itu adalah sebuah antenna BTS.
tentang router, yang jelas router diletakkan di rak. dan gunanya tentu saja untuk routing.
semoga berguna bagi yang membaca.