Thursday, February 25, 2010

Crystal Report with ASP.net

There are many approaches you can take to link crystal report with asp.net . In this article I’m going to discuss some methods.

Crystal Report with Asp.NET – Using Data Objects

image
Customer.cs file


public class Customer
{
public int Year { get; set; }
public String Name { get; set; }
}


Then go to query editor and run this SQL, It is better you have some records inserted in the table.













image

SELECT TOP (1) Name, Year
FROM Table1
FOR XML AUTO, Elements



It will return following kind of a XML. thus copy it and save it as Table1.xml (for that add a new XML file to the project and paste the content and save it.)







<?xml version="1.0" encoding="utf-8" ?>
<Table1>
<Name>Amal</Name>
<Year>12</Year>
</Table1>



Then add a new crystal report by selecting a black report option.

















image

 image


Now go to the database Expert and select .Net Object from the Tree menu.













image image


In there select the Customer (this is the class which we created early) and click it to push the other category. Then It will popup following screen. In there select the table1.xml that we created early.



image If you click finished auto generated report will be appear. You also can customize your report as relevant.



imageNow you want to put the data to the report.  Thus add a web form to your project and named it as Report.aspx.  and drag and drop a crystal report viewer to the page.



Report.aspx



<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"><title></title></head>
<
body><form id="form1" runat="server"> <div> <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" />
</
div>
</
form>
</
body>
</
html>


Report.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
List<Customer> cutomerlist = getCustomers();
ReportDocument report = new ReportDocument();
report.Load(Server.MapPath("CrystalReport.rpt"));
report.SetDataSource(cutomerlist);
CrystalReportViewer1.ReportSource = report;
}

private List<Customer> getCustomers()
{
// Put your data base code here to get customers
// I'm adding sample data here
List<Customer> list = new List<Customer>();
list.Add(new Customer() { Name = "Saman", Year = 12 });
list.Add(new Customer() { Name = "Brao", Year = 15 });
return list;
}

How to enable document versioning in the SharePoint

  • Go to particular document library or a list
  • Go to Document Library Settings

image 

  • Go to versioning settings

image

Enable it . In here you can also configure the versioning amount , type and others.

Wednesday, February 24, 2010

Easy Enter

image

Blackberry App

image

Windows Mobile App

image

InfoSD

image

InsMag

image

Crystal Report With Asp.NET – Data Set in Different Project

When architecting the system some types you might layering the application to Data Layer and Presentation Layer. Therefore you normally put the Dataset to the data layer, But your report in the presentation layer. Thus When you are creating the crystal report in Presentation Layer it is not showing the Data Set which is in the Data Layer.

image 

There fore when you are creating the report using data set, it is shown as empty.

image   Thus you want to copy the dataset to the project. For that copy and paste the data set to the project.

image

Now you can design your report by adding the dataset as previous article. After design the report you can delete the dataset i the project (WebApplication)

Now we want to call the report when the page is loading.

Report.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{

ReportDocument CollReport = new ReportDocument();
string reportPath = Server.MapPath("CrystalReport.rpt");
CollReport.Load(reportPath);

DataLayer.DataSetTableAdapters.Table1TableAdapter ta =
new DataLayer.DataSetTableAdapters.Table1TableAdapter();
// We have to refere Datalayer project

DataLayer.DataSet.Table1DataTable dt =
new DataLayer.DataSet.Table1DataTable();

ta.Fill(dt);

CollReport.SetDataSource((DataTable)dt);
CrystalReportViewer1.ReportSource = CollReport;
}

Tuesday, February 23, 2010

How to Disable Back Button (Escape Button) Programmatically in Blackberry

protected boolean keyChar(char character, int status, int time) {
if (Characters.ESCAPE == character) {
return true;
}
return super.keyChar(character, status, time);
}

Crystal Report with Asp.Net – Data Set Method

  • First you need to add a dataset to your project.
    image    image

  • Then Black Screen will be shown. Now you have to add database tables to your datasets. thus if you did not have any database connection yet create one using server explorer.

    image

    You can use either windows authentication or SQL server Authentication. In here I'm using SQL server  authentication. If every things fine you can select the database from the database list. (you can also create databases from here)

      image
  • Then Drag and drop the tables to the dataset designer.

image

  • Now you can design your report but we will do little a little advance thing. Assume you want to get Table1’s Names by giving the Year. Now you want to pass parameter to the query. So you want to add a new method to a table1’s Data Adapter. For that,

image   imageimage

do as above and generate your query using the query designer as follows.

image

  and click finished. Now can see new method is inserted to your table1’s Data Adapter.

image Now you want to design the Crystal report. For that as previous article you can add a new crystal report with blank report option. Now you want to configure the  report to get the data from the data set.

Thus, go to the database explorer and and the data set to the report as follows.

 

image

Finally click ok and design your report by drag and dropping tables fields.  
  image

 

Now you want to code the report.aspx page to load the report.

