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 DataTable GET_SCP_UNPAIED(V_SUPPLIERS_REGUALARLY p_entity) // { // StringBuilder _buffer = new StringBuilder(); //// SELECT VendId AS 供应商编码, VendName AS 供应商名称, Site AS 域, 税前金额, 税额, 税后金额 //// FROM(SELECT VendId, VendName, Site, SUM(ROUND(Qty * Price, 2)) AS 税前金额, SUM(ROUND(ROUND(Qty * Price, 2) //// * 0.13, 2)) AS 税额, SUM(ROUND(Qty * Price, 2)) + SUM(ROUND(ROUND(Qty * Price, 2) * 0.13, 2)) //// AS 税后金额 //// FROM dbo.V_TB_RECEIVE_LIST //// WHERE(State = 1) AND(Qty < 0) //// GROUP BY VendId, VendName, Site) AS a // } //public override DataTable GetPagedDataTable(int pageIndex, int pageSize) //{ // //SetWhere(); // //if (StrOrder == "") StrOrder = "UserType desc, UserName asc"; // int rowbegin = (pageIndex * pageSize) + 1; // int rowend = (pageIndex + 1) * pageSize; // return GetDataLimit(rowbegin, rowend, "", StrWhere + " and " + StrSearch, StrOrder); //} //public virtual DataTable GetDataLimit(int rows1, int rows2, string fields, string strwhere, string orderby,string p_tableview) //{ // var dbSetting = GlobalConfig.ScpDatabase; // try // { // if (fields == "") // { fields = "*"; } // string sql = @" // select {0} from ( // select ROW_NUMBER() over(order by {1}) as rows_number_9999999, {0} from {2} where {5} // ) as query_temp_table_9999999 where rows_number_9999999 between {3} and {4} and ({5}) // "; // object[] obj = new object[6]; // obj[0] = fields; // obj[1] = orderby; // obj[2] = p_tableview; // obj[3] = rows1; // obj[4] = rows2; // obj[5] = strwhere; // sql = string.Format(sql, obj); // DataTable dt = new DataTable(); // var strConn = EntitiesFactory.GetEfConnectionString(dbSetting); // SqlConnection conn = new System.Data.SqlClient.SqlConnection(); // conn.ConnectionString = strConn; // if (conn.State != ConnectionState.Open) // { // conn.Open(); // } // #region 结束时间范围 // SqlCommand cmd = new SqlCommand(); // cmd.Connection = conn; // cmd.CommandText = sql; // SqlDataAdapter adapter = new SqlDataAdapter(cmd); // adapter.Fill(dt); // return dt; // } // catch // { } //} 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 dic = new Dictionary(); StringBuilder _buffer = new StringBuilder(); for (int i = 1; i < 13; i++) { string _begin = string.Empty; string _end = string.Empty; if (i < 10) { _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 == 12) { _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 10: _month = "十月"; break; case 11: _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 _date = string.Empty; if (p_detail.BeginTime == null) { _date = string.Format(_sqlDate, DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")); } else { _date = 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 =_date; SqlDataAdapter adapter1 = new SqlDataAdapter(cmd1); adapter1.Fill(_tb1); List _ls = new List(); 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) { _ls.Add(string.Format("{0}", row["EndTime"].ToString())); } } else { _ls.Add(string.Format("{0}", row["EndTime"].ToString())); } } SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; string _sql = string.Format(sqlString,string.Join(",",_ls.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 _columnLs = new List(); 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 string GetASN_REC_REPORT(V_TB_ASK_DETAIL p_detail) { string sqlString = "SELECT a.PartCode,a.PoLine,a.AskBillNum,AskQty,isnull(sum(b.Qty),0) asnQty,isNull(SUM(c.Qty),0) as RecQty,a.PoBillNum FROM TB_ASK_DETAIL A\n" + "LEFT JOIN\n" + "\n" + "(select\n" + "TB_ASN_DETAIL.Qty,\n" + "TB_ASN.AsnBillNum,\n" + "TB_ASN.AskBillNum,\n" + "TB_ASN_DETAIL.PartCode,\n" + "TB_ASN_DETAIL.PoLine\n" + "from TB_ASN_DETAIL inner join TB_ASN on TB_ASN_DETAIL.AsnBillNum=tb_asn.AsnBillNum and TB_ASN.State<>-1) as\n" + " B on a.AskBillNum=b.AskBillNum and a.PartCode=b.PartCode and a.PoLine=b.PoLine\n" + "Left join\n" + "(\n" + "select\n" + "TB_RECEIVE_DETAIL.Qty,\n" + "TB_RECEIVE.AsnBillNum,\n" + "TB_RECEIVE_DETAIL.PartCode,\n" + "TB_RECEIVE_DETAIL.PoLine\n" + "from TB_RECEIVE_DETAIL inner join TB_RECEIVE on TB_RECEIVE_DETAIL.RecvBillNum=TB_RECEIVE.RecvBillNum and TB_RECEIVE.State<>-1) as\n" + "\n" + " C on B.AsnBillNum=C.AsnBillNum and B.PartCode=C.PartCode and B.PoLine=C.PoLine\n" + " where a.State<>-1 {0}" + "\n" + " GROUP BY a.PartCode,a.PoLine,a.AskBillNum,a.AskQty,a.PoBillNum"; if (!string.IsNullOrEmpty(p_detail.PartCode)) { } if (!string.IsNullOrEmpty(p_detail.VendId)) { } if (!string.IsNullOrEmpty(p_detail.AskBillNum)) { } if (!string.IsNullOrEmpty(p_detail.PoBillNum)) { } if (!string.IsNullOrEmpty(p_detail.PoBillNum)) { } return sqlString; } 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(); } /// /// 按零件编号获取及时率语句(沈阳) /// /// /// 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(" V_TB_ASN AS B on p.AskBillNum=b.AskBillNum LEFT OUTER JOIN dbo.V_TB_ARRIVE_DETAIL AS A ON b.AsnBillNum=A.AsnBillNum AND A.PoLine = p.PoLine AND A.PartCode = p.PartCode 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(); } /// /// 按供应商编号获取及时率语句(沈阳) /// /// /// 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>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string _sql = Get_V_SCP_FORECAST_REPORT_SQL(p_entity); IQueryable q = db.Database.SqlQuery(_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; } } /// /// 获取及时率数据 /// /// /// public static void Get_V_SCP_OTD_REPORT_List(int flag, SCP_OTD_EXPORT p_entity, Action>> p_action) { ResultObject> _ret = new ResultObject>(); 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 q = db.Database.SqlQuery(_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>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { var _sql = GET_SQE(p_entity); IQueryable q = db.Database.SqlQuery(_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_RECEIVE_List(TB_ASK_RECEIVE p_entity, Action>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { IQueryable 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 _ls=p_entity.PartCode.Split(new char[] { ',' }); q = q.Where(p =>_ls.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_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>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { IQueryable 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 _ls = p_entity.PartCode.Split(new char[] { ',' }); q = q.Where(p => _ls.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_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_V_TB_RECEIVE_INVOICE_List(V_TB_RECEIVE_INVOICE p_entity, Action>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string _sql =GET_V_TB_RECEIVE_INVOICE_SQL(p_entity); IQueryable q = db.Database.SqlQuery(_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>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string _sql = GET_V_SUPPLIERS_REGUALARLY_LIST_SQL(p_entity); IQueryable q = db.Database.SqlQuery(_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; } } /// /// 获取饼状图数据 /// /// /// public static void Get_V_Pie_Chart_List(V_Pie_Chart p_entity, Action>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string _sql = Get_V_Pie_Chart_List_SQL(p_entity); IQueryable q = db.Database.SqlQuery(_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; } } /// /// 获取曲线图数据 /// /// /// public static void Get_V_Line_Chart_List(V_Pie_Chart p_entity, Action>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string _sql = Get_V_Line_Chart_List_SQL(p_entity); IQueryable q = db.Database.SqlQuery(_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; } } /// /// 获取柱状图数据 /// /// /// public static void Get_V_Bar_Chart_List(V_Pie_Chart p_entity, Action>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string _sql = Get_V_bar_Chart_List_SQL(p_entity); IQueryable q = db.Database.SqlQuery(_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; } } /// /// 获取饼状图sql /// /// /// 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(); } /// /// 获取曲线图sql /// /// /// 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(); } /// /// 获取柱状图sql /// /// /// 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(); } } }