using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMFrameWork.Log;
using QMAPP.Entity;
using QMAPP.MD.Entity;
using QMAPP.MD.DAL;
using QMFrameWork.Data;
using QMAPP.MD.BLL.Dict;
namespace QMAPP.MD.BLL
{
///
/// 模块名称:工作中心
/// 作 者:郭兆福
/// 编写日期:2017年05月09日
///
public class WorkCenterBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public QMAPP.Entity.DataResult Get(WorkCenter model)
{
QMAPP.Entity.DataResult result = new DataResult();
try
{
WorkCenter workCenterObj = new WorkCenterDAL().Get(model);
workCenterObj.WORKCENTER_CODE_OLD = workCenterObj.CENTER_TYPE;
result.Result = workCenterObj;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(WorkCenter condition, DataPage page)
{
DataResult result = new DataResult();
try
{
DataPage dataPage = new WorkCenterDAL().GetList(condition, page);
List workCenterList = dataPage.Result as List;
DictManageBLL dictBackFlushFlagBll = new DictManageBLL(DictKind.CenterType);
foreach (WorkCenter m in workCenterList)
{
m.CENTER_TYPE = dictBackFlushFlagBll.GetDictValue(m.CENTER_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 ExistsWorkCenter(WorkCenter model)
{
try
{
return new WorkCenterDAL().ExistsWorkCenter(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断工厂是否被使用
///
/// 判断工厂是否被使用
///
/// 工作中心信息
/// 是否是删除
/// true:已使用;false:未使用。
public bool IsWorkCenterUsed(string[] workCenterAry, bool isDel)
{
try
{
//用到工厂基础信息表
List tableList = new List();
//MD_采集设备
tableList.Add("T_MD_EQUIPMENT");
//MD_工序
tableList.Add("T_MD_WORKCELL");
return new WorkCenterDAL().IsWorkCenterUsed(workCenterAry, tableList, isDel);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(WorkCenter model)
{
DataResult result = new DataResult();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.FLGDEL = "0";
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
WorkCenterDAL cmdDAL = new WorkCenterDAL();
try
{
if (ExistsWorkCenter(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.CodeExists;
return result;
}
result.Result = new WorkCenterDAL().Insert(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public DataResult Update(WorkCenter model)
{
DataResult result = new DataResult();
model.UPDATEUSER = this.LoginUser.UserID;
try
{
if (ExistsWorkCenter(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.CodeExists;
return result;
}
// 工作中心编码修改
if (model.WORKCENTER_CODE_OLD != model.CENTER_TYPE)
{
string[] param = { model.WORKCENTER_CODE_OLD };
if (IsWorkCenterUsed(param, false) == true)
{
result.IsSuccess = false;
result.Msg = Resource.WorkCenterUsed;
return result;
}
}
result.Result = new WorkCenterDAL().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)
{
int count = 0;
string[] list = strs.Split(":".ToCharArray());
DataResult result = new DataResult();
try
{
if (IsWorkCenterUsed(list, true) == true)
{
result.IsSuccess = false;
result.Msg = Resource.UsedNotDeleted;
return result;
}
count = this.DeleteWorkCenter(list);
if (count == 0)
{
result.IsSuccess = false;
return result;
}
result.Result = count;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 删除信息
///
/// 要删除的主键
/// 删除个数
public int DeleteWorkCenter(string[] pidAry)
{
int count = 0;
try
{
count = new WorkCenterDAL().Delete(pidAry, this.LoginUser.UserID);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取工作中心列表(下拉列表使用)
///
///
///
///
///
public DataResult> GetWorkCenterList(WorkCenter condition)
{
DataResult> result = new DataResult>();
try
{
result.Result = new WorkCenterDAL().GetWorkCenterList(condition);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
}
}