Browse Source

print

main
hulei 3 weeks ago
parent
commit
5143c3cffb

+ 147
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/PrintContainer.ts View File

@@ -0,0 +1,147 @@
1
+// 定义 PrintDevice 枚举
2
+enum PrintDevice {
3
+    Printer,
4
+    Other
5
+}
6
+
7
+// 模拟 ImageBrush 类
8
+class ImageBrush {
9
+    ImageSource: string | null = null;
10
+}
11
+
12
+// 模拟 Brush 类
13
+class Brush { }
14
+
15
+// 模拟 DependencyProperty 类
16
+class DependencyProperty {
17
+    static Register(name: string, type: any, ownerType: any, metadata: any) {
18
+        return new DependencyProperty();
19
+    }
20
+}
21
+
22
+// 模拟 UIPropertyMetadata 类
23
+class UIPropertyMetadata {
24
+    constructor(defaultValue: any, callback?: any) { }
25
+}
26
+
27
+// 模拟 Application 类
28
+class Application {
29
+    static Current = new Application();
30
+    TryFindResource(resource: any): any {
31
+        return null;
32
+    }
33
+}
34
+
35
+// 模拟 ContentControl 类
36
+class ContentControl {
37
+    Background: Brush | null = null;
38
+    VisualParent: any | null = null;
39
+    InvalidateVisual() { }
40
+    ActualWidth = 0;
41
+    ActualHeight = 0;
42
+    Content: any | null = null;
43
+}
44
+
45
+// 模拟 Window 类
46
+class Window {
47
+    Content: any | null = null;
48
+    ShowInTaskbar = false;
49
+    WindowState: any;
50
+    Top = 0;
51
+    Left = 0;
52
+    constructor() { }
53
+    Show() { }
54
+    Close() { }
55
+}
56
+
57
+// 模拟 XpsDocument 类
58
+class XpsDocument {
59
+    CoreDocumentProperties: {
60
+        Title: string;
61
+        Description: string;
62
+        ContentType: string;
63
+        Subject: string;
64
+    } = {
65
+        Title: '',
66
+        Description: '',
67
+        ContentType: '',
68
+        Subject: ''
69
+    };
70
+    constructor(fileName: string, access: any) { }
71
+    Close() { }
72
+}
73
+
74
+// 模拟 XpsDocumentWriter 类
75
+class XpsDocumentWriter {
76
+    static CreateXpsDocumentWriter(xd: XpsDocument) {
77
+        return new XpsDocumentWriter();
78
+    }
79
+    Write(visual: any) { }
80
+}
81
+
82
+// 模拟 RenderTargetBitmap 类
83
+class RenderTargetBitmap {
84
+    constructor(width: number, height: number, dpiX: number, dpiY: number, format: any) { }
85
+    Render(visual: any) { }
86
+}
87
+
88
+// 模拟 ImageSource 类
89
+class ImageSource { }
90
+
91
+class PrintContainer extends ContentControl {
92
+    private _documentId: string | null = null;
93
+    DocumentName: string;
94
+    Description: string;
95
+    Device: PrintDevice;
96
+    IsNotingPreview: boolean;
97
+    BackgroundImage: ImageBrush | null = null;
98
+    BackgroundBrush: string;
99
+
100
+    static readonly BackgroundBrushProperty = DependencyProperty.Register(
101
+        "BackgroundBrush",
102
+        String,
103
+        PrintContainer,
104
+        new UIPropertyMetadata('', (sender: any, e: any) => {
105
+            const element = sender as PrintContainer;
106
+            if (!element || !e.NewValue) return;
107
+            element.Background = Application.Current.TryFindResource(e.NewValue) as Brush;
108
+        })
109
+    );
110
+
111
+    static {
112
+        // 模拟重写默认样式键
113
+    }
114
+
115
+    constructor() {
116
+        super();
117
+        this.DocumentName = "默认表单";
118
+        this.Description = "";
119
+        this.Device = PrintDevice.Printer;
120
+        this.IsNotingPreview = false;
121
+        this.BackgroundBrush = '';
122
+    }
123
+
124
+    get DocumentId(): string {
125
+        if (!this._documentId) {
126
+            return this.constructor.name;
127
+        }
128
+        return this._documentId;
129
+    }
130
+
131
+    set DocumentId(value: string) {
132
+        this._documentId = value;
133
+    }
134
+
135
+    PrintToXps(): { path: string } {
136
+        const tempDir = `${process.cwd()}/temp`;
137
+        const filePath = `${tempDir}/${Math.random().toString(36).substring(7)}`;
138
+        // 模拟文件操作
139
+        return { path: filePath };
140
+    }
141
+
142
+    PrintToPng(): ImageSource {
143
+        return new ImageSource();
144
+    }
145
+}
146
+
147
+export { PrintContainer };

