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; using QMAPP.MESReport.Entity.Tables; namespace QMAPP.MESReport.DAL.LineQTY { /// /// 合格率分析 数据访问层 /// 于子清 /// 2017-10-13 /// public class StandardRateCountDAL : BaseDAL { /// /// 获取合格率图表数据 /// /// /// public List GetAllList(StandardRateDModel condition) { List list = 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(); } return list; } catch (Exception ex) { throw ex; } } public List GetAllListNot(StandardRateDModel condition) { List list = new List(); string sql = null; List parameters = new List(); try { sql = "select t1.NOK_QTY,t2.QTY, t2.QTY- t1.NOK_QTY as OK_QTY,t1.WORKCELL_CODE from "; sql += "(select sum(MENDNUMBER) as NOK_QTY,WORKCELL_CODE FROM T_AW_MENDRECORDER where MENDTEST = '否' "; if (string.IsNullOrEmpty(condition.START_DATE) == false && string.IsNullOrEmpty(condition.END_DATE) == false) { sql += "and BATCH_NO>='" + condition.START_DATE.Replace("-", "") + "' and BATCH_NO<='" + condition.END_DATE.Replace("-", "") + "' "; } if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false) { sql += "and WORKCELL_CODE='" + condition.WORKCELL_CODE + "' "; } sql += "group by WORKCELL_CODE) t1, "; sql += "(select sum(qty) as QTY,WORKCELL_CODE FROM T_SA_WORKCELLQTYCOUNT where EQUIPMENT_CODE <> '' "; if (string.IsNullOrEmpty(condition.START_DATE) == false && string.IsNullOrEmpty(condition.END_DATE) == false) { var startDate = condition.START_DATE + " 00:00:00"; var endDate = condition.END_DATE + " 23:59:59"; sql += "and STATIS_DATE>='" + startDate + "' and STATIS_DATE<='" + endDate + "' "; } sql += "group by WORKCELL_CODE) t2 "; sql += "where t1.WORKCELL_CODE=t2.WORKCELL_CODE "; using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql, parameters.ToArray()).ToList(); } return list; } catch (Exception ex) { throw ex; } } #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(StandardRateDModel condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.AppendLine("select sum(OK_QTY) OK_QTY,sum(NOK_QTY) NOK_QTY,tmd.WORKCELL_NAME from T_SA_WORKCELLQTYCOUNT tsa inner join T_MD_WORKCELL tmd on tmd.WORKCELL_CODE=tsa.WORKCELL_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 (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } sqlBuilder.Append(" group by tsa.WORKCELL_CODE,tmd.WORKCELL_NAME "); return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion } }