星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PrintWindow.xaml.cs 6.2KB

4 år sedan
4 år sedan
4 år sedan
4 år sedan
4 år sedan
4 år sedan
4 år sedan
4 år sedan
4 år sedan
4 år sedan
4 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Forms;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace XHWK.WKTool
  18. {
  19. /// <summary>
  20. /// 打印
  21. /// </summary>
  22. public partial class PrintWindow : Window
  23. {
  24. /// <summary>
  25. /// 下拉框数据源
  26. /// </summary>
  27. public DataTable data = new DataTable();
  28. private DataTable dtComponentsUniqueNo;
  29. public PrintWindow()
  30. {
  31. InitializeComponent();
  32. string defa = string.Empty;
  33. List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  34. if(defaList.Count>0)
  35. {
  36. data.Columns.Add("Value");
  37. data.Columns.Add("Key");
  38. for (int i = 0; i < defaList.Count; i++)
  39. {
  40. //创建一行
  41. DataRow row = data.NewRow();
  42. //将此行添加到table中
  43. data.Rows.Add(row);
  44. data.Rows[i]["Value"] = defaList[i];
  45. data.Rows[i]["Key"] = i.ToString();
  46. }
  47. dtComponentsUniqueNo = data.DefaultView.ToTable();
  48. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  49. cmbClass.SelectedIndex = 0;
  50. }
  51. }
  52. public void Initialize(string _imgPath)
  53. {
  54. if(!string.IsNullOrWhiteSpace(_imgPath))
  55. {
  56. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  57. }
  58. }
  59. /// <summary>
  60. /// 打印
  61. /// </summary>
  62. /// <param name="sender"></param>
  63. /// <param name="e"></param>
  64. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  65. {
  66. if(string.IsNullOrWhiteSpace(cmbClass.Text))
  67. {
  68. //MessageBox.Show("打印机不能为空!");
  69. System.Windows.Forms.MessageBox.Show("打印机不能为空!", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
  70. return;
  71. }
  72. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  73. FileToolsCommon.CreateFile(imgPath);
  74. string pdf = imgPath + "\\101.pdf";
  75. string tpf = imgPath + "\\102.TPF";
  76. int pr = 1;
  77. string msg = string.Empty;
  78. string outPut = string.Empty;
  79. int pyte = 0; //0为方点 1为圆点
  80. if(rbnSquarePoint.IsChecked==false)
  81. {
  82. pyte = 1;
  83. }
  84. LatticeFileHelper.GeneratingPDF(pdf, tpf, out pr, out msg, out outPut, pyte);
  85. if (pr == 0)
  86. {
  87. outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  88. APP.OutPut = outPut.Split(',');
  89. string []page= outPut.Split(',');
  90. for(int i=0;i<page.Length;i++) //增加页码编号
  91. {
  92. APP.PageDrawList[i].PageCode = page[i];
  93. }
  94. //string defa = string.Empty;
  95. //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  96. int printResult = 1;
  97. string standardError = string.Empty;
  98. string standardOutput = string.Empty;
  99. int frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  100. for (int i=0;i< frequency;i++)
  101. {
  102. LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF", 1, cmbClass.Text, out printResult, out standardError, out standardOutput);
  103. }
  104. if(printResult==0)// 0为成功
  105. {
  106. //MessageBox.Show("打印成功!");
  107. System.Windows.Forms.MessageBox.Show("打印成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
  108. }
  109. else
  110. {
  111. System.Windows.Forms.MessageBox.Show(standardError, "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
  112. //MessageBox.Show(standardError);
  113. }
  114. }
  115. else
  116. {
  117. System.Windows.Forms.MessageBox.Show(msg, "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
  118. }
  119. }
  120. /// <summary>
  121. /// 窗口移动
  122. /// </summary>
  123. /// <param name="sender"></param>
  124. /// <param name="e"></param>
  125. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  126. {
  127. DragMove();
  128. }
  129. /// <summary>
  130. /// 关闭
  131. /// </summary>
  132. /// <param name="sender"></param>
  133. /// <param name="e"></param>
  134. private void BtnClose_Click(object sender, RoutedEventArgs e)
  135. {
  136. this.Hide();
  137. }
  138. /// <summary>
  139. /// 减
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void BtnLess_Click(object sender, RoutedEventArgs e)
  144. {
  145. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  146. if(num>1)
  147. {
  148. num = num - 1;
  149. txbNumberOfCopies.Text = num.ToString();
  150. }
  151. }
  152. /// <summary>
  153. /// 新增
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  158. {
  159. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  160. if (num > 0)
  161. {
  162. num = num + 1;
  163. txbNumberOfCopies.Text = num.ToString();
  164. }
  165. }
  166. }
  167. }