You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1577 lines
94 KiB

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 CK.SCP.Models.ScpEntity.ExcelExportEnttity;
using System.Text.RegularExpressions;
namespace CK.SCP.Controller
{
public class SCP_REPORT_CONTROLLER
{
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 _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 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)
//{
// 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] = TableName;
// obj[3] = rows1;
// obj[4] = rows2;
// obj[5] = strwhere;
// sql = string.Format(sql, obj);
// return db.Exec_DataSet(sql).Tables[0];
//}
public static void Get_SCP_PO_REPORT(List<string> p_list, Action<ResultObject<DataSet>> p_action)
{
ResultObject<DataSet> _ret = new ResultObject<DataSet>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
DataSet _ds = new DataSet();
List<SCP_PO_REPORT> _ls = new List<SCP_PO_REPORT>();
SCP_PO_REPORT _report = new SCP_PO_REPORT();
var _askList=db.V_TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
if (_askList.Count>0)
{
var _ask=_askList.FirstOrDefault();
var _poList= _askList.Select(p => p.PoBillNum).Distinct().ToList();
_report.AuditTime = _ask.UpdateTime.Value.ToShortDateString();
_report.Auditor = _ask.UpdateUser;
_report.FactoryName = _ask.Site_Desc;
_report.ContectPhone = _ask.BuyerPhone;
_report.MaterialPlanner = _ask.Buyer;
_report.VendName = _ask.VendName;
_report.VendId = _ask.VendId;
_report.AskBillNum = string.Join(",", p_list.ToArray());
_report.PoBillNum = string.Join(",", _poList.ToArray());
var _first = db.TA_VENDER.Where(p => p.VendId == _ask.VendId).FirstOrDefault();
if (_first != null)
{
_report.VendPhone =_first.Phone;
}
_ls.Add(_report);
List<SCP_PO_REPORT_DETAIL> _detailList = new List<SCP_PO_REPORT_DETAIL>();
var _askDetailList = db.V_TB_ASK_DETAIL.Where(p => p_list.Contains(p.AskBillNum)).OrderBy(p => p.PartCode).ThenBy(p => p.EndTime).ToList();
decimal _sum = 0;
foreach (var itm in _askDetailList)
{
SCP_PO_REPORT_DETAIL _detail = new SCP_PO_REPORT_DETAIL();
_detail.PartCode = itm.PartCode;
_detail.PartDesc1 = (string.IsNullOrEmpty(itm.PartDesc1) ? string.Empty : itm.PartDesc2) + (string.IsNullOrEmpty(itm.PartDesc1) ? string.Empty : itm.PartDesc1);
_detail.PoUnit = itm.PoUnit;
_detail.AskQty = itm.AskQty;
_detail.PoBillNum = itm.PoBillNum;
_detail.PoLine = itm.PoLine;
_detail.Price = itm.Price;
_detail.BeginTime = itm.BeginTime.Value;
_detail.EndTime = (itm.EndTime != null) ? itm.EndTime.Value : itm.BeginTime.Value;
decimal _subTotal = Math.Round(itm.Price * itm.AskQty,2);
_detail.SubTotal = _subTotal.ToString();
_sum += _subTotal;
_detailList.Add(_detail);
}
_report.TotalPrice = Math.Round(_sum, 2).ToString();
var dt = ConvertHelper.ToDataTable(_ls);
_ds.Tables.Add(dt);
var _dt1 = ConvertHelper.ToDataTable(_detailList);
_ds.Tables.Add(_dt1);
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = _ds;
p_action(_ret);
}
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Get_V_TB_ASK_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Get_V_TB_ASK_List", e.Message);
throw e;
}
}
public static DataTable Get_RECEIVE_YEAR(V_TB_RECEIVE_DETAIL p_detail, string p_year ,int p_state=1)
{
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 LEFT JOIN TA_PART F ON f.partcode =d.partcode where {1}";
string sqlString = string.Empty;
if (p_state == 1)
{
sqlString = "SELECT * FROM\n" +
"(\n" +
"SELECT SUM(qty)数量,PartCode,'{0}' AS M ,VendId,SubSite,PartDesc1,PoUnit\n" +
" FROM [V_TB_ARRIVE_DETAIL] where createtime between '{1}' and '{2}' and [BillType_DESC]='到货单' group by PartCode,VendId,SubSite,PartDesc1,PoUnit) {4}";
}
if (p_state == 2)
{
sqlString = "SELECT * FROM\n" +
"(\n" +
"SELECT SUM(qty)数量,PartCode,'{0}' AS M ,VendId,SubSite,PartDesc1,PoUnit\n" +
" FROM [V_TB_ARRIVE_DETAIL] where createtime between '{1}' and '{2}' and [BillType_DESC]='退货单' group by PartCode,VendId,SubSite,PartDesc1,PoUnit) {4}";
}
Dictionary<string, string> dic = new Dictionary<string, string>();
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.SubSite))
{
where1 += string.Format(" and D.SubSite = '{0}' ", p_detail.SubSite);
}
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["SubSite"].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 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 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, 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,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 and RD.SubSite= ad.SubSite ");
_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 and rd.Site=ad.Site and rd.SubSite=ad.SubSite ");
_builder.AppendFormat(" where ad.State>=3 and rd.site='{0}'",p_entity.Site);
_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.PartCode ,sum (h.Qty) as ArriveQty , SUM(AskQty) as AskQty ,(SUM(AskQty) -sum (h.Qty)) as Qty ,sum(h.NntimelyQty) as NntimelyQty , ");
_builder.Append(" (CASE WHEN sum(Qty)=0 Then 0 ELSE (sum (NntimelyQty)/sum(Qty)) END) as OTD , sum (h.Qty)/sum(AskQty) AS ArriveOTD from ( SELECT p.AskBillNum, p.PartCode, ISNULL(A.Qty,0) as Qty, ");
_builder.Append(" p.AskQty, (CASE WHEN DATEDIFF(day, A.ShipTime, p.EndTime) > 0 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 ");
if (p_entity.BeginTime != null)
{
_builder.AppendFormat(" where 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);
}
_builder.Append(") as h group by h.PartCode");
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.VendId ,sum (h.Qty) as ArriveQty , SUM(AskQty) as AskQty ,(SUM(AskQty) -sum (h.Qty)) as Qty ,sum(h.NntimelyQty) as NntimelyQty , ");
_builder.Append(" (CASE WHEN sum(Qty)=0 Then 0 ELSE (sum (NntimelyQty)/sum(Qty)) END) as OTD , sum (h.Qty)/sum(AskQty) AS ArriveOTD from ( SELECT p.VendId, p.AskBillNum, ISNULL(A.Qty,0) as Qty, ");
_builder.Append(" p.AskQty, (CASE WHEN DATEDIFF(day, A.ShipTime, p.EndTime) > 0 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 ");
if (p_entity.BeginTime != null)
{
_builder.AppendFormat(" where 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.VendId='{0}'", p_entity.VendId);
}
_builder.Append(") as h group by h.VendId");
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_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 _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.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_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}' and V_TB_RECEIVE_DETAIL.VendId='{2}' ) temp group by temp.Site,temp.VendId,temp.VendName ,RecTime ,temp.flag", p_entity.BeginTime, p_entity.EndTime ,p_entity.VendId);
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}') and ( TA_PART.ProjectId='{2}') ) AS temp ", p_entity.BeginTime,p_entity.EndTime,p_entity.ProjectId);
_buffer.Append(" GROUP BY Site, ProjectId, RecTime, flag");
return _buffer.ToString();
}
}
}