SVN-Revision: r278
This commit is contained in:
tdx
2025-02-21 03:57:02 +00:00
parent d11c1d200c
commit ba85d23227
@@ -7,8 +7,10 @@ using Lskj.Core;
using Lskj.Model; using Lskj.Model;
using Lskj.Util; using Lskj.Util;
using Microsoft.WindowsAPICodePack.Shell; using Microsoft.WindowsAPICodePack.Shell;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.IO; using System.IO;
using System.Net; using System.Net;
@@ -322,41 +324,74 @@ namespace Lskj.PubArtworkDynamic.Control
string fileStream = Convert.ToBase64String(fileBytes); string fileStream = Convert.ToBase64String(fileBytes);
string userId = ERPInfo.Instance.UserId; string userId = ERPInfo.Instance.UserId;
DateTime uploadTime = DateTime.Now; DateTime uploadTime = DateTime.Now;
//上传文件到服务器目录 //上传文件到服务器目录
postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}"; postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}";
if (!string.IsNullOrEmpty(leftTopGridIdValue)) if (!string.IsNullOrEmpty(leftTopGridIdValue))
{ {
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, this.MainViewModel.SysModel.ModuleCode, leftTopGridIdValue, "UploadFilesTemp", fileBytes.Length, 0, name, "DoWebUpload"); string token = "";
HttpTools.setting("application/x-www-form-urlencoded", null, null); string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx";
string result = ""; HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
CookieCollection cookieCollection = null; Dictionary<string, string> loginPmsDic = new Dictionary<string, string>();
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, HttpTools.Method.POST, out cookieCollection, out result); loginPmsDic.Add("method", "Login");
if (webResponse != null && !string.IsNullOrEmpty(result)) loginPmsDic.Add("username", ERPInfo.Instance.UserName);
loginPmsDic.Add("password", ERPInfo.Instance.InPassWord);
HttpWebResponse loginResponse = HttpTools.Post(loginUrl, "", loginPmsDic, HttpTools.Method.POST, out CookieCollection loginCookie, out string loginResult);
if (loginResponse != null && !string.IsNullOrEmpty(loginResult))
{ {
JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result); JObject jObject = JsonConvert.DeserializeObject<JObject>(loginResult);
string isSuccess = jsonObject["success"] + ""; if (jObject.ContainsKey("success"))
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
{ {
string fileId = jsonObject["other"] + ""; if ((jObject["success"] + "").Equals("True"))
string webpath = jsonObject["data"]["WebRelPath"] + ""; {
string searchSql = @"update P_fm_FileTab set author='{2}',CreationTime='{3}' ,Uploader='{4}',UploaderId='{5}' ,UploadTime='{6}' ,Pid='{1}' if (jObject.ContainsKey("token"))
{
token = jObject["token"] + "";
}
}
}
}
if (!string.IsNullOrEmpty(token))
{
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, this.MainViewModel.SysModel.ModuleCode, leftTopGridIdValue, "UploadFilesTemp", fileBytes.Length, 0, name, "DoWebUpload");
HttpTools.setting("application/x-www-form-urlencoded", null, null);
string result = "";
CookieCollection cookieCollection = null;
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("Authorization", $"Bearer {token}");
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, headerDic, HttpTools.Method.POST, out cookieCollection, out result);
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result);
string isSuccess = jsonObject["success"] + "";
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
{
string fileId = jsonObject["other"] + "";
string webpath = jsonObject["data"]["WebRelPath"] + "";
string searchSql = @"update P_fm_FileTab set author='{2}',CreationTime='{3}' ,Uploader='{4}',UploaderId='{5}' ,UploadTime='{6}' ,Pid='{1}'
where dllcoid = '{0}' and fileId='{7}' "; where dllcoid = '{0}' and fileId='{7}' ";
searchSql = string.Format(searchSql, this.MainViewModel.SysModel.ModuleCode, this.leftTopGridIdValue, fileAuthor, fileInfo.CreationTime, ERPInfo.Instance.UserName, ERPInfo.Instance.UserId, uploadTime, fileId); searchSql = string.Format(searchSql, this.MainViewModel.SysModel.ModuleCode, this.leftTopGridIdValue, fileAuthor, fileInfo.CreationTime, ERPInfo.Instance.UserName, ERPInfo.Instance.UserId, uploadTime, fileId);
SqlHelper.ExecuteNonQuery(searchSql); SqlHelper.ExecuteNonQuery(searchSql);
isUpload = true; isUpload = true;
}
else
{
if (jsonObject.ContainsKey("msg"))
{
returnMsg = jsonObject["msg"] + "";
}
isUpload = false;
}
} }
else else
{ {
if (jsonObject.ContainsKey("msg")) returnMsg = "上传请求失败";
{
returnMsg = jsonObject["msg"] + "";
}
isUpload = false; isUpload = false;
} }
} }
else else
{ {
returnMsg = "上传请求失败"; returnMsg = loginResult;
isUpload = false; isUpload = false;
} }
} }
@@ -442,38 +477,4 @@ namespace Lskj.PubArtworkDynamic.Control
/// 附件转换byte[] /// 附件转换byte[]
/// </summary> /// </summary>
/// <param name="filePath">附件路径</param> /// <param name="filePath">附件路径</param>
/// <returns>二进制</returns> /// <returns>二进制</retur
private byte[] ConvertFileToBytes(string filePath)
{
byte[] bytContent = null;
System.IO.FileStream fs = null;
System.IO.BinaryReader br = null;
try
{
fs = new FileStream(filePath, System.IO.FileMode.Open);
}
catch (Exception)
{
throw;
}
finally
{
if (fs != null)
br = new BinaryReader((Stream)fs);
if (br != null)
bytContent = br.ReadBytes((Int32)fs.Length);
if (fs != null)
fs.Dispose();
}
return bytContent;
}
/// <summary>
/// 右键菜单回调
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnRightMenuCallBack(object sender, EventArgs e)
{
}
}
}