using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Basic;
using QMFrameWork.Data;
using System.Data;
using QMFrameWork.Log;
namespace QMAPP.FJC.DAL.Basic
{
///
/// 模块编号:M2-10
/// 作 用:物料架类型维护数据层
/// 作 者:王丹丹
/// 编写日期:2015年06月03日
///
public class MaterialShelfTypeDAL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// *信息
public MaterialShelfType Get(MaterialShelfType model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料架类型维护数据层-获取信息"
});
throw;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(MaterialShelfType condition, DataPage page)
{
string sql = null;
List parameters = new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
else
{
//按照标题排序
if (page.SortExpression.IndexOf("COLORCODETXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("COLORCODETXT", "COLORCODE");
}
if (page.SortExpression.IndexOf("VERSIONTXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("VERSIONTXT", "VERSION");
}
}
#endregion
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 = "物料架类型维护数据层-获取列表"
});
throw;
}
}
///
/// 获取列表
///
/// 条件
/// 数据页
public List GetList(MaterialShelfType condition)
{
List list = new List();
string sql = null;
List parameters = new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(MaterialShelfType condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT MS.PID ");
sqlBuilder.AppendLine(" ,MS.MARERIALSHELFTYPECODE ");
sqlBuilder.AppendLine(" ,MS.MARERIALSHELFTYPENAME ");
sqlBuilder.AppendLine(" ,MS.PRODUCTTYPE ");
sqlBuilder.AppendLine(" ,MS.VERSION ");
sqlBuilder.AppendLine(" ,MS.COLORCODE ");
sqlBuilder.AppendLine(" ,MS.CAPACITY ");
sqlBuilder.AppendLine(" ,MS.CREATEUSER ");
sqlBuilder.AppendLine(" ,MS.CREATEDATE ");
sqlBuilder.AppendLine(" ,MS.UPDATEUSER ");
sqlBuilder.AppendLine(" ,MS.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" FROM T_BD_MATERIALSHELFTYPE MS ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=MS.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=MS.UPDATEUSER ");
//查询条件
//物料架型号
if (string.IsNullOrEmpty(condition.MARERIALSHELFTYPECODE) == false)
{
whereBuilder.Append(" AND MS.MARERIALSHELFTYPECODE LIKE '%'+" + "@MARERIALSHELFTYPECODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MARERIALSHELFTYPECODE", DataType = DbType.String, Value = condition.MARERIALSHELFTYPECODE });
}
//物料架名称
if (string.IsNullOrEmpty(condition.MARERIALSHELFTYPENAME) == false)
{
whereBuilder.Append(" AND MS.MARERIALSHELFTYPENAME LIKE '%'+" + "@MARERIALSHELFTYPENAME" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MARERIALSHELFTYPENAME", DataType = DbType.String, Value = condition.MARERIALSHELFTYPENAME });
}
//产品类别
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
{
whereBuilder.Append(" AND MS.PRODUCTTYPE = @PRODUCTTYPE ");
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
}
//高低配
if (string.IsNullOrEmpty(condition.VERSION) == false)
{
whereBuilder.Append(" AND MS.VERSION = @VERSION ");
parameters.Add(new DataParameter { ParameterName = "VERSION", DataType = DbType.String, Value = condition.VERSION });
}
//高低配
if (string.IsNullOrEmpty(condition.COLORCODE) == false)
{
whereBuilder.Append(" AND MS.COLORCODE = @COLORCODE ");
parameters.Add(new DataParameter { ParameterName = "COLORCODE", DataType = DbType.String, Value = condition.COLORCODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断信息是否重复
///
/// 判断信息是否重复
///
///
/// true:已存在;fasel:不存在。
public bool ExistsMaterialShelfType(MaterialShelfType model)
{
string PID = "";
int count = 0;
string sql = null;
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
sql = "SELECT COUNT(*) FROM T_BD_MATERIALSHELFTYPE WHERE PID <> @PID AND MARERIALSHELFTYPECODE=@MARERIALSHELFTYPECODE";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
new DataParameter { ParameterName = "MARERIALSHELFTYPECODE", Value = model.MARERIALSHELFTYPECODE }));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料架类型维护数据层-判断信息是否重复"
});
throw;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public int Insert(MaterialShelfType model)
{
int count = 0;
try
{
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 = "物料架类型维护数据层-插入信息"
});
throw;
}
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public int Update(MaterialShelfType model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料架类型维护数据层-更新信息"
});
throw;
}
}
#endregion
#region 删除信息
///
/// 删除信息
///
/// 物料号信息(ID)
/// 删除个数
public int Delete(MaterialShelfType model)
{
StringBuilder sqlBuilder = new StringBuilder();
List parameters = new List();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料架类型维护数据层-删除信息"
});
throw;
}
}
#endregion
}
}