+ 15
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/PrintDevice.ts View File

@@ -0,0 +1,15 @@
1
+// 定义 PrintDevice 枚举
2
+export enum PrintDevice {
3
+    /**
4
+     * 屏幕
5
+     */
6
+    Screen,
7
+    /**
8
+     * 文件
9
+     */
10
+    File,
11
+    /**
12
+     * 打印机
13
+     */
14
+    Printer
15
+}

+ 268
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/PrintManager.ts View File

@@ -0,0 +1,268 @@
1
+// 模拟 PrintDevice 枚举
2
+enum PrintDevice {
3
+  Printer = 'Printer'
4
+}
5
+
6
+// 模拟 XpsDocument 类
7
+class XpsDocument {
8
+  constructor(private filePath: string, private access: string) {}
9
+  CoreDocumentProperties = {
10
+    Title: '',
11
+    Description: '',
12
+    Subject: '',
13
+    ContentType: 'false'
14
+  };
15
+  getFixedDocumentSequence() {
16
+    return {
17
+      DocumentPaginator: {
18
+        PageCount: 1,
19
+        ComputePageCount() {},
20
+        GetPage(index: number) {
21
+          return {
22
+            Visual: new FixedPage()
23
+          };
24
+        }
25
+      }
26
+    };
27
+  }
28
+  close() {}
29
+}
30
+
31
+// 模拟 FixedPage 类
32
+class FixedPage {
33
+  Children: any[] = [];
34
+  Width = 0;
35
+  Height = 0;
36
+  Margin = { Left: 0, Top: 0, Right: 0, Bottom: 0 };
37
+  addChild(child: any) {
38
+    this.Children.push(child);
39
+  }
40
+}
41
+
42
+// 模拟 FrameworkElement 类
43
+class FrameworkElement {}
44
+
45
+// 模拟 FileInfo 类
46
+class FileInfo {
47
+  constructor(public FullName: string) {}
48
+  get Directory() {
49
+    return {
50
+      Exists: false,
51
+      Create() {}
52
+    };
53
+  }
54
+  get Exists() {
55
+    return false;
56
+  }
57
+  Delete() {}
58
+  CopyTo(destination: string, overwrite: boolean) {}
59
+}
60
+
61
+// 模拟 PlatformLogger 类
62
+class PlatformLogger {
63
+  static SystemErrorInfo(message: string, error: any) {
64
+    console.error(message, error);
65
+  }
66
+}
67
+
68
+// 模拟 DependencyObjectExtensions 类
69
+class DependencyObjectExtensions {
70
+  static FindVisualTreeChildren(parent: any, predicate: (item: any) => boolean) {
71
+    return [];
72
+  }
73
+}
74
+
75
+// 模拟 Glyphs 类
76
+class Glyphs {
77
+  Indices = '';
78
+  FontUri = '';
79
+}
80
+
81
+// 模拟 ZipPackage 类
82
+class ZipPackage {
83
+  static Open(filePath: string) {
84
+    return new ZipPackage();
85
+  }
86
+  GetPart(uri: string) {
87
+    return {
88
+      GetStream() {
89
+        return {
90
+          Length: 1024
91
+        };
92
+      }
93
+    };
94
+  }
95
+  close() {}
96
+}
97
+
98
+// 模拟 Process 类
99
+class Process {
100
+  static GetProcessesByName(name: string) {
101
+    return [];
102
+  }
103
+  StartInfo = {
104
+    FileName: ''
105
+  };
106
+  Start() {}
107
+}
108
+
109
+// 模拟 AppDomain 类
110
+class AppDomain {
111
+  static get CurrentDomain() {
112
+    return {
113
+      BaseDirectory: ''
114
+    };
115
+  }
116
+}
117
+
118
+// 模拟 Platform.Common.RunningParameters.PlatformSettings 类
119
+namespace Platform {
120
+  export namespace Common {
121
+    export namespace RunningParameters {
122
+      export class PlatformSettings {
123
+        static PrinterOffset = {
124
+          X: 0,
125
+          Y: 0
126
+        };
127
+      }
128
+    }
129
+  }
130
+}
131
+
132
+export class PrintManager {
133
+  private _xpsFile: FileInfo;
134
+  private _device: PrintDevice;
135
+  private _isReprint: boolean;
136
+  private _printBitmap: any;
137
+
138
+  public Title: string;
139
+  public Description: string;
140
+  public Subject: string;
141
+  public IsPrinted: boolean = false;
142
+  public IsNotingPreview: boolean;
143
+  public PrintElement: FixedPage;
144
+  public ReprintFile: FileInfo;
145
+
146
+  public static ReprintMarkup: FrameworkElement;
147
+
148
+  constructor(file: FileInfo, printDevice: PrintDevice, reprint: boolean) {
149
+    this._xpsFile = file;
150
+    this._device = printDevice;
151
+    this._isReprint = reprint;
152
+    this.PrintElement = this.RenderPrintElement();
153
+  }
154
+
155
+  private RenderPrintElement(): FixedPage {
156
+    const xpsDoc = new XpsDocument(this._xpsFile.FullName, 'Read');
157
+    this.Title = xpsDoc.CoreDocumentProperties.Title;
158
+    this.Description = xpsDoc.CoreDocumentProperties.Description;
159
+    this.Subject = xpsDoc.CoreDocumentProperties.Subject;
160
+    this.IsNotingPreview = Boolean(xpsDoc.CoreDocumentProperties.ContentType);
161
+
162
+    const paginator = xpsDoc.getFixedDocumentSequence().DocumentPaginator;
163
+    paginator.ComputePageCount();
164
+    if (paginator.PageCount === 0) {
165
+      throw new Error('xps文档为空文档!');
166
+    }
167
+
168
+    const visual = paginator.GetPage(0).Visual as FixedPage;
169
+    if (!visual) {
170
+      throw new Error('xps文档页面数据非法!');
171
+    }
172
+
173
+    if (this._isReprint) {
174
+      let reprintMark = PrintManager.ReprintMarkup;
175
+      if (!reprintMark) {
176
+        const markup = new FrameworkElement();
177
+        reprintMark = markup;
178
+      }
179
+      visual.addChild(reprintMark);
180
+    }
181
+
182
+    xpsDoc.close();
183
+
184
+    const glyphs = DependencyObjectExtensions.FindVisualTreeChildren(visual, (x) => x instanceof Glyphs).map((x) => x as Glyphs);
185
+    if (glyphs.length > 0) {
186
+      const g = glyphs.find((x) => x.Indices !== '');
187
+      if (g) {
188
+        PlatformLogger.SystemErrorInfo(`打印乱码监测:从xps中发现Indices有效的Glyphs要素->${g.Indices}${this._xpsFile.FullName}`, null);
189
+      }
190
+
191
+      const zip = ZipPackage.Open(this._xpsFile.FullName);
192
+      try {
193
+        const part = zip.GetPart(glyphs[0].FontUri);
194
+        const size = part.GetStream().Length / 1024;
195
+        if (size < 100) {
196
+          PlatformLogger.SystemErrorInfo(`打印乱码监测:从xps中发现小Size的字体文件->${size}${this._xpsFile.FullName}`, null);
197
+        }
198
+      } finally {
199
+        zip.close();
200
+      }
201
+    }
202
+
203
+    return visual;
204
+  }
205
+
206
+  private PrintImage() {
207
+    this.ReprintFile = this.CrateReprintXps(this.PrintElement);
208
+    if (this._device === PrintDevice.Printer) {
209
+      PrintManager.SendToPrinter(this.ReprintFile, this.PrintElement.Width, this.PrintElement.Height, this.Title);
210
+      this.IsPrinted = true;
211
+    }
212
+  }
213
+
214
+  public static SendToPrinter(file: FileInfo, width: number, height: number, documentName: string | null = null, printerName: string | null = null) {
215
+    const processes = Process.GetProcessesByName('Platform.PrintService');
216
+    if (processes.length < 1) {
217
+      const printProcess = new Process();
218
+      printProcess.StartInfo.FileName = `${AppDomain.CurrentDomain.BaseDirectory}Platform.PrintService.exe`;
219
+      printProcess.Start();
220
+      // 模拟 Thread.Sleep
221
+      setTimeout(() => {}, 1000);
222
+    }
223
+
224
+    let argumentsStr = `${file.FullName.replace(' ', '*')}&${documentName || file.FullName}&${width}&${height}&${printerName}`;
225
+    PrintManager.SendMessage('D7D01788-86BC-4E9C-9BB9-041BF848EA4E', argumentsStr);
226
+  }
227
+
228
+  public static SendMessage(windowName: string, strMsg: string) {
229
+    if (!strMsg) return;
230
+    // 模拟 FindWindow 和 SendMessage
231
+    console.log(`向窗口 ${windowName} 发送消息: ${strMsg}`);
232
+  }
233
+
234
+  private CrateReprintXps(page: FixedPage): FileInfo {
235
+    let file: FileInfo | null = null;
236
+    if (page) {
237
+      file = new FileInfo(`print/${this._xpsFile.FullName}`);
238
+      if (file.Exists) {
239
+        file.Delete();
240
+      }
241
+      if (!file.Directory.Exists) {
242
+        file.Directory.Create();
243
+      }
244
+
245
+      if (!this._isReprint) {
246
+        this._xpsFile.CopyTo(file.FullName, true);
247
+      } else {
248
+        const doc = new XpsDocument(file.FullName, 'ReadWrite');
249
+        doc.CoreDocumentProperties.Title = this.Title;
250
+        doc.CoreDocumentProperties.Description = this.Description;
251
+        if (this.Subject) {
252
+          doc.CoreDocumentProperties.Subject = this.Subject;
253
+        }
254
+
255
+        const offsetX = Platform.Common.RunningParameters.PlatformSettings.PrinterOffset.X;
256
+        const offsetY = Platform.Common.RunningParameters.PlatformSettings.PrinterOffset.Y;
257
+        page.Margin = { Left: (offsetX * 96) / 25.4, Top: (offsetY * 96) / 25.4, Right: 0, Bottom: 0 };
258
+
259
+        doc.close();
260
+      }
261
+    }
262
+    return file!;
263
+  }
264
+
265
+  public Print() {
266
+    this.PrintImage();
267
+  }
268
+}

