Thursday 30 April, 2009

XMLHttpRequest - Post Method

function getNewHTTPObject()
{
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp = false;
}
}
return xmlhttp;
}
/*this function post successfully*/
function postForm(getposturl)
{
var xmlvalue=null;
var xmlpost = new getNewHTTPObject();
xmlpost.onreadystatechange=Gtpost;
xmlvalue="posttitle="+ posttitle.value +"&txtnewpost="+post1.value;
var tmppost = encodeURI(getposturl);
xmlpost.open('POST', tmppost, false);
xmlpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlpost.setRequestHeader("Content-length", xmlvalue.length);
xmlpost.setRequestHeader("Connection", "close");
xmlpost.send(xmlvalue);
return;
}

Crystal Report Printing in ASP.Net

function ShowCreprt()
{
string str_sql=null;
DataSet DsMain = new DataSet();
CrystalDecisions.CrystalReports.Engine.ReportDocument rp;

string reportPath = Server.MapPath("LogReport.rpt"); //Set path of Crystal Report

rp = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); // Object of Report Document

sql = "Select l_name as username,'' as sno, userdetail.user_ip as uip from userdetail Where userdetail.user_id=" + int_loginID + " order by servertime";

//in DsMain i fill records as per above query

rp.FileName = reportPath;
rp.SetDataSource(dsmain.Tables[0]);

crviewer.ReportSource = rp;
//I have crviewer control on my page


}

Crystal Report Printing

This example of printing crystal report in Desktop application

Dim DsPrint As New DataSet

//In DsPrint I have my data for printing in crystal reply. Assume that Record only One.

If (DsPrint.Tables(0).Rows.Count - 1) >= 0 Then
Dim ObjR As New CrystalDecisions.CrystalReports.Engine.ReportDocument

ObjR.FileName = "F:\Myproject\CrystalReceipt.rpt" // this is physical path of crystal report.
ObjR.ParameterFields.Item("Trans_ID").CurrentValues.AddValue(Int_TransID)
ObjR.ParameterFields.Item("Str_M").CurrentValues.AddValue(DsPrint.Tables(0).Rows(0).Item(5).ToString)
ObjR.ParameterFields.Item("Str_S").CurrentValues.AddValue(DsPrint.Tables(0).Rows(0).Item(0).ToString)
ObjR.ParameterFields.Item("Str_C").CurrentValues.AddValue(DsPrint.Tables(0).Rows(0).Item(2).ToString)
ObjR.ParameterFields.Item("Str_Con").CurrentValues.AddValue(DsPrint.Tables(0).Rows(0).Item(3).ToString)
ObjR.ParameterFields.Item("Str_Del").CurrentValues.AddValue(DsPrint.Tables(0).Rows(0).Item(1).ToString)
ObjR.ParameterFields.Item("Str_Price").CurrentValues.AddValue(DsPrint.Tables(0).Rows(0).Item(4).ToString)
ObjR.ParameterFields.Item("Str_Status").CurrentValues.AddValue("Deducted")
ObjR.PrintOptions.PrinterName = str_ReceiptPrinter
ObjR.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape // You can change as per your need.

ObjR.PrintToPrinter(1, False, 1, 1)
End If

Wednesday 29 April, 2009

XMLHttpRequest - GET Method

GET Method:
//object creation.
function getNewHTTPObject()
{
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp = false;
}
}

return xmlhttp;
}

function GetResponse()
{
var xmlHttp= new getNewHTTPObject();
xmlHttp.onreadystatechange = httpCallBack;
/*here httpCallBack is function, this function continues running till get final response.*/

xmlHttp.open('GET','http://www.google.co.in',true);
xmlHttp.Send(null);

}

function httpCallBack()
{
if (xmlHttp.readyState == 4)
{
var xmlDoc = null;
if (xmlHttp.status==200)
{
if (xmlHttp.responseText)
{
var myresp= xmlHttp.responseText;
//myresp geting response from URL.
}
}
else
{
alert('no response or error');
}
}
}

