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

213 lines
7.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.FIS;
using QMFrameWork.Log;
using System.Data;
using QMAPP.DAL;
using QMAPP.FJC.Entity.FileCopy.FIS;
namespace QMAPP.FJC.DAL.FIS
{
public class FISOrederSendDetialDAL : BaseDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(FISOrederSendDetial condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "SHIPMENT_NO DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<FISOrederSendDetial>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS 计划信息数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(FISOrederSendDetial condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT F.PID, ");
sqlBuilder.AppendLine(" F.FIS_PID, ");
sqlBuilder.AppendLine(" F.SHIPMENT_NO, ");
sqlBuilder.AppendLine(" F.STATE, ");
sqlBuilder.AppendLine(" F.MATERIAL_CODE, ");
sqlBuilder.AppendLine(" M.MATERIALNAME AS MATERIAL_NAME, ");
sqlBuilder.AppendLine(" F.FACTORY_CODE, ");
sqlBuilder.AppendLine(" A.FACTORY_NAME, ");
sqlBuilder.AppendLine(" F.WORKCENTER_CODE, ");
sqlBuilder.AppendLine(" W.WORKCENTER_NAME ");
sqlBuilder.AppendLine(" FROM T_PP_FISORDERSENDDETAIL F ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_FACTORY A ON A.FACTORY_CODE=F.FACTORY_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_MATERIALINFO M ON M.MATERIALNO=F.MATERIAL_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_WORKCENTER W ON W.WORKCENTER_CODE=F.WORKCENTER_CODE ");
//查询条件
//发货号
if (string.IsNullOrEmpty(condition.SHIPMENT_NO) == false)
{
whereBuilder.Append(" AND SHIPMENT_NO = @SHIPMENT_NO");
parameters.Add(new DataParameter { ParameterName = "SHIPMENT_NO", DataType = DbType.String, Value = condition.SHIPMENT_NO });
}
//状态
if (string.IsNullOrEmpty(condition.STATE) == false)
{
whereBuilder.Append(" AND STATE = @STATE");
parameters.Add(new DataParameter { ParameterName = "STATE", DataType = DbType.String, Value = condition.STATE });
}
//物料号
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND MATERIAL_CODE = @MATERIAL_CODE ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//工厂号
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
{
whereBuilder.Append(" AND FACTORY_CODE = @FACTORY_CODE");
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
}
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>
/// <returns>数据</returns>
public DataTable GetExportData(FISOrederSendDetial 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 = "FISOrederSendDetialExp";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS订单发货信息导出获取数据错误!"
});
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(FISOrederSendDetial model)
{
int count = 0;
try
{
if (BaseSession != null)
{
//插入基本信息
count = BaseSession.Insert<FISOrederSendDetial>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<FISOrederSendDetial>(model);
}
}
//using (IDataSession session = AppDataFactory.CreateMainSession())
//{
// //插入基本信息
// count = session.Insert<FISOrder>(model);
//}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS 计划信息数据层-插入信息"
});
throw;
}
}
#endregion
}
}