I have created a back - end application in C# with embedded microsft sql server. I am pretty new to crystal reports and I had created one but in a wrong way and I am trying to correct it. I almost don't remember how I created and I feel bad for that.
So, I have a form represent orders management. So when the user runs the application, he enters an OrderID in the Search Text Box and the corresponding Order appears in the form controls. More detailed, the displayed Order comes with the appropriate Invoice Record, the appropriate Customer that made this order, all these appear in RichTextBoxes, and a DataGridView that displays the products that Customer ordered. Everything runs perfectly.
I also have button for my crystal report of the searched order, the btnPrint.
I would like also to mention that report values are place to details section.
The problem comes when I try to give values to the report from the DataGridView with GiveValuesToRpt function, all the other values appears correctly. I get to the Report only the last record of product details of the DataGridView and not all the records it's need. Any suggestions, help and explanation will be much appreciated.
Thank you so much in advanced.
What I have tried:
<pre>
private void btnPrint_Click(object sender, EventArgs e)
{
Reports.OrderRpt orderRprt = new Reports.OrderRpt(); ;
OrdersPrintReport printFrm = new OrdersPrintReport(ref orderRprt);
IEnumerable<String> paramNames = (from CrystalDecisions.Shared.ParameterField p in orderRprt.ParameterFields
where string.IsNullOrEmpty(p.ReportName)
select p.Name);
foreach (Control Container in this.Controls)
if (Container.GetType() == typeof(GroupBox) || Container.GetType() == typeof(Panel))
{
GiveValuesToRpt(Container, paramNames,ref orderRprt);
}
printFrm.Text = this.Text;
fromForm.OpenChildForm(printFrm, this.fromForm.menuBtn);
}
private void GiveValuesToRpt(Control Container, IEnumerable<String> paramNames, ref Reports.OrderRpt OrderReport)
{
IEnumerable<RichTextBox> RtBoxes;
IEnumerable<CustomCombo> Cbos;
IEnumerable<CheckBox> checkBoxes;
IEnumerable<DateTimePicker> dtPickers;
dtPickers = Enumerable.Empty<DateTimePicker>();
IEnumerable<DataGridView> dtGridViews;
string name, ColumnName;
RtBoxes = SaveSQLquery.GetControls<RichTextBox>(Container.Controls);
Cbos = SaveSQLquery.GetControls<CustomCombo>(Container.Controls);
dtPickers = SaveSQLquery.GetControls<DateTimePicker>(Container.Controls);
checkBoxes = SaveSQLquery.GetControls<CheckBox>(Container.Controls);
dtGridViews = SaveSQLquery.GetControls<DataGridView>(Container.Controls);
foreach (Control cntrl in Container.Controls)
{
if (RtBoxes.Any())
foreach (var RTxtbox in RtBoxes)
{
if (paramNames.Contains(RTxtbox.Name))
{
name = RTxtbox.Name.ToString();
OrderReport.SetParameterValue(name, RTxtbox.Text);
}
}
if (Cbos.Any())
foreach (var Cbo in Cbos)
{
if (paramNames.Contains(Cbo.Name))
OrderReport.SetParameterValue(Cbo.Name, Cbo.Text);
}
if (dtPickers.Any())
foreach (var dtP in dtPickers)
{
if (paramNames.Contains(dtP.Name))
{
OrderReport.SetParameterValue(dtP.Name, DateTime.Parse(dtP.Text.ToString()));
}
}
if (checkBoxes.Any())
{
foreach (var checkBox in checkBoxes)
{
if (paramNames.Contains(checkBox.Name))
{
bool value = checkBox.Checked;
string yes = "Ναι";
if (!value) yes = "Όχι";
OrderReport.SetParameterValue(checkBox.Name, yes);
}
}
}
if (dtGridViews.Any())
{
foreach (var dtGridV in dtGridViews)
{
for (int iR = 0; iR <= dtGridV.Rows.Count - 1; iR++)
for (int iC = 0; iC <= dtGridV.Columns.Count - 1; iC++)
{
ColumnName = dtGridV.Columns[iC].Name;
if (paramNames.Contains(ColumnName))
{
if (dtGridV.Rows[iR].Cells[ColumnName].Value.GetType() == typeof(string))
OrderReport.SetParameterValue(ColumnName, dtGridV.Rows[iR].Cells[ColumnName].Value.ToString());
}
}
}
}
}
}