using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Data ;
using QMFrameWork.Data ;
using QMAPP.Entity ;
using QMAPP.FJC.Entity.Operation ;
using QMAPP.DAL ;
using QMAPP.FJC.Entity ;
namespace QMAPP.FJC.DAL.Operation
{
/// <summary>
/// 模块编号:M13-2
/// 作 用:加工记录查询数据层
/// 作 者:单雨春
/// 编写日期:2015年06月04日
///</summary>
public class MainOperationDAL : BaseDAL
{
/// <summary>
/// 数据会话
/// </summary>
//public IDataSession BaseSession = null;
#region 获取信息加工记录
/// <summary>
/// 获取信息加工记录
/// </summary>
/// <param name="">条件</param>
/// <returns>加工记录信息</returns>
public MainOperation Get ( MainOperation model )
{
try
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//获取信息
model = session . Get < MainOperation > ( model ) ;
}
return model ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public MainOperation GetMainOperation ( MainOperation condition )
{
try
{
MainOperation model ;
string sql = @ "SELECT PID
, PDID
, PRODUCTCODE
, PROCESSTYPE
, PRODUCTTYPE
, MACHINENAME
, MACHINECODDE
, MOLDNUMBER
, [ STATUS ]
, OPERATESTATE
, OPERATEDDATE
, CURRENTPROCESS
, PRODUCESHIFTNAME
, PRODUCESHIFTTCODE
, PRODUCELINE
, [ FILENAME ]
, FILEPATH
, MODELSTATION
, CREATEUSER
, CREATEDATE
, UPDATEUSER
, UPDATEDATE
, PRODUCTCODESTR
FROM T_AW_MAINOPERATION where 1 = 1 ";
if ( string . IsNullOrEmpty ( condition . PDID ) = = false )
{
sql + = string . Format ( " and PDID='{0}' " , condition . PDID ) ;
}
if ( string . IsNullOrEmpty ( condition . PROCESSTYPE ) = = false )
{
sql + = string . Format ( " and PROCESSTYPE='{0}' " , condition . PROCESSTYPE ) ;
}
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//获取信息
model = session . Get < MainOperation > ( sql , new List < DataParameter > ( ) . ToArray ( ) ) ;
}
return model ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList ( MainOperation 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 < MainOperation > ( sql , parameters . ToArray ( ) , page ) ;
}
return page ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <param name="page"></param>
/// <returns></returns>
public DataPage GetOperationList ( MainOperation condition , DataPage page )
{
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
string sql = this . GetOperationQuerySql ( condition , ref parameters ) ;
//分页关键字段及排序
//page.KeyName = "PID";
//if (string.IsNullOrEmpty(page.SortExpression))
//{
// page.SortExpression = "UPDATEDATE DESC";
//}
List < MainOperation > list = new List < MainOperation > ( ) ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
list = session . GetList < MainOperation > ( sql , parameters . ToArray ( ) ) . ToList < MainOperation > ( ) ;
}
List < MainOperation > opingList =
list . Where ( o = > o . OPERATESTATE = = EnumGeter . OPERATESTATE . OPERATING . GetHashCode ( ) . ToString ( ) )
. OrderByDescending ( o = > o . CREATEDATE )
. ToList < MainOperation > ( ) ;
List < MainOperation > opedList =
list . Where ( o = > o . OPERATESTATE ! = EnumGeter . OPERATESTATE . OPERATING . GetHashCode ( ) . ToString ( ) )
. OrderByDescending ( o = > o . CREATEDATE )
. ToList < MainOperation > ( ) ;
opingList = opingList . Concat ( opedList ) . ToList < MainOperation > ( ) ;
page . Result = opingList ;
return page ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <param name="page"></param>
/// <returns></returns>
public DataPage GetOperationListNew ( MainOperation condition , DataPage page )
{
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
StringBuilder sql = new StringBuilder ( ) ; // this.GetOperationQuerySql(condition, ref parameters);
//分页关键字段及排序
//page.KeyName = "PID";
//if (string.IsNullOrEmpty(page.SortExpression))
//{
// page.SortExpression = "UPDATEDATE DESC";
//}
sql . AppendLine ( string . Format ( "SELECT TOP {0} R.[PID] " , page . PageSize ) ) ;
sql . AppendLine ( " ,P.[PID] AS [PDID] " ) ;
sql . AppendLine ( " ,P.[PRODUCTCODE] " ) ;
sql . AppendLine ( " ,'' AS [PRODUCTCODESTR] " ) ;
sql . AppendLine ( " ,R.[WORKCELL_CODE] AS [PROCESSTYPE] " ) ;
sql . AppendLine ( " ,P.[PRODUCTTYPE] " ) ;
sql . AppendLine ( " ,P.[MACHINENAME] " ) ;
sql . AppendLine ( " ,P.[MACHINECODDE] " ) ;
//sql.AppendLine(" ,R.[MODULE_CODE] AS [MOLDNUMBER] ");
sql . AppendLine ( " ,P.[PLAN_NO] AS [MOLDNUMBER] " ) ;
sql . AppendLine ( " ,P.[STATUS] " ) ;
sql . AppendLine ( " ,R.[PROCESS_STATE] AS [OPERATESTATE] " ) ;
sql . AppendLine ( " ,R.[WORK_END_TIME] AS [OPERATEDDATE] " ) ;
sql . AppendLine ( " ,R.[WORKLOC_CODE] AS [CURRENTPROCESS] " ) ;
sql . AppendLine ( " ,P.[PRODUCESHIFTNAME] " ) ;
sql . AppendLine ( " ,P.[PRODUCESHIFTTCODE] " ) ;
sql . AppendLine ( " ,P.[WORKCENTER_CODE] AS [PRODUCELINE] " ) ;
sql . AppendLine ( " ,'' AS [FILENAME] " ) ;
sql . AppendLine ( " ,'' AS [FILEPATH] " ) ;
sql . AppendLine ( " ,'' AS [MODELSTATION] " ) ;
sql . AppendLine ( " ,P.[CREATEUSER] " ) ;
sql . AppendLine ( " ,R.[IN_WORKCELL_TIME] AS [CREATEDATE] " ) ;
sql . AppendLine ( " ,P.[UPDATEUSER] " ) ;
sql . AppendLine ( " ,P.[UPDATEDATE] " ) ;
sql . AppendLine ( " ,M.[MATERIAL_NAME] AS [PRODUCTTYPETEXT] " ) ;
sql . AppendLine ( " ,W.[WORKCELL_NAME] AS PROCESSTYPETEXT " ) ;
sql . AppendLine ( " FROM [T_QT_PROCESSRECORD] AS R WITH(NOLOCK) " ) ;
sql . AppendLine ( " LEFT JOIN [T_AW_PRODUCT] AS P WITH(NOLOCK) " ) ;
sql . AppendLine ( " ON R.[PRODUCT_PID]=P.[PID] " ) ;
sql . AppendLine ( " LEFT JOIN [T_MD_MATERIAL] AS M " ) ;
sql . AppendLine ( " ON P.[MATERIAL_CODE]= M.[MATERIAL_CODE] " ) ;
sql . AppendLine ( " LEFT JOIN [T_MD_WORKCELL] AS W " ) ;
sql . AppendLine ( " ON W.[WORKCELL_CODE] = R.[WORKCELL_CODE] " ) ;
if ( ! string . IsNullOrWhiteSpace ( condition . CURRENTPROCESS ) )
{
sql . AppendLine ( " WHERE R.[WORKLOC_CODE]=@workloccode " ) ;
parameters . Add ( new DataParameter ( "workloccode" , condition . CURRENTPROCESS ) ) ;
}
sql . AppendLine ( " ORDER BY R.[IN_WORKCELL_TIME] DESC " ) ;
List < MainOperation > list = new List < MainOperation > ( ) ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
list = session . GetList < MainOperation > ( sql . ToString ( ) , parameters . ToArray ( ) ) . ToList < MainOperation > ( ) ;
}
page . Result = list ;
return page ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部</returns>
public List < MainOperation > GetList ( MainOperation condition )
{
string sql = null ;
List < MainOperation > list = new List < MainOperation > ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
sql = this . GetQuerySql ( condition , ref parameters ) ;
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
list = session . GetList < MainOperation > ( sql , parameters . ToArray ( ) ) . ToList ( ) ;
}
return list ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部</returns>
public List < MainOperation > GetMainOperationWorkCell ( string ProductCode , bool isINJECTION )
{
string sql = null ;
List < MainOperation > list = new List < MainOperation > ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
if ( isINJECTION )
{
sql =
"select MACHINECODDE,OPERATEDDATE,PRODUCESHIFTTCODE,PRODUCTCODE,WORKCELL_CODE,(SELECT WORKCELL_NAME FROM T_MD_WORKCELL where WORKCELL_CODE = t.WORKCELL_CODE) as WORKCELL_NAME from T_AW_MAINOPERATION t where PDID in(select PRODUCT_PID from T_QT_PRODUCT_STRUCTURE where PROCESS_CODE='" +
ProductCode + "') " ;
}
else
{
sql =
"SELECT MACHINECODDE,CREATEDATE as OPERATEDDATE,PRODUCESHIFTTCODE,PRODUCTCODE FROM T_AW_PRODUCT where PRODUCTCODE='" + ProductCode + "' and CREATEDATE=(select max(CREATEDATE) from T_AW_PRODUCT where PRODUCTCODE='" +
ProductCode + "')" ;
}
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
list = session . GetList < MainOperation > ( sql , parameters . ToArray ( ) ) . ToList ( ) ;
}
return list ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部</returns>
public List < MainOperation > GetOperationRecords ( string ProductCode )
{
StringBuilder sql = new StringBuilder ( ) ;
List < MainOperation > list = new List < MainOperation > ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
sql . AppendLine ( "SELECT O.* ,M.MATERIAL_NAME AS MATERIAL_CODE_NAME,w.WORKCELL_NAME,U.USERNAME AS CREATEUSERNAME " ) ;
sql . AppendLine ( " FROM (SELECT * FROM T_AW_MAINOPERATION " ) ;
sql . AppendLine ( " WHERE PDID IN(SELECT PRODUCT_PID FROM T_QT_PRODUCT_STRUCTURE " ) ;
sql . AppendFormat ( " WHERE PROCESS_CODE='{0}' \r" , ProductCode ) ;
sql . AppendLine ( " UNION " ) ;
sql . AppendLine ( " SELECT PART_PID FROM T_QT_PRODUCT_STRUCTURE " ) ;
sql . AppendFormat ( " WHERE PROCESS_CODE='{0}')) AS O \r" , ProductCode ) ;
sql . AppendLine ( " LEFT JOIN T_MD_MATERIAL M ON M.MATERIAL_CODE=O.MATERIAL_CODE " ) ;
sql . AppendLine ( " LEFT JOIN T_MD_WORKCELL W ON W.WORKCELL_CODE=O.WORKCELL_CODE " ) ;
sql . AppendLine ( " LEFT JOIN T_QM_USER U ON U.USERID=O.CREATEUSER " ) ;
sql . AppendLine ( " ORDER BY OPERATEDDATE DESC " ) ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
list = session . GetList < MainOperation > ( sql . ToString ( ) , parameters . ToArray ( ) ) . ToList ( ) ;
}
return list ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部</returns>
public DataTable GetListForstatistic ( MainOperation condition )
{
DataTable dt = null ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
string sql = null ;
sql = @ "select MODELSTATION as 模具,PRODUCTTYPE as 产品类别,count(1) as 加工数量,
case SUBSTRING ( productcode , 1 3 , 1 ) when 'H' then 'H' when 'B' then 'B' else ' ' end as 高 低 配
from T_AW_MAINOPERATION where 1 = 1 ";
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND MACHINECODDE = @MACHINECODDE" ) ;
parameters . Add ( new DataParameter { ParameterName = "MACHINECODDE" , DataType = DbType . String , Value = condition . MACHINECODDE } ) ;
}
if ( string . IsNullOrEmpty ( condition . CREATEUSER ) = = false )
{
whereBuilder . Append ( " AND CREATEUSER = @CREATEUSER" ) ;
parameters . Add ( new DataParameter { ParameterName = "CREATEUSER" , DataType = DbType . String , Value = condition . CREATEUSER } ) ;
}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND CREATEDATE >= @DATEOPESTART" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPESTART" , DataType = DbType . DateTime , Value = condition . DATEOPESTART } ) ;
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND CREATEDATE <= @DATEOPEEND" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPEEND" , DataType = DbType . DateTime , Value = condition . DATEOPEEND } ) ;
}
sql + = whereBuilder . ToString ( ) ;
sql + = " group by MODELSTATION ,PRODUCTTYPE, case SUBSTRING(productcode, 13, 1) when 'H' then 'H' when 'B' then 'B' else '' end " ;
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
}
return dt ;
}
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public DataTable GetListForStatisticWithColor ( MainOperation condition )
{
DataTable dt = null ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
string sql = null ;
sql = @ "select MODELSTATION as 模具,temp.MATERIAL_NAME as 零件名称,temp.MATERIAL_CODE as 零件号,
count ( 1 ) as 加 工 数 量
, COLORVALUE AS 颜 色
from (
select MODELSTATION , m . MATERIAL_NAME , c . material_code ,
case RIGHT ( c . MATERIAL_CODE , 3 ) when ' 6 T6 ' then ' 黑 色 ' when ' 7 AQ ' then ' 灰 色 ' when ' 8 AS ' then ' 棕 色 ' else ' 未 确 认 颜 色 ' end as COLORVALUE
from T_AW_MAINOPERATION c
left join T_MD_MATERIAL m on m . MATERIAL_CODE = c . MATERIAL_CODE
where 1 = 1 ";
// select MODELSTATION as 模具,PRODUCTTYPE as 产品类别,count(1) as 加工数量,
//HB as 高低配 ,COLORVALUE AS 颜色 from (
//select MODELSTATION,PRODUCTTYPE,case SUBSTRING(productcode, 13, 1) when 'H' then '高' when 'B' then '低' else '' end as HB,
//case SUBSTRING(productcode, 14, 1) when '1' then '黑色' when '2' then '灰/浅灰' else '棕/米' end as COLORVALUE
//from T_AW_MAINOPERATION where 1=1 ";
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND MACHINECODDE = @MACHINECODDE" ) ;
parameters . Add ( new DataParameter { ParameterName = "MACHINECODDE" , DataType = DbType . String , Value = condition . MACHINECODDE } ) ;
}
//if (string.IsNullOrEmpty(condition.CREATEUSER) == false)
//{
// whereBuilder.Append(" AND CREATEUSER = @CREATEUSER");
// parameters.Add(new DataParameter { ParameterName = "CREATEUSER", DataType = DbType.String, Value = condition.CREATEUSER });
//}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND c.CREATEDATE >= @DATEOPESTART" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPESTART" , DataType = DbType . DateTime , Value = condition . DATEOPESTART } ) ;
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND c.CREATEDATE <= @DATEOPEEND" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPEEND" , DataType = DbType . DateTime , Value = condition . DATEOPEEND } ) ;
}
sql + = whereBuilder . ToString ( ) ;
sql + = " )temp " ;
//sql += " group by MODELSTATION ,PRODUCTTYPE, HB,COLORVALUE ORDER BY HB,COLORVALUE ASC";
sql + = " group by MODELSTATION ,temp.MATERIAL_NAME ,temp.MATERIAL_CODE,COLORVALUE ORDER BY COLORVALUE ASC" ;
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
}
return dt ;
}
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public DataTable GetListForStatisticWithColor2 ( MainOperation condition )
{
DataTable dt = null ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
string sql = null ;
sql = @ "select MODELSTATION as 模具,temp.MATERIALNAME as 零件名称,temp.materialno as 零件号,
SUM ( SYSCOMPLETECOUNT ) AS 加 工 数 量
, COLORVALUE AS 颜 色
from (
select ' ' MODELSTATION , m . MATERIALNAME , c . materialno , c . SYSCOMPLETECOUNT ,
case RIGHT ( c . materialno , 3 ) when ' 6 T6 ' then ' 黑 色 ' when ' 7 AQ ' then ' 灰 色 ' when ' 8 AS ' then ' 棕 色 ' else ' 未 确 认 颜 色 ' end as COLORVALUE
from T_AW_COMPLETE_STATISTICS c
left join T_BD_MATERIAL_BARCODE_INFO m ON m . materialno = c . materialno
where c . DELFLAG = '1' ";
//if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
//{
// whereBuilder.Append(" AND MACHINECODDE = @MACHINECODDE");
// parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
//}
//if (string.IsNullOrEmpty(condition.CREATEUSER) == false)
//{
// whereBuilder.Append(" AND CREATEUSER = @CREATEUSER");
// parameters.Add(new DataParameter { ParameterName = "CREATEUSER", DataType = DbType.String, Value = condition.CREATEUSER });
//}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND c.ENDTIME >= @DATEOPESTART" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPESTART" , DataType = DbType . DateTime , Value = condition . DATEOPESTART } ) ;
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND c.ENDTIME <= @DATEOPEEND" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPEEND" , DataType = DbType . DateTime , Value = condition . DATEOPEEND } ) ;
}
sql + = whereBuilder . ToString ( ) ;
sql + = " )temp " ;
//sql += " group by MODELSTATION ,PRODUCTTYPE, HB,COLORVALUE ORDER BY HB,COLORVALUE ASC";
sql + = " group by MODELSTATION ,temp.MATERIALNAME ,temp.materialno,COLORVALUE ORDER BY COLORVALUE ASC" ;
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
}
return dt ;
}
#region
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetListWithParameter ( MainOperation condition , DataPage page )
{
string sql = null ;
string countSql = null ;
DataTable dt = new DataTable ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
//分页关键字段及排序
page . KeyName = "PID" ;
if ( string . IsNullOrEmpty ( page . SortExpression ) )
{
page . SortExpression = "OPERATEDDATE DESC" ;
}
sql = this . GetPageQuerySqlWithParameter ( condition , ref parameters , page ) ;
// sql = this.GetPageQuerySql(condition, ref parameters, page);
countSql = this . GetCountQuerySql ( condition ) ;
int sum = 0 ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
List < DataParameter > parameters1 = new List < DataParameter > ( ) ;
dt = session . GetTable ( sql , parameters1 . ToArray ( ) ) ;
sum = Convert . ToInt32 ( session . ExecuteSqlScalar ( countSql , parameters . ToArray ( ) ) ) ;
}
page . RecordCount = sum ;
page . Result = dt ;
#region 设置分页属性
if ( page . RecordCount = = 0 )
{
page . PageIndex = 1 ;
return page ;
}
if ( page . RecordCount % page . PageSize ! = 0 )
{
page . PageCount = page . RecordCount / page . PageSize + 1 ;
if ( page . PageCount < page . PageIndex )
{
page . PageIndex = page . PageCount ;
}
}
else
{
page . PageCount = page . RecordCount / page . PageSize ;
}
if ( page . PageCount < page . PageIndex )
{
page . PageIndex = page . PageCount ;
}
#endregion
return page ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public DataTable GetListWithParameterDt ( MainOperation condition )
{
string sql = null ;
string countSql = null ;
DataTable dt = new DataTable ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
sql = this . GetPageQuerySqlWithParameterDt ( condition , ref parameters ) ;
int sum = 0 ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
List < DataParameter > parameters1 = new List < DataParameter > ( ) ;
dt = session . GetTable ( sql , parameters1 . ToArray ( ) ) ;
}
return dt ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取列表Title
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataTable GetListWithParameterTitle ( MainOperation condition )
{
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
DataTable dt = new DataTable ( ) ;
try
{
sql = this . GetQuerySqlWithParameter ( condition , ref parameters ) ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
}
return dt ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public string GetJsonSource ( System . Data . DataTable dt )
{
string pa = "," ;
try
{
StringBuilder returnValue = new StringBuilder ( "{ \"total\":\" " + dt . Rows . Count . ToString ( ) + "\", \"rows\":[" ) ;
if ( dt . Rows . Count > 0 )
{
for ( int i = 0 ; i < dt . Rows . Count ; i + + )
{
if ( i ! = 0 )
{
returnValue . AppendLine ( pa ) ;
}
string josnItem = "" ;
List < string > itemValue = new List < string > ( ) ;
foreach ( DataColumn item in dt . Columns )
{
object value = dt . Rows [ i ] [ item . ColumnName ] ;
itemValue . Add ( string . Format ( "\"{0}\":\"{1}\"" , item . ColumnName , value ! = null & & value ! = System . DBNull . Value ? value : string . Empty ) ) ;
}
if ( itemValue . Count > 0 )
{
josnItem = "{" + string . Join ( "," , itemValue . ToArray ( ) ) + "}" ;
}
else
{
josnItem = string . Empty ;
}
returnValue . AppendLine ( josnItem ) ;
}
}
returnValue . Append ( "]" ) ;
returnValue . Append ( "}" ) ;
return returnValue . ToString ( ) ;
}
catch ( Exception )
{
throw ;
}
}
#endregion
#region
/// <summary>
/// 获取列表(不带加工参数)
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetListWithOutParameter ( MainOperation condition , DataPage page )
{
string sql = null ;
string countSql = null ;
DataTable dt = new DataTable ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
//分页关键字段及排序
page . KeyName = "PID" ;
if ( string . IsNullOrEmpty ( page . SortExpression ) )
{
page . SortExpression = "OPERATEDDATE DESC" ;
}
sql = this . GetPageQuerySqlWithOutParameter ( condition , ref parameters , page ) ;
// sql = this.GetPageQuerySql(condition, ref parameters, page);
countSql = this . GetCountQuerySql ( condition ) ;
int sum = 0 ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
sum = Convert . ToInt32 ( session . ExecuteSqlScalar ( countSql , parameters . ToArray ( ) ) ) ;
}
page . RecordCount = sum ;
page . Result = dt ;
#region 设置分页属性
if ( page . RecordCount = = 0 )
{
page . PageIndex = 1 ;
return page ;
}
if ( page . RecordCount % page . PageSize ! = 0 )
{
page . PageCount = page . RecordCount / page . PageSize + 1 ;
if ( page . PageCount < page . PageIndex )
{
page . PageIndex = page . PageCount ;
}
}
else
{
page . PageCount = page . RecordCount / page . PageSize ;
}
if ( page . PageCount < page . PageIndex )
{
page . PageIndex = page . PageCount ;
}
#endregion
return page ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public DataTable GetListWithOutParameterDt ( MainOperation condition )
{
DataResult < DataTable > result = new DataResult < DataTable > ( ) ;
string sql = null ;
DataTable dt = new DataTable ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
sql = this . GetPageQuerySqlWithOutParameterDt ( condition , ref parameters ) ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
}
//result.Result = dt;
return dt ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取列表Title(不带加工参数)
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataTable GetListWithOutParameterTitle ( MainOperation condition )
{
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
DataTable dt = new DataTable ( ) ;
try
{
sql = this . GetQuerySqlWithOutParameter ( condition , ref parameters ) ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
}
return dt ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @ "SELECT A.[PID]
, A . [ PDID ]
, A . [ PRODUCTCODE ]
, A . [ PRODUCTCODESTR ]
, A . [ PROCESSTYPE ]
, A . [ PRODUCTTYPE ]
, A . [ MACHINENAME ]
, A . [ MACHINECODDE ]
, A . [ MOLDNUMBER ]
, A . [ STATUS ]
, A . [ OPERATESTATE ]
, A . [ OPERATEDDATE ]
, A . [ CURRENTPROCESS ]
, A . [ PRODUCESHIFTNAME ]
, A . [ PRODUCESHIFTTCODE ]
, A . [ PRODUCELINE ]
, A . [ FILENAME ]
, A . [ FILEPATH ]
, A . [ MATERIAL_CODE ]
, A . [ MATERIAL_NAME ]
, A . [ MATERIAL_TYPE_CODE ]
, A . [ WORKCENTER_CODE ]
, A . [ MODELSTATION ]
, A . [ CREATEUSER ]
, A . [ CREATEDATE ]
, A . [ UPDATEUSER ]
, A . [ UPDATEDATE ]
, B . PRODUCTNAME AS PRODUCTTYPETEXT
, C . PROCESSNAME AS PROCESSTYPETEXT
FROM [ T_AW_MAINOPERATION ] A
LEFT JOIN T_BD_PRODUCTBASIC B ON A . PRODUCTTYPE = B . PRODUCTTYPE
LEFT JOIN T_BD_PROCESSINFO C ON A . PROCESSTYPE = C . PROCESSTYPE ");
if ( string . IsNullOrEmpty ( condition . PDID ) = = false )
{
whereBuilder . Append ( " AND A.PDID in ( select PDID from T_AW_MAINPRODUCT where mid=@PDID union select @PDID)" ) ;
parameters . Add ( new DataParameter { ParameterName = "PDID" , DataType = DbType . String , Value = condition . PDID } ) ;
}
if ( string . IsNullOrEmpty ( condition . OPERATESTATE ) = = false )
{
whereBuilder . Append ( " AND A.OPERATESTATE = @OPERATESTATE" ) ;
parameters . Add ( new DataParameter { ParameterName = "OPERATESTATE" , DataType = DbType . String , Value = condition . OPERATESTATE } ) ;
}
if ( string . IsNullOrEmpty ( condition . PROCESSTYPE ) = = false )
{
whereBuilder . Append ( " AND A.PROCESSTYPE = @PROCESSTYPE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PROCESSTYPE" , DataType = DbType . String , Value = condition . PROCESSTYPE } ) ;
}
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND A.MACHINECODDE = @MACHINECODDE" ) ;
parameters . Add ( new DataParameter { ParameterName = "MACHINECODDE" , DataType = DbType . String , Value = condition . MACHINECODDE } ) ;
}
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND A.PRODUCTCODE = @PRODUCTCODE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCTCODE" , DataType = DbType . String , Value = condition . PRODUCTCODE } ) ;
}
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCTTYPE ) = = false )
{
whereBuilder . Append ( " AND A.PRODUCTTYPE = @PRODUCTTYPE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCTTYPE" , DataType = DbType . String , Value = condition . PRODUCTTYPE } ) ;
}
//查询条件零件号
if ( string . IsNullOrEmpty ( condition . MATERIAL_CODE ) = = false )
{
whereBuilder . Append ( " AND A.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 A.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 . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND A.WORKCENTER_CODE = @WORKCENTER_CODE" ) ;
parameters . Add ( new DataParameter { ParameterName = "WORKCENTER_CODE" , DataType = DbType . String , Value = condition . WORKCENTER_CODE } ) ;
}
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND A.PRODUCELINE = @PRODUCELINE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCELINE" , DataType = DbType . String , Value = condition . PRODUCELINE } ) ;
}
if ( string . IsNullOrEmpty ( condition . MOLDNUMBER ) = = false )
{
whereBuilder . Append ( " AND A.MOLDNUMBER = @MOLDNUMBER" ) ;
parameters . Add ( new DataParameter { ParameterName = "MOLDNUMBER" , DataType = DbType . String , Value = condition . MOLDNUMBER } ) ;
}
//加入时间条件
if ( condition . OPERATEDDATE ! = DateTime . MinValue )
{
String startDateTime = condition . OPERATEDDATE . ToString ( "yyyy-MM-dd" ) + " 00:00:00" ;
whereBuilder . Append ( " AND A.OPERATEDDATE >= '" + Convert . ToDateTime ( startDateTime ) + "'" ) ;
}
if ( condition . OPERATEDDATE ! = DateTime . MinValue )
{
String endDateTime = condition . OPERATEDDATE . ToString ( "yyyy-MM-dd" ) + " 23:59:59" ;
whereBuilder . Append ( " AND A.OPERATEDDATE <= '" + Convert . ToDateTime ( endDateTime ) + "'" ) ;
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
sqlBuilder . Append ( " ORDER BY OPERATEDDATE ASC " ) ;
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
private string GetOperationQuerySql ( MainOperation condition , ref List < DataParameter > parameters )
{
condition . CreateDateStart = System . DateTime . Now . AddDays ( - 1 ) . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @ "SELECT A.[PID]
, A . [ PDID ]
, A . [ PRODUCTCODE ]
, A . [ PRODUCTCODESTR ]
, A . [ PROCESSTYPE ]
, A . [ PRODUCTTYPE ]
, A . [ MACHINENAME ]
, A . [ MACHINECODDE ]
, A . [ MOLDNUMBER ]
, A . [ STATUS ]
, A . [ OPERATESTATE ]
, A . [ OPERATEDDATE ]
, A . [ CURRENTPROCESS ]
, A . [ PRODUCESHIFTNAME ]
, A . [ PRODUCESHIFTTCODE ]
, A . [ PRODUCELINE ]
, A . [ FILENAME ]
, A . [ FILEPATH ]
, A . [ MATERIAL_CODE ]
, A . [ MATERIAL_NAME ]
, A . [ MATERIAL_TYPE_CODE ]
, A . [ WORKCENTER_CODE ]
, A . [ MODELSTATION ]
, A . [ WORKCELL_CODE ]
, A . [ CREATEUSER ]
, A . [ CREATEDATE ]
, A . [ UPDATEUSER ]
, A . [ UPDATEDATE ]
, B . PRODUCTNAME AS PRODUCTTYPETEXT
, C . PROCESSNAME AS PROCESSTYPETEXT
FROM [ T_AW_MAINOPERATION ] A
LEFT JOIN T_BD_PRODUCTBASIC B ON A . PRODUCTTYPE = B . PRODUCTTYPE
LEFT JOIN T_BD_PROCESSINFO C ON A . PROCESSTYPE = C . PROCESSTYPE
where A . OPERATESTATE = '0'
");
if ( string . IsNullOrEmpty ( condition . PROCESSTYPE ) = = false )
{
sqlBuilder . Append ( " AND A.PROCESSTYPE = @PROCESSTYPE" ) ;
//parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
}
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
sqlBuilder . Append ( " AND A.MACHINECODDE = @MACHINECODDE" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
sqlBuilder . Append ( " union " ) ;
sqlBuilder . Append ( @ "SELECT A.[PID]
, A . [ PDID ]
, A . [ PRODUCTCODE ]
, A . [ PRODUCTCODESTR ]
, A . [ PROCESSTYPE ]
, A . [ PRODUCTTYPE ]
, A . [ MACHINENAME ]
, A . [ MACHINECODDE ]
, A . [ MOLDNUMBER ]
, A . [ STATUS ]
, A . [ OPERATESTATE ]
, A . [ OPERATEDDATE ]
, A . [ CURRENTPROCESS ]
, A . [ PRODUCESHIFTNAME ]
, A . [ PRODUCESHIFTTCODE ]
, A . [ PRODUCELINE ]
, A . [ FILENAME ]
, A . [ FILEPATH ]
, A . [ MODELSTATION ]
, A . [ MATERIAL_CODE ]
, A . [ MATERIAL_NAME ]
, A . [ MATERIAL_TYPE_CODE ]
, A . [ WORKCELL_CODE ]
, A . [ WORKCENTER_CODE ]
, A . [ CREATEUSER ]
, A . [ CREATEDATE ]
, A . [ UPDATEUSER ]
, A . [ UPDATEDATE ]
, B . PRODUCTNAME AS PRODUCTTYPETEXT
, C . PROCESSNAME AS PROCESSTYPETEXT
FROM [ T_AW_MAINOPERATION ] A
LEFT JOIN T_BD_PRODUCTBASIC B ON A . PRODUCTTYPE = B . PRODUCTTYPE
LEFT JOIN T_BD_PROCESSINFO C ON A . PROCESSTYPE = C . PROCESSTYPE ");
if ( string . IsNullOrEmpty ( condition . CreateDateStart ) = = false )
{
whereBuilder . Append ( " A.CREATEDATE >@CREATEDATE" ) ;
parameters . Add ( new DataParameter { ParameterName = "CREATEDATE" , DataType = DbType . String , Value = condition . CreateDateStart } ) ;
}
if ( string . IsNullOrEmpty ( condition . OPERATESTATE ) = = false )
{
whereBuilder . Append ( " AND A.OPERATESTATE = @OPERATESTATE" ) ;
parameters . Add ( new DataParameter { ParameterName = "OPERATESTATE" , DataType = DbType . String , Value = condition . OPERATESTATE } ) ;
}
if ( string . IsNullOrEmpty ( condition . PROCESSTYPE ) = = false )
{
whereBuilder . Append ( " AND A.PROCESSTYPE = @PROCESSTYPE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PROCESSTYPE" , DataType = DbType . String , Value = condition . PROCESSTYPE } ) ;
}
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND A.MACHINECODDE = @MACHINECODDE" ) ;
parameters . Add ( new DataParameter { ParameterName = "MACHINECODDE" , DataType = DbType . String , Value = condition . MACHINECODDE } ) ;
}
//查询条件零件号
if ( string . IsNullOrEmpty ( condition . MATERIAL_CODE ) = = false )
{
whereBuilder . Append ( " AND A.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 A.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 . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND A.WORKCENTER_CODE = @WORKCENTER_CODE" ) ;
parameters . Add ( new DataParameter { ParameterName = "WORKCENTER_CODE" , DataType = DbType . String , Value = condition . WORKCENTER_CODE } ) ;
}
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND A.PRODUCTCODE = @PRODUCTCODE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCTCODE" , DataType = DbType . String , Value = condition . PRODUCTCODE } ) ;
}
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCTTYPE ) = = false )
{
whereBuilder . Append ( " AND A.PRODUCTTYPE = @PRODUCTTYPE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCTTYPE" , DataType = DbType . String , Value = condition . PRODUCTTYPE } ) ;
}
if ( string . IsNullOrEmpty ( condition . PDID ) = = false )
{
whereBuilder . Append ( " AND A.PDID = @PDID" ) ;
parameters . Add ( new DataParameter { ParameterName = "PDID" , DataType = DbType . String , Value = condition . PDID } ) ;
}
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND A.PRODUCELINE = @PRODUCELINE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCELINE" , DataType = DbType . String , Value = condition . PRODUCELINE } ) ;
}
if ( string . IsNullOrEmpty ( condition . MOLDNUMBER ) = = false )
{
whereBuilder . Append ( " AND A.MOLDNUMBER = @MOLDNUMBER" ) ;
parameters . Add ( new DataParameter { ParameterName = "MOLDNUMBER" , DataType = DbType . String , Value = condition . MOLDNUMBER } ) ;
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) ) ;
}
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取查询语句(带加工参数)
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySqlWithParameter ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @ "SELECT M.[PID]
, M . [ PRODUCTCODE ]
, M . [ PROCESSTYPE ]
, M . [ PRODUCTTYPE ]
, M . [ MACHINENAME ]
, M . [ MACHINECODDE ]
, M . [ WORKCELL_CODE ]
, M . [ STATUS ]
, M . [ OPERATESTATE ]
, M . [ OPERATEDDATE ]
, M . [ PRODUCESHIFTNAME ]
, M . [ PRODUCESHIFTTCODE ]
, M . [ MATERIAL_CODE ]
, MA . [ MATERIAL_NAME ]
, M . [ MATERIAL_TYPE_CODE ]
, M . [ WORKCENTER_CODE ]
, M . [ MODELSTATION ]
, M . [ CREATEDATE ]
, ' ' AS OPERATEDDATESTR
, ' ' AS CREATEDATESTR
, O . [ USERNAME ] AS CREATEUSERNAME ");
sqlBuilder . AppendFormat ( " ,P.[{0}] " , condition . SelectCollumns . Replace ( "," , "],P.[" ) ) ;
sqlBuilder . Append ( " FROM [T_AW_MAINOPERATION] M " ) ;
sqlBuilder . AppendFormat ( " LEFT JOIN {0} P ON M.[PID]=P.[MOID] " , condition . PARATABLENAME ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER O ON O.[USERID] = M.[CREATEUSER]" ) ;
sqlBuilder . Append ( " LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE " ) ;
#region 查询条件
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCELINE = @PRODUCELINE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCELINE" , DataType = DbType . String , Value = condition . PRODUCELINE } ) ;
}
//产品条码
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCTCODE LIKE '%" + condition . PRODUCTCODE + "%' " ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = String.Format("%{0}%", condition.PRODUCTCODE) });
}
//班次编号
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCESHIFTTCODE = '" + condition . PRODUCESHIFTTCODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编码
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND M.MACHINECODDE = '" + condition . MACHINECODDE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//产品状态
if ( string . IsNullOrEmpty ( condition . STATUS ) = = false )
{
whereBuilder . Append ( " AND M.STATUS = '" + condition . STATUS + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//查询条件零件类别
if ( string . IsNullOrEmpty ( condition . MATERIAL_TYPE_CODE ) = = false )
{
whereBuilder . Append ( " AND M.MATERIAL_TYPE_CODE = '" + condition . 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 = '" + condition . MATERIAL_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//查询条件工作中心
if ( string . IsNullOrEmpty ( condition . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCENTER_CODE = '" + condition . WORKCENTER_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
//工序
if ( string . IsNullOrEmpty ( condition . WORKCELL_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCELL_CODE = '" + condition . WORKCELL_CODE + "'" ) ;
}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE >= @DATEOPESTART" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPESTART" , DataType = DbType . DateTime , Value = condition . DATEOPESTART } ) ;
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE <= @DATEOPEEND" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPEEND" , DataType = DbType . DateTime , Value = condition . DATEOPEEND } ) ;
}
#endregion
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取查询语句(不带带加工参数)
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySqlWithOutParameter ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @ "SELECT M.[PID]
, M . [ PRODUCTCODE ]
, M . [ PROCESSTYPE ]
, M . [ PRODUCTTYPE ]
, M . [ MACHINENAME ]
, M . [ MACHINECODDE ]
, M . [ WORKCELL_CODE ]
, M . [ STATUS ]
, M . [ OPERATESTATE ]
, M . [ OPERATEDDATE ]
, M . [ PRODUCESHIFTNAME ]
, M . [ PRODUCESHIFTTCODE ]
, M . [ MATERIAL_CODE ]
, MA . [ MATERIAL_NAME ]
, M . [ MATERIAL_TYPE_CODE ]
, M . [ WORKCENTER_CODE ]
, M . [ WORKCELL_CODE ]
, M . [ MODELSTATION ]
, M . [ CREATEDATE ]
, ' ' AS OPERATEDDATESTR
, ' ' AS CREATEDATESTR
, O . [ USERNAME ] AS CREATEUSERNAME ");
sqlBuilder . Append ( " FROM [T_AW_MAINOPERATION] M " ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER O ON O.[USERID] = M.[CREATEUSER]" ) ;
sqlBuilder . Append ( " LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE " ) ;
#region 查询条件
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCELINE = @PRODUCELINE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCELINE" , DataType = DbType . String , Value = condition . PRODUCELINE } ) ;
}
//产品条码
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCTCODE LIKE '%" + condition . PRODUCTCODE + "%' " ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = String.Format("%{0}%", condition.PRODUCTCODE) });
}
//班次编号
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCESHIFTTCODE = '" + condition . PRODUCESHIFTTCODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编码
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND M.MACHINECODDE = '" + condition . MACHINECODDE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//产品状态
if ( string . IsNullOrEmpty ( condition . STATUS ) = = false )
{
whereBuilder . Append ( " AND M.STATUS = '" + condition . STATUS + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//查询条件零件类别
if ( string . IsNullOrEmpty ( condition . MATERIAL_TYPE_CODE ) = = false )
{
whereBuilder . Append ( " AND M.MATERIAL_TYPE_CODE = '" + condition . 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 = '" + condition . MATERIAL_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//查询条件工作中心
if ( string . IsNullOrEmpty ( condition . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCENTER_CODE = '" + condition . WORKCENTER_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
//工序
if ( string . IsNullOrEmpty ( condition . WORKCELL_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCELL_CODE = '" + condition . WORKCELL_CODE + "'" ) ;
}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE >= @DATEOPESTART" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPESTART" , DataType = DbType . DateTime , Value = condition . DATEOPESTART } ) ;
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE <= @DATEOPEEND" ) ;
parameters . Add ( new DataParameter { ParameterName = "DATEOPEEND" , DataType = DbType . DateTime , Value = condition . DATEOPEEND } ) ;
}
#endregion
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 框架外的分页语句获取查询语句(不带带加工参数)
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <param name="page"></param>
/// <returns></returns>
private string GetPageQuerySqlWithOutParameter ( MainOperation condition , ref List < DataParameter > parameters , DataPage page )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
if ( page . SortExpression . Contains ( "CREATEUSER" ) = = false & & page . SortExpression . Contains ( "UPDATEUSER" ) = = false )
{
page . SortExpression = "M." + page . SortExpression ;
}
if ( page . SortExpression . Contains ( "CREATEUSER" ) )
{
page . SortExpression = page . SortExpression . Substring ( page . SortExpression . TrimStart ( ) . IndexOf ( " " ) ) ;
page . SortExpression = "O.USERNAME " + page . SortExpression ;
}
sqlBuilder . Append ( "SELECT * FROM (" ) ;
sqlBuilder . AppendFormat ( @"SELECT top {0} ROW_NUMBER() OVER (ORDER BY {1} ) AS ROWINDEX," , ( page . PageIndex * page . PageSize ) . ToString ( ) , page . SortExpression ) ;
sqlBuilder . Append ( @ "
M . PID
, M . [ PRODUCTCODE ]
, M . [ MATERIAL_CODE ]
, MA . [ MATERIAL_NAME ]
, M . [ MATERIAL_TYPE_CODE ]
, M . [ WORKCELL_CODE ]
, M . [ MACHINENAME ]
, M . [ MACHINECODDE ]
, M . [ STATUS ]
, M . [ OPERATESTATE ]
, ' ' as OPERATEDDATE
, M . [ PRODUCESHIFTNAME ]
, M . [ PRODUCESHIFTTCODE ]
, M . [ WORKCENTER_CODE ]
, M . [ MODELSTATION ]
, ' ' as CREATEDATE
, CONVERT ( VARCHAR ( 1 9 ) , M . [ OPERATEDDATE ] , 1 2 0 ) AS OPERATEDDATESTR
, CONVERT ( VARCHAR ( 1 9 ) , M . [ CREATEDATE ] , 1 2 0 ) AS CREATEDATESTR
, O . [ USERNAME ] AS CREATEUSERNAME ");
sqlBuilder . Append ( " FROM [T_AW_MAINOPERATION] M " ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER O ON O.[USERID] = M.[CREATEUSER]" ) ;
sqlBuilder . Append ( " LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE " ) ;
#region 查询条件
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCELINE = '" + condition . PRODUCELINE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE });
}
//产品条码
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCTCODE LIKE '%" + condition . PRODUCTCODE + "%' " ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = String.Format("%{0}%", condition.PRODUCTCODE) });
}
//班次编号
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCESHIFTTCODE = '" + condition . PRODUCESHIFTTCODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编码
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND M.MACHINECODDE = '" + condition . MACHINECODDE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//产品状态
if ( string . IsNullOrEmpty ( condition . STATUS ) = = false )
{
whereBuilder . Append ( " AND M.STATUS = '" + condition . STATUS + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//查询条件零件类别
if ( string . IsNullOrEmpty ( condition . MATERIAL_TYPE_CODE ) = = false )
{
whereBuilder . Append ( " AND M.MATERIAL_TYPE_CODE = '" + condition . 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 = '" + condition . MATERIAL_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//查询条件工作中心
if ( string . IsNullOrEmpty ( condition . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCENTER_CODE = '" + condition . WORKCENTER_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
//工序
if ( string . IsNullOrEmpty ( condition . WORKCELL_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCELL_CODE = '" + condition . WORKCELL_CODE + "'" ) ;
}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE >= '" + condition . DATEOPESTART + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPESTART", DataType = DbType.DateTime, Value = condition.DATEOPESTART });
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE <= '" + condition . DATEOPEEND + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPEEND", DataType = DbType.DateTime, Value = condition.DATEOPEEND });
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
sqlBuilder . AppendFormat ( ") QMDATAPAGE1 WHERE ROWINDEX BETWEEN {0} AND {1}" , Convert . ToString ( page . PageSize * ( page . PageIndex - 1 ) + 1 ) , Convert . ToString ( page . PageSize * page . PageIndex ) ) ;
#endregion
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
private string GetPageQuerySqlWithOutParameterDt ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @ "SELECT
M . PID ,
M . [ PRODUCTCODE ]
, M . [ PROCESSTYPE ]
, M . [ PRODUCTTYPE ]
, M . [ MACHINENAME ]
, M . [ MACHINECODDE ]
, M . [ WORKCELL_CODE ]
, CASE M . [ STATUS ] WHEN '0' THEN ' 正 常 ' else ' 异 常 ' end as STATUS
, CASE M . [ OPERATESTATE ] WHEN '0' THEN ' 加 工 中 ' WHEN '1' THEN ' 加 工 完 成 ' else ' 放 行 ' end as OPERATESTATE
, ' ' as OPERATEDDATE
, M . [ PRODUCESHIFTNAME ]
, M . [ PRODUCESHIFTTCODE ]
, M . [ MATERIAL_CODE ]
, MA . [ MATERIAL_NAME ]
, M . [ MATERIAL_TYPE_CODE ]
, M . [ WORKCENTER_CODE ]
, M . [ MODELSTATION ]
, ' ' as CREATEDATE
, CONVERT ( VARCHAR ( 1 9 ) , M . [ OPERATEDDATE ] , 1 2 0 ) AS OPERATEDDATESTR
, CONVERT ( VARCHAR ( 1 9 ) , M . [ CREATEDATE ] , 1 2 0 ) AS CREATEDATESTR
, O . [ USERNAME ] AS CREATEUSERNAME ");
sqlBuilder . Append ( " FROM [T_AW_MAINOPERATION] M " ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER O ON O.[USERID] = M.[CREATEUSER]" ) ;
sqlBuilder . Append ( " LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE " ) ;
#region 查询条件
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCELINE = '" + condition . PRODUCELINE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE });
}
//产品条码
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCTCODE LIKE '%" + condition . PRODUCTCODE + "%' " ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = String.Format("%{0}%", condition.PRODUCTCODE) });
}
//班次编号
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCESHIFTTCODE = '" + condition . PRODUCESHIFTTCODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编码
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND M.MACHINECODDE = '" + condition . MACHINECODDE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//产品状态
if ( string . IsNullOrEmpty ( condition . STATUS ) = = false )
{
whereBuilder . Append ( " AND M.STATUS = '" + condition . STATUS + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//查询条件零件类别
if ( string . IsNullOrEmpty ( condition . MATERIAL_TYPE_CODE ) = = false )
{
whereBuilder . Append ( " AND M.MATERIAL_TYPE_CODE = '" + condition . 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 = '" + condition . MATERIAL_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//查询条件工作中心
if ( string . IsNullOrEmpty ( condition . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCENTER_CODE = '" + condition . WORKCENTER_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
//工序
if ( string . IsNullOrEmpty ( condition . WORKCELL_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCELL_CODE = '" + condition . WORKCELL_CODE + "'" ) ;
}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE >= '" + condition . DATEOPESTART + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPESTART", DataType = DbType.DateTime, Value = condition.DATEOPESTART });
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE <= '" + condition . DATEOPEEND + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPEEND", DataType = DbType.DateTime, Value = condition.DATEOPEEND });
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
#endregion
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 框架外的分页语句获取查询语句(带加工参数)
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <param name="page"></param>
/// <returns></returns>
private string GetPageQuerySqlWithParameter ( MainOperation condition , ref List < DataParameter > parameters , DataPage page )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
if ( page . SortExpression . Contains ( "CREATEUSER" ) = = false & & page . SortExpression . Contains ( "UPDATEUSER" ) = = false )
{
if ( condition . SelectCollumns . ToUpper ( ) . IndexOf ( page . SortExpression . ToUpper ( ) . Replace ( "DESC" , "" ) . Replace ( "ASC" , "" ) . Trim ( ) ) > = 0 )
{
page . SortExpression = "M.CREATEDATE DESC " ;
}
else
{
page . SortExpression = "M." + page . SortExpression ;
}
}
if ( page . SortExpression . Contains ( "CREATEUSERNAME" ) )
{
page . SortExpression = page . SortExpression . Replace ( "CREATEUSERNAME" , "CREATEUSER" ) ;
}
sqlBuilder . Append ( "SELECT tt.*,O.[USERNAME] AS CREATEUSERNAME " ) ;
sqlBuilder . AppendFormat ( " ,P.[{0}] " , condition . SelectCollumns . Replace ( "," , "],P.[" ) ) ;
sqlBuilder . Append ( " FROM (" ) ;
sqlBuilder . AppendFormat ( @"SELECT top {0} ROW_NUMBER() OVER (ORDER BY {1} ) AS ROWINDEX," , ( page . PageIndex * page . PageSize ) . ToString ( ) , page . SortExpression ) ;
sqlBuilder . Append ( @ "
M . PID
, M . [ PRODUCTCODE ]
, M . [ PROCESSTYPE ]
, M . [ PRODUCTTYPE ]
, M . [ MACHINENAME ]
, M . [ MACHINECODDE ]
, M . [ WORKCELL_CODE ]
, M . [ STATUS ]
, M . [ OPERATESTATE ]
, ' ' as OPERATEDDATE
, M . [ PRODUCESHIFTNAME ]
, M . [ PRODUCESHIFTTCODE ]
, M . [ MATERIAL_CODE ]
, MA . [ MATERIAL_NAME ]
, M . [ MATERIAL_TYPE_CODE ]
, M . [ WORKCENTER_CODE ]
, M . [ MODELSTATION ]
, ' ' as CREATEDATE
, M . [ CREATEUSER ]
, M . [ OPERATEDDATE ] AS OPERATEDDATESTR
, M . [ CREATEDATE ] AS CREATEDATESTR ");
sqlBuilder . Append ( @" FROM [T_AW_MAINOPERATION] M " ) ;
sqlBuilder . Append ( " LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE " ) ;
#region //查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCELINE = '" + condition . PRODUCELINE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE });
}
//产品条码
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCTCODE LIKE '%" + condition . PRODUCTCODE + "%' " ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = String.Format("%{0}%", condition.PRODUCTCODE) });
}
//班次编号
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCESHIFTTCODE = '" + condition . PRODUCESHIFTTCODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编码
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND M.MACHINECODDE = '" + condition . MACHINECODDE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//产品状态
if ( string . IsNullOrEmpty ( condition . STATUS ) = = false )
{
whereBuilder . Append ( " AND M.STATUS = '" + condition . STATUS + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//查询条件零件类别
if ( string . IsNullOrEmpty ( condition . MATERIAL_TYPE_CODE ) = = false )
{
whereBuilder . Append ( " AND M.MATERIAL_TYPE_CODE = '" + condition . 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 = '" + condition . MATERIAL_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//查询条件工作中心
if ( string . IsNullOrEmpty ( condition . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCENTER_CODE = '" + condition . WORKCENTER_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
//工序
if ( string . IsNullOrEmpty ( condition . WORKCELL_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCELL_CODE = '" + condition . WORKCELL_CODE + "'" ) ;
}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE >= '" + condition . DATEOPESTART + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPESTART", DataType = DbType.DateTime, Value = condition.DATEOPESTART });
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE <= '" + condition . DATEOPEEND + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPEEND", DataType = DbType.DateTime, Value = condition.DATEOPEEND });
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
#endregion
sqlBuilder . Append ( ") tt " ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER O ON O.[USERID] = tt.[CREATEUSER]" ) ;
sqlBuilder . AppendFormat ( " LEFT JOIN {0} P ON tt.[PID]=P.[MOID]" , condition . PARATABLENAME ) ;
sqlBuilder . AppendFormat ( " WHERE ROWINDEX BETWEEN {0} AND {1}" , Convert . ToString ( page . PageSize * ( page . PageIndex - 1 ) + 1 ) , Convert . ToString ( page . PageSize * page . PageIndex ) ) ;
//#endregion
//sqlBuilder.Clear().Append( " select abc.*,p.RESTTHICKNESS,o.USERNAME from ( select top 20 ROW_NUMBER() OVER (ORDER BY M.OPERATEDDATE DESC ) AS ROWINDEX,* from [T_AW_MAINOPERATION] M WHERE M.CREATEDATE >= '2012-01-01' AND M.CREATEDATE <= '2016-01-01' AND M.PROCESSTYPE = 6) abc left join "
// + " T_AW_BURNPARAMETER P ON abc.[PID]=P.[MOID] AND P.CREATEDATE >= '2012-01-01' AND P.CREATEDATE <= '2016-01-01' LEFT JOIN T_QM_USER O ON O.[USERID] = abc.[CREATEUSER]");
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// Sql语句
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
private string GetPageQuerySqlWithParameterDt ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
sqlBuilder . Append ( "SELECT tt.*,O.[USERNAME] AS CREATEUSERNAME " ) ;
sqlBuilder . AppendFormat ( " ,P.[{0}] " , condition . SelectCollumns . Replace ( "," , "],P.[" ) ) ;
sqlBuilder . Append ( " FROM (" ) ;
sqlBuilder . Append ( @ "SELECT
M . PID ,
M . [ PRODUCTCODE ]
, M . [ PROCESSTYPE ]
, M . [ PRODUCTTYPE ]
, M . [ MACHINENAME ]
, M . [ MACHINECODDE ]
, M . [ WORKCELL_CODE ]
, M . [ STATUS ]
, M . [ OPERATESTATE ]
, ' ' as OPERATEDDATE
, M . [ PRODUCESHIFTNAME ]
, M . [ PRODUCESHIFTTCODE ]
, M . [ MODELSTATION ]
, ' ' as CREATEDATE
, M . [ MATERIAL_CODE ]
, MA . [ MATERIAL_NAME ]
, M . [ MATERIAL_TYPE_CODE ]
, M . [ WORKCENTER_CODE ]
, M . [ CREATEUSER ]
, M . [ OPERATEDDATE ] AS OPERATEDDATESTR
, M . [ CREATEDATE ] AS CREATEDATESTR ");
sqlBuilder . Append ( @" FROM [T_AW_MAINOPERATION] M " ) ;
sqlBuilder . Append ( " LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE " ) ;
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCELINE = '" + condition . PRODUCELINE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE });
}
//产品条码
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCTCODE LIKE '%" + condition . PRODUCTCODE + "%' " ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = String.Format("%{0}%", condition.PRODUCTCODE) });
}
//班次编号
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCESHIFTTCODE = '" + condition . PRODUCESHIFTTCODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编码
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND M.MACHINECODDE = '" + condition . MACHINECODDE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//产品状态
if ( string . IsNullOrEmpty ( condition . STATUS ) = = false )
{
whereBuilder . Append ( " AND M.STATUS = '" + condition . STATUS + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//查询条件零件类别
if ( string . IsNullOrEmpty ( condition . MATERIAL_TYPE_CODE ) = = false )
{
whereBuilder . Append ( " AND M.MATERIAL_TYPE_CODE = '" + condition . 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 = '" + condition . MATERIAL_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//查询条件工作中心
if ( string . IsNullOrEmpty ( condition . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCENTER_CODE = '" + condition . WORKCENTER_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
//工序
if ( string . IsNullOrEmpty ( condition . WORKCELL_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCELL_CODE = '" + condition . WORKCELL_CODE + "'" ) ;
}
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE >= '" + condition . DATEOPESTART + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPESTART", DataType = DbType.DateTime, Value = condition.DATEOPESTART });
}
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE <= '" + condition . DATEOPEEND + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPEEND", DataType = DbType.DateTime, Value = condition.DATEOPEEND });
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
sqlBuilder . Append ( ") tt " ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER O ON O.[USERID] = tt.[CREATEUSER]" ) ;
sqlBuilder . AppendFormat ( " LEFT JOIN {0} P ON tt.[PID]=P.[MOID]" , condition . PARATABLENAME ) ;
//#endregion
//sqlBuilder.Clear().Append( " select abc.*,p.RESTTHICKNESS,o.USERNAME from ( select top 20 ROW_NUMBER() OVER (ORDER BY M.OPERATEDDATE DESC ) AS ROWINDEX,* from [T_AW_MAINOPERATION] M WHERE M.CREATEDATE >= '2012-01-01' AND M.CREATEDATE <= '2016-01-01' AND M.PROCESSTYPE = 6) abc left join "
// + " T_AW_BURNPARAMETER P ON abc.[PID]=P.[MOID] AND P.CREATEDATE >= '2012-01-01' AND P.CREATEDATE <= '2016-01-01' LEFT JOIN T_QM_USER O ON O.[USERID] = abc.[CREATEUSER]");
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 获取求和语句
/// <summary>
/// 获取求和语句
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
private string GetCountQuerySql ( MainOperation condition )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @"SELECT count(1) " ) ;
sqlBuilder . Append ( "FROM T_AW_MAINOPERATION M" ) ;
#region 查询条件
//查询条件
if ( string . IsNullOrEmpty ( condition . PRODUCELINE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCELINE = '" + condition . PRODUCELINE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE });
}
//产品条码
if ( string . IsNullOrEmpty ( condition . PRODUCTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCTCODE LIKE '%" + condition . PRODUCTCODE + "%' " ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = String.Format("%{0}%", condition.PRODUCTCODE) });
}
//班次编号
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND M.PRODUCESHIFTTCODE = '" + condition . PRODUCESHIFTTCODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编码
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND M.MACHINECODDE = '" + condition . MACHINECODDE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//产品状态
if ( string . IsNullOrEmpty ( condition . STATUS ) = = false )
{
whereBuilder . Append ( " AND M.STATUS = '" + condition . STATUS + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//查询条件零件类别
if ( string . IsNullOrEmpty ( condition . MATERIAL_TYPE_CODE ) = = false )
{
whereBuilder . Append ( " AND M.MATERIAL_TYPE_CODE = '" + condition . 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 = '" + condition . MATERIAL_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//查询条件工作中心
if ( string . IsNullOrEmpty ( condition . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCENTER_CODE = '" + condition . WORKCENTER_CODE + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
//工序
if ( string . IsNullOrEmpty ( condition . WORKCELL_CODE ) = = false )
{
whereBuilder . Append ( " AND M.WORKCELL_CODE = '" + condition . WORKCELL_CODE + "'" ) ;
}
//开始时间
if ( condition . DATEOPESTART ! = null & & condition . DATEOPESTART ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE >= '" + condition . DATEOPESTART + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPESTART", DataType = DbType.DateTime, Value = condition.DATEOPESTART });
}
//结束时间
if ( condition . DATEOPEEND ! = null & & condition . DATEOPEEND ! = DateTime . MinValue )
{
whereBuilder . Append ( " AND M.CREATEDATE <= '" + condition . DATEOPEEND + "'" ) ;
//parameters.Add(new DataParameter { ParameterName = "DATEOPEEND", DataType = DbType.DateTime, Value = condition.DATEOPEEND });
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
#endregion
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData ( MainOperation 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_MAIN" ;
}
return dt ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsMainOperation ( MainOperation 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_MAINOPERATION" ) ;
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 ( MainOperation model )
{
int count = 0 ;
try
{
if ( this . BaseSession ! = null )
{
count = this . BaseSession . Insert < MainOperation > ( model ) ;
}
else
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//插入基本信息
count = session . Insert < MainOperation > ( model ) ;
}
}
return count ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入多行数</returns>
public int Insert ( List < MainOperation > model )
{
int count = 0 ;
try
{
if ( this . BaseSession ! = null )
{
count = this . BaseSession . Insert < List < MainOperation > > ( model ) ;
}
else
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//插入基本信息
count = session . Insert < List < MainOperation > > ( model ) ;
}
}
return count ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update ( MainOperation model )
{
int count = 0 ;
try
{
if ( this . BaseSession ! = null )
{
//更新基本信息
count = BaseSession . Update < MainOperation > ( model ) ;
}
else
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//更新基本信息
count = session . Update < MainOperation > ( model ) ;
}
}
return count ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 逻辑删除
/// <summary>
/// 逻辑删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete ( MainOperation model )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
int count = 0 ;
try
{
if ( this . BaseSession ! = null )
{
sqlBuilder . Append ( "DELETE T_AW_MAINOPERATION " ) ;
sqlBuilder . Append ( "WHERE PID = @PID " ) ;
parameters . Add ( new DataParameter { ParameterName = "PID" , DataType = DbType . String , Value = model . PID } ) ;
count = BaseSession . ExecuteSql ( sqlBuilder . ToString ( ) , parameters . ToArray ( ) ) ;
}
else
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//删除基本信息
sqlBuilder . Append ( "DELETE T_AW_MAINOPERATION " ) ;
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 获取列表(产品加工追溯)
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetMainOperationReviewList ( MainOperation condition , DataPage page )
{
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
sql = this . GetMainOperationReviewSql ( condition , ref parameters ) ;
//分页关键字段及排序
page . KeyName = "PID" ;
page . SortExpression = "UPDATEDATE DESC" ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
page = session . GetDataPage < MainOperation > ( sql , parameters . ToArray ( ) , page ) ;
}
return page ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public List < Product > GetMainOperations ( Product condition )
{
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
sql = "select p.[PID],p.[PRODUCTTYPE],p.[PRODUCTCODE],p.[PRODUCTSOURCE],p.[MACHINENAME]" ;
sql + = ",p.[MACHINECODDE],p.[MATERIAL_CODE],p.[STATUS],p.[ISPARENT],p.[CURRENTPROCESS],p.[PRODUCELINE],p.[PRODUCESHIFTNAME],p.[PRODUCESHIFTTCODE]" ;
sql + = ",p.[OUTFLAG],p.[USINGSTATE],p.[CAPACITY],p.[USINGCOUNT],p.[CREATEUSER],p.[CREATEDATE],p.[UPDATEUSER],p.[UPDATEDATE],p.[WORKCELL_CODE]" ;
sql + = ",p.[WORKLOC_CODE],p.[WORKCENTER_CODE],p.[TEAM_CODE],p.[ENDOFLINE],p.[PLAN_NO]" ;
sql + = ",p.[MATERIAL_TYPE],m.MAINCODE " ;
sql + = "from T_AW_PRODUCT p left join T_AW_MAIN m on m.EPIDERMISCODE=p.PRODUCTCODE" ;
sql + = " where p.pid in ( select PART_PID from T_QT_PRODUCT_STRUCTURE where PROCESS_CODE='" + condition . PRODUCTCODE + "' ) " ;
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
return session . GetList < Product > ( sql , parameters . ToArray ( ) ) . ToList ( ) ;
}
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetMainOperationReviewSql ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( " SELECT MP.*,C.USERNAME AS CREATEUSERNAME " ) ;
sqlBuilder . Append ( " FROM T_AW_MAINOPERATION MP " ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER C ON C.USERID=MP.CREATEUSER " ) ;
sqlBuilder . Append ( " WHERE MP.PDID IN( " ) ;
sqlBuilder . Append ( " SELECT M.PID " ) ;
sqlBuilder . Append ( " FROM T_AW_MAIN M where 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( condition . PRODUCTCODE ) )
{
//产品条码
sqlBuilder . Append ( " and M.EPIDERMISCODE=@PRODUCTCODEA " ) ; //'本体条码(产品条码)'
parameters . Add ( new DataParameter { ParameterName = "PRODUCTCODEA" , DataType = DbType . String , Value = condition . PRODUCTCODE } ) ;
}
if ( ! string . IsNullOrEmpty ( condition . MAINCODE ) )
{
sqlBuilder . Append ( " and M.MAINCODE=@MAINCODE " ) ; //'本体条码(产品条码)'
parameters . Add ( new DataParameter { ParameterName = "MAINCODE" , DataType = DbType . String , Value = condition . MAINCODE } ) ;
}
sqlBuilder . Append ( " UNION " ) ;
sqlBuilder . Append ( " SELECT P.PID " ) ;
sqlBuilder . Append ( " FROM T_AW_PRODUCT P " ) ;
sqlBuilder . Append ( " LEFT JOIN T_AW_MAINPRODUCT MNP ON MNP.PDID = P.PID " ) ;
sqlBuilder . Append ( " LEFT JOIN T_AW_MAIN M ON M.PID = MNP.MID WHERE 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( condition . PRODUCTCODE ) )
{
//产品条码
sqlBuilder . Append ( " and M.EPIDERMISCODE=@PRODUCTCODEB " ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCTCODEB" , DataType = DbType . String , Value = condition . PRODUCTCODE } ) ;
}
if ( ! string . IsNullOrEmpty ( condition . MAINCODE ) )
{
//产品条码
sqlBuilder . Append ( " and M.MAINCODE=@MAINCODE " ) ;
//parameters.Add(new DataParameter { ParameterName = "MAINCODE", DataType = DbType.String, Value = condition.MAINCODE });
}
sqlBuilder . Append ( " ) " ) ;
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetMainOperationReviewSqlw ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( " SELECT MP.*,C.USERNAME AS CREATEUSERNAME " ) ;
sqlBuilder . Append ( " FROM T_AW_MAINOPERATION MP " ) ;
sqlBuilder . Append ( " LEFT JOIN T_QM_USER C ON C.USERID=MP.CREATEUSER " ) ;
sqlBuilder . Append ( " WHERE MP.PDID IN( " ) ;
sqlBuilder . Append ( " SELECT M.PID " ) ;
sqlBuilder . Append ( " FROM T_AW_MAIN M where 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( condition . PRODUCTCODE ) )
{
//产品条码
sqlBuilder . Append ( " and M.EPIDERMISCODE=@PRODUCTCODEA " ) ; //'本体条码(产品条码)'
parameters . Add ( new DataParameter { ParameterName = "PRODUCTCODEA" , DataType = DbType . String , Value = condition . PRODUCTCODE } ) ;
}
if ( ! string . IsNullOrEmpty ( condition . MAINCODE ) )
{
sqlBuilder . Append ( " and M.MAINCODE=@MAINCODE " ) ; //'本体条码(产品条码)'
parameters . Add ( new DataParameter { ParameterName = "MAINCODE" , DataType = DbType . String , Value = condition . MAINCODE } ) ;
}
sqlBuilder . Append ( " UNION " ) ;
sqlBuilder . Append ( " SELECT P.PID " ) ;
sqlBuilder . Append ( " FROM T_AW_PRODUCT P " ) ;
sqlBuilder . Append ( " LEFT JOIN T_AW_MAINPRODUCT MNP ON MNP.PDID = P.PID " ) ;
sqlBuilder . Append ( " LEFT JOIN T_AW_MAIN M ON M.PID = MNP.MID where 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( condition . PRODUCTCODE ) )
{
//产品条码
sqlBuilder . Append ( " and M.EPIDERMISCODE=@PRODUCTCODEB " ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCTCODEB" , DataType = DbType . String , Value = condition . PRODUCTCODE } ) ;
}
if ( ! string . IsNullOrEmpty ( condition . MAINCODE ) )
{
sqlBuilder . Append ( " and M.MAINCODE=@MAINCODE " ) ;
}
sqlBuilder . Append ( " ) " ) ;
return sqlBuilder . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportDataForMOR ( MainOperation model )
{
DataTable dt = null ;
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
//构成查询语句
sql = this . GetMainOperationReviewSqlw ( model , ref parameters ) ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
dt . TableName = "T_AW_MAINOPERATION" ;
}
return dt ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public DataTable GetExportDataForMORNew ( MainOperation model )
{
DataTable dt = null ;
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
try
{
//构成查询语句
sql = "select * from T_AW_MAINOPERATION p where pdid in ( select PRODUCT_PID from T_QT_PRODUCT_STRUCTURE where PROCESS_CODE='" + model . PRODUCTCODE + "' )" ;
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
dt = session . GetTable ( sql , parameters . ToArray ( ) ) ;
dt . TableName = "T_AW_MAINOPERATION" ;
}
return dt ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#endregion
#region 插入设备加工信息
/// <summary>
/// 设备加工信息
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int MachineOperation ( OperationServiceParam model )
{
int count = 0 ;
try
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
try
{
session . OpenTs ( ) ;
//1. 判断主体表是否存在
if ( model . main ! = null )
count = session . Insert < Main > ( model . main ) ;
//2. 主体零件关系表
if ( model . mainProductList ! = null & & model . mainProductList . Count > 0 )
count = session . Insert < MainProduct > ( model . mainProductList ) ;
//3. 更新零件表
if ( model . productList ! = null & & model . productList . Count > 0 )
count = session . Update < Product > ( model . productList ) ;
//4. 插入记录表
count = session . Insert < MainOperation > ( model . mainOperation ) ;
session . CommitTs ( ) ;
}
catch ( Exception )
{
session . RollbackTs ( ) ;
throw ;
}
}
return count ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
#region 产量趋势统计
/// <summary>
/// 产量趋势统计
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List < MainOperation > GetListGroupBy ( MainOperation condition )
{
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
List < MainOperation > list = new List < MainOperation > ( ) ;
try
{
sql = this . GetQuerySqlForStatistics ( condition , ref parameters ) ;
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
list = session . GetList < MainOperation > ( sql , parameters . ToArray ( ) ) . ToList ( ) ;
}
return list ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
/// <summary>
/// 获取查询语句(带加工参数)
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySqlForStatistics ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @"SELECT COUNT(PRODUCTCODE) AS COUNTS,MACHINECODDE,MACHINENAME,PRODUCESHIFTTCODE,PRODUCESHIFTNAME FROM DBO.T_AW_MAINOPERATION " ) ;
if ( string . IsNullOrEmpty ( condition . MACHINECODDE ) = = false )
{
whereBuilder . Append ( " AND MACHINECODDE = @MACHINECODDE" ) ;
parameters . Add ( new DataParameter { ParameterName = "MACHINECODDE" , DataType = DbType . String , Value = condition . MACHINECODDE } ) ;
}
if ( string . IsNullOrEmpty ( condition . PRODUCESHIFTTCODE ) = = false )
{
whereBuilder . Append ( " AND PRODUCESHIFTTCODE = @PRODUCESHIFTTCODE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PRODUCESHIFTTCODE" , DataType = DbType . String , Value = condition . PRODUCESHIFTTCODE } ) ;
}
//查询条件物料号
if ( string . IsNullOrEmpty ( condition . MATERIAL_CODE ) = = false )
{
whereBuilder . Append ( " AND 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 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 . WORKCENTER_CODE ) = = false )
{
whereBuilder . Append ( " AND WORKCENTER_CODE = @WORKCENTER_CODE" ) ;
parameters . Add ( new DataParameter { ParameterName = "WORKCENTER_CODE" , DataType = DbType . String , Value = condition . WORKCENTER_CODE } ) ;
}
if ( string . IsNullOrEmpty ( condition . CreateDateStart ) = = false )
{
whereBuilder . Append ( " AND CREATEDATE >= @CreateDateStart" ) ;
parameters . Add ( new DataParameter { ParameterName = "CreateDateStart" , DataType = DbType . String , Value = condition . CreateDateStart } ) ;
}
if ( string . IsNullOrEmpty ( condition . CreateDateEnd ) = = false )
{
whereBuilder . Append ( " AND CREATEDATE <= @CreateDateEnd" ) ;
parameters . Add ( new DataParameter { ParameterName = "CreateDateEnd" , DataType = DbType . String , Value = condition . CreateDateEnd } ) ;
}
if ( whereBuilder . Length > 0 )
{
sqlBuilder . Append ( " WHERE " + whereBuilder . ToString ( ) . Substring ( 4 ) ) ;
}
return sqlBuilder . Append ( " GROUP BY MACHINECODDE,MACHINENAME,PRODUCESHIFTTCODE,PRODUCESHIFTNAME ORDER BY PRODUCESHIFTTCODE,MACHINECODDE" ) . ToString ( ) ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#region 合格率
/// <summary>
/// 合格率
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List < MainOperation > GetListGroupByStauts ( MainOperation condition )
{
string sql = null ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
List < MainOperation > list = new List < MainOperation > ( ) ;
try
{
sql = this . GetQuerySqlForStatusStatistics ( condition , ref parameters ) ;
//分页关键字段及排序
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
list = session . GetList < MainOperation > ( sql , parameters . ToArray ( ) ) . ToList ( ) ;
}
return list ;
}
catch ( Exception ex )
{
throw ex ;
}
}
#endregion
/// <summary>
/// 获取查询语句(带加工参数)
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySqlForStatusStatistics ( MainOperation condition , ref List < DataParameter > parameters )
{
StringBuilder sqlBuilder = new StringBuilder ( ) ;
StringBuilder whereBuilder = new StringBuilder ( ) ;
try
{
//构成查询语句
sqlBuilder . Append ( @ "SELECT A.PROCESSTYPE,
QUALIFIED = CASE WHEN A . [ STATUS ] = 0 THEN SUM ( 1 ) ELSE 0 END ,
REPAIR = CASE WHEN A . [ STATUS ] = 1 THEN SUM ( 1 ) ELSE 0 END ,
CANCEL = CASE WHEN A . [ STATUS ] = 2 THEN SUM ( 1 ) ELSE 0 END ,
B . PROCESSNAME PROCESSTYPETEXT FROM DBO . T_AW_MAINOPERATION A , DBO . T_BD_PROCESSINFO B WHERE A . PROCESSTYPE = B . PROCESSTYPE ");
if ( string . IsNullOrEmpty ( condition . PROCESSTYPE ) = = false )
{
sqlBuilder . Append ( " AND A.PROCESSTYPE = @PROCESSTYPE" ) ;
parameters . Add ( new DataParameter { ParameterName = "PROCESSTYPE" , DataType = DbType . String , Value = condition . PROCESSTYPE } ) ;
}
if ( string . IsNullOrEmpty ( condition . CreateDateStart ) = = false )
{
sqlBuilder . Append ( " AND A.CREATEDATE >= @CreateDateStart" ) ;
parameters . Add ( new DataParameter { ParameterName = "CreateDateStart" , DataType = DbType . String , Value = condition . CreateDateStart } ) ;
}
if ( string . IsNullOrEmpty ( condition . CreateDateEnd ) = = false )
{
sqlBuilder . Append ( " AND A.CREATEDATE <= @CreateDateEnd" ) ;
parameters . Add ( new DataParameter { ParameterName = "CreateDateEnd" , DataType = DbType . String , Value = condition . CreateDateEnd } ) ;
}
sqlBuilder . Append ( " GROUP BY A.PROCESSTYPE,[STATUS],B.PROCESSNAME " ) ;
string reString = "SELECT SUM(QUALIFIED) QUALIFIED,SUM(REPAIR) REPAIR,SUM(CANCEL) CANCEL,(SUM(REPAIR) + SUM(CANCEL)) UNQUALIFIED ,PROCESSTYPE,PROCESSTYPETEXT FROM ("
+ sqlBuilder . ToString ( )
+ ") T1 GROUP BY PROCESSTYPE,PROCESSTYPETEXT ORDER BY PROCESSTYPE" ;
return reString ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public int ReplaceBarcode ( string oldcode , string newcode )
{
try
{
int count = 0 ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
string sql = "UPDATE T_AW_MAINOPERATION SET PRODUCTCODE=@newcode WHERE PRODUCTCODE=@oldcode" ;
parameters . Add ( new DataParameter ( "newcode" , newcode ) ) ;
parameters . Add ( new DataParameter ( "oldcode" , oldcode ) ) ;
if ( this . BaseSession ! = null )
{
count = this . BaseSession . ExecuteSql ( sql , parameters . ToArray ( ) ) ;
}
else
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//更新基本信息
count = session . ExecuteSql ( sql , parameters . ToArray ( ) ) ;
}
}
return count ;
}
catch ( Exception ex )
{
throw ex ;
}
}
public int DPParamReplace ( string oldcode , string newcode )
{
try
{
int count = 0 ;
List < DataParameter > parameters = new List < DataParameter > ( ) ;
StringBuilder sql = new StringBuilder ( ) ;
sql . AppendLine ( "UPDATE [T_PA_4CA-WB0002] SET PRODUCTCODE=@newcode WHERE PRODUCTCODE=@oldcode" ) ;
sql . AppendLine ( "UPDATE [T_PA_4CA-WB0003] SET PRODUCTCODE=@newcode WHERE PRODUCTCODE=@oldcode" ) ;
sql . AppendLine ( "UPDATE [T_PA_4CA-WB0004] SET PRODUCTCODE=@newcode WHERE PRODUCTCODE=@oldcode" ) ;
sql . AppendLine ( "UPDATE [T_PA_4CA-WB0005] SET PRODUCTCODE=@newcode WHERE PRODUCTCODE=@oldcode" ) ;
parameters . Add ( new DataParameter ( "newcode" , newcode ) ) ;
parameters . Add ( new DataParameter ( "oldcode" , oldcode ) ) ;
if ( this . BaseSession ! = null )
{
count = this . BaseSession . ExecuteSql ( sql . ToString ( ) , parameters . ToArray ( ) ) ;
}
else
{
using ( IDataSession session = AppDataFactory . CreateMainSession ( ) )
{
//更新基本信息
count = session . ExecuteSql ( sql . ToString ( ) , parameters . ToArray ( ) ) ;
}
}
return count ;
}
catch ( Exception ex )
{
throw ex ;
}
}
}
}