using BimWeb.DataConnection;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Drawing;
namespace BimWeb.BimWebService
{
/// <summary>
/// RevitUpload 的摘要说明
/// </summary>
[WebService(Namespace = "SxanBimWebService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class RevitUpload : System.Web.Services.WebService
{
//连接数据库
MSSqlHelper MHelper = new MSSqlHelper();
//web.config中图片文件路径的配置
public string RevitFileUrl = ConfigurationManager.AppSettings["UploadRevits"].ToString();
public string ImageFileUrl = ConfigurationManager.AppSettings["UploadImage"].ToString();
#region 获取表BimWeb_ModelType中的数据,返回datatable
/// <summary>
/// 获取表BimWeb_ModelType中的[Id],[Name],[ParentIndexId]
/// </summary>
/// <returns></returns>
[WebMethod]
public DataTable getCatagories()
{
string sqlC = "select Id,Name,ParentIndexId from BimWeb_ModelType ";
DataTable dtModelType = MHelper.ExecuteDataTable(sqlC, "BimWeb_ModelType");
return dtModelType;
}
#endregion
#region 获取表BimWeb_ModelSet中的数据,返回datatable
/// <summary>
/// 获取表BimWeb_ModelSet中的[Id],[Name]
/// </summary>
/// <returns></returns>
[WebMethod]
public DataTable getModelSet()
{
string sqlModelSet = "select Id,Name from BimWeb_ModelSet ";
DataTable dtModelSet = MHelper.ExecuteDataTable(sqlModelSet, "BimWeb_ModelSet");
return dtModelSet;
}
#endregion
#region 上传单个族文件Revit 对应的表: BimWeb_Model
/// <summary>
/// 上传单个族文件Revit 对应的表: BimWeb_Model
/// </summary>
/// <param name="uniquid">唯一标识UniqueId</param>
/// <param name="name">Name</param>
/// <param name="content">RFCModelFilePath</param>
/// <param name="categoryid">ModelTypeIndexId</param>
/// <param name="thumb">D3ModelImagePath</param>
/// <returns></returns>
[WebMethod]
public int UploadRevit(string uniquid, string name, byte[] content, int categoryid, int setID, byte[] thumb = null)
{
//包括新增和修改(用uniquid区分修改或新增,判断该uniquid是否已存在。如果是修改的话,把BimWeb_ModelInfo和BimWeb_ModelStandard中的相关数据删掉)
//content 目录 。存库RFCModelFilePath
//categoryid 对应ModelTypeIndexId
//thumb 判断有无,存库,对应 D3ModelImagePath
int backUniqueId = -1;
//已经存在的文件地址RFCModelFilePath
string FileName = "";
string thumbFile = "";
int BimWeb_ModelID = 0;
//根据uniquid查询表BimWeb_Model中是否已经存在该数据
if (uniquid != "" && uniquid != null)
{
string sqlModelIsExit = "select * from BimWeb_Model where UniqueId='" + uniquid + "'";
DataTable dtIsExit = MHelper.ExecuteDataTable(sqlModelIsExit, "BimWeb_Model");
if (dtIsExit.Rows.Count > 0)
{
backUniqueId = Convert.ToInt16(dtIsExit.Rows[0]["Id"]);
FileName = Convert.ToString(dtIsExit.Rows[0]["RFCModelFilePath"]);
thumbFile = Convert.ToString(dtIsExit.Rows[0]["D3ModelImagePath"]);
BimWeb_ModelID = Convert.ToInt16(dtIsExit.Rows[0]["Id"]);
//数据已经存在的文件,删除本地文件RFCModelFilePath
if (FileName != "")
{
//判断该文件是否已存在
// string RfaFile = FileName;
string NewFile2 = Server.MapPath("~/" + FileName);
if (System.IO.File.Exists(NewFile2)) System.IO.File.Delete(NewFile2);
}
string NewFileName2 = uniquid + ".rfa";
string RfaFile2 = RevitFileUrl + NewFileName2;
string NewFile3 = Server.MapPath("~/" + RevitFileUrl) + NewFileName2;
if (System.IO.File.Exists(NewFile3)) System.IO.File.Delete(NewFile3);
System.IO.File.WriteAllBytes(NewFile3, content);
//D3ModelImagePath数据已存在,删除本地文件
//string NewFilethumbName3 = thumbFile;
//string ImageFile3 = ImageFileUrl + NewFilethumbName3;
string NewFilethumbName4 = uniquid + ".jpg";
string ImageFile4 = ImageFileUrl + NewFilethumbName4;
if (thumbFile != "")
{
//删除文件
string NewImageFile2 = Server.MapPath("~/" + thumbFile);
if (System.IO.File.Exists(NewImageFile2)) System.IO.File.Delete(NewImageFile2);
//写入文件
using (System.IO.MemoryStream mem = new MemoryStream(thumb))
{
string NewFileJpg = Server.MapPath("~/" + ImageFileUrl) + NewFilethumbName4;
System.Drawing.Bitmap bmp = System.Drawing.Bitmap.FromStream(mem) as System.Drawing.Bitmap;
bmp.Save(NewFileJpg);
}
}
//数据已存在,则修改表BimWeb_Model中的数据,删除BimWeb_ModelInfo和BimWeb_ModelStandard中的相关数据
string UpdateBimWeb_Model = "update BimWeb_Model set Name='" + name + "',RFCModelFilePath='" + RfaFile2 + "',ModelTypeIndexId='" + categoryid + "',D3ModelImagePath='" + ImageFile4 + "',ModelSetIndexId=" + setID + " where UniqueId='" + uniquid + "';";
int backRows = MHelper.ExecuteNonQuery(UpdateBimWeb_Model);
if (backRows != -1)
{
//修改成功后,删除表BimWeb_ModelInfo和BimWeb_ModelStandard中的相关数据
string DelBimWeb_ModelInfo = "delete from BimWeb_ModelInfo where ModelIndexId=" + BimWeb_ModelID;
int delBack = MHelper.ExecuteNonQuery(DelBimWeb_ModelInfo);
if (delBack > 0)
{
//删除表BimWeb_ModelInfo成功
}
else
{
//删除失败
}
string DelBimWeb_ModelStandard = "delete from BimWeb_ModelStandard where ModelId="+ BimWeb_ModelID;
int delBackS = MHelper.ExecuteNonQuery(DelBimWeb_ModelStandard);
if (delBackS > 0)
{
//删除表BimWeb_ModelStandard成功
}
else
{
//删除失败
}
}
}
else
{
//将字节流转换成文件保存本地 RFCModelFilePath
string NewFileName2 = uniquid + ".rfa";
string RfaFile = RevitFileUrl + NewFileName2;
string NewFile2 = Server.MapPath("~/" + RevitFileUrl) + NewFileName2;
if (System.IO.File.Exists(NewFile2)) System.IO.File.Delete(NewFile2);
System.IO.File.WriteAllBytes(NewFile2, content);
string NewFilethumbName2 = uniquid + ".jpg";
string ImageFile = ImageFileUrl + NewFilethumbName2;
if (thumb != null)
{
using (System.IO.MemoryStream mem = new MemoryStream(thumb))
{
string NewFileJpg = Server.MapPath("~/" + ImageFileUrl) + NewFilethumbName2;
System.Drawing.Bitmap bmp = System.Drawing.Bitmap.FromStream(mem) as System.Drawing.Bitmap;
bmp.Save(NewFileJpg);
}
}
//数据不存在,新增BimWeb_Model表中的数据
string InsertBimWeb_Model = "insert into BimWeb_Model(UniqueId,Name,RFCModelFilePath,ModelTypeIndexId,D3ModelImagePath,ModelSetIndexId) values('" + uniquid + "','" + name + "','" + RfaFile + "'," + categoryid + ",'" + ImageFile + "'," + setID + ");select @@IDENTITY";
backUniqueId = MHelper.ExecuteScalerB(InsertBimWeb_Model);
if (backUniqueId != -1)
{
//新增成功
}
else
{
//新增失败
}
}
}
return backUniqueId;//id
}
#endregion
#region 上传参数 对应表 BimWeb_ModelInfo
/// <summary>
/// ModelIndexId 表对应modelid
/// </summary>
/// <param name="modelid"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
[WebMethod]
//id上个方法返回的值
public bool UploadRevitParameters(int modelid, string key, string value)
{
string InsertModelInfo = "insert into BimWeb_ModelInfo(ModelIndexId,[Key],Value) values('" + modelid + "','" + key + "','" + value + "')";
int backValue = MHelper.ExecuteNonQuery(InsertModelInfo);
//根据ModelIndexIdhe key(列表)
if (backValue > 0)
{
return true;
}
else
{
return false;
}
}
#endregion
#region 上传 BimWeb_ModelStandard
/// <summary>
/// UploadRevit方法返回的ID
/// </summary>
/// <param name="zuname"></param>
/// <param name="zufile"></param>
/// <param name="categoryid"></param>
/// <returns></returns>
[WebMethod]
public bool UploadRevitTypes(int modelid, string name, byte[] BimWeb_ModelStandard = null)
{
//BimWeb_ModelStandard 图片保存到本地,存库。
string NewFilethumbName2 = Guid.NewGuid().ToString() + ".jpg";
string ImageFile = ImageFileUrl + NewFilethumbName2;
if (BimWeb_ModelStandard != null)
{
using (System.IO.MemoryStream mem = new MemoryStream(BimWeb_ModelStandard))
{
string NewFileJpg = Server.MapPath("~/" + ImageFileUrl) + NewFilethumbName2;
System.Drawing.Bitmap bmp = System.Drawing.Bitmap.FromStream(mem) as System.Drawing.Bitmap;
bmp.Save(NewFileJpg);
}
}
string InsertModelStandard = "insert into BimWeb_ModelStandard(Name,D3ModelImagePath,ModelId) values('" + name + "','" + ImageFile + "','" + modelid + "')";
if (MHelper.ExecuteNonQuery(InsertModelStandard) > 0)
{
return true;
}
else
{
return false;
}
}
#endregion
}
}
WebService 类文件内容 RevitUpload
最新推荐文章于 2018-03-07 17:34:13 发布