225 lines
8.9 KiB
C#
225 lines
8.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using Business = SuperMap.RealEstate.Finance.Running.Business;
|
|
using StorageBusiness = SuperMap.RealEstate.Finance.Storage.Business;
|
|
|
|
namespace SuperMap.RealEstate.Finance.Handler
|
|
{
|
|
/// <summary>
|
|
/// ModuleObject_ajax 的摘要说明
|
|
/// </summary>
|
|
public class ModuleObject_ajax : IHttpHandler
|
|
{
|
|
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
|
|
context.Request.ContentEncoding = Encoding.GetEncoding("UTF-8");
|
|
context.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
|
|
context.Response.Charset = "UTF-8";
|
|
|
|
string RetString = string.Empty;
|
|
HttpPostedFile file = context.Request.Files["Filedata"];
|
|
|
|
string Proinst_id = context.Request.Form["PROINST_ID"].ToString();
|
|
string uploadtype = context.Request.Form["uploadtype"].ToString();
|
|
string attachmentType = context.Request.Form["attachmentType"];
|
|
|
|
|
|
double size = GetMB(file.ContentLength);
|
|
if (size > 10)
|
|
{
|
|
RetString = "{\"imageid\" : 0}";
|
|
context.Response.Write(RetString);
|
|
}
|
|
else
|
|
{
|
|
if (Proinst_id == "")
|
|
return;
|
|
string uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/FINANCEPROINST/") + "\\";
|
|
string ExtraString = System.DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
string extension = Path.GetExtension(file.FileName).ToLower();
|
|
string filename = Path.GetFileName(file.FileName).Replace(extension, "");
|
|
SuperMap.RealEstate.ServiceModel.Transaction _Transaction = new SuperMap.RealEstate.ServiceModel.Transaction();
|
|
if (file != null)
|
|
{
|
|
if (extension.ToLower() == ".exe")
|
|
{
|
|
RetString = "0";
|
|
return;
|
|
}
|
|
|
|
ImageObject _ImageObject = new ImageObject();
|
|
if (!Directory.Exists(uploadPath))
|
|
{
|
|
Directory.CreateDirectory(uploadPath);
|
|
}
|
|
file.SaveAs(uploadPath + filename + ExtraString + extension);
|
|
switch (uploadtype)
|
|
{
|
|
case "proinst_upload":
|
|
case "proinst_upload1000":
|
|
case "proinst_upload2000":
|
|
case "proinst_upload3000":
|
|
case "proinst_upload4000":
|
|
using (Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(_Transaction))
|
|
{
|
|
_ATTACHMENT.ATTACHMENT_NAME = filename + ExtraString + extension;
|
|
_ATTACHMENT.CREATEDATE = DateTime.Now;
|
|
_ATTACHMENT.PROINST_ID = int.Parse(Proinst_id);
|
|
_ATTACHMENT.ATTACHMENT_DESC = !string.IsNullOrEmpty(attachmentType) ? attachmentType : "";
|
|
_ATTACHMENT.Insert();
|
|
string fname = _ATTACHMENT.ATTACHMENT_NAME;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _ATTACHMENT.ATTACHMENT_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
case "finance_upload":
|
|
using (StorageBusiness.ATTACHMENT _ATTACHMENT = new StorageBusiness.ATTACHMENT(_Transaction))
|
|
{
|
|
_ATTACHMENT.ATTACHMENT_NAME = filename + ExtraString + extension;
|
|
_ATTACHMENT.CREATEDATE = DateTime.Now;
|
|
_ATTACHMENT.PROINST_ID = int.Parse(Proinst_id);
|
|
_ATTACHMENT.Insert();
|
|
string fname = _ATTACHMENT.ATTACHMENT_NAME;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _ATTACHMENT.ATTACHMENT_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
case "upload_files":
|
|
using (StorageBusiness.IMAGE _IMAGE = new StorageBusiness.IMAGE(_Transaction))
|
|
{
|
|
_IMAGE.IMAGE_URL = filename + ExtraString + extension;
|
|
_IMAGE.IMAGE_DATE = DateTime.Now;
|
|
_IMAGE.TABLE_ID = int.Parse(Proinst_id);
|
|
_IMAGE.TABLE_NAME = "T_DOCUMENT";
|
|
_IMAGE.Insert();
|
|
string fname = _IMAGE.IMAGE_URL;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _IMAGE.IMAGE_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
}
|
|
_Transaction.AutoCommit();
|
|
context.Response.ContentType = "text/plain";
|
|
//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
|
|
context.Response.Write(RetString);
|
|
}
|
|
else
|
|
{
|
|
context.Response.Write(RetString);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
#region webUpload使用方法
|
|
//WebUpload使用方法
|
|
//public void ProcessRequest(HttpContext context)
|
|
//{
|
|
|
|
// //string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file
|
|
// string id = HttpContext.Current.Request.Form["id"];
|
|
// string name = HttpContext.Current.Request.Form["name"];
|
|
// string type = HttpContext.Current.Request.Form["type"];
|
|
// string lastModifiedDate = HttpContext.Current.Request.Form["lastModifiedDate"];
|
|
// int size = int.Parse(HttpContext.Current.Request.Form["size"]);
|
|
// //HttpPostedFileBase _HttpPostedFileBase = HttpContext.Current.Request.Files;
|
|
|
|
// //上传文件
|
|
// string action_type = HttpContext.Current.Request.Form["action_type"];
|
|
|
|
// string reString = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
// string CurrentGuid = string.Empty;
|
|
|
|
|
|
// context.Response.ContentType = "text/plain";
|
|
// context.Response.Write(reString);
|
|
// context.Response.End();
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
/// 将B转换为MB
|
|
/// </summary>
|
|
/// <param name="b"></param>
|
|
/// <returns></returns>
|
|
private double GetMB(long b)
|
|
{
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
b /= 1024;
|
|
}
|
|
return b;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 文件保存操作
|
|
/// </summary>
|
|
/// <param name="basePath"></param>
|
|
private void SaveFile(string basePath = "~/Upload/Images/")
|
|
{
|
|
var name = string.Empty;
|
|
basePath = (basePath.IndexOf("~") > -1) ? System.Web.HttpContext.Current.Server.MapPath(basePath) :
|
|
basePath;
|
|
HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
|
|
//如果目录不存在,则创建目录
|
|
if (!Directory.Exists(basePath))
|
|
{
|
|
Directory.CreateDirectory(basePath);
|
|
}
|
|
|
|
var suffix = files[0].ContentType.Split('/');
|
|
//获取文件格式
|
|
var _suffix = suffix[1].Equals("jpeg", StringComparison.CurrentCultureIgnoreCase) ? "" : suffix[1];
|
|
var _temp = System.Web.HttpContext.Current.Request["name"];
|
|
//如果不修改文件名,则创建随机文件名
|
|
if (!string.IsNullOrEmpty(_temp))
|
|
{
|
|
name = _temp;
|
|
}
|
|
else
|
|
{
|
|
Random rand = new Random(24 * (int)DateTime.Now.Ticks);
|
|
name = rand.Next() + "." + _suffix;
|
|
}
|
|
//文件保存
|
|
var full = basePath + name;
|
|
files[0].SaveAs(full);
|
|
var _result = "{\"jsonrpc\" : \"2.0\", \"result\" : null, \"id\" : \"" + name + "\"}";
|
|
System.Web.HttpContext.Current.Response.Write(_result);
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
public class ImageObject
|
|
{
|
|
public string imagename
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
public string imageid
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
}
|
|
} |