Tuesday 28 April, 2009

Reading/Writing Excel without Office.

//reading and writing into xls file without install office at local machine
OleDbConnection objconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/DataUser/User" + loginfolder + "/" + excelsheetname + ".xls") + ";Extended Properties=Excel 8.0;");
objconn.Open();

DataTable dtSheetSchema = new DataTable();
OleDbCommand ObjCmd;

string Str_Sql;
dtSheetSchema = objconn.GetSchema("Tables"); // for getting all table list

string Str_SheetName = "[" + workbookname + "]";
ObjCmd = new OleDbCommand();
ObjCmd.Connection = objconn;
//this code using for preparing sheet columns headings
if (k == 0)
{
Str_Sql = "Select " + str_header.ToString().Substring(0, str_header.Length - 1) + " into " + Str_SheetName + " From [Sheet1$]";
ObjCmd.CommandText = Str_Sql;
ObjCmd.ExecuteNonQuery();
}

Str_Sql = "";
//this code using for insert value in sheet columns
Str_Sql = "Insert into " + Str_SheetName + "(" + str_columns.ToString().Substring(0, str_columns.Length - 1) + ") values(" + str_colvalue.ToString().Substring(0, str_colvalue.Length - 1) + ")";
ObjCmd.CommandText = Str_Sql;
ObjCmd.ExecuteNonQuery();
str_colvalue.Remove(0, str_colvalue.Length);
}
objconn.Close();

Monday 27 April, 2009

Crystal Report Configuration in IIS

First find the path and install on your server and your local machine also.
Drive letter depands on you that where installed your .net
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\CrystalReports\CRRedist2005_x86.msi


After find out below path in your system.
Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\

If in your server crystal report support installed then you found below path
Under below path if this path is available then you configure this path in your crystal report viewer control


suppose my path is below
Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\CrystalReportWebFormViewer3\


set crystal report viewer property ToolbarImagesFolderUrl="/aspnet_client/system_web/2_0_50727/CrystalReportWebFormViewer3/images/toolbar/"


Note : If on server Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\CrystalReportWebFormViewer3 this path is not available then must be create path.
You can copy and paste on server from local machine.. It will be work.

Tuesday 21 April, 2009

Extracting Attributes from XML file

suppose your xml is :
<entry>
<id>myid</id>
<published>mydate</published>
<updated>2009-04-20T22:42:23.233-07:00</updated>
<title type='text'>ASP.NET</title>
<summary type='html'></summary>
<link rel='self' type='application/atom+xml' href='#'/>
<link rel='alternate' type='text/html' href='#'/>
<link rel='http://schemas.my.com/g/2005#feed' type='application/atom+xml' href='#'/>
<link rel='http://schemas.my.com/g/2005#post' type='application/atom+xml' href='#'/>
<link rel='http://schemas.my.com/e' type='application/atom+xml' href='#'/>
<link rel='http://schemas.my.com/g/2008#settings' type='application/atom+xml' href='#'/>
<author>
<name>naresh</name>
<uri>http://www.naresh.com/profile</uri>
<email>noreply@blogger.com</email>
</author>
</entry>

This code read below xml attributes... Working fine.

void ReadXML()
{
XmlDocument xmldoc;

XmlNodeList xmlnodes;
DataSet dsxml = new DataSet();


dsxml = //using this if fill this dataset from database;
dsxml.ReadXml("write here xml path"); // if you have xml file then load xml file in dataset

if (dsxml.Tables.Count > 0)
{
xmldoc = new XmlDocument();
xmldoc.LoadXml(dsxml.GetXml());

xmlnodes = xmldoc.GetElementsByTagName("entry"); // here entry is element

XmlElement xmlel = null;

if (xmlnodes.Count > 0)
{
for (int k = 0; k < xmlnodes.Count; k++)
{
xmlel = xmlnodes[k]["link"];
string str_desc = "";
str_desc = getXmlItem(xmlnodes, "title", "", k);
}

}
}
}


