loading multiple reports in single cystal report viewer - c#

i am passing a parameter called "CustomerId" to the crystal Report ('.rpt') file, based on the parameter its generating the report. when i load this report ('.rpt') to crystal report viewer its working fine...
But i have Different "CustomerId". i need to generate the report based on the parameter and load them into a single report viewer. i.e instead of viewing them single by single, i want to view them all into single report viewer as page wise.
can any one tell me how to solve this please....

You need to set your CustomerID parameter to accept multiple values. Also create a group by Customer and set start new page after for the last section in the group

Create a report viewer for Each report. then report viewers add tab page on tab control.
private void FormCrystalRepotViewer_Shown(object sender, EventArgs e)
{
ReportDocument crReport = crArrReport[0];
crystalReportViewer.ReportSource = crReport;
crystalReportViewer.Zoom(100);
crystalReportViewer.PrintMode = CrystalDecisions.Windows.Forms.PrintMode.PrintToPrinter;
tcTabControl.TabPages[0].Text = arrRaporlar.Get(0).sReportName;
for (int i = 1; i < crArrReport.Count; i++)
{
crReport = crArrReport[i];
CrystalDecisions.Windows.Forms.CrystalReportViewer crview = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
crview.ReportSource = crReport;
crview.Zoom(100);
crview.PrintMode = crystalReportViewer.PrintMode;
crview.ActiveViewIndex = -1;
crview.BorderStyle = crystalReportViewer.BorderStyle;
crview.Cursor = crystalReportViewer.Cursor;
crview.Dock = crystalReportViewer.Dock;
crview.Location = crystalReportViewer.Location;
crview.Size = crystalReportViewer.Size;
crview.TabIndex = 0;
crview.ToolPanelView = crystalReportViewer.ToolPanelView;
crview.ShowParameterPanelButton = crystalReportViewer.ShowParameterPanelButton;
crview.ShowLogo = crystalReportViewer.ShowLogo;
crview.ReportRefresh += new CrystalDecisions.Windows.Forms.RefreshEventHandler(this.crystalReportViewer_ReportRefresh);
TabPage page = new TabPage(arrRaporlar.Get(i).sReportName);
tcTabControl.TabPages.Add(page);
page.Controls.Add(crview);
page.AutoScroll = true;
}
}
private void crystalReportViewer_ReportRefresh(object source, CrystalDecisions.Windows.Forms.ViewerEventArgs e)
{
e.Handled = true;
ParametreleriKontrolEt();
crystalReportViewer.ReportSource = crArrReport[0];
for (int i = 1; i < crArrReport.Count; i++)
{
CrystalDecisions.Windows.Forms.CrystalReportViewer crview = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
crview = tcTabControl.TabPages[i].Controls[0] as CrystalDecisions.Windows.Forms.CrystalReportViewer;
crview.ReportSource = crArrReport[i];
}
}

Related

RDLC report table not populate data from dataset

I am creating an app that prints invoices through Microsoft RDLC report.The report showing some data but the tablix is not showing the values which i provide from dataset.Please see my code below and try to solve my problem.
private void InvoiceButton_Click(object sender, EventArgs e)
{
Parameters p = new Parameters();
List<Parameters> lst = new List<Parameters>();
p.date = CurrentDateTimePicker.Text;
p.CustomerName = CustomerTextBox.Text;
if (CartDataGridView.Rows.Count != 0)
{
for (int i = 0; i < CartDataGridView.Rows.Count-1; i++)
{
lst.Add(new Parameters
{
ItemName = CartDataGridView.Rows[i].Cells[1].Value.ToString(),
Price = CartDataGridView.Rows[i].Cells[2].Value.ToString(),
Quantity = CartDataGridView.Rows[i].Cells[3].Value.ToString(),
Company = CartDataGridView.Rows[i].Cells[4].Value.ToString(),
ExpiryDate = CartDataGridView.Rows[i].Cells[5].Value.ToString(),
Total = CartDataGridView.Rows[i].Cells[7].Value.ToString()
// Subtotal = (Convert.ToInt32(CartDataGridView.Rows[i].Cells[7].Value))
});
}
}
InvoiceForm f = new InvoiceForm();
ReportDataSource rd = new ReportDataSource("MyDataSet");
rd.Value = lst;
f.reportViewer1.LocalReport.ReportEmbeddedResource = "CPMSTestPhase.InvoiceReport.rdlc";
f.reportViewer1.LocalReport.DataSources.Add(rd);
ReportParameter[] rptparam = new ReportParameter[]
{
new ReportParameter("Date",p.date),
new ReportParameter("CustomerName",p.CustomerName),
// new ReportParameter("Subtotal",p.Subtotal.ToString()),
};
f.reportViewer1.LocalReport.SetParameters(rptparam);
f.reportViewer1.RefreshReport();
f.ShowDialog();
}
}ere
I try all solutions available on youtube but did not work.
I myself figured out the issue. The issue is with the order of dataset fields and my parameters class properties. They should be the same.

