last day (15 days later) » 

9:14 AM
0
Q: Delegate call can not update already opened report

Zubair HasanI am creating c# application. I have two forms let say MainForm and ReportForm. I opened both forms side by side. When some data is saved into database on mainform, i want to show it automatically on reportform. I'm using delegates and delegate call the report method but the crystal report does n...

 
Reports.FullSaleReport saleReport = (Reports.FullSaleReport)Activator.CreateInstance(typeof(Repo‌​rts.FullSaleReport))‌​;This creates a new Report Window. I thought you wanted to update the already opened one?
Secondly, is it possible to have more than 1 ReportWindow opened? If so, the condition will be false (because == 1, better use >= 1 and update all?). Is there a special reason you are using delegates and not events?
 
yes i want to update the opened one. what i have to do?
 
Probably unrelated: Don't concat sql strings, use SqlParameters, and I'd use a using block there.
 
yes it is possible that more than 1 report windows opened but not the same form. Different report windows.
 
"what i have to do?" Do a foreach over the filtered FormCollection and call the items' ShowReport function.
 
9:14 AM
where i concat sql string
sql query runs but don't update the report using delegate method. Preview button runs the same query and update the report
foreach loop? Why?
 
String Query = "..."+ fromDate + ".." + toDate + "... "; <- here. Have a look at the example here: docs.microsoft.com/en-us/dotnet/api/…
"foreach loop? Why?" Don't you want all Forms updated? Or only a specific one? Then it gets tricky.
But anyway: What I'd do is that I'd have a Checkbox on the ReportForms that switches "Watch updates" on or off. Then have the main form fire an event on db updates. Have the ReportForms register for that event and in the handler , if the checkbox is set, trigger that very same update that you are doing on pressing the "update" button.
 
Only one form. Not all forms. I only want to update reportform after inserting a data into database through mainform
 
OK, but you said, there can be more than 1 open at any given time. So how would you identify that one?
 
leave that. its bit confusing. in simple words i only want to update reportform when data is inserted into database through mainform. Both forms are opened at the same time. Let us suppose there is no other form in the application. I update my question using a picture
 
OK. Try: if (Application.OpenForms.OfType<Reports.FullSaleReport>().Coun‌​t() == 1) { Application.OpenForms.OfType<Reports.FullSaleReport>().First‌​OrDefault()?.ShowRep‌​ort("%", DateTime.Now.AddMonths(-1).ToShortDateString(), DateTime.Now.AddDays(1).ToShortDateString()); } If it works, I'll explain further.
 
9:14 AM
nothing happened.
reportform not updated at all.
 
Ok, that's odd. I'll have another look.
Where is CrystalReportViewer from? Is it "CrystalDecisions.Web (CrystalDecisions.Web.dll)"?
 
Fildor it updates a report to an empty report. Before it doesn't change report view.
I'm sorry. I have changed some code to check something so that i told you wrong. but when i rollback the code. it shows an empty report. means update the report view with an empty report.
Your above mentioned code somehow works for me.
 
Just that it updates to an empty report. But that may be a different problem.
 
Before this code it couldn't update the report. But now it changes the view although to an empty report. No data has shown on the report
Fildor Thanks a lot. It works with few more changes
Thanks a lot bro. Highly appreciated. I have to talk to you 4 days before. I have waste my 4 to 5 days on this issue
 

last day (15 days later) »