|
|
|
|
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;
|
|
|
|
|
using ThoughtWorks.QRCode.Codec;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.Drawing.Printing;
|
|
|
|
|
using formula_manage.UserClass;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using FastReport.Format;
|
|
|
|
|
using Svg;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Media.Media3D;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace formula_manage.Windows
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Print.xaml 的交互逻辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class Print : Window
|
|
|
|
|
{
|
|
|
|
|
public Print()
|
|
|
|
|
{
|
|
|
|
|
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
cbxPrinter.ItemsSource = this.GetLocalPrinters(); //打印机搜索
|
|
|
|
|
cbxPrinter2.ItemsSource = this.GetLocalPrinters();
|
|
|
|
|
cbxPrinter3.ItemsSource = this.GetLocalPrinters();
|
|
|
|
|
this.Closing += Window_Closing; //添加窗口关闭事件
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini";
|
|
|
|
|
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
|
|
|
|
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件
|
|
|
|
|
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
|
|
|
|
|
|
|
|
|
|
bool Printer;
|
|
|
|
|
bool Printer2;
|
|
|
|
|
bool Printer3;
|
|
|
|
|
bool Printer4;
|
|
|
|
|
bool Printer5;
|
|
|
|
|
|
|
|
|
|
private void Window_Print(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
|
|
|
|
|
|
|
|
|
|
Printer = Boolean.Parse(Configini.IniReadvalue("PRINTER", "P1"));
|
|
|
|
|
cbxPrinter.SelectedValue = Configini.IniReadvalue("PRINTER", "P2"); //读配置文件
|
|
|
|
|
Print_path.Text = Configini.IniReadvalue("PRINTER", "P3");
|
|
|
|
|
Printer2 = Boolean.Parse(Configini.IniReadvalue("PRINTER", "P4"));
|
|
|
|
|
Printer3 = Boolean.Parse(Configini.IniReadvalue("PRINTER", "P5"));
|
|
|
|
|
cbxPrinter2.SelectedValue = Configini.IniReadvalue("PRINTER", "P8"); //读配置文件
|
|
|
|
|
cbxPrinter3.SelectedValue = Configini.IniReadvalue("PRINTER", "P9"); //读配置文件
|
|
|
|
|
Print_path2.Text = Configini.IniReadvalue("PRINTER", "P12");
|
|
|
|
|
Template_M.Text = Configini.IniReadvalue("PRINTER", "P13");
|
|
|
|
|
Template_S.Text = Configini.IniReadvalue("PRINTER", "P14");
|
|
|
|
|
|
|
|
|
|
TEXT_Print.IsChecked = Printer;
|
|
|
|
|
cbxPrinter.IsEnabled = Printer;
|
|
|
|
|
|
|
|
|
|
TEXT_Print2.IsChecked = Printer2;
|
|
|
|
|
cbxPrinter2.IsEnabled = Printer2;
|
|
|
|
|
|
|
|
|
|
TEXT_Print3.IsChecked = Printer3;
|
|
|
|
|
cbxPrinter3.IsEnabled = Printer3;
|
|
|
|
|
|
|
|
|
|
DirectoryInfo di_M = new DirectoryInfo(Print_path.Text); //new文件夹
|
|
|
|
|
FileInfo[] files_M = di_M.GetFiles();//加载文件夹中的文件名
|
|
|
|
|
Template_M.ItemsSource = files_M;
|
|
|
|
|
Template_M.DisplayMemberPath = "Name"; // 显示文件名
|
|
|
|
|
DirectoryInfo di_S = new DirectoryInfo(Print_path2.Text);
|
|
|
|
|
FileInfo[] files_S = di_M.GetFiles();
|
|
|
|
|
Template_S.ItemsSource = files_S;
|
|
|
|
|
Template_S.DisplayMemberPath = "Name";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
|
|
|
|
|
{
|
|
|
|
|
MessageBoxResult result = System.Windows.MessageBox.Show("设置完成后请重启程序", "提示", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel);
|
|
|
|
|
|
|
|
|
|
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P1", Printer.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P2", cbxPrinter.SelectedValue.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P3", Print_path.Text.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P4", Printer2.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P5", Printer3.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P8", cbxPrinter2.SelectedValue.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P9", cbxPrinter3.SelectedValue.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P12", Print_path2.Text.ToString());
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P13", Template_M.Text);
|
|
|
|
|
Configini.IniWritevalue("PRINTER", " P14", Template_S.Text);
|
|
|
|
|
|
|
|
|
|
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
|
|
|
|
|
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
|
|
|
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
|
|
|
|
wr.WriteLine(Log_time + "Print:Print_SET");
|
|
|
|
|
wr.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e) //路径选择按钮
|
|
|
|
|
{
|
|
|
|
|
FolderBrowserDialog Dilog = new FolderBrowserDialog();
|
|
|
|
|
Dilog.SelectedPath = Print_path.Text; //打开目录
|
|
|
|
|
Dilog.ShowNewFolderButton = false; //不显示新建文件夹按钮
|
|
|
|
|
//
|
|
|
|
|
if (Dilog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Print_path.Text = Dilog.SelectedPath; //返回选择的字符串
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void Button_Click1(object sender, RoutedEventArgs e) //路径选择按钮
|
|
|
|
|
{
|
|
|
|
|
FolderBrowserDialog Dilog = new FolderBrowserDialog();
|
|
|
|
|
Dilog.SelectedPath = Print_path2.Text; //打开目录
|
|
|
|
|
Dilog.ShowNewFolderButton = false; //不显示新建文件夹按钮
|
|
|
|
|
//
|
|
|
|
|
if (Dilog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Print_path2.Text = Dilog.SelectedPath; //返回选择的字符串
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_Click_1(object sender, RoutedEventArgs e) //编辑模板
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Template_M.Text))
|
|
|
|
|
{
|
|
|
|
|
System.Windows.MessageBox.Show("模板不能为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tuple = PrintHelper.Design(Print_path.Text+"/" + Template_M.Text);
|
|
|
|
|
if (!tuple.Item1)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.MessageBox.Show($"打开设计器失败:{tuple.Item2}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void Button_Click_12(object sender, RoutedEventArgs e) //编辑模板
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Template_S.Text))
|
|
|
|
|
{
|
|
|
|
|
System.Windows.MessageBox.Show("模板不能为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tuple = PrintHelper.Design(Print_path2.Text +"/" + Template_S.Text);
|
|
|
|
|
if (!tuple.Item1)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.MessageBox.Show($"打开设计器失败:{tuple.Item2}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_Click_2(object sender, RoutedEventArgs e) //预览模板
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void Button_Click_22(object sender, RoutedEventArgs e) //预览模板
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Print_Checked(object sender, RoutedEventArgs e) //打印机是否生效
|
|
|
|
|
{
|
|
|
|
|
Printer = TEXT_Print.IsChecked.GetValueOrDefault(); //打印机是否生效
|
|
|
|
|
cbxPrinter.IsEnabled = Printer; //
|
|
|
|
|
}
|
|
|
|
|
private void Print_Checked2(object sender, RoutedEventArgs e) //打印机是否生效
|
|
|
|
|
{
|
|
|
|
|
Printer2 = TEXT_Print2.IsChecked.GetValueOrDefault(); //打印机是否生效
|
|
|
|
|
cbxPrinter2.IsEnabled = Printer2; //
|
|
|
|
|
}
|
|
|
|
|
private void Print_Checked3(object sender, RoutedEventArgs e) //打印机是否生效
|
|
|
|
|
{
|
|
|
|
|
Printer3 = TEXT_Print3.IsChecked.GetValueOrDefault(); //打印机是否生效
|
|
|
|
|
cbxPrinter3.IsEnabled = Printer3; //
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<XElement> GetLocalPrinters() //查找打印机
|
|
|
|
|
{
|
|
|
|
|
List<XElement> list = new List<XElement>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (string fPrinterName in PrinterSettings.InstalledPrinters)
|
|
|
|
|
{
|
|
|
|
|
var xePrintName = new XElement("Item", new XElement("OPTIONNAME", fPrinterName.Trim()), new XElement("OPTIONCODE", fPrinterName.Trim()));
|
|
|
|
|
|
|
|
|
|
if (!list.Contains(xePrintName))
|
|
|
|
|
list.Add(xePrintName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|