Monday, April 21, 2008

Passing Parameters to Crystal Reports

It is seam to be passing parameters to crystal reports (without prompting Enter to parameter values) programmatically some what confusing. So in this article I’ll explain Step by step “how to pass parameters to crystal reports”. We need to import following namespace.
using CrystalDecisions.CrystalReports.Engine;

Then following code pass the parameter value to crystal reports.

protected void Page_Load(object sender, EventArgs e){
this.CrystalReportViewer1.ParameterFieldInfo.Clear();
ParameterDiscreteValue desValue1= new ParameterDiscreteValue();
desValue1.Value = "Testing";// set value for parameter
ParameterField paraFld = new ParameterField();
paraFld.Name = "User";// this is parameter name
paraFld.CurrentValues.Add(desValue1);
paraFld.HasCurrentValue = true;
this.CrystalReportViewer1.ParameterFieldInfo.Add(paraFld);
this.CrystalReportViewer1.ShowFirstPage();
}

If we have more than two parameters it is bit difficult .So we can write common Method to passé parameters to crystal report as follow.

Public Void SetParameter(string ParaName ,string ParaValue)
{
ParameterDiscreteValue desValue= new ParameterDiscreteValue();
desValue. Value= ParaValue;
ParameterField paraFld = new ParameterField();
paraFld.Name = ParaName;
paraFld.CurrentValues.Add(desValue);
paraFld.HasCurrentValue = true;
CrystalReportViewer1.ParameterFieldInfo.Add(paraFld);

}

By using above method we can pass any number of parameters very easily.
As following (Think, ReportName and Createdby are two parameters which we defined in crystal reports) Then

protected void Page_Load(object sender, EventArgs e)
{
this.CrystalReportViewer1.ParameterFieldInfo.Clear();
SetParameter(“ReportName”,”My First Report”);// SetParameter(“Createdby”,”Dinesh”);
this.CrystalReportViewer1.ShowFirstPage();

}

}

Saturday, January 12, 2008

Log4j

Inserting log statements into your code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications.

With log4j it is possible to enable logging at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost. Logging behavior can be controlled by editing a configuration file, without touching the application binary.
so first we need to download log 4j jar file and put it into lib directory .
http://logging.apache.org/log4j/1.2/download.html"

Configure Log4j with Xml file
To configure log4j only we need to copy following log4j.xml file to src folder of project. And edit the location which the log message should be write as
< param name="File" value="../webapps/myporject/info.log > in the log4j.xml file .

log4j.xml

< ? xml version="1.0" encoding="UTF-8" ?>
< !DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
< log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j / ' >

< appender name="STDOUT" class="org.apache.log4j.ConsoleAppender" >
< layout class="org.apache.log4j.PatternLayout">
< param name="ConversionPattern" value="%p-- %c %d{ISO8601}-- %m%n" / >
< /layout>
< /appender>

< appender name="INFO" class="org.apache.log4j.RollingFileAppender">
< param name="File" value="../webapps/myporject/info.log"/> // the location and file name
< param name="Append" value="true" / >
< param name="MaxFileSize" value="5000KB" / >
< param name="MaxBackupIndex" value="2"/>
< layout class="org.apache.log4j.PatternLayout">
< param name="ConversionPattern" value=" %p --%c-- %d{ISO8601} -- %m%n" / >
< /layout>
< filter class="org.apache.log4j.varia.LevelRangeFilter" >
< param name="LevelMin" value="INFO" / >
< /filter>
< /appender>

< appender name="DEBUG" class="org.apache.log4j.RollingFileAppender >
< param name="File" value=" value="../webapps/myporject/logs/debug.log"/ >
< param name="Append" value="true"/>
< param name="MaxFileSize" value="5000KB"/ >
< param name="MaxBackupIndex" value="2"/ >
< layout class="org.apache.log4j.PatternLayout" >
< param name="ConversionPattern" value=" %p--%c %d{ISO8601} -- %m%n"/ >
< /layout>
< filter class="org.apache.log4j.varia.LevelRangeFilter" >
< param name="LevelMin" value="DEBUG" / >
< /filter>
< /appender>

