chr
7 天以前 43a0207d207390abdeeb3ab9155eebf03edd7b1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using log4net;
using PdmSwPlugin.Commmon.Util.UI;
using PdmSwPlugin.Common.Entity.DrawAudit;
using PdmSwPlugin.Common.Interface;
using PdmSwPlugin.Common.Util.Http;
using SolidWorks.Interop.sldworks;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
 
namespace PdmSwPlugin.DrawApprove
{
    /// <summary>
    /// XamlWindow.xaml 的交互逻辑
    /// </summary>
    public partial class XamlWindow : Window, INotifyPropertyChanged, ISwAppSetter
    {
        #region ...
        public virtual event PropertyChangedEventHandler PropertyChanged;
 
        public virtual void RaisePropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
 
        public void RaiseAndSetIfChanged<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
        {
            old = @new;
            if (propertyName != null)
            {
                RaisePropertyChanged(propertyName);
            }
        }
        #endregion
 
        private string _title;
 
        public string title
        {
            get => _title;
            set => RaiseAndSetIfChanged(ref _title, value);
        }
 
        public SldWorks SwApp => this.swApp;
 
        private readonly DrawAudit drawInfo;
        private readonly ILog Logger;
        private readonly HttpClient Client;
        private readonly SldWorks swApp;
 
 
        public XamlWindow(string title, DrawAudit da, HttpClient Client, ILog Logger, SldWorks swApp)
        {
            this.title = title ?? string.Empty;
            drawInfo = da;
            this.Client = Client;
            this.Logger = Logger;
            this.swApp = swApp;
            DataContext = this;
            InitializeComponent();
        }
 
        private void Ok_Click(object sender, RoutedEventArgs e)
        {
            byte[] blob = richBox.GetBlob();
            byte[] base64Data = richBox.GetBase64Blob();
            MaskAdorner.ShowMask(content, "请求中,请稍候...");
            Task.Run(() =>
            {
                try
                {
                    drawInfo.pass = false;
                    drawInfo.comment = "123";
                    drawInfo.commentBlob = blob;
                    drawInfo.base64Data = base64Data;
                    Result<object> res = Client.PostSyncAction<object>(drawInfo, "drawAudit/complete");
                    object obj = res.HandleResult();
                    Dispatcher.Invoke(() =>
                    {
                        DialogResult = true;
                    });
                }
                catch (Exception ex)
                {
                    Logger.Error("Draw complete failed.", ex);
                    MessageBox.Show($"驳回失败!{ex.Message}");
                }
                finally
                {
                    MaskAdorner.HideMask(content);
                }
            });
        }
 
        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            //string ss = richBox.ToBase64Image();
            //Debug.Print(ss);
            DialogResult = false;
        }
 
        public void SetSwApp(SldWorks SwApp)
        {
            //throw new NotImplementedException();
        }
    }
}