Подтвердить что ты не робот

Передайте значение параметра sql для отчета devexpress?

Я хочу передать sql-параметр из формы пользователя в свой класс отчетов, но он не работает и не создает отчет, и когда я снова открываю вкладку конструктора отчетов после добавления аргумента ID в класс отчета, он обновляет отчет и удалите мои компоненты.

В чем проблема?

Вот мой класс отчета:

public SodoorZemanatName(long ID)
    {
        InitializeComponent(ID);
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Designer generated code
    private void InitializeComponent(long ID)
    {
            this.components = new System.ComponentModel.Container();
            DevExpress.DataAccess.Sql.CustomSqlQuery customSqlQuery1 = new DevExpress.DataAccess.Sql.CustomSqlQuery();
            DevExpress.DataAccess.Sql.QueryParameter queryParameter1 = new DevExpress.DataAccess.Sql.QueryParameter();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SodoorZemanatName));
            this.topMarginBand1 = new DevExpress.XtraReports.UI.TopMarginBand();
            this.detailBand1 = new DevExpress.XtraReports.UI.DetailBand();
            this.bottomMarginBand1 = new DevExpress.XtraReports.UI.BottomMarginBand();
            this.sqlDataSource2 = new DevExpress.DataAccess.Sql.SqlDataSource(this.components);
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.topMarginBand1.HeightF = 100F;
            this.topMarginBand1.Name = "topMarginBand1";
            this.detailBand1.HeightF = 100F;
            this.detailBand1.Name = "detailBand1";
            this.bottomMarginBand1.HeightF = 100F;
            this.bottomMarginBand1.Name = "bottomMarginBand1";
            this.sqlDataSource2.ConnectionName = "Context";
            this.sqlDataSource2.Name = "sqlDataSource2";
            customSqlQuery1.Name = "Query";
            queryParameter1.Name = "ID";
            queryParameter1.Type = typeof(long);
            queryParameter1.ValueInfo = "0";
            queryParameter1.Value = ID;
            customSqlQuery1.Parameters.Add(queryParameter1);
            customSqlQuery1.Sql = "select * from LG_Garanti where [email protected]";
            this.sqlDataSource2.Queries.AddRange(new DevExpress.DataAccess.Sql.SqlQuery[] {
            customSqlQuery1});
            this.sqlDataSource2.ResultSchemaSerializable = resources.GetString("sqlDataSource2.ResultSchemaSerializable");
    this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] {
    this.topMarginBand1,
    this.detailBand1,
    this.bottomMarginBand1});
    this.ComponentStorage.AddRange(new System.ComponentModel.IComponent[] {
    this.sqlDataSource2});
    this.DataSource = this.sqlDataSource2;
    this.Version = "15.2";
    ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
}
#endregion

И вот мое призвание:

SodoorZemanatName report = new SodoorZemanatName(1);
ASPxDocumentViewer1.ReportTypeName = "SodoorZemanatName";
ASPxDocumentViewer1.Report = report;
4b9b3361

Ответ 1

Я думаю, вы хотите (1) нажать кнопку, (2) передать идентификатор, затем (3) открыть отчет, содержимое которого зависит от этого идентификатора. Так вот как я это сделал (я не уверен, есть ли другой способ, потому что devexpress не является открытым исходным кодом):

  • Создайте свой набор данных, он содержит только информацию, которую вы хотите показать, используя инструмент набора данных Visual Studio. то есть идентификатор, имя, адрес,..... Назовите этот набор данных = ReportDataset. Этот набор данных имеет 1 таблицу с именем MyTable.
  • Создайте свой отчет с именем MyReport с помощью инструмента GUI (не забудьте выбрать XtraReport) и выберите datasource = the ReportDataset, не редактируйте код, сгенерированный инструментом GUI. Просто используйте графический интерфейс, щелкните и щелкните, чтобы добавить метки, добавьте значение из ReportDataset.
  • В форме, форме окна и т.д. ниже должно быть внутри функции, вызванной событием button_click (ваш "вызов" в последнем фрагменте вашего вопроса):

    DataSet new_ds = new DataSet();
    ReportDataset.MyTable runtime_data = new ReportDataset.MyTable();
    //get data from your database according to ID, Row by row 
    //then add them to the runtime_data table
    //in your case, add all the result of "select * from LG_Garanti where [email protected]";
    runtime_data.Rows.Add(new object[] {.blah blah..});// just add row, use whatever method you like
    new_ds.Tables.Add(runtime_data);
    //from this point, new_ds contains runtime data of the row(s) you want ID.
    //now just link that dynamic dataset to your designed report
    MyReport my_report = new MyReport();
    my_report.DataSource = new_ds;
    // Show the print preview or do whatever you want 
    ReportPrintTool printTool = new ReportPrintTool(my_report);
    printTool.ShowRibbonPreviewDialog();
    

Вышеупомянутое должно сделать его более гибким, поскольку отчет может использовать собственный набор данных со смесью разных таблиц.... Вы можете сделать это проще, повторно используя свой собственный набор данных на шаге 1. Надеюсь, это поможет.