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] : "";
|
}
|
}
|
}
|