using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.Entity.Sys;
using QMAPP.DAL.Sys;
using QMFrameWork.Data;
using System.Data;
using QMAPP.Entity;
namespace QMAPP.BLL.Sys
{
///
/// 文件管理逻辑层
/// 创建者:王丹丹
/// 创建时间:2015-03-17
///
public class FileInfoBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public FileInfo Get(FileInfo model)
{
try
{
return new FileInfoDAL().Get(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 根据文件类型获取文件信息
///
/// 获取信息
///
/// 条件
/// 信息
public IList GetListModel(FileType model)
{
try
{
return new FileInfoDAL().GetList(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(FileInfo condition, DataPage page)
{
try
{
return new FileInfoDAL().GetList(condition, page);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
///
/// 判断名称是否存在
///
///
/// true:已存在;fasel:不存在。
public bool ExistsFileInfo(FileInfo model)
{
try
{
return new FileInfoDAL().ExistsFileInfo(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入文件信息
///
/// 插入文件信息
///
/// 文件信息
/// 插入行数
public int Insert(FileInfo model)
{
try
{
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
FileInfoDAL cmdDAL = new FileInfoDAL();
//校验文件名称是否
if (ExistsFileInfo(model) == true)
{
return -1;
}
int ret=new FileInfoDAL().Insert(model);
if (ret > 0)
{
SendFileIntoNotice(model);
}
return ret;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public int Update(FileInfo model)
{
try
{
int ret=new FileInfoDAL().Update(model);
if (ret > 0)
{
SendFileIntoNotice(model);
}
return ret;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
///
/// 删除文件
///
/// 文件类型主键串
/// 删除个数
public int Delete(string strs)
{
int count = 0;
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
count += this.DeleteFileInfo(new FileInfo { PID = str });
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 删除文件
///
/// 信息
/// 删除个数
public int DeleteFileInfo(FileInfo model)
{
int count = 0;
try
{
count = new FileInfoDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断附件路径是否存在
public bool ExistsFile(string newFilePath)
{
bool issuccess = true;
if (!System.IO.File.Exists(newFilePath))
{
issuccess = false;
}
return issuccess;
}
#endregion
#region 删除附件
public void DeleteFile(string FilePath)
{
if (System.IO.File.Exists(FilePath))
{
System.IO.File.Delete(FilePath); ;
}
}
#endregion
#region 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(FileInfo model)
{
DataTable dt = new DataTable();
FileInfoDAL nmDal = new FileInfoDAL();
try
{
dt = nmDal.GetExportData(model);
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 将文件对象生成对应的通知并创建
private DataResult SendFileIntoNotice(FileInfo model)
{
try
{
NoticeInfo notice = new NoticeInfo();
FileType fileType = new FileType();
fileType.TYPENO = model.TYPENO;
fileType = new FileTypeBLL().Get(fileType);
notice.NOTICETITLE = "文件管理中的文件分类 '" + fileType.TYPENAME + " '下的文件 '" + model.FILENAME + " ' 被创建或修改!";
notice.NOTICECONTEXT = "文件管理中的文件分类 '" +fileType.TYPENAME + " '下的文件 '" + model.FILENAME + " ' 被创建或修改!";
List users = new UserManageDAL().GetAllUser(null);
StringBuilder strUsers = new StringBuilder();
foreach (User itemUser in users)
{
strUsers.Append(itemUser.UserID + ",");
}
if (strUsers.Length > 0)
{
notice.SENDAIM = strUsers.ToString();
notice.SENDAIM = notice.SENDAIM.Substring(0, notice.SENDAIM.Length - 1);
}
else
{
notice.SENDAIM = string.Empty;
}
notice.SENDFLG = "0";
notice.SENDTIME = System.DateTime.Now;
notice.USETIME = System.DateTime.Now;
notice.OUTTIME = DateTime.Now.AddDays(2);
notice.CREATEUSER = this.LoginUser.UserID;
notice.CREATEDATE = DateTime.Now;
notice.UPDATEUSER = this.LoginUser.UserID;
notice.UPDATEDATE = DateTime.Now;
notice.CANREPLY = "0";
notice.NOTICETYPE = "1";
return new NoticeManageBll().Save(notice);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}