1

我有一个带有组合框和日期时间选择器的表单。我希望用户从组合框中选择一个值并选择一个日期,该值需要作为参数捕获并显示在报告中,其中日期等于所选日期,itempiececode 等于所选组合框值。

涉及的部分

表格 - Piece Code.cs 报告 - Report6.rdlc 表格上的 ReportViewer 片段 Code.cs - reportviewer1

如果您仍然不明白我的问题是什么,请点击 ->图片

突出显示的黄色是我需要的。

我有这么远的代码

填写reportviewer

private void PieceCode_Load(object sender, EventArgs e)
{
    // TODO: This line of code loads data into the 'CorsicanaNetWeightDataSet9.CandyPieceSize' table. You can move, or remove it, as needed.
    this.CandyPieceSizeTableAdapter.Fill(this.CorsicanaNetWeightDataSet9.CandyPieceSize);
    // TODO: This line of code loads data into the 'CorsicanaNetWeightDataSet4.PieceDimensionMasterDataUpdate' table. You can move, or remove it, as needed.
    this.PieceDimensionMasterDataUpdateTableAdapter.Fill(this.CorsicanaNetWeightDataSet4.PieceDimensionMasterDataUpdate);
    // TODO: This line of code loads data into the 'corsicanaNetWeightDataSet4piece.Item_Piece' table. You can move, or remove it, as needed.
    this.item_PieceTableAdapter.Fill(this.corsicanaNetWeightDataSet4piece.Item_Piece);
    PieceReport pr = new PieceReport();
    reportViewer1.Visible = false;
    this.reportViewer1.RefreshReport();
}

为了填充组合框,我使用了 datasource 和 displaymemeber 属性 **我使用了报告向导来生成报告 6**

我为大部分程序使用了 GUI,所以没有太多代码可以共享

我需要的总结 我需要将combobox1.selectedtext设置为等于report6上的一个参数,并将datetimepicker.text =设置为另一个参数,以便我可以在我的reportviewer中显示它?或者该程序是否有任何其他解决方法。

我在这里是完全诚实的,请不要关闭这个话题,或者让我停下来,因为我已经提供了我所拥有的一切以供你理解,请帮助我,因为这是我项目的最后一部分,我真的很想完成它假期前与家人共度时光 感谢您的帮助

用代码尝试过,GUI有时不会削减它

namespace CorsicanaNetWeightProgram
{
    public partial class PieceCode : Form
    {

        public string constr = "Data Source=KCMJF1XTR1\\SQLEXPRESS;Initial Catalog=CorsicanaNetWeight;Integrated Security=True";

        public reportfiller fullpiecedetails;

        public piecedescription piece;


        PieceReport pr = new PieceReport(); 
        public PieceCode()
        {
            InitializeComponent();
        }

        private void PieceCode_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'CorsicanaNetWeightDataSet9.CandyPieceSize' table. You can move, or remove it, as needed.

            // TODO: This line of code loads data into the 'corsicanaNetWeightDataSet4piece.Item_Piece' table. You can move, or remove it, as needed.
           // this.item_PieceTableAdapter.Fill(this.corsicanaNetWeightDataSet4piece.Item_Piece);
            PieceReport pr = new PieceReport();
            reportViewer1.Visible = false;
            piece = new piecedescription();
            fillpiece();



            this.reportViewer1.RefreshReport();
        }

