2016-03-23 19 views
10

Voglio passare un parametro sql dal modulo utente alla mia classe di report ma non funziona e non crea il report e quando apro nuovamente la scheda di progettazione report dopo aver aggiunto l'argomento ID alla classe report, aggiorna il report e elimina i miei componenti.Passa un valore di parametro sql al rapporto devexpress?

Qual è il problema?

Qui è la mia classe report:

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 

E qui è la mia vocazione:

SodoorZemanatName report = new SodoorZemanatName(1); 
ASPxDocumentViewer1.ReportTypeName = "SodoorZemanatName"; 
ASPxDocumentViewer1.Report = report; 
+0

Penso che sia necessario progettare il report separatamente. Basta usare 'new DevExpress.XtraReports.UI.XtraReport();' potrebbe non funzionare perché non sa come usare la tua origine dati, come visualizzare i dati. 'rapporto DevExpress.XtraReports.UI.XtraReport = new your_report_design_class();' Ho usato questo genere di cose in passato, devo creare nuovo rapporto con il mio progetto prima di assegnare un DataSource ad esso – minhhn2910

risposta

1

Credo che si desidera (1) fare clic sul pulsante, (2) passare un ID poi (3) aprire il report ha contenuto dipende da tale ID. Quindi questo (non ci non sono sicuro sia un altro modo perché DevExpress non è open source) è il modo in cui l'ho fatto,:

  1. progettare il vostro set di dati, contiene solo le informazioni che si desidera visualizzare utilizzando il set di dati strumento di Visual Studio. ID, nome, indirizzo, ..... Nome set di dati = ReportDataset. Quel set di dati ha 1 tabella denominata MyTable.
  2. Progettare il report denominato MyReport utilizzando lo strumento GUI (ricordarsi di selezionare XtraReport) e selezionare datasource = that ReportDataset, non modificare il codice generato dallo strumento GUI. Basta usare la GUI, fare clic su & fare clic per aggiungere etichette, aggiungere valore da ReportDataset.
  3. In si forma, la forma della finestra o qualsiasi altra cosa, il seguito dovrebbe essere all'interno della funzione innescato da evento button (la vostra "chiamata" nell'ultimo frammento di tua domanda):

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

È possibile che questo è renderlo più flessibile poiché il report può utilizzare il proprio set di dati con la combinazione di diverse tabelle, .... È possibile renderlo più semplice riutilizzando il proprio set di dati nel passaggio 1. Spero che questo aiuti.

+0

Nel mio codice dietro Non posso accedere a ReportDataset perché l'ho creato in Report Designer. –

+0

Ci scusiamo per la confusione, creare l'origine dati all'esterno e assegnarlo al report (utilizzando il file .xsd), non ho accesso a Visual Studio ora, quindi non posso dirlo. https://documentation.devexpress.com/#XtraReports/CustomDocument4797 – minhhn2910

+0

Creare il set di dati e salvarlo come file .xsd in questo modo: https://msdn.microsoft.com/en-us/library/ms171897.aspx – minhhn2910

Problemi correlati