protected void Page_Load(object sender, EventArgs e)
{

int Year = 12; // you can also get this from query string;

ReportDocument CollReport = new ReportDocument();
string reportPath = Server.MapPath("CrystalReport1.rpt");
CollReport.Load(reportPath);

DataSet1TableAdapters.Table1TableAdapter ta = new WebApplication2.DataSet1TableAdapters.Table1TableAdapter();

DataSet1.Table1DataTable dt = new DataSet1.Table1DataTable();
ta.FillBy(dt, Year);
CollReport.SetDataSource((DataTable)dt);
CrystalReportViewer1.ReportSource = CollReport;
}

Monday, February 22, 2010

Crystal Report with Asp.NET – Direct method using server credentials

In this we are going to create a database connection using server user name and password. For this do the all the steps as previous post until

Make New Connection to Create a New DB connection,

in there give server name, username and password. If everything is correct you can select the server database in your list.

image  

Then click next and finished the wizard.
So you can view your tables in the Field explorer as previous post . Now you can design your report by drag and dropping fields.

Finally save you report as report1.rpt. 

 

Now not like the previous, we want to give server credentials when we Load the report. Thus following codes you can use to  give credentials in report.aspx

protected void Page_Load(object sender, EventArgs e)
{
ReportDocument CollReport = new ReportDocument();
string reportPath = Server.MapPath("Report1.rpt");
CollReport.Load(reportPath);
CollReport.SetDatabaseLogon("username", "password", "servername", "db");
CrystalReportViewer1.ReportSource = CollReport;
}

Crystal Report in ASP.NET – Direct Method Using Integrated Security

  • Create new Asp.Net Web Application or a Web Site
  • Add new crystal report to the application.

image             image

  •   Then select the Black Report. (You can also select the other options (Ex:-Wizard,) ) when you are familiar.

image 

  • Next we want to add the data base connection to create the report. In Here I’m going to use Integrated security.  Thus in the Field Explorer..

image

           image
  • Then click Make New Connection to Create a New DB connection
image       image
  • As above you want to give the server name and check the Integrated Security. If every this is correct now you can select your database from the database list.  Then click finish to Finished the wizard.
  • Then under connection your database will be shown. Then select the tables you want to add the report and add them.
    image    image

  • Then Click ok to continue. Now you can see the table in the Field Explorer. Now you can drag and drop fields and design your report and save it as Report1.rpt.
  • When the report is done. you want to link it to the asp.net page. Assume we are having 2 pages named default.aspx and report.aspx. And when you click the button of index page report should appear.
  • Add a web Form (aspx) to the application and add a button.

Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>



  Default.aspx.cs

 protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/Report.aspx", true);
}


Now we are going to add Report.aspx. Hence add a web form and drag and drop a CrystalReportViewer and CrystalReportSource to your page.  In the page load write the following code to load the report.



Report.aspx



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
</CR:CrystalReportSource>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" />
</div>
</form>
</body>
</html>



Report.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
{
ReportDocument CollReport = new ReportDocument();
string reportPath = Server.MapPath("Report1.rpt");
CollReport.Load(reportPath);
CrystalReportViewer1.ReportSource = CollReport;
}
}

Thursday, February 11, 2010

How to connect to Internet Using Blackberry

In the blackberry there are many standard connection methods.

  1. BES/MDS
  2. Direct TCP
  3. WiFi

But in these methods some times will not work on all the careers so their is a another undocumented method that you  can use.

package com.rdmcorp.itms.sdm.DataService;

import net.rim.device.api.servicebook.ServiceBook;
import net.rim.device.api.servicebook.ServiceRecord;
import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.WLANInfo;

public class ConnectionCreator {

public static String getConnectionString() throws ServerException
{
String connectionString = null;

// Simulator behavior is controlled by the USE_MDS_IN_SIMULATOR variable.
if(DeviceInfo.isSimulator())
{
connectionString = ";deviceside=true";
}

// Wifi is the preferred transmission method
else if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
{
//logMessage("Device is connected via Wifi.");
connectionString = ";interface=wifi";
}

// Is the carrier network the only way to connect?
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
{

String carrierUid = getCarrierBIBSUid();
if(carrierUid == null)
{
// Has carrier coverage, but not BIBS. So use the carrier's TCP network
connectionString = ";deviceside=true";
}
else
{
// otherwise, use the Uid to construct a valid carrier BIBS request
connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public";
}
}

// Check for an MDS connection instead (BlackBerry Enterprise Server)
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
{
connectionString = ";deviceside=false";
}

// If there is no connection available abort to avoid bugging the user unnecssarily.
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
{
ServerException exception = new ServerException(000,"No connection found");

throw exception;
}

// In theory, all bases are covered so this shouldn't be reachable.
else
{
connectionString = ";deviceside=true";
}

return connectionString;
}

/**
* Looks through the phone's service book for a carrier provided BIBS network
* @return The uid used to connect to that network.
*/
private static String getCarrierBIBSUid()
{
ServiceRecord[] records = ServiceBook.getSB().getRecords();
int currentRecord;

for(currentRecord = 0; currentRecord < records.length; currentRecord++)
{
if(records[currentRecord].getCid().toLowerCase().equals("ippp"))
{
if(records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0)
{
return records[currentRecord].getUid();
}
}
}

return null;
}
}