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.
453 lines
15 KiB
453 lines
15 KiB
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;
|
|
using QMAPP.DAL;
|
|
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
/// <summary>
|
|
/// 模块编号:M2-6
|
|
/// 作 用:工序名称信息数据层
|
|
/// 作 者:王丹丹
|
|
/// 编写日期:2015年05月29日
|
|
///</summary>
|
|
public class ProcessInfoDAL : BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public ProcessInfo Get(ProcessInfo model)
|
|
{
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<ProcessInfo>(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(ProcessInfo 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("OPERATETYPETXT") > -1)
|
|
{
|
|
page.SortExpression = page.SortExpression.Replace("OPERATETYPETXT", "OPERATETYPE");
|
|
}
|
|
if (page.SortExpression.IndexOf("PROCESSTYPETXT") > -1)
|
|
{
|
|
page.SortExpression = page.SortExpression.Replace("PROCESSTYPETXT", "PROCESSTYPE");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<ProcessInfo>(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<ProcessInfo> GetList(ProcessInfo condition)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
List<ProcessInfo> listProcessInfo = new List<ProcessInfo>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
listProcessInfo = session.GetList<ProcessInfo>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return listProcessInfo;
|
|
}
|
|
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(ProcessInfo condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT PID ");
|
|
sqlBuilder.AppendLine(" ,PROCESSNAME ");
|
|
sqlBuilder.AppendLine(" ,PROCESSTYPE ");
|
|
sqlBuilder.AppendLine(" ,OPERATETYPE ");
|
|
sqlBuilder.AppendLine(" ,MEMO ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" FROM T_BD_PROCESSINFO M ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ");
|
|
|
|
|
|
//查询条件
|
|
//工序名称
|
|
if (string.IsNullOrEmpty(condition.PROCESSNAME) == false)
|
|
{
|
|
whereBuilder.Append(" AND PROCESSNAME LIKE '%'+" + "@PROCESSNAME" + "+'%'");
|
|
parameters.Add(new DataParameter { ParameterName = "PROCESSNAME", DataType = DbType.String, Value = condition.PROCESSNAME });
|
|
}
|
|
//工序类别
|
|
if (string.IsNullOrEmpty(condition.PROCESSTYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PROCESSTYPE = @PROCESSTYPE");
|
|
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
|
|
}
|
|
//操作类别
|
|
if (string.IsNullOrEmpty(condition.OPERATETYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND OPERATETYPE = @OPERATETYPE ");
|
|
parameters.Add(new DataParameter { ParameterName = "OPERATETYPE", DataType = DbType.String, Value = condition.OPERATETYPE });
|
|
}
|
|
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 ExistsProcessName(ProcessInfo 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_PROCESSINFO WHERE PID <> @PID AND PROCESSNAME=@PROCESSNAME";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "PROCESSNAME", Value = model.PROCESSNAME }));
|
|
}
|
|
|
|
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="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsProcessType(ProcessInfo 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_PROCESSINFO WHERE PID <> @PID AND PROCESSTYPE=@PROCESSTYPE";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "PROCESSTYPE", Value = model.PROCESSTYPE }));
|
|
}
|
|
|
|
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="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(ProcessInfo model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<ProcessInfo>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "工序名称信息数据层-插入信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(ProcessInfo model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<ProcessInfo>(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(ProcessInfo model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
count = session.Delete<ProcessInfo>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "工序名称信息数据层-删除"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 工序下拉
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns></returns>
|
|
public List<ProcessInfo> GetProcessInfoBasicList(ProcessInfo condition)
|
|
{
|
|
List<ProcessInfo> list = new List<ProcessInfo>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProcessInfo>(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="model"></param>
|
|
/// <returns></returns>
|
|
public List<ProcessInfo> GetProcessInfoList(ProcessInfo model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
List<ProcessInfo> list = new List<ProcessInfo>();
|
|
|
|
sql = @" SELECT * FROM T_BD_PROCESSINFO";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
list = session.GetList<ProcessInfo>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|