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.
427 lines
15 KiB
427 lines
15 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.DAL;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
public class MaterielVersionDAL : BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public MaterielVersion Get(MaterielVersion model)
|
|
{
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<MaterielVersion>(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(MaterielVersion condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
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("PROCESSTYPETXT") > -1)
|
|
// {
|
|
// page.SortExpression = page.SortExpression.Replace("PROCESSTYPETXT", "PROCESSTYPE");
|
|
// }
|
|
// if (page.SortExpression.IndexOf("MATERIALTYPETXT") > -1)
|
|
// {
|
|
// page.SortExpression = page.SortExpression.Replace("MATERIALTYPETXT", "MATERIALTYPE");
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<MaterielVersion>(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<MaterielVersion> GetList(MaterielVersion condition)
|
|
{
|
|
List<MaterielVersion> list = new List<MaterielVersion>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<MaterielVersion>(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(MaterielVersion condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
sqlBuilder.AppendLine(" SELECT M.PID ");
|
|
sqlBuilder.AppendLine(" ,M.MATERIAL_PID ");
|
|
sqlBuilder.AppendLine(" ,ML.MATERIALNO AS MATERIAL_CODE ");
|
|
sqlBuilder.AppendLine(" ,ML.MATERIALNAME AS MATERIAL_NAME ");
|
|
sqlBuilder.AppendLine(" ,M.MATERIAL_VERSION ");
|
|
sqlBuilder.AppendLine(" ,M.MANUFACTURER ");
|
|
sqlBuilder.AppendLine(" ,M.SPEC_DESCRIPTION ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEUSR ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEUSR ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" FROM T_BD_MATERIAL_VERSION M ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_BD_MATERIALINFO ML ON ML.PID=M.MATERIAL_PID ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSR ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSR ");
|
|
|
|
whereBuilder.Append(" AND M.FLAGDEL='0'");
|
|
//查询条件
|
|
//物料号
|
|
if (string.IsNullOrEmpty(condition.MATERIAL_PID) == false)
|
|
{
|
|
whereBuilder.Append(" AND MATERIAL_PID = @MATERIAL_PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_PID", DataType = DbType.String, Value = condition.MATERIAL_PID });
|
|
}
|
|
//物料版本
|
|
if (string.IsNullOrEmpty(condition.MATERIAL_VERSION) == false)
|
|
{
|
|
whereBuilder.Append(" AND MATERIAL_VERSION LIKE '%'+" + "@MATERIAL_VERSION" + "+'%'");
|
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_VERSION", DataType = DbType.String, Value = condition.MATERIAL_VERSION });
|
|
}
|
|
//物料类别
|
|
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 (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 判断名称是否存在
|
|
/// <summary>
|
|
/// 判断名称是否存在
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsMateriel(MaterielVersion 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_MATERIAL_VERSION WHERE PID <> @PID AND MATERIAL_CODE=@MATERIAL_CODE AND MATERIAL_VERSION = @MATERIAL_VERSION";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "MATERIAL_CODE", Value = model.MATERIAL_CODE },
|
|
new DataParameter { ParameterName = "MATERIAL_VERSION", Value = model.MATERIAL_VERSION }));
|
|
}
|
|
|
|
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 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name=model"">物料号信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(MaterielVersion model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<MaterielVersion>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "物料版本信息数据层-插入信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取物料号
|
|
public string GetCode(MaterielVersion model)
|
|
{
|
|
//StringBuilder sqlBuilder = new StringBuilder();
|
|
//StringBuilder whereBuilder = new StringBuilder();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
string marterialcode = "";
|
|
sqlBuilder.AppendLine(" SELECT M.MATERIALNO ");
|
|
sqlBuilder.AppendLine(" FROM T_BD_MATERIALINFO M ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_BD_MATERIAL_VERSION MV ON M.PID=MV.MATERIAL_PID ");
|
|
sqlBuilder.AppendLine(" WHERE M.PID=@MATERIAL_PID ");
|
|
//parameters.Add(new DataParameter { ParameterName = "MATERIAL_PID", DataType = DbType.String, Value = model.MATERIAL_PID });
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
marterialcode = Convert.ToString(session.ExecuteSqlScalar(sqlBuilder.ToString(), new DataParameter("MATERIAL_PID", model.MATERIAL_PID)));
|
|
}
|
|
return marterialcode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name="model">物料号信息</param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(MaterielVersion model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<MaterielVersion>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "物料版本信息数据层-更新信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除信息
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name="model">物料号信息(ID)</param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(MaterielVersion 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_MATERIAL_VERSION ");
|
|
sqlBuilder.Append("SET FLAGDEL = '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)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "物料版本信息数据层-删除信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//#region 物料号是否使用
|
|
///// <summary>
|
|
///// 物料号是否使用
|
|
///// </summary>
|
|
///// <param name="info"></param>
|
|
///// <returns>true:已使用;fasel:未使用。</returns>
|
|
//public bool IsUsing(MaterielVersion model)
|
|
//{
|
|
// int count = 0;
|
|
// string sql = null;
|
|
// StringBuilder sqlBuilder = new StringBuilder();
|
|
// try
|
|
// {
|
|
// sqlBuilder.AppendLine(" SELECT COUNT(*) FROM T_AW_INJECTIONRECORDER ");
|
|
// sqlBuilder.AppendLine(" WHERE MATERIALCODE=(SELECT MATERIAL_CODE ");
|
|
// sqlBuilder.AppendLine(" FROM T_BD_MATERIAL_ERSION WHERE PID=@PID ) ");
|
|
|
|
// using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
// {
|
|
// count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(),
|
|
// new DataParameter { ParameterName = "PID", Value = model.PID }));
|
|
// }
|
|
|
|
// if (count > 0)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// else
|
|
// {
|
|
// return false;
|
|
// }
|
|
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// LogManager.LogHelper.Error(new LogInfo()
|
|
// {
|
|
// ErrorInfo = ex,
|
|
// Tag = ex.StackTrace,
|
|
// Info = "物料版本信息数据层-物料号是否使用"
|
|
// });
|
|
// throw;
|
|
// }
|
|
//}
|
|
|
|
|
|
//#endregion
|
|
}
|
|
}
|
|
|