Member 14649908 Ответов: 1

Как создать отчет crystal на основе выбора флажка


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)
);


Что я уже пробовал:

Что я сделал смотрите код ниже и модифицируйте код для достижения желаемой цели:

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;  
    }

1 Ответов

Рейтинг:
1

Gerry Schmitz

Используйте одно текстовое поле свободной формы и отформатируйте свои результаты перед отправкой их в отчет.

"Свободная форма" просто означает, что вы делаете форматирование (разрывы строк, отступы, "богатый" текст).