PDA

View Full Version : سوال: تبدیل از یک repeter به excel



ندااحمدی
چهارشنبه 12 بهمن 1390, 16:59 عصر
DataSet ds = new DataSet();
PersianCalendar pCalendar = new PersianCalendar();
DateTime a = DateTime.Now;
int year = pCalendar.GetYear(a);
int month = pCalendar.GetMonth(a);
int day = pCalendar.GetDayOfMonth(a);
if (txtNewsDateّFrom.Text == "")
{
arrParams[0] = new SqlParameter("@Start_TarYY", Convert.ToString(year).Substring(2, 2));
arrParams[1] = new SqlParameter("@Start_TarMM", Convert.ToString(month));
arrParams[2] = new SqlParameter("@Start_TarDD", Convert.ToString(day));
}
else
{
DateTime nw;
nw = Convert.ToDateTime(txtNewsDateّFrom.Text);
string sStartDateYY = Convert.ToString(nw.Year);
arrParams[0] = new SqlParameter("@Start_TarYY", sStartDateYY.Substring(2, 2));
string sStartDateMM = Convert.ToString(nw.Month);
string sStartDateDD = Convert.ToString(nw.Day);
arrParams[1] = new SqlParameter("@Start_TarMM", sStartDateMM);
arrParams[2] = new SqlParameter("@Start_TarDD", sStartDateDD);
}
if (txtNewsDateTo.Text == "")
{


arrParams[3] = new SqlParameter("@End_TarYY", Convert.ToString(year).Substring(2, 2));
arrParams[4] = new SqlParameter("@End_TarMM", Convert.ToString(month));
arrParams[5] = new SqlParameter("@End_TarDD", Convert.ToString(day));
}
else
{
DateTime nw;
nw = Convert.ToDateTime(txtNewsDateTo.Text);
string sStartDateYY = Convert.ToString(nw.Year);
arrParams[3] = new SqlParameter("@End_TarYY", sStartDateYY.Substring(2, 2));
string sStartDateMM = Convert.ToString(nw.Month);
string sStartDateDD = Convert.ToString(nw.Day);
arrParams[4] = new SqlParameter("@End_TarMM", sStartDateMM);
arrParams[5] = new SqlParameter("@End_TarDD", sStartDateDD);
}

try
{
hatra.DA.ExecuteDataReader(CommandType.StoredProce dure, "SP_ReportingFoodsMosh", arrParams, ref oMess);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//-----------------------------------------------------------------------
try
{
hatra.DA.ExecuteDataReader(CommandType.StoredProce dure, "SP_Get_ReportingFoodsMosh", null, ref oMess);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//-----------------------------------------------------------------------
try
{
hatra.DA.ExecuteDataReader(CommandType.StoredProce dure, "SP_ReportingFoodsSalon", arrParams, ref oMess);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//-----------------------------------------------------------------------
try
{
hatra.DA.ExecuteDataReader(CommandType.StoredProce dure, "SP_Get_ReportingFoodsSalon", null, ref oMess);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//-----------------------------------------------------------------------
try
{
ds = hatra.DA.ExecuteDataSet(CommandType.StoredProcedur e, "SP_Get_ReportingFoodsAll", null, ref oMess);

}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

//----------------------------------------------------------------------
//ds = hatra.DA.ExecuteDataSet(CommandType.StoredProcedur e, "SP_Get_ReportingFoodsAllTotal", null, ref oMess);
//DataRow dr = ds.Tables[0].Rows[0];
//string[] ArrayTotal = new string[11];
//for (int i = 0; i < 5; i++)
//{
// ArrayTotal[i] = dr.ItemArray[i].ToString();
//}
//lbl0.Text = ViewUserPrice(Convert.ToInt32(ArrayTotal[0]));
//lbl1.Text = ViewUserPrice(Convert.ToInt32(ArrayTotal[1]));
//lbl2.Text = ViewUserPrice(Convert.ToInt32(ArrayTotal[2]));
//lbl3.Text = ViewUserPrice(Convert.ToInt32(ArrayTotal[3]));
//lbl4.Text = ViewUserPrice(Convert.ToInt32(ArrayTotal[4]));
CurrentPage = 0;
dgForm.DataSource = ds;
dgForm.DataBind();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=report.xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "UTF-8";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.ms-excel";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
dgForm.RenderControl(htmlWrite);

Response.Write("<table><tr><center> لیست گزارش فروش رستوران" + "<td > <td> </center></tr><tr><td>شعب</td><td >هات داگ</td><td >برگر</td><td >پیتزا</td><td >ساندویچ</td><td >پیش غذا</td></tr>");
Response.Write(stringWrite.ToString());
Response.Write("</table>");
Response.End();
این کدهام هستش وتا آخر کدها درست عمل میکند ولی فایل اکسل را دانلود نمیکند نمیدانم مشکل کار کجاست لطفا راهنمایی کنید