using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.MD.Entity;
using QMAPP.MD.DAL;
using QMFrameWork.Data;
using QMFrameWork.Log;
namespace QMAPP.MD.BLL
{
///
/// 模块名称:工厂
/// 作 者:郭兆福
/// 编写日期:2017年05月04日
///
public class FactoryBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public DataResult Get(Factory model)
{
DataResult result = new DataResult();
try
{
Factory factoryObj = new FactoryDAL().Get(model);
factoryObj.FACTORY_CODE_OLD = factoryObj.FACTORY_CODE;
result.Result = factoryObj;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(Factory condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取工厂信息列表
DataPage dataPage = new FactoryDAL().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(Factory condition)
{
try
{
//获取物料信息列表
List list = new FactoryDAL().GetAllList(condition);
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 得到当前公司信息
///
/// 得到公司信息
///
/// 当前公司信息
public Corp GetCurrentCorp()
{
try
{
return new CorpDAL().Get();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
///
/// 判断名称是否存在
///
///
/// true:已存在;false:不存在。
public bool ExistsFactory(Factory model)
{
try
{
return new FactoryDAL().ExistsFactory(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断工厂是否被使用
///
/// 判断工厂是否被使用
///
/// 工厂信息
/// 是否是删除
/// true:已使用;false:未使用。
public bool IsFactoryUsed(string[] factoryAry, bool isDel)
{
try
{
//用到工厂基础信息表
List tableList = new List();
//MD_工作中心
tableList.Add("T_MD_WORKCENTER");
//MD_工厂物料
tableList.Add("T_MD_MATERIAL_IN_FACTORY");
//MD_工厂PBOM
tableList.Add("T_MD_PBOM_IN_FACTORY");
//QT_班组
tableList.Add("T_QT_TEAM");
//QT_班次信息
tableList.Add("T_QT_SHIFT");
//MD_工厂工艺
tableList.Add("T_MD_FACTORY_PROCESS");
//MD_替代工艺路线
tableList.Add("T_MD_SUBSTITUTE_ROUTE");
return new FactoryDAL().IsFactoryUsed(factoryAry, tableList, isDel);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(Factory model)
{
DataResult result = new DataResult();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.FLGDEL = "0";
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
FactoryDAL cmdDAL = new FactoryDAL();
try
{
if (ExistsFactory(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.CodeExists;
return result;
}
model.CORP_CODE = GetCurrentCorp().CORP_CODE;
if (string.IsNullOrEmpty(model.CORP_CODE) == true)
{
result.IsSuccess = false;
result.Msg = Resource.CorpNotExists;
return result;
}
result.Result = new FactoryDAL().Insert(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public DataResult Update(Factory model)
{
DataResult result = new DataResult();
model.UPDATEUSER = this.LoginUser.UserID;
try
{
if (ExistsFactory(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.CodeExists;
return result;
}
// 工厂编号修改
if (model.FACTORY_CODE_OLD != model.FACTORY_CODE)
{
string[] param = { model.FACTORY_CODE_OLD };
if (IsFactoryUsed(param, false) == true)
{
result.IsSuccess = false;
result.Msg = Resource.FactoryUsed;
return result;
}
}
result.Result = new FactoryDAL().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 (IsFactoryUsed(list, true) == true)
{
result.IsSuccess = false;
result.Msg = Resource.UsedNotDeleted;
return result;
}
count = this.DeleteFactory(list);
if (count == 0)
{
result.IsSuccess = false;
return result;
}
result.Result = count;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 删除信息
///
/// 要删除的主键
/// 删除个数
public int DeleteFactory(string[] pidAry)
{
int count = 0;
count = new FactoryDAL().Delete(pidAry, this.LoginUser.UserID);
return count;
}
#endregion
#region 获取工厂列表(下拉列表使用)
///
/// 获取列表
///
/// 条件
/// 全部集合
public DataResult> GetFactoryList(Factory condition)
{
DataResult> result = new DataResult>();
try
{
result.Result = new FactoryDAL().GetAllList(condition);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
}
}