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.
454 lines
16 KiB
454 lines
16 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMFrameWork.Data;
|
|
using System.Data;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using QMFrameWork.Log;
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
/// <summary>
|
|
/// 模块编号:M13-1
|
|
/// 作 用:零件基本类别
|
|
/// 作 者:王庆男
|
|
/// 编写日期:2015年06月09日
|
|
///</summary>
|
|
public class ProductBasicDAL
|
|
{
|
|
|
|
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public ProductBasic Get(ProductBasic model)
|
|
{
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<ProductBasic>(model);
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "零件类别数据层-获取信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(ProductBasic condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "UPDATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<ProductBasic>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "零件类别数据层-获取列表"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public List<ProductBasic> GetList(ProductBasic condition)
|
|
{
|
|
string sql = null;
|
|
List<ProductBasic> list = new List<ProductBasic>();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProductBasic>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "操作者数据层-获取零件类别列表"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句(2017.03.07 郭兆福修改)
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(ProductBasic condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT P.PID ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTTYPE ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTTYPECODE ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTNAME ");
|
|
sqlBuilder.AppendLine(" ,CASE P.PRODUCTUNIT WHEN '0' THEN '单体' WHEN '1' THEN '集合' ELSE '' END AS PRODUCTUNIT ");
|
|
sqlBuilder.AppendLine(" ,CASE P.PRODUCTSOURCE WHEN '0' THEN '自制' WHEN '1' THEN '外购' ELSE '' END AS PRODUCTSOURCE ");
|
|
sqlBuilder.AppendLine(" ,P.ISPARENT ");
|
|
sqlBuilder.AppendLine(" ,P.CAPATITY ");
|
|
sqlBuilder.AppendLine(" ,P.DELFLAG ");
|
|
sqlBuilder.AppendLine(" ,P.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,P.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" FROM T_BD_PRODUCTBASIC P ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=P.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=P.UPDATEUSER ");
|
|
|
|
whereBuilder.Append(" AND P.DELFLAG='0'");
|
|
//查询条件
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPECODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTTYPECODE = @PRODUCTTYPECODE");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPECODE", DataType = DbType.String, Value = condition.PRODUCTTYPECODE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTTYPE = @PRODUCTTYPE");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTSOURCE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTSOURCE = @PRODUCTSOURCE");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTSOURCE", DataType = DbType.String, Value = condition.PRODUCTSOURCE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTUNIT) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTUNIT = @PRODUCTUNIT");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTUNIT", DataType = DbType.String, Value = condition.PRODUCTUNIT });
|
|
}
|
|
|
|
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)(2017.03.07 郭兆福)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(ProductBasic model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = session.Insert<ProductBasic>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 信息是否重复
|
|
/// <summary>
|
|
/// 判断名称是否存在
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsProductBasic(ProductBasic model)
|
|
{
|
|
string PID = "";
|
|
int count = 0;
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
PID = model.PID;
|
|
}
|
|
sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_BD_PRODUCTBASIC ");
|
|
sqlBuilder.AppendLine(" WHERE PID <> @PID AND (PRODUCTTYPECODE=@PRODUCTTYPECODE OR PRODUCTNAME=@PRODUCTNAME)");
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "PRODUCTTYPECODE", Value = model.PRODUCTTYPECODE },
|
|
new DataParameter { ParameterName = "PRODUCTNAME", Value = model.PRODUCTNAME }));
|
|
}
|
|
if (count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(ProductBasic model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<ProductBasic>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 逻辑删除
|
|
/// <summary>
|
|
/// 逻辑删除信息(2017.03.07 郭兆福)
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(ProductBasic model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append("UPDATE T_BD_PRODUCTBASIC ");
|
|
sqlBuilder.Append("SET DELFLAG = '1'");
|
|
sqlBuilder.Append("WHERE PID = @PID");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除校验
|
|
/// <summary>
|
|
/// 删除校验
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns>结果</returns>
|
|
public int DelCheck(ProductBasic model)
|
|
{
|
|
int num1 = 0;
|
|
StringBuilder sqlBuilder1 = new StringBuilder();
|
|
try
|
|
{
|
|
sqlBuilder1.AppendLine(" SELECT COUNT(1) ");
|
|
sqlBuilder1.AppendLine(" FROM T_BD_PRODUCTINFO ");
|
|
sqlBuilder1.AppendLine(" WHERE ProductBasicID = @PID ");
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
num1 = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder1.ToString(), new DataParameter("PID", model.PID)));
|
|
}
|
|
return num1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(ProductBasic 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_BD_PRODUCTBASIC";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取最大零件类别值
|
|
/// <summary>
|
|
/// 获取最大零件类别值
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns>结果</returns>
|
|
public int GetType(ProductBasic condition)
|
|
{
|
|
int num = 0;
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT ISNULL(MAX(CONVERT(INT,PRODUCTTYPE)),0) FROM T_BD_PRODUCTBASIC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
num = Convert.ToInt32(session.ExecuteSqlScalar(sql, parameters.ToArray()));
|
|
}
|
|
return num;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取工厂列表(下拉列表数据源)
|
|
/// <summary>
|
|
/// 获取工厂列表(下拉列表数据源)
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<ProductBasic> GetProductBasicList(ProductBasic condition)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<ProductBasic> list = new List<ProductBasic>();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sqlBuilder.AppendLine(" SELECT P.PID ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTTYPE ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTTYPECODE ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTNAME ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTUNIT ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTSOURCE ");
|
|
sqlBuilder.AppendLine(" ,P.ISPARENT ");
|
|
sqlBuilder.AppendLine(" ,P.CAPATITY ");
|
|
sqlBuilder.AppendLine(" ,P.DELFLAG ");
|
|
sqlBuilder.AppendLine(" ,P.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,P.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" FROM T_BD_PRODUCTBASIC P ");
|
|
sqlBuilder.AppendLine(" WHERE P.DELFLAG = '0'");
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProductBasic>(sqlBuilder.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "零件类别信息-获取零件类别列表"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|