edit
This commit is contained in:
+59
-26
@@ -68,7 +68,7 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
string fname = fileName + ext;
|
||||
if (File.Exists(fname))
|
||||
{
|
||||
return fname;
|
||||
return ext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
|
||||
int mvClientDown = 0;//转移到客户端下载
|
||||
|
||||
int isFromClient = 0;
|
||||
int isFromClient = 0;
|
||||
if (onlyDownFile != 1)
|
||||
{
|
||||
if (Request["supplier"] == null || Request["supplier"].ToString() != "1")//如果不是只下文件,那他就要是供应商
|
||||
@@ -133,23 +133,23 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Int32.TryParse(Request["isFromClient"], out isFromClient);
|
||||
/* Int32.TryParse(Request["isFromClient"], out isFromClient);
|
||||
|
||||
if (userId > 0 && isFromClient != 1)
|
||||
{
|
||||
string file_client_down_flg = erpRedis.RedisHelper.StringGet("file_client_down_flg_" + userId);
|
||||
if (file_client_down_flg != null && file_client_down_flg == "1")
|
||||
{
|
||||
mvClientDown = 1;
|
||||
}
|
||||
}*/
|
||||
if (userId > 0 && isFromClient != 1)
|
||||
{
|
||||
string file_client_down_flg = erpRedis.RedisHelper.StringGet("file_client_down_flg_" + userId);
|
||||
if (file_client_down_flg != null && file_client_down_flg == "1")
|
||||
{
|
||||
mvClientDown = 1;
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.AppendFormat("select ctid,seller_memo,FinishDesignTime,OrderState,SupplierName,FileMd5 from view_erptradecell where FinishDesignTime is not null and ctid in ({0}) {1}", ("'" + tids.Replace(",", "','") + "'"), ((onlyDownFile == 1 || isFromClient == 1) ? "" : " and OrderState=5 "));
|
||||
sql.AppendFormat("select ctid,seller_memo,FinishDesignTime,OrderState,SupplierName,FileMd5,OrderSn,tid from view_erptradecell where FinishDesignTime is not null and ctid in ({0}) {1}", ("'" + tids.Replace(",", "','") + "'"), ((onlyDownFile == 1 || isFromClient == 1) ? "" : " and OrderState=5 "));
|
||||
DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
|
||||
if (dt == null || dt.Rows.Count < 1)
|
||||
{
|
||||
@@ -160,12 +160,23 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
List<string> files = new List<string>();
|
||||
List<string> noFileLst = new List<string>();
|
||||
List<string> ctidLst = new List<string>();
|
||||
List<string> rnameList = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string finishDesignTime = getDesignTime(dr["FinishDesignTime"]);
|
||||
string ctid = dr["ctid"].ToString();
|
||||
string df_name = upPath + "\\" + finishDesignTime + "\\" + formatMemo(dr["seller_memo"]);
|
||||
string fname = getCanDownFile(df_name);
|
||||
string ext = getCanDownFile(df_name);
|
||||
string fname = df_name + ext;
|
||||
string tid = dr["tid"].ToString();
|
||||
string orderSn = dr["OrderSn"].ToString();
|
||||
string rname = "";
|
||||
if (!string.IsNullOrEmpty(tid) && !string.IsNullOrEmpty(orderSn))
|
||||
{
|
||||
rname = formatMemo(dr["seller_memo"]).Replace(orderSn, tid);
|
||||
rname = rname + "《" + orderSn + "》";
|
||||
rname = rname + ext;
|
||||
}
|
||||
int IsFileEncrypt = IsFileEncrypted(fname);
|
||||
if (IsFileEncrypt == 1 && File.Exists(fname))
|
||||
{
|
||||
@@ -200,11 +211,14 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
files.Add(fname);
|
||||
ctidLst.Add(ctid);
|
||||
|
||||
rnameList.Add(rname);
|
||||
fileMd5 += "," + dr["FileMd5"].ToString();
|
||||
fileNames += "#$#" + Path.GetFileName(fname);
|
||||
|
||||
if (onlyDownFile != 1 && mvClientDown != 1)
|
||||
copyFile(getDesignDate(dr["FinishDesignTime"]), dr["SupplierName"].ToString(), fname);
|
||||
{
|
||||
copyFile(getDesignDate(dr["FinishDesignTime"]), dr["SupplierName"].ToString(), fname, rname);
|
||||
}
|
||||
}
|
||||
|
||||
if (files.Count == 0)
|
||||
@@ -243,11 +257,11 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
|
||||
if (files.Count == 1)
|
||||
{
|
||||
downLoadFile(userId, ctidLst[0], files[0], onlyDownFile, isFromClient);
|
||||
downLoadFile(userId, ctidLst[0], files[0], onlyDownFile, isFromClient, rnameList[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ZipFileDownload(userId, ctidLst, files, "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip", onlyDownFile, isFromClient); //downLoadFile(userId, ctidLst[i], files[i]);
|
||||
ZipFileDownload(userId, ctidLst, files, "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip", onlyDownFile, isFromClient, rnameList); //downLoadFile(userId, ctidLst[i], files[i]);
|
||||
}
|
||||
|
||||
//conSuc("文件已下载完成");
|
||||
@@ -269,16 +283,35 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
m = m.Replace("\\", "").Replace("/", "").Replace(":", "").Replace("*", "").Replace("?", "").Replace("<", "").Replace(">", "").Replace("|", "");
|
||||
return m;
|
||||
}
|
||||
|
||||
private void copyFile(string date, string supplier, string file)
|
||||
Dictionary<string, string> replaceRules = new Dictionary<string, string>
|
||||
{
|
||||
{ "皙贝", "白卡" },
|
||||
{ "睿狐", "莱尼" },
|
||||
{ "岚蝶", "安格" },
|
||||
{ "琮纹", "刚古" },
|
||||
{ "珠光", "珠光" },
|
||||
{ "溪雪", "珠光" },
|
||||
{ "雅柔", "雅柔" },
|
||||
{ "萱姿", "雅柔" },
|
||||
{ "草香", "草香" },
|
||||
{ "芳怡", "草香" },
|
||||
{ "金绒", "牛皮" },
|
||||
{ "素芸", "棉卡" },
|
||||
{ "玉蕊", "蛋壳" }
|
||||
};
|
||||
private void copyFile(string date, string supplier, string file, string rname)
|
||||
{
|
||||
string path = copyPath + "\\" + date + "\\" + supplier + "\\" + "车间下载";
|
||||
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
||||
string fname = Path.GetFileName(file);
|
||||
File.Copy(file, path + "\\" + fname, true);
|
||||
if (!File.Exists(path + "\\" + fname))
|
||||
foreach (var rule in replaceRules)
|
||||
{
|
||||
File.Copy(file, path + "\\" + fname, true);
|
||||
rname = rname.Replace(rule.Key, rule.Value);
|
||||
}
|
||||
|
||||
File.Copy(file, path + "\\" + rname, true);
|
||||
if (!File.Exists(path + "\\" + rname))
|
||||
{
|
||||
File.Copy(file, path + "\\" + rname, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +332,7 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
/// </summary>
|
||||
/// <param name="files">文件列表(绝对路径)</param> 这里用的数组,你可以用list 等或者
|
||||
/// <param name="zipFileName">生成的zip文件名称</param>
|
||||
private void ZipFileDownload(int userId, List<string> ctidLst, List<string> files, string zipFileName, int onlyDownFile, int isFromClient)
|
||||
private void ZipFileDownload(int userId, List<string> ctidLst, List<string> files, string zipFileName, int onlyDownFile, int isFromClient, List<string> rnameList)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] buffer = null;
|
||||
@@ -317,7 +350,7 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
{
|
||||
try
|
||||
{
|
||||
file.Add(files[i]);
|
||||
file.Add(files[i], rnameList[i]);
|
||||
addFiles.Add(files[i]);
|
||||
addCtid.Add(ctidLst[i]);
|
||||
}
|
||||
@@ -360,7 +393,7 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
}
|
||||
|
||||
//public static object downfileObj = new object();
|
||||
private void downLoadFile(int userId, string ctid, string file, int onlyDownFile, int isFromClient)
|
||||
private void downLoadFile(int userId, string ctid, string file, int onlyDownFile, int isFromClient, string fname)
|
||||
{
|
||||
string filePath = file;
|
||||
string dfile = Path.GetFileName(file);
|
||||
@@ -380,7 +413,7 @@ public partial class supplierDownload : System.Web.UI.Page
|
||||
//通知浏览器下载文件而不是打开\\fileDownload=true; path=/
|
||||
Response.AddHeader("Set-Cookie", "fileDownload=true; path=/;");
|
||||
//Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(dfile, System.Text.Encoding.UTF8));
|
||||
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fname, System.Text.Encoding.UTF8));
|
||||
Response.AddHeader("Content-Length", bytes.Length.ToString());
|
||||
Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
Response.BinaryWrite(bytes);
|
||||
|
||||
Reference in New Issue
Block a user