edit
This commit is contained in:
@@ -0,0 +1,343 @@
|
||||
using Aliyun.OSS;
|
||||
using Aliyun.OSS.Common;
|
||||
using BizCom;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using NPOI.OpenXmlFormats.Dml.Diagram;
|
||||
using NPOI.OpenXmlFormats.Shared;
|
||||
using SiteCore.Handler;
|
||||
using SiteCore.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Services.Description;
|
||||
using System.Web.UI;
|
||||
|
||||
|
||||
public partial class supplierBuildFile : System.Web.UI.Page
|
||||
{
|
||||
public static string upPath = ConfigurationManager.AppSettings["upPath"];
|
||||
public static string copyPath = ConfigurationManager.AppSettings["copyPath"];
|
||||
|
||||
public static string siteUrl = ConfigurationManager.AppSettings["OriSiteUrl"];
|
||||
|
||||
[DllImport("DrvInterface64.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern uint DecFile(string filename);
|
||||
|
||||
[DllImport("DrvInterface64.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern int IsFileEncrypted(string filename);//返回1为加密,0为未被加密
|
||||
[DllImport("DrvInterface64.dll", CharSet = CharSet.Ansi)]
|
||||
public static extern void CreateUserKey(StringBuilder key, int len);
|
||||
[DllImport("DrvInterface64.dll", CharSet = CharSet.Ansi)]
|
||||
public static extern int InitAesKey(StringBuilder key, int len);
|
||||
|
||||
[DllImport("DrvInterface64.dll")]
|
||||
public static extern int IsInitedAesKey();
|
||||
|
||||
private void conErc(string msg)
|
||||
{
|
||||
XLog.SaveLog(0, msg);
|
||||
Response.Write(msg);
|
||||
//Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
//Response.End();
|
||||
}
|
||||
|
||||
private void conSuc(string msg)
|
||||
{
|
||||
Response.Write("{\"type\":\"success\",\"result\":\"" + msg + "\"}");
|
||||
//Response.End();
|
||||
}
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
Response.Buffer = true;
|
||||
downloadMore();
|
||||
}
|
||||
}
|
||||
|
||||
private string getCanDownFile(string fileName)
|
||||
{
|
||||
string[] extArr = new string[] { ".cdr", ".zip", ".rar", ".pdf" };
|
||||
foreach (string ext in extArr)
|
||||
{
|
||||
string fname = fileName + ext;
|
||||
if (File.Exists(fname))
|
||||
{
|
||||
return fname;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
static bool running = false;
|
||||
|
||||
private void downloadMore()
|
||||
{
|
||||
if (running)
|
||||
{
|
||||
conSuc("运行中!");
|
||||
return;
|
||||
}
|
||||
running = true;
|
||||
|
||||
var identity = WindowsIdentity.GetCurrent();
|
||||
var principal = new WindowsPrincipal(identity);
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
using (identity.Impersonate())
|
||||
{
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] buffer = null;
|
||||
List<string> addFiles = new List<string>();
|
||||
List<string> addCtid = new List<string>();
|
||||
using (ZipFile file = ZipFile.Create(ms))
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
});
|
||||
|
||||
conSuc("运行结束!");
|
||||
//FileOssUp();
|
||||
}
|
||||
|
||||
|
||||
private string formatMemo(object memo)
|
||||
{
|
||||
string m = memo.ToString();
|
||||
m = m.Replace("\\", "").Replace("/", "").Replace(":", "").Replace("*", "").Replace("?", "").Replace("<", "").Replace(">", "").Replace("|", "");
|
||||
return m;
|
||||
}
|
||||
|
||||
private void copyFile(string date, string supplier, string file)
|
||||
{
|
||||
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))
|
||||
{
|
||||
File.Copy(file, path + "\\" + fname, true);
|
||||
}
|
||||
}
|
||||
|
||||
private string getDesignTime(object v)
|
||||
{
|
||||
if (v.ToString() == "") return "";
|
||||
return Convert.ToDateTime(v).ToString("yyyyMMdd");
|
||||
}
|
||||
|
||||
private string getDesignDate(object v)
|
||||
{
|
||||
return DateTime.Now.ToString("yyyy-MM-dd");
|
||||
/*if (v.ToString() == "") return "";
|
||||
return Convert.ToDateTime(v).ToString("yyyy-MM-dd");*/
|
||||
}
|
||||
|
||||
private void FileOssUp()
|
||||
{
|
||||
// yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
||||
var endpoint = "https://oss-cn-fuzhou.aliyuncs.com";
|
||||
// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
|
||||
var accessKeyId = "LTAI5tE7wuNkeT9jZ42bQnyr";
|
||||
var accessKeySecret = "NnutvWhKl4HbQFSad3HosYbCkEkbjN";
|
||||
// 填写Bucket名称,例如examplebucket。
|
||||
var bucketName = "dfdiyfile";
|
||||
// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
|
||||
var objectName = "supplierFile/test.zip";
|
||||
|
||||
// 填写Bucket所在地域对应的Region。以华东1(杭州)为例,Region填写为cn-hangzhou。
|
||||
string region = "cn-fuzhou";
|
||||
|
||||
// 创建ClientConfiguration实例,按照您的需要修改默认参数。
|
||||
var conf = new ClientConfiguration();
|
||||
|
||||
// 设置v4签名。
|
||||
conf.SignatureVersion = SignatureVersion.V4;
|
||||
|
||||
// 创建OssClient实例。
|
||||
var client = new OssClient(endpoint, accessKeyId, accessKeySecret, conf);
|
||||
client.SetRegion(region);
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] buffer = null;
|
||||
using (ZipFile file = ZipFile.Create(ms))
|
||||
{
|
||||
|
||||
file.BeginUpdate();
|
||||
//file.NameTransform = new ZipNameTransform();
|
||||
file.NameTransform = new MyNameTransfom();
|
||||
|
||||
file.Add("C:\\Users\\231010\\Downloads\\setup.exe");
|
||||
file.CommitUpdate();
|
||||
buffer = new byte[ms.Length];
|
||||
ms.Position = 0;
|
||||
ms.Read(buffer, 0, buffer.Length); //读取文件内容(1次读ms.Length/1024M)
|
||||
ms.Flush();
|
||||
ms.Close();
|
||||
|
||||
}
|
||||
MemoryStream requestContent = new MemoryStream(buffer);
|
||||
// 上传文件。
|
||||
client.PutObject(bucketName, objectName, requestContent);
|
||||
Debug.WriteLine("Put object succeeded");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine("Put object failed" + ex.Message);
|
||||
}
|
||||
|
||||
|
||||
conSuc("上传成功!");
|
||||
return;
|
||||
}
|
||||
/// 批量进行多个文件压缩到一个文件
|
||||
/// </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)
|
||||
{
|
||||
|
||||
// yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
||||
var endpoint = "https://oss-cn-fuzhou.aliyuncs.com";
|
||||
// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
|
||||
var accessKeyId = "LTAI5tE7wuNkeT9jZ42bQnyr";
|
||||
var accessKeySecret = "NnutvWhKl4HbQFSad3HosYbCkEkbjN";
|
||||
// 填写Bucket名称,例如examplebucket。
|
||||
var bucketName = "dfdiyfile";
|
||||
// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
|
||||
var objectName = "exampledir/exampleobject.txt";
|
||||
// 填写字符串。
|
||||
var objectContent = "More than just cloud.";
|
||||
// 填写Bucket所在地域对应的Region。以华东1(杭州)为例,Region填写为cn-hangzhou。
|
||||
const string region = "oss-cn-fuzhou";
|
||||
|
||||
// 创建ClientConfiguration实例,按照您的需要修改默认参数。
|
||||
var conf = new ClientConfiguration();
|
||||
|
||||
// 设置v4签名。
|
||||
conf.SignatureVersion = SignatureVersion.V4;
|
||||
|
||||
// 创建OssClient实例。
|
||||
var client = new OssClient(endpoint, accessKeyId, accessKeySecret, conf);
|
||||
client.SetRegion(region);
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] buffer = null;
|
||||
using (ZipFile file = ZipFile.Create(ms))
|
||||
{
|
||||
|
||||
file.BeginUpdate();
|
||||
//file.NameTransform = new ZipNameTransform();
|
||||
file.NameTransform = new MyNameTransfom();
|
||||
|
||||
file.Add("C:\\Users\\231010\\Downloads\\setup.exe");
|
||||
file.CommitUpdate();
|
||||
buffer = new byte[ms.Length];
|
||||
ms.Position = 0;
|
||||
ms.Read(buffer, 0, buffer.Length); //读取文件内容(1次读ms.Length/1024M)
|
||||
ms.Flush();
|
||||
ms.Close();
|
||||
|
||||
}
|
||||
MemoryStream requestContent = new MemoryStream(buffer);
|
||||
// 上传文件。
|
||||
client.PutObject(bucketName, objectName, requestContent);
|
||||
Console.WriteLine("Put object succeeded");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Put object failed, {0}", ex.Message);
|
||||
}
|
||||
|
||||
|
||||
conSuc("上传成功!");
|
||||
return;
|
||||
//for (int i = 0; i < addFiles.Count; i++)
|
||||
//{
|
||||
// updateIsDownSuccess(userId, addCtid[i]);
|
||||
//}
|
||||
//StringBuilder sql = new StringBuilder();
|
||||
//string tids = string.Join(",", addCtid);
|
||||
//sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6 where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
|
||||
//CeErpTradeCell.ExecuteNonQuery(sql.ToString());
|
||||
//sql = new StringBuilder();
|
||||
//sql.AppendFormat("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"), (int)OrderState.下单完成, userId, "下载设计文件");
|
||||
//CeErpTradeCell.ExecuteNonQuery(sql.ToString());
|
||||
}
|
||||
|
||||
//public static object downfileObj = new object();
|
||||
private void downLoadFile(int userId, string ctid, string file, int onlyDownFile, int isFromClient)
|
||||
{
|
||||
string filePath = file;
|
||||
string dfile = Path.GetFileName(file);
|
||||
|
||||
FileStream fs = new FileStream(filePath, FileMode.Open);
|
||||
byte[] bytes = new byte[(int)fs.Length];
|
||||
fs.Read(bytes, 0, bytes.Length);
|
||||
fs.Close();
|
||||
|
||||
|
||||
Response.Clear();
|
||||
//
|
||||
Response.ClearContent();
|
||||
Response.ClearHeaders();
|
||||
|
||||
Response.ContentType = "application/octet-stream";
|
||||
//通知浏览器下载文件而不是打开\\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-Length", bytes.Length.ToString());
|
||||
Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
Response.BinaryWrite(bytes);
|
||||
Response.Flush();
|
||||
|
||||
//updateIsDownSuccess(userId, ctid);
|
||||
//StringBuilder sql = new StringBuilder();
|
||||
//string tids = string.Join(",", ctid);
|
||||
//sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6 where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
|
||||
//CeErpTradeCell.ExecuteNonQuery(sql.ToString());
|
||||
//sql = new StringBuilder();
|
||||
//sql.AppendFormat("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"), (int)OrderState.下单完成, userId, "下载设计文件");
|
||||
//CeErpTradeCell.ExecuteNonQuery(sql.ToString());
|
||||
}
|
||||
|
||||
public static void addLog(string ctid, int userid, string con, int orderState = 0, int aftersaleState = 0)
|
||||
{
|
||||
CeErpTradeLog log = new CeErpTradeLog();
|
||||
log.tid = ctid;
|
||||
log.UserId = userid;
|
||||
log.Con = con;
|
||||
log.OrderState = orderState;
|
||||
log.AfterSaleState = aftersaleState;
|
||||
log.OperateTime = DateTime.Now;
|
||||
log.Create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user