天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1452 lines
70 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMAPP.FJC.Entity.ProduceManage;
using QMFrameWork.Data;
using QMFrameWork.Log;
using System.Data;
using QMAPP.FJC.Entity;
namespace QMAPP.FJC.DAL.ProduceManage
{
/// <summary>
/// 模块编号:
/// 作 用:返修记录
/// 作 者:王庆男
/// 编写日期:2015年06月24日
///</summary>
public class ScrapRecordDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public MendRecorder Get(MendRecorder model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<MendRecorder>(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-获取信息!"
});
throw ex;
}
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public MendRecorder GetMendRecorderInfo(MendRecorder model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//获取信息
sql = this.GetQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
model = session.Get<MendRecorder>(sql, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-获取信息!"
});
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(MendRecorder condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<MendRecorder>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-获取列表!"
});
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(MendRecorder condition, ref List<DataParameter> 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.MENDNUMBER ");
sqlBuilder.Append(" ,M.CREATEUSER ");
sqlBuilder.Append(" ,M.CREATEDATE ");
sqlBuilder.Append(" ,M.UPDATEUSER ");
sqlBuilder.Append(" ,M.UPDATEDATE ");
sqlBuilder.Append(" ,M.MENDDUTY ");
sqlBuilder.Append(" ,M.ERP_MFGCODETYPE ");
sqlBuilder.Append(" ,M.ERP_CAR ");
sqlBuilder.Append(" ,M.ERP_WORKLINE ");
sqlBuilder.Append(" ,M.ERP_SHIFT ");
sqlBuilder.Append(" ,M.ERP_WORKCELL ");
sqlBuilder.Append(" ,M.ERP_DEFECTTO ");
sqlBuilder.Append(" ,M.ERP_PRODUCTTYPE ");
sqlBuilder.Append(" ,M.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(" ,P.STATUS ");
sqlBuilder.Append(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.Append(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.Append(" FROM T_AW_MENDRECORDER M ");
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 ");
whereBuilder.Append(" AND M.MENDRESULT = '2'");
//查询条件
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.PRODUCESHIFTTCODE) == false)
{
whereBuilder.Append(" AND M.PRODUCESHIFTTCODE =@PRODUCESHIFTTCODE");
parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
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.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.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.BATCH_NO >=@CREATEDATESTART");
parameters.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART.Replace("-", "") });
}
//操作结束日期
if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false)
{
whereBuilder.Append(" AND M.BATCH_NO <=@CREATEDATEEND");
parameters.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND.Replace("-", "") });
}
//返修原因
if (string.IsNullOrEmpty(condition.MENDREASON) == false)
{
whereBuilder.Append(" AND exists(select 1 from T_AW_MENDERREASON r where r.ppid=m.pid and r.DEFECTKEY=@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;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(MendRecorder model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
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;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsMendRecorder(MendRecorder model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
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 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(MendRecorder model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<MendRecorder>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(MendRecorder model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<MendRecorder>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 逻辑删除
/// <summary>
/// 逻辑删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(MendRecorder model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
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
#region 获取返修列表??????
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
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<DataParameter>().ToArray());
}
return dt;
}
#endregion
#region 获取返修统计信息填充图表
/// <summary>
/// 获取返修统计信息
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<MendRecorder> GetMendRecorderStatistics(MendRecorder condition)
{
List<DataParameter> paralist = new List<DataParameter>();
List<MendRecorder> recorderList = new List<MendRecorder>();
string sql = GetStatisticsSql(condition, ref paralist);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
recorderList = session.GetList<MendRecorder>(sql, paralist.ToArray()).ToList<MendRecorder>();
}
return recorderList;
}
#endregion
#region 统计信息查询语句
private string GetStatisticsSql(MendRecorder condition, ref List<DataParameter> 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<DataParameter> 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<DataParameter> paralist = new List<DataParameter>();
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 获取返修记录数量
public int GetCountByMaterial(string materialCode)
{
int count = 0;
string sql = string.Format("select isnull(sum(mendnumber),0) from T_AW_MENDRECORDER where MATERIAL_CODE='{0}' and MENDRESULT = '2'", materialCode);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new List<DataParameter>().ToArray()));
}
return count;
}
#endregion
}
}