2022-09-15 23:20:10 +08:00
|
|
|
|
using RestSharp;
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-09-05 16:36:31 +08:00
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
namespace BLL
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class HJGL_DataImportService
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void AddHJGL_DataImport(Model.HJGL_DataImport newtable)
|
|
|
|
|
|
{
|
|
|
|
|
|
Model.HJGL_DataImport table = new Model.HJGL_DataImport();
|
|
|
|
|
|
table.DataImportId = newtable.DataImportId;
|
|
|
|
|
|
table.FileId = newtable.FileId;
|
|
|
|
|
|
table.Version = newtable.Version;
|
|
|
|
|
|
table.Remark = newtable.Remark;
|
|
|
|
|
|
table.CreateMan = newtable.CreateMan;
|
|
|
|
|
|
table.CreateDate = newtable.CreateDate;
|
|
|
|
|
|
table.ProjectId = newtable.ProjectId;
|
|
|
|
|
|
table.UnitWorkId = newtable.UnitWorkId;
|
|
|
|
|
|
table.DesignProfessionalId = newtable.DesignProfessionalId;
|
|
|
|
|
|
table.ImportType = newtable.ImportType;
|
|
|
|
|
|
table.FileName = newtable.FileName;
|
|
|
|
|
|
table.FilePath = newtable.FilePath;
|
|
|
|
|
|
table.FileType = newtable.FileType;
|
|
|
|
|
|
table.FileSize = newtable.FileSize;
|
|
|
|
|
|
Funs.DB.HJGL_DataImport.InsertOnSubmit(table);
|
|
|
|
|
|
Funs.DB.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void DeleteHJGL_DataImportById(string DataImportId)
|
|
|
|
|
|
{
|
|
|
|
|
|
Model.HJGL_DataImport table = Funs.DB.HJGL_DataImport.FirstOrDefault(e => e.DataImportId == DataImportId);
|
|
|
|
|
|
if (table != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Funs.DB.HJGL_DataImport.DeleteOnSubmit(table);
|
|
|
|
|
|
Funs.DB.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据文件名称返回最新文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="FileName"></param>
|
|
|
|
|
|
/// <param name="project"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2022-10-13 18:52:45 +08:00
|
|
|
|
public static Model.HJGL_DataImport GetLatestFileByFileName(string FileName,string ImportType, string project)
|
2022-09-05 16:36:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
var q = (from x in Funs.DB.HJGL_DataImport
|
2022-10-13 18:52:45 +08:00
|
|
|
|
where x.FileName.Contains(FileName) && x.ProjectId == project&&x.ImportType==ImportType
|
2022-09-05 16:36:31 +08:00
|
|
|
|
select x
|
|
|
|
|
|
).OrderByDescending(x => x.Version).FirstOrDefault();
|
|
|
|
|
|
return q;
|
|
|
|
|
|
}
|
2022-09-23 00:01:54 +08:00
|
|
|
|
public static string ConvertFileType(object ImportType)
|
|
|
|
|
|
{
|
|
|
|
|
|
string TypeName=string.Empty;
|
|
|
|
|
|
if (ImportType != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (ImportType.ToString ())
|
|
|
|
|
|
{
|
|
|
|
|
|
case "0":
|
|
|
|
|
|
TypeName = "ISO轴测图";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "1":
|
|
|
|
|
|
TypeName = "三维模型";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "2":
|
|
|
|
|
|
TypeName = "属性文件";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "3":
|
|
|
|
|
|
TypeName = "管道预制加工图";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return TypeName;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-09-05 16:36:31 +08:00
|
|
|
|
public static List<decimal?> GetListVersionByUnitWorkId(string UnitWorkId)
|
|
|
|
|
|
{
|
|
|
|
|
|
//decimal a = 0.1M;
|
|
|
|
|
|
decimal MaxVersion = 0.9M;
|
|
|
|
|
|
var q = (from x in Funs.DB.HJGL_DataImport where x.UnitWorkId == UnitWorkId select x.Version).Distinct().ToList();
|
|
|
|
|
|
if (q != null && q.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
MaxVersion = (decimal)q.Max();
|
|
|
|
|
|
}
|
|
|
|
|
|
var newVersion = MaxVersion + 0.1m;
|
|
|
|
|
|
q.Add(newVersion);
|
|
|
|
|
|
return q;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 下载文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filePah"></param>
|
|
|
|
|
|
/// <param name="fileName"></param>
|
|
|
|
|
|
public static void DownFile(string filePah, string fileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = Funs.RootPath + filePah.Replace('/', '\\');
|
|
|
|
|
|
FileInfo info = new FileInfo(url);
|
|
|
|
|
|
long fileSize = info.Length;
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.BufferOutput = true;
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.Clear();
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.TransmitFile(url, 0, fileSize);
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.Flush();
|
|
|
|
|
|
System.Web.HttpContext.Current.Response.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-09-15 23:20:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="file">文件地址</param>
|
|
|
|
|
|
/// <param name="subject">主项</param>
|
|
|
|
|
|
/// <param name="fileType">1模型2图纸</param>
|
|
|
|
|
|
public static bool UploadFileToOa(string file, string unitworkid, string fileType)
|
2022-09-05 16:36:31 +08:00
|
|
|
|
{
|
2022-09-15 23:20:10 +08:00
|
|
|
|
bool result = true;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var client = new RestClient("http://sgglnet.sedin.com.cn:6060/file/uploadSingle");
|
|
|
|
|
|
client.Timeout = -1;
|
|
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
|
// client.UserAgent = "apifox/1.0.0 (https://www.apifox.cn)";
|
|
|
|
|
|
//request.AddFile("file", @"E:\微信\WeChat\WeChat Files\wxid_9140361403112\FileStorage\File\2022-08\焊接管理尾项20220809.docx");
|
|
|
|
|
|
request.AddFile("file", file);
|
|
|
|
|
|
string unitworkname = BLL.UnitWorkService.GetNameById(unitworkid);
|
|
|
|
|
|
request.AddParameter("subject", unitworkname);
|
|
|
|
|
|
request.AddParameter("fileType", fileType);
|
|
|
|
|
|
IRestResponse response = client.Execute(request);
|
|
|
|
|
|
var contentPost = response.Content;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
result =false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
2022-09-05 16:36:31 +08:00
|
|
|
|
|
2022-09-15 23:20:10 +08:00
|
|
|
|
}
|
2022-09-05 16:36:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前文件新的版本号
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="UnitWorkId"></param>
|
|
|
|
|
|
/// <param name="filename">文件名称</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static decimal GetNewVersionByUnitWorkId(string UnitWorkId, string filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
decimal a = 0.1M;
|
|
|
|
|
|
decimal MaxVersion = 0.9M;
|
|
|
|
|
|
var q = (from x in Funs.DB.HJGL_DataImport where x.UnitWorkId == UnitWorkId & x.FileName == filename select x.Version).Distinct().ToList();
|
|
|
|
|
|
if (q != null && q.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
MaxVersion = (decimal)q.Max();
|
|
|
|
|
|
}
|
|
|
|
|
|
var newVersion = MaxVersion + 0.1m;
|
|
|
|
|
|
return newVersion;
|
|
|
|
|
|
}
|
2022-10-12 18:36:04 +08:00
|
|
|
|
public static string Getlatest3DModelNameByUnitWorkId(string UnitWorkId )
|
|
|
|
|
|
{
|
|
|
|
|
|
string result = "";
|
|
|
|
|
|
var q = (from x in Funs.DB.HJGL_DataImport
|
2022-10-28 17:01:51 +08:00
|
|
|
|
join y in Funs.DB.Base_DesignProfessional on x.DesignProfessionalId equals y.DesignProfessionalId into mm
|
|
|
|
|
|
from m in mm.DefaultIfEmpty()
|
|
|
|
|
|
where x.UnitWorkId == UnitWorkId && x.ImportType == "1" && m.ProfessionalName.Contains("管道")
|
2022-10-12 18:36:04 +08:00
|
|
|
|
group x by x.UnitWorkId into tt
|
|
|
|
|
|
from t in tt.DefaultIfEmpty()
|
|
|
|
|
|
select new
|
|
|
|
|
|
{
|
|
|
|
|
|
FileName = (from x2 in tt where x2.Version == tt.Max(x => x.Version ) select x2.FileName).FirstOrDefault()
|
|
|
|
|
|
}
|
|
|
|
|
|
).FirstOrDefault();
|
|
|
|
|
|
//where t.Key == UnitWorkId & x.FileType == "1" select x.Version).Distinct().ToList();
|
2022-10-15 15:40:49 +08:00
|
|
|
|
if (q!=null&&!string.IsNullOrEmpty(q.FileName))
|
2022-10-12 18:36:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
result=q.FileName.Substring (0,q.FileName.LastIndexOf('.'));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2022-09-05 16:36:31 +08:00
|
|
|
|
public static void InitVersionDownList(FineUIPro.DropDownList dropName, string UnitWorkId)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
dropName.DataSource = GetListVersionByUnitWorkId(UnitWorkId);
|
|
|
|
|
|
dropName.DataBind();
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据主键获取对象
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="DataImportId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static Model.HJGL_DataImport GetHJGL_DataImportById(string DataImportId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Funs.DB.HJGL_DataImport.FirstOrDefault(e => e.DataImportId == DataImportId);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="newtable"></param>
|
|
|
|
|
|
public static void UpdateHJGL_DataImport(Model.HJGL_DataImport newtable)
|
|
|
|
|
|
{
|
|
|
|
|
|
Model.HJGL_DataImport table = Funs.DB.HJGL_DataImport.FirstOrDefault(e => e.DataImportId == newtable.DataImportId);
|
|
|
|
|
|
|
|
|
|
|
|
if (table != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
table.DataImportId = newtable.DataImportId;
|
|
|
|
|
|
table.FileId = newtable.FileId;
|
|
|
|
|
|
table.Version = newtable.Version;
|
|
|
|
|
|
table.Remark = newtable.Remark;
|
|
|
|
|
|
table.CreateMan = newtable.CreateMan;
|
|
|
|
|
|
table.CreateDate = newtable.CreateDate;
|
|
|
|
|
|
table.ProjectId = newtable.ProjectId;
|
|
|
|
|
|
table.UnitWorkId = newtable.UnitWorkId;
|
|
|
|
|
|
table.DesignProfessionalId = newtable.DesignProfessionalId;
|
|
|
|
|
|
table.ImportType = newtable.ImportType;
|
|
|
|
|
|
table.FileName = newtable.FileName;
|
|
|
|
|
|
table.FilePath = newtable.FilePath;
|
|
|
|
|
|
table.FileType = newtable.FileType;
|
|
|
|
|
|
table.FileSize = newtable.FileSize;
|
|
|
|
|
|
Funs.DB.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|