using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.MD.Entity;
using QMAPP.Entity;
using QMAPP.MD.DAL;
using QMFrameWork.Data;
using QMAPP.MD.BLL.Dict;
namespace QMAPP.MD.BLL
{
public class ProjectBLL : BaseBLL
{
#region 获取设备下拉列表
///
/// 获取设备下拉列表
///
/// 条件
/// 数据页
public DataResult> GetProjectList(Project condition)
{
DataResult> result = new DataResult>();
try
{
result.Result = new ProjectDAL().GetList(condition);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
}
#endregion
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public DataResult Get(Project model)
{
DataResult result = new DataResult();
try
{
result.Result = new ProjectDAL().Get(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(Project condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取信息列表
DataPage dataPage = new ProjectDAL().GetList(condition, page);
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
///
/// 获取列表
///
/// 条件
/// 全部集合
public List GetAllList(Project condition)
{
try
{
List list = new ProjectDAL().GetList(condition);
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
///
/// 判断项目号是否存在
///
///
/// true:已存在;fasel:不存在。
public DataResult IsExistsProject(Project model)
{
DataResult result = new DataResult();
try
{
if (new ProjectDAL().IsExistsProjectCodeName(model) == true)
{
result.IsSuccess = false;
result.Msg = "相同的项目号已经存在";
return result;
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(Project model)
{
DataResult result = new DataResult();
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
ProjectDAL cmdDAL = new ProjectDAL();
try
{
DataResult isExist = new DataResult();
isExist = IsExistsProject(model);
if (isExist.IsSuccess == false)
{
result.IsSuccess = false;
result.Msg = isExist.Msg;
return result;
}
result.Result = new ProjectDAL().Insert(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public DataResult Update(Project model)
{
DataResult result = new DataResult();
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
model.UPDATEDATE = DateTime.Now;
try
{
DataResult isExist = new DataResult();
isExist = IsExistsProject(model);
if (isExist.IsSuccess == false)
{
result.IsSuccess = false;
result.Msg = isExist.Msg;
return result;
}
result.Result = new ProjectDAL().Update(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
///
/// 删除信息
///
///
/// 删除个数
public DataResult Delete(string strs)
{
DataResult result = new DataResult();
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
if (IsUsing(list) == true)
{
result.IsSuccess = false;
result.Msg = "项目号已经在使用无法删除";
return result;
}
}
foreach (string str in list)
{
result.Result += this.DeleteProject(new Project { PID = str });
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int DeleteProject(Project model)
{
int count = 0;
try
{
count = new ProjectDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 项目号是否使用
///
/// 项目号是否使用
///
///
/// true:已使用;fasel:未使用。
public bool IsUsing(string[] pid)
{
try
{
return new ProjectDAL().IsUsing(pid);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}