天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

685 lines
24 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.DAL.Basic;
using QMFrameWork.Data;
using QMAPP.FJC.BLL.Dict;
using QMAPP.FJC.Entity;
using QMAPP.Entity;
using QMFrameWork.Log;
namespace QMAPP.FJC.BLL.Basic
{
/// <summary>
/// 模块编号:M2-7
/// 作 用:工序设置逻辑层
/// 作 者:王丹丹
/// 编写日期:2015年06月01日
///</summary>
public class ProcessSetBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public DataResult<ProcessSet> Get(ProcessSet model)
{
DataResult<ProcessSet> result = new DataResult<ProcessSet>();
try
{
result.Result = new ProcessSetDAL().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;
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public DataResult<ProcessSet> GetByModel(ProcessSet model)
{
DataResult<ProcessSet> result = new DataResult<ProcessSet>();
try
{
List<ProcessSet> list = new ProcessSetDAL().GetList(model);
if (list.Count > 0)
{
result.Result = list[0];
}
}
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;
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public DataResult<List<ProcessSet>> GetListByModel(ProcessSet model)
{
DataResult<List<ProcessSet>> result = new DataResult<List<ProcessSet>>();
try
{
List<ProcessSet> list = new ProcessSetDAL().GetList(model);
if (list.Count > 0)
{
result.Result = list;
}
}
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 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetList(ProcessSet condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取信息列表
DataPage dataPage = new ProcessSetDAL().GetList(condition, page);
#region 转换工序是否必须、在制品工序设置、工序类别、是否是主零件显示类型
List<ProcessSet> processSetList = dataPage.Result as List<ProcessSet>;
DictManageBLL dictLpneccessaryBll = new DictManageBLL(DictKind.LPNECCESSARY);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictWipSetBll = new DictManageBLL(DictKind.WIPSET);
DictManageBLL dictIsMainBll = new DictManageBLL(DictKind.ISMAIN);
DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE);
foreach (ProcessSet m in processSetList)
{
//工序是否必须
m.LPNECCESSARYTXT = dictLpneccessaryBll.GetDictValue(m.LPNECCESSARY);
//工序类别
m.PROCESSTYPETXT = dictProcessTypeBll.GetDictValue(m.PROCESSTYPE);
//在制品工序设置
m.WIPSETTXT = dictWipSetBll.GetDictValue(m.WIPSET);
//是否是主零件
m.ISMAINTXT = dictIsMainBll.GetDictValue(m.ISMAIN);
//零件类别
m.PRODUCTTYPETEXT = dictProductTypeBll.GetDictValue(m.PRODUCTTYPE);
}
#endregion
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;
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>所有数据</returns>
public List<ProcessSet> GetAllList(ProcessSet condition)
{
try
{
//获取信息列表
#region 转换工序是否必须、在制品工序设置、工序类别显示类型
List<ProcessSet> processSetList = new ProcessSetDAL().GetList(condition);
DictManageBLL dictLpneccessaryBll = new DictManageBLL(DictKind.LPNECCESSARY);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictWipSetBll = new DictManageBLL(DictKind.WIPSET);
foreach (ProcessSet m in processSetList)
{
//工序是否必须
m.LPNECCESSARYTXT = dictLpneccessaryBll.GetDictValue(m.LPNECCESSARY);
//工序类别
m.PROCESSTYPETXT = dictProcessTypeBll.GetDictValue(m.PROCESSTYPE);
//在制品工序设置
m.WIPSETTXT = dictWipSetBll.GetDictValue(m.WIPSET);
}
#endregion
return processSetList;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsProcessSet(ProcessSet model)
{
try
{
return new ProcessSetDAL().ExistsProcessSet(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> Insert(ProcessSet model)
{
DataResult<int> result = new DataResult<int>();
ProcessSetDAL cmdDAL = new ProcessSetDAL();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
model.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString();
try
{
if (ExistsProcessSet(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProduceTypeOrProcesssTypeIsHave;
return result;
}
result.Result = new ProcessSetDAL().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 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult<int> Update(ProcessSet model)
{
DataResult<int> result = new DataResult<int>();
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
try
{
if (ExistsProcessSet(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProduceTypeOrProcesssTypeIsHave;
return result;
}
result.Result = new ProcessSetDAL().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 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public DataResult<int> Delete(string strs)
{
DataResult<int> result = new DataResult<int>();
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
result.Result += this.DeleteProcessSet(new ProcessSet { PID = str });
}
}
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;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteProcessSet(ProcessSet model)
{
int count = 0;
DataResult<ProcessSet> result = new DataResult<ProcessSet>();
try
{
//获取当前工序设置信息
model = new ProcessSetDAL().Get(model);
//获取该零件下的最大工序顺序的工序信息
result = this.GetProcessIndex(new ProcessSet()
{
PRODUCTTYPE = model.PRODUCTTYPE,
});
//删除工序
count = new ProcessSetDAL().Delete(model);
//更新该工序后的所有工序的工序顺序
//如果当前工序不等于应插入的最大工序顺序
if (model.PROCESSINDEX != result.Result.MAXPROCESSINDEX)
{
result.Result.OLDPROCESSINDEX = model.PROCESSINDEX + 1;
//更新原工序顺序
new ProcessSetDAL().UpdateIndexForWord(result.Result);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 根据工序id获取工序信息
/// <summary>
/// 根据工序id获取工序信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public DataResult<ProcessInfo> GetProcessInfo(ProcessSet model)
{
ProcessInfo condition = new ProcessInfo();
ProcessInfoDAL psDal = new ProcessInfoDAL();
DataResult<ProcessInfo> result = new DataResult<ProcessInfo>();
try
{
if (model != null && !string.IsNullOrEmpty(model.PCID))
{
condition.PID = model.PCID;
//获取工序信息
condition = psDal.Get(condition);
#region 转换工序类别显示类型
if (condition != null)
{
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
//工序类别
condition.PROCESSTYPETXT = condition.PROCESSNAME;
}
#endregion
}
result.Result= condition;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工序设置逻辑层-根据工序id获取工序信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 根据工序id获取工序信息集合
/// <summary>
/// 根据工序id获取工序信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public DataResult<List<ProcessInfo>> GetProcessInfoList(ProcessSet model)
{
ProcessInfo condition = new ProcessInfo();
ProcessInfoDAL psDal = new ProcessInfoDAL();
DataResult<List<ProcessInfo>> result = new DataResult<List<ProcessInfo>>();
try
{
if (model != null && !string.IsNullOrEmpty(model.PCID))
{
condition.PID = model.PCID;
}
if (model != null&&!string.IsNullOrEmpty(model.OPERATETYPE))
{
condition.OPERATETYPE = model.OPERATETYPE;
}
if (!string.IsNullOrEmpty(model.PROCESSTYPE))
{
condition.PROCESSTYPE = model.PROCESSTYPE;
}
//获取工序信息
result.Result = new ProcessInfoDAL().GetList(condition);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工序设置逻辑层-根据工序id获取工序信息集合!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取下一个加工工序
/// <summary>
/// 获取下一个加工工序
/// </summary>
/// <param name="current">当前工序</param>
/// <returns></returns>
public ProcessSet GetNextProcess(ProcessSet current)
{
ProcessSet nextProcessSet = new ProcessSet();
ProcessSetDAL psdal = new ProcessSetDAL();
try
{
//获取该生产线下该产品类别所有加工工序
List<ProcessSet> psList = psdal.GetList(new ProcessSet()
{
PRODUCTTYPE = current.PRODUCTTYPE,
PRODUCELINE = current.PRODUCELINE,
});
//获取当前工序
ProcessSet currentProcess = psList.First(o => o.PROCESSTYPE == current.PROCESSTYPE);
//获取加工序列大于当前工序的加工工序
if (psList.Count(o => o.PROCESSINDEX > currentProcess.PROCESSINDEX) > 0)
{
nextProcessSet = psList.Where(o => o.PROCESSINDEX > currentProcess.PROCESSINDEX)
.OrderBy(o=>o.PROCESSINDEX).First();
}
}
catch (Exception ex)
{
throw ex;
}
return nextProcessSet;
}
#endregion
#region 获取该生产线下该产品类别下最新工序
/// <summary>
/// 获取该生产线下该产品类别下最新工序
/// </summary>
/// <param name="current">当前工序</param>
/// <returns></returns>
public DataResult<ProcessSet> GetProcessIndex(ProcessSet current)
{
ProcessSetDAL psdal = new ProcessSetDAL();
ProcessSet processSet = new ProcessSet();
DataResult<ProcessSet> result = new DataResult<ProcessSet>();
try
{
//获取该生产线下该产品类别所有加工工序
List<ProcessSet> psList = psdal.GetList(new ProcessSet()
{
PRODUCTTYPE = current.PRODUCTTYPE,
});
//获取产品类别下最新工序
result.Result = psList.Where(o => o.PROCESSINDEX == psList.Max(p => p.PROCESSINDEX)).FirstOrDefault();
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工序设置逻辑层-获取该生产线下该产品类别下最新工序!"
});
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 保存工序设置信息
/// <summary>
/// 保存工序设置信息
/// </summary>
/// <param name="processSet">工序信息</param>
/// <returns>插入/更新数量</returns>
public DataResult<int> Save(ProcessSet processSet)
{
DataResult<int> result = new DataResult<int>();
ProcessSetDAL psDal = new ProcessSetDAL();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
psDal.BaseSession = session;
#region 更新
//更新
if (!string.IsNullOrEmpty(processSet.PID))
{
if (psDal.ExistsProcessSet(processSet) == true)
{
result.IsSuccess = false;
result.Msg = Resource.IsHaving;
return result;
}
else
{
//如果修改了零件类别或修改了工序顺序(原工序类别不等于当前工序类别或原工序顺序不等于当前工序顺序)
if (processSet.OLDPRODUCTTYPE != processSet.PROCESSTYPE || processSet.PROCESSINDEX != processSet.OLDPROCESSINDEX)
{
//如果当前工序不等于应插入的最大工序顺序
if (processSet.PROCESSINDEX != processSet.MAXPROCESSINDEX + 1)
{
if (processSet.PROCESSINDEX > processSet.OLDPROCESSINDEX)
{
processSet.OLDPROCESSINDEX = processSet.OLDPROCESSINDEX + 1;
//更新原工序顺序
psDal.UpdateIndexForWord(processSet);
}
if (processSet.PROCESSINDEX < processSet.OLDPROCESSINDEX)
{
processSet.OLDPROCESSINDEX = processSet.OLDPROCESSINDEX - 1;
//更新原工序顺序
psDal.UpdateIndexBackWord(processSet);
}
}
}
//更新新工序设置
result.Result = psDal.Update(processSet);
}
}
#endregion
#region 新建
//新建
else
{
//基本信息
processSet.PID = Guid.NewGuid().ToString();
if (psDal.ExistsProcessSet(processSet) == true)
{
result.IsSuccess = false;
result.Msg = Resource.IsHaving;
return result;
}
else
{
//如果当前工序不等于应插入的最大工序顺序
if (processSet.PROCESSINDEX != processSet.MAXPROCESSINDEX + 1)
{
processSet.OLDPROCESSINDEX = processSet.MAXPROCESSINDEX;
//更新原工序顺序
psDal.UpdateIndexBackWord(processSet);
}
#region 基本信息
//基本信息
processSet.CREATEUSER = this.LoginUser.UserID;
processSet.CREATEDATE = DateTime.Now;
processSet.UPDATEUSER = processSet.CREATEUSER;
processSet.UPDATEDATE = processSet.CREATEDATE;
processSet.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString();
processSet.PRODUCTNAME = processSet.PRODUCTTYPE;
#endregion
//插入新工序设置
result.Result = psDal.Insert(processSet);
}
}
#endregion
session.CommitTs();
}
}
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
}
}