using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMFrameWork.Data; using QMAPP.FJC.Entity.Basic; using System.Data; using QMFrameWork.Log; using QMAPP.FJC.Entity.ProduceManage; using QMAPP.DAL; using QMAPP.FJC.Entity; namespace QMAPP.FJC.DAL.ProduceManage { /// /// 模块编号: /// 作 用:返修记录 /// 作 者:王庆男 /// 编写日期:2015年06月24日 /// public class MendRecorderDAL : BaseDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public MendRecorder Get(MendRecorder 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 ex; } } /// /// 获取信息 /// /// 条件 /// *信息 public MendRecorder GetMendRecorderInfo(MendRecorder model) { string sql = null; List parameters = new List(); try { //获取信息 sql = this.GetQuerySql(model, ref parameters); 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 ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(MendRecorder condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); //sql = this.GetCallListSql(model, out 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) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "返修记录-获取列表!" }); throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(MendRecorder condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { ////构成查询语句 sqlBuilder.Append(" SELECT M.PID "); sqlBuilder.Append(" ,M.PPID "); sqlBuilder.Append(" ,M.PRODUCTCODE "); sqlBuilder.Append(" ,M.PRODUCTTYPE "); sqlBuilder.Append(" ,M.MATERIAL_CODE "); sqlBuilder.Append(" ,M.MATERIAL_TYPE_CODE "); sqlBuilder.Append(" ,M.CURRENTPROCESS "); sqlBuilder.Append(" ,M.PRODUCELINE "); sqlBuilder.Append(" ,M.PRODUCESHIFTNAME "); sqlBuilder.Append(" ,M.PRODUCESHIFTTCODE "); sqlBuilder.Append(" ,M.MENDREASON "); sqlBuilder.Append(" ,M.MENDTYPE "); sqlBuilder.Append(" ,M.MENDRESULT "); sqlBuilder.Append(" ,M.REGISTERSTATUS "); sqlBuilder.Append(" ,M.MOLDNUMBER "); sqlBuilder.Append(" ,M.BATCH_NO "); sqlBuilder.Append(" ,M.CREATEUSER "); sqlBuilder.Append(" ,M.CREATEDATE "); sqlBuilder.Append(" ,M.UPDATEUSER "); sqlBuilder.Append(" ,M.UPDATEDATE "); sqlBuilder.Append(" ,M.MENDDUTY "); sqlBuilder.Append(" ,M.MENDTEST "); sqlBuilder.Append(" ,M.MENDNUMBER "); sqlBuilder.Append(" ,M.WORKCELL_CODE "); sqlBuilder.Append(" ,M.MACHINECODDE "); sqlBuilder.Append(" ,M.HANDLEMETHOD "); sqlBuilder.Append(" ,(M.ERP_MFGCODETYPE+'/'+R8.MFGNAME) AS ERP_MFGCODETYPE "); sqlBuilder.Append(" ,(M.ERP_CAR+'/'+R.MFGNAME) as ERP_CAR "); sqlBuilder.Append(" ,(M.ERP_WORKLINE+'/'+R6.MFGNAME) AS ERP_WORKLINE "); sqlBuilder.Append(" ,(M.ERP_SHIFT+'/'+R2.MFGNAME) as ERP_SHIFT "); sqlBuilder.Append(" ,(M.ERP_WORKCELL+'/'+R3.MFGNAME) AS ERP_WORKCELL "); sqlBuilder.Append(" ,(M.ERP_DEFECTTO+'/'+R4.MFGNAME) AS ERP_DEFECTTO "); sqlBuilder.Append(" ,(M.ERP_PRODUCTTYPE+'/'+R5.MFGNAME) AS ERP_PRODUCTTYPE "); sqlBuilder.Append(" ,(M.ERP_DEFECTCODE+'/'+R7.MFGNAME) AS ERP_DEFECTCODE "); sqlBuilder.Append(" ,(M.ERP_MFGCODETYPE+M.ERP_CAR+M.ERP_WORKLINE+M.ERP_SHIFT+M.ERP_WORKCELL+M.ERP_DEFECTTO+M.ERP_PRODUCTTYPE+M.ERP_DEFECTCODE) as ERPS "); sqlBuilder.Append(" ,MB.MACHINENAME "); sqlBuilder.Append(" ,MA.MATERIAL_NAME "); sqlBuilder.Append(" ,MA.OUTSOURCE "); sqlBuilder.Append(" ,MC.MATERIAL_TYPE_NAME "); sqlBuilder.Append(" ,C.USERNAME AS CREATEUSERNAME "); sqlBuilder.Append(" ,U.USERNAME AS UPDATEUSERNAME "); sqlBuilder.Append(" FROM T_AW_MENDRECORDER M "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R ON R.MFGCODE = M.ERP_CAR AND R.MFGCODETYPE = 'CAR' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R2 ON R2.MFGCODE = M.ERP_SHIFT AND R2.MFGCODETYPE = 'SHIFT' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R3 ON R3.MFGCODE = M.ERP_WORKCELL AND R3.MFGCODETYPE = 'WORKCELL' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R4 ON R4.MFGCODE = M.ERP_DEFECTTO AND R4.MFGCODETYPE = 'DEFECTTO' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R5 ON R5.MFGCODE = M.ERP_PRODUCTTYPE AND R5.MFGCODETYPE = 'PRODUCTTYPE' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R6 ON R6.MFGCODE = M.ERP_WORKLINE AND R6.MFGCODETYPE = 'WORKLINE' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R7 ON R7.MFGCODE = M.ERP_DEFECTCODE AND R7.MFGCODETYPE = 'DEFECTCODE' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R8 ON R8.MFGCODE = M.ERP_MFGCODETYPE AND R8.MFGCODETYPE = 'MENDTYPE'"); sqlBuilder.Append(" LEFT JOIN T_BD_MACHINEINFO MB ON MB.MACHINECODDE=M.MACHINECODDE "); sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER "); //如果类型为空返回空 //if (string.IsNullOrEmpty(condition.MENDRESULT) ) //{ // //赋一个没有的值,使得查询记录为空。 // condition.MENDRESULT = "X"; //} //查询条件 if (string.IsNullOrEmpty(condition.PID) == false) { whereBuilder.Append(" AND M.PID =@PID"); parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = condition.PID }); } if (string.IsNullOrEmpty(condition.PPID) == false) { whereBuilder.Append(" AND M.PPID =@PPID"); parameters.Add(new DataParameter { ParameterName = "PPID", DataType = DbType.String, Value = condition.PPID }); } //产品条码查询条件 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.PRODUCTCODETXT) == false) { whereBuilder.Append(" AND M.PRODUCTCODE = @PRODUCTCODE"); parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODETXT }); } //返修方式 if (string.IsNullOrEmpty(condition.MENDTYPE) == false) { whereBuilder.Append(" AND M.MENDTYPE =@MENDTYPE"); parameters.Add(new DataParameter { ParameterName = "MENDTYPE", DataType = DbType.String, Value = condition.MENDTYPE }); } //返修结果 if (string.IsNullOrEmpty(condition.MENDRESULT) == false) { whereBuilder.Append(" AND M.MENDRESULT =@MENDRESULT"); parameters.Add(new DataParameter { ParameterName = "MENDRESULT", DataType = DbType.String, Value = condition.MENDRESULT }); } //产品类别 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.MOLDNUMBER) == false) { whereBuilder.Append(" AND M.MOLDNUMBER =@MOLDNUMBER"); parameters.Add(new DataParameter { ParameterName = "MOLDNUMBER", DataType = DbType.String, Value = condition.MOLDNUMBER }); } 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.MATERIAL_TYPE_CODE) == false) { whereBuilder.Append(" AND M.MATERIAL_TYPE_CODE =@MATERIAL_TYPE_CODE"); parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = condition.MATERIAL_TYPE_CODE }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { whereBuilder.Append(" AND M.PRODUCESHIFTTCODE =@PRODUCESHIFTTCODE"); parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } //操作开始日期 if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { whereBuilder.Append(" AND M.CREATEDATE >=@CREATEDATESTART"); parameters.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART.Replace("-", "") }); } //操作结束日期 if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { whereBuilder.Append(" AND M.CREATEDATE <=@CREATEDATEEND"); parameters.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND.Replace("-", "") }); } //返修原因 if (string.IsNullOrEmpty(condition.MENDREASON) == false) { whereBuilder.Append(" AND M.ERP_DEFECTCODE=@MENDREASON "); parameters.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.HORIZONTAL) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { string position = condition.VERTICAL + condition.HORIZONTAL; whereBuilder.AppendFormat(" AND exists(select 1 from T_AW_MENDERREASON r where r.ppid=m.pid and r.POSITION LIKE '%" + position + "%')"); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } private string GetQuerySqlScrap(MendRecorder condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append(" SELECT sum(M.MENDNUMBER) as MENDNUMBER , M.MATERIAL_CODE, MA.MATERIAL_NAME, (M.ERP_MFGCODETYPE+M.ERP_CAR+M.ERP_WORKLINE+M.ERP_SHIFT+M.ERP_WORKCELL+M.ERP_DEFECTTO+M.ERP_PRODUCTTYPE+M.ERP_DEFECTCODE) as ERPS "); sqlBuilder.Append(" FROM T_AW_MENDRECORDER M LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE "); //通过主键获取数据 if (string.IsNullOrEmpty(condition.PIDS) == false) { string[] list = condition.PIDS.Split(":".ToCharArray()); whereBuilder.Append(" AND M.PID IN ("); for (int i = 0; i < list.Length; i++) { whereBuilder.AppendFormat("'{0}'", list[i]); if (list.Length != 1 && i != (list.Length - 1)) { whereBuilder.Append(","); } } whereBuilder.Append(")"); } if (string.IsNullOrEmpty(condition.PID) == false) { whereBuilder.Append(" AND M.PID =@PID"); parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = condition.PID }); } if (string.IsNullOrEmpty(condition.PPID) == false) { whereBuilder.Append(" AND M.PPID =@PPID"); parameters.Add(new DataParameter { ParameterName = "PPID", DataType = DbType.String, Value = condition.PPID }); } //产品条码查询条件 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.PRODUCTCODETXT) == false) { whereBuilder.Append(" AND M.PRODUCTCODE = @PRODUCTCODE"); parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODETXT }); } //返修方式 if (string.IsNullOrEmpty(condition.MENDTYPE) == false) { whereBuilder.Append(" AND M.MENDTYPE =@MENDTYPE"); parameters.Add(new DataParameter { ParameterName = "MENDTYPE", DataType = DbType.String, Value = condition.MENDTYPE }); } //返修结果 if (string.IsNullOrEmpty(condition.MENDRESULT) == false) { whereBuilder.Append(" AND M.MENDRESULT =@MENDRESULT"); parameters.Add(new DataParameter { ParameterName = "MENDRESULT", DataType = DbType.String, Value = condition.MENDRESULT }); } //产品类别 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.MOLDNUMBER) == false) { whereBuilder.Append(" AND M.MOLDNUMBER =@MOLDNUMBER"); parameters.Add(new DataParameter { ParameterName = "MOLDNUMBER", DataType = DbType.String, Value = condition.MOLDNUMBER }); } 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.MATERIAL_TYPE_CODE) == false) { whereBuilder.Append(" AND M.MATERIAL_TYPE_CODE =@MATERIAL_TYPE_CODE"); parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = condition.MATERIAL_TYPE_CODE }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { whereBuilder.Append(" AND M.PRODUCESHIFTTCODE =@PRODUCESHIFTTCODE"); parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } //操作开始日期 if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { whereBuilder.Append(" AND M.CREATEDATE >=@CREATEDATESTART"); parameters.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART.Replace("-", "") }); } //操作结束日期 if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { whereBuilder.Append(" AND M.CREATEDATE <=@CREATEDATEEND"); parameters.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND.Replace("-", "") }); } //返修原因 if (string.IsNullOrEmpty(condition.MENDREASON) == false) { whereBuilder.Append(" AND M.ERP_DEFECTCODE=@MENDREASON "); parameters.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.HORIZONTAL) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { string position = condition.VERTICAL + condition.HORIZONTAL; whereBuilder.AppendFormat(" AND exists(select 1 from T_AW_MENDERREASON r where r.ppid=m.pid and r.POSITION LIKE '%" + position + "%')"); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } sqlBuilder.Append(" group by M.MATERIAL_CODE,MA.MATERIAL_NAME ,(M.ERP_MFGCODETYPE+M.ERP_CAR+M.ERP_WORKLINE+M.ERP_SHIFT+M.ERP_WORKCELL+M.ERP_DEFECTTO+M.ERP_PRODUCTTYPE+M.ERP_DEFECTCODE) "); string sql = string.Format(" SELECT MENDNUMBER ,newid() as PID, MATERIAL_CODE, MATERIAL_NAME, ERPS FROM(" + sqlBuilder.ToString() + ")TEMP"); return sql; } catch (Exception ex) { throw ex; } } #endregion #region 导出界面上数据 public DataTable ExportExcelData(MendRecorder model) { DataParameter[] parameters; string sql = this.GetCallListSql(model, out parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetTable(sql, parameters); } } private string GetCallListSql(MendRecorder model, out DataParameter[] parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parametersList = new List(); try { //构成查询语句 sqlBuilder.Append(" SELECT M.PID "); sqlBuilder.Append(" ,M.PPID "); sqlBuilder.Append(" ,M.PRODUCTCODE "); sqlBuilder.Append(" ,M.PRODUCTTYPE "); sqlBuilder.Append(" ,M.MATERIAL_CODE "); sqlBuilder.Append(" ,M.MATERIAL_TYPE_CODE "); sqlBuilder.Append(" ,M.CURRENTPROCESS "); sqlBuilder.Append(" ,M.PRODUCELINE "); sqlBuilder.Append(" ,M.PRODUCESHIFTNAME "); sqlBuilder.Append(" ,M.PRODUCESHIFTTCODE "); sqlBuilder.Append(" ,M.MENDREASON "); sqlBuilder.Append(" ,M.MENDTYPE "); sqlBuilder.Append(" ,M.MENDRESULT "); sqlBuilder.Append(" ,M.REGISTERSTATUS "); sqlBuilder.Append(" ,M.MOLDNUMBER "); sqlBuilder.Append(" ,M.BATCH_NO "); sqlBuilder.Append(" ,M.CREATEUSER "); sqlBuilder.Append(" ,CONVERT(VARCHAR(19),M.CREATEDATE,120) AS CREATEDATE "); sqlBuilder.Append(" ,M.UPDATEUSER "); sqlBuilder.Append(" ,M.UPDATEDATE "); sqlBuilder.Append(" ,M.MENDDUTY "); sqlBuilder.Append(" ,M.MENDTEST "); sqlBuilder.Append(" ,M.MENDNUMBER "); sqlBuilder.Append(" ,M.WORKCELL_CODE "); sqlBuilder.Append(" ,M.MACHINECODDE "); sqlBuilder.Append(" ,M.HANDLEMETHOD "); sqlBuilder.Append(" ,(M.ERP_MFGCODETYPE+'/'+R8.MFGNAME) AS ERP_MFGCODETYPE "); sqlBuilder.Append(" ,(M.ERP_CAR+'/'+R.MFGNAME) as ERP_CAR "); sqlBuilder.Append(" ,(M.ERP_WORKLINE+'/'+R6.MFGNAME) AS ERP_WORKLINE "); sqlBuilder.Append(" ,(M.ERP_SHIFT+'/'+R2.MFGNAME) as ERP_SHIFT "); sqlBuilder.Append(" ,(M.ERP_WORKCELL+'/'+R3.MFGNAME) AS ERP_WORKCELL "); sqlBuilder.Append(" ,(M.ERP_DEFECTTO+'/'+R4.MFGNAME) AS ERP_DEFECTTO "); sqlBuilder.Append(" ,(M.ERP_PRODUCTTYPE+'/'+R5.MFGNAME) AS ERP_PRODUCTTYPE "); sqlBuilder.Append(" ,(M.ERP_DEFECTCODE+'/'+R7.MFGNAME) AS ERP_DEFECTCODE "); sqlBuilder.Append(" ,(M.ERP_MFGCODETYPE+M.ERP_CAR+M.ERP_WORKLINE+M.ERP_SHIFT+M.ERP_WORKCELL+M.ERP_DEFECTTO+M.ERP_PRODUCTTYPE+M.ERP_DEFECTCODE) as ERPS "); sqlBuilder.Append(" ,MB.MACHINENAME "); sqlBuilder.Append(" ,MA.MATERIAL_NAME "); sqlBuilder.Append(" ,MA.OUTSOURCE "); sqlBuilder.Append(" ,MC.MATERIAL_TYPE_NAME "); sqlBuilder.Append(" ,C.USERNAME AS CREATEUSERNAME "); sqlBuilder.Append(" ,U.USERNAME AS UPDATEUSERNAME "); sqlBuilder.Append(" FROM T_AW_MENDRECORDER M "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R ON R.MFGCODE = M.ERP_CAR AND R.MFGCODETYPE = 'CAR' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R2 ON R2.MFGCODE = M.ERP_SHIFT AND R2.MFGCODETYPE = 'SHIFT' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R3 ON R3.MFGCODE = M.ERP_WORKCELL AND R3.MFGCODETYPE = 'WORKCELL' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R4 ON R4.MFGCODE = M.ERP_DEFECTTO AND R4.MFGCODETYPE = 'DEFECTTO' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R5 ON R5.MFGCODE = M.ERP_PRODUCTTYPE AND R5.MFGCODETYPE = 'PRODUCTTYPE' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R6 ON R6.MFGCODE = M.ERP_WORKLINE AND R6.MFGCODETYPE = 'WORKLINE' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R7 ON R7.MFGCODE = M.ERP_DEFECTCODE AND R7.MFGCODETYPE = 'DEFECTCODE' "); sqlBuilder.Append(" LEFT JOIN T_AW_MENDRECORDERERP R8 ON R8.MFGCODE = M.ERP_MFGCODETYPE AND R8.MFGCODETYPE = 'MENDTYPE'"); sqlBuilder.Append(" LEFT JOIN T_BD_MACHINEINFO MB ON MB.MACHINECODDE=M.MACHINECODDE "); sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE "); sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER "); sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER "); //查询条件 if (string.IsNullOrEmpty(model.PID) == false) { whereBuilder.Append(" AND M.PID =@PID"); parametersList.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID }); } if (string.IsNullOrEmpty(model.PPID) == false) { whereBuilder.Append(" AND M.PPID =@PPID"); parametersList.Add(new DataParameter { ParameterName = "PPID", DataType = DbType.String, Value = model.PPID }); } //产品条码查询条件 if (string.IsNullOrEmpty(model.PRODUCTCODE) == false) { whereBuilder.Append(" AND M.PRODUCTCODE LIKE @PRODUCTCODE"); parametersList.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = "%" + model.PRODUCTCODE + "%" }); } //产品条码查询返修信息 if (string.IsNullOrEmpty(model.PRODUCTCODETXT) == false) { whereBuilder.Append(" AND M.PRODUCTCODE = @PRODUCTCODE"); parametersList.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = model.PRODUCTCODETXT }); } //返修方式 if (string.IsNullOrEmpty(model.MENDTYPE) == false) { whereBuilder.Append(" AND M.MENDTYPE =@MENDTYPE"); parametersList.Add(new DataParameter { ParameterName = "MENDTYPE", DataType = DbType.String, Value = model.MENDTYPE }); } //返修结果 if (string.IsNullOrEmpty(model.MENDRESULT) == false) { whereBuilder.Append(" AND M.MENDRESULT =@MENDRESULT"); parametersList.Add(new DataParameter { ParameterName = "MENDRESULT", DataType = DbType.String, Value = model.MENDRESULT }); } //产品类别 if (string.IsNullOrEmpty(model.PRODUCTTYPE) == false) { whereBuilder.Append(" AND M.PRODUCTTYPE =@PRODUCTTYPE"); parametersList.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = model.PRODUCTTYPE }); } if (string.IsNullOrEmpty(model.MOLDNUMBER) == false) { whereBuilder.Append(" AND M.MOLDNUMBER =@MOLDNUMBER"); parametersList.Add(new DataParameter { ParameterName = "MOLDNUMBER", DataType = DbType.String, Value = model.MOLDNUMBER }); } if (string.IsNullOrEmpty(model.MATERIAL_CODE) == false) { whereBuilder.Append(" AND M.MATERIAL_CODE =@MATERIAL_CODE"); parametersList.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = model.MATERIAL_CODE }); } if (string.IsNullOrEmpty(model.MATERIAL_TYPE_CODE) == false) { whereBuilder.Append(" AND M.MATERIAL_TYPE_CODE =@MATERIAL_TYPE_CODE"); parametersList.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = model.MATERIAL_TYPE_CODE }); } if (string.IsNullOrEmpty(model.PRODUCESHIFTTCODE) == false) { whereBuilder.Append(" AND M.PRODUCESHIFTTCODE =@PRODUCESHIFTTCODE"); parametersList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = model.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(model.CREATEDATESTART) == false) { whereBuilder.Append(" AND M.CREATEDATE >=@CREATEDATESTART"); parametersList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = model.CREATEDATESTART.Replace("-", "") }); } if (string.IsNullOrEmpty(model.CREATEDATEEND) == false) { whereBuilder.Append(" AND M.CREATEDATE <=@CREATEDATEEND"); parametersList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = model.CREATEDATEEND.Replace("-", "") }); } //返修原因 if (string.IsNullOrEmpty(model.MENDREASON) == false) { whereBuilder.Append(" AND M.ERP_DEFECTCODE=@MENDREASON "); parametersList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = model.MENDREASON }); } if (string.IsNullOrEmpty(model.HORIZONTAL) == false || string.IsNullOrEmpty(model.VERTICAL) == false) { string position = model.VERTICAL + model.HORIZONTAL; whereBuilder.AppendFormat(" AND exists(select 1 from T_AW_MENDERREASON r where r.ppid=m.pid and r.POSITION LIKE '%" + position + "%')"); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } parameters = parametersList.ToArray(); return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion #region 获取导出的数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(MendRecorder model) { DataTable dt = null; string sql = null; List parameters = new List(); try { //构成查询语句 sql = this.GetQuerySql(model, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = "T_AW_MENDRECORDER"; } return dt; } catch (Exception ex) { throw ex; } } public DataTable GetExportDataScrap(MendRecorder model) { DataTable dt = null; string sql = null; List parameters = new List(); try { //构成查询语句 sql = this.GetQuerySqlScrap(model, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = "T_AW_MENDRECORDER"; } return dt; } catch (Exception ex) { throw ex; } } #endregion #region 信息是否重复 /// /// 判断名称是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsMendRecorder(MendRecorder model) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { sqlBuilder.Append("SELECT COUNT(PID) FROM T_AW_MENDRECORDER"); if (string.IsNullOrEmpty(model.PID) == false) { whereBuilder.Append(" AND PID =@PID "); parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID }); } //if (string.IsNullOrEmpty(model.) == false) //{ //whereBuilder.Append(" AND AREACODE=@AREACODE"); //parameters.Add(new DataParameter { ParameterName = "AREACODE", DataType = DbType.String, Value = ""model.AREACODE + "" }); //} 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())); } if (count > 0) { return true; } else { return false; } } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public int Insert(MendRecorder model) { int count = 0; try { if (this.BaseSession != null) { //插入基本信息 count = BaseSession.Insert(model); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(model); } } return count; } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public int Update(MendRecorder model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //更新基本信息 count = session.Update(model); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 逻辑删除 /// /// 逻辑删除信息 /// /// /// 删除个数 public int Delete(MendRecorder model) { StringBuilder sqlBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //删除基本信息 sqlBuilder.Append("DELETE T_AW_MENDRECORDER "); sqlBuilder.Append("WHERE PID = @PID "); parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID }); count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray()); } return count; } catch (Exception ex) { throw ex; } } #endregion public DataTable GetListForstatistic(MendRecorder condition) { DataTable dt = new DataTable(); string sql = string.Format(@"select count(1) as MENDSUM ,MOLDNUMBER,PRODUCESHIFTTCODE from T_AW_MENDRECORDER where CREATEDATE>='{0}' and CREATEDATE<'{1}' group by MOLDNUMBER,PRODUCESHIFTTCODE ORDER BY PRODUCESHIFTTCODE,MOLDNUMBER ASC ", condition.CREATEDATESTART, condition.CREATEDATEEND); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, new List().ToArray()); } return dt; } #region 获取返修统计信息填充图表 /// /// 获取返修统计信息 /// /// /// public List GetMendRecorderStatistics(MendRecorder condition) { List paralist = new List(); List recorderList = new List(); string sql = GetStatisticsSql(condition, ref paralist); using (IDataSession session = AppDataFactory.CreateMainSession()) { recorderList = session.GetList(sql, paralist.ToArray()).ToList(); } return recorderList; } #endregion #region 统计信息查询语句 private string GetStatisticsSql(MendRecorder condition, ref List paraList) { StringBuilder sql = new StringBuilder(); #region 返修件缺陷类型 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.DEFECTTYPE.GetHashCode().ToString()) { StringBuilder existsSql = new StringBuilder(); sql.Append("select DEFECTVALUE,sum(1) as QUATITY from (SELECT distinct s.ppid,s.DEFECTVALUE FROM T_AW_MENDERREASON s where 1=1 "); existsSql.Append(" and exists(select 1 from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); existsSql.Append(" and t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); existsSql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { existsSql.Append(" AND t.PRODUCESHIFTTCODE <= @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } existsSql.Append(" and t.pid=s.ppid and t.MENDRESULT=0 ) "); sql.Append(existsSql.ToString()); sql.Append(")t group by DEFECTVALUE"); } #endregion #region 返修件缺陷位置 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.DEFECTPOSITION.GetHashCode().ToString()) { StringBuilder existsSql = new StringBuilder(); sql.Append("select POSITION,sum(1) as QUATITY from (SELECT distinct s.ppid,s.POSITION FROM T_AW_MENDERREASON s where 1=1 "); existsSql.Append(" and exists(select 1 from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); existsSql.Append(" and t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); existsSql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { existsSql.Append(" AND t.PRODUCESHIFTTCODE <= @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } existsSql.Append(" and t.pid=s.ppid and t.MENDRESULT=0 ) "); sql.Append(existsSql.ToString()); sql.Append(")t group by POSITION ORDER BY POSITION ASC"); } #endregion #region 返修件班次信息 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.DEFECTTEAM.GetHashCode().ToString()) { sql.Append("select t.PRODUCESHIFTTCODE,sum(1) as QUATITY from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists (select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.pid=s.ppid )"); } sql.Append(" and t.MENDRESULT=0 group by PRODUCESHIFTTCODE ORDER BY PRODUCESHIFTTCODE ASC"); } #endregion #region 返修率趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.MENDRATE.GetHashCode().ToString()) { sql.Append(@"select DEFECTVALUE ,sum(case when pid='' then 0 else 1 end) as countValue, sum(1) as sumValue from(select convert(varchar(10),m.CREATEDATE,120) as DEFECTVALUE ,ISNULL(s.pid,'') as pid from t_aw_main m left join T_AW_MENDRECORDER s on s.PPID=m.PID "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and s.CREATEDATE>@CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = Convert.ToDateTime(condition.CREATEDATEEND).AddDays(5).ToString("yyyy-MM-dd HH:mm:ss") }); } if(string.IsNullOrEmpty(condition.MENDREASON)==false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists(select 1 from T_AW_MENDERREASON t where 1=1 "); sql.Append(" and t.CREATEDATE>@CREATEDATESTART"); sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND t.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND t.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.ppid=s.PID "); sql.Append(")"); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND s.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } sql.Append(" and MENDRESULT=0 where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and m.CREATEDATE>@CREATEDATESTART"); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND m.CREATEDATE <= @MCREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "MCREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } sql.Append(" )temp group by DEFECTVALUE order by DEFECTVALUE asc"); } #endregion #region 返修数量趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.MENDSUM.GetHashCode().ToString()) { sql.Append(" select DEFECTVALUE, sum(quatity) as quatity from( select convert(varchar(10),CREATEDATE,120) as DEFECTVALUE,1 as quatity from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists (select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.pid=s.ppid )"); } sql.Append(" and MENDRESULT='0')temp group by DEFECTVALUE order by DEFECTVALUE asc"); } #endregion #region 生产返修对比趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.PRODUCEMENDRATE.GetHashCode().ToString()) { sql.Append(@"select sumValue,countValue, maintemp.DEFECTVALUE from ( select sum(1) as sumValue ,convert(varchar(10),m.CREATEDATE,120) as DEFECTVALUE from t_aw_main m where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and m.CREATEDATE>@CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND m.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } sql.Append(" group by convert(varchar(10),m.CREATEDATE,120))maintemp,"); sql.Append(" ("); sql.Append(" select sum(1) as countValue ,convert(varchar(10),t.CREATEDATE,120) as DEFECTVALUE from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and t.CREATEDATE>@CREATEDATESTART"); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } sql.Append(" and t.MENDRESULT='0' "); if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists(select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" and s.CREATEDATE>@CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and s.ppid=t.PID "); sql.Append(")"); } sql.Append(" group by convert(varchar(10),t.CREATEDATE,120))mendtemp where maintemp.DEFECTVALUE=mendtemp.DEFECTVALUE"); } #endregion #region 废品趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.SCARPRATE.GetHashCode().ToString()) { sql.Append(" select DEFECTVALUE, sum(quatity) as quatity from( select convert(varchar(10),CREATEDATE,120) as DEFECTVALUE,1 as quatity from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists (select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.pid=s.ppid )"); } sql.Append(" and MENDRESULT='1')temp group by DEFECTVALUE order by DEFECTVALUE asc"); } #endregion #region 废品件缺陷类型 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.SCARPDEFECT.GetHashCode().ToString()) { StringBuilder existsSql = new StringBuilder(); sql.Append("select DEFECTVALUE,sum(1) as QUATITY from (SELECT distinct s.ppid,s.DEFECTVALUE FROM T_AW_MENDERREASON s where 1=1 "); existsSql.Append(" and exists(select 1 from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); existsSql.Append(" and t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); existsSql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { existsSql.Append(" AND t.PRODUCESHIFTTCODE <= @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } existsSql.Append(" and t.pid=s.ppid and t.MENDRESULT='1' ) "); sql.Append(existsSql.ToString()); sql.Append(")t group by DEFECTVALUE"); } #endregion return sql.ToString(); } private string GetStatisticsExportSql(MendRecorder condition, ref List paraList) { StringBuilder sql = new StringBuilder(); #region 返修件缺陷类型 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.DEFECTTYPE.GetHashCode().ToString()) { StringBuilder existsSql = new StringBuilder(); sql.Append("select DEFECTVALUE,sum(1) as QUATITY from (SELECT distinct s.ppid,s.DEFECTVALUE FROM T_AW_MENDERREASON s where 1=1 "); existsSql.Append(" and exists(select 1 from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); existsSql.Append(" and t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); existsSql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { existsSql.Append(" AND t.PRODUCESHIFTTCODE <= @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } existsSql.Append(" and t.pid=s.ppid and t.MENDRESULT=0 ) "); sql.Append(existsSql.ToString()); sql.Append(")t group by DEFECTVALUE"); } #endregion #region 返修件缺陷位置 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.DEFECTPOSITION.GetHashCode().ToString()) { StringBuilder existsSql = new StringBuilder(); sql.Append("select POSITION,sum(1) as QUATITY from (SELECT distinct s.ppid,s.POSITION FROM T_AW_MENDERREASON s where 1=1 "); existsSql.Append(" and exists(select 1 from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); existsSql.Append(" and t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); existsSql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { existsSql.Append(" AND t.PRODUCESHIFTTCODE <= @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } existsSql.Append(" and t.pid=s.ppid and t.MENDRESULT=0 ) "); sql.Append(existsSql.ToString()); sql.Append(")t group by POSITION ORDER BY POSITION ASC"); } #endregion #region 返修件班次信息 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.DEFECTTEAM.GetHashCode().ToString()) { sql.Append("select t.PRODUCESHIFTTCODE,sum(1) as QUATITY from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists (select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.pid=s.ppid )"); } sql.Append(" and MENDRESULT=0 group by PRODUCESHIFTTCODE ORDER BY PRODUCESHIFTTCODE ASC"); } #endregion #region 返修率趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.MENDRATE.GetHashCode().ToString()) { sql.Append(@"select DEFECTVALUE ,sum(case when pid='' then 0 else 1 end) as countValue, sum(1) as sumValue ,'' as PERCENTVALUE from(select convert(varchar(10),m.CREATEDATE,120) as DEFECTVALUE ,ISNULL(s.pid,'') as pid from t_aw_main m left join T_AW_MENDRECORDER s on s.PPID=m.PID "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and s.CREATEDATE>@CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = Convert.ToDateTime(condition.CREATEDATEEND).AddDays(5).ToString("yyyy-MM-dd HH:mm:ss") }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists(select 1 from T_AW_MENDERREASON t where 1=1 "); sql.Append(" and t.CREATEDATE>@CREATEDATESTART"); sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND t.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND t.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.ppid=s.PID "); sql.Append(")"); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND s.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } sql.Append(" and MENDRESULT=0 where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and m.CREATEDATE>@CREATEDATESTART"); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND m.CREATEDATE <= @MCREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "MCREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } sql.Append(" )temp group by DEFECTVALUE order by DEFECTVALUE asc"); } #endregion #region 返修数量趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.MENDSUM.GetHashCode().ToString()) { sql.Append(" select DEFECTVALUE, sum(quatity) as quatity from( select convert(varchar(10),CREATEDATE,120) as DEFECTVALUE,1 as quatity from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists (select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.pid=s.ppid )"); } sql.Append(" and MENDRESULT='0')temp group by DEFECTVALUE order by DEFECTVALUE asc"); } #endregion #region 生产返修对比趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.PRODUCEMENDRATE.GetHashCode().ToString()) { sql.Append(@"select sumValue,countValue, maintemp.DEFECTVALUE,'' as PERCENTVALUE from ( select sum(1) as sumValue ,convert(varchar(10),m.CREATEDATE,120) as DEFECTVALUE from t_aw_main m where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and m.CREATEDATE>@CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND m.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } sql.Append(" group by convert(varchar(10),m.CREATEDATE,120))maintemp,"); sql.Append(" ("); sql.Append(" select sum(1) as countValue ,convert(varchar(10),t.CREATEDATE,120) as DEFECTVALUE from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" and t.CREATEDATE>@CREATEDATESTART"); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } sql.Append(" and t.MENDRESULT='0' "); if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists(select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" and s.CREATEDATE>@CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and s.ppid=t.PID "); sql.Append(")"); } sql.Append(" group by convert(varchar(10),t.CREATEDATE,120))mendtemp where maintemp.DEFECTVALUE=mendtemp.DEFECTVALUE"); } #endregion #region 废品趋势图 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.SCARPRATE.GetHashCode().ToString()) { sql.Append(" select DEFECTVALUE, sum(quatity) as quatity from( select convert(varchar(10),CREATEDATE,120) as DEFECTVALUE,1 as quatity from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { sql.Append(" AND t.PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false || string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND exists (select 1 from T_AW_MENDERREASON s where 1=1 "); sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } sql.Append(" and t.pid=s.ppid )"); } sql.Append(" and MENDRESULT='1')temp group by DEFECTVALUE order by DEFECTVALUE asc"); } #endregion #region 废品件缺陷类型 if (condition.MENDTYPE == EnumGeter.MENDSTATICTYPE.SCARPDEFECT.GetHashCode().ToString()) { StringBuilder existsSql = new StringBuilder(); sql.Append("select DEFECTVALUE,sum(1) as QUATITY from (SELECT distinct s.ppid,s.DEFECTVALUE FROM T_AW_MENDERREASON s where 1=1 "); existsSql.Append(" and exists(select 1 from T_AW_MENDRECORDER t where 1=1 "); if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false) { sql.Append(" AND s.CREATEDATE >= @CREATEDATESTART"); existsSql.Append(" and t.CREATEDATE >= @CREATEDATESTART"); paraList.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART }); } if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false) { sql.Append(" AND s.CREATEDATE <= @CREATEDATEEND"); existsSql.Append(" AND t.CREATEDATE <= @CREATEDATEEND"); paraList.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND }); } if (string.IsNullOrEmpty(condition.MENDREASON) == false) { sql.Append(" AND s.DEFECTKEY = @MENDREASON"); paraList.Add(new DataParameter { ParameterName = "MENDREASON", DataType = DbType.String, Value = condition.MENDREASON }); } if (string.IsNullOrEmpty(condition.VERTICAL) == false) { sql.Append(" AND s.POSITION = @POSITION"); paraList.Add(new DataParameter { ParameterName = "POSITION", DataType = DbType.String, Value = condition.VERTICAL + condition.HORIZONTAL }); } if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false) { existsSql.Append(" AND t.PRODUCESHIFTTCODE <= @PRODUCESHIFTTCODE"); paraList.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE }); } existsSql.Append(" and t.pid=s.ppid and t.MENDRESULT='1' ) "); sql.Append(existsSql.ToString()); sql.Append(")t group by DEFECTVALUE"); } #endregion return sql.ToString(); } #endregion #region 获取返修统计信息导出 public DataTable ExportMendRecorderStatistics(MendRecorder condition) { List paralist = new List(); DataTable dt = new DataTable(); string sql = GetStatisticsExportSql(condition, ref paralist); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, paralist.ToArray()); } return dt; } #endregion #region 获取返修信息-ERP /// /// 获取某个返修类型的数据-ERP /// /// public List GetMFGCODES(string MFGCODETYPE) { List paralist = new List(); string sql = "SELECT MFGCODE as ERP_CODE,MFGNAME as ERP_NAME,MFGCODETYPE AS ERP_MFGCODETYPE FROM T_AW_MENDRECORDERERP order by MFGCODE"; if (!string.IsNullOrEmpty(MFGCODETYPE)) { sql = "SELECT MFGCODE as ERP_CODE,MFGNAME as ERP_NAME ,MFGCODETYPE AS ERP_MFGCODETYPE FROM T_AW_MENDRECORDERERP where MFGCODETYPE='" + MFGCODETYPE + "' order by MFGCODE"; } using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, paralist.ToArray()).ToList(); } } #endregion public Entity.Operation.MainOperation GetMianOperationInfo(Entity.Operation.MainOperation mainOperation) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); try { sqlBuilder.Append(" SELECT M.PID, "); sqlBuilder.Append(" M.PDID, "); sqlBuilder.Append(" M.PRODUCTCODE, "); sqlBuilder.Append(" M.PROCESSTYPE, "); sqlBuilder.Append(" M.PRODUCTTYPE, "); sqlBuilder.Append(" M.MACHINENAME, "); sqlBuilder.Append(" M.MACHINECODDE, "); sqlBuilder.Append(" M.MOLDNUMBER, "); sqlBuilder.Append(" M.STATUS, "); sqlBuilder.Append(" M.OPERATESTATE, "); sqlBuilder.Append(" M.OPERATEDDATE, "); sqlBuilder.Append(" M.CURRENTPROCESS, "); sqlBuilder.Append(" M.PRODUCESHIFTNAME, "); sqlBuilder.Append(" M.PRODUCESHIFTTCODE, "); sqlBuilder.Append(" M.PRODUCELINE, "); sqlBuilder.Append(" M.FILENAME, "); sqlBuilder.Append(" M.FILEPATH, "); sqlBuilder.Append(" M.MODELSTATION, "); sqlBuilder.Append(" M.CREATEUSER, "); sqlBuilder.Append(" M.CREATEDATE, "); sqlBuilder.Append(" M.UPDATEUSER, "); sqlBuilder.Append(" M.UPDATEDATE, "); sqlBuilder.Append(" M.PRODUCTCODESTR, "); sqlBuilder.Append(" M.MATERIAL_CODE, "); sqlBuilder.Append(" M.MATERIAL_NAME, "); sqlBuilder.Append(" M.MATERIAL_TYPE_CODE, "); sqlBuilder.Append(" M.WORKCENTER_CODE, "); sqlBuilder.Append(" M.WORKCELL_CODE, "); sqlBuilder.Append(" E.MFGCODE AS ERP_WORKLINE "); sqlBuilder.Append("FROM T_AW_MAINOPERATION M "); sqlBuilder.Append("LEFT JOIN T_AW_MENDRECORDERERP E ON E.TYPE_CODE=M.WORKCENTER_CODE AND MFGCODETYPE='WORKLINE' "); if (string.IsNullOrEmpty(mainOperation.PDID) == false) { whereBuilder.Append(" AND PDID =@PDID "); parameters.Add(new DataParameter { ParameterName = "PDID", DataType = DbType.String, Value = mainOperation.PDID }); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } using (IDataSession session = AppDataFactory.CreateMainSession()) { mainOperation = session.Get(sqlBuilder.ToString(), parameters.ToArray()); } return mainOperation; } catch (Exception ex) { throw ex; } } } }