        private void fillpiece()
        {
            try
            {
            using(MSSQL.SqlConnection connection = new MSSQL.SqlConnection(constr))
            {
                connection.Open ();
                using (MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT Item + '-' + Description AS PieceDescription FROM dbo.[Piece Dimension Master Data]" ,connection))
                {
                  MSSQL.SqlDataAdapter myadapter = new System.Data.SqlClient.SqlDataAdapter();
                        myadapter.SelectCommand = command;
                        myadapter.Fill(piece, "DataTable1");
                comboBox1.DataSource = piece.DataTable1;
                comboBox1.ValueMember = "PieceDescription";
                comboBox1.DisplayMember = "PieceDescription";


        }
            }
            }

            catch (Exception) { /*Handle error*/ }
            }


        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {          

        }

        private void button1_Click(object sender, EventArgs e)
        { 


            reportViewer1.Visible = true;
            {
                using (MSSQL.SqlConnection connection = new MSSQL.SqlConnection(constr))
                {
                    fullpiecedetails = new reportfiller();
                    connection.Open();
                    //MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT * From EtimePunchDetail WHERE (EmpID = @empid) And  (Paygroup = @paygroup) And (TransDate >= @fromdate) And (TransDate <= @todate)", connection);
                    MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT * FROM dbo.[Piece Dimension Master Data] WHERE Item + '-' + Description  = @piecedesc", connection);
                    {

                        MSSQL.SqlParameter parmEmp = new MSSQL.SqlParameter();
                        parmEmp.ParameterName = "@piecedesc";
                        parmEmp.Value = comboBox1.SelectedValue;
                        command.Parameters.Add(parmEmp);



                        MSSQL.SqlDataAdapter EtimePunchDetailTableAdapter = new System.Data.SqlClient.SqlDataAdapter();
                        EtimePunchDetailTableAdapter.SelectCommand = command;
                        EtimePunchDetailTableAdapter.Fill(fullpiecedetails, "DataTable1");



                        string exeFolder = Path.GetDirectoryName(Application.ExecutablePath);
                        string reportPath = exeFolder + @"\Report6.rdlc";



                        reportViewer1.LocalReport.ReportPath = reportPath;

                        reportViewer1.LocalReport.DataSources.Clear();

                        reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("reportfiller_DataTable1", fullpiecedetails));
                        reportViewer1.RefreshReport();
                        reportViewer1.Refresh();
                        reportViewer1.Visible = true;
                   }
                }
            }

        }

我收到以下错误“值不在预期范围内”。在这部分代码reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("reportfiller_DataTable1", fullpiecedetails));

4

2 回答 2

1

假设您的日期参数名称是 DateParameter。要设置值,我将执行以下操作:

        ReportParameter rpDateParameter = new ReportParameter();
        rpDateParameter.Name = "DateParameter";
        rpDateParameter.Values.Add(dateTimePicker1.Value.ToString());
        reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rpDateParameter });

        // Refresh the report
        reportViewer1.RefreshReport();
于 2014-12-19T08:56:59.840 回答
0

我创建了一个新表单,添加了一个新报告,新数据集并通过 GUI 完成了所有操作 - 使用向导生成报告。

我将数据集编辑为以下代码

SELECT Item, Description, [Piece Category], Shape, [Deposit Weight], [Center Weight], [Center Weight Constant], [Coating Weight], [Coating Weight Constant], [Decorations Weight], [Inclusions Weight], [Center Diameter_LL], [Center Diameter_UL], [Center Length_LL], [Center Length_UL], [Center Width_LL], [Center Width_UL], [Center Height_LL], [Center Height_UL], [Center Weight Variation], [Coated Diameter_LL], [Coated Diameter_UL], [Coated Length_LL], [Coated Length_UL], [Coated Width_LL], [Coated Width_UL], [Coated Height_LL], [Coated Height_UL], [Coated Weight Variation], Item + '-' + Description AS [PieceDescription] FROM [Piece Dimension Master Data] WHERE **Item + '-' + Description  = @piece**

然后在报告中添加了一个包含所有必需列的表格

GUI 为我生成了这段代码

namespace CorsicanaNetWeightProgram
{
    public partial class PieceCodepc : Form
    {
        public PieceCodepc()
        {
            InitializeComponent();
        }

        private void PieceCodepc_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.DataTable1' table. You can move, or remove it, as needed.
            this.dataTable1TableAdapter.Fill(this.dataSet1.DataTable1);

        }

        private void button1_Click(object sender, EventArgs e)
        {

            // TODO: This line of code loads data into the 'empty.Piece_Dimension_Master_Data' table. You can move, or remove it, as needed.
            this.Piece_Dimension_Master_DataTableAdapter.Fill(this.empty.Piece_Dimension_Master_Data, comboBox1.SelectedValue.ToString());

            this.reportViewer1.RefreshReport();


        }
    }
}

我所做的只是将 comboBox1.SelectedValue.ToString() 传递给 DataTableAdapter 并且它工作了!!!!!!

于 2014-12-23T20:29:12.863 回答