PDA

View Full Version : ارسال یک مقدار به گزارش



behrouznami
جمعه 06 خرداد 1390, 18:52 عصر
با سلام؛
چگونه می توان یک مقدار (مقدار یک متغیر). را برای گزارش ارسال کرد؟ در ضمن گزارش گیری با استفاده از Microsoft Report می باشد.

با تشکر

catgirl
شنبه 07 خرداد 1390, 11:30 صبح
سلام.فکر کنم بنونی این کارو بکنی که وقتی می خوای فرمی رو show کنی که microsoft report رو توش قرار دادی مقدار متغییرت رو بفرست به فرمی که microsoft report رو توش گذاشتی.من یه تکه کد ساده برات می ذارم.
privatevoid button2_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32(comboBox1.SelectedValue);
print_havale2 f17 = newprint_havale2(i);
f17.Show();
}
فرض کن این دکمه رو که زدی فرمی که نامش print_havale2 هست و کنترل microsoft report رو توش قرار دادی نمایش داده میشه.

TableLogOnInfo LogInfo = newTableLogOnInfo();
void SetLogonInfo()
{
LogInfo.ConnectionInfo.ServerName = "نام سرور";
LogInfo.ConnectionInfo.IntegratedSecurity = true;
LogInfo.ConnectionInfo.DatabaseName = "anbaredaroo";
}
ReportDocument rt = newReportDocument();
cr_havalee rptcrystal = newcr_havalee();
public print_havale2(int b)
{
InitializeComponent();
rt.Load(@"C:\Documents and Settings\maryam\My Documents\Visual Studio 2008\Projects\project\project\cr-havalee.rpt");
rptcrystal.Database.Tables[0].ApplyLogOnInfo(LogInfo);
DataTable DT = newDataTable();
// CmdStr = "select * from daroo where coderesid=@a";
SqlCommand cmd = newSqlCommand();
cmd.CommandText = "select * from table_1 where customerid=@c";
cmd.Parameters.Add("c", SqlDbType.Int).Value = b;
SqlConnection connection = newSqlConnection("data source=localhost;initial catalog=anbaredaroo;integrated security=true");
cmd.Connection = connection;
connection.Open();
SqlDataAdapter Adpt = newSqlDataAdapter(cmd);
DT.Clear();
Adpt.Fill(DT);
connection.Close();
rptcrystal.Database.Tables[0].SetDataSource(DT);
crystalReportViewer1.ReportSource = rptcrystal;
crystalReportViewer1.Zoom(1);
}

متوجه شدی که من اومدم تویه public print_havale2(int b)
یه متغیر تعریف کردم و هنگامی که این فرم رو فراخوانی کردم مقدار این متغیر رو براش فرستادم.نمی دونم تونستم کمکت کنم یا نه؟

b_savad
یک شنبه 08 خرداد 1390, 09:08 صبح
سلام.فکر کنم بنونی این کارو بکنی که وقتی می خوای فرمی رو show کنی که microsoft report رو توش قرار دادی مقدار متغییرت رو بفرست به فرمی که microsoft report رو توش گذاشتی.من یه تکه کد ساده برات می ذارم.
privatevoid button2_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32(comboBox1.SelectedValue);
print_havale2 f17 = newprint_havale2(i);
f17.Show();
}
فرض کن این دکمه رو که زدی فرمی که نامش print_havale2 هست و کنترل microsoft report رو توش قرار دادی نمایش داده میشه.

TableLogOnInfo LogInfo = newTableLogOnInfo();
void SetLogonInfo()
{
LogInfo.ConnectionInfo.ServerName = "نام سرور";
LogInfo.ConnectionInfo.IntegratedSecurity = true;
LogInfo.ConnectionInfo.DatabaseName = "anbaredaroo";
}
ReportDocument rt = newReportDocument();
cr_havalee rptcrystal = newcr_havalee();
public print_havale2(int b)
{
InitializeComponent();
rt.Load(@"C:\Documents and Settings\maryam\My Documents\Visual Studio 2008\Projects\project\project\cr-havalee.rpt");
rptcrystal.Database.Tables[0].ApplyLogOnInfo(LogInfo);
DataTable DT = newDataTable();
// CmdStr = "select * from daroo where coderesid=@a";
SqlCommand cmd = newSqlCommand();
cmd.CommandText = "select * from table_1 where customerid=@c";
cmd.Parameters.Add("c", SqlDbType.Int).Value = b;
SqlConnection connection = newSqlConnection("data source=localhost;initial catalog=anbaredaroo;integrated security=true");
cmd.Connection = connection;
connection.Open();
SqlDataAdapter Adpt = newSqlDataAdapter(cmd);
DT.Clear();
Adpt.Fill(DT);
connection.Close();
rptcrystal.Database.Tables[0].SetDataSource(DT);
crystalReportViewer1.ReportSource = rptcrystal;
crystalReportViewer1.Zoom(1);
}

متوجه شدی که من اومدم تویه public print_havale2(int b)
یه متغیر تعریف کردم و هنگامی که این فرم رو فراخوانی کردم مقدار این متغیر رو براش فرستادم.نمی دونم تونستم کمکت کنم یا نه؟

آره
همین جواب میده