using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.Entity;
using QMFrameWork.Log;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMAPP.MD.DAL;
using QMAPP.MD.BLL.Dict;
namespace QMAPP.MD.BLL
{
///
/// 模块名称:工艺路线
/// 作 者:郭兆福
/// 编写日期:2017年05月12日
///
public class ProcessRouteBLL : BaseBLL
{
#region 获取工艺路线
///
/// 获取工艺路线
///
/// 条件
/// 信息
public DataResult Get(ProcessRoute model)
{
DataResult result = new DataResult();
try
{
result.Result = new ProcessRouteDAL().Get(model);
}
catch (Exception ex)
{
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)
{
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.FLGDEL = "0";
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
try
{
if (ExistsProcessRoute(model) == true)
{
result.IsSuccess = false;
result.Msg = "工艺路线已经存在!";
return result;
}
result.Result = new ProcessRouteDAL().Insert(model);
}
catch (Exception ex)
{
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.UPDATEUSER = 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)
{
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_CODE = str });
//删除工序配置的前置工序
deleteWorkCellSeqCount += processRouteDAL.DeleteProcessRouteWorkCellSeq(new ProcessRouteWorkCell { ROUTE_CODE = str });
session.CommitTs();
}
catch (Exception)
{
session.RollbackTs();
throw;
}
}
}
}
catch (Exception ex)
{
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);
#region 转换质检标记
List processRouteWorkCellList = dataPage.Result as List;
DictManageBLL qcFlagBll = new DictManageBLL(DictKind.QcFlag);
foreach (ProcessRouteWorkCell m in processRouteWorkCellList)
{
//质检标记
m.FLAG_QC_NAME = qcFlagBll.GetDictValue(m.FLAG_QC);
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
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_CODE = model.WORKCELL_CODE }))
{
result.Msg = Resource.ProcessRouteWorkCellIsHave;
result.IsSuccess = false;
return result;
}
//工序配置信息
WorkCell info = new WorkCellDAL().Get(new WorkCell() { WORKCELL_CODE = model.WORKCELL_CODE });
model.WORKCELL_CODE=info.WORKCELL_CODE;
model.WORKCELL_NAME=info.WORKCELL_NAME;
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
model.FLGDEL = "0";
//准备前置工序
listPRWCS = model.Details;
if (listPRWCS.Count != 0)
{
foreach (var item in listPRWCS)
{
WorkCell entity = new WorkCellDAL().Get(new WorkCell() { WORKCELL_CODE = item.PRE_WORKCELL_CODE });
item.PID = Guid.NewGuid().ToString();
item.WORKCELL_CODE = model.WORKCELL_CODE;
item.ROUTE_CODE = model.ROUTE_CODE;
item.VER_NUM = model.VER_NUM;
item.CREATEUSER = this.LoginUser.UserID;
item.CREATEDATE = DateTime.Now;
item.UPDATEUSER = item.CREATEUSER;
item.UPDATEDATE = item.CREATEDATE;
item.FLGDEL = "0";
item.PRE_WORKCELL_NAME = entity.WORKCELL_NAME;
item.PRE_WORKCELL_CODE = entity.WORKCELL_CODE;
}
}
else
{
// Q5 特殊,没有前置工序的时候加一条前置工序为空的工序顺序记录
ProcessRouteWorkCellSeq item = new ProcessRouteWorkCellSeq();
item.PID = Guid.NewGuid().ToString();
item.WORKCELL_CODE = model.WORKCELL_CODE;
item.ROUTE_CODE = model.ROUTE_CODE;
item.VER_NUM = model.VER_NUM;
item.CREATEUSER = this.LoginUser.UserID;
item.CREATEDATE = DateTime.Now;
item.UPDATEUSER = item.CREATEUSER;
item.UPDATEDATE = item.CREATEDATE;
item.FLGDEL = "0";
listPRWCS.Add(item);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenCon();
int processRouteWorkCellCount=proRouteDal.InsertProcessRouteWorkCell(model);
int processRouteWorkCellSeqCount = proRouteDal.InsertProcessRouteWorkCellSeq(listPRWCS);
session.CommitTs();
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 工序配置信息删除
///
/// 工序配置信息删除
///
///
/// 删除个数
public DataResult ProcessRouteWorkCellDelete(string selectKey, string ROUTE_CODE)
{
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_CODE = ROUTE_CODE });
deleteWorkCellSeqCount += processRouteDAL.DeleteProcessRouteWorkCellSeq(new ProcessRouteWorkCell { PID = str, ROUTE_CODE = ROUTE_CODE });
}
session.CommitTs();
}
catch (Exception e)
{
session.RollbackTs();
throw e;
}
}
}
catch (Exception ex)
{
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().GetRouteList(condition);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
}
#endregion
#region 获取工艺路线工序下拉列表
///
/// 获取工艺路线工序下拉列表
///
/// 条件
/// 数据页
public DataResult> GeProcessRouteWorkCellList(ProcessRouteWorkCell condtion)
{
DataResult> result = new DataResult>();
try
{
result.Result = new ProcessRouteDAL().GetProcessRouteWorkCellData(condtion);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
}
#endregion
public ProcessRoute GetRouteByMachine(string machinecode)
{
return new ProcessRouteDAL().GetRouteByMachine(machinecode);
}
}
}