星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PrintWindow.xaml.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. /// <summary>
  23. /// 计时器状态
  24. /// </summary>
  25. private enum State
  26. {
  27. Start,
  28. Pause,
  29. End
  30. }
  31. private DispatcherTimer t = null;
  32. /// <summary>
  33. /// 状态
  34. /// </summary>
  35. private State _state = State.End;
  36. /// <summary>
  37. /// 计时用
  38. /// </summary>
  39. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  40. public PrintWindow()
  41. {
  42. InitializeComponent();
  43. double proportion = 1036.0 / 1290.0;
  44. double Widths = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right);
  45. double Heights = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom);
  46. Width = Widths / 1.42;
  47. Height = Heights / 1.71;
  48. GridContent.Width = Width+5;
  49. GridContent.Height = Height;
  50. this.ResizeMode = ResizeMode.NoResize;
  51. string defa = string.Empty;
  52. List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  53. if (defaList.Count > 0)
  54. {
  55. data.Columns.Add("Value");
  56. data.Columns.Add("Key");
  57. for (int i = 0; i < defaList.Count; i++)
  58. {
  59. //创建一行
  60. DataRow row = data.NewRow();
  61. //将此行添加到table中
  62. data.Rows.Add(row);
  63. data.Rows[i]["Value"] = defaList[i];
  64. data.Rows[i]["Key"] = i.ToString();
  65. }
  66. dtComponentsUniqueNo = data.DefaultView.ToTable();
  67. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  68. cmbClass.SelectedIndex = 0;
  69. }
  70. }
  71. public void Initialize(string _imgPath)
  72. {
  73. if (!string.IsNullOrWhiteSpace(_imgPath))
  74. {
  75. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  76. }
  77. else
  78. {
  79. imgPri.Source = null;
  80. }
  81. I = 0;
  82. if (t == null)
  83. {
  84. t = new DispatcherTimer();
  85. t.Tick += OnTimer;
  86. t.Interval = new TimeSpan(0, 0, 0, 1);
  87. t.IsEnabled = true;
  88. t.Start();
  89. }
  90. t.Interval = new TimeSpan(0, 0, 0, 1);
  91. tip_outer.Visibility = Visibility.Collapsed;
  92. }
  93. private System.Timers.Timer times;
  94. /// <summary>
  95. /// 打印
  96. /// </summary>
  97. /// <param name="sender"></param>
  98. /// <param name="e"></param>
  99. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  100. {
  101. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  102. {
  103. //MessageWindow.Show("打印机不能为空!");
  104. MessageWindow.Show("打印机不能为空!");
  105. return;
  106. }
  107. APP.myloading.Show();
  108. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  109. //I = 1;
  110. //APP.myloading.Show();
  111. //tip_outer.Visibility = Visibility.Visible;
  112. //Thread.Sleep(2000);
  113. //Times();
  114. //Dispatcher.Invoke(() =>
  115. //{
  116. // times = new System.Timers.Timer(100)//初始值为300
  117. // {
  118. // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  119. // };//设置执行一次(false)还是一直执行(true)
  120. // I = 0;
  121. // tip_outer.Visibility = Visibility.Visible;
  122. // times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  123. // times.Enabled = true; //启动计时器
  124. // //APP.myloading.Show();
  125. //});
  126. //string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  127. //FileToolsCommon.CreateFile(imgPath);
  128. //string pdf = imgPath + "\\101.pdf";
  129. //string tpf = imgPath + "\\102.TPF";
  130. //string msg = string.Empty;
  131. //string outPut = string.Empty;
  132. ////if(rbnSquarePoint.IsChecked==false)
  133. ////{
  134. //// pyte = 1;
  135. ////}
  136. //LatticeFileHelper.GeneratingPDF(pdf, tpf, out int pr, out msg, out outPut/*, pyte*/);
  137. //if (pr == 0)
  138. //{
  139. // //outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  140. // //APP.OutPut = outPut.Split(',');
  141. // //string []page= outPut.Split(',');
  142. // //for(int i=0;i<page.Length;i++) //增加页码编号
  143. // //{
  144. // // APP.PageDrawList[i].PageCode = page[i];
  145. // //}
  146. // //string defa = string.Empty;
  147. // //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  148. // string standardError = string.Empty;
  149. // string standardOutput = string.Empty;
  150. // int frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  151. // //for (int i=0;i< frequency;i++)
  152. // //{
  153. // LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput);
  154. // //}
  155. // if (printResult == 0)// 0为成功
  156. // {
  157. // new Thread(new ThreadStart(new Action(() =>
  158. // {
  159. // Dispatcher.Invoke(() =>
  160. // {
  161. // I = 100;
  162. // pgbProcess.Value = I * 100 / 100;
  163. // lbProcess.Content = string.Format("{0}/{1}", I, 100);
  164. // APP.myloading.Hide();
  165. // I = 0;
  166. // });
  167. // Thread.Sleep(2000);
  168. // Dispatcher.Invoke(() =>
  169. // {
  170. // //tip_outer.Visibility = Visibility.Collapsed;
  171. // MessageWindow.Show("打印成功");
  172. // });
  173. // }))).Start();
  174. // }
  175. // else
  176. // {
  177. // APP.myloading.Hide();
  178. // MessageWindow.Show(standardError);
  179. // }
  180. //}
  181. //else
  182. //{
  183. // APP.myloading.Hide();
  184. // MessageWindow.Show(msg);
  185. //}
  186. }
  187. /// <summary>
  188. /// 打印-开始
  189. /// </summary>
  190. /// <returns></returns>
  191. private object InvokeServering()
  192. {
  193. Dispatcher.Invoke(() =>
  194. {
  195. I = 1;
  196. pgbProcess.Value = I * 100 / 100;
  197. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  198. tip_outer.Visibility = Visibility.Visible;
  199. //I = 0;
  200. });
  201. Thread.Sleep(2000);
  202. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  203. FileToolsCommon.CreateFile(imgPath);
  204. string pdf = imgPath + "\\101.pdf";
  205. string tpf = imgPath + "\\102.TPF";
  206. string msg = string.Empty;
  207. string outPut = string.Empty;
  208. //if(rbnSquarePoint.IsChecked==false)
  209. //{
  210. // pyte = 1;
  211. //}
  212. LatticeFileHelper.GeneratingPDF(pdf, tpf, out int pr, out msg, out outPut/*, pyte*/);
  213. if (pr == 0)
  214. {
  215. //outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  216. //APP.OutPut = outPut.Split(',');
  217. //string []page= outPut.Split(',');
  218. //for(int i=0;i<page.Length;i++) //增加页码编号
  219. //{
  220. // APP.PageDrawList[i].PageCode = page[i];
  221. //}
  222. //string defa = string.Empty;
  223. //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  224. string standardError = string.Empty;
  225. string standardOutput = string.Empty;
  226. int frequency = 1;
  227. Dispatcher.Invoke(() =>
  228. {
  229. frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  230. LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput);
  231. if (printResult == 0)// 0为成功
  232. {
  233. new Thread(new ThreadStart(new Action(() =>
  234. {
  235. Dispatcher.Invoke(() =>
  236. {
  237. I = 100;
  238. pgbProcess.Value = I * 100 / 100;
  239. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  240. APP.myloading.Hide();
  241. I = 0;
  242. });
  243. Thread.Sleep(3000);
  244. Dispatcher.Invoke(() =>
  245. {
  246. tip_outer.Visibility = Visibility.Collapsed;
  247. //tip_outer.Visibility = Visibility.Collapsed;
  248. MessageWindow.Show("打印成功");
  249. });
  250. }))).Start();
  251. }
  252. else
  253. {
  254. APP.myloading.Hide();
  255. MessageWindow.Show(standardError);
  256. }
  257. });
  258. }
  259. else
  260. {
  261. APP.myloading.Hide();
  262. MessageWindow.Show(msg);
  263. }
  264. return "";
  265. }
  266. /// <summary>
  267. /// 打印-结束
  268. /// </summary>
  269. /// <returns></returns>
  270. public void InvokeServerCompate(object obj)
  271. {
  272. try
  273. {
  274. GC.Collect();
  275. APP.myloading.Hide();
  276. }
  277. catch (Exception)
  278. {
  279. }
  280. }
  281. /// <summary>
  282. /// 时钟回调
  283. /// </summary>
  284. /// <param name="sender"></param>
  285. /// <param name="e"></param>
  286. private void OnTimer(object sender, EventArgs e)
  287. {
  288. switch (_state)
  289. {
  290. case State.Start:
  291. {
  292. _timeSpan += new TimeSpan(0, 0, 0, 1);
  293. }
  294. break;
  295. case State.Pause:
  296. {
  297. }
  298. break;
  299. case State.End:
  300. {
  301. _timeSpan = new TimeSpan();
  302. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  303. }
  304. break;
  305. }
  306. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  307. if(I < 90 && I != 0)
  308. {
  309. Dispatcher.Invoke(() =>
  310. {
  311. pgbProcess.Value = I * 100 / 100;
  312. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  313. if (I == 1)
  314. {
  315. I = 30;
  316. }
  317. else
  318. {
  319. I += 30;
  320. }
  321. });
  322. }
  323. }
  324. private void Times()
  325. {
  326. Dispatcher.Invoke(() =>
  327. {
  328. while (I <= 90&&I!=0)
  329. {
  330. pgbProcess.Value = I * 100 / 100;
  331. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  332. Thread.Sleep(100);
  333. I++;
  334. }
  335. });
  336. }
  337. private int I = 0;
  338. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  339. {
  340. Dispatcher.Invoke(() =>
  341. {
  342. if (I <= 90)
  343. {
  344. try
  345. {
  346. pgbProcess.Value = I * 100 / 100;
  347. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  348. I++;
  349. }
  350. catch (Exception ex)
  351. {
  352. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  353. }
  354. }
  355. });
  356. }
  357. /// <summary>
  358. /// 窗口移动
  359. /// </summary>
  360. /// <param name="sender"></param>
  361. /// <param name="e"></param>
  362. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  363. {
  364. DragMove();
  365. }
  366. /// <summary>
  367. /// 关闭
  368. /// </summary>
  369. /// <param name="sender"></param>
  370. /// <param name="e"></param>
  371. private void BtnClose_Click(object sender, RoutedEventArgs e)
  372. {
  373. Hide();
  374. }
  375. /// <summary>
  376. /// 减
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void BtnLess_Click(object sender, RoutedEventArgs e)
  381. {
  382. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  383. if (num > 1)
  384. {
  385. num = num - 1;
  386. txbNumberOfCopies.Text = num.ToString();
  387. }
  388. }
  389. /// <summary>
  390. /// 新增
  391. /// </summary>
  392. /// <param name="sender"></param>
  393. /// <param name="e"></param>
  394. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  395. {
  396. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  397. if (num > 0)
  398. {
  399. num = num + 1;
  400. txbNumberOfCopies.Text = num.ToString();
  401. }
  402. }
  403. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  404. {
  405. }
  406. }
  407. }