using Common.system; using System; using System.Collections.Generic; using System.Data; using System.Threading; using System.Windows; using System.Windows.Input; using System.Windows.Media.Imaging; using System.Windows.Threading; namespace XHWK.WKTool { /// /// 打印 /// public partial class PrintWindow : Window { /// /// 下拉框数据源 /// public DataTable data = new DataTable(); private DataTable dtComponentsUniqueNo; /// /// 计时器状态 /// private enum State { Start, Pause, End } private DispatcherTimer t = null; /// /// 状态 /// private State _state = State.End; /// /// 计时用 /// private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0); public PrintWindow() { InitializeComponent(); double proportion = 1036.0 / 1290.0; double Widths = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right); double Heights = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom); Width = Widths / 1.42; Height = Heights / 1.71; GridContent.Width = Width+5; GridContent.Height = Height; this.ResizeMode = ResizeMode.NoResize; string defa = string.Empty; List 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)); } else { imgPri.Source = null; } I = 0; if (t == null) { t = new DispatcherTimer(); t.Tick += OnTimer; t.Interval = new TimeSpan(0, 0, 0, 1); t.IsEnabled = true; t.Start(); } t.Interval = new TimeSpan(0, 0, 0, 1); tip_outer.Visibility = Visibility.Collapsed; } private System.Timers.Timer times; /// /// 打印 /// /// /// private void BtnPrint_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(cmbClass.Text)) { //MessageWindow.Show("打印机不能为空!"); MessageWindow.Show("打印机不能为空!"); return; } APP.myloading.Show(); APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate); //I = 1; //APP.myloading.Show(); //tip_outer.Visibility = Visibility.Visible; //Thread.Sleep(2000); //Times(); //Dispatcher.Invoke(() => //{ // times = new System.Timers.Timer(100)//初始值为300 // { // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件 // };//设置执行一次(false)还是一直执行(true) // I = 0; // tip_outer.Visibility = Visibility.Visible; // times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed); // times.Enabled = true; //启动计时器 // //APP.myloading.Show(); //}); //string imgPath = FileToolsCommon.GetFileAbsolutePath("temp"); //FileToolsCommon.CreateFile(imgPath); //string pdf = imgPath + "\\101.pdf"; //string tpf = imgPath + "\\102.TPF"; //string msg = string.Empty; //string outPut = string.Empty; ////if(rbnSquarePoint.IsChecked==false) ////{ //// pyte = 1; ////} //LatticeFileHelper.GeneratingPDF(pdf, tpf, out int 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 defaList = LatticeFileHelper.GetPrinterList(out defa); // string standardError = string.Empty; // string standardOutput = string.Empty; // int frequency = Convert.ToInt32(txbNumberOfCopies.Text); // //for (int i=0;i< frequency;i++) // //{ // LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput); // //} // if (printResult == 0)// 0为成功 // { // new Thread(new ThreadStart(new Action(() => // { // Dispatcher.Invoke(() => // { // I = 100; // pgbProcess.Value = I * 100 / 100; // lbProcess.Content = string.Format("{0}/{1}", I, 100); // APP.myloading.Hide(); // I = 0; // }); // Thread.Sleep(2000); // Dispatcher.Invoke(() => // { // //tip_outer.Visibility = Visibility.Collapsed; // MessageWindow.Show("打印成功"); // }); // }))).Start(); // } // else // { // APP.myloading.Hide(); // MessageWindow.Show(standardError); // } //} //else //{ // APP.myloading.Hide(); // MessageWindow.Show(msg); //} } /// /// 打印-开始 /// /// private object InvokeServering() { Dispatcher.Invoke(() => { I = 1; pgbProcess.Value = I * 100 / 100; lbProcess.Content = string.Format("{0}/{1}", I, 100); tip_outer.Visibility = Visibility.Visible; //I = 0; }); Thread.Sleep(2000); string imgPath = FileToolsCommon.GetFileAbsolutePath("temp"); FileToolsCommon.CreateFile(imgPath); string pdf = imgPath + "\\101.pdf"; string tpf = imgPath + "\\102.TPF"; string msg = string.Empty; string outPut = string.Empty; //if(rbnSquarePoint.IsChecked==false) //{ // pyte = 1; //} LatticeFileHelper.GeneratingPDF(pdf, tpf, out int 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 defaList = LatticeFileHelper.GetPrinterList(out defa); string standardError = string.Empty; string standardOutput = string.Empty; int frequency = 1; Dispatcher.Invoke(() => { frequency = Convert.ToInt32(txbNumberOfCopies.Text); LatticeFileHelper.PrinterTPFFile(tpf, frequency, cmbClass.Text, out int printResult, out standardError, out standardOutput); if (printResult == 0)// 0为成功 { new Thread(new ThreadStart(new Action(() => { Dispatcher.Invoke(() => { I = 100; pgbProcess.Value = I * 100 / 100; lbProcess.Content = string.Format("{0}/{1}", I, 100); APP.myloading.Hide(); I = 0; }); Thread.Sleep(3000); Dispatcher.Invoke(() => { tip_outer.Visibility = Visibility.Collapsed; //tip_outer.Visibility = Visibility.Collapsed; MessageWindow.Show("打印成功"); }); }))).Start(); } else { APP.myloading.Hide(); MessageWindow.Show(standardError); } }); } else { APP.myloading.Hide(); MessageWindow.Show(msg); } return ""; } /// /// 打印-结束 /// /// public void InvokeServerCompate(object obj) { APP.myloading.Hide(); } /// /// 时钟回调 /// /// /// private void OnTimer(object sender, EventArgs e) { switch (_state) { case State.Start: { _timeSpan += new TimeSpan(0, 0, 0, 1); } break; case State.Pause: { } break; case State.End: { _timeSpan = new TimeSpan(); //_timeSpan = new TimeSpan(0, 23, 12, 45, 54); } break; } string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds); if(I < 90 && I != 0) { Dispatcher.Invoke(() => { pgbProcess.Value = I * 100 / 100; lbProcess.Content = string.Format("{0}/{1}", I, 100); if (I == 1) { I = 30; } else { I += 30; } }); } } private void Times() { Dispatcher.Invoke(() => { while (I <= 90&&I!=0) { pgbProcess.Value = I * 100 / 100; lbProcess.Content = string.Format("{0}/{1}", I, 100); Thread.Sleep(100); I++; } }); } private int I = 0; private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Dispatcher.Invoke(() => { if (I <= 90) { try { pgbProcess.Value = I * 100 / 100; lbProcess.Content = string.Format("{0}/{1}", I, 100); I++; } catch (Exception ex) { LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex); } } }); } /// /// 窗口移动 /// /// /// private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragMove(); } /// /// 关闭 /// /// /// private void BtnClose_Click(object sender, RoutedEventArgs e) { Hide(); } /// /// 减 /// /// /// private void BtnLess_Click(object sender, RoutedEventArgs e) { int num = Convert.ToInt32(txbNumberOfCopies.Text); if (num > 1) { num = num - 1; txbNumberOfCopies.Text = num.ToString(); } } /// /// 新增 /// /// /// private void BtnAdd_Click(object sender, RoutedEventArgs e) { int num = Convert.ToInt32(txbNumberOfCopies.Text); if (num > 0) { num = num + 1; txbNumberOfCopies.Text = num.ToString(); } } private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e) { } } }