+ 62
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/PrintPreviewContent.xaml View File

@@ -0,0 +1,62 @@
1
+<UserControl x:Class="Platform.Print.PrintPreviewContent"
2
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
4
+    <Border>
5
+        <Grid Margin="10">
6
+            <Grid.RowDefinitions>
7
+                <RowDefinition Height="30" />
8
+                <RowDefinition Height="*" />
9
+                <RowDefinition Height="50" />
10
+            </Grid.RowDefinitions>
11
+            <Grid.ColumnDefinitions>
12
+                <ColumnDefinition Width="*" />
13
+                <ColumnDefinition Width="100" />
14
+                <ColumnDefinition Width="100" />
15
+            </Grid.ColumnDefinitions>
16
+            <TextBlock Name="Text_Title"
17
+                       Grid.Row="0"
18
+                       Grid.ColumnSpan="3"
19
+                       Height="30"
20
+                       FontSize="20"
21
+                       FontWeight="Bold"
22
+                       LineHeight="20"
23
+                       Text="表单名称" />
24
+            <ScrollViewer Grid.Row="1"
25
+                          Grid.ColumnSpan="3"
26
+                          Margin="5"
27
+                          HorizontalScrollBarVisibility="Auto"
28
+                          VerticalScrollBarVisibility="Auto">
29
+                <Grid>
30
+                    <Border Name="Panel_Print" BorderThickness="0" />
31
+                    <Border Name="Panel_Print1" Panel.ZIndex="10" />
32
+                    <Border Name="Panel_NotingPreview"
33
+                            Panel.ZIndex="9999"
34
+                            Visibility="Hidden">
35
+                        <Border HorizontalAlignment="Center"
36
+                                VerticalAlignment="Center"
37
+                                BorderBrush="Red"
38
+                                BorderThickness="2"
39
+                                Padding="5">
40
+                            <TextBlock FontFamily="SimSun"
41
+                                       FontSize="25"
42
+                                       FontWeight="Bold"
43
+                                       Foreground="Red"
44
+                                       Text="无预览:机密数据" />
45
+                            <Border.RenderTransform>
46
+                                <RotateTransform Angle="-10" CenterX="0.5" CenterY="0.5" />
47
+                            </Border.RenderTransform>
48
+                        </Border>
49
+                    </Border>
50
+                </Grid>
51
+            </ScrollViewer>
52
+            <TextBlock Name="Text_Description"
53
+                       Grid.Row="2"
54
+                       Width="553"
55
+                       Margin="5,5,0,5"
56
+                       HorizontalAlignment="Left"
57
+                       FontSize="16"
58
+                       FontWeight="Bold"
59
+                       Text="详细信息" />
60
+        </Grid>
61
+    </Border>
62
+</UserControl>