Telerik report showing same data for all columns created dynamically

I have created a telerik report using Visual Studio and set the Datasource from the DataTable. I am creating the columns dynamically at runtime using Telerik.Reporting.TableGroup. Now the problem I am having here is that the report showing the same data for all of the fields and when I debug it is setting different fields for different.
The code I am using is as follows:
private void Report4_NeedDataSource(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = SalesReport.reportDataTable;
table1.DataSource = dt;
Telerik.Reporting.HtmlTextBox textboxGroup;
Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int ColCount = dt.Columns.Count;
for (int i = 0; i <= ColCount - 1; i++)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
textboxGroup = new Telerik.Reporting.HtmlTextBox();
textboxGroup.Style.BorderColor.Default = Color.Black;
textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
textboxGroup.Value = dt.Columns[i].ColumnName;
textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));
tableGroupColumn.ReportItem = textboxGroup;
textBoxTable = new Telerik.Reporting.HtmlTextBox();
textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
table1.Body.SetCellContent(0, i, textBoxTable);
table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
}
}
I suggest reading the following article. I found this same problem and my solution was to add unique names to the group column, label, and detail text boxes.
http://www.telerik.com/forums/incorrect-dynamic-table-columns
//Added
tableGroupColumn.Name = "group" + *something_uniquegoeshere*;
//Added
textboxGroup.Name = "label" + *something_uniquegoeshere*;
//Added
textBoxTable.Name = "data" + *something_uniquegoeshere*;
Not enough space in a comment unfortunately but here's my advice/suggestion. I'm not certain about your specific error, however in the past I have had issues when re-using variables. You declare your variable outside the for statement and it is possible that this is what is causing the problem.
private void Report4_NeedDataSource(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = SalesReport.reportDataTable;
table1.DataSource = dt;
//Telerik.Reporting.HtmlTextBox textboxGroup;
//Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int ColCount = dt.Columns.Count;
for (int i = 0; i <= ColCount - 1; i++)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
var textboxGroup = new Telerik.Reporting.HtmlTextBox();
textboxGroup.Style.BorderColor.Default = Color.Black;
textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
textboxGroup.Value = dt.Columns[i].ColumnName;
textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));
tableGroupColumn.ReportItem = textboxGroup;
var textBoxTable = new Telerik.Reporting.HtmlTextBox();
textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
table1.Body.SetCellContent(0, i, textBoxTable);
table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
}
}

getting many messages of a Table change in SQL with C#

I am Sending my DataGridview data to SQL database. I have created and initiate the connection. All working fine but when I have more than one raw in my Datagridview, I am getting more messages that means each and every raw getting me a successfully added I need to get only one message.
private void buttonsave_Click(object sender, EventArgs e)
{
InvoiceNew myobj = new InvoiceNew();
myobj.Invoicedate = dateTimePicker1.Value;
myobj.Invoiceno = textBoxInvoiceNo.Text;
myobj.Invoicetotal = Convert.ToDouble(textboxtotal.Text);
myobj.Balance = 0.00;
myobj.Paidammount = Convert.ToDouble(textboxtotal.Text);
myobj.AddInvoiceHeader(myobj);
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
InvoiceDetailNew myobjd = new InvoiceDetailNew();
myobjd.Invoiceno = textBoxInvoiceNo.Text;
myobjd.Itemcode = dataGridView1.Rows[i].Cells[0].Value.ToString();
myobjd.Itemname = dataGridView1.Rows[i].Cells[2].Value.ToString();
myobjd.Qty =
Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value.ToString());
myobjd.Unitprice =
Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value.ToString());
myobjd.Subtotal =
Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value.ToString());
myobjd.AddInvoiceDetail(myobjd);
main_menu myobj1 = new main_menu();
myobj1.Show();
this.Hide();
}
}

