SVN r278
SVN-Revision: r278
This commit is contained in:
@@ -7,8 +7,10 @@ using Lskj.Core;
|
||||
using Lskj.Model;
|
||||
using Lskj.Util;
|
||||
using Microsoft.WindowsAPICodePack.Shell;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
@@ -322,41 +324,74 @@ namespace Lskj.PubArtworkDynamic.Control
|
||||
string fileStream = Convert.ToBase64String(fileBytes);
|
||||
string userId = ERPInfo.Instance.UserId;
|
||||
DateTime uploadTime = DateTime.Now;
|
||||
|
||||
//上传文件到服务器目录
|
||||
postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}";
|
||||
if (!string.IsNullOrEmpty(leftTopGridIdValue))
|
||||
{
|
||||
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;
|
||||
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, HttpTools.Method.POST, out cookieCollection, out result);
|
||||
if (webResponse != null && !string.IsNullOrEmpty(result))
|
||||
string token = "";
|
||||
string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx";
|
||||
HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
|
||||
Dictionary<string, string> loginPmsDic = new Dictionary<string, string>();
|
||||
loginPmsDic.Add("method", "Login");
|
||||
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);
|
||||
string isSuccess = jsonObject["success"] + "";
|
||||
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
|
||||
JObject jObject = JsonConvert.DeserializeObject<JObject>(loginResult);
|
||||
if (jObject.ContainsKey("success"))
|
||||
{
|
||||
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}'
|
||||
if ((jObject["success"] + "").Equals("True"))
|
||||
{
|
||||
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}' ";
|
||||
searchSql = string.Format(searchSql, this.MainViewModel.SysModel.ModuleCode, this.leftTopGridIdValue, fileAuthor, fileInfo.CreationTime, ERPInfo.Instance.UserName, ERPInfo.Instance.UserId, uploadTime, fileId);
|
||||
SqlHelper.ExecuteNonQuery(searchSql);
|
||||
isUpload = true;
|
||||
searchSql = string.Format(searchSql, this.MainViewModel.SysModel.ModuleCode, this.leftTopGridIdValue, fileAuthor, fileInfo.CreationTime, ERPInfo.Instance.UserName, ERPInfo.Instance.UserId, uploadTime, fileId);
|
||||
SqlHelper.ExecuteNonQuery(searchSql);
|
||||
isUpload = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonObject.ContainsKey("msg"))
|
||||
{
|
||||
returnMsg = jsonObject["msg"] + "";
|
||||
}
|
||||
isUpload = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonObject.ContainsKey("msg"))
|
||||
{
|
||||
returnMsg = jsonObject["msg"] + "";
|
||||
}
|
||||
returnMsg = "上传请求失败";
|
||||
isUpload = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnMsg = "上传请求失败";
|
||||
returnMsg = loginResult;
|
||||
isUpload = false;
|
||||
}
|
||||
}
|
||||
@@ -442,38 +477,4 @@ namespace Lskj.PubArtworkDynamic.Control
|
||||
/// 附件转换byte[]
|
||||
/// </summary>
|
||||
/// <param name="filePath">附件路径</param>
|
||||
/// <returns>二进制</returns>
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <returns>二进制</retur
|
||||
Reference in New Issue
Block a user