ReportView.xaml.cs 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using AIPractice.LabellerServer.Managers;
  14. using AIPractice.LabellerServer.Managers.Entities;
  15. using AIPractice.LabellerServer.ViewModels;
  16. using AIPractice.Shared.ImageRois;
  17. using MailKit.Net.Smtp;
  18. using MailKit.Security;
  19. using MimeKit;
  20. using PdfSharp;
  21. using PdfSharp.Drawing;
  22. using PdfSharp.Pdf;
  23. namespace AIPractice.LabellerServer.WPF
  24. {
  25. public class ReportDocument:IDisposable
  26. {
  27. private int _pageCount;
  28. private readonly PdfDocument _document;
  29. public ReportDocument(PdfDocument document)
  30. {
  31. _document = document;
  32. }
  33. public ReportPage CreateCoverPage()
  34. {
  35. _pageCount++;
  36. return new CoverPage(_document.AddPage(), _pageCount);
  37. }
  38. public ReportPage CreateContentPage()
  39. {
  40. _pageCount++;
  41. return new ContentPage(_document.AddPage(), _pageCount);
  42. }
  43. public void Save(string filePath)
  44. {
  45. _document.Options.FlateEncodeMode = PdfFlateEncodeMode.BestCompression;
  46. _document.Options.UseFlateDecoderForJpegImages = PdfUseFlateDecoderForJpegImages.Always;
  47. _document.Options.EnableCcittCompressionForBilevelImages = true;
  48. _document.Options.NoCompression = false;
  49. _document.Options.CompressContentStreams = true;
  50. _document.Save(filePath);
  51. }
  52. public void Save(Stream stream)
  53. {
  54. _document.Options.FlateEncodeMode = PdfFlateEncodeMode.BestCompression;
  55. _document.Options.UseFlateDecoderForJpegImages = PdfUseFlateDecoderForJpegImages.Always;
  56. _document.Options.EnableCcittCompressionForBilevelImages = true;
  57. _document.Options.NoCompression = false;
  58. _document.Options.CompressContentStreams = true;
  59. _document.Save(stream);
  60. }
  61. public void Dispose()
  62. {
  63. _document?.Dispose();
  64. }
  65. }
  66. public class ReportPage
  67. {
  68. protected readonly PdfPage Page;
  69. private int _index;
  70. public ReportPage(PdfPage page, int index)
  71. {
  72. _index = index;
  73. Page = page;
  74. Page.Size = PageSize.A3;
  75. }
  76. public virtual void Render()
  77. {
  78. using (XGraphics g = XGraphics.FromPdfPage(Page))
  79. {
  80. var indexVisual = new DrawingVisual();
  81. var indexContext = indexVisual.RenderOpen();
  82. var indexText = new FormattedText(
  83. $"Page {_index}",
  84. CultureInfo.GetCultureInfo("zh-cn"),
  85. FlowDirection.LeftToRight,
  86. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  87. 16,
  88. Brushes.Black);
  89. indexContext.DrawText(indexText, new Point(0, 0));
  90. indexContext.Close();
  91. BitmapSource indexImage = new RenderTargetBitmap((int)indexText.Width, (int)indexText.Height, 96, 96,
  92. PixelFormats.Default);
  93. ((RenderTargetBitmap)indexImage).Render(indexVisual);
  94. g.DrawImage(XImage.FromBitmapSource(indexImage), new XPoint(4, 4));
  95. }
  96. }
  97. }
  98. public class CoverPage : ReportPage
  99. {
  100. public string Title { get; set; }
  101. public string UserName { get; set; }
  102. public CoverPage(PdfPage page, int index) : base(page, index)
  103. {
  104. }
  105. public override void Render()
  106. {
  107. base.Render();
  108. using (XGraphics g = XGraphics.FromPdfPage(Page))
  109. {
  110. var titleVisual = new DrawingVisual();
  111. var titleContext = titleVisual.RenderOpen();
  112. var titleText = new FormattedText(
  113. Title,
  114. CultureInfo.GetCultureInfo("zh-cn"),
  115. FlowDirection.LeftToRight,
  116. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal),
  117. 32,
  118. Brushes.Black);
  119. titleContext.DrawText(titleText, new Point(0, 0));
  120. titleContext.Close();
  121. BitmapSource titleImage = new RenderTargetBitmap((int)titleText.Width, (int)titleText.Height, 96, 96, PixelFormats.Default);
  122. ((RenderTargetBitmap)titleImage).Render(titleVisual);
  123. if (titleImage.Width > Page.Width)
  124. {
  125. var scale = Page.Width / titleImage.Width;
  126. titleImage = new TransformedBitmap(titleImage, new ScaleTransform(scale, scale));
  127. }
  128. var image = XImage.FromBitmapSource(titleImage);
  129. var x = (Page.Width - image.PixelWidth * 72 / image.HorizontalResolution) / 2;
  130. g.DrawImage(image, x, Page.Height / 2 - titleImage.Height - 4);
  131. var userVisual = new DrawingVisual();
  132. var userContext = userVisual.RenderOpen();
  133. var userText = new FormattedText(
  134. UserName,
  135. CultureInfo.GetCultureInfo("zh-cn"),
  136. FlowDirection.LeftToRight,
  137. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  138. 20,
  139. Brushes.Black);
  140. userContext.DrawText(userText, new Point(0, 0));
  141. userContext.Close();
  142. BitmapSource userImage = new RenderTargetBitmap((int)userText.Width, (int)userText.Height, 96, 96, PixelFormats.Default);
  143. ((RenderTargetBitmap)userImage).Render(userVisual);
  144. if (userImage.Width > Page.Width)
  145. {
  146. var scale = Page.Width / userImage.Width;
  147. userImage = new TransformedBitmap(userImage, new ScaleTransform(scale, scale));
  148. }
  149. image = XImage.FromBitmapSource(userImage);
  150. x = (Page.Width - image.PixelWidth * 72 / image.HorizontalResolution) / 2;
  151. g.DrawImage(image, x, Page.Height / 2 + userImage.Height + 4);
  152. }
  153. }
  154. }
  155. public class ContentPage : ReportPage
  156. {
  157. public string Conclusion { get; set; }
  158. public string BestConclusion { get; set; }
  159. public string ReviewDescription { get; set; }
  160. public BitmapSource OriginalImage { get; set; }
  161. public BitmapSource LabeledImage { get; set; }
  162. public BitmapSource BestImage { get; set; }
  163. public ContentPage(PdfPage page, int index) : base(page, index)
  164. {
  165. }
  166. public override void Render()
  167. {
  168. base.Render();
  169. var contentHeight = 0d;
  170. using (XGraphics g = XGraphics.FromPdfPage(Page))
  171. {
  172. var imageTitleVisual1 = new DrawingVisual();
  173. var imageTitleContext1 = imageTitleVisual1.RenderOpen();
  174. var imageTitleText1 = new FormattedText(
  175. "原始图",
  176. CultureInfo.GetCultureInfo("zh-cn"),
  177. FlowDirection.LeftToRight,
  178. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  179. 16,
  180. Brushes.Black);
  181. imageTitleContext1.DrawText(imageTitleText1, new Point(0, 0));
  182. imageTitleContext1.Close();
  183. BitmapSource titleBitmap1 = new RenderTargetBitmap((int)imageTitleText1.Width, (int)imageTitleText1.Height, 96, 96, PixelFormats.Default);
  184. ((RenderTargetBitmap)titleBitmap1).Render(imageTitleVisual1);
  185. var titleImage1 = XImage.FromBitmapSource(titleBitmap1);
  186. var imageTitleVisual2 = new DrawingVisual();
  187. var imageTitleContext2 = imageTitleVisual2.RenderOpen();
  188. var imageTitleText2 = new FormattedText(
  189. "标注图",
  190. CultureInfo.GetCultureInfo("zh-cn"),
  191. FlowDirection.LeftToRight,
  192. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  193. 16,
  194. Brushes.Black);
  195. imageTitleContext2.DrawText(imageTitleText2, new Point(0, 0));
  196. imageTitleContext2.Close();
  197. BitmapSource titleBitmap2 = new RenderTargetBitmap((int)imageTitleText2.Width, (int)imageTitleText2.Height, 96, 96, PixelFormats.Default);
  198. ((RenderTargetBitmap)titleBitmap2).Render(imageTitleVisual2);
  199. var titleImage2 = XImage.FromBitmapSource(titleBitmap2);
  200. var imageTitleVisual3 = new DrawingVisual();
  201. var imageTitleContext3 = imageTitleVisual3.RenderOpen();
  202. var imageTitleText3 = new FormattedText(
  203. "最佳标注图",
  204. CultureInfo.GetCultureInfo("zh-cn"),
  205. FlowDirection.LeftToRight,
  206. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  207. 16,
  208. Brushes.Black);
  209. imageTitleContext3.DrawText(imageTitleText3, new Point(0, 0));
  210. imageTitleContext3.Close();
  211. BitmapSource titleBitmap3 = new RenderTargetBitmap((int)imageTitleText3.Width, (int)imageTitleText3.Height, 96, 96, PixelFormats.Default);
  212. ((RenderTargetBitmap)titleBitmap3).Render(imageTitleVisual3);
  213. var titleImage3 = XImage.FromBitmapSource(titleBitmap3);
  214. var totalTitleHeight = titleImage1.PixelHeight * 72 /
  215. titleImage1.VerticalResolution +
  216. titleImage2.PixelHeight * 72 /
  217. titleImage2.VerticalResolution +
  218. titleImage3.PixelHeight * 72 /
  219. titleImage3.VerticalResolution;
  220. var imageHeight = (Page.Height / 4 * 3 -24 - totalTitleHeight -4)/3;
  221. BitmapSource originalBitmap = OriginalImage;
  222. var originalImage = XImage.FromBitmapSource(originalBitmap);
  223. var originalImageHeight = originalImage.PixelHeight * 72 / originalImage.VerticalResolution;
  224. if (originalImageHeight > imageHeight)
  225. {
  226. var scale = imageHeight / originalImageHeight;
  227. originalBitmap = new TransformedBitmap(originalBitmap, new ScaleTransform(scale, scale));
  228. originalImage = XImage.FromBitmapSource(originalBitmap);
  229. }
  230. var originalImageWidth = originalImage.PixelWidth * 72 / originalImage.HorizontalResolution;
  231. if (originalImageWidth > Page.Width)
  232. {
  233. var scale = Page.Width / originalImageWidth;
  234. originalBitmap = new TransformedBitmap(originalBitmap, new ScaleTransform(scale, scale));
  235. originalImage = XImage.FromBitmapSource(originalBitmap);
  236. }
  237. var x = (Page.Width - originalImage.PixelWidth * 72 / originalImage.HorizontalResolution) / 2;
  238. var y = 24d;
  239. g.DrawImage(originalImage, new XPoint(x, y));
  240. contentHeight += 24 + originalImage.PixelHeight * 72 / originalImage.VerticalResolution;
  241. x = (Page.Width - titleImage1.PixelWidth * 72 / titleImage1.HorizontalResolution) / 2;
  242. y = contentHeight + 2;
  243. g.DrawImage(titleImage1, new XPoint(x, y));
  244. contentHeight += 2 + titleImage1.PixelHeight * 72 / titleImage1.VerticalResolution;
  245. var labeledBitmap = LabeledImage;
  246. var labeledImage = XImage.FromBitmapSource(labeledBitmap);
  247. var labeledImageHeight = labeledImage.PixelHeight * 72 / labeledImage.VerticalResolution;
  248. if (labeledImageHeight > imageHeight)
  249. {
  250. var scale = imageHeight / labeledImageHeight;
  251. labeledBitmap = new TransformedBitmap(labeledBitmap, new ScaleTransform(scale, scale));
  252. labeledImage = XImage.FromBitmapSource(labeledBitmap);
  253. }
  254. var labeledImageWidth = labeledImage.PixelWidth * 72 / labeledImage.HorizontalResolution;
  255. if (labeledImageWidth > Page.Width)
  256. {
  257. var scale = Page.Width / labeledImageWidth;
  258. labeledBitmap = new TransformedBitmap(labeledBitmap, new ScaleTransform(scale, scale));
  259. labeledImage = XImage.FromBitmapSource(labeledBitmap);
  260. }
  261. x = (Page.Width - labeledImage.PixelWidth * 72 / labeledImage.HorizontalResolution) / 2;
  262. y = contentHeight + 2;
  263. g.DrawImage(labeledImage, new XPoint(x, y));
  264. contentHeight += 2 + labeledImage.PixelHeight * 72 / labeledImage.VerticalResolution;
  265. x = (Page.Width - titleImage2.PixelWidth * 72 / titleImage2.HorizontalResolution) / 2;
  266. y = contentHeight + 2;
  267. g.DrawImage(titleImage2, new XPoint(x, y));
  268. contentHeight += 2 + titleImage2.PixelHeight * 72 / titleImage2.VerticalResolution;
  269. var bestBitmap = BestImage;
  270. if (bestBitmap != null)
  271. {
  272. var bestImage = XImage.FromBitmapSource(bestBitmap);
  273. var bestImageHeight = bestImage.PixelHeight * 72 / bestImage.VerticalResolution;
  274. if (bestImageHeight > imageHeight)
  275. {
  276. var scale = imageHeight / bestImageHeight;
  277. bestBitmap = new TransformedBitmap(bestBitmap, new ScaleTransform(scale, scale));
  278. bestImage = XImage.FromBitmapSource(bestBitmap);
  279. }
  280. var bestImageWidth = bestImage.PixelWidth * 72 / bestImage.HorizontalResolution;
  281. if (bestImageWidth > Page.Width)
  282. {
  283. var scale = Page.Width / bestImageWidth;
  284. bestBitmap = new TransformedBitmap(bestBitmap, new ScaleTransform(scale, scale));
  285. bestImage = XImage.FromBitmapSource(bestBitmap);
  286. }
  287. x = (Page.Width - bestImage.PixelWidth * 72 / bestImage.HorizontalResolution) / 2;
  288. y = contentHeight + 2;
  289. g.DrawImage(bestImage, new XPoint(x, y));
  290. contentHeight += 2 + bestImage.PixelHeight * 72 / bestImage.VerticalResolution;
  291. x = (Page.Width - titleImage3.PixelWidth * 72 / titleImage3.HorizontalResolution) / 2;
  292. y = contentHeight + 2;
  293. g.DrawImage(titleImage3, new XPoint(x, y));
  294. contentHeight += 2 + titleImage3.PixelHeight * 72 / titleImage3.VerticalResolution;
  295. }
  296. var maxTextWidth = Page.Width * 96 / 72 - 8.0 * 96 / 72;
  297. var conclusionVisual = new DrawingVisual();
  298. var conclusionContext = conclusionVisual.RenderOpen();
  299. var conclusionTitle = new FormattedText(
  300. "标注结果:",
  301. CultureInfo.GetCultureInfo("zh-cn"),
  302. FlowDirection.LeftToRight,
  303. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal),
  304. 22,
  305. Brushes.Black);
  306. var conclusionText = new FormattedText(
  307. Conclusion,
  308. CultureInfo.GetCultureInfo("zh-cn"),
  309. FlowDirection.LeftToRight,
  310. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  311. 14,
  312. Brushes.Black);
  313. conclusionText.MaxTextWidth = maxTextWidth;
  314. conclusionContext.DrawText(conclusionTitle, new Point(0, 0));
  315. conclusionContext.DrawText(conclusionText, new Point(0, conclusionTitle.Height + 4));
  316. conclusionContext.Close();
  317. var width = Math.Max(conclusionTitle.Width, conclusionText.Width);
  318. var height = conclusionTitle.Height + 4 + conclusionText.Height;
  319. BitmapSource conclusionBitmap = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Default);
  320. ((RenderTargetBitmap)conclusionBitmap).Render(conclusionVisual);
  321. var conclusionImage = XImage.FromBitmapSource(conclusionBitmap);
  322. var imageWidth = conclusionImage.PixelWidth * 72 / conclusionImage.HorizontalResolution;
  323. if (imageWidth > (Page.Width - 8))
  324. {
  325. var scale = (Page.Width - 8) / imageWidth;
  326. conclusionBitmap = new TransformedBitmap(conclusionBitmap, new ScaleTransform(scale, scale));
  327. }
  328. conclusionImage = XImage.FromBitmapSource(conclusionBitmap);
  329. x = 8;
  330. y = contentHeight + 8;
  331. g.DrawImage(conclusionImage, new XPoint(x, y));
  332. contentHeight += 8 + conclusionImage.PixelHeight * 72 / conclusionImage.VerticalResolution;
  333. if (!string.IsNullOrEmpty(BestConclusion))
  334. {
  335. var bestConclusionVisual = new DrawingVisual();
  336. var bestConclusionContext = bestConclusionVisual.RenderOpen();
  337. var bestConclusionTitle = new FormattedText(
  338. "参考结论:",
  339. CultureInfo.GetCultureInfo("zh-cn"),
  340. FlowDirection.LeftToRight,
  341. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Bold,
  342. FontStretches.Normal),
  343. 22,
  344. Brushes.Black);
  345. var bestConclusionText = new FormattedText(
  346. BestConclusion,
  347. CultureInfo.GetCultureInfo("zh-cn"),
  348. FlowDirection.LeftToRight,
  349. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal,
  350. FontStretches.Normal),
  351. 14,
  352. Brushes.Blue);
  353. bestConclusionText.MaxTextWidth = maxTextWidth;
  354. bestConclusionContext.DrawText(bestConclusionTitle, new Point(0, 0));
  355. bestConclusionContext.DrawText(bestConclusionText, new Point(0, conclusionTitle.Height + 4));
  356. bestConclusionContext.Close();
  357. width = Math.Max(bestConclusionTitle.Width, bestConclusionText.Width);
  358. height = bestConclusionTitle.Height + 4 + bestConclusionText.Height;
  359. BitmapSource bestConclusionBitmap =
  360. new RenderTargetBitmap((int) width, (int) height, 96, 96, PixelFormats.Default);
  361. ((RenderTargetBitmap) bestConclusionBitmap).Render(bestConclusionVisual);
  362. var bestConclusionImage = XImage.FromBitmapSource(bestConclusionBitmap);
  363. imageWidth = bestConclusionImage.PixelWidth * 72 / bestConclusionImage.HorizontalResolution;
  364. if (imageWidth > (Page.Width - 8))
  365. {
  366. var scale = (Page.Width - 8) / imageWidth;
  367. bestConclusionBitmap =
  368. new TransformedBitmap(bestConclusionBitmap, new ScaleTransform(scale, scale));
  369. }
  370. bestConclusionImage = XImage.FromBitmapSource(bestConclusionBitmap);
  371. x = 8;
  372. y = contentHeight + 8;
  373. g.DrawImage(bestConclusionImage, new XPoint(x, y));
  374. contentHeight += 8 + bestConclusionImage.PixelHeight * 72 / bestConclusionImage.VerticalResolution;
  375. }
  376. var reviewVisual = new DrawingVisual();
  377. var reviewContext = reviewVisual.RenderOpen();
  378. var reviewTitle = new FormattedText(
  379. "审核结果:",
  380. CultureInfo.GetCultureInfo("zh-cn"),
  381. FlowDirection.LeftToRight,
  382. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal),
  383. 22,
  384. Brushes.Black);
  385. var reviewText = new FormattedText(
  386. ReviewDescription,
  387. CultureInfo.GetCultureInfo("zh-cn"),
  388. FlowDirection.LeftToRight,
  389. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  390. 14,
  391. Brushes.Red);
  392. reviewText.MaxTextWidth = maxTextWidth;
  393. reviewContext.DrawText(reviewTitle, new Point(0, 0));
  394. reviewContext.DrawText(reviewText, new Point(0, reviewTitle.Height + 4));
  395. reviewContext.Close();
  396. width = Math.Max(reviewTitle.Width, reviewText.Width);
  397. height = reviewTitle.Height + 4 + reviewText.Height;
  398. BitmapSource reviewBitmap = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Default);
  399. ((RenderTargetBitmap)reviewBitmap).Render(reviewVisual);
  400. var reviewImage = XImage.FromBitmapSource(reviewBitmap);
  401. imageWidth = reviewImage.PixelWidth * 72 / reviewImage.HorizontalResolution;
  402. if (imageWidth > (Page.Width - 8))
  403. {
  404. var scale = (Page.Width - 8) / imageWidth;
  405. reviewBitmap = new TransformedBitmap(reviewBitmap, new ScaleTransform(scale, scale));
  406. }
  407. reviewImage = XImage.FromBitmapSource(reviewBitmap);
  408. x = 8;
  409. y = contentHeight + 8;
  410. g.DrawImage(reviewImage, new XPoint(x, y));
  411. }
  412. }
  413. }
  414. public class ReviewInfo
  415. {
  416. public string Name { get; }
  417. public int Best { get; }
  418. public int Ok { get; }
  419. public int Bad { get; }
  420. public int Total => Best + Ok + Bad;
  421. public string BadLv
  422. {
  423. get
  424. {
  425. if (Bad == 0)
  426. {
  427. return "0%";
  428. }
  429. return $"{(int) ((double) Bad / Total * 100)}%";
  430. }
  431. }
  432. public ReviewInfo(string name, int best, int ok, int bad)
  433. {
  434. Best = best;
  435. Ok = ok;
  436. Bad = bad;
  437. Name = name;
  438. }
  439. }
  440. /// <summary>
  441. /// Interaction logic for ReportView.xaml
  442. /// </summary>
  443. public partial class ReportView : UserControl
  444. {
  445. private readonly ObservableCollection<AccountViewModel> _accountViewModels = new ObservableCollection<AccountViewModel>();
  446. public ReportView()
  447. {
  448. InitializeComponent();
  449. StartDate.SelectedDate = DateTime.Now.AddMonths(-1);
  450. EndDate.SelectedDate = DateTime.Now;
  451. AccountSelector.ItemsSource = _accountViewModels;
  452. LoadAccounts();
  453. var dataManager = ManagerContainer.GetManager<IDataManager>();
  454. var smtpInfo = dataManager.GetSmtpInfo();
  455. if (smtpInfo != null)
  456. {
  457. SmtpServer.Text = smtpInfo.SmtpServer;
  458. SmtpAccount.Text = smtpInfo.SmtpAccount;
  459. SmtpPassword.Password = smtpInfo.SmtpPassword;
  460. }
  461. else
  462. {
  463. SmtpServer.Text = "host.vinno.com";
  464. SmtpAccount.Text = "ai@vinno.com";
  465. SmtpPassword.Password = "68FwL8XZE4";
  466. }
  467. }
  468. private MimeMessage CreateMessage(string from, string to, string title, string fromName, string toName, Stream reportStream)
  469. {
  470. var message = new MimeMessage();
  471. message.From.Add(new MailboxAddress(fromName, from));
  472. message.To.Add(new MailboxAddress(toName, to));
  473. message.Subject = title;
  474. // create our message text, just like before (except don't set it as the message.Body)
  475. var body = new TextPart("plain")
  476. {
  477. Text = $"{toName}, 您好,请查阅附件中有关您的标注审核报告,如有疑问,可以联系标注系统的负责人。此邮件为系统自动发出,请勿直接回复。"
  478. };
  479. // create an image attachment for the file located at path
  480. var attachment = new MimePart("application","pdf")
  481. {
  482. Content = new MimeContent(reportStream),
  483. ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
  484. ContentTransferEncoding = ContentEncoding.Base64,
  485. FileName = $"{DateTime.Now:yyyyMMdd}.pdf"
  486. };
  487. // now create the multipart/mixed container to hold the message text and the
  488. // image attachment
  489. var multipart = new Multipart("mixed") {body, attachment};
  490. // now set the multipart/mixed as the message body
  491. message.Body = multipart;
  492. return message;
  493. }
  494. private void SendBadReports()
  495. {
  496. if (Application.Current.MainWindow != null)
  497. {
  498. Application.Current.MainWindow.IsEnabled = false;
  499. var dataManager = ManagerContainer.GetManager<IDataManager>();
  500. var startDate = (DateTime)StartDate.SelectedDate;
  501. var endDate = ((DateTime)EndDate.SelectedDate).AddDays(1);
  502. var smtpServer = SmtpServer.Text;
  503. var smtpAccount = SmtpAccount.Text;
  504. var smtpPassword = SmtpPassword.Password;
  505. Task.Run(() =>
  506. {
  507. try
  508. {
  509. LogManager.WriteLog("开始发送报告...");
  510. var accounts = _accountViewModels.Where(x => x.IsSelected).ToList();
  511. var accountIndex = 0;
  512. foreach (var account in accounts)
  513. {
  514. var committedImages =
  515. dataManager.GetReviewedBadCommittedImageCount(account.Id, startDate, endDate).ToList();
  516. if (committedImages.Count > 0)
  517. {
  518. using (var reportDocument = new ReportDocument(new PdfDocument()))
  519. {
  520. var coverPage = (CoverPage) reportDocument.CreateCoverPage();
  521. coverPage.Title =
  522. $"{startDate.ToLongDateString()}-{endDate.ToLongDateString()}标注错误审核报告";
  523. coverPage.UserName = account.FriendlyName;
  524. coverPage.Render();
  525. foreach (var committedImage in committedImages)
  526. {
  527. var bestCommittedImage = dataManager.GetBestCommittedImage(committedImage.ImageId);
  528. BitmapSource bestImage = null;
  529. var bestConclusion = new StringBuilder();
  530. if (bestCommittedImage != null)
  531. {
  532. var bestImageData = ImageData.FromXml(bestCommittedImage.Content);
  533. bestConclusion.AppendLine($"部位:{bestImageData.RootLabelTitle}");
  534. bestConclusion.AppendLine($"图像结论:{bestImageData.Conclusion?.Title}");
  535. bestConclusion.Append("ROI结论:");
  536. foreach (var imageRoi in bestImageData.Rois)
  537. {
  538. bestConclusion.Append(
  539. $"[ROI-{imageRoi.Index}] - {imageRoi.Conclusion?.Title}, ");
  540. }
  541. bestImage = BitmapFrame.Create(new MemoryStream(bestImageData.Data));
  542. var bestVisual = new DrawingVisual();
  543. var bestContext = bestVisual.RenderOpen();
  544. bestContext.DrawImage(bestImage, new Rect(0, 0, bestImage.Width, bestImage.Height));
  545. foreach (var imageRoi in bestImageData.Rois)
  546. {
  547. StreamGeometry geometry = new StreamGeometry
  548. {
  549. FillRule = FillRule.Nonzero
  550. };
  551. var points = imageRoi.Points.Select(x => new Point(x.X, x.Y)).ToArray();
  552. using (StreamGeometryContext ctx = geometry.Open())
  553. {
  554. ctx.BeginFigure(points[0], true, true);
  555. ctx.PolyLineTo(points, true, true);
  556. ctx.LineTo(points[0], true, true);
  557. }
  558. geometry.Freeze();
  559. bestContext.DrawGeometry(Brushes.Transparent, new Pen(Brushes.Lime, 3), geometry);
  560. var indexStr = new FormattedText(
  561. imageRoi.Index.ToString(),
  562. CultureInfo.GetCultureInfo("zh-cn"),
  563. FlowDirection.LeftToRight,
  564. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  565. 12,
  566. Brushes.White);
  567. var width = Math.Max(indexStr.Width, indexStr.Height) + 2;
  568. var height = Math.Max(indexStr.Width, indexStr.Height) + 2;
  569. var left = points.Min(x => x.X) - width;
  570. var top = points.Min(x => x.Y) - height;
  571. var rectTopLeft = new Point(left, top);
  572. bestContext.DrawRoundedRectangle(Brushes.DarkGoldenrod, new Pen(Brushes.Green, 0.5), new Rect(rectTopLeft, new Size(width, height)), 4, 4);
  573. var textTopLeft = new Point(left + (width - indexStr.Width) / 2, top + (height - indexStr.Height) / 2);
  574. bestContext.DrawText(indexStr, textTopLeft);
  575. }
  576. bestContext.Close();
  577. bestImage = new RenderTargetBitmap(bestImage.PixelWidth, bestImage.PixelHeight, 96, 96, PixelFormats.Default);
  578. ((RenderTargetBitmap)bestImage).Render(bestVisual);
  579. }
  580. var conclusion = new StringBuilder();
  581. var image = ImageData.FromXml(committedImage.Content);
  582. conclusion.AppendLine($"部位:{image.RootLabelTitle}");
  583. conclusion.AppendLine($"图像结论:{image.Conclusion?.Title}");
  584. conclusion.Append("ROI结论:");
  585. foreach (var imageRoi in image.Rois)
  586. {
  587. conclusion.Append(
  588. $"[ROI-{imageRoi.Index}] - {imageRoi.Conclusion?.Title}, ");
  589. }
  590. var originalImage = BitmapFrame.Create(new MemoryStream(image.Data));
  591. var visual = new DrawingVisual();
  592. var context = visual.RenderOpen();
  593. context.DrawImage(originalImage, new Rect(0,0, originalImage.Width, originalImage.Height));
  594. foreach (var imageRoi in image.Rois)
  595. {
  596. StreamGeometry geometry = new StreamGeometry
  597. {
  598. FillRule = FillRule.Nonzero
  599. };
  600. var points = imageRoi.Points.Select(x => new Point(x.X, x.Y)).ToArray();
  601. using (StreamGeometryContext ctx = geometry.Open())
  602. {
  603. ctx.BeginFigure(points[0], true, true);
  604. ctx.PolyLineTo(points, true, true);
  605. ctx.LineTo(points[0], true, true);
  606. }
  607. geometry.Freeze();
  608. context.DrawGeometry(Brushes.Transparent, new Pen(Brushes.Lime,3), geometry);
  609. var indexStr = new FormattedText(
  610. imageRoi.Index.ToString(),
  611. CultureInfo.GetCultureInfo("zh-cn"),
  612. FlowDirection.LeftToRight,
  613. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  614. 12,
  615. Brushes.White);
  616. var width = Math.Max(indexStr.Width, indexStr.Height) + 2;
  617. var height = Math.Max(indexStr.Width, indexStr.Height) + 2;
  618. var left = points.Min(x => x.X) - width;
  619. var top = points.Min(x => x.Y) - height;
  620. var rectTopLeft = new Point(left, top);
  621. context.DrawRoundedRectangle(Brushes.DarkGoldenrod, new Pen(Brushes.Green, 0.5), new Rect(rectTopLeft, new Size(width, height)), 4, 4);
  622. var textTopLeft = new Point(left + (width - indexStr.Width) / 2, top + (height - indexStr.Height) / 2);
  623. context.DrawText(indexStr, textTopLeft);
  624. }
  625. context.Close();
  626. var labeledImage = new RenderTargetBitmap(originalImage.PixelWidth, originalImage.PixelHeight,96,96, PixelFormats.Default);
  627. labeledImage.Render(visual);
  628. var contentPage = (ContentPage)reportDocument.CreateContentPage();
  629. contentPage.BestConclusion = bestConclusion.ToString();
  630. contentPage.BestImage = bestImage;
  631. contentPage.OriginalImage = originalImage;
  632. contentPage.LabeledImage = labeledImage;
  633. contentPage.Conclusion = conclusion.ToString();
  634. contentPage.ReviewDescription = committedImage.ResultDescription;
  635. contentPage.Render();
  636. }
  637. using (var reportStream = new MemoryStream())
  638. {
  639. reportDocument.Save(reportStream);
  640. //Send Email
  641. var message = CreateMessage(smtpAccount, account.Email, "AI图像标注审核报告",
  642. "AI标注系统", account.FriendlyName, reportStream);
  643. if (message != null)
  644. {
  645. using (var client = new SmtpClient())
  646. {
  647. client.ServerCertificateValidationCallback = (s, c, h, e) => true;
  648. client.Connect(smtpServer, 465, SecureSocketOptions.SslOnConnect);
  649. client.Authenticate(smtpAccount, smtpPassword);
  650. client.Send(message);
  651. client.Disconnect(true);
  652. }
  653. }
  654. }
  655. }
  656. }
  657. accountIndex++;
  658. var progress = (int)((float)accountIndex / accounts.Count * 100);
  659. LogManager.WriteLog($"报告发送中...{progress}%");
  660. }
  661. dataManager.SetSmtpInfo(smtpServer,smtpAccount,smtpPassword);
  662. }
  663. catch (Exception ex)
  664. {
  665. LogManager.WriteLog($"报告发送出错:{ex.Message}。");
  666. }
  667. finally
  668. {
  669. Dispatcher.Invoke(() => { Application.Current.MainWindow.IsEnabled = true; });
  670. }
  671. });
  672. }
  673. }
  674. private void CreateTotalBadReport(string filePath)
  675. {
  676. if (Application.Current.MainWindow != null)
  677. {
  678. Application.Current.MainWindow.IsEnabled = false;
  679. var dataManager = ManagerContainer.GetManager<IDataManager>();
  680. var startDate = (DateTime)StartDate.SelectedDate;
  681. var endDate = ((DateTime)EndDate.SelectedDate).AddDays(1);
  682. Task.Run(() =>
  683. {
  684. using (var reportDocument = new ReportDocument(new PdfDocument()))
  685. {
  686. try
  687. {
  688. LogManager.WriteLog("开始生成报告...");
  689. var accounts = _accountViewModels.Where(x => x.IsSelected).ToList();
  690. var accountIndex = 0;
  691. foreach (var account in accounts)
  692. {
  693. var committedImages =
  694. dataManager.GetReviewedBadCommittedImageCount(account.Id, startDate, endDate)
  695. .ToList();
  696. if (committedImages.Count > 0)
  697. {
  698. var coverPage = (CoverPage) reportDocument.CreateCoverPage();
  699. coverPage.Title =
  700. $"{startDate.ToLongDateString()}-{endDate.ToLongDateString()}标注错误审核报告";
  701. coverPage.UserName = account.FriendlyName;
  702. coverPage.Render();
  703. foreach (var committedImage in committedImages)
  704. {
  705. var bestCommittedImage = dataManager.GetBestCommittedImage(committedImage.ImageId);
  706. BitmapSource bestImage = null;
  707. var bestConclusion = new StringBuilder();
  708. if (bestCommittedImage != null)
  709. {
  710. var bestImageData = ImageData.FromXml(bestCommittedImage.Content);
  711. bestConclusion.AppendLine($"部位:{bestImageData.RootLabelTitle}");
  712. bestConclusion.AppendLine($"图像结论:{bestImageData.Conclusion?.Title}");
  713. bestConclusion.Append("ROI结论:");
  714. foreach (var imageRoi in bestImageData.Rois)
  715. {
  716. bestConclusion.Append(
  717. $"[ROI-{imageRoi.Index}] - {imageRoi.Conclusion?.Title}, ");
  718. }
  719. bestImage = BitmapFrame.Create(new MemoryStream(bestImageData.Data));
  720. var bestVisual = new DrawingVisual();
  721. var bestContext = bestVisual.RenderOpen();
  722. bestContext.DrawImage(bestImage, new Rect(0, 0, bestImage.Width, bestImage.Height));
  723. foreach (var imageRoi in bestImageData.Rois)
  724. {
  725. StreamGeometry geometry = new StreamGeometry
  726. {
  727. FillRule = FillRule.Nonzero
  728. };
  729. var points = imageRoi.Points.Select(x => new Point(x.X, x.Y)).ToArray();
  730. using (StreamGeometryContext ctx = geometry.Open())
  731. {
  732. ctx.BeginFigure(points[0], true, true);
  733. ctx.PolyLineTo(points, true, true);
  734. ctx.LineTo(points[0], true, true);
  735. }
  736. geometry.Freeze();
  737. bestContext.DrawGeometry(Brushes.Transparent, new Pen(Brushes.Lime, 3), geometry);
  738. var indexStr = new FormattedText(
  739. imageRoi.Index.ToString(),
  740. CultureInfo.GetCultureInfo("zh-cn"),
  741. FlowDirection.LeftToRight,
  742. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  743. 12,
  744. Brushes.White);
  745. var width = Math.Max(indexStr.Width, indexStr.Height) + 2;
  746. var height = Math.Max(indexStr.Width, indexStr.Height) + 2;
  747. var left = points.Min(x => x.X) - width;
  748. var top = points.Min(x => x.Y) - height;
  749. var rectTopLeft = new Point(left, top);
  750. bestContext.DrawRoundedRectangle(Brushes.DarkGoldenrod, new Pen(Brushes.Green, 0.5), new Rect(rectTopLeft, new Size(width, height)), 4, 4);
  751. var textTopLeft = new Point(left + (width - indexStr.Width) / 2, top + (height - indexStr.Height) / 2);
  752. bestContext.DrawText(indexStr, textTopLeft);
  753. }
  754. bestContext.Close();
  755. bestImage = new RenderTargetBitmap(bestImage.PixelWidth, bestImage.PixelHeight, 96, 96, PixelFormats.Default);
  756. ((RenderTargetBitmap)bestImage).Render(bestVisual);
  757. }
  758. var conclusion = new StringBuilder();
  759. var image = ImageData.FromXml(committedImage.Content);
  760. conclusion.AppendLine($"部位:{image.RootLabelTitle}");
  761. conclusion.AppendLine($"图像结论:{image.Conclusion?.Title}");
  762. conclusion.Append("ROI结论:");
  763. foreach (var imageRoi in image.Rois)
  764. {
  765. conclusion.Append(
  766. $"[ROI-{imageRoi.Index}] - {imageRoi.Conclusion?.Title}, ");
  767. }
  768. var originalImage = BitmapFrame.Create(new MemoryStream(image.Data));
  769. var visual = new DrawingVisual();
  770. var context = visual.RenderOpen();
  771. context.DrawImage(originalImage, new Rect(0, 0, originalImage.Width, originalImage.Height));
  772. foreach (var imageRoi in image.Rois)
  773. {
  774. StreamGeometry geometry = new StreamGeometry
  775. {
  776. FillRule = FillRule.Nonzero
  777. };
  778. var points = imageRoi.Points.Select(x => new Point(x.X, x.Y)).ToArray();
  779. using (StreamGeometryContext ctx = geometry.Open())
  780. {
  781. ctx.BeginFigure(points[0], true, true);
  782. ctx.PolyLineTo(points, true, true);
  783. ctx.LineTo(points[0], true, true);
  784. }
  785. geometry.Freeze();
  786. context.DrawGeometry(Brushes.Transparent, new Pen(Brushes.Lime, 3), geometry);
  787. var indexStr = new FormattedText(
  788. imageRoi.Index.ToString(),
  789. CultureInfo.GetCultureInfo("zh-cn"),
  790. FlowDirection.LeftToRight,
  791. new Typeface(new FontFamily("Microsoft YaHei"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
  792. 12,
  793. Brushes.White);
  794. var width = Math.Max(indexStr.Width, indexStr.Height) + 2;
  795. var height = Math.Max(indexStr.Width, indexStr.Height) + 2;
  796. var left = points.Min(x => x.X) - width;
  797. var top = points.Min(x => x.Y) - height;
  798. var rectTopLeft = new Point(left, top);
  799. context.DrawRoundedRectangle(Brushes.DarkGoldenrod,new Pen(Brushes.Green,0.5), new Rect(rectTopLeft, new Size(width,height)),4,4 );
  800. var textTopLeft = new Point(left + (width - indexStr.Width)/2, top + (height - indexStr.Height)/2);
  801. context.DrawText(indexStr, textTopLeft);
  802. }
  803. context.Close();
  804. var labeledImage = new RenderTargetBitmap(originalImage.PixelWidth, originalImage.PixelHeight, 96, 96, PixelFormats.Default);
  805. labeledImage.Render(visual);
  806. var contentPage = (ContentPage)reportDocument.CreateContentPage();
  807. contentPage.BestConclusion = bestConclusion.ToString();
  808. contentPage.BestImage = bestImage;
  809. contentPage.OriginalImage = originalImage;
  810. contentPage.LabeledImage = labeledImage;
  811. contentPage.Conclusion = conclusion.ToString();
  812. contentPage.ReviewDescription = committedImage.ResultDescription;
  813. contentPage.Render();
  814. }
  815. }
  816. accountIndex++;
  817. var progress = (int) ((float) accountIndex / accounts.Count * 100);
  818. LogManager.WriteLog($"报告生成中...{progress}%");
  819. }
  820. reportDocument.Save(filePath);
  821. LogManager.WriteLog("报告生成成功。");
  822. }
  823. catch (Exception ex)
  824. {
  825. LogManager.WriteLog($"报告生成出错:{ex.Message}。");
  826. }
  827. finally
  828. {
  829. Dispatcher.Invoke(() => { Application.Current.MainWindow.IsEnabled = true; });
  830. }
  831. }
  832. });
  833. }
  834. }
  835. private void LoadAccounts()
  836. {
  837. AccountSelector.Text = string.Empty;
  838. foreach (var accountViewModel in _accountViewModels)
  839. {
  840. accountViewModel.IsSelectedChanged -= OnAccountViewModelIsSelectedChanged;
  841. }
  842. _accountViewModels.Clear();
  843. var dataManager = ManagerContainer.GetManager<IDataManager>();
  844. var accounts = dataManager.GetAccounts();
  845. foreach (var account in accounts)
  846. {
  847. var accountViewModel = new AccountViewModel
  848. {
  849. Id = account.Id,
  850. Name = account.Name,
  851. Description = account.Description,
  852. Password = account.Password,
  853. CreatedTime = account.CreatedTime,
  854. Labels = account.Labels,
  855. IsReviewer = account.IsReviewer,
  856. Email = account.Email,
  857. };
  858. accountViewModel.IsSelectedChanged += OnAccountViewModelIsSelectedChanged;
  859. _accountViewModels.Add(accountViewModel);
  860. }
  861. AccountSelector.SelectAll();
  862. }
  863. private void OnAccountViewModelIsSelectedChanged(object sender, EventArgs e)
  864. {
  865. var selectedNames = _accountViewModels.Where(x => x.IsSelected).Select(x => x.FriendlyName).ToArray();
  866. AccountSelector.Text = string.Join(",", selectedNames);
  867. }
  868. private void OnClearClick(object sender, RoutedEventArgs e)
  869. {
  870. Result.Items.Clear();
  871. }
  872. private void OnSelectUnSelectAllAccounts(object sender, bool e)
  873. {
  874. foreach (var accountViewModel in _accountViewModels)
  875. {
  876. accountViewModel.IsSelected = e;
  877. }
  878. }
  879. private void OnAccountsOnRefreshed(object sender, EventArgs e)
  880. {
  881. LoadAccounts();
  882. }
  883. private void OnCalcReviewedClick(object sender, RoutedEventArgs e)
  884. {
  885. Result.Items.Clear();
  886. if (Application.Current.MainWindow != null)
  887. {
  888. Application.Current.MainWindow.IsEnabled = false;
  889. var dataManager = ManagerContainer.GetManager<IDataManager>();
  890. var startDate = (DateTime)StartDate.SelectedDate;
  891. var endDate = ((DateTime)EndDate.SelectedDate).AddDays(1);
  892. var resultList = new List<ReviewInfo>();
  893. Task.Run(() =>
  894. {
  895. try
  896. {
  897. LogManager.WriteLog("开始统计信息...");
  898. var accounts = _accountViewModels.Where(x => x.IsSelected).ToList();
  899. var accountIndex = 0;
  900. foreach (var account in accounts)
  901. {
  902. var bestCount = dataManager.GetReviewedCommittedImageCount(account.Id,ReviewResult.Best,startDate, endDate);
  903. var okCount = dataManager.GetReviewedCommittedImageCount(account.Id, ReviewResult.Ok, startDate, endDate);
  904. var badCount = dataManager.GetReviewedCommittedImageCount(account.Id, ReviewResult.Fail, startDate, endDate);
  905. resultList.Add(new ReviewInfo(account.FriendlyName, bestCount, okCount, badCount));
  906. accountIndex++;
  907. var progress = (int)((float)accountIndex / accounts.Count * 100);
  908. LogManager.WriteLog($"统计信息中...{progress}%");
  909. }
  910. Dispatcher.Invoke(() =>
  911. {
  912. foreach (var result in resultList)
  913. {
  914. Result.Items.Add(result);
  915. }
  916. });
  917. LogManager.WriteLog("统计信息完毕。");
  918. }
  919. catch (Exception ex)
  920. {
  921. LogManager.WriteLog($"统计信息出错:{ex.Message}。");
  922. }
  923. finally
  924. {
  925. Dispatcher.Invoke(() => { Application.Current.MainWindow.IsEnabled = true; });
  926. }
  927. });
  928. }
  929. }
  930. private void OnExportTotalBadReportClick(object sender, RoutedEventArgs e)
  931. {
  932. Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
  933. sfd.Filter = "*.pdf|*.pdf";
  934. if (sfd.ShowDialog() == true)
  935. {
  936. CreateTotalBadReport(sfd.FileName);
  937. }
  938. }
  939. private void OnSendBadReportsClick(object sender, RoutedEventArgs e)
  940. {
  941. if (string.IsNullOrEmpty(SmtpServer.Text))
  942. {
  943. MessageBox.Show("请输入SMTP服务器地址", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  944. SmtpServer.Focus();
  945. return;
  946. }
  947. if (string.IsNullOrEmpty(SmtpAccount.Text))
  948. {
  949. MessageBox.Show("请输入发送邮件的账号", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  950. SmtpAccount.Focus();
  951. return;
  952. }
  953. if (string.IsNullOrEmpty(SmtpPassword.Password))
  954. {
  955. MessageBox.Show("请输入发送邮件账号的密码", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  956. SmtpPassword.Focus();
  957. return;
  958. }
  959. SendBadReports();
  960. }
  961. }
  962. }