using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using QMAPP.DAL; using QMAPP.FJC.Entity.Common.Constants; using QMAPP.FJC.Entity.CompleteStatistics; using QMFrameWork.Data; namespace QMAPP.FJC.DAL.CompleteStatistics { public class CompleteStatisticsDAL : BaseDAL { public DataPage GetList(CompleteStatisticsEntity condition, DataPage page) { DataParameter[] parameters; string sql = this.GetNewQuerySql(condition, out parameters); //分页关键字段及排序 page.KeyName = "PID"; page.SortExpression = "ENDTIME ASC"; using (IDataSession session = AppDataFactory.CreateMainSession()) { page = session.GetDataPage(sql, parameters, page); } return page; } public DataPage GetNewList(CompleteStatisticsEntity condition, DataPage page) { DataParameter[] parameters; string sql = this.GetNewQuerySql(condition, out parameters); //分页关键字段及排序 page.KeyName = "PID"; page.SortExpression = "ENDTIME desc"; using (IDataSession session = AppDataFactory.CreateMainSession()) { page = session.GetDataPage(sql, parameters, page); } return page; } public List GetList(CompleteStatisticsEntity condition) { DataParameter[] parameters; string sql = this.GetNewQuerySql(condition, out parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, parameters).ToList(); } } public CompleteStatisticsEntity Get(CompleteStatisticsEntity model) { using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.Get(model); } } public int Insert(CompleteStatisticsEntity model) { using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.Insert(model); } } public int Select_Get(string ProductCode) { var sql = $"select * from T_AW_COMPLETE_STATISTICS where ORDERNO = '{ProductCode}' and DELFLAG = '0'"; using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, new DataParameter[] { }).ToList().Count; } } public bool ExistCompleteStatistics(CompleteStatisticsEntity model) { throw new NotImplementedException(); } protected string ExistQureySql() { StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT *"); sql.AppendLine(" FROM T_AW_MAINOPERATION T"); sql.AppendLine(" WHERE INFO.BARCODEIDENTIFY IS NOT NULL"); sql.AppendLine(" AND T.OPERATEDDATE > @StartTime"); sql.AppendLine(" AND T.OPERATEDDATE <= @EndTime"); return sql.ToString(); } public int Update(CompleteStatisticsEntity model) { using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.Update(model); } } public int GenericCompleteStatistics(DateTime starTime, DateTime endTime) { int count = 0; using (IDataSession session = AppDataFactory.CreateMainSession()) { DataParameter[] parameters = { new DataParameter {ParameterName = "StartTime", DataType = DbType.DateTime, Value = starTime}, new DataParameter {ParameterName = "EndTime", DataType = DbType.DateTime, Value = endTime} }; try { session.OpenTs(); //string location = this.GetSystemConfig(CompleteStatisticsConstants.COMP_STATIS_SITE).CODEVALUE; //string sql = location.Equals("080121") ? this.GetGenericStatisticsSqlForCC() : this.GetGenericStatisticsSqlForCD(); //成品 string sql = GetGenericStatisticsSqlForBORA(); count = session.ExecuteSql(sql, parameters); ////更新备份表 var sql2 = GetGenericStatisticsSqlForINJECT(); session.ExecuteSql(sql2, parameters); this.UpdateLastGenericTime(endTime, session); session.CommitTs(); } catch (Exception) { session.RollbackTs(); throw; } } return count; } public int FrmPlaceCompleteStatistics(DateTime starTime, DateTime endTime) { int count = 0; using (IDataSession session = AppDataFactory.CreateMainSession()) { //DataParameter[] parameters = { // new DataParameter {ParameterName = "StartTime", DataType = DbType.DateTime, Value = starTime}, // new DataParameter {ParameterName = "EndTime", DataType = DbType.DateTime, Value = endTime} //}; try { session.OpenTs(); //string location = this.GetSystemConfig(CompleteStatisticsConstants.COMP_STATIS_SITE).CODEVALUE; //string sql = location.Equals("080121") ? this.GetGenericStatisticsSqlForCC() : this.GetGenericStatisticsSqlForCD(); //成品 //string sql = GetGenericStatisticsSqlForBORA(); //count = session.ExecuteSql(sql, parameters); ////注塑件 //sql = GetGenericStatisticsSqlForINJECT(); //count += session.ExecuteSql(sql, parameters); this.UpdateLastGenericTime(endTime, session); session.CommitTs(); } catch (Exception) { session.RollbackTs(); throw; } } return count; } public SystemConfig GetSystemConfig(string codeType) { StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT *"); sql.AppendLine(" FROM T_SYSTEM_CONFIG"); sql.AppendLine(" WHERE CODETYPE = @CodeType"); DataParameter[] parameters = { new DataParameter {ParameterName = "CodeType", DataType = DbType.String, Value = codeType} }; using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.Get(sql.ToString(), parameters); } } public string GetMFGMaterialCode(string MaterialCode) { StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT *"); sql.AppendLine(" FROM T_PP_TJFY_ExchangeType"); sql.AppendLine(" WHERE MaterialCode = @MaterialCode"); DataParameter[] parameters = { new DataParameter {ParameterName = "MaterialCode", DataType = DbType.String, Value = MaterialCode} }; using (IDataSession session = AppDataFactory.CreateMainSession()) { var date = session.GetTable(sql.ToString(), parameters); if (date.Rows.Count > 0) { return date.Rows[0]["MFGMaterialCode"].ToString(); } else return ""; } } protected int UpdateLastGenericTime(DateTime endTime, IDataSession session) { StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE T_SYSTEM_CONFIG"); sql.AppendLine(" SET CODEVALUE = @EndTime"); sql.AppendLine(" WHERE CODETYPE = @CodeType"); DataParameter[] parameters = { new DataParameter {ParameterName = "EndTime", DataType = DbType.String, Value = endTime.ToString("yyyy/MM/dd HH:mm:ss")}, new DataParameter {ParameterName = "CodeType", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_LSTTIME} }; return session.ExecuteSql(sql.ToString(), parameters); } /// /// 成都工厂适用SQL /// /// protected string GetGenericStatisticsSqlForCD() { StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO T_AW_COMPLETE_STATISTICS"); sql.AppendLine("SELECT NEWID(),"); sql.AppendLine(" REPLACE(T.CUSTOMERSPAREPARTS, ' ', '') AS MATERIALNO,"); sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT,"); sql.AppendLine(" COUNT(*) AS COMPLETECOUNT,"); sql.AppendLine(" @StartTime AS STARTTIME,"); sql.AppendLine(" @EndTime AS ENDTIME,"); sql.AppendLine(" CNFG.CODEVALUE + "); sql.AppendLine(" REPLACE(CONVERT(VARCHAR(100), GETDATE(), 112) +"); sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + "); sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY T.CUSTOMERSPAREPARTS))) + CAST (ROW_NUMBER() OVER (ORDER BY T.CUSTOMERSPAREPARTS) AS VARCHAR) AS ORDERNO,"); sql.AppendLine(" GETDATE() AS CREATETIME,"); sql.AppendLine(" USR.USERID AS CREATEUSER,"); sql.AppendLine(" GETDATE() AS UPDATETIME,"); sql.AppendLine(" USR.USERID AS UPDATEUSER,"); sql.AppendLine(" '0' AS DELFLAG"); sql.AppendLine(" FROM T_DAS_BARCODEVIBPAR T"); sql.AppendLine(" LEFT JOIN T_QM_USER USR"); sql.AppendLine(" ON USR.USERID = 'SYSTEM'"); sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG CNFG"); sql.AppendLine(" ON CNFG.CODETYPE = 'COMP_STATIS_ORDER'"); sql.AppendLine(" WHERE T.SCANTIME > @StartTime"); sql.AppendLine(" AND T.SCANTIME <= @EndTime"); sql.AppendLine(" AND SUBSTRING(T.ABARCODE, 9, 2) <> '99'"); sql.AppendLine(" GROUP BY T.CUSTOMERSPAREPARTS, USR.USERID, CNFG.CODEVALUE"); return sql.ToString(); } //长春 protected string GetGenericStatisticsSqlForCC() { StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO T_AW_COMPLETE_STATISTICS"); sql.AppendLine("SELECT NEWID(),"); sql.AppendLine(" INFO.MATERIALNO AS MATERIALNO,"); sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT,"); sql.AppendLine(" COUNT(*) AS COMPLETECOUNT,"); sql.AppendLine(" @StartTime AS STARTTIME,"); sql.AppendLine(" @EndTime AS ENDTIME,"); sql.AppendLine(" CNFG.CODEVALUE + "); sql.AppendLine(" REPLACE(CONVERT(VARCHAR(100), GETDATE(), 112) +"); sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + "); sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY INFO.MATERIALNO))) + CAST (ROW_NUMBER() OVER (ORDER BY INFO.MATERIALNO) AS VARCHAR) AS ORDERNO,"); sql.AppendLine(" GETDATE() AS CREATETIME,"); sql.AppendLine(" USR.USERID AS CREATEUSER,"); sql.AppendLine(" GETDATE() AS UPDATETIME,"); sql.AppendLine(" USR.USERID AS UPDATEUSER,"); sql.AppendLine(" '0' AS DELFLAG"); sql.AppendLine(" FROM T_AW_MAINOPERATION T"); sql.AppendLine(" LEFT JOIN T_BD_BARCODE_PRODUCT_RELATION RELATION"); sql.AppendLine(" ON T.PRODUCTTYPE = RELATION.PRODUCTTYPE"); sql.AppendLine(" AND T.PROCESSTYPE = RELATION.PROCESSTYPE"); sql.AppendLine(" LEFT JOIN T_BD_MATERIAL_BARCODE_INFO INFO"); sql.AppendLine(" ON INFO.PROCESSTYPE = RELATION.PROCESSTYPE"); sql.AppendLine(" AND INFO.PRODUCTTYPE = RELATION.PRODUCTTYPE"); sql.AppendLine(" AND SUBSTRING(T.PRODUCTCODE, RELATION.STARTINDEX, RELATION.SUBLENGTH) = INFO.BARCODEIDENTIFY"); sql.AppendLine(" LEFT JOIN T_QM_USER USR"); sql.AppendLine(" ON USR.USERNAME = 'SYSTEM'"); sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG CNFG"); sql.AppendLine(" ON CNFG.CODETYPE = 'COMP_STATIS_ORDER'"); sql.AppendLine(" WHERE INFO.BARCODEIDENTIFY IS NOT NULL"); sql.AppendLine(" AND T.OPERATEDDATE > @StartTime"); sql.AppendLine(" AND T.OPERATEDDATE <= @EndTime"); sql.AppendLine(" GROUP BY INFO.MATERIALNO, USR.USERID, CNFG.CODEVALUE"); return sql.ToString(); } //青岛仪表板/门板的成品 //protected string GetGenericStatisticsSqlForBORA() //{ // StringBuilder sql = new StringBuilder(); // sql.AppendLine(" INSERT INTO T_AW_COMPLETE_STATISTICS "); // sql.AppendLine(" SELECT NEWID(), "); // sql.AppendLine(" T.MATERIAL_CODE AS MATERIALNO, "); // sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT, "); // sql.AppendLine(" COUNT(*) AS COMPLETECOUNT, "); // sql.AppendLine(" @StartTime AS STARTTIME, "); // sql.AppendLine(" @EndTime AS ENDTIME, "); // sql.AppendLine(" CNFG.CODEVALUE + "); // sql.AppendLine(" REPLACE(CONVERT(VARCHAR(100), GETDATE(), 112) + "); // sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + "); // sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY T.MATERIAL_CODE))) + CAST (ROW_NUMBER() OVER (ORDER BY T.MATERIAL_CODE) AS VARCHAR) AS ORDERNO, "); // sql.AppendLine(" GETDATE() AS CREATETIME, "); // sql.AppendLine(" USR.USERID AS CREATEUSER, "); // sql.AppendLine(" GETDATE() AS UPDATETIME, "); // sql.AppendLine(" USR.USERID AS UPDATEUSER, "); // sql.AppendLine(" '0' AS DELFLAG "); // sql.AppendLine(" FROM T_AW_MAINOPERATION T "); // sql.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS C ON C.MATERIAL_TYPE_CODE=T.MATERIAL_TYPE_CODE "); // sql.AppendLine(" LEFT JOIN T_QM_USER USR "); // sql.AppendLine(" ON USR.USERNAME = 'SYSTEM' "); // sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG CNFG "); // sql.AppendLine(" ON CNFG.CODETYPE = 'COMP_STATIS_ORDER' "); // sql.AppendLine(" WHERE T.OPERATEDDATE > @StartTime "); // sql.AppendLine(" AND T.OPERATEDDATE <= @EndTime "); // sql.AppendLine(" AND C.MATERIAL_ATTRIBUTE='2' "); // sql.AppendLine(" GROUP BY T.MATERIAL_CODE, USR.USERID, CNFG.CODEVALUE "); // return sql.ToString(); //} //青岛注塑件 protected string GetGenericStatisticsSqlForBORA() { StringBuilder sql = new StringBuilder(); sql.AppendLine(" INSERT INTO T_AW_COMPLETE_STATISTICS SELECT NEWID(),MATERIALNO AS MATERIALNO,COUNT(MATERIALNO) AS SYSCOMPLETECOUNT,COUNT(MATERIALNO) AS COMPLETECOUNT, "); sql.AppendLine(" @StartTime AS STARTTIME,"); sql.AppendLine(" @EndTime AS ENDTIME,"); sql.AppendLine(" CASE MAX(line) WHEN '770B' THEN 'DP20' ELSE MAX(line) END AS ORDERNO, "); sql.AppendLine(" GETDATE() AS CREATETIME,"); sql.AppendLine(" 'b5c45b3e-724e-4d92-aad0-ef0cf3422a9e' AS CREATEUSER,"); sql.AppendLine(" GETDATE() AS UPDATETIME,"); sql.AppendLine(" 'b5c45b3e-724e-4d92-aad0-ef0cf3422a9e' AS UPDATEUSER,"); sql.AppendLine(" '0' AS DELFLAG"); sql.AppendLine(" FROM T_AW_COMPLETE_TJSTATISTICS T"); sql.AppendLine(" WHERE T.DELFLAG ='0' "); sql.AppendLine(" AND T.ENDTIME > @StartTime "); sql.AppendLine(" AND T.ENDTIME <= @EndTime"); sql.AppendLine(" GROUP BY T.MATERIALNO "); return sql.ToString(); } protected string GetGenericStatisticsSqlForINJECT() { StringBuilder sql = new StringBuilder(); sql.AppendLine(" update T_AW_COMPLETE_TJSTATISTICS set DELFLAG ='1' "); sql.AppendLine(" WHERE DELFLAG ='0'"); sql.AppendLine(" AND ENDTIME > @StartTime "); sql.AppendLine(" AND ENDTIME <= @EndTime "); return sql.ToString(); } protected string GetQuerySql(CompleteStatisticsEntity condition, out DataParameter[] parameters) { List parametersList = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT T.PID, "); sql.AppendLine(" T.MATERIALNO, "); sql.AppendLine(" MAT.MATERIALNAME, "); sql.AppendLine(" MAT.PRODUCTLINE, "); sql.AppendLine(" T.SYSCOMPLETECOUNT,"); sql.AppendLine(" T.COMPLETECOUNT,"); sql.AppendLine(" T.STARTTIME, "); sql.AppendLine(" T.ENDTIME, "); sql.AppendLine(" T.ORDERNO, "); sql.AppendLine(" T.CREATETIME,"); sql.AppendLine(" T.CREATEUSER,"); sql.AppendLine(" T.UPDATETIME,"); sql.AppendLine(" T.UPDATEUSER,"); sql.AppendLine(" T.DELFLAG,"); sql.AppendLine(" CUSER.USERNAME AS CREATEUSER_DISPLAY,"); sql.AppendLine(" UUSER.USERNAME AS UPDATEUSER_DISPLAY"); sql.AppendLine(" FROM T_AW_COMPLETE_STATISTICS T"); sql.AppendLine(" LEFT JOIN T_QM_USER CUSER"); sql.AppendLine(" ON T.CREATEUSER = CUSER.USERID"); sql.AppendLine(" LEFT JOIN T_QM_USER UUSER"); sql.AppendLine(" ON T.UPDATEUSER = UUSER.USERID"); sql.AppendLine(" INNER JOIN T_BD_MATERIAL_BARCODE_INFO MAT"); sql.AppendLine(" ON T.MATERIALNO = MAT.MATERIALNO"); sql.AppendLine(" WHERE 1 = 1"); if (!string.IsNullOrWhiteSpace(condition.MATERIALNO)) { sql.AppendLine(" AND T.MATERIALNO LIKE @MaterialNo"); parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) }); } if (!string.IsNullOrWhiteSpace(condition.DELFLAG)) { if(condition.DELFLAG == "是") sql.AppendLine(" AND T.DELFLAG = '1'"); else if(condition.DELFLAG == "否") sql.AppendLine(" AND T.DELFLAG = '0'"); } if (!string.IsNullOrWhiteSpace(condition.SENDTIME)) { sql.AppendLine(" AND T.ENDTIME >= @SEndTime"); parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) }); } if (!string.IsNullOrWhiteSpace(condition.EENDTIME)) { sql.AppendLine(" AND T.ENDTIME <= @EEndTime"); parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.EENDTIME) }); } parameters = parametersList.ToArray(); return sql.ToString(); } protected string GetNewQuerySql(CompleteStatisticsEntity condition, out DataParameter[] parameters) { List parametersList = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT T.PID, "); sql.AppendLine(" T.MATERIALNO, "); sql.AppendLine(" T.SYSCOMPLETECOUNT,"); sql.AppendLine(" T.COMPLETECOUNT,"); sql.AppendLine(" T.STARTTIME, "); sql.AppendLine(" T.ENDTIME, "); sql.AppendLine(" T.ORDERNO, "); sql.AppendLine(" T.CREATETIME,"); sql.AppendLine(" T.CREATEUSER,"); sql.AppendLine(" T.UPDATETIME,"); sql.AppendLine(" T.UPDATEUSER,"); sql.AppendLine(" T.DELFLAG,"); sql.AppendLine(" T.line as 'PRODUCTLINE',"); sql.AppendLine(" CUSER.USERNAME AS CREATEUSER_DISPLAY,"); sql.AppendLine(" UUSER.USERNAME AS UPDATEUSER_DISPLAY"); sql.AppendLine(" FROM T_AW_COMPLETE_TJSTATISTICS T"); sql.AppendLine(" LEFT JOIN T_QM_USER CUSER"); sql.AppendLine(" ON T.CREATEUSER = CUSER.USERID"); sql.AppendLine(" LEFT JOIN T_QM_USER UUSER"); sql.AppendLine(" ON T.UPDATEUSER = UUSER.USERID"); sql.AppendLine(" WHERE 1 = 1"); if (!string.IsNullOrWhiteSpace(condition.MATERIALNO)) { sql.AppendLine(" AND T.MATERIALNO LIKE @MaterialNo"); parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) }); } if (!string.IsNullOrWhiteSpace(condition.DELFLAG)) { if (condition.DELFLAG == "是") sql.AppendLine(" AND T.DELFLAG = '1'"); else if (condition.DELFLAG == "否") sql.AppendLine(" AND T.DELFLAG = '0'"); } if (!string.IsNullOrWhiteSpace(condition.SENDTIME)) { sql.AppendLine(" AND T.ENDTIME >= @SEndTime"); parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) }); } if (!string.IsNullOrWhiteSpace(condition.EENDTIME)) { sql.AppendLine(" AND T.ENDTIME <= @EEndTime"); parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.EENDTIME) }); } parameters = parametersList.ToArray(); return sql.ToString(); } public List GetExportData(CompleteStatisticsEntity model, IDataSession session) { DataParameter[] parameters; string sql = this.GetExportSql(model, out parameters); DataParameter[] unableParameters; //数据上传状态回填 string unableSql = this.unableExportDataString(model, out unableParameters); List rtn = session.GetList(sql, parameters).ToList(); //var count = session.ExecuteSql(unableSql, unableParameters); using (IDataSession session2 = AppDataFactory.CreateMainSession()) { var count = session2.ExecuteSql(unableSql, unableParameters); } return rtn; } private string unableExportDataString(CompleteStatisticsEntity condition, out DataParameter[] parameters) { List parametersList = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE [dbo].[T_AW_COMPLETE_STATISTICS] "); sql.AppendLine(" SET DELFLAG = '1'"); sql.AppendLine(" WHERE DELFLAG = '0'"); if (!string.IsNullOrWhiteSpace(condition.MATERIALNO)) { sql.AppendLine(" AND MATERIALNO LIKE @MaterialNo"); parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) }); } //20211214重传后DELFLAG状态修改 //if (!string.IsNullOrWhiteSpace(condition.SENDTIME)) //{ // sql.AppendLine(" AND ENDTIME >= @SEndTime"); // parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) }); //} if (!string.IsNullOrWhiteSpace(condition.EENDTIME)) { sql.AppendLine(" AND ENDTIME <= @EEndTime"); parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.EENDTIME) }); } parameters = parametersList.ToArray(); return sql.ToString(); } //protected string GetExportSql(CompleteStatisticsEntity condition, out DataParameter[] parameters) //{ // List parametersList = new List(); // StringBuilder sql = new StringBuilder(); // sql.AppendLine("SELECT EM.CODEVALUE AS EMPLOYEE, "); // sql.AppendLine(" SI.CODEVALUE AS SITE, "); // sql.AppendLine(" '' AS SHIFT, "); // sql.AppendLine(" T.MATERIALNO, "); // sql.AppendLine(" MAT.PRODUCTLINE, "); // sql.AppendLine(" '' AS EDIMAT, "); // sql.AppendLine(" '' AS SERIAL, "); // sql.AppendLine(" USR.CODEVALUE AS USERID, "); // sql.AppendLine(" T.ORDERNO, "); // sql.AppendLine(" T.COMPLETECOUNT,"); // sql.AppendLine(" T.STARTTIME"); // sql.AppendLine(" FROM T_AW_COMPLETE_STATISTICS T"); // sql.AppendLine(" INNER JOIN T_BD_MATERIAL_BARCODE_INFO MAT"); // sql.AppendLine(" ON T.MATERIALNO = MAT.MATERIALNO"); // sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG EM"); // sql.AppendLine(" ON EM.CODETYPE = @Employee"); // parametersList.Add(new DataParameter { ParameterName = "Employee", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_EMPLOYEE }); // sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG SI"); // sql.AppendLine(" ON SI.CODETYPE = @Site"); // parametersList.Add(new DataParameter { ParameterName = "Site", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_SITE }); // sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG USR"); // sql.AppendLine(" ON USR.CODETYPE = @UserId"); // parametersList.Add(new DataParameter { ParameterName = "UserId", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_USER }); // sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG ORD"); // sql.AppendLine(" ON ORD.CODETYPE = @OrderNo"); // parametersList.Add(new DataParameter { ParameterName = "OrderNo", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_ORDER }); // sql.AppendLine(" WHERE T.DELFLAG = '0'"); // if (!string.IsNullOrWhiteSpace(condition.MATERIALNO)) // { // sql.AppendLine(" AND T.MATERIALNO LIKE @MaterialNo"); // parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) }); // } // if (!string.IsNullOrWhiteSpace(condition.SENDTIME)) // { // sql.AppendLine(" AND T.ENDTIME >= @SEndTime"); // parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) }); // } // if (!string.IsNullOrWhiteSpace(condition.EENDTIME)) // { // sql.AppendLine(" AND T.ENDTIME <= @EEndTime"); // parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = string.Format("{0}", condition.EENDTIME) }); // } // sql.AppendLine(" ORDER BY T.ORDERNO ASC"); // parameters = parametersList.ToArray(); // return sql.ToString(); //} protected string GetExportSql(CompleteStatisticsEntity condition, out DataParameter[] parameters) { List parametersList = new List(); StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT (select top 1 MFG_USERCODE from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO) AS EMPLOYEE, "); sql.AppendLine(" (select top 1 MFG_LOCATIONCODE from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO) AS SITE, "); sql.AppendLine(" '' AS SHIFT, "); sql.AppendLine(" T.MATERIALNO, "); sql.AppendLine(" (select top 1 PRODUCELINECODE from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO) AS PRODUCTLINE, "); sql.AppendLine(" '' AS EDIMAT, "); sql.AppendLine(" '' AS SERIAL, "); sql.AppendLine(" (select top 1 USERID from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO), "); sql.AppendLine(" T.ORDERNO, "); sql.AppendLine(" T.COMPLETECOUNT,"); sql.AppendLine(" T.STARTTIME,"); sql.AppendLine(" T.ENDTIME"); sql.AppendLine(" FROM T_AW_COMPLETE_STATISTICS T"); sql.AppendLine(" WHERE T.DELFLAG = '0'"); if (!string.IsNullOrWhiteSpace(condition.MATERIALNO)) { sql.AppendLine(" AND T.MATERIALNO LIKE @MaterialNo"); parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) }); } //20211214如网络中断,重连后数据重传 //if (!string.IsNullOrWhiteSpace(condition.SENDTIME)) //{ // sql.AppendLine(" AND T.ENDTIME >= @SEndTime"); // parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) }); //} if (!string.IsNullOrWhiteSpace(condition.EENDTIME)) { sql.AppendLine(" AND T.ENDTIME <= @EEndTime"); parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = string.Format("{0}", condition.EENDTIME) }); } sql.AppendLine(" ORDER BY T.ORDERNO ASC"); parameters = parametersList.ToArray(); return sql.ToString(); } public DataTable ExportExcelData(CompleteStatisticsEntity model) { DataParameter[] parameters; string sql = this.GetNewQuerySql(model, out parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetTable(sql, parameters); } } } }