using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.MD.Entity; using QMFrameWork.Data; using QMFrameWork.Log; using System.Data; using QMAPP.DAL; using QMAPP.MD.Entity.View; namespace QMAPP.MD.DAL { /// /// 模块名称:工艺路线 /// 作 者:郭兆福 /// 编写日期:2017年05月12日 /// public class ProcessRouteDAL : BaseDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public ProcessRoute Get(ProcessRoute model) { string sql = null; List parameters = new List(); try { sql = "SELECT * FROM T_MD_PROCESS_ROUTE WHERE FLGDEL='0' "; if (string.IsNullOrEmpty(model.PID) == false) { sql += " AND PID = @PID"; parameters.Add(new DataParameter("PID", model.PID)); } if (string.IsNullOrEmpty(model.ROUTE_CODE) == false) { sql += " AND ROUTE_CODE = @ROUTE_CODE"; parameters.Add(new DataParameter("ROUTE_CODE", model.ROUTE_CODE)); } using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sql, session); //获取信息 model = session.Get(sqlChange, parameters.ToArray()); } return model; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-获取信息"); throw ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(ProcessRoute condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); #region 排序 //分页关键字段及排序 page.KeyName = "PID"; if (string.IsNullOrEmpty(page.SortExpression)) { page.SortExpression = "UPDATEDATE DESC"; } //else //{ // //按照标题排序 // if (page.SortExpression.IndexOf("AREA") > -1) // { // page.SortExpression = page.SortExpression.Replace("PROCESSTYPETXT", "PROCESSTYPE"); // } // if (page.SortExpression.IndexOf("MATERIALTYPETXT") > -1) // { // page.SortExpression = page.SortExpression.Replace("MATERIALTYPETXT", "MATERIALTYPE"); // } //} #endregion using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sql, session); page = session.GetDataPage(sqlChange, parameters.ToArray(), page); } return page; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-获取列表"); throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(ProcessRoute condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { sqlBuilder.AppendLine("SELECT T.PID "); sqlBuilder.AppendLine(" ,T.FACTORY_CODE "); sqlBuilder.AppendLine(" ,F.FACTORY_NAME "); sqlBuilder.AppendLine(" ,T.ROUTE_CODE "); sqlBuilder.AppendLine(" ,T.ROUTE_NAME "); sqlBuilder.AppendLine(" ,T.EFF_DATE "); sqlBuilder.AppendLine(" ,T.EXP_DATE "); sqlBuilder.AppendLine(" ,T.ROUTE_VER "); sqlBuilder.AppendLine(" ,T.REMARK "); sqlBuilder.AppendLine(" ,T.CREATEDATE "); sqlBuilder.AppendLine(" ,T.UPDATEDATE "); sqlBuilder.AppendLine(" ,T.FLGDEL "); sqlBuilder.AppendLine(" FROM T_MD_PROCESS_ROUTE T ");; sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=T.FACTORY_CODE "); whereBuilder.Append(" AND T.FLGDEL='0'"); //查询条件 //工厂 if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false) { whereBuilder.Append(" AND T.FACTORY_CODE = @FACTORY_CODE "); parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE }); } //工艺路线编码 if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false) { whereBuilder.Append(" AND T.ROUTE_CODE = @ROUTE_CODE "); parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE }); } //工艺路线名称 if (string.IsNullOrEmpty(condition.ROUTE_NAME) == false) { whereBuilder.Append(" AND T.ROUTE_NAME LIKE @ROUTE_NAME"); parameters.Add(new DataParameter { ParameterName = "ROUTE_NAME", DataType = DbType.String, Value = base.EscapeValue(condition.ROUTE_NAME) + "%" }); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion #region 判断名称是否存在 /// /// 判断名称是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsProcessRoute(ProcessRoute model) { string PID = ""; int count = 0; string sql = null; try { if (string.IsNullOrEmpty(model.PID) == false) { PID = model.PID; } sql = "SELECT COUNT(*) FROM T_MD_PROCESS_ROUTE WHERE PID <> @PID AND FACTORY_CODE=@FACTORY_CODE AND ROUTE_CODE=@ROUTE_CODE AND FLGDEL = '0' "; using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sql, session); count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, new DataParameter("PID", PID), new DataParameter { ParameterName = "FACTORY_CODE", Value = model.FACTORY_CODE }, new DataParameter { ParameterName = "ROUTE_CODE", Value = model.ROUTE_CODE })); } if (count > 0) { return true; } else { return false; } } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-判断工艺路线编号是否存在"); throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 工艺路线 /// 插入行数 public int Insert(ProcessRoute model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(model); } return count; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-插入信息"); throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// 工艺路线 /// 更新行数 public int Update(ProcessRoute model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //更新基本信息 count = session.Update(model); } return count; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-更新信息"); throw ex; } } #endregion #region 删除信息 /// /// 删除信息 /// /// 工艺路线(ID) /// 删除个数 public int Delete(ProcessRoute model) { StringBuilder sqlBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { sqlBuilder.Append("UPDATE T_MD_PROCESS_ROUTE "); sqlBuilder.Append("SET FLGDEL = '1'"); sqlBuilder.Append("WHERE PID = @PID"); parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID }); if (BaseSession != null) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession); //删除基本信息 count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray()); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session); //删除基本信息 count = session.ExecuteSql(sqlChange, parameters.ToArray()); } } return count; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-删除信息"); throw ex; } } #endregion #region 获取工艺路线工序列表 /// /// 获取工艺路线工序列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetProcessRouteWorkCellData(ProcessRouteWorkCell condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetProcessRouteWorkCellSql(condition, ref parameters); #region 排序 //分页关键字段及排序 page.KeyName = "PID"; if (string.IsNullOrEmpty(page.SortExpression)) { page.SortExpression = "UPDATEDATE DESC"; } #endregion using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sql, session); page = session.GetDataPage(sqlChange, parameters.ToArray(), page); } return page; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-获取列表"); throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetProcessRouteWorkCellSql(ProcessRouteWorkCell condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { sqlBuilder.AppendLine(@" SELECT A.PID ,B.ROUTE_CODE ,B.ROUTE_NAME ,C.WORKCELL_CODE ,C.WORKCELL_NAME ,A.REMARK ,A.VER_NUM ,A.FLAG_QC ,A.CREATEUSER ,A.CREATEDATE ,A.UPDATEUSER ,A.UPDATEDATE ,A.FLGDEL ,STUFF((SELECT ','+RTRIM(S.PRE_WORKCELL_CODE)+'/'+S1.WORKCELL_NAME FROM T_MD_PROCESS_ROUTE_WORKCELL_SEQ S LEFT JOIN T_MD_WORKCELL S1 ON S.PRE_WORKCELL_CODE = S1.WORKCELL_CODE AND S1.FLGDEL = '0' WHERE S.ROUTE_CODE=A.ROUTE_CODE AND S.WORKCELL_CODE=A.WORKCELL_CODE AND S.FLGDEL='0' FOR XML PATH('')),1,1,'') AS PRE_WORKCELL_CODE FROM T_MD_PROCESS_ROUTE_WORKCELL A LEFT JOIN T_MD_PROCESS_ROUTE B ON B.ROUTE_CODE=A.ROUTE_CODE LEFT JOIN T_MD_WORKCELL C ON C.WORKCELL_CODE=A.WORKCELL_CODE "); if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false) { whereBuilder.Append(" AND A.ROUTE_CODE = @ROUTE_CODE"); parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE }); } whereBuilder.Append(" AND A.FLGDEL = '0' "); //查询条件 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion #region 判断工序编号是否存在 /// /// 判断工序编号是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsProcess(ProcessRouteWorkCell model) { List parameters = new List(); StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); int count = 0; try { sqlBuilder.Append("SELECT COUNT(*) FROM T_MD_PROCESS_ROUTE_WORKCELL T "); //查询条件 if (string.IsNullOrEmpty(model.ROUTE_CODE) == false) { whereBuilder.Append(" AND T.ROUTE_CODE = @ROUTE_CODE"); parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = model.ROUTE_CODE }); } if (string.IsNullOrEmpty(model.WORKCELL_CODE) == false) { whereBuilder.Append(" AND T.WORKCELL_CODE = @WORKCELL_CODE"); parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = model.WORKCELL_CODE }); } whereBuilder.Append(" AND T.FLGDEL = '0' "); if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session); count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, parameters.ToArray())); } if (count > 0) { return true; } else { return false; } } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-判断工序编号是否存在"); throw ex; } } #endregion #region 插入工序配置信息 /// /// 插入工序配置信息(单表) /// /// 工序配置信息 /// 插入行数 public int InsertProcessRouteWorkCell(ProcessRouteWorkCell model) { int count = 0; try { if (BaseSession != null) { //插入基本信息 count = BaseSession.Insert(model); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(model); } } return count; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-插入工序配置信息"); throw ex; } } #endregion #region 插入工序与前置工序中间表 /// /// 插入工序与前置工序中间表 /// /// 工序配置信息 /// 插入行数 public int InsertProcessRouteWorkCellSeq(List list) { int count = 0; try { if (BaseSession != null) { //插入基本信息 count = BaseSession.Insert(list); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(list); } } return count; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-插入工序与前置工序中间表"); throw ex; } } #endregion #region 删除工序配置信息 /// /// 删除工序配置信息 /// /// 工序配置信息(ID) /// 删除个数 public int DeleteProcessRouteWorkCell(ProcessRouteWorkCell model) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { sqlBuilder.Append(" UPDATE T_MD_PROCESS_ROUTE_WORKCELL SET FLGDEL=@FLGDEL "); parameters.Add(new DataParameter() { ParameterName = "FLGDEL", DataType = DbType.String, Value ="1"}); if (string.IsNullOrEmpty(model.ROUTE_CODE) == false) { whereBuilder.Append(" AND ROUTE_CODE=@ROUTE_CODE"); parameters.Add(new DataParameter() { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = model.ROUTE_CODE }); } if (string.IsNullOrEmpty(model.PID) == false) { whereBuilder.Append(" AND PID=@PID"); parameters.Add(new DataParameter() { ParameterName = "PID", DataType = DbType.String, Value = model.PID }); } //查询条件 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } if (BaseSession != null) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession); //删除基本信息 count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray()); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session); //删除基本信息 count = session.ExecuteSql(sqlChange, parameters.ToArray()); } } return count; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-删除工序配置信息"); throw ex; } } #endregion #region 删除工序与前置工序中间表 /// /// 删除工序与前置工序中间表 /// /// 工序配置信息(ID) /// 删除个数 public int DeleteProcessRouteWorkCellSeq(ProcessRouteWorkCell model) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { sqlBuilder.Append(" UPDATE T_MD_PROCESS_ROUTE_WORKCELL_SEQ SET FLGDEL=@FLGDEL "); parameters.Add(new DataParameter() { ParameterName = "FLGDEL", DataType = DbType.String, Value = "1"}); if (string.IsNullOrEmpty(model.ROUTE_CODE) == false) { whereBuilder.Append(" AND ROUTE_CODE=@ROUTE_CODE"); parameters.Add(new DataParameter() { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = model.ROUTE_CODE }); } if (string.IsNullOrEmpty(model.WORKCELL_CODE) == false) { whereBuilder.Append(" AND WORKCELL_CODE=@WORKCELL_CODE"); parameters.Add(new DataParameter() { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = model.WORKCELL_CODE }); } //查询条件 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } if (BaseSession != null) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession); //删除基本信息 count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray()); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session); //删除基本信息 count = session.ExecuteSql(sqlChange, parameters.ToArray()); } } return count; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-删除工序与前置工序中间表"); throw ex; } } #endregion #region 获取工艺路线数据无分页 /// /// 获取工艺路线数据列表无分页 /// /// 条件 /// 全部集合 public List GetRouteList(ProcessRoute condition) { List list = new List(); string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); sql = sql + " ORDER BY UPDATEDATE DESC "; using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sql, session); list = session.GetList(sqlChange, parameters.ToArray()).ToList(); } return list; } catch (Exception ex) { throw ex; } } #endregion #region 获取工艺路线工序列表无分页 /// /// 获取工艺路线工序列表无分页 /// /// 条件 /// 数据页 /// 数据页 public List GetProcessRouteWorkCellData(ProcessRouteWorkCell condition) { string sql = null; List list = new List(); List parameters = new List(); try { sql = this.GetProcessRouteWorkCellSql(condition, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sql, session); list = session.GetList(sqlChange, parameters.ToArray()).ToList(); } return list; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-获取工艺路线工序列表"); throw ex; } } #endregion #region 根据工序获得工艺路线 /// /// 根据工序获得工艺路线 /// /// 工序编码 /// 工艺路线 public ProcessRoute GetProcessRouteByWorkCell(string workCellCode) { ProcessRoute route = new ProcessRoute(); List parameters = new List(); try { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append(" SELECT "); sqlBuilder.Append(GetSqlSelectItem("A")); sqlBuilder.Append(" FROM "); sqlBuilder.Append(" T_MD_PROCESS_ROUTE A "); sqlBuilder.Append(" LEFT JOIN T_MD_PROCESS_ROUTE_WORKCELL B "); sqlBuilder.Append(" ON A.ROUTE_CODE = B.ROUTE_CODE AND B.FLGDEL = '0' "); sqlBuilder.Append(" WHERE "); sqlBuilder.Append(" B.WORKCELL_CODE = @WORKCELL_CODE "); sqlBuilder.Append(" AND A.FLGDEL = '0' "); parameters.Add(new DataParameter("WORKCELL_CODE",DbType.String,workCellCode)); if (null != BaseSession) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession); route = BaseSession.Get(sqlChange, parameters.ToArray()); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session); route = session.Get(sqlChange, parameters.ToArray()); } } return route; } catch (Exception ex) { RecordExceptionLog(ex, "工艺路线数据层-根据工序获取工艺路线"); throw ex; } } #endregion #region 得到检索项目 /// /// 得到检索项目 /// /// /// private string GetSqlSelectItem(string suffix) { String[] tableItem = {"PID" ,"ROUTE_CODE" ,"ROUTE_NAME" ,"EFF_DATE" ,"EXP_DATE" ,"ROUTE_VER" ,"REMARK" ,"CREATEUSER" ,"CREATEDATE" ,"UPDATEUSER" ,"UPDATEDATE" ,"FLGDEL" }; StringBuilder sb = new StringBuilder(); if (String.IsNullOrEmpty(suffix)) { suffix = ","; } else { suffix = "," + suffix + "."; } foreach (string str in tableItem) { sb.Append(suffix).Append(str); } return sb.ToString().Substring(1); } #endregion #region 根据BOM和工序定位工艺路线 /// /// 根据BOM和工序定位工艺路线 /// /// /// /// public RouteLocation LocateRoute(string bomcode, string workcellcode) { StringBuilder sql = new StringBuilder(); List parameters = new List(); try { /* sql.AppendLine("SELECT R.[ROUTE_CODE] AS [RouteCode] "); sql.AppendLine(" ,R.[ROUTE_NAME] AS [RouteName] "); sql.AppendLine(" ,MR.[MATERIAL_CODE] AS [BomCode] "); sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE_WORKCELL] AS RW "); sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL_ROUTE] AS MR "); sql.AppendLine(" ON RW.[ROUTE_CODE]=MR.[ROUTE_CODE] "); sql.AppendLine(" LEFT JOIN [T_MD_PROCESS_ROUTE] AS R "); sql.AppendLine(" ON RW.[ROUTE_CODE]=R.[ROUTE_CODE] "); sql.AppendLine(" WHERE [MATERIAL_CODE]=@bomcode "); sql.AppendLine(" AND [WORKCELL_CODE]=@workcellcode "); */ sql.AppendLine("SELECT R.[ROUTE_CODE] AS [RouteCode] "); sql.AppendLine(" ,R.[ROUTE_NAME] AS [RouteName] "); sql.AppendLine(" ,P.[PBOM_CODE] AS [BomCode] "); sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE] AS R "); sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL_ROUTE] AS MR "); sql.AppendLine(" ON R.[ROUTE_CODE]=MR.[ROUTE_CODE] "); sql.AppendLine(" LEFT JOIN [T_MD_PBOM] AS P "); sql.AppendLine(" ON P.[MATERIAL_CODE]=MR.[MATERIAL_CODE] "); sql.AppendLine(" WHERE EXISTS(SELECT 1 "); sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE_WORKCELL] AS RW "); sql.AppendLine(" WHERE RW.[ROUTE_CODE]=R.[ROUTE_CODE] "); sql.AppendLine(" AND RW.[WORKCELL_CODE]=@workcellcode ) "); sql.AppendLine(" AND P.PBOM_CODE=@bomcode "); parameters.Add(new DataParameter("bomcode", bomcode)); parameters.Add(new DataParameter("workcellcode", workcellcode)); using (var session = AppDataFactory.CreateMainSession()) { var route = session.Get(sql.ToString(), parameters.ToArray()); return route; } } catch (Exception ex) { throw ex; } } #endregion #region 根据工序定位工艺路线 /// /// 根据工序定位工艺路线 /// /// /// public RouteLocation LocateRoute(string workcellcode) { StringBuilder sql = new StringBuilder(); List parameters = new List(); try { sql.AppendLine("SELECT R.[ROUTE_CODE] AS [RouteCode] "); sql.AppendLine(" ,R.[ROUTE_NAME] AS [RouteName] "); sql.AppendLine(" ,'' AS [BomCode] "); sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE_WORKCELL] AS RW "); sql.AppendLine(" LEFT JOIN [T_MD_PROCESS_ROUTE] AS R "); sql.AppendLine(" ON RW.[ROUTE_CODE]=R.[ROUTE_CODE] "); sql.AppendLine(" WHERE [WORKCELL_CODE]=@workcellcode and RW.FLGDEL = '0'"); parameters.Add(new DataParameter("workcellcode", workcellcode)); using (var session = AppDataFactory.CreateMainSession()) { var route = session.Get(sql.ToString(), parameters.ToArray()); return route; } } catch (Exception ex) { throw ex; } } #endregion #region 根据物料定位工艺路线 /// /// 根据物料定位工艺路线 /// /// /// public ProcessRoute RouteWithMaterial(string material) { StringBuilder sql = new StringBuilder(); List parameters = new List(); try { sql.AppendLine("SELECT *"); sql.AppendLine(" FROM T_MD_PROCESS_ROUTE AS PR "); sql.AppendLine(" LEFT JOIN T_MD_MATERIAL_ROUTE AS MR "); sql.AppendLine(" ON PR.ROUTE_CODE=MR.ROUTE_CODE "); sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M "); sql.AppendLine(" ON MR.MATERIAL_CODE=M.MATERIAL_CODE "); sql.AppendLine(" WHERE MR.MATERIAL_CODE=@material "); parameters.Add(new DataParameter("material", material)); using (var session = AppDataFactory.CreateMainSession()) { var route = session.Get(sql.ToString(), parameters.ToArray()); return route; } } catch (Exception ex) { throw ex; } } #endregion public ProcessRoute GetRouteByMachine(string machinecode) { StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT * "); sql.AppendLine(" FROM T_MD_PROCESS_ROUTE "); sql.AppendLine(" WHERE ROUTE_CODE=(SELECT top 1 ROUTE_CODE "); sql.AppendLine(" FROM T_MD_PROCESS_ROUTE_WORKCELL "); sql.AppendLine(" WHERE WORKCELL_CODE=(SELECT WORKCELL_CODE "); sql.AppendLine(" FROM T_MD_WORKLOC "); sql.AppendLine(" WHERE WORKLOC_CODE=(SELECT WORKLOC_CODE "); sql.AppendLine(" FROM T_BD_MACHINEINFO "); sql.AppendLine(" WHERE MACHINECODDE=@machinecode)))"); List parameters = new List(); parameters.Add(new DataParameter("machinecode", machinecode)); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.Get(sql.ToString(), parameters.ToArray()); } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "工艺路线信息-获取工艺路线列表" }); throw; } } } }