星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PrintWindow.xaml.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. APP.myloading.Hide();
  273. }
  274. /// <summary>
  275. /// 时钟回调
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void OnTimer(object sender, EventArgs e)
  280. {
  281. switch (_state)
  282. {
  283. case State.Start:
  284. {
  285. _timeSpan += new TimeSpan(0, 0, 0, 1);
  286. }
  287. break;
  288. case State.Pause:
  289. {
  290. }
  291. break;
  292. case State.End:
  293. {
  294. _timeSpan = new TimeSpan();
  295. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  296. }
  297. break;
  298. }
  299. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  300. if(I < 90 && I != 0)
  301. {
  302. Dispatcher.Invoke(() =>
  303. {
  304. pgbProcess.Value = I * 100 / 100;
  305. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  306. if (I == 1)
  307. {
  308. I = 30;
  309. }
  310. else
  311. {
  312. I += 30;
  313. }
  314. });
  315. }
  316. }
  317. private void Times()
  318. {
  319. Dispatcher.Invoke(() =>
  320. {
  321. while (I <= 90&&I!=0)
  322. {
  323. pgbProcess.Value = I * 100 / 100;
  324. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  325. Thread.Sleep(100);
  326. I++;
  327. }
  328. });
  329. }
  330. private int I = 0;
  331. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  332. {
  333. Dispatcher.Invoke(() =>
  334. {
  335. if (I <= 90)
  336. {
  337. try
  338. {
  339. pgbProcess.Value = I * 100 / 100;
  340. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  341. I++;
  342. }
  343. catch (Exception ex)
  344. {
  345. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  346. }
  347. }
  348. });
  349. }
  350. /// <summary>
  351. /// 窗口移动
  352. /// </summary>
  353. /// <param name="sender"></param>
  354. /// <param name="e"></param>
  355. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  356. {
  357. DragMove();
  358. }
  359. /// <summary>
  360. /// 关闭
  361. /// </summary>
  362. /// <param name="sender"></param>
  363. /// <param name="e"></param>
  364. private void BtnClose_Click(object sender, RoutedEventArgs e)
  365. {
  366. Hide();
  367. }
  368. /// <summary>
  369. /// 减
  370. /// </summary>
  371. /// <param name="sender"></param>
  372. /// <param name="e"></param>
  373. private void BtnLess_Click(object sender, RoutedEventArgs e)
  374. {
  375. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  376. if (num > 1)
  377. {
  378. num = num - 1;
  379. txbNumberOfCopies.Text = num.ToString();
  380. }
  381. }
  382. /// <summary>
  383. /// 新增
  384. /// </summary>
  385. /// <param name="sender"></param>
  386. /// <param name="e"></param>
  387. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  388. {
  389. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  390. if (num > 0)
  391. {
  392. num = num + 1;
  393. txbNumberOfCopies.Text = num.ToString();
  394. }
  395. }
  396. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  397. {
  398. }
  399. }
  400. }