246 lines
10 KiB
C#
246 lines
10 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
|
||
using System.Collections;
|
||
using System.Text;
|
||
using System.IO;
|
||
using SuperMap.RealEstate.Web.UI;
|
||
using SuperMap.RealEstate.HousingSecurity.APIPlugs;
|
||
using SuperMap.RealEstate.HousingSecurity.APIPlugs.flashuploader;
|
||
using System.Web.Script.Serialization;
|
||
using SRAI = SuperMap.RealEstate.Archives.Image;
|
||
using SuperMap.RealEstate.HousingSecurity.Storage.Business;
|
||
using System.Data;
|
||
|
||
namespace SuperMap.RealEstate.HousingSecurity.API.upload
|
||
{
|
||
/// <summary>
|
||
/// uphousephotos 的摘要说明
|
||
/// 【提供给房屋编辑上传图片】
|
||
/// </summary>
|
||
public class uphousephotos : IHttpHandler
|
||
{
|
||
|
||
private static int _MOCK_USERID = 1;//MOCK
|
||
private static string _MOCK_USERNAME = "";//MOCK
|
||
|
||
private const string SUCCESS = "SUCCESS";
|
||
private const string ERROR = "ERROR";
|
||
|
||
|
||
private HttpContext context;
|
||
public void ProcessRequest(HttpContext context)
|
||
{
|
||
this.context = context;
|
||
|
||
//context.Response.ContentType = "text/plain";
|
||
//context.Response.Write("Hello World");
|
||
string _CaseFileID = context.Request.QueryString["CaseFileID"];
|
||
long CaseFileID = 0;
|
||
|
||
string _MaterialID = context.Request.QueryString["MaterialID"];
|
||
long MaterialID = 0;
|
||
|
||
FlashUpJsonInfo _json = null;
|
||
if (long.TryParse(_CaseFileID, out CaseFileID) && CaseFileID != 0)
|
||
{
|
||
_MOCK_USERID = (int)CaseFileID;//直接采用这个作为分割
|
||
_MOCK_USERNAME = "";
|
||
_json = UpHousePhotos(CaseFileID, MaterialID);
|
||
}
|
||
else if (long.TryParse(_MaterialID, out MaterialID) && MaterialID != 0)
|
||
{
|
||
_MOCK_USERID = (int)MaterialID;//直接采用这个作为分割
|
||
_MOCK_USERNAME = "";
|
||
_json = UpHousePhotos(CaseFileID,MaterialID);
|
||
}
|
||
else
|
||
{
|
||
_json = new FlashUpJsonInfo();
|
||
_json.state = ERROR;
|
||
_json.msg = "house(" + _CaseFileID + ") is error! ";
|
||
}
|
||
|
||
|
||
|
||
//直接输出json
|
||
context.Response.ContentType = "application/json";
|
||
Hashtable ht = new Hashtable();
|
||
ht.Add("state", _json.state);
|
||
ht.Add("msg", _json.msg);
|
||
ht.Add("title", _json.title);
|
||
ht.Add("url", _json.url);
|
||
ht.Add("original", _json.original);
|
||
ht.Add("fid", _json.fid);
|
||
|
||
StringBuilder buider = new StringBuilder();
|
||
JavaScriptSerializer json = new JavaScriptSerializer(new SimpleTypeResolver());
|
||
json.MaxJsonLength = Int32.MaxValue;
|
||
json.Serialize(ht, buider);
|
||
context.Response.Write(buider.ToString());
|
||
}
|
||
|
||
#region [图片上传] -> UpHousePhotos <- 上传房源相关图片
|
||
public FlashUpJsonInfo UpHousePhotos(long CaseFileID, long MaterialID)
|
||
{
|
||
FlashUpJsonInfo _json = new FlashUpJsonInfo();
|
||
|
||
MyUpFileInfo upfileinfo = null;
|
||
if (doupload(_json, out upfileinfo))
|
||
{
|
||
try
|
||
{
|
||
ServiceModel.Transaction _Transaction = new ServiceModel.Transaction();
|
||
|
||
//if (CaseFileID != 0)
|
||
//{
|
||
// //获取现有的扫描件数量
|
||
// SRAI.Business.ScanFile _ScanFile = new SRAI.Business.ScanFile(_Transaction);
|
||
// string sql = "select SCANFILE_INDEX from T_SCANFILE where CaseFile_ID=" + CaseFileID;
|
||
// DataTable dt = _ScanFile.ExecuteDataTable(sql);
|
||
// int count = dt.Rows.Count;
|
||
|
||
// #region 流程外上传扫描资料
|
||
// CaseFile _CaseFile = new CaseFile(_Transaction);
|
||
// _CaseFile.CaseFile_ID = CaseFileID;
|
||
// if (_CaseFile.Select())
|
||
// {
|
||
// //同时添加到房源的关联库
|
||
// using (SRAI.Business.ScanFile _ProjectImage = new SRAI.Business.ScanFile(_Transaction))
|
||
// {
|
||
// _ProjectImage.CaseFile_ID = CaseFileID;//关联外键
|
||
// _ProjectImage.ScanFile_Name = upfileinfo.Entity.memo;
|
||
// _ProjectImage.ScanFile_Blob = GetPicBlob(upfileinfo.Entity.serverAllPhysicalPath);
|
||
// _ProjectImage.ScanFile_Path = upfileinfo.Entity.serverpath + upfileinfo.Entity.serverfilename;
|
||
// _ProjectImage.ScanFile_Index = count + 1;
|
||
// //新增
|
||
// _ProjectImage.Insert();
|
||
// _Transaction.AutoCommit();
|
||
// if (_ProjectImage.ScanFile_ID.HasValue)
|
||
// {
|
||
// upfileinfo.Entity.fid = (int)_ProjectImage.ScanFile_ID;//must
|
||
// _json.fid = (int)_ProjectImage.ScanFile_ID;//fix
|
||
// count++;
|
||
// }
|
||
// }
|
||
// _CaseFile.ScanFile_Count = (short)count;
|
||
// _CaseFile.Update();
|
||
// }
|
||
// #endregion
|
||
//}
|
||
if (MaterialID!=0)
|
||
{
|
||
//获取现有的扫描件数量
|
||
SRAI.Business.ProinstScanFile _ScanFile = new SRAI.Business.ProinstScanFile(_Transaction);
|
||
string sql = "select SCANFILE_INDEX from T_ProinstScanFile where Material_ID=" + MaterialID;
|
||
DataTable dt = _ScanFile.ExecuteDataTable(sql);
|
||
int count = dt.Rows.Count;
|
||
|
||
using (SRAI.Business.ProinstScanFile _ProjectImage = new SRAI.Business.ProinstScanFile(_Transaction))
|
||
{
|
||
_ProjectImage.Material_ID = MaterialID;//关联外键
|
||
_ProjectImage.ScanFile_Name = upfileinfo.Entity.memo;
|
||
_ProjectImage.ScanFile_Blob = GetPicBlob(upfileinfo.Entity.serverAllPhysicalPath);
|
||
_ProjectImage.ScanFile_Path = upfileinfo.Entity.serverpath + upfileinfo.Entity.serverfilename;
|
||
_ProjectImage.ScanFile_Index = count + 1;
|
||
//新增
|
||
_ProjectImage.Insert();
|
||
_Transaction.AutoCommit();
|
||
if (_ProjectImage.ProinstScanFile_ID.HasValue)
|
||
{
|
||
upfileinfo.Entity.fid = (int)_ProjectImage.ProinstScanFile_ID;//must
|
||
_json.fid = (int)_ProjectImage.ProinstScanFile_ID;//fix
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_json.state = ERROR;
|
||
_json.msg = "upload file success,but save photos is error:" + ex.Message;
|
||
}
|
||
}
|
||
return _json;
|
||
}
|
||
#endregion
|
||
|
||
public byte[] GetPicBlob(string PicPath)
|
||
{
|
||
FileStream fs = new FileStream(PicPath, FileMode.Open);
|
||
byte[] byDate = new byte[fs.Length];
|
||
fs.Read(byDate, 0, byDate.Length);
|
||
fs.Close();
|
||
return byDate;
|
||
}
|
||
|
||
private bool doupload(FlashUpJsonInfo _json, out MyUpFileInfo _upfileinfo)
|
||
{
|
||
bool _isok = false;
|
||
_upfileinfo = null;
|
||
|
||
|
||
HttpRequestBase request = new HttpRequestWrapper(this.context.Request);
|
||
|
||
//Hashtable _ht = new Hashtable();
|
||
if (request.Files != null && request.Files.Count > 0)
|
||
{
|
||
//处理出需要上传的文件对象(单文件处理)
|
||
_upfileinfo = new MyUpFileInfo(request.Files[0], _MOCK_USERID);
|
||
|
||
//[处理返回的参数]
|
||
_upfileinfo.Entity.memo = GetFileFieldVal(context, "pictitle");//ueditor专用字段,用于标识title,并且记录到数据库
|
||
string _msg = string.Empty;
|
||
if (UpFlashHelper.TrySaveUpFile(_upfileinfo.HttpPostedFileBase, _MOCK_USERID, _MOCK_USERNAME, ref _upfileinfo, out _msg))
|
||
{
|
||
_isok = true;//标记成功
|
||
_json.state = SUCCESS;
|
||
_json.msg = _msg;
|
||
|
||
_json.url = _upfileinfo.GetUri();
|
||
_json.title = _upfileinfo.Entity.memo;
|
||
_json.original = _upfileinfo.Entity.filename;
|
||
_json.fid = _upfileinfo.Entity.fid;
|
||
|
||
//if (currentType != null)
|
||
// infoList.Add("currentType", currentType);
|
||
//if (originalName != null)
|
||
// infoList.Add("originalName", originalName);
|
||
|
||
}
|
||
else
|
||
{
|
||
_json.state = ERROR;
|
||
_json.msg = _msg;
|
||
//Zoyoa.Core.Utility.SecurityHelper.HtmlEncode(_msg)
|
||
//显示信息需要编码,防止JSON解析错误无法显示信息
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_json.state = ERROR;
|
||
_json.msg = "Request.Files is null";
|
||
}
|
||
|
||
return _isok;
|
||
}
|
||
private static string GetFileFieldVal(HttpContext cxt, string field)
|
||
{
|
||
string info = null;
|
||
if (cxt.Request.Form[field] != null && !String.IsNullOrEmpty(cxt.Request.Form[field]))
|
||
{
|
||
info = cxt.Request.Form[field];
|
||
}
|
||
return info;
|
||
}
|
||
|
||
public bool IsReusable
|
||
{
|
||
get
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
} |