Hi
I have Parameter as Original , Duplicate , Triplicate , ALL.
If user selects Original then 1 copy should get print.
If All is selected then original , Duplicate , Triplicate copies should get printed
Thanks
Hi
I have Parameter as Original , Duplicate , Triplicate , ALL.
If user selects Original then 1 copy should get print.
If All is selected then original , Duplicate , Triplicate copies should get printed
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 3, 2023, 11:38 AM EST
To achieve this functionality in Crystal Report using C#, you can follow these steps:
Create a parameter in your Crystal Report design to capture the user's selection. Let's call it
CopyType. Set the parameter type to "String" and provide the available values as "Original," "Duplicate," "Triplicate," and "ALL."In your Crystal Report design, add the necessary sections for each copy of the invoice. For example, you can have three sections: "Original," "Duplicate," and "Triplicate." Design each section according to your requirements.
In the section expert for each copy section, go to the "Common" tab and set the "Suppress" formula. Use the following formula for each section:
For "Triplicate" section:
{CopyType} <> "ALL"ReportDocument report = new ReportDocument(); report.Load("path_to_your_report.rpt"); // Set the parameter value report.SetParameterValue("CopyType", "Original"); // Replace "Original" with the user's selection // Print the report report.PrintToPrinter(1, false, 0, 0);Amit MohantyRank #112 · 20K reputationPosted Dec 4, 2023, 4:11 AM EST
Check the below code, this may help you to resolve your issue.
private void btnPrint_Click(object sender, EventArgs e) { // Assuming parameterValue is the variable storing the user-selected parameter value (Original/Duplicate/Triplicate/ALL) string parameterValue = "your-parameter-value"; switch (parameterValue) { case "Original": PrintReport("Original"); break; case "Duplicate": PrintReport("Duplicate"); break; case "Triplicate": PrintReport("Triplicate"); break; case "All": PrintReport("Original"); PrintReport("Duplicate"); PrintReport("Triplicate"); break; default: // Handle any other cases or errors break; } } private void PrintReport(string selectedOption) { ConnectionInfo connectionInfo = new ConnectionInfo { ServerName = @"Your-Server-Name", DatabaseName = "SampleDB", UserID = "sa", Password = "pa$$w0rd" }; ReportDocument reportDocument = new ReportDocument(); reportDocument.Load("path_to_your_report_file.rpt"); reportDocument.SetParameterValue("SelectedOption", selectedOption); TableLogOnInfo tableLogOnInfo = new TableLogOnInfo(); Tables crTables = _reportDocument.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables) { tableLogOnInfo = crTable.LogOnInfo; tableLogOnInfo.ConnectionInfo = connectionInfo; crTable.ApplyLogOnInfo(tableLogOnInfo); } reportDocument.Refresh(); reportDocument.PrintToPrinter(1, false, 0, 0); }