< appender name="FATAL" class="org.apache.log4j.RollingFileAppender" >
< param name="File" value=" value="../webapps/myporject/logs/fatal.log"/ >
< param name="Append" value="true"/ >
< param name="MaxFileSize" value="5000KB"/ >
< param name="MaxBackupIndex" value="2"/ >
< layout class="org.apache.log4j.PatternLayout">
< param name="ConversionPattern" value=" %p--%c %d{ISO8601} -- %m%n"/ >
< /layout>
< filter class="org.apache.log4j.varia.LevelRangeFilter" >
< param name="LevelMin" value="FATAL" / >
< /filter>
< /appender>

< appender name="WARN" class="org.apache.log4j.RollingFileAppender" >
< param name="File" value="../webapps/myporject/logs/warn.log"/ >
< param name="Append" value="true"/ >
< param name="MaxFileSize" value="5000KB"/ >
< param name="MaxBackupIndex" value="2"/>
< layout class="org.apache.log4j.PatternLayout" >
< param name="ConversionPattern" value=" %p--%c %d{ISO8601} -- %m%n"/ >
< /layout>
< filter class="org.apache.log4j.varia.LevelRangeFilter" >
< param name="LevelMin" value="WARN" />
< /filter>
< /appender>

< appender name="ERROR" class="org.apache.log4j.RollingFileAppender" >
< param name="File" value="../webapps/myporject/logs/error.log"/ >
< param name="Append" value="true"/ >
< param name="MaxFileSize" value="5000KB"/ >
< param name="MaxBackupIndex" value="2"/ >
< layout class="org.apache.log4j.PatternLayout">
< param name="ConversionPattern" value="%p--%c %d{ISO8601} -- %m%n"/ >
< /layout>
< filter class="org.apache.log4j.varia.LevelRangeFilter">
< param name="LevelMin" value="ERROR" / >
< /filter>
< /appender>

< root>
< priority value="ALL"/>
< appender-ref ref="DEBUG"/>
< appender-ref ref="FATAL"/>
< appender-ref ref="INFO"/>
< appender-ref ref="WARN"/>
< appender-ref ref="ERROR"/>
< /root>

< /log4j:configuration>



Put log messages in the Class
After put above file to src folder in the project.Then we can use log4j as following code in the progrmme.

import org.apache.log4j.Logger;

class testlog()
{
Logger log=new Logger(testlog.class);
log.Infor("<>>>");// this simply print in specify
//locationwebapps/myporject/info.log
}

Monday, December 10, 2007

Windows From Mouse Right Click pop up menu in c#

Muse right click menu

1.Create Menu in design view (by adding "ContextMenu" control onto the form in the design view )
2.add following code( MouseUp event of the form)

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
contextMenuStrip1.Show(this,e.X, e.Y);
}
}

Wednesday, December 5, 2007

Tomcat configaration

1.Install java 1.5 0r 1.6
2.set PATH by putting following line to c:\autoexec.bat file.(use JDK1.5)

set PATH="C:\Program Files\Java\jdk1.5.0_07\bin";%PATH%

3.Check configured properly by using "java -version" and "javac -help" in command prompt.Make sure not an error message about an unknown command.

4.Go to http://tomcat.apache.org/download-60.cgi and download and unpack the zip file to C:\apache-tomcat-6.0.10 (current version of tomcat 6.0.10)

5.set JAVA_HOME directory by putting following line to c:\autoexec.bat file

set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_07


6.Turn on Servlet Reloading

To turn on servlet reloading, edit Edit C:\apache-tomcat-6.0.14\conf\context.xml and change

< Context >
to
< Context reloadable="true" privileged="true" >

7.Now in the command prompt

C:\>AUTOEXEC.BAT
C:\apache-tomcat-6.0.14\bin>startup.bat

Tuesday, December 4, 2007

Copy Dataset to another Dataset or Table to Table

if We need to copy Dataset contain to another data set we can use copy() method belong to that data set...

private void loadDtagrideview (DataSet ds) // this DataSet retun by another method
{


DataTable table1 = ds.Tables[0].Copy();

table1.Clear(); //remain the structure of the table without data

foreach (DataRow dr in ds.Tables[0].Rows)

{
if( some condition)// copy only the data if the condition true
{

table1.Rows.Add(dr.ItemArray);// only selected rows ..
}
}
}