忱 沈 2 years ago
parent
commit
e35c278cb2
  1. 13
      Windows/Print.xaml
  2. 38
      Windows/Print.xaml.cs

13
Windows/Print.xaml

@ -5,14 +5,17 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:formula_manage.Windows" xmlns:local="clr-namespace:formula_manage.Windows"
mc:Ignorable="d" mc:Ignorable="d"
Title="打印设置" Height="450" Width="500" MaxWidth="500"> Title="打印设置" Height="500" Width="500" MaxWidth="500">
<Grid> <Grid>
<TextBlock HorizontalAlignment="Left" Height="20" Margin="20,35,0,0" TextWrapping="Wrap" Text="打印模板:" VerticalAlignment="Top" Width="70" FontSize="16"/> <TextBlock HorizontalAlignment="Left" Height="20" Margin="20,35,0,0" TextWrapping="Wrap" Text="打印模板:" VerticalAlignment="Top" Width="70" FontSize="16"/>
<TextBox x:Name="Print_path" HorizontalAlignment="Left" Height="20" Margin="90,35,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="285"/> <TextBox x:Name="Print_path" HorizontalAlignment="Left" Height="20" Margin="90,35,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="285"/>
<Button x:Name="Print_path_select" Content="浏览路径" HorizontalAlignment="Left" Height="20" Margin="375,35,0,0" VerticalAlignment="Top" Width="70" Background="#FFF9F9F9" Click="Button_Click"/> <Button Content="浏览路径" HorizontalAlignment="Left" Height="20" Margin="375,35,0,0" VerticalAlignment="Top" Width="70" Background="#FFF9F9F9" Click="Button_Click"/>
<CheckBox HorizontalAlignment="Left" Height="15" Margin="20,60,0,0" Content="默认打印机:" VerticalAlignment="Top" Width="110"/> <CheckBox HorizontalAlignment="Left" Height="15" Margin="20,70,0,0" Content="默认打印机:" VerticalAlignment="Top" Width="90"
<Button Content="编辑模板" HorizontalAlignment="Right" Height="20" Margin="0,60,150,0" VerticalAlignment="Top" Width="85" Background="#FFE6E6E6" Click="Button_Click_1"/> x:Name="TEXT_Print" Checked="Print_Checked" Unchecked="Print_Checked"/>
<Button Content="预览" HorizontalAlignment="Right" Height="20" Margin="0,60,50,0" VerticalAlignment="Top" Width="85" Background="#FFE6E6E6" Click="Button_Click_2"/> <ComboBox HorizontalAlignment="Left" Height="20" Margin="110,65,0,0" VerticalAlignment="Top" Width="180"
x:Name="cbxPrinter" SelectedValuePath="Element[OPTIONCODE].Value" DisplayMemberPath="Element[OPTIONNAME].Value"/>
<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"/>
</Grid> </Grid>
</Window> </Window>

38
Windows/Print.xaml.cs

@ -18,6 +18,7 @@ using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Drawing.Printing; using System.Drawing.Printing;
using formula_manage.UserClass; using formula_manage.UserClass;
using System.Xml.Linq;
namespace formula_manage.Windows namespace formula_manage.Windows
{ {
@ -30,8 +31,11 @@ namespace formula_manage.Windows
{ {
WindowStartupLocation = WindowStartupLocation.CenterScreen; WindowStartupLocation = WindowStartupLocation.CenterScreen;
InitializeComponent(); InitializeComponent();
cbxPrinter.ItemsSource = this.GetLocalPrinters();
} }
bool Printer;
private void Button_Click(object sender, RoutedEventArgs e) //SQL_DISPEN_bak路径选择按钮 private void Button_Click(object sender, RoutedEventArgs e) //SQL_DISPEN_bak路径选择按钮
{ {
FolderBrowserDialog Dilog = new FolderBrowserDialog(); FolderBrowserDialog Dilog = new FolderBrowserDialog();
@ -43,13 +47,13 @@ namespace formula_manage.Windows
Print_path.Text = Dilog.SelectedPath; //返回选择的字符串 Print_path.Text = Dilog.SelectedPath; //返回选择的字符串
} }
} }
private void Button_Click_1(object sender, RoutedEventArgs e) //SQL_DISPEN_bak路径选择按钮 private void Button_Click_1(object sender, RoutedEventArgs e) //编辑模板
{ {
if (string.IsNullOrEmpty(Print_path.Text)) /* if (string.IsNullOrEmpty(Print_path.Text))
{ {
System.Windows.MessageBox.Show("模板不能为空"); System.Windows.MessageBox.Show("模板不能为空");
return; return;
} }*/
var data = this.CreateBillData(); var data = this.CreateBillData();
if (!data.Item1) if (!data.Item1)
{ {
@ -63,7 +67,7 @@ namespace formula_manage.Windows
System.Windows.MessageBox.Show($"打开设计器失败:{tuple.Item2}"); System.Windows.MessageBox.Show($"打开设计器失败:{tuple.Item2}");
} }
} }
private void Button_Click_2(object sender, RoutedEventArgs e) //SQL_DISPEN_bak路径选择按钮 private void Button_Click_2(object sender, RoutedEventArgs e) //预览模板
{ {
} }
@ -97,5 +101,31 @@ namespace formula_manage.Windows
return new Tuple<bool, Dictionary<string, object>, DataSet>(true, dic, dsFrx); 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 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;
}
} }
} }

Loading…
Cancel
Save