嗨,大家好,我一直在使用WPF C#工作和搜索報告,並發現了一個很好的報告,也很容易,發現這個link並使用它。所以我試圖使用它,請檢查我的代碼,指定的視覺已經是另一個視覺或組件目標的根子
在我EmployeeProfileWindow
在打印按鈕,
private void btnprintviolation_Click(object sender, RoutedEventArgs e)
{
ReportViolationWindow NewReportViolationWindow = new ReportViolationWindow();
//Windows.Add(NewReportViolationWindow);
GlobalVar.ViolationEmpNum = txtdispid.Text;
GlobalVar.ViolationRefNumToPrint.Clear();
for (int i = 0; i < lvviolations.Items.Count; i++)
{
GlobalVar.ViolationRefNumToPrint.Add(((EmpViolationObject)lvviolations.Items[i]).VioRefNum);
}
NewReportViolationWindow.Show();
}
所以,如果有的話我按一下按鈕,將出現一個新的窗口名稱NewReportViolationWindow
。我將在Template文件夾中將其作爲開源示例中的內容進行復制或編輯。我創建了我的報告,名稱爲ReportViolation
,
現在,這是NewReportViolationWindow
後面的代碼。
ReportDocument reportDocument = new ReportDocument();
string ats = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
StreamReader reader = new StreamReader(new FileStream(ats.ToString() + @"\Template\ReportViolation.xaml", FileMode.Open, FileAccess.Read));
reportDocument.XamlData = reader.ReadToEnd();
reportDocument.XamlImagePath = Path.Combine(ats.ToString(), @"Template\");
reader.Close();
DateTime dateTimeStart = DateTime.Now; // start time measure here
List<ReportData> listData = new List<ReportData>();
//foreach (string item in GlobalVar.ViolationRefNumToPrint)
for (int i = 0; i < 5 ; i++)
{
ReportData data = new ReportData();
data.ReportDocumentValues.Add("PrintDate", DateTime.Now);
data.ReportDocumentValues.Add("EmpIDNum", NewIDNumber.ToString());
data.ReportDocumentValues.Add("EmpName", NewEmpName.ToString());
data.ReportDocumentValues.Add("EmpPosition", NewPosition.ToString());
//data.ReportDocumentValues.Add("VioRefCode", item.ToString());
listData.Add(data);
}
XpsDocument xps = reportDocument.CreateXpsDocument(listData);
documentViewer.Document = xps.GetFixedDocumentSequence();
// show the elapsed time in window title
Title += " - generated in " + (DateTime.Now - dateTimeStart).TotalMilliseconds + "ms";
}
catch (Exception ex)
{
// show exception
MessageBox.Show(ex.Message + "\r\n\r\n" + ex.GetType() + "\r\n" + ex.StackTrace, ex.GetType().ToString(), MessageBoxButton.OK, MessageBoxImage.Stop);
}
現在,當我運行我的應用程序,然後單擊打印按鈕。有時在首先它會打開NewReportViolationWindow
,並沒有錯誤,但是當我嘗試關閉報表或再次單擊該按鈕,它會給出一個消息,
指定的可視已經是另一個視覺或根的孩子該組件目標
下面是錯誤的圖像,
我認爲這個問題是,當我打電話打印報告,打印後面的代碼按鈕,嗯,任何人都可以?請... :)
2ND編輯
關於你的問題:- 你說,該報告的窗口通常沒有錯誤打開了 第一次,但不是之後呢?
是正確的..
- 是否存在一些在
ReportViolationWindow
正在使用的任何共享資源?
對不起,我沒有任何想法因爲我只是跟着開源中的示例。
- 你是如何處理/處理關閉的
ReportViolationWindow
?
到目前爲止,我還沒有正確關閉我的ReportViolationWindow
的代碼。當我點擊關閉按鈕,就是這樣,對不起。 :(
- 您保留任何其他引用該
ReportViolationWindow
實例?
號我所知道的。
你怎麼能給我一個例子如何和我該做什麼。謝謝 –
呃...我很抱歉,很有可能它不是*你的代碼 - 我現在只是通過「ReportPaginator」類的源代碼來尋找...... – JerKimball
在這種情況下,很可能你正在處理報告中的一個錯誤發動機本身;既然它是開源的,我會建議抓住源代碼並調試到代碼中......或者詢問創建者。 – JerKimball