星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

PrintWindow.xaml.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Threading;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. using System.Windows.Media.Imaging;
  9. using System.Windows.Threading;
  10. namespace XHWK.WKTool
  11. {
  12. /// <summary>
  13. /// 打印
  14. /// </summary>
  15. public partial class PrintWindow : Window
  16. {
  17. /// <summary>
  18. /// 下拉框数据源
  19. /// </summary>
  20. public DataTable data = new DataTable();
  21. private DataTable dtComponentsUniqueNo;
  22. private System.Timers.Timer times;
  23. public PrintWindow()
  24. {
  25. InitializeComponent();
  26. double proportion = 1036.0 / 1290.0;
  27. double Widths = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right);
  28. double Heights = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom);
  29. Width = Widths / 1.42;
  30. Height = Heights / 1.71;
  31. GridContent.Width = Width+5;
  32. GridContent.Height = Height;
  33. this.ResizeMode = ResizeMode.NoResize;
  34. string defa = string.Empty;
  35. List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  36. if (defaList.Count > 0)
  37. {
  38. data.Columns.Add("Value");
  39. data.Columns.Add("Key");
  40. for (int i = 0; i < defaList.Count; i++)
  41. {
  42. //创建一行
  43. DataRow row = data.NewRow();
  44. //将此行添加到table中
  45. data.Rows.Add(row);
  46. data.Rows[i]["Value"] = defaList[i];
  47. data.Rows[i]["Key"] = i.ToString();
  48. }
  49. dtComponentsUniqueNo = data.DefaultView.ToTable();
  50. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  51. cmbClass.SelectedIndex = 0;
  52. }
  53. }
  54. public void Initialize(string _imgPath)
  55. {
  56. if (!string.IsNullOrWhiteSpace(_imgPath))
  57. {
  58. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  59. }
  60. else
  61. {
  62. imgPri.Source = null;
  63. }
  64. I = 0;
  65. tip_outer.Visibility = Visibility.Collapsed;
  66. }
  67. /// <summary>
  68. /// 打印
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  73. {
  74. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  75. {
  76. //MessageWindow.Show("打印机不能为空!");
  77. MessageWindow.Show("打印机不能为空!");
  78. return;
  79. }
  80. //APP.myloading.Show();
  81. btnClose.IsEnabled = false;
  82. btnPrint.IsEnabled = false;
  83. //APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  84. Thread myThread = new Thread(StartPrint);
  85. List<string> StrList = new List<string>();
  86. //string imgPath =
  87. //FileToolsCommon.CreateFile(imgPath);
  88. //string pdf = imgPath + "\\101.pdf";
  89. //PDF位置
  90. string SourcePath=FileToolsCommon.GetFileAbsolutePath("/temp/101.pdf");
  91. StrList.Add(SourcePath);
  92. //打印数量
  93. int PrinterNum = Convert.ToInt32(txbNumberOfCopies.Text);
  94. StrList.Add(PrinterNum.ToString());
  95. //打印机名称
  96. string PrinterName = cmbClass.Text;
  97. StrList.Add(PrinterName);
  98. num = 0;
  99. tip_outer.Visibility = Visibility.Visible;
  100. myThread.Start(StrList);
  101. times = new System.Timers.Timer(100);
  102. times.Elapsed += Times_ElapsedClick;
  103. times.Start();
  104. }
  105. int num = 0;
  106. /// <summary>
  107. /// 计时器
  108. /// </summary>
  109. /// <param name="sender"></param>
  110. /// <param name="e"></param>
  111. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  112. {
  113. Dispatcher.Invoke(() =>
  114. {
  115. pgbProcess.Value = num;
  116. lbProcess.Content = string.Format("{0}% / {1}%", num, 100);
  117. if (num < 99)
  118. {
  119. num++;
  120. times.Interval += (num/2);
  121. }
  122. else
  123. {
  124. times.Stop();
  125. }
  126. });
  127. }
  128. /// <summary>
  129. /// 开始打印
  130. /// </summary>
  131. void StartPrint(object obj)
  132. {
  133. List<string> objStr = (List<string>)obj;
  134. string SourcePath= objStr[0];
  135. int PrinterNum=int.Parse(objStr[1]);
  136. string PrinterName= objStr[2];
  137. //TPF文件位置
  138. string TPFPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  139. FileToolsCommon.CreateDirectory(TPFPath);
  140. TPFPath += "101.TPF";
  141. //生成点阵文件
  142. LatticeFileHelper.GeneratingPDF(SourcePath, TPFPath, out int pr, out string msg, out string outPut/*, pyte*/);
  143. while(!FileToolsCommon.IsExistFile(TPFPath))
  144. {
  145. Thread.Sleep(100);
  146. }
  147. while(string.IsNullOrWhiteSpace(pr.ToString()))
  148. {
  149. Thread.Sleep(100);
  150. }
  151. Thread.Sleep(1000);
  152. //打印
  153. LatticeFileHelper.PrinterTPFFile(TPFPath, PrinterNum, PrinterName, out int printResult, out string standardError, out string standardOutput);
  154. if (printResult == 0)
  155. {
  156. Dispatcher.Invoke(() =>
  157. {
  158. btnClose.IsEnabled = true;
  159. btnPrint.IsEnabled = true;
  160. num = 99;
  161. times.Stop();
  162. pgbProcess.Value = 100;
  163. lbProcess.Content = string.Format("{0}% / {1}%", 100, 100);
  164. MessageWindow.Show("打印成功!");
  165. tip_outer.Visibility = Visibility.Collapsed;
  166. });
  167. }
  168. else
  169. {
  170. Dispatcher.Invoke(() =>
  171. {
  172. btnClose.IsEnabled = true;
  173. btnPrint.IsEnabled = true;
  174. times.Stop();
  175. tip_outer.Visibility = Visibility.Collapsed;
  176. MessageWindow.Show(standardError);
  177. });
  178. }
  179. }
  180. /// <summary>
  181. /// 打印-开始
  182. /// </summary>
  183. /// <returns></returns>
  184. private object InvokeServering()
  185. {
  186. Dispatcher.Invoke(() =>
  187. {
  188. I = 1;
  189. pgbProcess.Value = I * 100 / 100;
  190. lbProcess.Content = string.Format("{0}% / {1}%", I, 100);
  191. tip_outer.Visibility = Visibility.Visible;
  192. //I = 0;
  193. });
  194. Thread.Sleep(2000);
  195. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  196. FileToolsCommon.CreateFile(imgPath);
  197. string pdf = imgPath + "\\101.pdf";
  198. string tpf = imgPath + "\\102.TPF";
  199. string msg = string.Empty;
  200. string outPut = string.Empty;
  201. //if(rbnSquarePoint.IsChecked==false)
  202. //{
  203. // pyte = 1;
  204. //}
  205. LatticeFileHelper.GeneratingPDF(pdf, tpf, out int pr, out msg, out outPut/*, pyte*/);
  206. if (pr == 0)
  207. {
  208. //outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  209. //APP.OutPut = outPut.Split(',');
  210. //string []page= outPut.Split(',');
  211. //for(int i=0;i<page.Length;i++) //增加页码编号
  212. //{
  213. // APP.PageDrawList[i].PageCode = page[i];
  214. //}
  215. //string defa = string.Empty;
  216. //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  217. string standardError = string.Empty;
  218. string standardOutput = string.Empty;
  219. int frequency = 1;
  220. //Dispatcher.Invoke(() =>
  221. //{
  222. frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  223. LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput);
  224. if (printResult == 0)// 0为成功
  225. {
  226. new Thread(new ThreadStart(new Action(() =>
  227. {
  228. Dispatcher.Invoke(() =>
  229. {
  230. I = 100;
  231. pgbProcess.Value = I * 100 / 100;
  232. lbProcess.Content = string.Format("{0}% / {1}%", I, 100);
  233. APP.myloading.Hide();
  234. I = 0;
  235. });
  236. Thread.Sleep(3000);
  237. Dispatcher.Invoke(() =>
  238. {
  239. tip_outer.Visibility = Visibility.Collapsed;
  240. //tip_outer.Visibility = Visibility.Collapsed;
  241. MessageWindow.Show("打印成功");
  242. });
  243. }))).Start();
  244. }
  245. else
  246. {
  247. Dispatcher.Invoke(() =>
  248. {
  249. APP.myloading.Hide();
  250. MessageWindow.Show(standardError);
  251. });
  252. }
  253. //});
  254. }
  255. else
  256. {
  257. APP.myloading.Hide();
  258. MessageWindow.Show(msg);
  259. }
  260. return "";
  261. }
  262. /// <summary>
  263. /// 打印-结束
  264. /// </summary>
  265. /// <returns></returns>
  266. public void InvokeServerCompate(object obj)
  267. {
  268. try
  269. {
  270. GC.Collect();
  271. APP.myloading.Hide();
  272. }
  273. catch (Exception)
  274. {
  275. }
  276. }
  277. private int I = 0;
  278. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  279. {
  280. Dispatcher.Invoke(() =>
  281. {
  282. if (I <= 90)
  283. {
  284. try
  285. {
  286. pgbProcess.Value = I * 100 / 100;
  287. lbProcess.Content = string.Format("{0}% / {1}%", I, 100);
  288. I++;
  289. }
  290. catch (Exception ex)
  291. {
  292. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  293. }
  294. }
  295. });
  296. }
  297. /// <summary>
  298. /// 窗口移动
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  303. {
  304. DragMove();
  305. }
  306. /// <summary>
  307. /// 关闭
  308. /// </summary>
  309. /// <param name="sender"></param>
  310. /// <param name="e"></param>
  311. private void BtnClose_Click(object sender, RoutedEventArgs e)
  312. {
  313. Hide();
  314. }
  315. /// <summary>
  316. /// 减
  317. /// </summary>
  318. /// <param name="sender"></param>
  319. /// <param name="e"></param>
  320. private void BtnLess_Click(object sender, RoutedEventArgs e)
  321. {
  322. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  323. if (num > 1)
  324. {
  325. num = num - 1;
  326. txbNumberOfCopies.Text = num.ToString();
  327. }
  328. }
  329. /// <summary>
  330. /// 新增
  331. /// </summary>
  332. /// <param name="sender"></param>
  333. /// <param name="e"></param>
  334. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  335. {
  336. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  337. if (num > 0)
  338. {
  339. num = num + 1;
  340. txbNumberOfCopies.Text = num.ToString();
  341. }
  342. }
  343. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  344. {
  345. }
  346. }
  347. }