How to uniquely identify a report

Stimulsoft Reports.WEB discussion
Post Reply
hunter
Posts: 20
Joined: Thu Sep 08, 2011 7:13 pm
Location: Sydney, AUS

How to uniquely identify a report

Post by hunter »

I am loading a report from a database. I am unable to find any identifier which is truly unique and I can set (users can not change).

I read this post: http://forum.stimulsoft.com/Default.aspx?g=posts&t=2185
I tried the ReportFile property, but if a user creates a report of the same name as another report, then the ReportFile will be the same and the original will get overwritten.

I tried ReportGuid. That does not hold its state from Load to Save. Neither does Tag or ViewState(...). Is there any field I can put the database's report ID into (or -1 for new report) and read it back at save time, without the user being able to interfere with it?
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

How to uniquely identify a report

Post by Ivan »

Hello,

Please use the MetaTags property of report, for example:

Code: Select all

StiReport Report = new StiReport();
Report.MetaTags.Add(new StiMetaTag("Name1", "Value1"));
Report.MetaTags.Add(new StiMetaTag("Name2", "Test"));
Report.MetaTags.Add(new StiMetaTag("Name3", "Blah"));
Report.MetaTags.Add(new StiMetaTag("Name4", "Stuff"));

.....

string Variable1 = Report.MetaTags["Name1"];
string Variable2 = Report.MetaTags["Name2"];
Thank you.
hunter
Posts: 20
Joined: Thu Sep 08, 2011 7:13 pm
Location: Sydney, AUS

How to uniquely identify a report

Post by hunter »

I have been using this method, but occasionally have problems. I finally looked into it and it seems to be another bug..

When i load the report i set the database index in a MetaTag. If it is a new report, i set to tag to -1.

Code: Select all

report.MetaTags.Add("Report_No", -1)
On save, that value -1 or the index is there - great!

Code: Select all

e.Report.MetaTags("Report_No").Tag
But if the user is creating a new report, I set the new index into the meta tag, to overwrite the -1. It does set, but it does not seem to persist to the next save. If the user keeps pressing save without reloading the report, then it keep getting -1 in the tag which creates another report.

Code: Select all

e.Report.MetaTags("Report_No").Tag = intReport_No
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

How to uniquely identify a report

Post by HighAley »

Hello.

The cause of the problem doesn't quite understand by your description.
Sorry, can you provide sample project for this issue?

Thank you.
hunter
Posts: 20
Joined: Thu Sep 08, 2011 7:13 pm
Location: Sydney, AUS

How to uniquely identify a report

Post by hunter »

The VB test code is a bit messy and may confuse you more. Let me expand on the description:

Loading Code: (this works perfectly)

Code: Select all

Dim intReport As Integer = DataHelper.cInteger(ddlReport.SelectedValue, -1)
Dim drReports As DataRow = AppDatabase.DataRowExec("SELECT FileName, Other_Source FROM Reports WHERE Report_No=" & intReport.ToString)
If IsNothing(drReports) Then General.NotFoundRedirect(ddlReport.SelectedValue, "Report")
report.Load(UTF8Encoding.UTF8.GetBytes(drReports("Other_Source")))
If report.MetaTags.Count = 0 Then
     report.MetaTags.Add("Report_No", intReport)
Else
     report.MetaTags("Report_No").Tag = intReport
End If
On saving, If i have opened an existing report and save it (once or many times), everything work perfectly.
If I open a new report, so that MetaTags("Report_No").Tag=-1 in the code above, and save, then it saves as a new report perfectly and MetaTags("Report_No").Tag is set to >0.
If after saving, the user hits Save again (without closing the Flash app and reloading), then MetaTags("Report_No").Tag is still set to -1 despite just setting it to >0.
I know the code is working as i have stepped thru and seen the meta update and hold the new figure, for at least a moment.

Saving code:

Code: Select all

Dim UpdateReport As New UpdatableTable(AppDatabase)
Dim blnCreating As Boolean
If UpdateReport.Open("SELECT * FROM Reports WHERE Report_No = " & e.Report.MetaTags("Report_No").Tag) < 1 Then
    UpdateReport.NewRow()
    UpdateReport.DataRow("Company") = UserProfile.Company
    UpdateReport.DataRow("FileName") = e.Report.ReportFile
    UpdateReport.AddRow()
    blnCreating = True
End If
UpdateReport.DataRow("Updated_Date") = Now
UpdateReport.DataRow("Updated_By") = UserProfile.ID_No
UpdateReport.DataRow("Report_Name") = e.Report.ReportName
UpdateReport.DataRow("Other_Source") = e.Report.SaveToString()

UpdateReport.Update()
If blnCreating Then
    e.Report.MetaTags("Report_No").Tag = UpdateReport.LastIndex
End If
UpdateReport.Close()
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

How to uniquely identify a report

Post by HighAley »

Hello.

Your code is not enough to make the reason of your problem.
Sorry, can you provide sample project for this issue?

Thank you.
hunter
Posts: 20
Joined: Thu Sep 08, 2011 7:13 pm
Location: Sydney, AUS

How to uniquely identify a report

Post by hunter »

Getting back to this issue. I have stripped down some code and tested it with the latest 2011.3. The attached code shows that the MetaTag is not persisting after the save.

I guess it is because the "e" argument is being passed as a value not a reference. I tried "ByRef" but it is not the same signature as the event. So, how do store the report's primary key at save time?
Attachments
1409.Reports.zip
(1.57 KiB) Downloaded 194 times
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

How to uniquely identify a report

Post by Ivan »

Hello,

We need some additional time to check the issue.

Thank you.
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to uniquely identify a report

Post by Vladimir »

Hello,

We have analyzed your project. Unfortunately, currently is no way to change the report in the save event. We have added this feature to our to-do list, and will try to complete it to an official release 2011.3

Thank you.
Post Reply