SGGL_SHJ/SGGL/BLL/HJGL/DataImport/DataImportService.cs

187 lines
7.7 KiB
C#

using RestSharp;
using System.Collections.Generic;
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>
public static Model.HJGL_DataImport GetLatestFileByFileName(string FileName, string project)
{
var q = (from x in Funs.DB.HJGL_DataImport
where x.FileName == FileName && x.ProjectId == project
select x
).OrderByDescending(x => x.Version).FirstOrDefault();
return q;
}
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;
};
}
/// <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)
{
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;
}
/// <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;
}
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();
}
}
}
}