忱 沈 2 years ago
committed by sc
parent
commit
d68355c547
  1. 23
      Windows/Print.xaml
  2. 98
      Windows/Print.xaml.cs

23
Windows/Print.xaml

@ -17,5 +17,28 @@
<Button Content="预览模板" HorizontalAlignment="Left" Height="20" Margin="375,65,0,0" VerticalAlignment="Top" Width="70" Background="#FFF9F9F9" Click="Button_Click_2"/>
<Button Content="编辑模板" HorizontalAlignment="Left" Height="20" Margin="295,65,0,0" VerticalAlignment="Top" Width="70" Background="#FFF9F9F9" Click="Button_Click_1"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="20,105,0,0" TextWrapping="Wrap" Text="发布至其它目标打印机" VerticalAlignment="Top" Width="200" FontSize="20"/>
<TextBlock HorizontalAlignment="Left" Height="20" Margin="20,135,0,0" TextWrapping="Wrap" Text="打印模板:" VerticalAlignment="Top" Width="70" FontSize="16"/>
<TextBox x:Name="Print_path2" HorizontalAlignment="Left" Height="20" Margin="90,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="285"/>
<Button Content="浏览路径" HorizontalAlignment="Left" Height="20" Margin="375,135,0,0" VerticalAlignment="Top" Width="70" Background="#FFF9F9F9" Click="Button_Click1"/>
<CheckBox HorizontalAlignment="Left" Height="15" Margin="20,170,0,0" Content="同步推送:" VerticalAlignment="Top" Width="90"
x:Name="TEXT_Print2" Checked="Print_Checked2" Unchecked="Print_Checked2"/>
<ComboBox HorizontalAlignment="Left" Height="20" Margin="110,165,0,0" VerticalAlignment="Top" Width="180"
x:Name="cbxPrinter2" SelectedValuePath="Element[OPTIONCODE].Value" DisplayMemberPath="Element[OPTIONNAME].Value"/>
<CheckBox HorizontalAlignment="Left" Height="15" Margin="20,195,0,0" Content="同步推送:" VerticalAlignment="Top" Width="90"
x:Name="TEXT_Print3" Checked="Print_Checked3" Unchecked="Print_Checked3"/>
<ComboBox HorizontalAlignment="Left" Height="20" Margin="110,190,0,0" VerticalAlignment="Top" Width="180"
x:Name="cbxPrinter3" SelectedValuePath="Element[OPTIONCODE].Value" DisplayMemberPath="Element[OPTIONNAME].Value"/>
<CheckBox HorizontalAlignment="Left" Height="15" Margin="20,220,0,0" Content="同步推送:" VerticalAlignment="Top" Width="90"
x:Name="TEXT_Print4" Checked="Print_Checked4" Unchecked="Print_Checked4"/>
<ComboBox HorizontalAlignment="Left" Height="20" Margin="110,215,0,0" VerticalAlignment="Top" Width="180"
x:Name="cbxPrinter4" SelectedValuePath="Element[OPTIONCODE].Value" DisplayMemberPath="Element[OPTIONNAME].Value"/>
<CheckBox HorizontalAlignment="Left" Height="15" Margin="20,245,0,0" Content="同步推送:" VerticalAlignment="Top" Width="90"
x:Name="TEXT_Print5" Checked="Print_Checked5" Unchecked="Print_Checked5"/>
<ComboBox HorizontalAlignment="Left" Height="20" Margin="110,240,0,0" VerticalAlignment="Top" Width="180"
x:Name="cbxPrinter5" SelectedValuePath="Element[OPTIONCODE].Value" DisplayMemberPath="Element[OPTIONNAME].Value"/>
<Button Content="预览模板" HorizontalAlignment="Left" Height="20" Margin="375,165,0,0" VerticalAlignment="Top" Width="70" Background="#FFF9F9F9" Click="Button_Click_22"/>
<Button Content="编辑模板" HorizontalAlignment="Left" Height="20" Margin="295,165,0,0" VerticalAlignment="Top" Width="70" Background="#FFF9F9F9" Click="Button_Click_12"/>
</Grid>
</Window>

98
Windows/Print.xaml.cs

@ -36,6 +36,10 @@ namespace formula_manage.Windows
WindowStartupLocation = WindowStartupLocation.CenterScreen;
InitializeComponent();
cbxPrinter.ItemsSource = this.GetLocalPrinters(); //打印机搜索
cbxPrinter2.ItemsSource = this.GetLocalPrinters();
cbxPrinter3.ItemsSource = this.GetLocalPrinters();
cbxPrinter4.ItemsSource = this.GetLocalPrinters();
cbxPrinter5.ItemsSource = this.GetLocalPrinters();
this.Closing += Window_Closing; //添加窗口关闭事件
}
@ -45,6 +49,10 @@ namespace formula_manage.Windows
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)
{
@ -52,9 +60,31 @@ namespace formula_manage.Windows
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"));
Printer4 = Boolean.Parse(Configini.IniReadvalue("PRINTER", "P6"));
Printer5 = Boolean.Parse(Configini.IniReadvalue("PRINTER", "P7"));
cbxPrinter2.SelectedValue = Configini.IniReadvalue("PRINTER", "P8"); //读配置文件
cbxPrinter3.SelectedValue = Configini.IniReadvalue("PRINTER", "P9"); //读配置文件
cbxPrinter4.SelectedValue = Configini.IniReadvalue("PRINTER", "P10"); //读配置文件
cbxPrinter5.SelectedValue = Configini.IniReadvalue("PRINTER", "P11"); //读配置文件
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;
TEXT_Print4.IsChecked = Printer4;
cbxPrinter4.IsEnabled = Printer4;
TEXT_Print5.IsChecked = Printer5;
cbxPrinter5.IsEnabled = Printer5;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
@ -64,6 +94,16 @@ namespace formula_manage.Windows
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", " P6", Printer4.ToString());
Configini.IniWritevalue("PRINTER", " P7", Printer5.ToString());
Configini.IniWritevalue("PRINTER", " P8", cbxPrinter2.SelectedValue.ToString());
Configini.IniWritevalue("PRINTER", " P9", cbxPrinter3.SelectedValue.ToString());
Configini.IniWritevalue("PRINTER", " P10", cbxPrinter4.SelectedValue.ToString());
Configini.IniWritevalue("PRINTER", " P11", cbxPrinter5.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);
@ -83,6 +123,18 @@ namespace formula_manage.Windows
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))
@ -103,15 +155,39 @@ namespace formula_manage.Windows
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");
@ -143,6 +219,26 @@ namespace formula_manage.Windows
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 void Print_Checked4(object sender, RoutedEventArgs e) //打印机是否生效
{
Printer4 = TEXT_Print4.IsChecked.GetValueOrDefault(); //打印机是否生效
cbxPrinter4.IsEnabled = Printer4; //
}
private void Print_Checked5(object sender, RoutedEventArgs e) //打印机是否生效
{
Printer5 = TEXT_Print5.IsChecked.GetValueOrDefault(); //打印机是否生效
cbxPrinter5.IsEnabled = Printer5; //
}
private List<XElement> GetLocalPrinters() //查找打印机
{

Loading…
Cancel
Save