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 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(FISOrederSendDetial condition, DataPage page)
{
string sql = null;
List parameters = new List();
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(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS 计划信息数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(FISOrederSendDetial condition, ref List 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 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(FISOrederSendDetial model)
{
DataTable dt = null;
string sql = null;
List parameters = new List();
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 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public int Insert(FISOrederSendDetial model)
{
int count = 0;
try
{
if (BaseSession != null)
{
//插入基本信息
count = BaseSession.Insert(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert(model);
}
}
//using (IDataSession session = AppDataFactory.CreateMainSession())
//{
// //插入基本信息
// count = session.Insert(model);
//}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS 计划信息数据层-插入信息"
});
throw;
}
}
#endregion
}
}