chore: 初始化 VPSA ASP.NET 管理端
This commit is contained in:
103
submit/MESUploadFile.ashx
Normal file
103
submit/MESUploadFile.ashx
Normal file
@@ -0,0 +1,103 @@
|
||||
<%@ WebHandler Language="C#" Class="UploadHandler" %>
|
||||
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Web.Services;
|
||||
using System.Text;
|
||||
using DataLinkMesWork;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
public class UploadHandler : IHttpHandler
|
||||
{
|
||||
private static string connectionString = System.Configuration.ConfigurationManager.AppSettings.GetValues("ConnectionString")[0].ToString();
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
string filePath = "../webpage/part";
|
||||
filePath = HttpContext.Current.Server.MapPath(filePath);
|
||||
string num = HttpContext.Current.Request["num"];
|
||||
string tableName = HttpContext.Current.Request["tableName"];
|
||||
string result = "";
|
||||
bool isOK;
|
||||
try
|
||||
{
|
||||
Guid guid = Guid.NewGuid();
|
||||
string uid = guid.ToString().Replace("-", "").ToUpper();
|
||||
HttpFileCollection files = context.Request.Files;
|
||||
if (files.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
HttpPostedFile hpFile = files[0];
|
||||
if (hpFile.ContentLength > 0)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(hpFile.FileName);
|
||||
string suffix = fileName.Split(new Char[] { '.' })[1];
|
||||
string name = fileName.Split(new Char[] { '.' })[0];
|
||||
string sql = "insert into " + tableName + " (num, uid, name, suffix, 是否启用) values(" + num + ",'" + uid + "','" + name + "','" + suffix + "'," + '1' + ")";
|
||||
isOK = DataLinkMesWork.DataLink.ExecuteNonQuery(sql);
|
||||
//isOK = SQLCommon.ExecuteNonQuery(sql, connectionString, out result);
|
||||
if (isOK)
|
||||
{
|
||||
filePath = filePath + "/" + uid + "." + suffix;
|
||||
hpFile.SaveAs(filePath);
|
||||
result = "[{ \"result\":\"1\"}]";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "[{ \"result\":\"0\"}]";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//增加文件保存到数据库的功能
|
||||
byte[]bytes = new byte[files[0].InputStream.Length];
|
||||
files[0].InputStream.Read(bytes, 0, bytes.Length);
|
||||
string procedureName = "_文件存储_高精_增加";
|
||||
string errorMessage;
|
||||
SqlParameter []thisParms = new SqlParameter[5];
|
||||
thisParms[0] = new SqlParameter("@业务代码", 10);
|
||||
thisParms[1] = new SqlParameter("@文件标识", uid);
|
||||
thisParms[2] = new SqlParameter("@文件名称", name);
|
||||
thisParms[3] = new SqlParameter("@文件后缀", suffix);
|
||||
thisParms[4] = new SqlParameter("@文件内容", bytes);
|
||||
DataLinkMesWork.DataLink.ExecuteStoredProcedure(procedureName, ref thisParms, out errorMessage);
|
||||
|
||||
if(DataLinkMesWork.DataLink.isBakup=="1")
|
||||
{
|
||||
DataLinkMesWork.DataLink.ExecuteNonQuery_Bakup(sql);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.Write(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = "[{ \"result\":\"0\"}]";
|
||||
}
|
||||
context.Response.Write(result);
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user