+ 118
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/PrintPreviewContent.xaml.cs View File

@@ -0,0 +1,118 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Windows;
6
+using System.Windows.Controls;
7
+using System.Windows.Data;
8
+using System.Windows.Documents;
9
+using System.Windows.Input;
10
+using System.Windows.Media;
11
+using System.Windows.Media.Imaging;
12
+using System.Windows.Shapes;
13
+using System.IO;
14
+using System.Windows.Xps.Packaging;
15
+using System.Threading;
16
+using Platform.Presentation.Interfaces;
17
+
18
+namespace Platform.Print
19
+{
20
+    /// <summary>
21
+    /// PrintPreviewContent.xaml 的交互逻辑
22
+    /// </summary>
23
+    public partial class PrintPreviewContent
24
+    {
25
+        #region 字段
26
+        /// <summary>
27
+        /// 打印管理类
28
+        /// </summary>
29
+        private PrintManager _printManager;
30
+        #endregion
31
+
32
+        #region Prop
33
+        #region IsEnableFocusControl
34
+        public bool IsEnableFocusControl
35
+        {
36
+            get { return (bool)GetValue(IsEnableFocusControlProperty); }
37
+            set { SetValue(IsEnableFocusControlProperty, value); }
38
+        }
39
+
40
+        public static readonly DependencyProperty IsEnableFocusControlProperty =
41
+            DependencyProperty.Register("IsEnableFocusControl", typeof(bool), typeof(PrintPreviewContent), new UIPropertyMetadata(true));
42
+        #endregion
43
+        #endregion
44
+
45
+        #region 方法
46
+        /// <summary>
47
+        /// 初始化打印窗体
48
+        /// </summary>
49
+        /// <param name="xpsFile">要解析的xps文件</param>
50
+        /// <param name="device">打印设备</param>
51
+        /// <param name="isReprint">是否添加补打标记</param>
52
+        public PrintPreviewContent(FileInfo xpsFile, PrintDevice device, bool isReprint = false)
53
+        {
54
+            InitializeComponent();
55
+
56
+            if (xpsFile == null)
57
+                throw new ArgumentNullException("xpsFile");
58
+            _printManager = new PrintManager(xpsFile, device, isReprint);
59
+            Panel_Print.Width = _printManager.PrintElement.Width;
60
+            Panel_Print.Height = _printManager.PrintElement.Height;
61
+            Panel_Print1.Width = _printManager.PrintElement.Width;
62
+            Panel_Print1.Height = _printManager.PrintElement.Height;
63
+            //表单名称
64
+            Text_Title.Text = _printManager.Title;
65
+            //表单描述
66
+            Text_Description.Text = _printManager.Description;
67
+            //背景画刷
68
+            Brush background = Brushes.White;
69
+            if (!string.IsNullOrEmpty(_printManager.Subject))
70
+            {
71
+                //要求必须使用全局资源作为背景图像
72
+                if (_printManager.Subject.StartsWith("ImageSource_"))
73
+                {
74
+                    Uri uri = null;
75
+                    if (Uri.TryCreate(_printManager.Subject.Substring(12), UriKind.RelativeOrAbsolute, out uri))
76
+                    {
77
+                        background = new ImageBrush(new BitmapImage(uri));
78
+                    }
79
+                }
80
+                else if (_printManager.Subject.StartsWith("StaticResource_"))
81
+                {
82
+                    background = Application.Current.TryFindResource(_printManager.Subject.Substring(15)) as Brush;
83
+                }
84
+            }
85
+            if (!_printManager.IsNotingPreview)
86
+            {
87
+                Panel_Print.Background = background;
88
+                _printManager.PrintElement.Background = Brushes.Transparent;
89
+                Panel_Print1.Background = new VisualBrush(_printManager.PrintElement);
90
+            }
91
+            else
92
+            {
93
+                Panel_NotingPreview.Visibility = System.Windows.Visibility.Visible;
94
+                Panel_NotingPreview.Background = background;
95
+            }
96
+        }
97
+
98
+        /// <summary>
99
+        /// 打印当前项
100
+        /// </summary>
101
+        public void Print()
102
+        {
103
+            _printManager.Print() ;
104
+        }
105
+
106
+        /// <summary>
107
+        /// 是否已经打印
108
+        /// </summary>
109
+        public bool IsPrinted
110
+        {
111
+            get
112
+            {
113
+                return this._printManager.IsPrinted;
114
+            }
115
+        }
116
+        #endregion
117
+    }
118
+}

