using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using QMAPP.FJC.Entity.FeedInManage; using QMAPP.FJC.Entity.Injection; using QMFrameWork.Data; using QMFrameWork.Log; using QMAPP.FJC.Entity; namespace QMAPP.FJC.DAL.FeedInManage { /// /// 模块编号:M3-3 /// 作 用:表皮信息查询 /// 作 者:张敬贺 /// 编写日期:2015年05月26日 /// public class EpidermisDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public Epidermis Get(Epidermis model) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 model = session.Get(model); } return model; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "表皮信息投料信息查询错误-获取信息" }); throw; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(Epidermis condition, DataPage page) { string sql = null; string countSql = null; List parameters = new List(); List list = new List(); try { //分页关键字段及排序 page.KeyName = "PID"; if (string.IsNullOrEmpty(page.SortExpression)) { page.SortExpression = "UPDATEDATE DESC"; } sql = this.GetPageQuerySql(condition, ref parameters, page); countSql = this.GetCountQuerySql(condition); int sum = 0; using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql, parameters.ToArray()).ToList(); sum = Convert.ToInt32(session.ExecuteSqlScalar(countSql, parameters.ToArray())); } page.RecordCount = sum; page.Result = list; #region 设置分页属性 if (page.RecordCount == 0) { page.PageIndex = 1; return page; } if (page.RecordCount % page.PageSize != 0) { page.PageCount = page.RecordCount / page.PageSize + 1; if (page.PageCount < page.PageIndex) { page.PageIndex = page.PageCount; } } else { page.PageCount = page.RecordCount / page.PageSize; } if (page.PageCount < page.PageIndex) { page.PageIndex = page.PageCount; } #endregion return page; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "表皮信息获取列表错误!" }); throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(Epidermis condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append(@"SELECT M.PID, M.PRODUCTTYPE, M.PRODUCTCODE, M.MACHINENAME, M.MACHINECODDE, MA.MATERIAL_NAME, MC.MATERIAL_TYPE_NAME, M.MATERIAL_TYPE, M.WORKCELL_CODE, M.MATERIAL_CODE, M.STATUS, M.CURRENTPROCESS, M.PRODUCELINE, M.PRODUCESHIFTNAME, M.PRODUCESHIFTTCODE, M.OUTFLAG, M.USINGSTATE, M.CAPACITY, M.USINGCOUNT, G.USERNAME AS CREATEUSER, CONVERT(VARCHAR(19),M.CREATEDATE,120) AS CREATEDATE, K.USERNAME AS UPDATEUSER, CONVERT(VARCHAR(19),M.UPDATEDATE,120) AS UPDATEDATE "); sqlBuilder.Append("FROM T_AW_PRODUCT M"); sqlBuilder.AppendLine(" LEFT JOIN T_AW_MATERIALTYPE MT ON MT.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER G ON G.USERID=M.CREATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER K ON K.USERID=M.UPDATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE "); #region 查询条件 if (condition.STARTCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND M.CREATEDATE >= @STARTCREATEDATE"); parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") }); } if (condition.ENDCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND M.CREATEDATE < @ENDCREATEDATE"); parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") }); } if (string.IsNullOrEmpty(condition.MATERIAL_TYPE) == false) { whereBuilder.Append(" AND M.MATERIAL_TYPE = @MATERIAL_TYPE"); parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE", DataType = DbType.String, Value = condition.MATERIAL_TYPE }); } if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false) { whereBuilder.Append(" AND M.MATERIAL_CODE = @MATERIAL_CODE"); parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE }); } if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false) { whereBuilder.Append(" AND M.PRODUCTTYPE = @PRODUCTTYPE"); parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE }); } if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false) { whereBuilder.Append(" AND M.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%'"); parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE }); } if (string.IsNullOrEmpty(condition.MACHINECODDE) == false) { whereBuilder.Append(" AND M.MACHINECODDE LIKE '%'+" + "@MACHINECODDE" + "+'%'"); parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE }); } if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false) { whereBuilder.Append(" AND M.CURRENTPROCESS = @CURRENTPROCESS"); parameters.Add(new DataParameter { ParameterName = "CURRENTPROCESS", DataType = DbType.String, Value = condition.CURRENTPROCESS }); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } sqlBuilder.Append(" ORDER BY M.UPDATEDATE DESC"); #endregion return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } /// /// 框架外的分页语句 /// /// /// /// /// private string GetPageQuerySql(Epidermis condition, ref List parameters, DataPage page) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 if (page.SortExpression.Contains("CREATEUSER") == false && page.SortExpression.Contains("UPDATEUSER") == false) { page.SortExpression = "M." + page.SortExpression; } if (page.SortExpression.Contains("CREATEUSER")) { page.SortExpression = page.SortExpression.Substring(page.SortExpression.TrimStart().IndexOf(" ")); page.SortExpression = "G.USERNAME " + page.SortExpression; } if (page.SortExpression.Contains("UPDATEUSER")) { page.SortExpression = page.SortExpression.Substring(page.SortExpression.TrimStart().IndexOf(" ")); page.SortExpression = "K.USERNAME " + page.SortExpression; } sqlBuilder.Append("SELECT * FROM ("); sqlBuilder.AppendFormat(@"SELECT top {0} ROW_NUMBER() OVER (ORDER BY {1} ) AS ROWINDEX,", (page.PageIndex * page.PageSize).ToString(), page.SortExpression); sqlBuilder.Append(@" M.PID, M.PRODUCTTYPE, M.PRODUCTCODE, M.MACHINENAME, M.MACHINECODDE, MA.MATERIAL_NAME, MC.MATERIAL_TYPE_NAME, M.MATERIAL_TYPE, M.WORKCELL_CODE, W.WORKCELL_NAME, PRW.ROUTE_CODE, M.PLAN_NO, M.MATERIAL_CODE, M.STATUS, M.CURRENTPROCESS, M.PRODUCELINE, M.PRODUCESHIFTNAME, M.PRODUCESHIFTTCODE, M.OUTFLAG, M.USINGSTATE, M.CAPACITY, M.USINGCOUNT,"); if (condition.PRODUCTTYPE == EnumGeter.ProductType.biaopi.GetHashCode().ToString()) { sqlBuilder.Append(@"pa.val3 as HB, pa.val4 as COLOR,"); } else { sqlBuilder.Append(@"'' as HB, '' as COLOR,"); } sqlBuilder.Append(@" G.USERNAME AS CREATEUSER, M.CREATEDATE, K.USERNAME AS UPDATEUSER, M.UPDATEDATE "); sqlBuilder.Append(" FROM T_AW_PRODUCT M "); sqlBuilder.AppendLine(" LEFT JOIN T_AW_MATERIALTYPE MT ON MT.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER G ON G.USERID=M.CREATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER K ON K.USERID=M.UPDATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROCESS_ROUTE_WORKCELL PRW ON PRW.WORKCELL_CODE=M.WORKCELL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROCESS_ROUTE PR ON PR.ROUTE_CODE=PRW.ROUTE_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCELL W ON W.WORKCELL_CODE=M.WORKCELL_CODE "); #region 查询条件 if (condition.STARTCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND M.CREATEDATE >= '" + condition.STARTCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") + "'"); } if (condition.ENDCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND M.CREATEDATE < '" + condition.ENDCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") + "'"); } if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false) { whereBuilder.Append(" AND M.PRODUCTTYPE = '" + condition.PRODUCTTYPE + "'"); } if (string.IsNullOrEmpty(condition.PRODUCTTYPES) == false) { whereBuilder.Append(" AND M.PRODUCTTYPE in ('" + condition.PRODUCTTYPES.Replace(",", "','") + "')"); } if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false) { whereBuilder.Append(" AND M.PRODUCTCODE LIKE '" + condition.PRODUCTCODE + "%'"); } if (string.IsNullOrEmpty(condition.PLAN_NO) == false) { whereBuilder.Append(" AND M.PLAN_NO_REV LIKE '" + new string(condition.PLAN_NO.Reverse().ToArray()) + "%'"); } if (string.IsNullOrEmpty(condition.MACHINECODDE) == false) { whereBuilder.Append(" AND M.MACHINECODDE LIKE '" + condition.MACHINECODDE + "%'"); } if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false) { whereBuilder.Append(" AND M.CURRENTPROCESS = '" + condition.CURRENTPROCESS + "'"); } if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false) { whereBuilder.Append(" AND PRW.ROUTE_CODE = '" + condition.ROUTE_CODE + "'"); } if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false) { whereBuilder.Append(" AND M.WORKCELL_CODE = '" + condition.WORKCELL_CODE + "'"); } if (string.IsNullOrEmpty(condition.MATERIAL_TYPE) == false) { whereBuilder.Append(" AND M.MATERIAL_TYPE = @MATERIAL_TYPE"); parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE", DataType = DbType.String, Value = condition.MATERIAL_TYPE }); } if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false) { whereBuilder.Append(" AND M.MATERIAL_CODE = @MATERIAL_CODE"); parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE }); } if (string.IsNullOrEmpty(condition.STATUS) == false) { whereBuilder.Append(" AND M.STATUS = '" + condition.STATUS + "'"); } if (string.IsNullOrEmpty(condition.USINGSTATE) == false) { whereBuilder.Append(" AND M.USINGSTATE = '" + condition.USINGSTATE + "'"); } //if (condition.PRODUCTTYPE == EnumGeter.ProductType.biaopi.GetHashCode().ToString()) //{ // sqlBuilder.Append(" left join T_AW_PRODUCTATTRIBUTE pa on pa.mppid=m.pid"); // if (condition.STARTCREATEDATE != DateTime.MinValue) // { // whereBuilder.Append(" AND pa.CREATEDATE >= '" + condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") + "'"); // } // if (condition.ENDCREATEDATE != DateTime.MinValue) // { // whereBuilder.Append(" AND pa.CREATEDATE < '" + condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); // } // if (string.IsNullOrEmpty(condition.HB) == false) // { // whereBuilder.Append(" AND pa.val3 = '" + condition.HB + "'"); // } // if (string.IsNullOrEmpty(condition.COLOR) == false) // { // whereBuilder.Append(" AND pa.val4 = '" + condition.COLOR + "'"); // } //} if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } sqlBuilder.AppendFormat(") QMDATAPAGE1 WHERE ROWINDEX BETWEEN {0} AND {1}", Convert.ToString(page.PageSize * (page.PageIndex - 1) + 1), Convert.ToString(page.PageSize * page.PageIndex)); #endregion return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } /// /// 获取求和语句 /// /// /// /// private string GetCountQuerySql(Epidermis condition) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { sqlBuilder.Append("SELECT count(1) FROM ("); sqlBuilder.AppendFormat(@"SELECT M.PID, M.PRODUCTTYPE, M.PRODUCTCODE, M.MACHINENAME, M.MACHINECODDE, MA.MATERIAL_NAME, MC.MATERIAL_TYPE_NAME, M.MATERIAL_TYPE, M.WORKCELL_CODE, PRW.ROUTE_CODE, M.PLAN_NO, M.MATERIAL_CODE, M.STATUS, M.CURRENTPROCESS, M.PRODUCELINE, M.PRODUCESHIFTNAME, M.PRODUCESHIFTTCODE, M.OUTFLAG, M.USINGSTATE, M.CAPACITY, M.USINGCOUNT,"); if (condition.PRODUCTTYPE == EnumGeter.ProductType.biaopi.GetHashCode().ToString()) { sqlBuilder.Append(@"pa.val3 as HB, pa.val4 as COLOR,"); } else { sqlBuilder.Append(@"'' as HB, '' as COLOR,"); } sqlBuilder.Append(@" G.USERNAME AS CREATEUSER, M.CREATEDATE, K.USERNAME AS UPDATEUSER, M.UPDATEDATE "); sqlBuilder.Append(" FROM T_AW_PRODUCT M "); sqlBuilder.AppendLine(" LEFT JOIN T_AW_MATERIALTYPE MT ON MT.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER G ON G.USERID=M.CREATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER K ON K.USERID=M.UPDATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROCESS_ROUTE_WORKCELL PRW ON PRW.WORKCELL_CODE=M.WORKCELL_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROCESS_ROUTE PR ON PR.ROUTE_CODE=PRW.ROUTE_CODE "); #region 查询条件 if (condition.STARTCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND M.CREATEDATE >= '" + condition.STARTCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") + "'"); } if (condition.ENDCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND M.CREATEDATE < '" + condition.ENDCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") + "'"); } if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false) { whereBuilder.Append(" AND M.PRODUCTTYPE = '" + condition.PRODUCTTYPE + "'"); } if (string.IsNullOrEmpty(condition.PRODUCTTYPES) == false) { whereBuilder.Append(" AND M.PRODUCTTYPE in ('" + condition.PRODUCTTYPES.Replace(",", "','") + "')"); } if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false) { whereBuilder.Append(" AND M.PRODUCTCODE LIKE '" + condition.PRODUCTCODE + "%'"); } if (string.IsNullOrEmpty(condition.PLAN_NO) == false) { whereBuilder.Append(" AND M.PLAN_NO_REV LIKE '" + new string(condition.PLAN_NO.Reverse().ToArray()) + "%'"); } if (string.IsNullOrEmpty(condition.MACHINECODDE) == false) { whereBuilder.Append(" AND M.MACHINECODDE LIKE '" + condition.MACHINECODDE + "%'"); } if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false) { whereBuilder.Append(" AND M.CURRENTPROCESS = '" + condition.CURRENTPROCESS + "'"); } if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false) { whereBuilder.Append(" AND PRW.ROUTE_CODE = '" + condition.ROUTE_CODE + "'"); } if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false) { whereBuilder.Append(" AND M.WORKCELL_CODE = '" + condition.WORKCELL_CODE + "'"); } if (string.IsNullOrEmpty(condition.MATERIAL_TYPE) == false) { whereBuilder.Append(" AND M.MATERIAL_TYPE = '" + condition.MATERIAL_TYPE + "'"); //parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE", DataType = DbType.String, Value = condition.MATERIAL_TYPE }); } if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false) { whereBuilder.Append(" AND M.MATERIAL_CODE = '" + condition.MATERIAL_CODE + "'"); //parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE }); } if (string.IsNullOrEmpty(condition.STATUS) == false) { whereBuilder.Append(" AND M.STATUS = '" + condition.STATUS + "'"); } if (string.IsNullOrEmpty(condition.USINGSTATE) == false) { whereBuilder.Append(" AND M.USINGSTATE = '" + condition.USINGSTATE + "'"); } //if (condition.PRODUCTTYPE == EnumGeter.ProductType.biaopi.GetHashCode().ToString()) //{ // sqlBuilder.Append(" left join T_AW_PRODUCTATTRIBUTE pa on pa.mppid=m.pid"); // if (condition.STARTCREATEDATE != DateTime.MinValue) // { // whereBuilder.Append(" AND pa.CREATEDATE >= '" + condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") + "'"); // } // if (condition.ENDCREATEDATE != DateTime.MinValue) // { // whereBuilder.Append(" AND pa.CREATEDATE < '" + condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); // } // if (string.IsNullOrEmpty(condition.HB) == false) // { // whereBuilder.Append(" AND pa.val3 = '" + condition.HB + "'"); // } // if (string.IsNullOrEmpty(condition.COLOR) == false) // { // whereBuilder.Append(" AND pa.val4 = '" + condition.COLOR + "'"); // } //} if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } sqlBuilder.Append(" )temp1" ); #endregion return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } #region //StringBuilder sqlBuilder = new StringBuilder(); //StringBuilder whereBuilder = new StringBuilder(); //try //{ // //构成查询语句 // sqlBuilder.Append(@"SELECT count(1) "); // sqlBuilder.Append("FROM T_AW_PRODUCT M"); // #region 查询条件 // if (condition.STARTCREATEDATE != DateTime.MinValue) // { // whereBuilder.Append(" AND M.CREATEDATE >= '" + condition.STARTCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") + "'"); // // parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") }); // } // if (condition.ENDCREATEDATE != DateTime.MinValue) // { // whereBuilder.Append(" AND M.CREATEDATE < '" + condition.ENDCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") + "'"); // // parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") }); // } // if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false) // { // whereBuilder.Append(" AND M.PRODUCTTYPE = '" + condition.PRODUCTTYPE + "'"); // // parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE }); // } // if (string.IsNullOrEmpty(condition.PRODUCTTYPES) == false) // { // whereBuilder.Append(" AND M.PRODUCTTYPE in ('" + condition.PRODUCTTYPES.Replace(",", "','") + "')"); // } // if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false) // { // whereBuilder.Append(" AND M.PRODUCTCODE LIKE '%" + condition.PRODUCTCODE + "%'"); // //parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE }); // } // if (string.IsNullOrEmpty(condition.MACHINECODDE) == false) // { // whereBuilder.Append(" AND M.MACHINECODDE LIKE '%" + condition.MACHINECODDE + "%'"); // //parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE }); // } // if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false) // { // whereBuilder.Append(" AND M.CURRENTPROCESS = '" + condition.CURRENTPROCESS + "'"); // //parameters.Add(new DataParameter { ParameterName = "CURRENTPROCESS", DataType = DbType.String, Value = condition.CURRENTPROCESS }); // } // if (whereBuilder.Length > 0) // { // sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); // } // #endregion // return sqlBuilder.ToString(); //} //catch (Exception ex) //{ // throw ex; //} #endregion } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public int Update(Epidermis model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //更新基本信息 count = session.Update(model); } return count; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "表皮信息投料信息查询错误-更新信息" }); throw; } } #endregion #region 更新表皮相关物料信息 /// /// 更新表皮相关物料信息 /// /// /// 更新行数 public int UpdateMaterial(InjectionRecorder model) { int count = 0; try { List paraList = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { string sql = "UPDATE T_AW_PRODUCTINJECTION SET MATERIALBATCH = @MATERIALBATCH WHERE PID=@PID"; paraList.Add(new DataParameter() { ParameterName = "PID", DataType = DbType.String, Value = model.PID }); paraList.Add(new DataParameter() { ParameterName = "MATERIALBATCH", DataType = DbType.String, Value = model.MATERIALBATCH }); //更新基本信息 count = session.ExecuteSql(sql.ToString(), paraList.ToArray()); } return count; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "表皮信息更新批次号错误!" }); throw ex; } } #endregion #region 获取导出的数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(Epidermis model) { DataTable dt = null; string sql = null; List parameters = new List(); try { //构成查询语句 sql = this.GetQuerySql(model, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { session.DbHelper.Timeout = 5000; dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = model.TableName; } return dt; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "表皮信息导出获取数据错误!" }); throw ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public List GetProductInfectionList(string id) { string sql = null; List parameters = new List(); List list = new List(); try { sql = this.GetProductInfectionQuerySql(id, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql, parameters.ToArray()).ToList(); } return list; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "表皮信息投料信息查询错误!" }); throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetProductInfectionQuerySql(string id, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append(@"SELECT PI.PID, PI.MPPID, PI.MATERIALNAME, PI.MATERIALCODE, PI.MATERIALTYPE, PI.MATERIALBATCH, PI.PROCESSTYPE, PI.INJECTIONINDEX, PI.INJECTIONTERMINAL, PI.USEDWEIGHT, P.MACHINENAME, P.MACHINECODDE, P.PRODUCESHIFTNAME, P.PRODUCESHIFTTCODE, P.PRODUCELINE, PI.CREATEUSER, PI.CREATEDATE, PI.UPDATEUSER, PI.UPDATEDATE FROM T_AW_PRODUCTINJECTION PI LEFT JOIN T_AW_PRODUCT P ON P.PID = PI.MPPID"); #region 查询条件 if (string.IsNullOrEmpty(id) == false) { whereBuilder.Append(" AND P.PID = @id"); whereBuilder.Append(" AND PI.MPPID = @id"); parameters.Add(new DataParameter { ParameterName = "id", DataType = DbType.String, Value = id }); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } #endregion return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion } }