忱 沈 2 years ago
parent
commit
4e0e102381
  1. 34
      UserClass/PrintHelper.cs
  2. 4
      Windows/Print.xaml
  3. 52
      Windows/Print.xaml.cs

34
UserClass/PrintHelper.cs

@ -69,6 +69,36 @@ namespace formula_manage.UserClass
return new Tuple<bool, string>(flag, msg);
}
/// <summary>
/// 设计
/// </summary>
/// <param name="frxPath">模板</param>
/// <returns></returns>
public static Tuple<bool, string> Design(string frxPath)
{
bool flag = false;
string msg = "";
FastReport.Report report = new FastReport.Report();
try
{
report.Load(frxPath);
report.DoublePass = true;
report.Design();
flag = true;
msg = "Designer Open";
}
catch (Exception ex)
{
flag = false;
msg = ex.Message;
}
finally
{
report.Dispose();
}
return new Tuple<bool, string>(flag, msg);
}
/// <summary>
/// 设计
/// </summary>
@ -76,7 +106,7 @@ namespace formula_manage.UserClass
/// <param name="dicParam">字典参数</param>
/// <param name="dsDataSource">数据源</param>
/// <returns></returns>
public static Tuple<bool, string> Design(string frxPath, Dictionary<string, object> dicParam, DataSet dsDataSource)
public static Tuple<bool, string> Designs(string frxPath, Dictionary<string, object> dicParam, DataSet dsDataSource)
{
bool flag = false;
string msg = "";
@ -103,7 +133,7 @@ namespace formula_manage.UserClass
report.Design();
flag = true;
msg = "设计器打开成功";
msg = "Designer Open";
}
catch (Exception ex)
{

4
Windows/Print.xaml

@ -8,7 +8,7 @@
Title="打印设置" Height="500" Width="500" MaxWidth="500">
<Grid>
<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" MaxLines="1"/>
<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,70,0,0" Content="默认打印机:" VerticalAlignment="Top" Width="90"
x:Name="TEXT_Print" Checked="Print_Checked" Unchecked="Print_Checked"/>
@ -19,7 +19,7 @@
<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"/>
<TextBox x:Name="Print_path2" HorizontalAlignment="Left" Height="20" Margin="90,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="285" MaxLines="1"/>
<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"/>

52
Windows/Print.xaml.cs

@ -126,24 +126,30 @@ namespace formula_manage.Windows
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);
var tuple = PrintHelper.Design(Print_path.Text);
if (!tuple.Item1)
{
System.Windows.MessageBox.Show($"打开设计器失败:{tuple.Item2}");
}
}
private void Button_Click_12(object sender, RoutedEventArgs e) //编辑模板
{
if (string.IsNullOrEmpty(Print_path2.Text))
{
System.Windows.MessageBox.Show("模板不能为空");
return;
}
var tuple = PrintHelper.Design(Print_path2.Text);
if (!tuple.Item1)
{
System.Windows.MessageBox.Show($"打开设计器失败:{tuple.Item2}");
}
}
private void Button_Click_2(object sender, RoutedEventArgs e) //预览模板
{
@ -153,36 +159,6 @@ namespace formula_manage.Windows
}
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(); //打印机是否生效

Loading…
Cancel
Save