Input data into a gridview with C#, ASP.net.

I am using a dataset that was created seperatley and is being used as a reference.
I need to create a gridview with data that comes from the dataset.
Coding is not the ASP.net code, but the C# code.
I just need to make one column of information.
Teacher has not taught us this and is on an assignment. If you can give me a link or type an example that would be great.
one way to doing is to bind the required columns with empty rows to the datatable and then binding the datatable to the girdview...i have given you a sample below
public void GenerateColumns()
{
dtblDummy = new DataTable("dtblDummy");
dtDummyColumn = new DataColumn("FirstName");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("LastName");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Email");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Login");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Password");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Role");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("RoleId");
dtblDummy.Columns.Add(dtDummyColumn);
}
public void GenerateRows(int intRow)
{
for(int intCounter = intRow; intCounter < intRow; intCounter++)
{
dtDummyRow = dtblDummy.NewRow();
dtDummyRow["FirstName"] = "";
dtDummyRow["LastName"] = "";
dtDummyRow["Email"] = "";
dtDummyRow["Login"] = "";
dtblDummy.Rows.Add(dtDummyRow);
}
dgrdUsers.DataSource = dtblDummy;
dgrdUsers.DataBind();
dtblDummy = null;
dtDummyRow = null;
dtDummyColumn = null;
}
in the above code dgrdUsers is the gridview control, and declare the dummy row, column and datatable above the page load function.
call the above two functions in your page load under ispostback....
dont forget the create the same no of columns as template column in your gridview...

C# DataGridView with DataSet display issue

I have the following code:
private void Timer1Tick(object sender, EventArgs e)
{
timer_ScanTimer.Enabled = false;
var psc = new ParseScannedCheckNumbers();
if (psc.ParseCheck(_checkData))
{
label_Status.Text = #"Scan Next Check";
var ct = checkTrans.IndividualCheck.NewIndividualCheckRow();
ct.Date = DateTime.Now.ToShortDateString();
var bracct = GetBranchAccountNumber(psc.BankAccountNumber);
if (bracct.Trim().Length == 7)
{
ct.Branch = bracct.Substring(0, 2);
ct.AccountNumber = bracct.Substring(2, 5);
ct.NameOnCheck = GetAccountName(ct.Branch + ct.AccountNumber);
ct.AccountBalance = GetAccountBalance(ct.Branch + ct.AccountNumber);
}
else
{
ct.Branch = Configuration.Branch;
ct.AccountNumber = string.Empty;
ct.NameOnCheck = string.Empty;
ct.AccountBalance = 0;
}
ct.CheckAmount = 0;
ct.BankRoutingNumber = psc.BankRoutingNumber;
ct.BankAccountNumber = psc.BankAccountNumber;
ct.CheckNumber = psc.CheckNumber;
ct.Status = "Entered";
checkTrans.IndividualCheck.Rows.Add(ct);
}
else
{
label_Status.Text = Resources.ScanCheck_ScanFailed;
}
_checkData = string.Empty;
var rs = new RegistrySettings();
if (!rs.ScanChecksContinuous)
{
StopScanning();
label_Status.Text = Resources.ScanCheck_Success;
EditLastRowEntered();
}
label_ChecksScanned.Text = (dgv_Checks.RowCount - 1).ToString();
}
When the timer goes off, I verified that I have received all of the data, then I add it to the dataset. It's being added to the dataset without issue, it's just being seen on the datagridview every time. Sometimes it works, most time it doesn't.
How do I get the datagridview to update when changes are done to the dataset? Am I doing something wrong in the above code?
Thanks! (again)
If you created the dataset and attached it to the DataGridView using the Visual Studio Data Source Configuration Wizard, then you probably have a call to
this.somethingTableAdapter.Fill(this.yourDataSet.someDataTable);
somewhere in your code. This is what actually loads the data from the DataSet into your DataGridView. While calling this method again might not be the 'proper' way to refresh your DGV, it did the job for me.

Categories