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.
347 lines
12 KiB
347 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.DAL;
|
|
using QMAPP.MD.Entity;
|
|
using QMFrameWork.Data;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.MD.DAL
|
|
{
|
|
public class ProjectDAL : BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>信息</returns>
|
|
public Project Get(Project model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_MD_PROJECT WHERE '1'='1' ";
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
sql += " AND PID = @PID";
|
|
parameters.Add(new DataParameter("PID", model.PID));
|
|
}
|
|
if (string.IsNullOrEmpty(model.PROJECT_CODE) == false)
|
|
{
|
|
sql += " AND PROJECT_CODE = @PROJECT_CODE";
|
|
parameters.Add(new DataParameter("PROJECT_CODE", model.PROJECT_CODE));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
//获取信息
|
|
model = session.Get<Project>(sqlChange, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "获取信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(Project condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
#region 排序
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "UPDATEDATE DESC";
|
|
#endregion
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
page = session.GetDataPage<Project>(sqlChange, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "获取列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>列表</returns>
|
|
public List<Project> GetList(Project condition)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
List<Project> listProcessInfo = new List<Project>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
listProcessInfo = session.GetList<Project>(sqlChange, parameters.ToArray()).ToList();
|
|
}
|
|
return listProcessInfo;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "获取列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(Project condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT P.PID ");
|
|
sqlBuilder.AppendLine(" ,P.FACTORY_CODE ");
|
|
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
|
|
sqlBuilder.AppendLine(" ,P.PROJECT_CODE ");
|
|
sqlBuilder.AppendLine(" ,P.PROJECT_NAME ");
|
|
sqlBuilder.AppendLine(" ,P.MEMO ");
|
|
sqlBuilder.AppendLine(" ,u.USERNAME as CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,m.USERNAME as UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,P.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" FROM T_MD_PROJECT P ");
|
|
sqlBuilder.AppendLine(" left join T_QM_USER u on u.USERID=p.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" left join T_QM_USER m on m.USERID=p.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=P.FACTORY_CODE ");
|
|
//查询条件
|
|
//工厂
|
|
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND P.FACTORY_CODE = @FACTORY_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
|
|
}
|
|
//编号
|
|
if (string.IsNullOrEmpty(condition.PROJECT_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PROJECT_CODE = @PROJECT_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "PROJECT_CODE", DataType = DbType.String, Value = condition.PROJECT_CODE });
|
|
}
|
|
//名称
|
|
if (string.IsNullOrEmpty(condition.PROJECT_NAME) == false)
|
|
{
|
|
whereBuilder.Append(" AND PROJECT_NAME = @PROJECT_NAME");
|
|
parameters.Add(new DataParameter { ParameterName = "PROJECT_NAME", DataType = DbType.String, Value = condition.PROJECT_NAME });
|
|
}
|
|
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="model">工序</param>
|
|
/// <returns>true:已存在;false:不存在。</returns>
|
|
public bool IsExistsProjectCodeName(Project model)
|
|
{
|
|
string PID = "";
|
|
int count = 0;
|
|
string sql = null;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
PID = model.PID;
|
|
}
|
|
sql = "SELECT COUNT(*) FROM T_MD_PROJECT WHERE PID <> @PID AND FACTORY_CODE=@FACTORY_CODE AND PROJECT_CODE=@PROJECT_CODE ";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = ChangeSqlByDB(sql, session);
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "FACTORY_CODE", Value = model.FACTORY_CODE },
|
|
new DataParameter { ParameterName = "PROJECT_CODE", Value = model.PROJECT_CODE }));
|
|
}
|
|
return count == 0 ? false : true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "判断编号名称是否存在");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Project model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<Project>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "插入信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Project model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<Project>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "更新信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name="model">物料号信息(ID)</param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(Project model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
count = session.Delete<Project>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "删除");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 项目号是否使用(删除校验)
|
|
/// <summary>
|
|
/// 项目号是否使用
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已使用;fasel:未使用。</returns>
|
|
public bool IsUsing(string[] pid)
|
|
{
|
|
int count = 0;
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
List<DataParameter> paramList = new List<DataParameter>();
|
|
sqlBuilder.AppendLine(" select count(*) ");
|
|
sqlBuilder.AppendLine(" from T_MD_MATERIAL M ");
|
|
sqlBuilder.AppendLine(" where exists ( select 1 from T_MD_PROJECT P where M.PROJECTCODE=P.PROJECT_CODE and P.PID ");
|
|
for (int i = 0; i < pid.Length; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
sqlBuilder.AppendLine("IN ( ");
|
|
}
|
|
else
|
|
{
|
|
sqlBuilder.AppendLine(",");
|
|
}
|
|
string param = "PID" + i.ToString();
|
|
sqlBuilder.Append("@" + param);
|
|
paramList.Add(new DataParameter(param, DbType.String, pid[i]));
|
|
if (i == pid.Length - 1)
|
|
{
|
|
sqlBuilder.AppendLine("))");
|
|
}
|
|
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
|
|
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, paramList.ToArray()));
|
|
|
|
}
|
|
|
|
return count == 0 ? false : true;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|