401 lines
20 KiB
C#
401 lines
20 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using Spire.Doc;
|
|
using Spire.Doc.Documents;
|
|
using SuperMap.RealEstate.Utility;
|
|
using Business = SuperMap.RealEstate.HighWay.Running.Business;
|
|
using StorageBusiness = SuperMap.RealEstate.HighWay.Storage.Business;
|
|
|
|
namespace HighWay.WebSite.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"];
|
|
string uploadtype = context.Request.Form["uploadtype"];
|
|
string other_name = "";
|
|
if (!string.IsNullOrEmpty(context.Request.Form["OTHER_NAME"]))
|
|
{
|
|
other_name = context.Request.Form["OTHER_NAME"].ToString();
|
|
}
|
|
if (string.IsNullOrWhiteSpace(Proinst_id))
|
|
{
|
|
return;
|
|
}
|
|
//string uploadPath = uploadtype == "contract_upload" ? HttpContext.Current.Server.MapPath(
|
|
// "~/UploadImageDir/ContractTemplate/") + "\\" : HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") + "\\";
|
|
string ExtraString = System.DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
string extension = Path.GetExtension(file.FileName).ToLower();
|
|
string filename = Path.GetFileName(file.FileName).Replace(extension, "");
|
|
string uploadPath = "", imagetype = "0";
|
|
|
|
if (extension.ToLower() == ".exe")
|
|
{
|
|
RetString = "0";
|
|
return;
|
|
}
|
|
|
|
#region 文件存储路径
|
|
switch (uploadtype)
|
|
{
|
|
case "proinst_upload":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/Proinst/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
case "proinst_uploadEnd":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/Proinst/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
case "compact_upload":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/Register/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
case "upload_files":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/Document/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
//阳光公示文件上传
|
|
case "Publicity_upload":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/Publicity/") +
|
|
ExtraString + "_" + filename + "/";
|
|
imagetype = context.Request.Form["imagetype"].ToString();
|
|
break;
|
|
//合同模板文件上传
|
|
case "contract_upload":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/ContractTemplate/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
//商品审批流程文件上传
|
|
case "Commodity_upload":
|
|
if (extension.ToLower() != ".pdf")
|
|
{
|
|
RetString = "0";
|
|
return;
|
|
}
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/Commodity/Proinst/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
//公文上传
|
|
case "Document_upload":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/Document/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
case "EXPENSEBILL_upload":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/HIGHTWAYEBNEW/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
//招商管理审批流程文件上传
|
|
case "Mnangement_upload":
|
|
uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/Mnangement/Proinst/") +
|
|
ExtraString + "_" + filename + "/";
|
|
break;
|
|
|
|
}
|
|
#endregion
|
|
|
|
SuperMap.RealEstate.ServiceModel.Transaction _Transaction = new SuperMap.RealEstate.ServiceModel.Transaction();
|
|
if (file != null)
|
|
{
|
|
//ImageObject _ImageObject = new ImageObject();
|
|
//if (!Directory.Exists(uploadPath))
|
|
//{
|
|
// Directory.CreateDirectory(uploadPath);
|
|
//}
|
|
//string webFilePath = uploadPath + filename + ExtraString + extension; // 服务器端文件路径
|
|
//file.SaveAs(uploadPath + filename + ExtraString + extension);
|
|
ImageObject _ImageObject = new ImageObject();
|
|
if (!Directory.Exists(uploadPath))
|
|
{
|
|
Directory.CreateDirectory(uploadPath);
|
|
}
|
|
string webFilePath = uploadPath + filename + extension; // 服务器端文件路径
|
|
file.SaveAs(uploadPath + filename + extension);
|
|
if (uploadtype == "contract_upload")
|
|
{
|
|
if (File.Exists(webFilePath))
|
|
{
|
|
try
|
|
{
|
|
//file.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件
|
|
Spire.Doc.Document doc = new Spire.Doc.Document();
|
|
doc.LoadFromFile(webFilePath);
|
|
//PictureWatermark picture = new PictureWatermark();
|
|
//picture.Picture = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(
|
|
// "~/CreateWord/WaterMarkImage/watermark.png"));
|
|
//picture.Scaling = 80;
|
|
//doc.Watermark = picture;
|
|
doc.SaveToFile(webFilePath);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SuperMap.RealEstate.Utility.ErrorLogHelper.Write(ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
#region 文件路径存储
|
|
switch (uploadtype)
|
|
{
|
|
case "proinst_upload":
|
|
case "Commodity_upload":
|
|
using (Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(_Transaction))
|
|
{
|
|
//_ATTACHMENT.ATTACHMENT_NAME = filename + ExtraString + extension;
|
|
_ATTACHMENT.ATTACHMENT_DESC = filename + extension;
|
|
_ATTACHMENT.PRESONNAME = "/Proinst/" + ExtraString + "_" + filename;
|
|
_ATTACHMENT.CREATEDATE = DateTime.Now;
|
|
_ATTACHMENT.PROINST_ID = int.Parse(Proinst_id);
|
|
_ATTACHMENT.OTHER_NAME = other_name;
|
|
_ATTACHMENT.Insert();
|
|
string fname = _ATTACHMENT.ATTACHMENT_NAME;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _ATTACHMENT.ATTACHMENT_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
case "proinst_uploadEnd":
|
|
using (StorageBusiness.ATTACHMENT _ATTACHMENT = new StorageBusiness.ATTACHMENT(_Transaction))
|
|
{
|
|
//_ATTACHMENT.ATTACHMENT_NAME = filename + ExtraString + extension;
|
|
_ATTACHMENT.ATTACHMENT_DESC = filename + extension;
|
|
_ATTACHMENT.PRESONNAME = "/Proinst/" + ExtraString + "_" + filename;
|
|
_ATTACHMENT.CREATEDATE = DateTime.Now;
|
|
_ATTACHMENT.PROINST_ID = int.Parse(Proinst_id);
|
|
_ATTACHMENT.OTHER_NAME = other_name;
|
|
_ATTACHMENT.Insert();
|
|
string fname = _ATTACHMENT.ATTACHMENT_NAME;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _ATTACHMENT.ATTACHMENT_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
case "Mnangement_upload":
|
|
using (Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(_Transaction))
|
|
{
|
|
//_ATTACHMENT.ATTACHMENT_NAME = filename + ExtraString + extension;
|
|
_ATTACHMENT.ATTACHMENT_DESC = filename + extension;
|
|
_ATTACHMENT.PRESONNAME = "/Proinst/" + ExtraString + "_" + filename;
|
|
_ATTACHMENT.CREATEDATE = DateTime.Now;
|
|
_ATTACHMENT.PROINST_ID = int.Parse(Proinst_id);
|
|
_ATTACHMENT.OTHER_NAME = other_name;
|
|
_ATTACHMENT.Insert();
|
|
string fname = _ATTACHMENT.ATTACHMENT_NAME;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _ATTACHMENT.ATTACHMENT_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
case "Document_upload":
|
|
using (Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(_Transaction))
|
|
{
|
|
//_ATTACHMENT.ATTACHMENT_NAME = filename + ExtraString + extension;
|
|
_ATTACHMENT.ATTACHMENT_DESC = filename + extension;
|
|
_ATTACHMENT.PRESONNAME = "/Document/" + ExtraString + "_" + filename;
|
|
_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 "EXPENSEBILL_upload":
|
|
using (Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(_Transaction))
|
|
{
|
|
//_ATTACHMENT.ATTACHMENT_NAME = filename + ExtraString + extension;
|
|
_ATTACHMENT.ATTACHMENT_DESC = filename + extension;
|
|
_ATTACHMENT.PRESONNAME = "/" + ExtraString + "_" + filename;
|
|
_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 "compact_upload":
|
|
using (StorageBusiness.COMPACTFILE _COMPACTFILE = new StorageBusiness.COMPACTFILE(_Transaction))
|
|
{
|
|
//_COMPACTFILE.COMPACTFILE_PATH = filename + ExtraString + extension;
|
|
_COMPACTFILE.COMPACTFILE_NAME = filename + extension;
|
|
_COMPACTFILE.COMPACTFILE_DESC = "/Register/" + ExtraString + "_" + filename;
|
|
_COMPACTFILE.COMPACTFILE_CREATEDATE = DateTime.Now;
|
|
_COMPACTFILE.REGISTERCOMPACT_ID = int.Parse(Proinst_id);
|
|
_COMPACTFILE.Insert();
|
|
string fname = _COMPACTFILE.COMPACTFILE_PATH;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _COMPACTFILE.COMPACTFILE_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
case "upload_files":
|
|
if (extension != ".exe")
|
|
{
|
|
using (StorageBusiness.IMAGE _IMAGE = new StorageBusiness.IMAGE(_Transaction))
|
|
{
|
|
//_IMAGE.IMAGE_URL = filename + ExtraString + extension;
|
|
_IMAGE.IMAGE_DESC = filename + extension;
|
|
_IMAGE.IMAGE_PATH = "/Document/" + "" + ExtraString + "_" + filename;
|
|
_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 + "\"}";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
RetString = "0";
|
|
}
|
|
break;
|
|
case "Publicity_upload":
|
|
if (extension != ".exe")
|
|
{
|
|
using (StorageBusiness.IMAGE _IMAGE = new StorageBusiness.IMAGE(_Transaction))
|
|
{
|
|
//_IMAGE.IMAGE_URL = filename + ExtraString + extension;
|
|
_IMAGE.IMAGE_DESC = filename + extension;
|
|
_IMAGE.IMAGE_PATH = "/Publicity/" + "" + ExtraString + "_" + filename;
|
|
_IMAGE.IMAGE_DATE = DateTime.Now;
|
|
_IMAGE.IMAGE_TYPE = short.Parse(imagetype);
|
|
_IMAGE.Table_ID = int.Parse(Proinst_id);
|
|
_IMAGE.Table_Name = "T_PUBLICITY";
|
|
_IMAGE.Insert();
|
|
string fname = _IMAGE.IMAGE_URL;//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _IMAGE.Image_ID_Encrypt + "\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
RetString = "0";
|
|
}
|
|
break;
|
|
case "contract_upload":
|
|
using (StorageBusiness.CONTRACTTEMPLATE _CONTRACTTEMPLATE = new StorageBusiness.CONTRACTTEMPLATE(_Transaction))
|
|
{
|
|
_CONTRACTTEMPLATE.CONTRACTTEMPLATE_DESC = filename + extension;
|
|
//_CONTRACTTEMPLATE.TEMPLATE_NAME = filename;
|
|
_CONTRACTTEMPLATE.TEMPLATE_PATH = ExtraString + "_" + filename;
|
|
_CONTRACTTEMPLATE.TEMPLATE_CREATEDATE = DateTime.Now;
|
|
_CONTRACTTEMPLATE.PRODEF_ID = Proinst_id.Split(',')[0];
|
|
_CONTRACTTEMPLATE.CONTRACT_TYPE = int.Parse(Proinst_id.Split(',')[1]);
|
|
_CONTRACTTEMPLATE.OPERATE_DATE = DateTime.Now;
|
|
_CONTRACTTEMPLATE.Insert();
|
|
string fname = _CONTRACTTEMPLATE.TEMPLATE_PATH;
|
|
//HttpUtility.HtmlEncode(_ATTACHMENT.ATTACHMENT_NAME);
|
|
RetString = "{\"imageid\" : \"" + _CONTRACTTEMPLATE.CONTRACTTEMPLATE_ID_Encrypt +
|
|
"\", \"imagename\" : \"" + fname + "\"}";
|
|
}
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
_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>
|
|
/// 文件保存操作
|
|
/// </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
|
|
}
|
|
|
|
#region 图片对象
|
|
public class ImageObject
|
|
{
|
|
public string imagename
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
public string imageid
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
}
|
|
#endregion
|
|
} |