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.
481 lines
18 KiB
481 lines
18 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using QMFrameWork.Data;
|
|
using QMFrameWork.Log;
|
|
using QMAPP.Entity;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
public class ProductInfoDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>信息</returns>
|
|
public ProductInfo Get(ProductInfo model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_BD_PRODUCTINFO WHERE '1'='1'";
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
sql += " AND PID = @PID";
|
|
parameters.Add(new DataParameter("PID", model.PID));
|
|
}
|
|
if (string.IsNullOrEmpty(model.PRODUCTMARK) == false)
|
|
{
|
|
sql += " AND PRODUCTMARK = @PRODUCTMARK";
|
|
parameters.Add(new DataParameter("PRODUCTMARK", model.PRODUCTMARK));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<ProductInfo>(sql, parameters.ToArray());
|
|
}
|
|
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(ProductInfo condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "PRODUCTMARK ASC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<ProductInfo>(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>
|
|
/// <returns>全部集合</returns>
|
|
public List<ProductInfo> GetList(ProductInfo condition)
|
|
{
|
|
List<ProductInfo> list = new List<ProductInfo>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProductInfo>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "操作者数据层-获取区域列表"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(ProductInfo condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT P.PID ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTMARK ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTDESCRIPTION ");
|
|
//sqlBuilder.AppendLine(" ,P.AREAID ");
|
|
//sqlBuilder.AppendLine(" ,A.AREACODE ");
|
|
//sqlBuilder.AppendLine(" ,A.AREANAME ");
|
|
sqlBuilder.AppendLine(" ,P.FACTORYID ");
|
|
sqlBuilder.AppendLine(" ,PL.FACTORY_CODE ");
|
|
sqlBuilder.AppendLine(" ,PL.FACTORY_NAME ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTBASICID ");
|
|
sqlBuilder.AppendLine(" ,PC.PRODUCTTYPECODE ");
|
|
sqlBuilder.AppendLine(" ,PC.PRODUCTNAME ");
|
|
sqlBuilder.AppendLine(" ,P.MEMO ");
|
|
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_PRODUCTINFO P ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_BD_PRODUCTBASIC PC ON PC.PID=P.PRODUCTBASICID ");
|
|
//sqlBuilder.AppendLine(" LEFT JOIN T_BD_AREA A ON A.PID=P.AREAID ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_BD_FACTORY PL ON PL.PID=P.FACTORYID ");
|
|
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 ");
|
|
//查询条件
|
|
if (string.IsNullOrEmpty(condition.PRODUCTMARK) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTMARK = @PRODUCTMARK ");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTMARK", DataType = DbType.String, Value = condition.PRODUCTMARK });
|
|
}
|
|
//if (string.IsNullOrEmpty(condition.AREAID) == false)
|
|
//{
|
|
// whereBuilder.Append(" AND P.AREAID = @AREAID ");
|
|
// parameters.Add(new DataParameter { ParameterName = "AREAID", DataType = DbType.String, Value = condition.AREAID });
|
|
//}
|
|
if (string.IsNullOrEmpty(condition.FACTORYID) == false)
|
|
{
|
|
whereBuilder.Append(" AND P.FACTORYID = @FACTORYID ");
|
|
parameters.Add(new DataParameter { ParameterName = "FACTORYID", DataType = DbType.String, Value = condition.FACTORYID });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.PRODUCTBASICID) == false)
|
|
{
|
|
whereBuilder.Append(" AND P.PRODUCTBASICID = @PRODUCTBASICID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTBASICID", DataType = DbType.String, Value = condition.PRODUCTBASICID });
|
|
}
|
|
|
|
|
|
|
|
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="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(ProductInfo model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<ProductInfo>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 信息是否重复
|
|
/// <summary>
|
|
/// 判断名称是否存在
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsProductInfo(ProductInfo 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_PRODUCTINFO ");
|
|
sqlBuilder.AppendLine(" WHERE PID <> @PID AND PRODUCTMARK=@PRODUCTMARK");
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(),
|
|
new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "PRODUCTMARK", Value = model.PRODUCTMARK }));
|
|
}
|
|
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(ProductInfo model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<ProductInfo>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
//提交事务
|
|
public int Delete(ProductInfo model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
count = session.Delete<ProductInfo>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(ProductInfo 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 = "ProductInfoExp";
|
|
dt.TableName = "T_BD_PRODUCTINFO";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 导入
|
|
public ImportMessage GetImportData(List<ProductInfo> list)
|
|
{
|
|
ImportMessage em = new ImportMessage();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//设置祖先对象数据会话
|
|
session.OpenTs();
|
|
foreach (ProductInfo info in list)
|
|
{
|
|
if (info.IsNewInfo == true)
|
|
{
|
|
//插入信息
|
|
int count = session.Insert<ProductInfo>(info);
|
|
em.insertNum++;
|
|
}
|
|
else
|
|
{
|
|
//更新信息
|
|
int count = session.Update<ProductInfo>(info);
|
|
em.updateNum++;
|
|
}
|
|
}
|
|
session.CommitTs();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return em;
|
|
}
|
|
#endregion
|
|
|
|
#region 导入校验工厂区域信息是否匹配
|
|
///// <summary>
|
|
///// 导入校验工厂区域信息是否匹配
|
|
///// </summary>
|
|
///// <param name="plantmodel">工厂</param>
|
|
///// <param name="areamodel">区域</param>
|
|
///// <returns>结果</returns>
|
|
//public int ImportCheck(Plant plantmodel, Area areamodel)
|
|
//{
|
|
// int num = 0;
|
|
// StringBuilder sqlBuilder = new StringBuilder();
|
|
// try
|
|
// {
|
|
// sqlBuilder.AppendLine("SELECT COUNT(1) FROM T_BD_FACTORY ");
|
|
// sqlBuilder.AppendLine(" WHERE PID=@PID AND AREAID=@AREAID");
|
|
// using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
// {
|
|
// num = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), new DataParameter("PID", plantmodel.PID),
|
|
// new DataParameter { ParameterName = "AREAID", Value = areamodel.PID }));
|
|
// }
|
|
// return num;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw ex;
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
#region 获取零件列表(下拉列表数据源)王丹丹 2017.03.13
|
|
/// <summary>
|
|
/// 获取零件列表(下拉列表数据源)
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<ProductInfo> GetProductInfoList(ProductInfo condition)
|
|
{
|
|
List<ProductInfo> list = new List<ProductInfo>();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
#region 构成查询语句
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT P.PID ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTMARK ");
|
|
sqlBuilder.AppendLine(" ,P.PRODUCTDESCRIPTION ");
|
|
//sqlBuilder.AppendLine(" ,P.AREAID ");
|
|
sqlBuilder.AppendLine(" ,P.FACTORYID ");
|
|
sqlBuilder.AppendLine(" ,P.MEMO ");
|
|
sqlBuilder.AppendLine(" ,P.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,P.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" FROM T_BD_PRODUCTINFO P ");
|
|
////区域
|
|
//if (!string.IsNullOrEmpty(condition.AREAID))
|
|
//{
|
|
// whereBuilder.AppendLine(" AND P.AREAID=@AREAID");
|
|
// parameters.Add(new DataParameter { ParameterName = "AREAID", DataType = DbType.String, Value = condition.AREAID });
|
|
//}
|
|
//工厂
|
|
if (!string.IsNullOrEmpty(condition.FACTORYID))
|
|
{
|
|
whereBuilder.AppendLine(" AND P.FACTORYID=@FACTORYID");
|
|
parameters.Add(new DataParameter { ParameterName = "FACTORYID", DataType = DbType.String, Value = condition.FACTORYID });
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
#endregion
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProductInfo>(sqlBuilder.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "零件号数据层-获取零件列表(下拉列表数据源)"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|