Click here to Skip to main content
15,844,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a form crystal report form(name:printBarcodeOfSingleProduct.cs) on which I have few Checkboxes of which some checkboxes are Checked by default while rest are unchecked whose properties are as below:
Control's Name property    Control's Text property        Control Checked property
chkPrice                      Price                   checked=true(By default checked)
chkStoreName                 Store Name               checked=true(By default checked)
chkProductName              Product Name              checked=true(By default checked)
chkPromotionPrice           Promotion Price           checked=false
chkUnit                     Unit                      checked=false
........................so on.......................................................
.......................so on.........................................................
chkCategory               Category Name                       checked=false

I have aditionally 2 textboxes and 1 button on crystal report form(name:printBarcodeOfSingleProduct.cs) whose property are as below:

Control's Name property   Control's Text property              Control Event
btnGenerateBarcode           Generate Barcode                 btnGenerateBarcode_Click
txtProductName               Product Name
txtNoOfCopies                No Of Copies
 
I want to generate crystal report(which prints actually barcode) based on selection of checkboxes.For example If the user check only "chkProductName" then the name of product should be only displayed in crystal report and rest column name should not be displayed.If the user check all the checkboxes then every column of corresponding checkboxes should be displayed.Currently the crytal report displays every column of corresponding checkboxes which is not needed.

 

I have a table named tblProducts
CREATE TABLE [dbo].[tblProducts]
(
[id] INT IDENTITY (1, 1) NOT NULL,
[code] VARCHAR (50) NOT NULL,
[name] CHAR (255) NOT NULL,
[unit] INT DEFAULT (NULL) NULL,
[price] DECIMAL (25, 4) NOT NULL,
[category_id] INT NOT NULL,
CONSTRAINT [code] UNIQUE NONCLUSTERED ([code] ASC)
);


What I have tried:

What I have done see the code below and modify the code to accompolished the desired goal:

C#
public partial class printBarcodeOfSingleProduct : Dashboard4  
    {  
        public printBarcodeOfSingleProduct()  
        {  
           InitializeComponent();  
        }  
  
        ReportDocument crystal = new ReportDocument();  
        private void printBarcodeOfSingleProduct_Load(object sender, EventArgs   
              e)  
        {  
            crystal.Load(@"C:\Project\POSNew\barcodeForParticulatProduct.rpt");  
  
        }


       private void btnGenerateBarcode_Click(object sender, EventArgs e)  
       {  
  
         string cs =   
         ConfigurationManager.ConnectionStrings["abc"].ConnectionString;  
         SqlConnection con = new SqlConnection(cs);  
         string query = "SELECT * FROM tblProducts WHERE id='" +   
                                                                      txtProductId.Text + "'";  
         for (int i = 1; i < int.Parse(txtNoOfCopies.Text); i++)  
         {  
            query += "UNION ALL SELECT * FROM tblProducts WHERE id= '" +   
                          int.Parse(txtProductId.Text) + "'";  
         }  
         SqlDataAdapter sda = new SqlDataAdapter(query, con);  
         DataSet ds = new DataSet();  
         sda.Fill(ds, "tblProducts");  
         crystal.SetDataSource(ds);  
         crystalReportViewer1.ReportSource = crystal;  
    }
Posted
Updated 21-Dec-19 6:16am
v2

1 solution

Use one free form text field and format your results before sending it to the report.

"Free-form" simply means you do the formatting (line breaks, indents, "rich" text).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900