使用料号ID,调用ERP料号图纸接口,实现可预览图纸功能
zjh
2025-03-08 5bd7ade241a9efe2cfe664a4ebc1f74054facb4c
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System.Diagnostics;
using System.Dynamic;
using static System.Runtime.InteropServices.JavaScript.JSType;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks;
namespace FileList
{
    public partial class Form1 : Form
    {
        public Form1(string[] Data)
        {
            InitializeComponent();
            CreateDynamicLinks(Data);
        }
        // ÔÚFormµÄLoadʼþ»ò°´Å¥µã»÷ʼþÖÐ
        private async Task CreateDynamicLinks(string[] Data)
        {
            //if (Data.Length > 0)
            //{
            //    MessageBox.Show(":" + Data[0] + Data[1] + Data[2] + Data[3]);
            //}
            //else { MessageBox.Show("ɶ:"); }  //ÕâÊDzâÊÔÓÐûÓвÎÊý´«µÝ¹ýÀ´
 
            // Á´½ÓÊý¾Ý¼¯ºÏ£¨Ê¾ÀýÊý¾Ý£©
            //var type = "2";
            //var itemID = "130912-0071";
            var type = Data[2];
            var itemID = Data[3];
            if (type=="1")
            {
                this.Text = "ͼֽ¹æ¸ñÊé";
            }
            else
            {
                this.Text = "½øÁϼìÑéÎļþ";
            }
            dynamic resultInfos = new ExpandoObject();
         
            var tbBillList = await GetFileUrlByU9List(type, itemID);
            var links=new Dictionary<string, string>();
            foreach (var item in tbBillList)
            {
                links.Add(GetLastSegment(item), item);
            }
      
 
            // ³õʼλÖÃ
            int topPosition = 20;
 
            foreach (var link in links)
            {
                // ´´½¨LinkLabelʵÀý
                var linkLabel = new LinkLabel
                {
                    Text = link.Key,
                    Location = new Point(20, topPosition),
                    AutoSize = true,
                    Tag = link.Value // ´æ´¢URL
                };
 
                // °ó¶¨µã»÷ʼþ
                linkLabel.LinkClicked += (sender, e) =>
                {
                    var url = ((LinkLabel)sender).Tag.ToString();
                    System.Diagnostics.Process.Start(new ProcessStartInfo
                    {
                        FileName = url,
                        UseShellExecute = true
                    });
                };
 
                // Ìí¼Óµ½ÈÝÆ÷
                this.Controls.Add(linkLabel);
 
                // µ÷ÕûÏÂÒ»¸ö¿Ø¼þλÖÃ
                topPosition += 30;
            }
        }
 
        /// <summary>
        /// ÁϺÅͼֽ½Ó¿Ú·µ»Ø¶ÔÏó
        /// </summary>
        public class ApiResponse
        {
            [JsonProperty("status")]
            public int Status { get; set; }
            [JsonProperty("message")]
            public string Message { get; set; }
            [JsonProperty("data")]
            public string[] Data { get; set; }
            [JsonProperty("totalCount")]
            public int TotalCount { get; set; }
        }
        private static readonly HttpClient client = new HttpClient();
        /// <summary>
        /// ´ÓU9»ñÈ¡ÁϺÅͼֽÁбí
        /// </summary>
        /// <param name="Type">u9No£ºu9ÎïÁϱàºÅ</param>
        /// <param name="U9No">type£º1£ºÍ¼Ö½¹æ¸ñÊé  2£º½øÁϼìÑéÎļþ </param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task<string[]> GetFileUrlByU9List(string Type, string U9No)
        {
            try
            {
                var requestUrl = $"https://erp.dream-maker.com/api/public/getFileUrlByU9No?u9No={Uri.EscapeDataString(U9No)}&type={Type}";
                var response = await client.GetAsync(requestUrl);
                response.EnsureSuccessStatusCode(); // ¼ì²éHTTP״̬Âë
                var responseContent = await response.Content.ReadAsStringAsync();
                var result = JsonConvert.DeserializeObject<ApiResponse>(responseContent);
 
                if (result.Status == 0 && result.Data != null)
                {
                    return result.Data;
                }
                else
                {
                    return null;
                }
 
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        string GetLastSegment(string input)
        {
            if (string.IsNullOrEmpty(input))
                return "";
 
            // Í¬Ê±Ö§³ÖÕý·´Ð±¸Ü·Ö¸î
            var segments = input.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
            return segments.Length > 0 ? segments[^1] : "";
        }
    }
}