123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using Common.system;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 打印
- /// </summary>
- public partial class PrintWindow : Window
- {
- /// <summary>
- /// 下拉框数据源
- /// </summary>
- public DataTable data = new DataTable();
- private DataTable dtComponentsUniqueNo;
- public PrintWindow()
- {
- InitializeComponent();
- string defa = string.Empty;
- List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
- if(defaList.Count>0)
- {
- data.Columns.Add("Value");
- data.Columns.Add("Key");
- for (int i = 0; i < defaList.Count; i++)
- {
- //创建一行
- DataRow row = data.NewRow();
- //将此行添加到table中
- data.Rows.Add(row);
- data.Rows[i]["Value"] = defaList[i];
- data.Rows[i]["Key"] = i.ToString();
- }
- dtComponentsUniqueNo = data.DefaultView.ToTable();
- cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
- cmbClass.SelectedIndex = 0;
- }
- }
- public void Initialize(string _imgPath)
- {
- if(!string.IsNullOrWhiteSpace(_imgPath))
- {
- imgPri.Source = new BitmapImage(new Uri(_imgPath));
- }
- }
- /// <summary>
- /// 打印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPrint_Click(object sender, RoutedEventArgs e)
- {
- if(string.IsNullOrWhiteSpace(cmbClass.Text))
- {
- //MessageBox.Show("打印机不能为空!");
- System.Windows.Forms.MessageBox.Show("打印机不能为空!", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
- return;
- }
- string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
- FileToolsCommon.CreateFile(imgPath);
- string pdf = imgPath + "\\101.pdf";
- string tpf = imgPath + "\\102.TPF";
- int pr = 1;
- string msg = string.Empty;
- string outPut = string.Empty;
- int pyte = 0; //0为方点 1为圆点
- if(rbnSquarePoint.IsChecked==false)
- {
- pyte = 1;
- }
- LatticeFileHelper.GeneratingPDF(pdf, tpf, out pr, out msg, out outPut, pyte);
- if (pr == 0)
- {
- outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
- APP.OutPut = outPut.Split(',');
- string []page= outPut.Split(',');
- for(int i=0;i<page.Length;i++) //增加页码编号
- {
- APP.PageDrawList[i].PageCode = page[i];
- }
-
- //string defa = string.Empty;
- //List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
-
- int printResult = 1;
- string standardError = string.Empty;
- string standardOutput = string.Empty;
- int frequency = Convert.ToInt32(txbNumberOfCopies.Text);
- for (int i=0;i< frequency;i++)
- {
- LatticeFileHelper.PrinterTPFFile(tpf, 1, cmbClass.Text, out printResult, out standardError, out standardOutput);
- }
- if(printResult==0)// 0为成功
- {
- //MessageBox.Show("打印成功!");
- System.Windows.Forms.MessageBox.Show("打印成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
- }
- else
- {
- System.Windows.Forms.MessageBox.Show(standardError, "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
- //MessageBox.Show(standardError);
- }
- }
- else
- {
- System.Windows.Forms.MessageBox.Show(msg, "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
- }
- }
- /// <summary>
- /// 窗口移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnClose_Click(object sender, RoutedEventArgs e)
- {
- this.Hide();
- }
- /// <summary>
- /// 减
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnLess_Click(object sender, RoutedEventArgs e)
- {
- int num = Convert.ToInt32(txbNumberOfCopies.Text);
- if(num>1)
- {
- num = num - 1;
- txbNumberOfCopies.Text = num.ToString();
- }
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- int num = Convert.ToInt32(txbNumberOfCopies.Text);
- if (num > 0)
- {
- num = num + 1;
- txbNumberOfCopies.Text = num.ToString();
- }
- }
- }
- }
|