using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMFrameWork.Data; using QMAPP.MESReport.Entity.LineQTY; using QMAPP.DAL; using System.Data; namespace QMAPP.MESReport.DAL.LineQTY { /// /// 生产每日工序设备情况统计-数据层对象 /// 创建人:李炳海 /// 创建时间:2017.09.22 /// public class LineDWQTYCountDAL:BaseDAL { /// /// 获取各工序设备日生产情况 /// public DataPage GetDayEquQTYByWorkCell(LineQtyCondition condition, DataPage page) { return page; } #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(LineDayQTYCount condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); //分页关键字段及排序 page.KeyName = "EQUIPMENT_CODE"; if (string.IsNullOrEmpty(page.SortExpression)) { page.SortExpression = "STATIS_DATE DESC , CREATEDATE"; } using (IDataSession session = AppDataFactory.CreateMainSession()) { page = session.GetDataPage(sql, parameters.ToArray(), page); } return page; } catch (Exception ex) { throw ex; } } /// /// 获取列表 /// /// 条件 /// 全部集合 public List GetAllList(LineDayQTYCount condition) { List list = new List(); List listNew = new List(); string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql, parameters.ToArray()).ToList(); listNew.AddRange(list); } return list; } catch (Exception ex) { throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(LineDayQTYCount condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.AppendLine("select convert(nvarchar(20),(OK_QTY*100/QTY))+'%' as OK_QTY_LV"); sqlBuilder.AppendLine(@",tsa.[PID] ,tsa.[WORKCENTER_CODE] ,tsa.[FACTORY_CODE] ,tsa.[EQUIPMENT_CODE] ,tsa.[WORKCELL_CODE] ,tsa.[MATRIAL_CODE] AS [MATERIAL_CODE] ,ma.MATERIAL_NAME ,tsa.[SHIFT_CODE] ,CONVERT(VARCHAR(10),tsa.[STATIS_DATE],120) as STATIS_DATE ,tsa.[QTY] ,tsa.[OK_QTY] ,tsa.[NOK_QTY] ,tsa.[REWORK_QTY] ,tsa.[CREATEDATE] ,tsa.[UPDATEDATE]"); sqlBuilder.AppendLine(",eq.MACHINENAME AS EQUIPMENT_NAME"); sqlBuilder.AppendLine(",tmw.WORKCELL_NAME "); sqlBuilder.AppendLine("from T_SA_WORKCELLQTYCOUNT tsa "); sqlBuilder.AppendLine("inner join T_BD_MACHINEINFO eq "); sqlBuilder.AppendLine("on eq.MACHINECODDE =tsa.EQUIPMENT_CODE "); sqlBuilder.AppendLine("inner join T_MD_WORKCELL tmw "); sqlBuilder.AppendLine("on tmw.WORKCELL_CODE =tsa.WORKCELL_CODE "); sqlBuilder.AppendLine("inner join T_MD_PROCESS_ROUTE_WORKCELL_SEQ tmprw "); sqlBuilder.AppendLine("on tmprw.WORKCELL_CODE =tsa.WORKCELL_CODE "); sqlBuilder.AppendLine("inner join T_MD_MATERIAL ma "); sqlBuilder.AppendLine("on ma.MATERIAL_CODE =tsa.MATRIAL_CODE "); if (string.IsNullOrEmpty(condition.START_DATE) == false) { whereBuilder.Append(" AND STATIS_DATE >= @START_DATE "); parameters.Add(new DataParameter { ParameterName = "START_DATE", DataType = DbType.DateTime, Value = condition.START_DATE }); } if (string.IsNullOrEmpty(condition.END_DATE) == false) { whereBuilder.Append(" AND STATIS_DATE <= @END_DATE "); parameters.Add(new DataParameter { ParameterName = "END_DATE", DataType = DbType.DateTime, Value = condition.END_DATE }); } if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false) { whereBuilder.Append(" AND tsa.WORKCELL_CODE = @WORKCELL_CODE "); parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = condition.WORKCELL_CODE }); } if (string.IsNullOrEmpty(condition.EQUIPMENT_NAME) == false) { whereBuilder.Append(" AND tsa.EQUIPMENT_CODE = @EQUIPMENT_CODE "); parameters.Add(new DataParameter { ParameterName = "EQUIPMENT_CODE", DataType = DbType.String, Value = condition.EQUIPMENT_NAME }); } if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false) { whereBuilder.Append(" AND tsa.WORKCENTER_CODE = @WORKCENTER_CODE "); parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE }); } if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false) { whereBuilder.Append(" AND ROUTE_CODE = @ROUTE_CODE "); parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE }); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } //sqlBuilder.Append(" order by STATIS_DATE desc, CREATEDATE "); return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion public DataTable GetExportData(LineDayQTYCount condition) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); DataTable dt = null; string sql = null; List parameters = new List(); try { //构成查询语句 sqlBuilder.Append("select tsa.*,ma.MATERIAL_NAME from T_SA_WORKCELLQTYCOUNT as tsa inner join T_MD_MATERIAL ma on ma.MATERIAL_CODE = tsa.MATRIAL_CODE "); if (whereBuilder.Length > 0) { sqlBuilder.Append(whereBuilder.ToString()); } sqlBuilder.Append(" ORDER BY tsa.STATIS_DATE DESC "); using (IDataSession session = AppDataFactory.CreateMainSession()) { sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session); dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = "T_SA_WORKCELLQTYCOUNT"; } return dt; } catch (Exception ex) { throw; } } } }