object getXmlItem(XmlNodeList aItem, string aWhat, string aInitValue, int int_aItemIndex)
{
string tmpVar = aInitValue;

if ((aItem[int_aItemIndex][aWhat] != null) && (aItem[int_aItemIndex][aWhat] != null))
{
if ((aItem[int_aItemIndex][aWhat].FirstChild != null) && (aItem[int_aItemIndex][aWhat] != null))
{
tmpVar = aItem[int_aItemIndex][aWhat].FirstChild.Value;
}
}
return tmpVar;
}

Load Report Failed.

Below code is working fine
CrystalDecisions.CrystalReports.Engine.ReportDocument rp;
string reportPath = Server.MapPath("LogReport.rpt");

rp = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

sql = "Select 'User Name :'+lmaster.l_name as username,'' as sno, userdetail.user_ip as uip from userdetail order by servertime";

dsmain = mydata.GetDataSet(sql, 1);// this method my own method will be return query data in dataset.
rp.FileName = reportPath;
rp.SetDataSource(dsmain.Tables[0]);
crviewer.ReportSource = rp;

Thursday 16 April, 2009

Difference between dataset and array

DataSet is good feature of .net, But while we need to working with large amount of data then it is not working.

I remember that once in my project I need to compare single column value from text file. Then i used DataSet, but row is more then 90,00,000 so it is failed there.

So i used normal array. It is working so fine. Normal Array can hold more then 10,000,000 value.

It is very easy to compare with array because we can use binary search.

Change Report Viewer Toolbar Images.

Find out below path in your system.
Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\

If in your server crystal report support installed then you found below path
Under below path you get then all images of report viewer control.
Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\CrystalReportWebFormViewer3\images\toolbar


You can replace your images with default images.
Note. Images name are same as default images.

Please Let me know if any query.

Monday 13 April, 2009

Sending Mail

First you add namespace "System.net.mail"

MailMessage objmail = new MailMessage("from mail address", "to mail address", "mail subject", mail message);
SmtpClient Objsmtpclient = new SmtpClient();
Objsmtpclient.Host = "write here your smtp ip (your smtp server ip)";
Objsmtpclient.Send(objmail);

Saturday 4 April, 2009

What is SOA?

service-oriented architecture is essentially a collection of services. These services communicate with each other. The communication can involve either simple data passing or it could involve two or more services coordinating some activity. Some means of connecting services to each other is needed.

The .Net technology introduces the SOA by mean of web services.



















The SOA can be used as the concept to connect multiple systems to provide services. It has it's great share in the future of the IT world.

According to the imaginary diagram above, we can see how the Service Oriented Architecture is being used to provide a set of centralized services to the citizens of a country. The citizens are given a unique identifying card, where that card carries all personal information of each citizen. Each service centers such as shopping complex, hospital, station, and factory are equipped with a computer system where that system is connected to a central server, which is responsible of providing service to a city. As an example when a customer enter the shopping complex the regional computer system report it to the central server and obtain information about the customer before providing access to the premises. The system welcomes the customer. The customer finished the shopping and then by the time he leaves the shopping complex, he will be asked to go through a billing process, where the regional computer system will manage the process. The payment will be automatically handled with the input details obtain from the customer identifying card.

The regional system will report to the city (computer system of the city) while the city will report to the country (computer system of the country).

What is Software Architecture?

Software Architecture is defined to be the rules, heuristics and patterns governing:

* Partitioning the problem and the system to be built into discrete pieces
* Techniques used to create interfaces between these pieces
* Techniques used to manage overall structure and flow
* Techniques used to interface the system to its environment
* Appropriate use of development and delivery approaches, techniques and tools.

Download Data From Website

Dim uri As New Uri(Str_DownloadUrl)
Dim ObjWebClient as new WebClient
ObjWebClient.DownloadFileAsync(uri, SavePath)
While ObjWebClient.IsBusy = True
comehere:
If ObjWebClient.IsBusy = True Then
GoTo comehere
Else
GoTo exitloop
End If
End While