天津投入产出系统后端
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.
 
 
 
 
 
 

538 lines
21 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-7
/// 作 用:工序设置数据层
/// 作 者:王丹丹
/// 编写日期:2015年06月01日
///</summary>
public class ProcessSetDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public ProcessSet Get(ProcessSet model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<ProcessSet>(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(ProcessSet 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("LPNECCESSARYTXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("LPNECCESSARYTXT", "LPNECCESSARY");
}
if (page.SortExpression.IndexOf("WIPSETTXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("WIPSETTXT", "WIPSET");
}
}
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<ProcessSet>(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<ProcessSet> GetList(ProcessSet condition)
{
List<ProcessSet> list = new List<ProcessSet>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ProcessSet>(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(ProcessSet condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT PS.PID ");
sqlBuilder.AppendLine(" ,PS.PCID ");
sqlBuilder.AppendLine(" ,PS.PROCESSTYPE ");
sqlBuilder.AppendLine(" ,PS.PRODUCTNAME ");
sqlBuilder.AppendLine(" ,PS.PROCESSNAME ");
sqlBuilder.AppendLine(" ,PS.PRODUCTTYPE ");
sqlBuilder.AppendLine(" ,PS.PROCESSINDEX ");
sqlBuilder.AppendLine(" ,PS.INTERVALVALUE ");
sqlBuilder.AppendLine(" ,PS.LPNECCESSARY ");
sqlBuilder.AppendLine(" ,PS.PRODUCELINE ");
sqlBuilder.AppendLine(" ,PS.MINVALUE ");
sqlBuilder.AppendLine(" ,PS.PRODUCEMINVALUE ");
sqlBuilder.AppendLine(" ,PS.WIPSET ");
sqlBuilder.AppendLine(" ,PS.ISMAIN ");
sqlBuilder.AppendLine(" ,PS.MEMO ");
sqlBuilder.AppendLine(" ,PS.CREATEUSER ");
sqlBuilder.AppendLine(" ,PS.CREATEDATE ");
sqlBuilder.AppendLine(" ,PS.UPDATEUSER ");
sqlBuilder.AppendLine(" ,PS.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
//sqlBuilder.AppendLine(" ,PO.PROCESSTYPE ");
sqlBuilder.AppendLine(" ,B.PRODUCTNAME AS PRODUCTTYPETEXT ");
sqlBuilder.AppendLine(" FROM T_BD_PROCESSSET PS ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_PROCESSINFO PO ON PS.PCID=PO.PID ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_PRODUCTBASIC B ON PS.PRODUCTTYPE=B.PRODUCTTYPE ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=PS.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=PS.UPDATEUSER ");
sqlBuilder.AppendLine(" WHERE 1=1 ");
//查询条件
//工序ID
if (string.IsNullOrEmpty(condition.PID) == false)
{
whereBuilder.Append(" AND PS.PID= @PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = condition.PID });
}
//工序名称ID
if (string.IsNullOrEmpty(condition.PROCESSNAME) == false)
{
whereBuilder.Append(" AND PS.PCID= @PCID ");
parameters.Add(new DataParameter { ParameterName = "PCID", DataType = DbType.String, Value = condition.PROCESSNAME });
}
//工序类别
if (string.IsNullOrEmpty(condition.PROCESSTYPESEARCH) == false)
{
whereBuilder.Append(" AND PS.PROCESSTYPE = @PROCESSTYPE ");
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPESEARCH });
}
//工序类别
if (string.IsNullOrEmpty(condition.PROCESSTYPE) == false)
{
whereBuilder.Append(" AND PS.PROCESSTYPE = @PROCESSTYPE ");
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
}
//零件类别
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
{
whereBuilder.Append(" AND PS.PRODUCTTYPE = @PRODUCTTYPE ");
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
}
//是否加工主零件
if (string.IsNullOrEmpty(condition.ISMAIN) == false)
{
whereBuilder.Append(" AND PS.ISMAIN = @ISMAIN ");
parameters.Add(new DataParameter { ParameterName = "ISMAIN", DataType = DbType.String, Value = condition.ISMAIN });
}
//工序顺序
if (string.IsNullOrEmpty(condition.PROCESSINDEXMIN) == false)
{
whereBuilder.Append(" AND PS.PROCESSINDEX > @PROCESSINDEXMIN ");
parameters.Add(new DataParameter { ParameterName = "PROCESSINDEXMIN", DataType = DbType.String, Value = condition.PROCESSINDEXMIN });
}
//工序顺序
if (string.IsNullOrEmpty(condition.PROCESSINDEXMAX) == false)
{
whereBuilder.Append(" AND PS.PROCESSINDEX < @PROCESSINDEXMAX ");
parameters.Add(new DataParameter { ParameterName = "PROCESSINDEXMAX", DataType = DbType.String, Value = condition.PROCESSINDEXMAX });
}
//是否必须
if (string.IsNullOrEmpty(condition.LPNECCESSARY) == false)
{
whereBuilder.Append(" AND PS.LPNECCESSARY = @LPNECCESSARY ");
parameters.Add(new DataParameter { ParameterName = "LPNECCESSARY", DataType = DbType.String, Value = condition.LPNECCESSARY });
}
//web页面编辑工序是否必须
if (string.IsNullOrEmpty(condition.EDITNECESSARY) == false)
{
whereBuilder.Append(@" AND PS.PID IN (
select PID from T_BD_PROCESSSET where PRODUCTTYPE='8'
union
select PID from T_BD_PROCESSSET where PRODUCTTYPE='0' and PROCESSTYPE='6'
union
select PID from T_BD_PROCESSSET where PRODUCTTYPE='1' and PROCESSTYPE='7'
union
select PID from T_BD_PROCESSSET where PRODUCTTYPE in ('4','5') and PROCESSTYPE='13')"
);
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(whereBuilder.ToString());
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsProcessSet(ProcessSet model)
{
string PID = "";
int count = 0;
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sqlBuilder = new StringBuilder();
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
sqlBuilder.Append(" SELECT COUNT(*) FROM T_BD_PROCESSSET WHERE PID <> @PID AND PRODUCTTYPE =@PRODUCTTYPE ");
sqlBuilder.Append(" AND PROCESSTYPE =@PROCESSTYPE ");//AND PROCESSINDEX =@PROCESSINDEX
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = model.PRODUCTTYPE });
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = model.PROCESSTYPE });
//parameters.Add(new DataParameter { ParameterName = "PROCESSINDEX", DataType = DbType.String, Value = model.PROCESSINDEX });
if (this.BaseSession != null)
{
count = Convert.ToInt32(BaseSession.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
}
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(ProcessSet model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
//插入基本信息
count = BaseSession.Insert<ProcessSet>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<ProcessSet>(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(ProcessSet model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
//更新基本信息
count = BaseSession.Update<ProcessSet>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<ProcessSet>(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(ProcessSet model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<ProcessSet>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工序设置数据层-删除"
});
throw;
}
}
#endregion
#region 更新工序顺序
/// <summary>
/// 更新工序顺序(当前工序顺序向后移动,后面的工序顺序依次向前移一位)
/// </summary>
/// <param name="processSet"></param>
/// <returns></returns>
public int UpdateIndexForWord(ProcessSet processSet)
{
int count = 0;
string sql = "";
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "UPDATE T_BD_PROCESSSET SET PROCESSINDEX = PROCESSINDEX-1 WHERE PROCESSINDEX BETWEEN @STARTINDEX AND @ENDINDEX AND PRODUCTTYPE=@PRODUCTTYPE";
parameters.Add(new DataParameter { ParameterName = "STARTINDEX", DataType = DbType.String, Value = processSet.OLDPROCESSINDEX });
parameters.Add(new DataParameter { ParameterName = "ENDINDEX", DataType = DbType.String, Value = processSet.PROCESSINDEX });
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = processSet.PRODUCTTYPE });
if (this.BaseSession != null)
{
count = Convert.ToInt32(BaseSession.ExecuteSqlScalar(sql, parameters.ToArray()));
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, parameters.ToArray()));
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工序设置数据层-更新工序顺序(当前工序顺序向后移动,后面的工序顺序依次向前移一位)"
});
throw;
}
}
/// <summary>
/// 更新工序顺序(当前工序顺序向前移动,前面的工序顺序依次向后移一位)
/// </summary>
/// <param name="processSet"></param>
/// <returns></returns>
public int UpdateIndexBackWord(ProcessSet processSet)
{
int count = 0;
string sql = "";
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "UPDATE T_BD_PROCESSSET SET PROCESSINDEX = PROCESSINDEX+1 WHERE PROCESSINDEX BETWEEN @STARTINDEX AND @ENDINDEX AND PRODUCTTYPE=@PRODUCTTYPE";
parameters.Add(new DataParameter { ParameterName = "STARTINDEX", DataType = DbType.String, Value = processSet.PROCESSINDEX });
parameters.Add(new DataParameter { ParameterName = "ENDINDEX", DataType = DbType.String, Value = processSet.OLDPROCESSINDEX });
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = processSet.PRODUCTTYPE });
if (this.BaseSession != null)
{
count = Convert.ToInt32(BaseSession.ExecuteSqlScalar(sql, parameters.ToArray()));
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, parameters.ToArray()));
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工序设置数据层-更新工序顺序(当前工序顺序向后移动,后面的工序顺序依次向前移一位)"
});
throw;
}
}
#endregion
}
}