using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.Entity;
using QMFrameWork.Log;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMAPP.MD.DAL;
using QMAPP.MD.BLL.Dict;
namespace QMAPP.MD.BLL
{
///
/// 模块名称:设备
/// 作 者:郭兆福
/// 编写日期:2017年05月10日
///
public class EquipmentBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public DataResult Get(Equipment model)
{
DataResult result = new DataResult();
try
{
result.Result = new EquipmentDAL().Get(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(Equipment condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取信息列表
DataPage dataPage = new EquipmentDAL().GetList(condition, page);
List equipmentList = dataPage.Result as List;
DictManageBLL dictEquipmentFlagBll = new DictManageBLL(DictKind.EquipmentFlag);
DictManageBLL dictEquipmentTypeBll = new DictManageBLL(DictKind.EquipmentType);
foreach (Equipment m in equipmentList)
{
//关键设备
m.FLAG_EQUIPMENT_NAME = dictEquipmentFlagBll.GetDictValue(m.FLAG_EQUIPMENT);
//设备类型
m.EQUIPMENT_TYPE_NAME = dictEquipmentTypeBll.GetDictValue(m.EQUIPMENT_TYPE);
}
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 信息是否重复
///
/// 判断名称是否存在
///
///
/// true:已存在;fasel:不存在。
public bool ExistsMachineInfo(Equipment model)
{
try
{
return new EquipmentDAL().ExistsMachineInfo(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(Equipment model)
{
DataResult result = new DataResult();
EquipmentDAL cmdDAL = new EquipmentDAL();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.FLGDEL = "0";
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
try
{
if (ExistsMachineInfo(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.MachineCodeIsHave;
return result;
}
result.Result = new EquipmentDAL().Insert(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public DataResult Update(Equipment model)
{
DataResult result = new DataResult();
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
try
{
if (ExistsMachineInfo(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.MachineCodeIsHave;
return result;
}
result.Result = new EquipmentDAL().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
{
if (new EquipmentDAL().IsUsedEquipmentLocCode(list) == true)
{
result.IsSuccess = false;
result.Msg = "准备删除的数据已被使用,删除不可!";
return result;
}
foreach (string str in list)
{
result.Result += this.DeleteMachineInfo(new Equipment { PID = str });
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int DeleteMachineInfo(Equipment model)
{
int count = 0;
try
{
count = new EquipmentDAL().Delete(model, this.LoginUser.LoginUserID);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取设备下拉列表
///
/// 获取设备下拉列表
///
/// 条件
/// 数据页
public DataResult> GetEquipmentList(Equipment condition)
{
DataResult> result = new DataResult>();
try
{
result.Result = new EquipmentDAL().GetList(condition);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
}
#endregion
}
}