天津投入产出系统后端
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.
 
 
 
 
 
 

356 lines
14 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.FJC.Entity.SendManage;
using System.Data;
using QMAPP.FJC.Entity.Operation;
namespace QMAPP.FJC.DAL.SendManage
{
/// <summary>
/// 模块编号:
/// 作 用:
/// 作 者:
/// 编写日期:
///</summary>
public class SendPlanRecordDAL
{
#region 获取数据
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(PastCard condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
page.KeyName = "PID";
page.SortExpression = "CREATETIME DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<PastCard>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "贴车单查询数据层-获取列表!"
});
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
public string GetQuerySql(PastCard condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT M.PID");
sqlBuilder.AppendLine(",M.PASTECARDNO");
sqlBuilder.AppendLine(",M.PASTECARDDATE");
sqlBuilder.AppendLine(",M.OPERATOR");
sqlBuilder.AppendLine(",M.VINLACK");
sqlBuilder.AppendLine(",M.FLAGDEL");
sqlBuilder.AppendLine(",M.PLANTNAME");
sqlBuilder.AppendLine(",M.CREATETIME");
sqlBuilder.AppendLine(",C.WORKCENTER_CODE");
sqlBuilder.AppendLine(",C.WORKCENTER_NAME");
sqlBuilder.Append(" FROM T_PP_PASTECARD M ");
sqlBuilder.Append(" left join T_MD_WORKCENTER C on C.WORKCENTER_CODE = M.PLANTNAME ");
//2018-9-18闫永刚注释
//whereBuilder.Append(" AND CREATETIME in (select max(CREATETIME) from T_PP_PASTECARD group by PASTECARDNO) ");
//查询条件
if (string.IsNullOrEmpty(condition.PASTECARDNO) == false)
{
whereBuilder.Append(" AND M.PASTECARDNO = @PASTECARDNO ");
parameters.Add(new DataParameter { ParameterName = "PASTECARDNO", DataType = DbType.String, Value = condition.PASTECARDNO });
}
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
{
whereBuilder.Append(" AND M.PLANTNAME LIKE @WORKCENTER_CODE ");
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
whereBuilder.Append(" AND M.FLAGDEL = '0' ");
//时间
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND M.PASTECARDDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND M.PASTECARDDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取详细信息查询语句
/// <summary>
/// 获取详细信息查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
public string GetQuerySqls(PastCard condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.FISDETAILID ");
sqlBuilder.AppendLine(" ,M.PASTECARDID ");
sqlBuilder.AppendLine(" ,M.SANBARCODE ");
sqlBuilder.AppendLine(" ,M.SCANDATE ");
sqlBuilder.AppendLine(" ,M.FLAGDEL ");
sqlBuilder.AppendLine(" ,F.KIN ");
sqlBuilder.AppendLine(" ,F.VIN ");
sqlBuilder.AppendLine(" ,F.M100_ONLINEDATE ");
sqlBuilder.AppendLine(" ,P.PASTECARDNO ");
sqlBuilder.AppendLine(" FROM T_PP_PASCARDDETAILS M ");
sqlBuilder.AppendLine(" LEFT JOIN T_PP_PASTECARD P ON P.PID=M.PASTECARDID ");
sqlBuilder.AppendLine(" LEFT JOIN T_PP_FISORDER F ON F.PID=M.FISDETAILID ");
//主键
if (string.IsNullOrEmpty(condition.PID) == false)
{
whereBuilder.Append(" AND M.PASTECARDID = @PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = condition.PID });
}
if (string.IsNullOrEmpty(condition.PASTECARDNO) == false)
{
whereBuilder.Append(" AND M.PASTECARDID IN (SELECT [PID] FROM [T_PP_PASTECARD] where PASTECARDNO=@PASTECARDNO) ");
parameters.Add(new DataParameter { ParameterName = "PASTECARDNO", DataType = DbType.String, Value = condition.PASTECARDNO });
}
if (string.IsNullOrEmpty(condition.PASTECARDNO_List) == false)
{
whereBuilder.Append(" AND M.PASTECARDID IN (SELECT [PID] FROM [T_PP_PASTECARD] where PASTECARDNO in "+condition.PASTECARDNO_List+") ");
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(" ORDER BY F.CP5A ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取详细信息
/// <summary>
/// 获取详细信息
/// </summary>
/// <param name="PastCard">数据模型</param>
/// <returns>数据</returns>
public DataTable GetItemsData(PastCard model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySqls(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "Items";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "在制品出库信息数据层-获取导出的数据!"
});
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(PastCard model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_PP_PASTECARD";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "信息数据层-获取导出的数据!"
});
throw ex;
}
}
#endregion
#region 获取导出的数据详细信息
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData2(PastCardDetail model)
{
DataTable dt = null;
string sql = null;
PastCard condition = new PastCard();
condition.PASTECARDNO_List = model.PASTECARDNO_List;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySqls(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "PastCardDetailExp";
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
public PastCard GetLastPastCard(string workcentercode)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = $"SELECT TOP 1 * FROM T_PP_PASTECARD WHERE PLANTNAME like '%{workcentercode}%' ORDER BY CREATETIME DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<PastCard>(sql, parameters.ToArray());
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "贴车单查询数据层-获取最后一条贴车单!"
});
throw ex;
}
}
public PastCard GetPID(string PID)
{
try
{
string sql = $"SELECT top 1 * FROM [T_PP_PASTECARD] WHERE [PASTECARDNO]= '{PID}' ";
List<DataParameter> parameters = new List<DataParameter>();
parameters.Add(new DataParameter("PID", PID));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
var info = session.Get<PastCard>(sql, parameters.ToArray());
return info;
}
}
catch (Exception ex)
{
throw ex;
}
}
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(PastCard info)
{
int count = 0;
try
{
List<DataParameter> parameters = new List<DataParameter>();
var sql = $"update T_PP_PASTECARD set FLAGDEL = '1' where PASTECARDNO = '{info.PASTECARDNO}'";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.ExecuteSql(sql, parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}