using System;
using System.Collections.Generic;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.FIS;
using QMFrameWork.Log;
using System.Data;
using System.Linq;
using QMAPP.DAL;
using QMAPP.FJC.Entity.FileCopy.FIS;
using QMAPP.MD.Entity;
namespace QMAPP.FJC.DAL.FIS
{
public class FISOrderDAL : BaseDAL
{
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(FISOrder condition, DataPage page)
{
string sql = null;
List parameters = new List();
//List list = new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "CP5A 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;
}
}
public List FISOrderIsNull(FISOrder condition)
{
//string sql = "SELECT * FROM [T_PP_FISORDER] where [VWSEQ]='" + condition.VWSEQ + "' and [KIN]='" + condition.KIN + "' and [VIN]='" + condition.VIN + "' and [LINENO]='" + condition.LINENO + "'";
string sql = "SELECT * FROM [T_PP_FISORDER] where [KIN]='" + condition.KIN + "' and [LINENO]='" + condition.LINENO + "'";
List parameters = new List();
try
{
//if (BaseSession != null)
//{
// return BaseSession.GetList(sql, parameters.ToArray()).ToList();
//}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList(sql, parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS 计划信息数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(FISOrder condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT F.PID, ");
sqlBuilder.AppendLine(" F.VWSEQ, ");
sqlBuilder.AppendLine(" F.KIN, ");
sqlBuilder.AppendLine(" F.VIN, ");
sqlBuilder.AppendLine(" F.PRODNO, ");
sqlBuilder.AppendLine(" F.CARSETDESC_CN, ");
sqlBuilder.AppendLine(" F.CP5A, ");
sqlBuilder.AppendLine(" F.SCANSTATE, ");
sqlBuilder.AppendLine(" F.[LINENO], ");
sqlBuilder.AppendLine(" CONVERT(VARCHAR(19),F.CREATETIME,120) AS CREATETIME, ");
sqlBuilder.AppendLine(" F.FLAGDEL ");
sqlBuilder.AppendLine(" FROM T_PP_FISORDER F ");
//查询条件
//大众顺序号
if (string.IsNullOrEmpty(condition.VWSEQ) == false)
{
whereBuilder.Append(" AND VWSEQ = @VWSEQ");
parameters.Add(new DataParameter { ParameterName = "VWSEQ", DataType = DbType.String, Value = condition.VWSEQ });
}
//KIN号
if (string.IsNullOrEmpty(condition.KIN) == false)
{
whereBuilder.Append(" AND KIN LIKE '%'+" + "@KIN" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "KIN", DataType = DbType.String, Value = condition.KIN });
}
//VIN号
if (string.IsNullOrEmpty(condition.VIN) == false)
{
whereBuilder.Append(" AND VIN LIKE '%'+" + "@VIN " + "+'%'");
parameters.Add(new DataParameter { ParameterName = "VIN", DataType = DbType.String, Value = condition.VIN });
}
//产品号
if (string.IsNullOrEmpty(condition.PRODNO) == false)
{
whereBuilder.Append(" AND PRODNO = @PRODNO");
parameters.Add(new DataParameter { ParameterName = "PRODNO", DataType = DbType.String, Value = condition.PRODNO });
}
//扫描状态
if (string.IsNullOrEmpty(condition.SCANSTATE) == false)
{
whereBuilder.Append(" AND SCANSTATE = @SCANSTATE");
parameters.Add(new DataParameter { ParameterName = "SCANSTATE", DataType = DbType.String, Value = condition.SCANSTATE });
}
//上线时间
if (condition.ONLINETIMESTART != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME >= @ONLINETIMESTART");
parameters.Add(new DataParameter { ParameterName = "ONLINETIMESTART", DataType = DbType.String, Value = condition.ONLINETIMESTART });
}
if (condition.ONLINETIMEEND != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME <= @ONLINETIMEEND");
parameters.Add(new DataParameter { ParameterName = "ONLINETIMEEND", DataType = DbType.String, Value = condition.ONLINETIMEEND });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(FISOrder 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 = "FISOrderExp";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS计划查询信息导出获取数据错误!"
});
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public int Insert(FISOrder 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
#region 更新信息
public int Update(FISOrder model)
{
int count = 0;
try
{
if (BaseSession != null)
{
//插入基本信息
count = BaseSession.Update(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Update(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
public FISOrder GetByPlan(string planno, string materialcode)
{
StringBuilder sql = new StringBuilder();
List parameters = new List();
//List list = new List();
try
{
sql.AppendLine("SELECT * FROM [T_PP_FISORDER] WHERE [ORDER_NO]=@planno AND [PRODNO]=@materialcode");
parameters.Add(new DataParameter("planno",planno));
parameters.Add(new DataParameter("materialcode",materialcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS 计划信息数据层-获取列表"
});
throw;
}
}
}
}