星火微课系统客户端
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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. I = 0;
  78. if (t == null)
  79. {
  80. t = new DispatcherTimer();
  81. t.Tick += OnTimer;
  82. t.Interval = new TimeSpan(0, 0, 0, 1);
  83. t.IsEnabled = true;
  84. t.Start();
  85. }
  86. t.Interval = new TimeSpan(0, 0, 0, 1);
  87. tip_outer.Visibility = Visibility.Collapsed;
  88. }
  89. private System.Timers.Timer times;
  90. /// <summary>
  91. /// 打印
  92. /// </summary>
  93. /// <param name="sender"></param>
  94. /// <param name="e"></param>
  95. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  96. {
  97. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  98. {
  99. //MessageWindow.Show("打印机不能为空!");
  100. MessageWindow.Show("打印机不能为空!");
  101. return;
  102. }
  103. APP.myloading.Show();
  104. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  105. //I = 1;
  106. //APP.myloading.Show();
  107. //tip_outer.Visibility = Visibility.Visible;
  108. //Thread.Sleep(2000);
  109. //Times();
  110. //Dispatcher.Invoke(() =>
  111. //{
  112. // times = new System.Timers.Timer(100)//初始值为300
  113. // {
  114. // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  115. // };//设置执行一次(false)还是一直执行(true)
  116. // I = 0;
  117. // tip_outer.Visibility = Visibility.Visible;
  118. // times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  119. // times.Enabled = true; //启动计时器
  120. // //APP.myloading.Show();
  121. //});
  122. //string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  123. //FileToolsCommon.CreateFile(imgPath);
  124. //string pdf = imgPath + "\\101.pdf";
  125. //string tpf = imgPath + "\\102.TPF";
  126. //string msg = string.Empty;
  127. //string outPut = string.Empty;
  128. ////if(rbnSquarePoint.IsChecked==false)
  129. ////{
  130. //// pyte = 1;
  131. ////}
  132. //LatticeFileHelper.GeneratingPDF(pdf, tpf, out int pr, out msg, out outPut/*, pyte*/);
  133. //if (pr == 0)
  134. //{
  135. // //outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  136. // //APP.OutPut = outPut.Split(',');
  137. // //string []page= outPut.Split(',');
  138. // //for(int i=0;i<page.Length;i++) //增加页码编号
  139. // //{
  140. // // APP.PageDrawList[i].PageCode = page[i];
  141. // //}
  142. // //string defa = string.Empty;
  143. // //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  144. // string standardError = string.Empty;
  145. // string standardOutput = string.Empty;
  146. // int frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  147. // //for (int i=0;i< frequency;i++)
  148. // //{
  149. // LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput);
  150. // //}
  151. // if (printResult == 0)// 0为成功
  152. // {
  153. // new Thread(new ThreadStart(new Action(() =>
  154. // {
  155. // Dispatcher.Invoke(() =>
  156. // {
  157. // I = 100;
  158. // pgbProcess.Value = I * 100 / 100;
  159. // lbProcess.Content = string.Format("{0}/{1}", I, 100);
  160. // APP.myloading.Hide();
  161. // I = 0;
  162. // });
  163. // Thread.Sleep(2000);
  164. // Dispatcher.Invoke(() =>
  165. // {
  166. // //tip_outer.Visibility = Visibility.Collapsed;
  167. // MessageWindow.Show("打印成功");
  168. // });
  169. // }))).Start();
  170. // }
  171. // else
  172. // {
  173. // APP.myloading.Hide();
  174. // MessageWindow.Show(standardError);
  175. // }
  176. //}
  177. //else
  178. //{
  179. // APP.myloading.Hide();
  180. // MessageWindow.Show(msg);
  181. //}
  182. }
  183. /// <summary>
  184. /// 打印-开始
  185. /// </summary>
  186. /// <returns></returns>
  187. private object InvokeServering()
  188. {
  189. Dispatcher.Invoke(() =>
  190. {
  191. I = 1;
  192. pgbProcess.Value = I * 100 / 100;
  193. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  194. tip_outer.Visibility = Visibility.Visible;
  195. //I = 0;
  196. });
  197. Thread.Sleep(2000);
  198. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  199. FileToolsCommon.CreateFile(imgPath);
  200. string pdf = imgPath + "\\101.pdf";
  201. string tpf = imgPath + "\\102.TPF";
  202. string msg = string.Empty;
  203. string outPut = string.Empty;
  204. //if(rbnSquarePoint.IsChecked==false)
  205. //{
  206. // pyte = 1;
  207. //}
  208. LatticeFileHelper.GeneratingPDF(pdf, tpf, out int pr, out msg, out outPut/*, pyte*/);
  209. if (pr == 0)
  210. {
  211. //outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  212. //APP.OutPut = outPut.Split(',');
  213. //string []page= outPut.Split(',');
  214. //for(int i=0;i<page.Length;i++) //增加页码编号
  215. //{
  216. // APP.PageDrawList[i].PageCode = page[i];
  217. //}
  218. //string defa = string.Empty;
  219. //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  220. string standardError = string.Empty;
  221. string standardOutput = string.Empty;
  222. int frequency = 1;
  223. Dispatcher.Invoke(() =>
  224. {
  225. frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  226. LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput);
  227. if (printResult == 0)// 0为成功
  228. {
  229. new Thread(new ThreadStart(new Action(() =>
  230. {
  231. Dispatcher.Invoke(() =>
  232. {
  233. I = 100;
  234. pgbProcess.Value = I * 100 / 100;
  235. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  236. APP.myloading.Hide();
  237. I = 0;
  238. });
  239. Thread.Sleep(3000);
  240. Dispatcher.Invoke(() =>
  241. {
  242. tip_outer.Visibility = Visibility.Collapsed;
  243. //tip_outer.Visibility = Visibility.Collapsed;
  244. MessageWindow.Show("打印成功");
  245. });
  246. }))).Start();
  247. }
  248. else
  249. {
  250. APP.myloading.Hide();
  251. MessageWindow.Show(standardError);
  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. APP.myloading.Hide();
  269. }
  270. /// <summary>
  271. /// 时钟回调
  272. /// </summary>
  273. /// <param name="sender"></param>
  274. /// <param name="e"></param>
  275. private void OnTimer(object sender, EventArgs e)
  276. {
  277. switch (_state)
  278. {
  279. case State.Start:
  280. {
  281. _timeSpan += new TimeSpan(0, 0, 0, 1);
  282. }
  283. break;
  284. case State.Pause:
  285. {
  286. }
  287. break;
  288. case State.End:
  289. {
  290. _timeSpan = new TimeSpan();
  291. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  292. }
  293. break;
  294. }
  295. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  296. if(I < 90 && I != 0)
  297. {
  298. Dispatcher.Invoke(() =>
  299. {
  300. pgbProcess.Value = I * 100 / 100;
  301. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  302. if (I == 1)
  303. {
  304. I = 30;
  305. }
  306. else
  307. {
  308. I += 30;
  309. }
  310. });
  311. }
  312. }
  313. private void Times()
  314. {
  315. Dispatcher.Invoke(() =>
  316. {
  317. while (I <= 90&&I!=0)
  318. {
  319. pgbProcess.Value = I * 100 / 100;
  320. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  321. Thread.Sleep(100);
  322. I++;
  323. }
  324. });
  325. }
  326. private int I = 0;
  327. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  328. {
  329. Dispatcher.Invoke(() =>
  330. {
  331. if (I <= 90)
  332. {
  333. try
  334. {
  335. pgbProcess.Value = I * 100 / 100;
  336. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  337. I++;
  338. }
  339. catch (Exception ex)
  340. {
  341. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  342. }
  343. }
  344. });
  345. }
  346. /// <summary>
  347. /// 窗口移动
  348. /// </summary>
  349. /// <param name="sender"></param>
  350. /// <param name="e"></param>
  351. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  352. {
  353. DragMove();
  354. }
  355. /// <summary>
  356. /// 关闭
  357. /// </summary>
  358. /// <param name="sender"></param>
  359. /// <param name="e"></param>
  360. private void BtnClose_Click(object sender, RoutedEventArgs e)
  361. {
  362. Hide();
  363. }
  364. /// <summary>
  365. /// 减
  366. /// </summary>
  367. /// <param name="sender"></param>
  368. /// <param name="e"></param>
  369. private void BtnLess_Click(object sender, RoutedEventArgs e)
  370. {
  371. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  372. if (num > 1)
  373. {
  374. num = num - 1;
  375. txbNumberOfCopies.Text = num.ToString();
  376. }
  377. }
  378. /// <summary>
  379. /// 新增
  380. /// </summary>
  381. /// <param name="sender"></param>
  382. /// <param name="e"></param>
  383. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  384. {
  385. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  386. if (num > 0)
  387. {
  388. num = num + 1;
  389. txbNumberOfCopies.Text = num.ToString();
  390. }
  391. }
  392. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  393. {
  394. }
  395. }
  396. }