SVN-Revision: r440
This commit is contained in:
wyf
2025-04-02 12:47:11 +00:00
parent 82c1baca7e
commit 16177d0d67
@@ -526,7 +526,7 @@ namespace Lskj.Control.Model
resultValue = ExecDynamicLinkLibary(model, paramList, dllName, true);
break;
case 5://执行存储过程获取下载url集合执行批量下载
resultValue = ExecDownloadFiles(model, paramList, rowData);
resultValue = ExecDownloadFiles(model, paramList, rows);
break;
case 6://下载后打开文件
resultValue = OpenAfterDownloading(model, paramList);
@@ -1076,17 +1076,128 @@ namespace Lskj.Control.Model
/// <para>版本:1.0</para>
/// </summary>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
private bool ExecDownloadFiles(GridRightMenuModel model, List<string> paramList, DataRow rowData, string comfirmFlag = "0")
private bool ExecDownloadFiles(GridRightMenuModel model, List<string> paramList, DataRow[] rows, string comfirmFlag = "0")
{
bool reaultValue = true;
string procName = model.Action;
if (string.IsNullOrWhiteSpace(procName))
{
MessageUtil.Show(ResourceKeys.NotFoundProcName);
return false;
if (rows.Length > 0 && rows[0].Table.Columns.Contains("webpath"))
{
StringBuilder urlsBuilder = new StringBuilder();
foreach (DataRow row in rows)
{
string url = row["webpath"] + "";
if (!string.IsNullOrEmpty(url))
{
urlsBuilder.Append($"{url},");
}
}
try
{
string urls = urlsBuilder.ToString().TrimEnd(',');
string idvalue = rows[0].Table.Columns.Contains("keyvalue") ? rows[0]["keyvalue"] + "" : "";
string fileDownTitle = rows[0].Table.Columns.Contains("fileTitle") ? rows[0]["fileTitle"] + "" : "";
if (!string.IsNullOrWhiteSpace(urls))
{
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 jObject = JsonConvert.DeserializeObject<JObject>(loginResult);
if (jObject.ContainsKey("success"))
{
if ((jObject["success"] + "").Equals("True"))
{
if (jObject.ContainsKey("token"))
{
token = jObject["token"] + "";
}
}
}
}
if (!string.IsNullOrEmpty(token))
{
string downUrl = string.Format("{0}Api/FileUploadApi.ashx", SystemInfo.Instance.OAUrl);
Dictionary<string, string> parmarsDic = new Dictionary<string, string>();
parmarsDic.Add("userid", ERPInfo.Instance.UserId);
parmarsDic.Add("username", ERPInfo.Instance.UserName);
parmarsDic.Add("password", ERPInfo.Instance.InPassWord);
parmarsDic.Add("method", "DownLoadFiels");
parmarsDic.Add("urls", urls);
parmarsDic.Add("moduleid", model.MenuTabName);
parmarsDic.Add("idvalue", idvalue);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("Authorization", $"Bearer {token}");
HttpTools.setting("application/x-www-form-urlencoded", null, null);
//HttpWebResponse response = HttpTools.Post(downUrl, "", parmarsDic, HttpTools.Method.POST);
HttpWebResponse response = HttpTools.Post(downUrl, "", parmarsDic, headerDic, HttpTools.Method.POST);
string result = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (response != null && !string.IsNullOrEmpty(result))
{
JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result);
string isSuccess = jsonObject["success"] + "";
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
{
string zipPathUrl = jsonObject["data"] + "";
string downLoadUrl = string.Format("{0}{1}", SystemInfo.Instance.OAUrl, zipPathUrl.TrimStart('/'));
FrmSelectDownload frmSelectDownload = new FrmSelectDownload();
frmSelectDownload.URL = downLoadUrl;
frmSelectDownload.ModelId = model.MenuTabName;
frmSelectDownload.MenuName = model.MenuName;
frmSelectDownload.MenuId = model.Id + "";
string[] szName = zipPathUrl.Split('/');
string fileTitle = !string.IsNullOrWhiteSpace(fileDownTitle) ? fileDownTitle : szName[szName.Length - 1];
frmSelectDownload.FileName = fileTitle;
//frmSelectDownload.TopMost = true;
frmSelectDownload.Show();
}
else
{
MessageUtil.Show(jsonObject["msg"] + "");
}
}
response.GetResponseStream().Close();
response.Close();
}
else
{
MessageUtil.Show($"登录验证失败\r\n{loginResult}");
}
}
else
{
MessageUtil.Show("操作失败,未查询到数据");
}
}
catch (SqlException ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
return false;
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
}
}
else
{
MessageUtil.Show("没有需要下载的数据");
}
return reaultValue;
}
else
{
bool reaultValue = true;
List<string> procParams = ReplaceHelper.GetParamFields(procName);
if (procParams.Count == 0)
{
@@ -1335,17 +1446,20 @@ namespace Lskj.Control.Model
else if (model.ActionType == 5)//批量下载
{
string modelAction = model.Action;
List<string> procParams = ReplaceHelper.GetParamFields(modelAction);
string[] paramStr = procParams[0].Replace("{", "").Replace("}", "").Split(',');
if (paramStr.Contains("@keyvalue"))
if (!string.IsNullOrEmpty(modelAction))
{
int index = Array.FindIndex(paramStr, new Predicate<string>(str =>
{
return str.Equals("@keyvalue");
}));
List<string> procParams = ReplaceHelper.GetParamFields(modelAction);
string[] paramStr = procParams[0].Replace("{", "").Replace("}", "").Split(',');
if (paramStr.Contains("@keyvalue"))
{
int index = Array.FindIndex(paramStr, new Predicate<string>(str =>
{
return str.Equals("@keyvalue");
}));
string fieldValue = paramList[index];
paramList[index] = ReplaceHelper.ReplaceRowParamSplit(rows, fieldValue, "", "", ';');
string fieldValue = paramList[index];
paramList[index] = ReplaceHelper.ReplaceRowParamSplit(rows, fieldValue, "", "", ';');
}
}
}
isOnlyOne = true;