+ 102
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/PrintPreviewWindow.xaml View File

@@ -0,0 +1,102 @@
1
+<Window x:Class="Platform.Print.PrintPreviewWindow"
2
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
+        xmlns:dhcc="http://www.dhcc.com.cn"
5
+        x:Name="win"
6
+        Title="打印窗口"
7
+        Width="800"
8
+        Height="600"
9
+        WindowStartupLocation="CenterOwner">
10
+    <Window.Resources>
11
+        <RoutedUICommand x:Key="PrintCommand" Text="打印(Enter)" />
12
+        <RoutedUICommand x:Key="CancelCommand" Text="取消(Cancel)" />
13
+    </Window.Resources>
14
+    <Window.InputBindings>
15
+        <KeyBinding Key="Esc" Command="{StaticResource CancelCommand}" />
16
+        <KeyBinding Key="Enter" Command="{StaticResource PrintCommand}" />
17
+    </Window.InputBindings>
18
+    <Window.CommandBindings>
19
+        <CommandBinding CanExecute="CommandBinding_CanExecute"
20
+                        Command="{StaticResource PrintCommand}"
21
+                        Executed="PrintCommandBinding_Executed" />
22
+        <CommandBinding CanExecute="CommandBinding_CanExecute"
23
+                        Command="{StaticResource CancelCommand}"
24
+                        Executed="CancelCommandBinding_Executed" />
25
+    </Window.CommandBindings>
26
+    <dhcc:PageContainer>
27
+        <dhcc:TradePage x:Name="rootTradePage" dhcc:FocusManager.EnableFocusControl="{Binding ElementName=win, Path=IsEnableFocusControl}">
28
+            <Border BorderBrush="Black" BorderThickness="2">
29
+                <Grid Margin="10">
30
+                    <Grid.RowDefinitions>
31
+                        <RowDefinition Height="30" />
32
+                        <RowDefinition Height="*" />
33
+                        <RowDefinition Height="50" />
34
+                    </Grid.RowDefinitions>
35
+                    <Grid.ColumnDefinitions>
36
+                        <ColumnDefinition Width="*" />
37
+                        <ColumnDefinition Width="100" />
38
+                        <ColumnDefinition Width="100" />
39
+                    </Grid.ColumnDefinitions>
40
+                    <TextBlock Name="Text_Title"
41
+                               Grid.Row="0"
42
+                               Grid.ColumnSpan="3"
43
+                               Height="30"
44
+                               FontSize="20"
45
+                               FontWeight="Bold"
46
+                               LineHeight="20"
47
+                               Text="表单名称" />
48
+                    <ScrollViewer Grid.Row="1"
49
+                                  Grid.ColumnSpan="3"
50
+                                  Margin="5"
51
+                                  HorizontalScrollBarVisibility="Auto"
52
+                                  VerticalScrollBarVisibility="Auto">
53
+                        <Grid>
54
+                            <Border Name="Panel_Print"
55
+                                    BorderBrush="Black"
56
+                                    BorderThickness="1" />
57
+                            <Border Name="Panel_Print1" Panel.ZIndex="10" />
58
+                            <Border Name="Panel_NotingPreview"
59
+                                    Panel.ZIndex="9999"
60
+                                    Visibility="Hidden">
61
+                                <Border HorizontalAlignment="Center"
62
+                                        VerticalAlignment="Center"
63
+                                        BorderBrush="Red"
64
+                                        BorderThickness="2"
65
+                                        Padding="5">
66
+                                    <TextBlock FontFamily="SimSun"
67
+                                               FontSize="25"
68
+                                               FontWeight="Bold"
69
+                                               Foreground="Red"
70
+                                               Text="无预览:机密数据" />
71
+                                    <Border.RenderTransform>
72
+                                        <RotateTransform Angle="-10" CenterX="0.5" CenterY="0.5" />
73
+                                    </Border.RenderTransform>
74
+                                </Border>
75
+                            </Border>
76
+                        </Grid>
77
+                    </ScrollViewer>
78
+                    <Button Grid.Row="2"
79
+                            Grid.Column="1"
80
+                            Height="23"
81
+                            VerticalAlignment="Bottom"
82
+                            Command="{StaticResource PrintCommand}"
83
+                            Content="打印(Enter)" />
84
+                    <Button Grid.Row="2"
85
+                            Grid.Column="2"
86
+                            Height="23"
87
+                            VerticalAlignment="Bottom"
88
+                            Command="{StaticResource CancelCommand}"
89
+                            Content="取消(Esc)" />
90
+                    <TextBlock Name="Text_Description"
91
+                               Grid.Row="2"
92
+                               Width="553"
93
+                               Margin="5,5,0,5"
94
+                               HorizontalAlignment="Left"
95
+                               FontSize="16"
96
+                               FontWeight="Bold"
97
+                               Text="详细信息" />
98
+                </Grid>
99
+            </Border>
100
+        </dhcc:TradePage>
101
+    </dhcc:PageContainer>
102
+</Window>

