| | |
| | | using DevExpress.Utils.DirectXPaint; |
| | | using DevExpress.XtraEditors; |
| | | using Gs.DevApp.ToolBox; |
| | | using Gs.DevApp.ToolBox; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Configuration; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Net.Http; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | |
| | | btnUpSelect.Click += BtnUpSelect_Click; |
| | | btnUp.Click += BtnUp_Click; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string parentGuid |
| | | { |
| | | get; |
| | | set; |
| | | } |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string parentGroup |
| | | { |
| | | get; |
| | | set; |
| | |
| | | /// 改变事件 |
| | | /// </summary> |
| | | public event EventHandler UpChanged; |
| | | |
| | | |
| | | #region 文件上传 |
| | | |
| | | /// <summary> |
| | |
| | | var WebApiUrl = ConfigurationSettings.AppSettings.Get("WebApiUrl"); |
| | | var address = WebApiUrl + "MesFile/UploadFile"; |
| | | var filePath = txtUpUrl.Text.Trim(); |
| | | if (string.IsNullOrEmpty(filePath)) { |
| | | if (string.IsNullOrEmpty(filePath)) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择你需要上传的文件!"); |
| | | return; |
| | | } |
| | |
| | | |
| | | private async Task UploadFileAsync(string url, string filePath) |
| | | { |
| | | UcLoading _loading = new UcLoading(); |
| | | string _parentGuid = parentGuid; |
| | | using (var httpClient = new HttpClient()) |
| | | using (var form = new MultipartFormDataContent()) |
| | | { |
| | | httpClient.DefaultRequestHeaders.Add("token", |
| | | UtilityHelper.GetBasicAuthTicket()); |
| | | using (var fs = File.OpenRead(filePath)) |
| | | using (var streamContent = new StreamContent(fs)) |
| | | try |
| | | { |
| | | form.Add(streamContent, "file", _parentGuid + "~" + Path.GetFileName(filePath)); |
| | | var response = await httpClient.PostAsync(url, form); |
| | | var responseString = |
| | | await response.Content.ReadAsStringAsync(); |
| | | // MessageBox.Show(responseString); |
| | | txtUpUrl.Text = ""; |
| | | using (var form = new MultipartFormDataContent()) |
| | | { |
| | | httpClient.DefaultRequestHeaders.Add("token", |
| | | UtilityHelper.GetBasicAuthTicket()); |
| | | using (var fs = File.OpenRead(filePath)) |
| | | using (var streamContent = new StreamContent(fs)) |
| | | { |
| | | form.Add(streamContent, "file", _parentGuid + "~" + Path.GetFileName(filePath) + "~" + parentGroup); |
| | | var response = await httpClient.PostAsync(url, form); |
| | | var responseString = |
| | | await response.Content.ReadAsStringAsync(); |
| | | // MessageBox.Show(responseString); |
| | | txtUpUrl.Text = ""; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | _loading.Close(); |
| | | catch (Exception ex) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.ShowError(ex.Message); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | #endregion |