using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMFrameWork.Data; using QMAPP.FJC.Entity.ProductionPlan; using System.Data; using QMAPP.Entity; using QMAPP.DAL; using QMFrameWork.Log; using QMAPP.FJC.Entity.TianJin; //using QMAPP.FJC.Entity.FIS; namespace QMAPP.FJC.DAL.TianJin { /// /// 模块名称:派工单 /// 作 者:张鹏 /// 编写日期:2017年10月24日 /// public class TJWorkOrderDAL : BaseDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public TJWorkOrder Get(TJWorkOrder info) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 info = session.Get(info); } return info; } catch (Exception ex) { throw ex; } } public TJWorkOrder GetOne(string ORDERPLANID) { string sql = "SELECT * FROM [T_PP_TJFY_WORKORDER] WITH(NOLOCK) where [ORDERPLANID]='" + ORDERPLANID + "'"; List parameters = new List(); try { if (BaseSession != null) { return BaseSession.GetList(sql, parameters.ToArray()).FirstOrDefault(); } using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, parameters.ToArray()).FirstOrDefault(); } } catch (Exception ex) { throw ex; } } public TJWorkOrder GetOneByID(string id) { string sql = "SELECT * FROM [T_PP_TJFY_WORKORDER] WITH(NOLOCK) where [PID]='" + id + "'"; List parameters = new List(); try { if (BaseSession != null) { return BaseSession.GetList(sql, parameters.ToArray()).FirstOrDefault(); } using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, parameters.ToArray()).FirstOrDefault(); } } catch (Exception ex) { throw ex; } } public TJWorkOrder GetOneByOrderNO(string ORDERPLANNO) { string sql = "SELECT * FROM [T_PP_TJFY_WORKORDER] WITH(NOLOCK) where [ORDERPLAN_NO]='" + ORDERPLANNO + "'"; List parameters = new List(); try { if (BaseSession != null) { return BaseSession.GetList(sql, parameters.ToArray()).FirstOrDefault(); } using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, parameters.ToArray()).FirstOrDefault(); } } catch (Exception ex) { throw ex; } } public TJWorkOrder GetOneByProduct(string productCode) { string sql = "SELECT * FROM [T_PP_TJFY_WORKORDER] WITH(NOLOCK) where [REMARK]='" + productCode + "'"; List parameters = new List(); try { if (BaseSession != null) { return BaseSession.GetList(sql, parameters.ToArray()).FirstOrDefault(); } using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, parameters.ToArray()).FirstOrDefault(); } } catch (Exception ex) { throw ex; } } /// /// 获取计划单号下所有派工单信息 /// /// /// public int GetAllWorkOrder(string ORDERPLANID) { int count = 0; string sql = "SELECT COUNT(1) FROM [T_PP_TJFY_WORKORDER] WITH(NOLOCK) where [ORDERPLANID]='" + ORDERPLANID + "' AND STATE<>0"; List parameters = new List(); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { count =Convert.ToInt32(session.ExecuteSqlScalar(sql, parameters.ToArray())); } } catch (Exception ex) { throw ex; } return count; } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(TJWorkOrder condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); //分页关键字段及排序 page.KeyName = "PID"; if (string.IsNullOrEmpty(page.SortExpression)) page.SortExpression = "UPDATEDATE DESC"; using (IDataSession session = AppDataFactory.CreateMainSession()) { page = session.GetDataPage(sql, parameters.ToArray(), page); } return page; } catch (Exception ex) { throw ex; } } public List GetList(TJWorkOrder condition) { List workOrderList = new List(); string sql = "select * from T_PP_TJFY_WORKORDER WITH(NOLOCK) t where 1=1 "; if (string.IsNullOrEmpty(condition.ORDERPLANID) == false) { sql += string.Format(" and ORDERPLANID='{0}'",condition.ORDERPLANID); } using (IDataSession session = AppDataFactory.CreateMainSession()) { workOrderList = session.GetList(sql, new List().ToArray()).ToList(); } return workOrderList; } public List GetWorkOrderInfo(string planno) { try { StringBuilder sql = new StringBuilder(); sql.AppendFormat("SELECT W.[PID]"); sql.AppendFormat(" ,W.[ORDERPLANID] "); sql.AppendFormat(" ,W.[ORDERPLAN_NO] "); sql.AppendFormat(" ,W.[ORDER_TYPE] "); sql.AppendFormat(" ,W.[SEQ] "); sql.AppendFormat(" ,W.[MATERIAL_CODE] "); sql.AppendFormat(" ,M.[MATERIAL_NAME] "); sql.AppendFormat(" ,W.[PBOM_CODE] "); sql.AppendFormat(" ,W.[QTY] "); sql.AppendFormat(" ,W.[COMPLETE_QTY] "); sql.AppendFormat(" ,W.[PLAN_DATE] "); sql.AppendFormat(" ,W.[SHIFT_CODE] "); sql.AppendFormat(" ,W.[WORKCENTER_CODE] "); sql.AppendFormat(" ,W.[WORKCENTER_NAME] "); sql.AppendFormat(" ,W.[WORKCELL_CODE] "); sql.AppendFormat(" ,W.[WORKCELL_NAME] "); sql.AppendFormat(" ,W.[WORKLOC_CODE] "); sql.AppendFormat(" ,W.[REMARK] "); sql.AppendFormat(" ,W.[EQPT_NAME] "); sql.AppendFormat(" ,W.[EQPT_CODE] "); sql.AppendFormat(" ,W.[STATE] "); sql.AppendFormat(" ,W.[MOULD_CODE] "); sql.AppendFormat(" ,W.[PRI] "); sql.AppendFormat(" ,W.[UPDATEDATE] "); sql.AppendFormat(" ,W.[PRINTED] "); sql.AppendFormat(" ,P.[IGNORE_FISBREAK] "); sql.AppendFormat(" ,P.[FIS_ASMSETCODE] "); sql.AppendFormat(" FROM [T_PP_TJFY_WORKORDER] AS W WITH(NOLOCK) "); sql.AppendFormat(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendFormat(" ON P.[PID]=W.[ORDERPLANID] "); sql.AppendFormat(" LEFT JOIN [T_MD_MATERIAL] AS M WITH(NOLOCK) "); sql.AppendFormat(" ON W.[MATERIAL_CODE]=M.[MATERIAL_CODE] "); sql.AppendFormat(" WHERE P.[PLAN_NO]=@planno "); sql.AppendFormat(" ORDER BY W.[UPDATEDATE],W.[PRI],W.[PLAN_DATE],P.PLAN_SEQ,W.[SEQ],W.[MATERIAL_CODE] "); List parameters = new List(); parameters.Add(new DataParameter("planno", planno)); using (var session = AppDataFactory.CreateMainSession()) { return session.GetList(sql.ToString(), parameters.ToArray()).ToList(); } } catch (Exception ex) { throw ex; } } /// /// 获取指定工序的生产计划清单 /// /// 工序编码 /// 数量 /// 过滤选项:0全部;1隐藏挂起;2只看挂起 /// public List GetOrderInCell(string workcellcode,int filter=0, int count = 20) { try { StringBuilder sql = new StringBuilder(); sql.AppendFormat("SELECT TOP {0} W.[PID]\r\n", count); sql.AppendFormat(" ,W.[ORDERPLANID] "); sql.AppendFormat(" ,W.[ORDERPLAN_NO] "); sql.AppendFormat(" ,W.[ORDER_TYPE] "); sql.AppendFormat(" ,W.[SEQ] "); sql.AppendFormat(" ,W.[MATERIAL_CODE] "); sql.AppendFormat(" ,M.[MATERIAL_NAME] "); sql.AppendFormat(" ,W.[PBOM_CODE] "); sql.AppendFormat(" ,W.[QTY] "); sql.AppendFormat(" ,W.[COMPLETE_QTY] "); sql.AppendFormat(" ,W.[PLAN_DATE] "); sql.AppendFormat(" ,W.[SHIFT_CODE] "); sql.AppendFormat(" ,W.[WORKCENTER_CODE] "); sql.AppendFormat(" ,W.[WORKCENTER_NAME] "); sql.AppendFormat(" ,W.[WORKCELL_CODE] "); sql.AppendFormat(" ,W.[WORKCELL_NAME] "); sql.AppendFormat(" ,W.[WORKLOC_CODE] "); sql.AppendFormat(" ,W.[REMARK] "); sql.AppendFormat(" ,W.[EQPT_NAME] "); sql.AppendFormat(" ,W.[EQPT_CODE] "); sql.AppendFormat(" ,W.[STATE] "); sql.AppendFormat(" ,W.[MOULD_CODE] "); sql.AppendFormat(" ,W.[PRI] "); sql.AppendFormat(" ,W.[UPDATEDATE] "); sql.AppendFormat(" ,P.[IGNORE_FISBREAK] "); sql.AppendFormat(" ,P.[FIS_ASMSETCODE] "); sql.AppendFormat(" FROM [T_PP_TJFY_WORKORDER] AS W WITH(NOLOCK) "); sql.AppendFormat(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendFormat(" ON P.[PID]=W.[ORDERPLANID] "); sql.AppendFormat(" LEFT JOIN [T_MD_MATERIAL] AS M WITH(NOLOCK)"); sql.AppendFormat(" ON W.[MATERIAL_CODE]=M.[MATERIAL_CODE] "); sql.AppendFormat(" WHERE W.[WORKCELL_CODE]=@workcellcode "); switch (filter) { case 1: { sql.AppendFormat(" AND W.[STATE]<>4 "); break; } case 2: { sql.AppendFormat(" AND W.[STATE]=4 "); break; } } sql.AppendFormat(" ORDER BY W.[UPDATEDATE],W.[PRI],W.[PLAN_DATE],P.PLAN_SEQ,W.[SEQ],W.[MATERIAL_CODE] "); List parameters = new List(); parameters.Add(new DataParameter("workcellcode", workcellcode)); using (var session = AppDataFactory.CreateMainSession()) { return session.GetList(sql.ToString(), parameters.ToArray()).ToList(); } } catch(Exception ex) { throw ex; } } /// /// 获取指定工序的生产计划清单 /// /// 工序编码 /// 数量 /// 过滤选项:0全部;1隐藏挂起;2只看挂起 /// public List GetOrderUnPrinted(string routecode, int filter = 0, int count = 20) { try { StringBuilder sql = new StringBuilder(); sql.AppendFormat("SELECT TOP {0} W.[PID]\r\n", count); sql.AppendFormat(" ,W.[ORDERPLANID] "); sql.AppendFormat(" ,W.[ORDERPLAN_NO] "); sql.AppendFormat(" ,W.[ORDER_TYPE] "); sql.AppendFormat(" ,W.[SEQ] "); sql.AppendFormat(" ,W.[MATERIAL_CODE] "); sql.AppendFormat(" ,M.[MATERIAL_NAME] "); sql.AppendFormat(" ,W.[PBOM_CODE] "); sql.AppendFormat(" ,W.[QTY] "); sql.AppendFormat(" ,W.[COMPLETE_QTY] "); sql.AppendFormat(" ,W.[PLAN_DATE] "); sql.AppendFormat(" ,W.[SHIFT_CODE] "); sql.AppendFormat(" ,W.[WORKCENTER_CODE] "); sql.AppendFormat(" ,W.[WORKCENTER_NAME] "); sql.AppendFormat(" ,W.[WORKCELL_CODE] "); sql.AppendFormat(" ,W.[WORKCELL_NAME] "); sql.AppendFormat(" ,W.[WORKLOC_CODE] "); sql.AppendFormat(" ,W.[REMARK] "); sql.AppendFormat(" ,W.[EQPT_NAME] "); sql.AppendFormat(" ,W.[EQPT_CODE] "); sql.AppendFormat(" ,W.[STATE] "); sql.AppendFormat(" ,W.[MOULD_CODE] "); sql.AppendFormat(" ,W.[PRI] "); sql.AppendFormat(" ,W.[UPDATEDATE] "); sql.AppendFormat(" ,W.[PRINTED] "); sql.AppendFormat(" ,P.[IGNORE_FISBREAK] "); sql.AppendFormat(" ,P.[FIS_ASMSETCODE] "); sql.AppendFormat(" FROM [T_PP_TJFY_WORKORDER] AS W WITH(NOLOCK) "); sql.AppendFormat(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendFormat(" ON P.[PID]=W.[ORDERPLANID] "); sql.AppendFormat(" LEFT JOIN [T_MD_MATERIAL] AS M WITH(NOLOCK) "); sql.AppendFormat(" ON W.[MATERIAL_CODE]=M.[MATERIAL_CODE] "); sql.AppendFormat(" WHERE P.[ROUTE_CODE]=@routecode "); sql.AppendFormat(" AND W.[PRINTED]='0' "); switch (filter) { case 1: { sql.AppendFormat(" AND W.[STATE]<>4 "); break; } case 2: { sql.AppendFormat(" AND W.[STATE]=4 "); break; } } sql.AppendFormat(" ORDER BY W.[UPDATEDATE],W.[PRI],W.[PLAN_DATE],P.PLAN_SEQ,W.[SEQ],W.[MATERIAL_CODE] "); List parameters = new List(); parameters.Add(new DataParameter("routecode", routecode)); using (var session = AppDataFactory.CreateMainSession()) { return session.GetList(sql.ToString(), parameters.ToArray()).ToList(); } } catch (Exception ex) { throw ex; } } /// /// 获取指定工序的待完成计划数量 /// /// 工序编码 /// 不指定班次则查询全部计划 /// 不指定班次则无需输入日期 /// public int GetOrderCountInCell(string workcellcode,string shift,DateTime date) { try { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendFormat("SELECT COUNT(*) "); sql.AppendFormat(" FROM [T_PP_TJFY_WORKORDER] WITH(NOLOCK) "); sql.AppendFormat(" WHERE [WORKCELL_CODE]=@workcellcode "); sql.AppendFormat(" AND [STATE]<>4"); if (!string.IsNullOrWhiteSpace(shift)) { sql.AppendFormat(" AND [SHIFT_CODE]=@shift"); parameters.Add(new DataParameter("shift", shift)); //sql.AppendFormat(" AND DATEDIFF(DAY,[PLAN_DATE],@date)=0"); //parameters.Add(new DataParameter("date", date)); sql.AppendFormat(" AND [PLAN_DATE] BETWEEN @date1 AND @date2"); parameters.Add(new DataParameter("date1", date.Date)); parameters.Add(new DataParameter("date2", date.Date.AddDays(1))); } parameters.Add(new DataParameter("workcellcode", workcellcode)); using (var session = AppDataFactory.CreateMainSession()) { return (int)session.ExecuteSqlScalar(sql.ToString(), parameters.ToArray()); } } catch (Exception ex) { throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(TJWorkOrder condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append("SELECT PID,ORDERPLANID,ORDERPLAN_NO,ORDER_TYPE,SEQ,MATERIAL_CODE,PBOM_CODE,QTY,COMPLETE_QTY,PLAN_DATE,SHIFT_CODE,WORKCENTER_CODE,WORKCENTER_NAME,WORKCELL_CODE,WORKCELL_NAME,WORKLOC_CODE,REMARK,EQPT_NAME,EQPT_CODE,STATE "); sqlBuilder.Append("FROM T_PP_TJFY_WORKORDER WITH(NOLOCK) "); whereBuilder.Append(" AND FLGDEL<> '1' "); //查询条件 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion #region 获取导出的数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(TJWorkOrder info) { DataTable dt = null; string sql = null; List parameters = new List(); try { //构成查询语句 sql = this.GetQuerySql(info, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = "TJWorkOrder"; } return dt; } catch (Exception ex) { throw ex; } } #endregion #region 信息是否重复 /// /// 判断名称是否存在 /// /// /// true:已存在;fasel:不存在。 public bool Exists(TJWorkOrder info) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { sqlBuilder.Append("SELECT COUNT(0) FROM T_PP_TJFY_WORKORDER WITH(NOLOCK) "); if (info.PID == null) { info.PID = ""; } whereBuilder.Append(" AND PID <> @PID "); parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID }); //添加进行无重复字段判断代码 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } using (IDataSession session = AppDataFactory.CreateMainSession()) { count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray())); } return count > 0; } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public int Insert(TJWorkOrder info) { try { if (BaseSession != null) { return BaseSession.Insert(info); } using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 return session.Insert(info); } } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public int Update(TJWorkOrder info) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //更新基本信息 count = session.Update(info); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 逻辑删除 /// /// 逻辑删除信息 /// /// /// 删除个数 public int Delete(TJWorkOrder info) { StringBuilder sqlBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //删除基本信息 sqlBuilder.Append("UPDATE T_PP_TJFY_WORKORDER "); sqlBuilder.Append("SET FLGDEL = '1' "); sqlBuilder.Append("WHERE PID = @PID "); parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID }); count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray()); } return count; } catch (Exception ex) { throw ex; } } #endregion /// /// 删除派工单 /// /// public void BatchDeleteByOrderPlan(TJWorkOrder entity) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { string deleteSql = string.Format("delete from T_PP_TJFY_WORKORDER where ORDERPLANID='{0}' ", entity.ORDERPLANID); session.ExecuteSql(deleteSql, new List().ToArray()); } } catch (Exception ex) { throw ex; } } #region 导入 public ImportMessage GetImportData(List list) { ImportMessage em = new ImportMessage(); List parameters = new List(); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //设置祖先对象数据会话 session.OpenTs(); foreach (TJWorkOrder info in list) { if (info.IsNewInfo) { //插入信息 int count = session.Insert(info); em.insertNum++; } else { //更新信息 int count = session.Update(info); em.updateNum++; } } session.CommitTs(); } } catch (Exception ex) { throw ex; } return em; } #endregion /// /// 获取指定工位正在执行的派工单 /// /// /// public TJWorkOrder GetWorkingOrderInLoc(string workloccode,string mouldcode) { try { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT O.* "); sql.AppendLine(" ,P.[IGNORE_FISBREAK] "); sql.AppendLine(" ,P.[FIS_ASMSETCODE] "); sql.AppendLine(" FROM [T_PP_TJFY_WORKORDER] AS O WITH(NOLOCK) "); sql.AppendLine(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendLine(" ON P.[PID]=O.[ORDERPLANID] "); sql.AppendLine(" WHERE O.[WORKLOC_CODE]=@workloccode "); sql.AppendLine(" AND O.[MOULD_CODE]=@mouldcode "); sql.AppendLine(" AND O.[STATE]='2' "); //工单状态为执行中 parameters.Add(new DataParameter("workloccode", workloccode)); parameters.Add(new DataParameter("mouldcode", mouldcode)); using (var session = AppDataFactory.CreateMainSession()) { return session.Get(sql.ToString(), parameters.ToArray()); } } catch (Exception ex) { throw ex; } } /// /// 获取第一条匹配的派工单 /// /// 工序 /// 产品物料号 /// public TJWorkOrder GetFirstMatchOrder(string workcellcode, string productmaterial,string planpid="") { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT TOP 1 O.* "); sql.AppendLine(" ,P.[IGNORE_FISBREAK] "); sql.AppendLine(" ,P.[FIS_ASMSETCODE] "); sql.AppendLine(" FROM [T_PP_TJFY_WORKORDER] AS O WITH(NOLOCK) "); sql.AppendLine(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendLine(" ON P.[PID]=O.[ORDERPLANID] "); sql.AppendLine(" WHERE O.[WORKCELL_CODE]=@workcellcode "); if (!string.IsNullOrWhiteSpace(planpid)) { sql.AppendLine(" AND O.[ORDERPLANID]=@planpid"); parameters.Add(new DataParameter("planpid", planpid)); } sql.AppendLine(" AND (EXISTS (SELECT 1 "); sql.AppendLine(" FROM T_MD_PBOM_ITEM AS I "); sql.AppendLine(" WHERE O.PBOM_CODE = I.PBOM_CODE "); sql.AppendLine(" AND I.FLGDEL = '0' "); sql.AppendLine(" AND I.MATERIAL_CODE = @materialcode) "); sql.AppendLine(" OR O.[MATERIAL_CODE]=@materialcode) "); sql.AppendLine(" AND (O.[STATE]='0' OR O.[STATE]='1') "); sql.AppendLine(" ORDER BY O.UPDATEDATE,O.PRI,O.PLAN_DATE,P.PLAN_SEQ,SEQ "); //排序为 FIS优先、日期正序、顺序号正序 parameters.Add(new DataParameter("workcellcode", workcellcode)); parameters.Add(new DataParameter("materialcode", productmaterial)); using (var session = AppDataFactory.CreateMainSession()) { return session.Get(sql.ToString(), parameters.ToArray()); } } /// /// 获取工序下匹配的派工单 /// /// 工序 /// public List GetMatchOrders(string workcellcode,string planpid="") { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT W.* "); sql.AppendLine(" ,P.[IGNORE_FISBREAK] "); sql.AppendLine(" ,P.[FIS_ASMSETCODE] "); sql.AppendLine(" FROM [T_PP_TJFY_WORKORDER] AS W WITH(NOLOCK) "); sql.AppendLine(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendLine(" ON P.[PID]=W.[ORDERPLANID] "); sql.AppendLine(" WHERE W.SEQ = (SELECT TOP 1 SEQ "); sql.AppendLine(" FROM [T_PP_TJFY_WORKORDER] AS O WITH(NOLOCK) "); sql.AppendLine(" LEFT JOIN [T_PP_ORDERPLAN] AS P1 WITH(NOLOCK) "); sql.AppendLine(" ON P1.[PID]=O.[ORDERPLANID] "); sql.AppendLine(" WHERE O.[WORKCELL_CODE]=@workcellcode "); sql.AppendLine(" AND (O.[STATE]='0' OR O.[STATE]='1') "); if (!string.IsNullOrWhiteSpace(planpid)) { sql.AppendLine(" AND O.[ORDERPLANID]=@planpid"); } sql.AppendLine(" ORDER BY O.UPDATEDATE,O.PRI,O.PLAN_DATE,P1.PLAN_SEQ,SEQ) ");//排序为 FIS优先、日期正序、计划顺序号、工单顺序号正序 sql.AppendLine(" AND W.[WORKCELL_CODE]=@workcellcode "); sql.AppendLine(" AND (W.[STATE]='0' OR W.[STATE]='1') "); if (!string.IsNullOrWhiteSpace(planpid)) { sql.AppendLine(" AND W.[ORDERPLANID]=@planpid"); parameters.Add(new DataParameter("planpid", planpid)); } parameters.Add(new DataParameter("workcellcode", workcellcode)); using (var session = AppDataFactory.CreateMainSession()) { return session.GetList(sql.ToString(), parameters.ToArray()).ToList(); } } #region 改变派工单 /// /// 改变派工单 /// /// public void ChangeByOrderPlan(TJWorkOrder entity) { if (this.BaseSession != null) { this.BaseSession.Update(entity); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { session.Update(entity); } } } #endregion /// /// 获取派工单 /// /// /// public TJWorkOrder GetworkOrderInfo(TJWorkOrder model) { string sql = null; List parameters = new List(); try { sql = "SELECT TOP 1 * FROM T_PP_TJFY_WORKORDER WITH(NOLOCK) WHERE STATE=0 "; if (string.IsNullOrEmpty(model.ORDERPLANID) == false) { sql += " AND ORDERPLANID = @ORDERPLANID"; parameters.Add(new DataParameter("ORDERPLANID", model.ORDERPLANID)); } if (BaseSession != null) { //获取信息 model = BaseSession.Get(sql, parameters.ToArray()); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 model = session.Get(sql, parameters.ToArray()); } } return model; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "信息数据层-获取信息" }); throw; } } /// /// 获取指定日期前的FIS计划顺序号 /// /// /// /// public string GetLastFISSEQ(DateTime plandate, string workcentercode) { StringBuilder sql = new StringBuilder() ; List parameters = new List(); try { sql.AppendLine("SELECT TOP 1 [PLAN_SEQ] "); sql.AppendLine(" FROM [T_PP_ORDERPLAN] WITH(NOLOCK) "); sql.AppendLine(" WHERE [PLANSOURCE]='0' "); sql.AppendLine(" AND [PLAN_DATE]<@plandate "); sql.AppendLine(" AND [WORKCENTER_CODE]=@workcentercode "); sql.AppendLine(" ORDER BY [PLAN_DATE] DESC "); parameters.Add(new DataParameter("plandate", plandate)); parameters.Add(new DataParameter("workcentercode", workcentercode)); using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 var ret= session.ExecuteSqlScalar(sql.ToString(), parameters.ToArray()); if (ret != null) { return ret.ToString(); } else { return ""; } } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "信息数据层-获取信息" }); throw; } } /// /// 根据模架搜索工单 /// /// /// public TJWorkOrder SearchByMould(string mouldcode, string workcellcode) { try { StringBuilder sql = new StringBuilder(); List parameters = new List(); sql.AppendLine("SELECT TOP 1 W.* "); sql.AppendLine(" FROM T_PP_TJFY_WORKORDER AS W WITH(NOLOCK) "); sql.AppendLine(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendLine(" ON P.[PID]=W.[ORDERPLANID] "); sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M WITH(NOLOCK) "); sql.AppendLine(" ON M.MATERIAL_CODE=W.MATERIAL_CODE "); sql.AppendLine(" LEFT JOIN T_QT_MATERIAL_BINDING AS MB WITH(NOLOCK) "); sql.AppendLine(" ON MB.MATERIAL_CODE=M.MATERIAL_TYPE_CODE "); sql.AppendLine(" AND MB.BINDING_TYPE='ASSY' "); sql.AppendLine(" WHERE MB.TARGET_CODE=@mouldcode "); sql.AppendLine(" AND W.WORKCELL_CODE=@workcellcode "); sql.AppendLine(" AND (W.STATE='1' OR W.STATE='0') "); sql.AppendLine(" ORDER BY W.UPDATEDATE,W.PRI,w.PLAN_DATE,P.PLAN_SEQ,W.SEQ "); parameters.Add(new DataParameter("mouldcode", mouldcode)); parameters.Add(new DataParameter("workcellcode", workcellcode)); 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; } } public List GetListByID(string[] orderid) { try { StringBuilder sql = new StringBuilder(); List parameters = new List(); string ids = string.Join("','", orderid); sql.AppendFormat("SELECT * FROM T_PP_TJFY_WORKORDER WITH(NOLOCK) WHERE PID IN ('{0}')", ids); using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 return session.GetList(sql.ToString(), parameters.ToArray()).ToList(); } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "信息数据层-获取信息GetListByID" }); throw; } } /// /// 批量更新 /// /// /// public int Update(List orders) { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 return session.Update(orders); } } /// /// 批量删除 /// /// /// public int Delete(List orders) { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 return session.Delete(orders); } } public TJWorkOrder GetWorkingOrderWithProduct(string workcellcode, string productcode, string planpid = "") { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT TOP 1 O.* "); sql.AppendLine(" ,P.[IGNORE_FISBREAK] "); sql.AppendLine(" ,P.[FIS_ASMSETCODE] "); sql.AppendLine(" FROM [T_PP_TJFY_WORKORDER] AS O WITH(NOLOCK) "); sql.AppendLine(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) "); sql.AppendLine(" ON P.[PID]=O.[ORDERPLANID] "); sql.AppendLine(" WHERE O.[WORKCELL_CODE]=@workcellcode "); if (!string.IsNullOrWhiteSpace(planpid)) { sql.AppendLine(" AND O.[ORDERPLANID]=@planpid"); parameters.Add(new DataParameter("planpid", planpid)); } sql.AppendLine(" AND O.[REMARK]=@productcode"); sql.AppendLine(" AND (O.[STATE]='0' OR O.[STATE]='1') "); sql.AppendLine(" ORDER BY O.UPDATEDATE,O.PRI,O.PLAN_DATE,P.PLAN_SEQ,SEQ "); //排序为 FIS优先、日期正序、顺序号正序 parameters.Add(new DataParameter("workcellcode", workcellcode)); parameters.Add(new DataParameter("productcode", productcode)); using (var session = AppDataFactory.CreateMainSession()) { return session.Get(sql.ToString(), parameters.ToArray()); } } public int GetDayPlanCount(string workcentercode, DateTime date) { try { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT ISNULL(SUM(QTY),0) "); sql.AppendLine(" FROM T_PP_ORDERPLAN WITH(NOLOCK) "); sql.AppendLine(" WHERE WORKCENTER_CODE=@workcentercode "); //sql.AppendLine(" AND DATEDIFF(DAY,PLAN_DATE,@date)=0 "); sql.AppendFormat(" AND [PLAN_DATE] BETWEEN @date1 AND @date2"); parameters.Add(new DataParameter("date1", date.Date)); parameters.Add(new DataParameter("date2", date.Date.AddDays(1))); parameters.Add(new DataParameter("workcentercode", workcentercode)); //parameters.Add(new DataParameter("date", date)); using (var session = AppDataFactory.CreateMainSession()) { return (int)session.ExecuteSqlScalar(sql.ToString(), parameters.ToArray()); } } catch (Exception ex) { throw ex; } } public int SetOrderPrinted(string orderpid) { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE T_PP_TJFY_WORKORDER SET PRINTED='1' WHERE PID=@orderpid"); parameters.Add(new DataParameter("orderpid", orderpid)); using (var session = AppDataFactory.CreateMainSession()) { return session.ExecuteSql(sql.ToString(), parameters.ToArray()); } } public List GetLastFISPlan(string workcellcode, string routecode) { List parameters = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT TOP 2 P.* "); sql.AppendLine(" FROM T_PP_ORDERPLAN AS P WITH(NOLOCK) "); sql.AppendLine(" LEFT JOIN T_PP_TJFY_WORKORDER AS W WITH(NOLOCK) "); sql.AppendLine(" ON W.ORDERPLAN_NO=P.PLAN_NO "); sql.AppendLine(" WHERE P.PLANSOURCE='0' "); sql.AppendLine(" AND P.ROUTE_CODE=@routecode "); sql.AppendLine(" AND ((W.WORKCELL_CODE=@workcellcode "); sql.AppendLine(" AND W.STATE='4') "); sql.AppendLine(" OR W.WORKCELL_CODE<>@workcellcode) "); sql.AppendLine(" ORDER BY P.PLAN_DATE DESC,P.PLAN_SEQ DESC,P.PLAN_NO DESC"); parameters.Add(new DataParameter("workcellcode", workcellcode)); parameters.Add(new DataParameter("routecode", routecode)); using (var session = AppDataFactory.CreateMainSession()) { return session.GetList(sql.ToString(), parameters.ToArray()).ToList(); } } } }