+ 154
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/PrintPreviewWindow.xaml.cs View File

@@ -0,0 +1,154 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Windows;
6
+using System.Windows.Controls;
7
+using System.Windows.Data;
8
+using System.Windows.Documents;
9
+using System.Windows.Input;
10
+using System.Windows.Media;
11
+using System.Windows.Media.Imaging;
12
+using System.Windows.Shapes;
13
+using System.IO;
14
+using System.Windows.Xps.Packaging;
15
+using System.Threading;
16
+using System.Text.RegularExpressions;
17
+
18
+namespace Platform.Print
19
+{
20
+    /// <summary>
21
+    /// PrintPreviewWindow.xaml 的交互逻辑
22
+    /// </summary>
23
+    public partial class PrintPreviewWindow : Window
24
+    {
25
+        #region 字段
26
+        /// <summary>
27
+        /// 打印管理类
28
+        /// </summary>
29
+        private PrintManager _printManager;
30
+
31
+        #endregion
32
+
33
+        #region Prop
34
+        #region IsEnableFocusControl
35
+        public bool IsEnableFocusControl
36
+        {
37
+            get { return (bool)GetValue(IsEnableFocusControlProperty); }
38
+            set { SetValue(IsEnableFocusControlProperty, value); }
39
+        }
40
+
41
+        public static readonly DependencyProperty IsEnableFocusControlProperty =
42
+            DependencyProperty.Register("IsEnableFocusControl", typeof(bool), typeof(PrintPreviewWindow), new UIPropertyMetadata(true));
43
+        #endregion
44
+        #endregion
45
+
46
+        #region 方法
47
+        /// <summary>
48
+        /// 初始化打印窗体
49
+        /// </summary>
50
+        /// <param name="xpsFile">要解析的xps文件</param>
51
+        /// <param name="device">打印设备</param>
52
+        /// <param name="isReprint">是否添加补打标记</param>
53
+        public PrintPreviewWindow(FileInfo xpsFile, PrintDevice device, bool isReprint = false)
54
+        {
55
+            InitializeComponent();
56
+
57
+            if (xpsFile == null)
58
+                throw new ArgumentNullException("xpsFile");
59
+            _printManager = new PrintManager(xpsFile, device, isReprint);
60
+            Panel_Print.Width = _printManager.PrintElement.Width;
61
+            Panel_Print.Height = _printManager.PrintElement.Height;
62
+            Panel_Print1.Width = _printManager.PrintElement.Width;
63
+            Panel_Print1.Height = _printManager.PrintElement.Height;
64
+            //表单名称
65
+            Text_Title.Text = _printManager.Title;
66
+            //表单描述
67
+            Text_Description.Text = _printManager.Description;
68
+            //背景画刷
69
+            Brush background = Brushes.White;
70
+            if (!string.IsNullOrEmpty(_printManager.Subject))
71
+            {
72
+                try
73
+                {
74
+                    //要求必须使用全局资源作为背景图像
75
+                    if (_printManager.Subject.StartsWith("ImageSource_"))
76
+                    {
77
+                        if (_printManager.Subject.Contains("/RES/"))
78
+                        {
79
+                            String path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RES", Regex.Split(_printManager.Subject, "/RES/")[1]);
80
+                            if (File.Exists(path))
81
+                            {
82
+                                var ms = new MemoryStream(File.ReadAllBytes(path));
83
+                                //防止内存泄漏,页面关闭时销毁内存流
84
+                                this.Closed += (sender, e) => { ms.Close(); };
85
+                                var imageSource = new BitmapImage();
86
+                                imageSource.BeginInit();
87
+                                imageSource.StreamSource = ms;
88
+                                imageSource.EndInit();
89
+                                background = new ImageBrush(imageSource);
90
+                            }
91
+                        }
92
+                        else
93
+                        {
94
+                            Uri uri = null;
95
+                            if (Uri.TryCreate(_printManager.Subject.Substring(12), UriKind.RelativeOrAbsolute, out uri))
96
+                                background = new ImageBrush(new BitmapImage(uri));
97
+                        }
98
+                    }
99
+                    else if (_printManager.Subject.StartsWith("StaticResource_"))
100
+                    {
101
+                        background = Application.Current.TryFindResource(_printManager.Subject.Substring(15)) as Brush;
102
+                    }
103
+                }
104
+                catch (Exception ex)
105
+                {
106
+                    Platform.Common.LogSystem.PlatformLogger.TradeErrorInfo("背景图转换出错!" + _printManager.Subject, ex);
107
+                    background = Brushes.White;
108
+                }
109
+            }
110
+            if (!_printManager.IsNotingPreview)
111
+            {
112
+                Panel_Print.Background = background;
113
+                _printManager.PrintElement.Background = Brushes.Transparent;
114
+                Panel_Print1.Background = new VisualBrush(_printManager.PrintElement);
115
+            }
116
+            else
117
+            {
118
+                Panel_NotingPreview.Visibility = System.Windows.Visibility.Visible;
119
+                Panel_NotingPreview.Background = background;
120
+            }
121
+        }
122
+
123
+
124
+        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
125
+        {
126
+            e.CanExecute = true;
127
+            e.Handled = true;
128
+        }
129
+
130
+        private void CancelCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
131
+        {
132
+            this.Close();
133
+        }
134
+
135
+        private void PrintCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
136
+        {
137
+            _printManager.Print();
138
+            this.Close();
139
+
140
+        }
141
+
142
+        /// <summary>
143
+        /// 是否已经打印
144
+        /// </summary>
145
+        public bool IsPrinted
146
+        {
147
+            get
148
+            {
149
+                return this._printManager.IsPrinted;
150
+            }
151
+        }
152
+        #endregion
153
+    }
154
+}

+ 18
- 0
ant-design-pro-vue3/src/views/front/platfrom/Print/Themes/Generic.xaml View File

@@ -0,0 +1,18 @@
1
+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2
+                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3
+                    xmlns:dhcc="http://www.dhcc.com.cn"
4
+                    xmlns:local="clr-namespace:Platform.Print">
5
+    <Style TargetType="{x:Type local:PrintContainer}">
6
+        <Setter Property="Template">
7
+            <Setter.Value>
8
+                <ControlTemplate TargetType="{x:Type local:PrintContainer}">
9
+                    <Border Background="{TemplateBinding Background}"
10
+                            BorderBrush="{TemplateBinding BorderBrush}"
11
+                            BorderThickness="{TemplateBinding BorderThickness}">
12
+                        <ContentPresenter ContentSource="{Binding Content}"/>
13
+                    </Border>
14
+                </ControlTemplate>
15
+            </Setter.Value>
16
+        </Setter>
17
+    </Style>
18
+</ResourceDictionary>

Loading…
Cancel
Save