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.
356 lines
13 KiB
356 lines
13 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 System.Data;
|
|
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
/// <summary>
|
|
/// 模块编号:M2-9
|
|
/// 作 用:投料配置规则数据层
|
|
/// 作 者:王丹丹
|
|
/// 编写日期:2015年06月03日
|
|
///</summary>
|
|
public class ProductMderuleDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public ProductMderule Get(ProductMderule model)
|
|
{
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<ProductMderule>(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(ProductMderule 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("COLORCODETXT") > -1)
|
|
{
|
|
page.SortExpression = page.SortExpression.Replace("COLORCODETXT", "COLORCODE");
|
|
}
|
|
if (page.SortExpression.IndexOf("HBTXT") > -1)
|
|
{
|
|
page.SortExpression = page.SortExpression.Replace("HBTXT", "HB");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<ProductMderule>(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<ProductMderule> GetList(ProductMderule condition)
|
|
{
|
|
List<ProductMderule> list = new List<ProductMderule>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProductMderule>(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(ProductMderule condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT PM.PID ");
|
|
sqlBuilder.AppendLine(" ,PM.PRODUCTTYPE ");
|
|
sqlBuilder.AppendLine(" ,PM.COLORCODE ");
|
|
sqlBuilder.AppendLine(" ,PM.HB ");
|
|
sqlBuilder.AppendLine(" ,PM.INJECTIONINDEX ");
|
|
sqlBuilder.AppendLine(" ,PM.INJECTIONTERMINAL ");
|
|
sqlBuilder.AppendLine(" ,PM.USEDWEIGHT ");
|
|
sqlBuilder.AppendLine(" ,PM.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,PM.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,PM.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,PM.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" FROM T_BD_PRODUCTMDERULE PM ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=PM.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=PM.UPDATEUSER ");
|
|
|
|
|
|
//查询条件
|
|
//颜色码
|
|
if (string.IsNullOrEmpty(condition.COLORCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PM.COLORCODE = @COLORCODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "COLORCODE", DataType = DbType.String, Value = condition.COLORCODE });
|
|
}
|
|
//高低配
|
|
if (condition.HB != null && string.IsNullOrEmpty(condition.HB.ToString()) == false)
|
|
{
|
|
whereBuilder.Append(" AND PM.HB = @HB ");
|
|
parameters.Add(new DataParameter { ParameterName = "HB", DataType = DbType.String, Value = condition.HB });
|
|
}
|
|
//搪塑上料口
|
|
if (string.IsNullOrEmpty(condition.INJECTIONTERMINALSEARCH) == false)
|
|
{
|
|
whereBuilder.Append(" AND PM.INJECTIONTERMINAL = @INJECTIONTERMINAL ");
|
|
parameters.Add(new DataParameter { ParameterName = "INJECTIONTERMINAL", DataType = DbType.String, Value = condition.INJECTIONTERMINALSEARCH });
|
|
}
|
|
//搪塑注料顺序
|
|
if (string.IsNullOrEmpty(condition.INJECTIONINDEXSEARCH) == false)
|
|
{
|
|
whereBuilder.Append(" AND PM.INJECTIONINDEX = @INJECTIONINDEX ");
|
|
parameters.Add(new DataParameter { ParameterName = "INJECTIONINDEX", DataType = DbType.String, Value = condition.INJECTIONINDEXSEARCH });
|
|
}
|
|
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 ExistsProductMderule(ProductMderule 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_PRODUCTMDERULE WHERE PID <> @PID AND INJECTIONTERMINAL=@INJECTIONTERMINAL AND INJECTIONINDEX=@INJECTIONINDEX and COLORCODE=@COLORCODE and HB=@HB";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "INJECTIONTERMINAL", Value = model.INJECTIONTERMINAL },
|
|
new DataParameter { ParameterName = "INJECTIONINDEX", Value = model.INJECTIONINDEX },
|
|
new DataParameter { ParameterName = "COLORCODE", Value = model.COLORCODE },
|
|
new DataParameter { ParameterName = "HB", Value = model.HB }));
|
|
}
|
|
|
|
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(ProductMderule model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<ProductMderule>(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(ProductMderule model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<ProductMderule>(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(ProductMderule model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
count = session.Delete<ProductMderule>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "投料配置规则数据层-删除信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|