using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.Entity;
using QMAPP.FJC.Entity;
using QMFrameWork.Log;
using QMAPP.BLL;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.DAL.Basic;
using QMFrameWork.Data;
namespace QMAPP.FJC.BLL.Basic
{
public class ProcessRouteBLL : BaseBLL
{
#region 获取工艺路线
///
/// 获取工艺路线
///
/// 条件
/// 信息
public DataResult Get(ProcessRoute model)
{
DataResult result = new DataResult();
try
{
result.Result = new ProcessRouteDAL().Get(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-获取工艺路线!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(ProcessRoute condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取工艺路线列表
DataPage dataPage = new ProcessRouteDAL().GetList(condition, page);
result.Result = dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-获取列表!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 信息是否重复
///
/// 判断名称是否存在
///
///
/// true:已存在;fasel:不存在。
public bool ExistsProcessRoute(ProcessRoute model)
{
try
{
return new ProcessRouteDAL().ExistsProcessRoute(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(ProcessRoute model)
{
DataResult result = new DataResult();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.FLAGDEL = "0";
model.CREATEUSR = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSR = model.CREATEUSR;
model.UPDATEDATE = model.CREATEDATE;
try
{
if (ExistsProcessRoute(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProcessRouteIsHave;
return result;
}
result.Result = new ProcessRouteDAL().Insert(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public DataResult Update(ProcessRoute model)
{
DataResult result = new DataResult();
//基本信息
model.UPDATEUSR = this.LoginUser.UserID;
try
{
if (ExistsProcessRoute(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProcessRouteIsHave;
return result;
}
result.Result = new ProcessRouteDAL().Update(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-更新信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
///
/// 删除信息
///
///
/// 删除个数
public DataResult Delete(string strs)
{
int deleteWorkCellCount = 0;
int deleteWorkCellSeqCount = 0;
int deleteProcessRouteCount = 0;
DataResult result = new DataResult();
string[] list = strs.Split(":".ToCharArray());
ProcessRouteDAL processRouteDAL = new ProcessRouteDAL();
try
{
foreach (string str in list)
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
processRouteDAL.BaseSession = session;
session.OpenCon();
try
{
//删除工艺路线
deleteProcessRouteCount += processRouteDAL.Delete(new ProcessRoute { PID = str });
//删除工艺路线下的工序
deleteWorkCellCount += processRouteDAL.DeleteProcessRouteWorkCell(new ProcessRouteWorkCell { ROUTE_PID = str });
//删除工序配置的前置工序
deleteWorkCellSeqCount += processRouteDAL.DeleteProcessRouteWorkCellSeq(new ProcessRouteWorkCell { ROUTE_PID = str });
session.CommitTs();
}
catch (Exception)
{
session.RollbackTs();
throw;
}
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-删除!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int DeleteProcessRoute(ProcessRoute model)
{
int count = 0;
try
{
count = new ProcessRouteDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取工序配置信息列表(分页)
///
/// 获取工序配置信息列表(分页)
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetProcessRouteWorkCellData(ProcessRouteWorkCell condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取生产线信息列表
DataPage dataPage = new ProcessRouteDAL().GetProcessRouteWorkCellData(condition, page);
result.Result = dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-获取工序配置信息列表!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 工序配置信息保存
///
/// 工序配置信息保存
///
///
///
public DataResult ProcessRouteWorkCellSave(ProcessRouteWorkCell model)
{
DataResult result = new DataResult();
ProcessRouteDAL proRouteDal = new ProcessRouteDAL();
List listPRWC = new List();
List listPRWCS = new List();
try
{
if (proRouteDal.ExistsProcess(new ProcessRouteWorkCell() { WORKCELL_PID = model.WORKCELL_PID, ROUTE_PID = model.ROUTE_PID }))
{
result.Msg = Resource.ProcessRouteWorkCellIsHave;
result.IsSuccess = false;
return result;
}
//工序配置信息
ProcessInfo info = new ProcessInfoDAL().Get(new ProcessInfo() { PID = model.WORKCELL_PID });
model.WORKCELL_NAME = info.PROCESSNAME;
model.PID = Guid.NewGuid().ToString();
model.CREATEUSR = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSR = model.CREATEUSR;
model.UPDATEDATE = model.CREATEDATE;
model.FLAGDEL = EnumGeter.FLAGDEL.NO.GetHashCode().ToString();
//准备前置工序
listPRWCS = model.Details;
if (listPRWCS.Count != 0)
{
foreach (var item in listPRWCS)
{
ProcessInfo entity = new ProcessInfoDAL().Get(new ProcessInfo() { PID = item.PRE_WORKCELL_CODE });
item.PRWS_PID = Guid.NewGuid().ToString();
item.PRW_PID = model.PID;
item.PRE_PRW_PID = entity.PID;
item.ROUTE_PID = model.ROUTE_PID;
item.CREATEUSR = this.LoginUser.UserID;
item.CREATEDATE = DateTime.Now;
item.UPDATEUSR = item.CREATEUSR;
item.UPDATEDATE = item.CREATEDATE;
item.FLAGDEL = EnumGeter.FLAGDEL.NO.GetHashCode().ToString();
item.PRE_WORKCELL_NAME = entity.PROCESSNAME;
//item.PRE_WORKCELL_CODE = entity.WORKCELL_CODE;
}
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenCon();
int processRouteWorkCellCount = proRouteDal.InsertProcessRouteWorkCell(model);
int processRouteWorkCellSeqCount = proRouteDal.InsertProcessRouteWorkCellSeq(listPRWCS);
session.CommitTs();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-工序配置信息保存!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 工序配置信息删除
///
/// 工序配置信息删除
///
///
/// 删除个数
public DataResult ProcessRouteWorkCellDelete(string selectKey, string ROUTE_PID)
{
DataResult result = new DataResult();
int deleteWorkCellCount = 0;
int deleteWorkCellSeqCount = 0;
ProcessRouteDAL processRouteDAL = new ProcessRouteDAL();
string[] list = selectKey.Split(":".ToCharArray());
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
try
{
session.OpenTs();
processRouteDAL.BaseSession = session;
foreach (string str in list)
{
deleteWorkCellCount += processRouteDAL.DeleteProcessRouteWorkCell(new ProcessRouteWorkCell { PID = str, ROUTE_PID = ROUTE_PID });
deleteWorkCellSeqCount += processRouteDAL.DeleteProcessRouteWorkCellSeq(new ProcessRouteWorkCell { PID = str, ROUTE_PID = ROUTE_PID });
}
session.CommitTs();
}
catch (Exception e)
{
session.RollbackTs();
throw e;
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线逻辑层-工序配置信息删除!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取班次列表(下拉列表使用)
///
/// 获取列表
///
/// 条件
/// 全部集合
public DataResult> GetProcessRouteList(ProcessRoute condition)
{
DataResult> result = new DataResult>();
try
{
result.Result = new ProcessRouteDAL().GetProcessRouteList(condition);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-获取班次列表(绑定下拉列表使用)!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
}
}