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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. int pr = 1;
  73. string msg = string.Empty;
  74. string outPut = string.Empty;
  75. int pyte = 0; //0为方点 1为圆点
  76. if(rbnSquarePoint.IsChecked==false)
  77. {
  78. pyte = 1;
  79. }
  80. LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF", out pr, out msg, out outPut, pyte);
  81. if (pr == 0)
  82. {
  83. outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
  84. APP.OutPut = outPut.Split(',');
  85. string []page= outPut.Split(',');
  86. for(int i=0;i<page.Length;i++) //增加页码编号
  87. {
  88. APP.PageDrawList[i].PageCode = page[i];
  89. }
  90. //string defa = string.Empty;
  91. //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
  92. int printResult = 1;
  93. string standardError = string.Empty;
  94. string standardOutput = string.Empty;
  95. int frequency = Convert.ToInt32(txbNumberOfCopies.Text);
  96. for (int i=0;i< frequency;i++)
  97. {
  98. LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF", 1, cmbClass.Text, out printResult, out standardError, out standardOutput);
  99. }
  100. if(printResult==0)// 0为成功
  101. {
  102. //MessageBox.Show("打印成功!");
  103. System.Windows.Forms.MessageBox.Show("打印成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
  104. }
  105. else
  106. {
  107. System.Windows.Forms.MessageBox.Show(standardError, "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
  108. //MessageBox.Show(standardError);
  109. }
  110. }
  111. else
  112. {
  113. System.Windows.Forms.MessageBox.Show(msg, "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
  114. }
  115. }
  116. /// <summary>
  117. /// 窗口移动
  118. /// </summary>
  119. /// <param name="sender"></param>
  120. /// <param name="e"></param>
  121. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  122. {
  123. DragMove();
  124. }
  125. /// <summary>
  126. /// 关闭
  127. /// </summary>
  128. /// <param name="sender"></param>
  129. /// <param name="e"></param>
  130. private void BtnClose_Click(object sender, RoutedEventArgs e)
  131. {
  132. this.Hide();
  133. }
  134. /// <summary>
  135. /// 减
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void BtnLess_Click(object sender, RoutedEventArgs e)
  140. {
  141. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  142. if(num>1)
  143. {
  144. num = num - 1;
  145. txbNumberOfCopies.Text = num.ToString();
  146. }
  147. }
  148. /// <summary>
  149. /// 新增
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  154. {
  155. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  156. if (num > 0)
  157. {
  158. num = num + 1;
  159. txbNumberOfCopies.Text = num.ToString();
  160. }
  161. }
  162. }
  163. }