星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

PrintWindow.xaml.cs 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. string defa = string.Empty;
  44. List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  45. if (defaList.Count > 0)
  46. {
  47. data.Columns.Add("Value");
  48. data.Columns.Add("Key");
  49. for (int i = 0; i < defaList.Count; i++)
  50. {
  51. //创建一行
  52. DataRow row = data.NewRow();
  53. //将此行添加到table中
  54. data.Rows.Add(row);
  55. data.Rows[i]["Value"] = defaList[i];
  56. data.Rows[i]["Key"] = i.ToString();
  57. }
  58. dtComponentsUniqueNo = data.DefaultView.ToTable();
  59. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  60. cmbClass.SelectedIndex = 0;
  61. }
  62. }
  63. public void Initialize(string _imgPath)
  64. {
  65. if (!string.IsNullOrWhiteSpace(_imgPath))
  66. {
  67. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  68. }
  69. I = 0;
  70. if (t == null)
  71. {
  72. t = new DispatcherTimer();
  73. t.Tick += OnTimer;
  74. t.Interval = new TimeSpan(0, 0, 0, 1);
  75. t.IsEnabled = true;
  76. t.Start();
  77. }
  78. t.Interval = new TimeSpan(0, 0, 0, 1);
  79. tip_outer.Visibility = Visibility.Collapsed;
  80. }
  81. private System.Timers.Timer times;
  82. /// <summary>
  83. /// 打印
  84. /// </summary>
  85. /// <param name="sender"></param>
  86. /// <param name="e"></param>
  87. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  88. {
  89. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  90. {
  91. //MessageWindow.Show("打印机不能为空!");
  92. MessageWindow.Show("打印机不能为空!");
  93. return;
  94. }
  95. I = 1;
  96. APP.myloading.Show();
  97. tip_outer.Visibility = Visibility.Visible;
  98. Thread.Sleep(2000);
  99. //Times();
  100. //Dispatcher.Invoke(() =>
  101. //{
  102. // times = new System.Timers.Timer(100)//初始值为300
  103. // {
  104. // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  105. // };//设置执行一次(false)还是一直执行(true)
  106. // I = 0;
  107. // tip_outer.Visibility = Visibility.Visible;
  108. // times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  109. // times.Enabled = true; //启动计时器
  110. // //APP.myloading.Show();
  111. //});
  112. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  113. FileToolsCommon.CreateFile(imgPath);
  114. string pdf = imgPath + "\\101.pdf";
  115. string tpf = imgPath + "\\102.TPF";
  116. string msg = string.Empty;
  117. string outPut = string.Empty;
  118. //if(rbnSquarePoint.IsChecked==false)
  119. //{
  120. // pyte = 1;
  121. //}
  122. LatticeFileHelper.GeneratingPDF(pdf, tpf, out int pr, out msg, out outPut/*, pyte*/);
  123. if (pr == 0)
  124. {
  125. //outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  126. //APP.OutPut = outPut.Split(',');
  127. //string []page= outPut.Split(',');
  128. //for(int i=0;i<page.Length;i++) //增加页码编号
  129. //{
  130. // APP.PageDrawList[i].PageCode = page[i];
  131. //}
  132. //string defa = string.Empty;
  133. //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  134. string standardError = string.Empty;
  135. string standardOutput = string.Empty;
  136. int frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  137. //for (int i=0;i< frequency;i++)
  138. //{
  139. LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput);
  140. //}
  141. if (printResult == 0)// 0为成功
  142. {
  143. new Thread(new ThreadStart(new Action(() =>
  144. {
  145. Dispatcher.Invoke(() =>
  146. {
  147. I = 100;
  148. pgbProcess.Value = I * 100 / 100;
  149. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  150. APP.myloading.Hide();
  151. I = 0;
  152. });
  153. Thread.Sleep(2000);
  154. Dispatcher.Invoke(() =>
  155. {
  156. //tip_outer.Visibility = Visibility.Collapsed;
  157. MessageWindow.Show("打印成功");
  158. });
  159. }))).Start();
  160. }
  161. else
  162. {
  163. APP.myloading.Hide();
  164. MessageWindow.Show(standardError);
  165. }
  166. }
  167. else
  168. {
  169. APP.myloading.Hide();
  170. MessageWindow.Show(msg);
  171. }
  172. }
  173. /// <summary>
  174. /// 时钟回调
  175. /// </summary>
  176. /// <param name="sender"></param>
  177. /// <param name="e"></param>
  178. private void OnTimer(object sender, EventArgs e)
  179. {
  180. switch (_state)
  181. {
  182. case State.Start:
  183. {
  184. _timeSpan += new TimeSpan(0, 0, 0, 1);
  185. }
  186. break;
  187. case State.Pause:
  188. {
  189. }
  190. break;
  191. case State.End:
  192. {
  193. _timeSpan = new TimeSpan();
  194. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  195. }
  196. break;
  197. }
  198. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  199. if(I <= 90 && I != 0)
  200. {
  201. Dispatcher.Invoke(() =>
  202. {
  203. pgbProcess.Value = I * 100 / 100;
  204. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  205. I++;
  206. });
  207. }
  208. }
  209. private void Times()
  210. {
  211. Dispatcher.Invoke(() =>
  212. {
  213. while (I <= 90&&I!=0)
  214. {
  215. pgbProcess.Value = I * 100 / 100;
  216. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  217. Thread.Sleep(100);
  218. I++;
  219. }
  220. });
  221. }
  222. private int I = 0;
  223. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  224. {
  225. Dispatcher.Invoke(() =>
  226. {
  227. if (I <= 90)
  228. {
  229. try
  230. {
  231. pgbProcess.Value = I * 100 / 100;
  232. lbProcess.Content = string.Format("{0}/{1}", I, 100);
  233. I++;
  234. }
  235. catch (Exception ex)
  236. {
  237. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  238. }
  239. }
  240. });
  241. }
  242. /// <summary>
  243. /// 窗口移动
  244. /// </summary>
  245. /// <param name="sender"></param>
  246. /// <param name="e"></param>
  247. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  248. {
  249. DragMove();
  250. }
  251. /// <summary>
  252. /// 关闭
  253. /// </summary>
  254. /// <param name="sender"></param>
  255. /// <param name="e"></param>
  256. private void BtnClose_Click(object sender, RoutedEventArgs e)
  257. {
  258. Hide();
  259. }
  260. /// <summary>
  261. /// 减
  262. /// </summary>
  263. /// <param name="sender"></param>
  264. /// <param name="e"></param>
  265. private void BtnLess_Click(object sender, RoutedEventArgs e)
  266. {
  267. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  268. if (num > 1)
  269. {
  270. num = num - 1;
  271. txbNumberOfCopies.Text = num.ToString();
  272. }
  273. }
  274. /// <summary>
  275. /// 新增
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  280. {
  281. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  282. if (num > 0)
  283. {
  284. num = num + 1;
  285. txbNumberOfCopies.Text = num.ToString();
  286. }
  287. }
  288. }
  289. }