using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMFrameWork.Common.Encrypt;
using QMFrameWork.Data;
using QMAPP.FJC.DAL.Basic;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity;
using QMAPP.FJC.DAL.Equipment;
using QMAPP.FJC.Entity.Equipment;
using QMAPP.BLL;
using QMAPP.BLL.Dict;
using QMAPP.Entity;
using QMFrameWork.Log;
namespace QMAPP.FJC.BLL.Equipment
{
///
/// 模块编号:M11-3
/// 作 用:设备停机维护
/// 作 者:王庆男
/// 编写日期:2015年06月02日
///
public class EquipmentMaintainBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public EquipmentMaintain Get(EquipmentMaintain model)
{
try
{
return new EquipmentMaintainDAL().Get(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--获取停机信息"
});
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(EquipmentMaintain condition, DataPage page)
{
try
{
return new EquipmentMaintainDAL().GetList(condition, page);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--获取停机列表"
});
throw ex;
}
}
#endregion
#region 信息是否重复
///
/// 判断名称是否存在
///
///
/// true:已存在;fasel:不存在。
public bool ExistsEquipmentMaintain(EquipmentMaintain model)
{
try
{
return new EquipmentMaintainDAL().ExistsEquipmentMaintain(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--判断停机信息是否重复"
});
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(EquipmentMaintain model)
{
DataResult result = new DataResult();
try
{
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
EquipmentMaintainDAL cmdDAL = new EquipmentMaintainDAL();
if (ExistsEquipmentMaintain(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.IsHaving;
return result;
}
result.Result = new EquipmentMaintainDAL().Insert(model);
result.IsSuccess = true;;
result.Msg = Resource.MsgSuccess;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--插入停机信息"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
}
return result;
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public DataResult Update(EquipmentMaintain model)
{
DataResult result = new DataResult();
try
{
if (ExistsEquipmentMaintain(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.IsHaving;
return result;
}
model.UPDATEUSER = this.LoginUser.UserID;
result.Result = new EquipmentMaintainDAL().Update(model);
result.IsSuccess = true;
result.Msg = Resource.MsgSuccess;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--更新停机信息"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
}
return result;
}
#endregion
#region 删除
///
/// 删除信息
///
///
/// 删除个数
public DataResult Delete(string strs)
{
DataResult result = new DataResult();
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
result.Result += this.DeleteEquipmentMaintain(new EquipmentMaintain { PID = str });
}
result.IsSuccess = true;
result.Msg = Resource.MsgSuccess;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--删除停机信息"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
}
return result;
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public DataResult DeleteEquipmentMaintainAndUpdateMachine(string str)
{
DataResult result = new DataResult();
try
{
EquipmentMaintain model = new EquipmentMaintainDAL().Get(new EquipmentMaintain { PID = str });
MachineInfo machine = new MachineInfoDAL().Get(new MachineInfo { PID = model.MID });
machine.STATUS = "0";
model.machine = machine;
result.Result = new EquipmentMaintainDAL().DeleteAndUpdateMachine(model);
result.IsSuccess = true;
result.Msg = Resource.MsgSuccess;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--删除停机信息并更新设备状态"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
}
return result;
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int DeleteEquipmentMaintain(EquipmentMaintain model)
{
int count = 0;
try
{
count = new EquipmentMaintainDAL().Delete(model);
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--删除停机信息"
});
throw ex;
}
}
#endregion
#region 导出数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(EquipmentMaintain model)
{
try
{
return new EquipmentMaintainDAL().GetExportData(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--导出停机信息"
});
throw ex;
}
}
#endregion
#region 导入数据
public DataResult GetImportData(List list)
{
DataResult result = new DataResult();
EquipmentMaintainDAL cmDal = new EquipmentMaintainDAL();
List List = new List();
int index = 0;
try
{
result.Result = new ImportMessage();
result.Result.Errors = new List();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//状态判断
foreach (EquipmentMaintain ma in list)
{
index++;
if (string.IsNullOrEmpty(ma.InfoError) == false)
{
ma.PID = null;
result.Result.failureNum += 1;
continue;
}
//修改改时根据主键等信息获取详细内容信息
EquipmentMaintain oldInfo = cmDal.Get(ma);
if (oldInfo != null)
{
//更新
ma.PID = oldInfo.PID;
ma.CREATEUSER = oldInfo.CREATEUSER;
ma.CREATEDATE = oldInfo.CREATEDATE;
ma.UPDATEUSER = this.LoginUser.UserID;
ma.UPDATEDATE = oldInfo.UPDATEDATE;
ma.IsNewInfo = false;
result.Result.updateNum += 1;
}
else
{
//新增
oldInfo = new EquipmentMaintain();
ma.PID = Guid.NewGuid().ToString();
ma.CREATEUSER = this.LoginUser.UserID;
ma.CREATEDATE = DateTime.Now;
ma.UPDATEUSER = ma.CREATEUSER;
ma.UPDATEDATE = ma.CREATEDATE;
ma.IsNewInfo = true;
result.Result.insertNum += 1;
}
List.Add(ma);
}
}
//导入
cmDal.GetImportData(List);
result.Msg = "导入成功";
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备停机维护--导入停机信息"
});
result.IsSuccess = false;
result.Ex = ex;
return result;
}
}
#endregion
}
}