You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
238 lines
9.6 KiB
238 lines
9.6 KiB
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;
|
|
|
|
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");
|
|
|
|
TEXT_Print.IsChecked = Printer;
|
|
cbxPrinter.IsEnabled = Printer;
|
|
|
|
TEXT_Print2.IsChecked = Printer2;
|
|
cbxPrinter2.IsEnabled = Printer2;
|
|
|
|
TEXT_Print3.IsChecked = Printer3;
|
|
cbxPrinter3.IsEnabled = Printer3;
|
|
}
|
|
|
|
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());
|
|
|
|
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(Print_path.Text))
|
|
{
|
|
System.Windows.MessageBox.Show("模板不能为空");
|
|
return;
|
|
}
|
|
var data = this.CreateBillData();
|
|
if (!data.Item1)
|
|
{
|
|
System.Windows.MessageBox.Show("模拟数据生成错误");
|
|
return;
|
|
}
|
|
|
|
var tuple = PrintHelper.Design(Print_path.Text, data.Item2, data.Item3);
|
|
if (!tuple.Item1)
|
|
{
|
|
System.Windows.MessageBox.Show($"打开设计器失败:{tuple.Item2}");
|
|
}
|
|
}
|
|
|
|
private void Button_Click_12(object sender, RoutedEventArgs e) //编辑模板
|
|
{
|
|
if (string.IsNullOrEmpty(Print_path.Text))
|
|
{
|
|
System.Windows.MessageBox.Show("模板不能为空");
|
|
return;
|
|
}
|
|
var data = this.CreateBillData();
|
|
if (!data.Item1)
|
|
{
|
|
System.Windows.MessageBox.Show("模拟数据生成错误");
|
|
return;
|
|
}
|
|
|
|
var tuple = PrintHelper.Design(Print_path2.Text, data.Item2, data.Item3);
|
|
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 Tuple<bool, Dictionary<string, object>, DataSet> CreateBillData()
|
|
{
|
|
//注意事项
|
|
//小票动态数据会变化,小票的长度也会动态改变
|
|
//这里主要演示下 动态数据源 为了动态拉伸,除了传入数据源,在模板上面code部分需要加代码
|
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
|
dic.Add("billNo", "2018111100002222");
|
|
dic.Add("optorName", "管理员");
|
|
|
|
//组装dataset数据源
|
|
DataTable dtDetail = new DataTable("dtDetail");
|
|
dtDetail.Columns.Add("GOODSCODE");
|
|
dtDetail.Columns.Add("GOODSNAME");
|
|
dtDetail.Columns.Add("GOODSPRICE");
|
|
dtDetail.Columns.Add("GOODSCOUNT");
|
|
dtDetail.Columns.Add("PAYSUM");
|
|
|
|
//加10种商品
|
|
for (int i = 1; i <= 10; i++)
|
|
{
|
|
dtDetail.Rows.Add("10000" + 1, "测试商品" + i, 10.00m, 5, 50.00m);
|
|
}
|
|
|
|
|
|
DataSet dsFrx = new DataSet();
|
|
dsFrx.Tables.Add(dtDetail);
|
|
|
|
return new Tuple<bool, Dictionary<string, object>, DataSet>(true, dic, dsFrx);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|