Friends, first of all many many thanks that you are helping me a lot
I get answer to all my posts
kindly help me in this scenario
code looks lengthy but please read and help me friends.....
current doubt scenario
In one of my page i found that
-->a button is there....it generates report,,that is excel report is generated
-->dataset is used here
protected void btnExcel_Click(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
{
DataSet ds = new DataSet();
System.Data.DataTable dt = new System.Data.DataTable();
int company_id = Convert.ToInt32(Session[TMS.Common.CommonConstants.CONST_COMPANY_ID].ToString());
DateTime from_date = Convert.ToDateTime(CalendarControl_FromDate.TextDate.Text);
DateTime To_date = Convert.ToDateTime(CalendarControl_ToDate.TextDate.Text);
int hub_id = Convert.ToInt32(ddl_Hub.SelectedValue);
TMS.Business.Report.INT_Adhoc_Capping obj = new TMS.Business.Report.INT_Adhoc_Capping();
ds = obj.Adhoc_Capping(company_id, from_date, To_date, hub_id);
if (isExecuteReportGeneration(ds))
{
dt = ds.Tables[0];
string attachment = "attachment; filename=Report_Adhoc_Capping.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dt.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
tab = "";
for (i = 0; i < dt.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
else
{
ShowMessageBox("No Record(s) Found.");
}
}
}
catch (Exception ex)
{
}
finally
{
}
}
protected bool isExecuteReportGeneration(DataSet dsResult)
{
bool result = true;
try
{
if (dsResult == null)
{
result = false;
}
if (dsResult.Tables.Count != 1)
{
result = false;
}
if (dsResult.Tables[0] == null)
{
result = false;
}
if (dsResult.Tables[0].Rows.Count == 0)
{
result = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return result;
}
}
--so in above code
ds = obj.Adhoc_Capping(company_id, from_date, To_date, hub_id);
here i get the dataset from backend sp and that is used in the below function..and the report gets successfully generated
if (isExecuteReportGeneration(ds))
-------------------------------------Doubt in second page--------------------------------------
here the scenario is
i have a search button ..upon search the data gets displayed....data comes through arraylist
if data is found the excelbutton visible becomes true,,,and upon click..the data which was displayed by search gets displayed in xcel........
protected void ExportToExcel_Click(object sender, EventArgs e)
{
TMS.API.Schedule.VO_Schedule_SC obj_Schedule = new TMS.API.Schedule.VO_Schedule_SC();
obj_Schedule.StartDate = DateTime.Parse(txt_From_date.Text).ToString("MM/dd/yyyy HH:mm:ss");
obj_Schedule.EndDate = DateTime.Parse(txt_To_date.Text).ToString("MM/dd/yyyy HH:mm:ss");
obj_Schedule.Hub_ID = ddl_Hub.SelectedValue;
obj_Schedule.UserID = string.IsNullOrEmpty(txtEmployeeID.Text) ? string.Empty : txtEmployeeID.Text;
INT_Schedule obj_Int_Schedule = new INT_Schedule();
ArrayList dsRecords = obj_Int_Schedule.GetAllImportedUser_Records(obj_Schedule, PageToDisplay, PageSize);
now here data comes from arraylist---in 1st case it was coming from dataset
i want to use the code of 1st case---but here the data comes from arraylist rather than dataset
ArrayList dsRecords = obj_Int_Schedule.GetAllImportedUser_Records(obj_Schedule, PageToDisplay, PageSize);
dsRecods which is arraylist...if it can be converted to dataset so that i can use the code of first case-that is pass the dataset to the below function and my excel report will be generated.....
if (isExecuteReportGeneration(dsRecords))
{
string attachment = "attachment; filename=Importeduserschedule.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dt.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
tab = "";
for (i = 0; i < dt.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
else
{
ShowMessageBox("No Record(s) Found.");
}
}
}
protected bool isExecuteReportGeneration(DataSet dsResult)
{
bool result = true;
try
{
if (dsResult == null)
{
result = false;
}
if (dsResult.Tables.Count != 1)
{
result = false;
}
if (dsResult.Tables[0] == null)
{
result = false;
}
if (dsResult.Tables[0].Rows.Count == 0)
{
result = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return result;
}
kindly help me in this case