Prabhat 7154it

Prabhat 7154it

  • NA
  • 61
  • 7.7k

generate crystal report based on checkbox selection

Dec 21 2019 2:52 AM
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.
What I have done see the code below and modify the code to accompolished the desired goal:
 
  1. public partial class printBarcodeOfSingleProduct : Dashboard4  
  2. {  
  3.      public printBarcodeOfSingleProduct()  
  4.      {  
  5.         InitializeComponent();  
  6.      }  
  7.   
  8.      ReportDocument crystal = new ReportDocument();  
  9.      private void printBarcodeOfSingleProduct_Load(object sender, EventArgs   
  10.               e)  
  11.      {  
  12.          crystal.Load(@"C:\Project\POSNew\barcodeForParticulatProduct.rpt");  
  13.   
  14.      }  
  15.   
  16.      private void btnGenerateBarcode_Click(object sender, EventArgs e)  
  17.      {  
  18.   
  19.       string cs =   
  20.       ConfigurationManager.ConnectionStrings["abc"].ConnectionString;  
  21.       SqlConnection con = new SqlConnection(cs);  
  22.       string query = "SELECT * FROM tblProducts WHERE id='" +   
  23.                                                                       txtProductId.Text + "'";  
  24.       for (int i = 1; i < int.Parse(txtNoOfCopies.Text); i++)  
  25.       {  
  26.          query += "UNION ALL SELECT * FROM tblProducts WHERE id= '" +   
  27.                         int.Parse(txtProductId.Text) + "'";  
  28.       }  
  29.       SqlDataAdapter sda = new SqlDataAdapter(query, con);  
  30.       DataSet ds = new DataSet();  
  31.       sda.Fill(ds, "tblProducts");  
  32.       crystal.SetDataSource(ds);  
  33.       crystalReportViewer1.ReportSource = crystal;  
  34.    }  
  35.   
  36.  }  
  37. }  
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)
);

Answers (1)