using System ;
using System.Collections.Generic ;
using System.Data.Entity.Migrations ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using CK.SCP.Models ;
using CK.SCP.Models.Enums ;
using CK.SCP.Models.ScpEntity ;
using CK.SCP.Utils ;
using System.Data.Entity.Core ;
using System.Web ;
using System.Data.SqlClient ;
using System.Data ;
using System.Text.RegularExpressions ;
namespace CK.SCP.Controller
{
public class SCP_REPORT_CONTROLLER
{
public static string GET_V_SUPPLIERS_REGUALARLY_LIST_SQL ( V_SUPPLIERS_REGUALARLY p_entity )
{
StringBuilder _ buffer = new StringBuilder ( ) ;
_ buffer . Append ( "SELECT temp2.Qty / temp1.ReciveSumQty AS Regularly, temp1.ReciveSumQty, temp2.PoBillNum, temp2.AsnBillNum, " ) ;
_ buffer . Append ( " temp2.PartCode, temp2.PartDesc1, temp2.Qty, temp2.AskQty, temp2.AskBillNum, temp2.ProjectId, temp2.PoLine, temp2.ShipTime,temp2.RecTime , " ) ;
_ buffer . Append ( " temp2.RecvBillNum ,temp2.Site ,temp2.Scope, temp2.ReceiveTimeScope " ) ;
_ buffer . Append ( "FROM(SELECT SUM(a.Qty) AS ReciveSumQty, a.PoLine, a.PoBillNum, C.AskBillNum, a.PartCode " ) ;
_ buffer . Append ( " FROM V_TB_RECEIVE_DETAIL AS a INNER JOIN " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL AS C ON a.AsnBillNum = C.AsnBillNum AND a.PartCode = C.PartCode AND " ) ;
_ buffer . Append ( " a.PoBillNum = C.PoBillNum AND a.PoLine = C.PoLine INNER JOIN " ) ;
_ buffer . Append ( " TB_ASN AS e ON a.AsnBillNum = e.AsnBillNum LEFT OUTER JOIN " ) ;
_ buffer . Append ( " V_TB_ASK_DETAIL AS B ON C.AskBillNum = B.AskBillNum AND B.PartCode = C.PartCode AND " ) ;
_ buffer . Append ( " B.PoBillNum = C.PoBillNum AND B.PoLine = C.PoLine " ) ;
_ buffer . AppendFormat ( "WHERE(a.IsDeleted = 0) AND(a.Site = '{0}') " , p_entity . Site ) ;
_ buffer . Append ( " GROUP BY a.PoLine, a.PoBillNum, C.AskBillNum, a.PartCode) AS temp1 INNER JOIN " ) ;
_ buffer . Append ( " (SELECT a.PoBillNum, a.AsnBillNum, a.PartCode, a.PartDesc1, a.Qty, B.AskQty, C.AskBillNum, f.ProjectId, a.PoLine,e.ShipTime,a.ShipTime as RecTime, " ) ;
_ buffer . Append ( " a.RecvBillNum, a.VendId, D.VendName ,a.site ,DATEDIFF(day, e.ShipTime, a.ShipTime) as Scope ,isnull(D.ReceiveTimeScope,0) as ReceiveTimeScope " ) ;
_ buffer . Append ( " FROM V_TB_RECEIVE_DETAIL AS a INNER JOIN " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL AS C ON a.AsnBillNum = C.AsnBillNum AND a.PartCode = C.PartCode AND " ) ;
_ buffer . Append ( " a.PoBillNum = C.PoBillNum AND a.PoLine = C.PoLine INNER JOIN " ) ;
_ buffer . Append ( " TB_ASN AS e ON a.AsnBillNum = e.AsnBillNum LEFT OUTER JOIN " ) ;
_ buffer . Append ( " V_TB_ASK_DETAIL AS B ON C.AskBillNum = B.AskBillNum AND B.PartCode = C.PartCode AND " ) ;
_ buffer . Append ( " B.PoBillNum = C.PoBillNum AND B.PoLine = C.PoLine LEFT OUTER JOIN " ) ;
_ buffer . Append ( " TA_VENDER AS D ON a.VendId = D.VendId LEFT OUTER JOIN " ) ;
_ buffer . Append ( " TA_PART AS f ON a.PartCode = f.PartCode INNER JOIN TA_VEND_PART as s on a.VendId=s.VendId and a.PartCode=s.PartCode and a.Site=s.Site " ) ;
_ buffer . Append ( " WHERE(DATEDIFF(day, DATEADD(day, ISNULL(D.ReceiveTimeScope, 0), e.ShipTime), a.ShipTime) < s.TransportationTime ) " ) ;
_ buffer . AppendFormat ( " AND(a.IsDeleted = 0) AND(a.Site = '{0}')) AS temp2 ON " , p_entity . Site ) ;
_ buffer . Append ( " temp1.AskBillNum = temp2.AskBillNum AND temp1.PoBillNum = temp2.PoBillNum AND " ) ;
_ buffer . Append ( " temp1.PartCode = temp2.PartCode AND temp1.PoLine = temp2.PoLine " ) ;
return _ buffer . ToString ( ) ;
}
public static DataTable Get_RECEIVE_YEAR ( V_TB_RECEIVE_DETAIL p_detail , string p_year )
{
string _ sql = "SELECT D.*,E.VENDNAME,F.PROJECTID FROM({0}) c pivot(sum(c.数量) for c.M in (一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月)) as d LEFT JOIN TA_VENDER E on D.vendid=E.VENDID AND D.SITE=E.SITE LEFT JOIN TA_PART F ON f.partcode =d.partcode and f.site=e.site where {1}" ;
string sqlString = "SELECT * FROM\n" +
"(\n" +
"SELECT SUM(qty)数量,PartCode,'{0}' AS M ,VendId,Site,PartDesc1,PoUnit\n" +
" FROM [V_TB_RECEIVE_DETAIL] where createtime between '{1}' and '{2}' and Site='{3}' group by PartCode,VendId,Site,PartDesc1,PoUnit) {4}" ;
Dictionary < string , string > dic = new Dictionary < string , string > ( ) ;
StringBuilder _ buffer = new StringBuilder ( ) ;
for ( int i = 1 ; i < 1 3 ; i + + )
{
string _ begin = string . Empty ;
string _ end = string . Empty ;
if ( i < 1 0 )
{
_ begin = p_year + "-" + "0" + i . ToString ( ) + "-" + "01" ;
_ end = DateTime . Parse ( _ begin ) . AddMonths ( 1 ) . AddDays ( - 1 ) . ToString ( "yyyy-MM-dd" ) ;
}
else
{
_ begin = p_year + "-" + i . ToString ( ) + "-" + "01" ;
_ end = DateTime . Parse ( _ begin ) . AddMonths ( 1 ) . AddDays ( - 1 ) . ToString ( "yyyy-MM-dd" ) ;
}
if ( i = = 1 2 )
{
_ buffer . AppendFormat ( sqlString , "十二月" , _ begin , _ end , p_detail . Site , "A" + i . ToString ( ) + "\r\n" ) ;
}
else
{
string _ month = string . Empty ;
switch ( i )
{
case 1 :
_ month = "一月" ;
break ;
case 2 :
_ month = "二月" ;
break ;
case 3 :
_ month = "三月" ;
break ;
case 4 :
_ month = "四月" ;
break ;
case 5 :
_ month = "五月" ;
break ;
case 6 :
_ month = "六月" ;
break ;
case 7 :
_ month = "七月" ;
break ;
case 8 :
_ month = "八月" ;
break ;
case 9 :
_ month = "九月" ;
break ;
case 1 0 :
_ month = "十月" ;
break ;
case 1 1 :
_ month = "十一月" ;
break ;
}
_ buffer . AppendFormat ( sqlString , _ month , _ begin , _ end , p_detail . Site , "A" + i . ToString ( ) + "\r\n UNION ALL \r\n" ) ;
}
}
string _ str = _ buffer . ToString ( ) ;
string where1 = " 1=1 " ;
if ( ! string . IsNullOrEmpty ( p_detail . PartCode ) )
{
where1 + = string . Format ( " and D.partcode='{0}' " , p_detail . PartCode ) ;
}
if ( ! string . IsNullOrEmpty ( p_detail . VendId ) )
{
where1 + = string . Format ( " and D.VendId='{0}' " , p_detail . VendId ) ;
}
if ( ! string . IsNullOrEmpty ( p_detail . ProjectId ) )
{
where1 + = string . Format ( " and ProjectId like '{0}%' " , p_detail . ProjectId ) ;
}
if ( ! string . IsNullOrEmpty ( p_detail . Site ) )
{
where1 + = string . Format ( " and D.SITE = '{0}' " , p_detail . Site ) ;
}
string _ sql1 = string . Format ( _ sql , _ str , where1 ) ;
DataTable dt = new DataTable ( ) ;
DataTable _ tbDate = new DataTable ( ) ;
var dbSetting = GlobalConfig . ScpDatabase ;
SqlConnection conn = new System . Data . SqlClient . SqlConnection ( ) ;
try
{
var strConn = EntitiesFactory . GetEfConnectionString ( dbSetting ) ;
conn . ConnectionString = strConn ;
if ( conn . State ! = ConnectionState . Open )
{
conn . Open ( ) ;
}
SqlCommand cmd = new SqlCommand ( ) ;
cmd . Connection = conn ;
cmd . CommandText = string . Format ( _ sql1 ) ;
SqlDataAdapter adapter = new SqlDataAdapter ( cmd ) ;
adapter . Fill ( dt ) ;
dt . Columns . Add ( "合计" ) ;
dt . Columns [ "PartCode" ] . ColumnName = "零件编号" ;
dt . Columns [ "VendId" ] . ColumnName = "供应商编号" ;
dt . Columns [ "VendName" ] . ColumnName = "供应商名称" ;
dt . Columns [ "PartDesc1" ] . ColumnName = "零件名称" ;
dt . Columns [ "Site" ] . ColumnName = "域" ;
dt . Columns [ "PoUnit" ] . ColumnName = "单位" ;
dt . Columns [ "Projectid" ] . ColumnName = "项目编号" ;
foreach ( DataRow row in dt . Rows )
{
decimal num = 0 ;
foreach ( DataColumn column in dt . Columns )
{
var _ reg = Regex . Match ( column . ColumnName , @"月" ) ;
if ( ! string . IsNullOrEmpty ( _ reg . Value ) )
{
if ( row [ column . ColumnName ] ! = null & & ! string . IsNullOrEmpty ( row [ column . ColumnName ] . ToString ( ) ) )
{
num + = decimal . Parse ( row [ column . ColumnName ] . ToString ( ) ) ;
}
}
}
row [ "合计" ] = num ;
}
}
catch
{ }
return dt ;
}
public static DataTable Get_PART_LIFE ( V_TB_PO_DETAIL p_detail )
{
DataTable dt = new DataTable ( ) ;
DataTable _ tbDate = new DataTable ( ) ;
string sqlString =
"SELECT * FROM (\n" +
"\n" +
"\n" +
" SELECT '计划' as A ,b.VENDNAME, c.* FROM\n" +
" (\n" +
" select po.projectid,po.partcode,po.PartDesc1,po.PoBillNum,po.PoLine,isnull(ASKQty,0) as Qty, CONVERT(varchar(100), ask.endTime, 23) as endtime,po.PoUnit,po.Site,po.VendId from V_TB_PO_DETAIL po left join\n" +
" V_TB_ASK_DETAIL ask on po.PoBillNum=ask.PoBillNum and po.PoLine=ask.PoLine and po.Site=ask.Site and po.PartCode=ask.PartCode {2}\n" +
" ) A\n" +
" pivot(sum(Qty) for a.endtime in ({0})\n" +
" ) as C left join TA_VENDER B ON C.VENDID=B.VENDID AND C.SITE=B.SITE LEFT JOIN TA_PART D ON C.PARTCODE=D.PARTCODE AND C.SITE=D.SITE where {1} ) P1" +
"\n UNION ALL \n" +
"SELECT * FROM (\n" +
"\n" +
"\n" +
" SELECT '已确认' as A ,b.VENDNAME, c.* FROM\n" +
" (\n" +
" select po.projectid, po.partcode,po.PartDesc1,po.PoBillNum,po.PoLine,isnull(ASKQty,0) as Qty, CONVERT(varchar(100), ask.UpdateTime, 23) as endtime,po.PoUnit,po.Site,po.VendId from V_TB_PO_DETAIL po left join\n" +
" V_TB_ASK_DETAIL ask on po.PoBillNum=ask.PoBillNum and po.PoLine=ask.PoLine and po.Site=ask.Site and po.PartCode=ask.PartCode {2}\n" +
" ) A\n" +
" pivot(sum(Qty) for a.endtime in ({0})\n" +
" ) as C left join TA_VENDER B ON C.VENDID=B.VENDID AND C.SITE=B.SITE LEFT JOIN TA_PART D ON C.PARTCODE=D.PARTCODE AND C.SITE=D.SITE where {1} ) P2" +
"\n UNION ALL\n" +
"SELECT * FROM (\n" +
"\n" +
"\n" +
" SELECT '已发货' as A ,b.VENDNAME, c.* FROM\n" +
" (\n" +
" select po.projectid, po.partcode,po.PartDesc1,po.PoBillNum,po.PoLine,isnull(asn.Qty,0) as qty, CONVERT(varchar(100), asn.CreateTime, 23) as endtime,po.PoUnit,po.Site,po.VendId from V_TB_PO_DETAIL po left join\n" +
" V_TB_ASN_DETAIL asn on po.PoBillNum=asn.PoBillNum and po.PoLine=asn.PoLine and po.Site=asn.Site and po.PartCode=asn.PartCode {2}\n" +
" ) A\n" +
" pivot(sum(Qty) for a.endtime in ( {0}\n" +
" )\n" +
" ) as C left join TA_VENDER B ON C.VENDID=B.VENDID AND C.SITE=B.SITE LEFT JOIN TA_PART D ON C.PARTCODE=D.PARTCODE AND C.SITE=D.SITE WHERE {1} ) P3" +
"\n" +
"UNION ALL\n" +
"SELECT * FROM (\n" +
"\n" +
"\n" +
" SELECT '已收货' as A ,b.VENDNAME, c.* FROM\n" +
" (\n" +
" select po.projectid, po.partcode,po.PartDesc1,po.PoBillNum,po.PoLine,isnull(rec.Qty,0) as qty, CONVERT(varchar(100), rec.CreateTime, 23) as endtime,po.PoUnit,po.Site,po.VendId from V_TB_PO_DETAIL po left join\n" +
" V_TB_RECEIVE_DETAIL rec on po.PoBillNum=rec.PoBillNum and po.PoLine=rec.PoLine and po.Site=rec.Site and po.PartCode=rec.PartCode and rec.qty>0 {2}\n" +
" ) A\n" +
" pivot(sum(Qty) for a.endtime in ( {0}\n" +
" )\n" +
" ) as C left join TA_VENDER B ON C.VENDID=B.VENDID AND C.SITE=B.SITE LEFT JOIN TA_PART D ON C.PARTCODE=D.PARTCODE AND C.SITE=D.SITE WHERE {1} ) P4" ;
string _ sqlDate = "select '[' + convert(varchar(10), DATEADD(day, number, CAST('{0}' as datetime)), 23) + ']' endtime\n" +
" from master.dbo.spt_values\n" +
" where type = 'p'\n" +
" AND number<= DATEDIFF(day, CAST('{0}' as datetime), DATEADD(DAY, -1, DATEADD(MM, DATEDIFF(MM, 0, CAST('{0}' as datetime)) +3, 0)))" ;
string _d ate = string . Empty ;
if ( p_detail . BeginTime = = null )
{
_d ate = string . Format ( _ sqlDate , DateTime . Now . AddMonths ( - 1 ) . ToString ( "yyyy-MM-dd" ) ) ;
}
else
{
_d ate = string . Format ( _ sqlDate , p_detail . BeginTime . Value . ToString ( "yyyy-MM-dd" ) ) ;
}
string _ where = " 1=1 " ;
_ where + = string . Format ( " And D.PartCode='{0}' " , p_detail . PartCode ) ;
var dbSetting = GlobalConfig . ScpDatabase ;
SqlConnection conn = new System . Data . SqlClient . SqlConnection ( ) ;
try
{
var strConn = EntitiesFactory . GetEfConnectionString ( dbSetting ) ;
conn . ConnectionString = strConn ;
if ( conn . State ! = ConnectionState . Open )
{
conn . Open ( ) ;
}
DataTable _ tb1 = new DataTable ( ) ;
SqlCommand cmd1 = new SqlCommand ( ) ;
cmd1 . Connection = conn ;
cmd1 . CommandText = _d ate ;
SqlDataAdapter adapter1 = new SqlDataAdapter ( cmd1 ) ;
adapter1 . Fill ( _ tb1 ) ;
List < string > _l s = new List < string > ( ) ;
foreach ( DataRow row in _ tb1 . Rows )
{
if ( p_detail . EndTime ! = null )
{
if ( DateTime . Parse ( row [ "EndTime" ] . ToString ( ) . Replace ( "[" , String . Empty ) . Replace ( "]" , String . Empty ) ) < = p_detail . EndTime . Value )
{
_l s . Add ( string . Format ( "{0}" , row [ "EndTime" ] . ToString ( ) ) ) ;
}
}
else
{
_l s . Add ( string . Format ( "{0}" , row [ "EndTime" ] . ToString ( ) ) ) ;
}
}
SqlCommand cmd = new SqlCommand ( ) ;
cmd . Connection = conn ;
string _ sql = string . Format ( sqlString , string . Join ( "," , _l s . ToArray ( ) ) , _ where , string . Format ( " where po.partcode='{0}' and po.pobillnum='{1}' and po.site='{2}'" , p_detail . PartCode , p_detail . PoBillNum , p_detail . Site ) ) ;
cmd . CommandText = string . Format ( _ sql ) ;
SqlDataAdapter adapter = new SqlDataAdapter ( cmd ) ;
adapter . Fill ( dt ) ;
if ( dt . Rows . Count > 0 )
{
var dr = dt . Rows [ 1 ] ;
var dr1 = dt . NewRow ( ) ;
dr1 [ "A" ] = "计划发货差额" ;
dr1 [ "ProjectId" ] = dr [ "ProjectId" ] ;
dr1 [ "VENDNAME" ] = dr [ "VENDNAME" ] ;
dr1 [ "partcode" ] = dr [ "partcode" ] ;
dr1 [ "PartDesc1" ] = dr [ "PartDesc1" ] ;
dr1 [ "PoBillNum" ] = dr [ "PoBillNum" ] ;
dr1 [ "PoLine" ] = dr [ "PoLine" ] ;
dr1 [ "PoUnit" ] = dr [ "PoUnit" ] ;
dr1 [ "Site" ] = dr [ "Site" ] ;
dr1 [ "VendId" ] = dr [ "VendId" ] ;
dt . Rows . Add ( dr1 ) ;
var dr2 = dt . NewRow ( ) ;
dr2 [ "A" ] = "计划收货差额" ;
dr2 [ "ProjectId" ] = dr [ "ProjectId" ] ;
dr2 [ "VENDNAME" ] = dr [ "VENDNAME" ] ;
dr2 [ "partcode" ] = dr [ "partcode" ] ;
dr2 [ "PartDesc1" ] = dr [ "PartDesc1" ] ;
dr2 [ "PoBillNum" ] = dr [ "PoBillNum" ] ;
dr2 [ "PoLine" ] = dr [ "PoLine" ] ;
dr2 [ "PoUnit" ] = dr [ "PoUnit" ] ;
dr2 [ "Site" ] = dr [ "Site" ] ;
dr2 [ "VendId" ] = dr [ "VendId" ] ;
dt . Rows . Add ( dr2 ) ;
}
foreach ( DataColumn column in dt . Columns )
{
var _ reg = Regex . Match ( column . ColumnName , @"\d{4}" ) . Value ;
if ( ! string . IsNullOrEmpty ( _ reg ) )
{
decimal _ planQty = 0 ;
decimal _ asnQty = 0 ;
decimal _ recQty = 0 ;
if ( dt . Rows [ 0 ] [ column . ColumnName ] ! = DBNull . Value )
{
_ planQty = decimal . Parse ( dt . Rows [ 0 ] [ column . ColumnName ] . ToString ( ) ) ;
}
if ( dt . Rows [ 2 ] [ column . ColumnName ] ! = DBNull . Value )
{
_ asnQty = decimal . Parse ( dt . Rows [ 2 ] [ column . ColumnName ] . ToString ( ) ) ;
}
if ( dt . Rows [ 3 ] [ column . ColumnName ] ! = DBNull . Value )
{
_ recQty = decimal . Parse ( dt . Rows [ 3 ] [ column . ColumnName ] . ToString ( ) ) ;
}
dt . Rows [ 4 ] [ column . ColumnName ] = _ planQty - _ asnQty ;
dt . Rows [ 5 ] [ column . ColumnName ] = _ planQty - _ recQty ;
}
}
dt . Columns . Add ( "合计" ) ;
foreach ( DataRow row in dt . Rows )
{
decimal num = 0 ;
foreach ( DataColumn column in dt . Columns )
{
var _ reg = Regex . Match ( column . ColumnName , @"\d{4}" ) ;
if ( ! string . IsNullOrEmpty ( _ reg . Value ) )
{
if ( row [ column . ColumnName ] ! = null & & ! string . IsNullOrEmpty ( row [ column . ColumnName ] . ToString ( ) ) )
{
num + = decimal . Parse ( row [ column . ColumnName ] . ToString ( ) ) ;
}
}
}
row [ "合计" ] = num ;
}
List < string > _ columnLs = new List < string > ( ) ;
foreach ( DataColumn column in dt . Columns )
{
var _ reg = Regex . Match ( column . ColumnName , @"\d{4}" ) ;
if ( ! string . IsNullOrEmpty ( _ reg . Value ) )
{
string _ sum = dt . Compute ( string . Format ( "sum([{0}])" , column . ColumnName ) , "true" ) . ToString ( ) ;
if ( _ sum = = "0" )
{
_ columnLs . Add ( column . ColumnName ) ;
}
}
}
foreach ( var itm in _ columnLs )
{
dt . Columns . Remove ( itm ) ;
}
//dt.Columns["VendID"].ColumnName = "供应商编码";
dt . Columns [ "PartCode" ] . ColumnName = "零件编码" ;
dt . Columns [ "PartDesc1" ] . ColumnName = "零件描述" ;
dt . Columns [ "PoUnit" ] . ColumnName = "单位" ;
dt . Columns [ "PoBillNum" ] . ColumnName = "订单编号" ;
dt . Columns [ "PoLine" ] . ColumnName = "行号" ;
dt . Columns [ "VendName" ] . ColumnName = "供应商名称" ;
dt . Columns [ "VendId" ] . ColumnName = "供应商编码" ;
dt . Columns [ "Site" ] . ColumnName = "域" ;
dt . Columns [ "A" ] . ColumnName = "状态" ;
dt . Columns [ "ProjectId" ] . ColumnName = "项目编码" ;
conn . Close ( ) ;
}
catch ( Exception ex )
{
conn . Close ( ) ;
throw ex ;
}
return dt ;
}
public static string GET_SQE ( V_TB_ASN_DETAIL p_entity )
{
StringBuilder _ buffer = new StringBuilder ( ) ;
_ buffer . Append ( "SELECT B.VendName,a.VendId ,b.FailQty, a.RecQty from " ) ;
_ buffer . Append ( " (select SUM(Qty) as RecQty,VendId from V_TB_RECEIVE_DETAIL " ) ;
_ buffer . Append ( " WHERE 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( p_entity . SQE_BeginTime ) )
{
_ buffer . AppendFormat ( " AND V_TB_RECEIVE_DETAIL.CreateTime>=CAST('{0}' as datetime) " , p_entity . SQE_BeginTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . SQE_EndTime ) )
{
_ buffer . AppendFormat ( " AND V_TB_RECEIVE_DETAIL.CreateTime<=CAST('{0}' as datetime) " , p_entity . SQE_EndTime ) ;
}
_ buffer . Append ( " group by VendId ) as A INNER JOIN" ) ;
_ buffer . Append ( " (select SUM(Failqty) as FailQty,V_TB_QUALITY.VendId,V_TB_QUALITY.VendName from V_TB_QUALITY " ) ;
_ buffer . Append ( " inner join V_TB_RECEIVE " ) ;
_ buffer . Append ( " on V_TB_RECEIVE.AsnBillNum=V_TB_QUALITY.By1 " ) ;
_ buffer . AppendFormat ( " WHERE 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( p_entity . SQE_BeginTime ) )
{
_ buffer . AppendFormat ( " AND V_TB_RECEIVE.CreateTime>=CAST('{0}' as datetime) " , p_entity . SQE_BeginTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . SQE_EndTime ) )
{
_ buffer . AppendFormat ( " AND V_TB_RECEIVE.CreateTime<=CAST('{0}' as datetime) " , p_entity . SQE_EndTime ) ;
}
_ buffer . Append ( " group by V_TB_QUALITY.VendId, V_TB_QUALITY.VendName " ) ;
_ buffer . Append ( " ) as B ON A.VendId=B.Vendid " ) ;
return _ buffer . ToString ( ) ;
}
public static string GET_V_TB_RECEIVE_INVOICE_SQL ( V_TB_RECEIVE_INVOICE p_entity )
{
StringBuilder _ builder = new StringBuilder ( ) ;
_ builder . Append ( " SELECT A.UID, A.RecvBillNum, A.PoLine, A.PartCode, A.Batch, A.Qty, A.DockCode, A.Remark, A.CreateTime, A.CreateUser, " ) ;
_ builder . Append ( " A.IsDeleted, A.GUID, A.AsnBillNum, A.Site, A.VendId, A.ShipTime, A.OperName, A.PartDesc1, A.State, A.PoBillNum, " ) ;
_ builder . Append ( " B.VendName, B.Site_Desc, isnull(p.Price,0) as Price, p.Currency, A.Unit, A.VendBatch, A.PoUnit, A.LocUnit, A.BillType_DESC, " ) ;
_ builder . Append ( " B.State_DESC, p.BeginTime,SUM(isnull(C.Qty,0)) as InvQty,an.AskBillNum " ) ;
_ builder . Append ( " FROM dbo.V_TB_RECEIVE_DETAIL AS A LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_RECEIVE AS B ON A.RecvBillNum = B.RecvBillNum LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_PO_DETAIL AS p ON A.PoBillNum = p.PoBillNum AND A.PoLine = p.PoLine AND A.PartCode = p.PartCode " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " left join V_TB_INVOICE_DETAIL C " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " ON A.PoBillNum = c.PoBillNum AND A.PoLine = C.PoLineNum AND A.PartCode = C.PartCode AND C.RecvBillNum = A.RecvBillNum " ) ;
_ builder . Append ( " inner join TB_PO po on a.PoBillNum = po.PoBillNum " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " inner join V_TB_ASN an on a.AsnBillNum = an.AsnBillNum " ) ;
_ builder . Append ( " where po.ModType = 1 and (C.IsDeleted = 0 or C.IsDeleted IS NULL) AND aN.IsDeleted = 0 " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " group by " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " A.UID, A.RecvBillNum, A.PoLine, A.PartCode, A.Batch, A.Qty, A.DockCode, A.Remark, A.CreateTime, A.CreateUser, " ) ;
_ builder . Append ( " A.IsDeleted, A.GUID, A.AsnBillNum, A.Site, A.VendId, A.ShipTime, A.OperName, A.PartDesc1, A.State, A.PoBillNum, " ) ;
_ builder . Append ( " B.VendName, B.Site_Desc, p.Price, p.Currency, A.Unit, A.VendBatch, A.PoUnit, A.LocUnit, A.BillType_DESC, " ) ;
_ builder . Append ( " B.State_DESC, p.BeginTime,an.AskBillNum " ) ;
_ builder . Append ( " union all " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " SELECT A.UID, A.RecvBillNum, A.PoLine, A.PartCode, A.Batch, A.Qty, A.DockCode, A.Remark, A.CreateTime, A.CreateUser, " ) ;
_ builder . Append ( " A.IsDeleted, A.GUID, A.AsnBillNum, A.Site, A.VendId, A.ShipTime, A.OperName, A.PartDesc1, A.State, A.PoBillNum, " ) ;
_ builder . Append ( " B.VendName, B.Site_Desc, p.Price, p.Currency, A.Unit, A.VendBatch, A.PoUnit, A.LocUnit, A.BillType_DESC, " ) ;
_ builder . Append ( " B.State_DESC, p.BeginTime,SUM(isnull(C.Qty,0)) as InvQty,ak.AskBillNum " ) ;
_ builder . Append ( " FROM dbo.V_TB_RECEIVE_DETAIL AS A LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_RECEIVE AS B ON A.RecvBillNum = B.RecvBillNum LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_PO_DETAIL AS p ON A.PoBillNum = p.PoBillNum AND A.PoLine = p.PoLine AND A.PartCode = p.PartCode " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " left join V_TB_INVOICE_DETAIL C " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " ON A.PoBillNum = c.PoBillNum AND A.PoLine = C.PoLineNum AND A.PartCode = C.PartCode AND C.RecvBillNum = A.RecvBillNum " ) ;
_ builder . Append ( " inner join TB_PO po on a.PoBillNum = po.PoBillNum " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " inner join V_TB_ASK ak on a.PoBillNum = ak.PoBillNum " ) ;
_ builder . Append ( " where po.ModType = 2 and (C.IsDeleted = 0 or C.IsDeleted IS NULL) AND ak.IsDeleted = 0 " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " group by " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " A.UID, A.RecvBillNum, A.PoLine, A.PartCode, A.Batch, A.Qty, A.DockCode, A.Remark, A.CreateTime, A.CreateUser, " ) ;
_ builder . Append ( " A.IsDeleted, A.GUID, A.AsnBillNum, A.Site, A.VendId, A.ShipTime, A.OperName, A.PartDesc1, A.State, A.PoBillNum, " ) ;
_ builder . Append ( " B.VendName, B.Site_Desc, p.Price, p.Currency, A.Unit, A.VendBatch, A.PoUnit, A.LocUnit, A.BillType_DESC, " ) ;
_ builder . Append ( " B.State_DESC, p.BeginTime,ak.AskBillNum " ) ;
return _ builder . ToString ( ) ;
}
public static string GetV_TIMELY_DELIVERY_SQL ( V_TIMELY_DELIVERY p_entity )
{
StringBuilder _ builder = new StringBuilder ( ) ;
_ builder . Append ( " SELECT AskQty, ReduceQty, Qty, s1.AskBillNum, PoBillNum, s1.PoLine, s1.PartCode, Number, PartDesc1, GUID, IsDeleted, BeginTime, EndTime, UID, ValidityDays, Site, VendId,DATEDIFF(day, s2.RecvTime, EndTime) AS ReviceDelayDay, RecvTime ,VendName ,s2.ReviceQty " ) ;
_ builder . Append ( " FROM(SELECT A.AskQty, ISNULL(A.ReduceQty, 0) AS ReduceQty, SUM(CASE WHEN b.State >= 3 THEN b.Qty ELSE 0 END) " ) ;
_ builder . Append ( " AS Qty, A.AskBillNum, A.PoBillNum, A.PoLine, A.PartCode, A.AskQty - ISNULL(A.ReduceQty, 0) " ) ;
_ builder . Append ( " - SUM(CASE WHEN b.State >= 3 THEN b.Qty ELSE 0 END) AS Number, A.PartDesc1, A.CreateTime, " ) ;
_ builder . Append ( " A.CreateUser, A.UpdateTime, A.UpdateUser, A.UpdateInfo, A.GUID, A.IsDeleted, A.BeginTime, A.EndTime, " ) ;
_ builder . Append ( " A.UID, DATEDIFF(day, DATEADD(day, A.ValidityDays, ISNULL(MAX(B.UpdateTime), GETDATE())), A.EndTime) " ) ;
_ builder . Append ( " AS ValidityDays, A.Site, A.VendId ,a.VendName " ) ;
_ builder . Append ( " FROM dbo.V_TB_ASK_DETAIL AS A LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_ASN_DETAIL AS B ON A.AskBillNum = B.AskBillNum AND A.PoLine = B.PoLine AND " ) ;
_ builder . Append ( " A.PartCode = B.PartCode " ) ;
_ builder . Append ( " left join TB_PO p on a.PoBillNum=p.PoBillNum " ) ;
_ builder . Append ( " WHERE(A.IsDeleted = 0) AND(A.State > 1) and p.ModType=1 " ) ;
//if (p_entity.BeginTime != null)
//{
// _builder.AppendFormat("AND a.BeginTime>=CAST('{0}' as datetime)", p_entity.BeginTime.Value.ToString());
//}
//if (p_entity.EndTime != null)
//{
// _builder.AppendFormat("AND a.BeginTime<=CAST('{0}' as datetime)", p_entity.EndTime.Value.ToString());
//}
//if (!string.IsNullOrEmpty(p_entity.PoBillNum))
//{
// _builder.AppendFormat("AND a.PoBillNum='{0}'",p_entity.PoBillNum);
//}
//if (!string.IsNullOrEmpty(p_entity.AskBillNum))
//{
// _builder.AppendFormat("AND a.AskBillNum='{0}'", p_entity.AskBillNum);
//}
_ builder . Append ( " GROUP BY A.AskBillNum, A.PoBillNum, A.PoLine, A.PartCode, A.AskQty, A.ReduceQty, A.PartDesc1, A.CreateTime, " ) ;
_ builder . Append ( " A.CreateUser, A.UpdateTime, A.UpdateUser, A.UpdateInfo, A.GUID, A.BeginTime, A.EndTime, A.IsDeleted, " ) ;
_ builder . Append ( " A.UID, A.ValidityDays, A.Site, A.VendId,a.VendName) AS s1 " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " left join " ) ;
_ builder . Append ( " (SELECT rd.PoLine, rd.PartCode, sum(rd.qty) AS ReviceQty, ad.AskBillNum,max(rd.ShipTime) as RecvTime FROM V_TB_RECEIVE_DETAIL rd inner join V_TB_ASN_DETAIL ad on rd.AsnBillNum=ad.AsnBillNum " ) ;
_ builder . Append ( " and rd.PoLine= ad.PoLine and rd.PartCode= ad.PartCode AND RD.Site= ad.Site " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " group by rd.PoLine, rd.PartCode, ad.AskBillNum) as s2 " ) ;
_ builder . Append ( " on s1.AskBillNum=s2.AskBillNum and s1.PartCode=s2.PartCode and s1.PoLine=s2.PoLine " ) ;
_ builder . Append ( " union all " ) ;
_ builder . Append ( " SELECT AskQty, ReduceQty, Qty, s1.AskBillNum, PoBillNum, s1.PoLine, s1.PartCode, Number, PartDesc1, GUID, IsDeleted, BeginTime, EndTime, UID, ValidityDays, Site, VendId,DATEDIFF(day, s2.RecvTime, EndTime) AS ReviceDelayDay, RecvTime,VendName ,s2.ReviceQty " ) ;
_ builder . Append ( " FROM(SELECT A.AskQty, ISNULL(A.ReduceQty, 0) AS ReduceQty, SUM(CASE WHEN b.State >= 3 THEN b.Qty ELSE 0 END) " ) ;
_ builder . Append ( " AS Qty, A.AskBillNum, A.PoBillNum, A.PoLine, A.PartCode, A.AskQty - ISNULL(A.ReduceQty, 0) " ) ;
_ builder . Append ( " - SUM(CASE WHEN b.State >= 3 THEN b.Qty ELSE 0 END) AS Number, A.PartDesc1, A.CreateTime, " ) ;
_ builder . Append ( " A.CreateUser, A.UpdateTime, A.UpdateUser, A.UpdateInfo, A.GUID, A.IsDeleted, A.BeginTime, A.EndTime, " ) ;
_ builder . Append ( " A.UID, DATEDIFF(day, DATEADD(day, A.ValidityDays, ISNULL(MAX(B.UpdateTime), GETDATE())), A.EndTime) " ) ;
_ builder . Append ( " AS ValidityDays, A.Site, A.VendId ,a.VendName " ) ;
_ builder . Append ( " FROM dbo.V_TB_ASK_DETAIL AS A LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_ASN_DETAIL AS B ON A.AskBillNum = B.AskBillNum AND A.PoLine = B.PoLine AND " ) ;
_ builder . Append ( " A.PartCode = B.PartCode " ) ;
_ builder . Append ( " left join TB_PO p on a.PoBillNum=p.PoBillNum " ) ;
_ builder . Append ( " WHERE(A.IsDeleted = 0) AND(A.State > 1) and p.ModType=2 " ) ;
//if (p_entity.BeginTime != null)
//{
// _builder.AppendFormat("AND A.BeginTime>=CAST('{0}' as datetime)", p_entity.BeginTime.Value.ToString());
//}
//if (p_entity.EndTime != null)
//{
// _builder.AppendFormat("AND A.BeginTime<=CAST('{0}' as datetime)", p_entity.EndTime.Value.ToString());
//}
//if (!string.IsNullOrEmpty(p_entity.PoBillNum))
//{
// _builder.AppendFormat("AND a.PoBillNum='{0}'", p_entity.PoBillNum);
//}
//if (!string.IsNullOrEmpty(p_entity.AskBillNum))
//{
// _builder.AppendFormat("AND a.AskBillNum='{0}'", p_entity.AskBillNum);
//}
_ builder . Append ( " GROUP BY A.AskBillNum, A.PoBillNum, A.PoLine, A.PartCode, A.AskQty, A.ReduceQty, A.PartDesc1, A.CreateTime, " ) ;
_ builder . Append ( " A.CreateUser, A.UpdateTime, A.UpdateUser, A.UpdateInfo, A.GUID, A.BeginTime, A.EndTime, A.IsDeleted, " ) ;
_ builder . Append ( " A.UID, A.ValidityDays, A.Site, A.VendId,a.VendName) AS s1 " ) ;
_ builder . Append ( " " ) ;
_ builder . Append ( " left join " ) ;
_ builder . Append ( " (SELECT ad.PoLine, ad.PartCode, sum(rd.qty) AS ReviceQty, ad.AskBillNum,max(rd.ShipTime) as RecvTime FROM V_TB_ASK_DETAIL ad inner join V_TB_RECEIVE_DETAIL rd on rd.PoBillNum=ad.PoBillNum " ) ;
_ builder . Append ( " and rd.PoLine= ad.PoLine and rd.PartCode= ad.PartCode " ) ;
_ builder . Append ( " where ad.State>=3 and rd.BillType_DESC='收货单'" ) ;
_ builder . Append ( " group by ad.PoLine, ad.PartCode, ad.AskBillNum) as s2" ) ;
_ builder . Append ( " on s1.AskBillNum=s2.AskBillNum and s1.PartCode=s2.PartCode and s1.PoLine=s2.PoLine" ) ;
return _ builder . ToString ( ) ;
}
public static string Get_V_SCP_FORECAST_REPORT_SQL ( V_FORECAST_REPORT p_entity )
{
StringBuilder _ builder = new StringBuilder ( ) ;
_ builder . Append ( " select B.PartCode,B.VendId,B.AskQty,B.Month, ISNULL(c.MonthQty1,0) as MonthQty1 ,ISNULL(c.MonthQty2,0) as MonthQty2 ,ISNULL(c.MonthQty3,0) as MonthQty3 from ( " ) ;
_ builder . Append ( " (selecT PartCode,VendId ,MONTH(BeginTime) as Month,sum(AskQty) as AskQty from V_TB_ASK_DETAIL A " ) ;
_ builder . Append ( " where A.IsDeleted=0 group by A.PartCode,A.VendId ,MONTH(A.BeginTime)) B LEFT OUTER JOIN " ) ;
_ builder . Append ( " TB_FORECAST c on B.PartCode=c.PartCode and B.VendId=c.VendId and b.Month=c.Month and c.IsDeleted=0 and c.State=1 ) where 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
_ builder . AppendFormat ( " And B.PartCode='{0}'" , p_entity . PartCode ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
_ builder . AppendFormat ( " And B.VendId='{0}'" , p_entity . VendId ) ;
}
if ( p_entity . Month ! = 0 )
{
_ builder . AppendFormat ( " And B.Month='{0}'" , p_entity . Month ) ;
}
return _ builder . ToString ( ) ;
}
/// <summary>
/// 按零件编号获取及时率语句(沈阳)
/// </summary>
/// <param name="p_entity"></param>
/// <returns></returns>
public static string Get_V_SCP_OTD_REPORT_SQL ( SCP_OTD_EXPORT p_entity )
{
StringBuilder _ builder = new StringBuilder ( ) ;
_ builder . Append ( " select h.Site, h.AskBillNum,h.EndTime, h.VendId, h.PartCode ,sum (h.Qty) as ArriveQty , AskQty ,(AskQty -sum (h.Qty)) as Qty ,sum(h.NntimelyQty) as NntimelyQty , " ) ;
_ builder . Append ( " (CASE WHEN AskQty=0 Then 0 ELSE (sum (NntimelyQty)/AskQty) END) as OTD ,( CASE WHEN AskQty=0 Then 0 ELSE (sum (h.Qty)/AskQty) END ) AS ArriveOTD from ( SELECT p.Site, p.VendId, p.AskBillNum, p.PartCode, ISNULL(A.Qty,0) as Qty, " ) ;
_ builder . Append ( " (p.AskQty- ISNULL(p.ReduceQty,0)) as AskQty , (CASE WHEN DATEDIFF(day, A.ShipTime, p.EndTime) >= -1 THEN A.Qty ELSE 0 END) as NntimelyQty ,a.ShipTime ,p.EndTime FROM dbo.V_TB_ASK_DETAIL AS p LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_ARRIVE_DETAIL AS A ON A.Remark = p.AskBillNum AND A.PoLine = p.PoLine AND A.PartCode = p.PartCode LEFT OUTER JOIN dbo.V_TB_ARRIVE AS B ON A.ArrvBillNum = B.ArrvBillNum where p.IsDeleted=0 " ) ;
if ( p_entity . BeginTime ! = null )
{
_ builder . AppendFormat ( " AND p.EndTime>='{0}'" , p_entity . BeginTime ) ;
}
if ( p_entity . EndTime ! = null )
{
_ builder . AppendFormat ( " AND p.EndTime<='{0}' " , p_entity . EndTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
_ builder . AppendFormat ( " AND p.PartCode='{0}'" , p_entity . PartCode ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
_ builder . AppendFormat ( " AND p.VendId='{0}'" , p_entity . VendId ) ;
}
_ builder . Append ( ") as h group by h.PartCode ,h.VendId ,h.AskBillNum,h.EndTime,h.Site,h.AskQty" ) ;
return _ builder . ToString ( ) ;
}
/// <summary>
/// 按供应商编号获取及时率语句(沈阳)
/// </summary>
/// <param name="p_entity"></param>
/// <returns></returns>
public static string Get_V_SCP_OTD_REPORT_SQL_VendId ( SCP_OTD_EXPORT p_entity )
{
StringBuilder _ builder = new StringBuilder ( ) ;
_ builder . Append ( " select h.AskBillNum ,h.EndTime, h.Site, h.VendId ,sum (h.Qty) as ArriveQty , AskQty ,(AskQty -sum (h.Qty)) as Qty ,sum(h.NntimelyQty) as NntimelyQty , " ) ;
_ builder . Append ( " (CASE WHEN AskQty=0 Then 0 ELSE (sum (NntimelyQty)/AskQty) END) as OTD , ( CASE WHEN AskQty=0 Then 0 ELSE (sum (h.Qty)/AskQty) END)AS ArriveOTD from ( SELECT p.Site,p.VendId, p.AskBillNum, ISNULL(A.Qty,0) as Qty, " ) ;
_ builder . Append ( " (p.AskQty- ISNULL(p.ReduceQty,0)) as AskQty , (CASE WHEN DATEDIFF(day, A.ShipTime, p.EndTime) >= -1 THEN A.Qty ELSE 0 END) as NntimelyQty ,a.ShipTime ,p.EndTime FROM dbo.V_TB_ASK_DETAIL AS p LEFT OUTER JOIN " ) ;
_ builder . Append ( " dbo.V_TB_ARRIVE_DETAIL AS A ON A.Remark = p.AskBillNum AND A.PoLine = p.PoLine AND A.PartCode = p.PartCode LEFT OUTER JOIN dbo.V_TB_ARRIVE AS B ON A.ArrvBillNum = B.ArrvBillNum where p.IsDeleted=0 " ) ;
if ( p_entity . BeginTime ! = null )
{
_ builder . AppendFormat ( " AND p.EndTime>='{0}'" , p_entity . BeginTime ) ;
}
if ( p_entity . EndTime ! = null )
{
_ builder . AppendFormat ( " AND p.EndTime<='{0}' " , p_entity . EndTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
_ builder . AppendFormat ( " AND p.VendId='{0}'" , p_entity . VendId ) ;
}
_ builder . Append ( ") as h group by h.VendId,h.Site,h.AskQty,h.AskBillNum,h.EndTime" ) ;
return _ builder . ToString ( ) ;
}
public static void Get_V_SCP_FORECAST_REPORT_List ( V_FORECAST_REPORT p_entity , Action < ResultObject < IQueryable < V_FORECAST_REPORT > > > p_action )
{
ResultObject < IQueryable < V_FORECAST_REPORT > > _ ret = new ResultObject < IQueryable < V_FORECAST_REPORT > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = Get_V_SCP_FORECAST_REPORT_SQL ( p_entity ) ;
IQueryable < V_FORECAST_REPORT > q = db . Database . SqlQuery < V_FORECAST_REPORT > ( _ sql ) . AsQueryable ( ) ;
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_FORECAST_REPORT_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_FORECAST_REPORT_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_FORECAST_REPORT_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_FORECAST_REPORT_List" , e . Message ) ;
throw e ;
}
}
/// <summary>
/// 获取及时率数据
/// </summary>
/// <param name="p_entity"></param>
/// <param name="p_action"></param>
public static void Get_V_SCP_OTD_REPORT_List ( int flag , SCP_OTD_EXPORT p_entity , Action < ResultObject < IQueryable < SCP_OTD_EXPORT > > > p_action )
{
ResultObject < IQueryable < SCP_OTD_EXPORT > > _ ret = new ResultObject < IQueryable < SCP_OTD_EXPORT > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = "" ;
if ( flag = = 1 )
{
_ sql = Get_V_SCP_OTD_REPORT_SQL ( p_entity ) ;
}
else
{
_ sql = Get_V_SCP_OTD_REPORT_SQL_VendId ( p_entity ) ;
}
IQueryable < SCP_OTD_EXPORT > q = db . Database . SqlQuery < SCP_OTD_EXPORT > ( _ sql ) . AsQueryable ( ) ;
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_OTD_REPORT_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_OTD_REPORT_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_OTD_REPORT_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SCP_OTD_REPORT_List" , e . Message ) ;
throw e ;
}
}
public static void Get_SQE ( V_TB_ASN_DETAIL p_entity , Action < ResultObject < IQueryable < SCP_TB_SQE > > > p_action )
{
ResultObject < IQueryable < SCP_TB_SQE > > _ ret = new ResultObject < IQueryable < SCP_TB_SQE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _ sql = GET_SQE ( p_entity ) ;
IQueryable < SCP_TB_SQE > q = db . Database . SqlQuery < SCP_TB_SQE > ( _ sql ) . AsQueryable ( ) ;
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_SQE" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_SQE" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_SQE" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_SQE" , e . Message ) ;
throw e ;
}
}
public static void Get_V_TB_ASK_ASN_View_List1 ( V_TB_REEEE p_entity , Action < ResultObject < IQueryable < V_TB_REEEE > > > p_action )
{
ResultObject < IQueryable < V_TB_REEEE > > _ ret = new ResultObject < IQueryable < V_TB_REEEE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_REEEE > q = db . V_TB_REEEE ;
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum = = p_entity . PoBillNum ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Get_V_TB_ASK_ASN_View_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Get_V_TB_ASK_ASN_View_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Get_V_TB_ASK_ASN_View_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Get_V_TB_ASK_ASN_View_List" , e . Message ) ;
throw e ;
}
}
public static void Get_V_TB_ASK_RECEIVE_List ( TB_ASK_RECEIVE p_entity , Action < ResultObject < IQueryable < TB_ASK_RECEIVE > > > p_action )
{
ResultObject < IQueryable < TB_ASK_RECEIVE > > _ ret = new ResultObject < IQueryable < TB_ASK_RECEIVE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < TB_ASK_RECEIVE > q = db . TB_ASK_RECEIVE ;
if ( p_entity . RecvBeginTime ! = null )
{
q = q . Where ( p = > p . RecvTime > = p_entity . RecvBeginTime ) ;
}
if ( p_entity . RecvEndTime ! = null )
{
q = q . Where ( p = > p . RecvTime < = p_entity . RecvEndTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AskBillNum ) )
{
q = q . Where ( p = > p . AskBillNum . Contains ( p_entity . AskBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
var _l s = p_entity . PartCode . Split ( new char [ ] { ',' } ) ;
q = q . Where ( p = > _l s . Contains ( p . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ProjectId ) )
{
q = q . Where ( p = > p . ProjectId . Contains ( p_entity . ProjectId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site = = p_entity . Site ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Buyer ) )
{
q = q . Where ( p = > p . Buyer = = p_entity . Buyer ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( p_entity . State ! = null )
{
switch ( p_entity . State )
{
case 0 :
q = q . Where ( p = > p . AskQty > 0 & & p . Qty = = 0 & & p . ReviceQty = = 0 ) ;
break ;
case 1 :
q = q . Where ( p = > p . AskQty > 0 & & p . Qty > 0 & & p . ReviceQty = = 0 ) ;
break ;
case 2 :
q = q . Where ( p = > p . AskQty = = p . ReviceQty ) ;
break ;
case 3 :
q = q . Where ( p = > p . ReviceQty > 0 & & p . AskQty > p . ReviceQty ) ;
break ;
}
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_ASK_RECEIVE_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_ASK_RECEIVE_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_ASK_RECEIVE_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_ASK_RECEIVE_List" , e . Message ) ;
throw e ;
}
}
public static void Get_V_TIMELY_DELIVERY_List ( V_TIMELY_DELIVERY p_entity , Action < ResultObject < IQueryable < V_TIMELY_DELIVERY > > > p_action )
{
ResultObject < IQueryable < V_TIMELY_DELIVERY > > _ ret = new ResultObject < IQueryable < V_TIMELY_DELIVERY > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = GetV_TIMELY_DELIVERY_SQL ( p_entity ) ;
IQueryable < V_TIMELY_DELIVERY > q = db . Database . SqlQuery < V_TIMELY_DELIVERY > ( _ sql ) . AsQueryable ( ) ;
if ( p_entity . RecvBeginTime ! = null )
{
q = q . Where ( p = > p . RecvTime > = p_entity . RecvBeginTime ) ;
}
if ( p_entity . RecvEndTime ! = null )
{
q = q . Where ( p = > p . RecvTime < = p_entity . RecvEndTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
var _l s = p_entity . PartCode . Split ( new char [ ] { ',' } ) ;
q = q . Where ( p = > _l s . Contains ( p . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p . PartDesc1 ) ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TIMELY_DELIVERY_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TIMELY_DELIVERY_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TIMELY_DELIVERY_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TIMELY_DELIVERY_List" , e . Message ) ;
throw e ;
}
}
public static void Get_TB_ASK_UNCOMPLETE_List ( TB_UNCOMPLETE_TEMPASK p_entity , Action < ResultObject < IQueryable < TB_UNCOMPLETE_TEMPASK > > > p_action )
{
ResultObject < IQueryable < TB_UNCOMPLETE_TEMPASK > > _ ret = new ResultObject < IQueryable < TB_UNCOMPLETE_TEMPASK > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < TB_UNCOMPLETE_TEMPASK > q = db . TB_UNCOMPLETE_TEMPASK ;
if ( p_entity . RecvBeginTime ! = null )
{
q = q . Where ( p = > p . RecvTime > = p_entity . RecvBeginTime ) ;
}
if ( p_entity . EndTime ! = null )
{
q = q . Where ( p = > p . EndTime . Value . Year = = p_entity . EndTime . Value . Year ) ;
}
if ( p_entity . RecvEndTime ! = null )
{
q = q . Where ( p = > p . RecvTime < = p_entity . RecvEndTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AskBillNum ) )
{
q = q . Where ( p = > p . AskBillNum . Contains ( p_entity . AskBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
var _l s = p_entity . PartCode . Split ( new char [ ] { ',' } ) ;
q = q . Where ( p = > _l s . Contains ( p . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ProjectId ) )
{
q = q . Where ( p = > p . ProjectId . Contains ( p_entity . ProjectId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site = = p_entity . Site ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Buyer ) )
{
q = q . Where ( p = > p . Buyer = = p_entity . Buyer ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( p_entity . State ! = null )
{
switch ( p_entity . State )
{
case 0 :
q = q . Where ( p = > p . AskQty > 0 & & p . Qty = = 0 & & p . ReviceQty = = 0 ) ;
break ;
case 1 :
q = q . Where ( p = > p . AskQty > 0 & & p . Qty > 0 & & p . ReviceQty = = 0 ) ;
break ;
case 2 :
q = q . Where ( p = > p . AskQty = = p . ReviceQty ) ;
break ;
case 3 :
q = q . Where ( p = > p . ReviceQty > 0 & & p . AskQty > p . ReviceQty ) ;
break ;
}
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_TB_ASK_UNCOMPLETE_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_TB_ASK_UNCOMPLETE_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_TB_ASK_UNCOMPLETE_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_TB_ASK_UNCOMPLETE_List" , e . Message ) ;
throw e ;
}
}
public static void Get_V_TB_RECEIVE_INVOICE_List ( V_TB_RECEIVE_INVOICE p_entity , Action < ResultObject < IQueryable < V_TB_RECEIVE_INVOICE > > > p_action )
{
ResultObject < IQueryable < V_TB_RECEIVE_INVOICE > > _ ret = new ResultObject < IQueryable < V_TB_RECEIVE_INVOICE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = GET_V_TB_RECEIVE_INVOICE_SQL ( p_entity ) ;
IQueryable < V_TB_RECEIVE_INVOICE > q = db . Database . SqlQuery < V_TB_RECEIVE_INVOICE > ( _ sql ) . AsQueryable ( ) ;
if ( ! string . IsNullOrEmpty ( p_entity . RecvBillNum ) )
{
q = q . Where ( p = > p . RecvBillNum . Contains ( p_entity . RecvBillNum ) ) ;
}
if ( p_entity . PoLine ! = 0 )
{
q = q . Where ( p = > p . PoLine = = p_entity . PoLine ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
q = q . Where ( p = > p . PartCode . Contains ( p_entity . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Batch ) )
{
q = q . Where ( p = > p . Batch . Contains ( p_entity . Batch ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum = = p_entity . AsnBillNum ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site = = p_entity . Site ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum = = p_entity . PoBillNum ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AskBillNum ) )
{
q = q . Where ( p = > p . AskBillNum = = p_entity . AskBillNum ) ;
}
if ( p_entity . UserInAddress ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInAddress . Contains ( p . Site ) ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_RECEIVE_INVOICE_LisT" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_RECEIVE_INVOICE_LisT" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_RECEIVE_INVOICE_LisT" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_TB_RECEIVE_INVOICE_LisT" , e . Message ) ;
throw e ;
}
}
public static void Get_V_SUPPLIERS_REGUALARLY_List ( V_SUPPLIERS_REGUALARLY p_entity , Action < ResultObject < IQueryable < V_SUPPLIERS_REGUALARLY > > > p_action )
{
ResultObject < IQueryable < V_SUPPLIERS_REGUALARLY > > _ ret = new ResultObject < IQueryable < V_SUPPLIERS_REGUALARLY > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = GET_V_SUPPLIERS_REGUALARLY_LIST_SQL ( p_entity ) ;
IQueryable < V_SUPPLIERS_REGUALARLY > q = db . Database . SqlQuery < V_SUPPLIERS_REGUALARLY > ( _ sql ) . AsQueryable ( ) ;
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId . Contains ( p_entity . VendId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
q = q . Where ( p = > p . PartCode . Contains ( p_entity . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( p_entity . Qty ! = 0 )
{
q = q . Where ( p = > p . Qty = = p_entity . Qty ) ;
}
if ( p_entity . AskQty ! = null )
{
q = q . Where ( p = > p . AskQty = = p_entity . AskQty ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AskBillNum ) )
{
q = q . Where ( p = > p . AskBillNum . Contains ( p_entity . AskBillNum ) ) ;
}
if ( p_entity . PoLine ! = 0 )
{
q = q . Where ( p = > p . PoLine = = p_entity . PoLine ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . RecvBillNum ) )
{
q = q . Where ( p = > p . RecvBillNum . Contains ( p_entity . RecvBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ProjectId ) )
{
q = q . Where ( p = > p . ProjectId . Contains ( p_entity . ProjectId ) ) ;
}
if ( p_entity . UserInAddress ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInAddress . Contains ( p . Site ) ) ;
}
if ( p_entity . UserInVendIds ! = null & & p_entity . UserInVendIds . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInVendIds . Contains ( p . VendId ) ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( V_SUPPLIERS_REGUALARLY ) , "Get_V_SUPPLIERS_REGUALARLY_List" , e . Message ) ;
throw e ;
}
}
/// <summary>
/// 获取饼状图数据
/// </summary>
/// <param name="p_entity"></param>
/// <param name="p_action"></param>
public static void Get_V_Pie_Chart_List ( V_Pie_Chart p_entity , Action < ResultObject < IQueryable < V_Pie_Chart > > > p_action )
{
ResultObject < IQueryable < V_Pie_Chart > > _ ret = new ResultObject < IQueryable < V_Pie_Chart > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = Get_V_Pie_Chart_List_SQL ( p_entity ) ;
IQueryable < V_Pie_Chart > q = db . Database . SqlQuery < V_Pie_Chart > ( _ sql ) . AsQueryable ( ) ;
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( p_entity . UserInAddress ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInAddress . Contains ( p . Site ) ) ;
}
if ( p_entity . UserInVendIds ! = null & & p_entity . UserInVendIds . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInVendIds . Contains ( p . VendId ) ) ;
}
//if (p_entity.BeginTime != null)
//{
// q = q.Where(p => Convert.ToDateTime(p.RecTime) >= p_entity.BeginTime);
//}
//if (p_entity.EndTime != null)
//{
// q = q.Where(p => Convert.ToDateTime(p.RecTime) <= p_entity.EndTime);
//}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_Pie_Chart_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_Pie_Chart_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_Pie_Chart_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( V_SUPPLIERS_REGUALARLY ) , "Get_V_Pie_Chart_List" , e . Message ) ;
throw e ;
}
}
/// <summary>
/// 获取曲线图数据
/// </summary>
/// <param name="p_entity"></param>
/// <param name="p_action"></param>
public static void Get_V_Line_Chart_List ( V_Pie_Chart p_entity , Action < ResultObject < IQueryable < V_Pie_Chart > > > p_action )
{
ResultObject < IQueryable < V_Pie_Chart > > _ ret = new ResultObject < IQueryable < V_Pie_Chart > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = Get_V_Line_Chart_List_SQL ( p_entity ) ;
IQueryable < V_Pie_Chart > q = db . Database . SqlQuery < V_Pie_Chart > ( _ sql ) . AsQueryable ( ) ;
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( p_entity . UserInAddress ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInAddress . Contains ( p . Site ) ) ;
}
if ( p_entity . UserInVendIds ! = null & & p_entity . UserInVendIds . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInVendIds . Contains ( p . VendId ) ) ;
}
//if (p_entity.BeginTime != null)
//{
// q = q.Where(p => Convert.ToDateTime(p.RecTime) >= p_entity.BeginTime);
//}
//if (p_entity.EndTime != null)
//{
// q = q.Where(p => Convert.ToDateTime(p.RecTime) <= p_entity.EndTime);
//}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( V_SUPPLIERS_REGUALARLY ) , "Get_V_SUPPLIERS_REGUALARLY_List" , e . Message ) ;
throw e ;
}
}
/// <summary>
/// 获取柱状图数据
/// </summary>
/// <param name="p_entity"></param>
/// <param name="p_action"></param>
public static void Get_V_Bar_Chart_List ( V_Pie_Chart p_entity , Action < ResultObject < IQueryable < V_Pie_Chart > > > p_action )
{
ResultObject < IQueryable < V_Pie_Chart > > _ ret = new ResultObject < IQueryable < V_Pie_Chart > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string _ sql = Get_V_bar_Chart_List_SQL ( p_entity ) ;
IQueryable < V_Pie_Chart > q = db . Database . SqlQuery < V_Pie_Chart > ( _ sql ) . AsQueryable ( ) ;
if ( ! string . IsNullOrEmpty ( p_entity . ProjectId ) )
{
q = q . Where ( p = > p . ProjectId = = p_entity . ProjectId ) ;
}
if ( p_entity . UserInAddress ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInAddress . Contains ( p . Site ) ) ;
}
//if (p_entity.BeginTime != null)
//{
// q = q.Where(p => Convert.ToDateTime(p.RecTime) >= p_entity.BeginTime);
//}
//if (p_entity.EndTime != null)
//{
// q = q.Where(p => Convert.ToDateTime(p.RecTime) <= p_entity.EndTime);
//}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_SUPPLIERS_REGUALARLY_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( V_SUPPLIERS_REGUALARLY ) , "Get_V_SUPPLIERS_REGUALARLY_List" , e . Message ) ;
throw e ;
}
}
/// <summary>
/// 获取饼状图sql
/// </summary>
/// <param name="p_entity"></param>
/// <returns></returns>
public static string Get_V_Pie_Chart_List_SQL ( V_Pie_Chart p_entity )
{
StringBuilder _ buffer = new StringBuilder ( ) ;
_ buffer . Append ( " SELECT V_TB_RECEIVE_DETAIL.Site, V_TB_ASN_DETAIL_VIEW.ShipUser, V_TB_ASN_DETAIL_VIEW.ReceiveUser, V_TB_ASN_DETAIL_VIEW.VendId, V_TB_ASN_DETAIL_VIEW.VendName, CONVERT(varchar(100)," ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_VIEW.ShipTime, 23) AS ShipTime, CONVERT(varchar(100), V_TB_RECEIVE_DETAIL.ShipTime, 23) AS RecTime, V_TB_ASN_DETAIL_VIEW.Qty, (CASE WHEN DATEDIFF(day, V_TB_ASN_DETAIL_View.ShipTime, " ) ;
_ buffer . Append ( " V_TB_RECEIVE_DETAIL.ShipTime) >= TA_VEND_PART.TransportationTime THEN 0 ELSE 1 END) AS Flag FROM V_TB_ASN_DETAIL_VIEW INNER JOIN " ) ;
_ buffer . Append ( " V_TB_RECEIVE_DETAIL ON V_TB_ASN_DETAIL_VIEW.PartCode = V_TB_RECEIVE_DETAIL.PartCode AND V_TB_ASN_DETAIL_VIEW.PoLine = V_TB_RECEIVE_DETAIL.PoLine AND " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_VIEW.AsnBillNum = V_TB_RECEIVE_DETAIL.AsnBillNum INNER JOIN TA_VEND_PART ON V_TB_ASN_DETAIL_VIEW.VendId = TA_VEND_PART.VendId AND " ) ;
_ buffer . AppendFormat ( " V_TB_ASN_DETAIL_VIEW.PartCode = TA_VEND_PART.PartCode AND V_TB_ASN_DETAIL_VIEW.Site = TA_VEND_PART.Site WHERE (V_TB_ASN_DETAIL_VIEW.IsDeleted = 0) and (V_TB_RECEIVE_DETAIL.ShipTime>='{0}') and (V_TB_RECEIVE_DETAIL.ShipTime<='{1}') " , p_entity . BeginTime , p_entity . EndTime ) ;
return _ buffer . ToString ( ) ;
}
/// <summary>
/// 获取曲线图sql
/// </summary>
/// <param name="p_entity"></param>
/// <returns></returns>
public static string Get_V_Line_Chart_List_SQL ( V_Pie_Chart p_entity )
{
StringBuilder _ buffer = new StringBuilder ( ) ;
_ buffer . Append ( " select temp.Site,temp.VendId,temp.VendName ,RecTime ,temp.flag , sum(temp.Qty) as Qty from (select V_TB_RECEIVE_DETAIL.Site, V_TB_ASN_DETAIL_View.ShipUser,V_TB_ASN_DETAIL_View.ReceiveUser, V_TB_ASN_DETAIL_View.VendId ," ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_View.VendName,CONVERT(varchar(100), V_TB_ASN_DETAIL_View.ShipTime, 23) as ShipTime,CONVERT(varchar(100), V_TB_RECEIVE_DETAIL.ShipTime, 23) as RecTime, " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_View.Qty,(case when DATEDIFF(day ,V_TB_ASN_DETAIL_View.ShipTime,V_TB_RECEIVE_DETAIL.ShipTime )>=TA_VEND_PART.TransportationTime then 0 else 1 end) as flag" ) ;
_ buffer . Append ( " from V_TB_ASN_DETAIL_View JOIN [dbo].[V_TB_RECEIVE_DETAIL] on V_TB_ASN_DETAIL_View.PartCode=V_TB_RECEIVE_DETAIL.PartCode and V_TB_ASN_DETAIL_View.PoLine=V_TB_RECEIVE_DETAIL.PoLine and V_TB_ASN_DETAIL_View.AsnBillNum=V_TB_RECEIVE_DETAIL.AsnBillNum " ) ;
_ buffer . Append ( " JOIN TA_VEND_PART on V_TB_ASN_DETAIL_View.VendId=TA_VEND_PART.VendId and V_TB_ASN_DETAIL_View.PartCode=TA_VEND_PART.PartCode and V_TB_ASN_DETAIL_View.Site=TA_VEND_PART.Site" ) ;
_ buffer . AppendFormat ( " where V_TB_ASN_DETAIL_View.IsDeleted=0 and V_TB_RECEIVE_DETAIL.ShipTime>='{0}' and V_TB_RECEIVE_DETAIL.ShipTime<='{1}' ) temp group by temp.Site,temp.VendId,temp.VendName ,RecTime ,temp.flag" , p_entity . BeginTime , p_entity . EndTime ) ;
return _ buffer . ToString ( ) ;
}
/// <summary>
/// 获取柱状图sql
/// </summary>
/// <param name="p_entity"></param>
/// <returns></returns>
public static string Get_V_bar_Chart_List_SQL ( V_Pie_Chart p_entity )
{
StringBuilder _ buffer = new StringBuilder ( ) ;
_ buffer . Append ( "SELECT Site, ProjectId, RecTime, flag, SUM(Qty) AS Qty" ) ;
_ buffer . Append ( " FROM (SELECT TA_PART.PartCode, TA_PART.ProjectId, V_TB_RECEIVE_DETAIL.Site, V_TB_ASN_DETAIL_VIEW.ShipUser, " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_VIEW.ReceiveUser, V_TB_ASN_DETAIL_VIEW.VendId, " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_VIEW.VendName, CONVERT(varchar(100), V_TB_ASN_DETAIL_VIEW.ShipTime, 23) " ) ;
_ buffer . Append ( " AS ShipTime, CONVERT(varchar(100), V_TB_RECEIVE_DETAIL.ShipTime, 23) AS RecTime," ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_VIEW.Qty, (CASE WHEN DATEDIFF(day, V_TB_ASN_DETAIL_View.ShipTime, " ) ;
_ buffer . Append ( " V_TB_RECEIVE_DETAIL.ShipTime) >= TA_VEND_PART.TransportationTime THEN 0 ELSE 1 END) AS flag" ) ;
_ buffer . Append ( " FROM V_TB_ASN_DETAIL_VIEW INNER JOIN V_TB_RECEIVE_DETAIL ON V_TB_ASN_DETAIL_VIEW.PartCode = V_TB_RECEIVE_DETAIL.PartCode AND " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_VIEW.PoLine = V_TB_RECEIVE_DETAIL.PoLine AND V_TB_ASN_DETAIL_VIEW.AsnBillNum = V_TB_RECEIVE_DETAIL.AsnBillNum INNER JOIN" ) ;
_ buffer . Append ( " TA_VEND_PART ON V_TB_ASN_DETAIL_VIEW.VendId = TA_VEND_PART.VendId AND V_TB_ASN_DETAIL_VIEW.PartCode = TA_VEND_PART.PartCode AND " ) ;
_ buffer . Append ( " V_TB_ASN_DETAIL_VIEW.Site = TA_VEND_PART.Site INNER JOIN TA_PART ON TA_PART.PartCode = TA_VEND_PART.PartCode" ) ;
_ buffer . AppendFormat ( " WHERE (V_TB_ASN_DETAIL_VIEW.IsDeleted = 0) and (V_TB_RECEIVE_DETAIL.ShipTime>='{0}') and (V_TB_RECEIVE_DETAIL.ShipTime<='{1}') ) AS temp " , p_entity . BeginTime , p_entity . EndTime ) ;
_ buffer . Append ( " GROUP BY Site, ProjectId, RecTime, flag" ) ;
return _ buffer . ToString ( ) ;
}
public static void Get_V_ARRIVE_PO_REPORT ( V_ARRIVE_PO_REPORT p_entity , Action < ResultObject < IQueryable < V_ARRIVE_PO_REPORT > > > p_action )
{
ResultObject < IQueryable < V_ARRIVE_PO_REPORT > > _ ret = new ResultObject < IQueryable < V_ARRIVE_PO_REPORT > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_ARRIVE_PO_REPORT > q = db . V_ARRIVE_PO_REPORT ;
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
q = q . Where ( p = > p . PartCode . Contains ( p_entity . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( p_entity . BeginTime ! = null )
{
q = q . Where ( p = > p . BeginTime > = p_entity . BeginTime ) ;
}
if ( p_entity . BeginTimeEnd ! = null )
{
q = q . Where ( p = > p . BeginTime < = p_entity . BeginTimeEnd ) ;
}
if ( p_entity . ShipTime ! = null )
{
q = q . Where ( p = > p . ShipTime > = p_entity . ShipTime ) ;
}
if ( p_entity . ShipTimeEnd ! = null )
{
q = q . Where ( p = > p . ShipTime < = p_entity . ShipTimeEnd ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_ARRIVE_PO_REPORT" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_ARRIVE_PO_REPORT" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_ARRIVE_PO_REPORT" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_REPORT_CONTROLLER ) , "Get_V_ARRIVE_PO_REPORT" , e . Message ) ;
throw e ;
}
}
}
}