简体   繁体   中英

XtraReport : An object assigned to the DataSource property cannot be used

I have a C# application that use reports stored in a database, and for a particular report, that use a XPObject as datasource ( CptOperation class, the code is below ), I have this error message when trying to print or preview :

An object assigned to the DataSource property cannot be used as a report's datasource, because it does not implement any of supported interfaces. For more information, refer to http://help.devexpress.com/#XtraReports/CustomDocument1179

Here is the code I use to print my report.

public static void PrintReport(string reportCode, object dataSource, string printerName)
{
    using (var uow = new UnitOfWork { ConnectionString = Content.GlobalInfo.ServerConnectionString })
    {
        var report = uow.FindObject<Content.Report>(new BinaryOperator("Code", reportCode));
        if (report == null)
        {
            XtraMessageBox.Show(String.Format("The report {0} is not found", reportCode),
                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }

        var xtraReport = getXtraReportFromReport(report);
        xtraReport.DataSource = dataSource;

        if (!String.IsNullOrEmpty(printerName))
            xtraReport.Print(printerName);
        else
            xtraReport.Print();
    }
}

private static XtraReport getXtraReportFromReport(Content.Report report)
{
    XtraReport xtraReport;
    using (var writer = new StreamWriter(new MemoryStream()))
    {
        writer.Write(report.Content);
        writer.Flush();
        xtraReport = XtraReport.FromStream(writer.BaseStream, true);
    }
    return xtraReport;
}

Here is my object persistance class "CptOperation" :

private CptTypeOperation cptTypeOperation;
public CptTypeOperation CptTypeOperation
{
    get { return cptTypeOperation; }
    set { SetPropertyValue<CptTypeOperation>("CptTypeOperation", ref cptTypeOperation, value); }
}

private int numero;
public int Numero
{
    get { return numero; }
    set { SetPropertyValue<int>("Numero", ref numero, value); }
}

private CptSession cptSession;
[Association("CptSession-CptOperation")]
public CptSession CptSession
{
    get { return cptSession; }
    set { SetPropertyValue<CptSession>("CptSession", ref cptSession, value); }
}

[Association("CptOperation-Piece")]
public XPCollection<Piece> Pieces
{
    get { return GetCollection<Piece>("Pieces"); }
}

[Association("CptOperation-Transact")]
public XPCollection<Transact> Transacts
{
    get { return GetCollection<Transact>("Transacts"); }
}

问题发生的原因是我发送了一个XPObject类型的对象作为报表数据源,但事实上,xtraReport数据源必须是IListIList<T>对象,例如,它可以是类型: XPCollection<CptOperation>List<CptOperation> ......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM