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

159 lines
6.4 KiB
C#
Raw Normal View History

2022-09-05 16:36:31 +08:00
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;
};
}
public static void UploadFileToOa()
{
}
/// <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();
}
}
}
}