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

375 lines
14 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;
using QMAPP.FJC.Entity.Basic;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 模块名称:加工参数
/// 作 者:来洋
/// 编写日期:2018年03月30日
/// </summary>
public class ParameterConfigEntityDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public ParameterConfigEntity Get(ParameterConfigEntity model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_BD_PARAMETERCONFIG WHERE '1'='1'";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
if (string.IsNullOrEmpty(model.MACHINECODDE) == false)
{
sql += " AND MACHINECODDE = @MACHINECODDE";
parameters.Add(new DataParameter("MACHINECODDE", model.MACHINECODDE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<ParameterConfigEntity>(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(ParameterConfigEntity condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "MACHINECODDE ASC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<ParameterConfigEntity>(sqlChange, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "加工参数设定-获取列表");
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(ParameterConfigEntity condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" select P.PID, P.MACHINECODDE ");
sqlBuilder.AppendLine(" ,M.MACHINENAME ");
sqlBuilder.AppendLine(" ,P.MOLDNUMBER ");
sqlBuilder.AppendLine(" ,P.COLUMNTYPE ");
sqlBuilder.AppendLine(" ,P.COLUMNCODE ");
sqlBuilder.AppendLine(" ,P.CONNECTIONSTRING ");
sqlBuilder.AppendLine(" ,P.DEALTYPE");
sqlBuilder.AppendLine(" ,P.PRODUCELINE ");
sqlBuilder.AppendLine(" ,P.TABLENAME ");
sqlBuilder.AppendLine(" ,P.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
sqlBuilder.AppendLine(" from T_BD_PARAMETERCONFIG P ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_MACHINEINFO M ON P.MACHINECODDE = M.MACHINECODDE ");
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.MACHINECODDE) == false)
{
whereBuilder.Append(" AND P.MACHINECODDE = @MACHINECODDE ");
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
if (string.IsNullOrEmpty(condition.MACHINENAME) == false)
{
whereBuilder.Append(" AND MACHINENAME = @MACHINENAME ");
parameters.Add(new DataParameter { ParameterName = "MACHINENAME", DataType = DbType.String, Value = condition.MACHINENAME });
}
if (string.IsNullOrEmpty(condition.MOLDNUMBER) == false)
{
whereBuilder.Append(" AND MOLDNUMBER = @MOLDNUMBER ");
parameters.Add(new DataParameter { ParameterName = "MOLDNUMBER", DataType = DbType.String, Value = condition.MOLDNUMBER });
}
if (string.IsNullOrEmpty(condition.COLUMNCODE) == false)
{
whereBuilder.Append(" AND COLUMNCODE = @COLUMNCODE ");
parameters.Add(new DataParameter { ParameterName = "COLUMNCODE", DataType = DbType.String, Value = condition.COLUMNCODE });
}
if (string.IsNullOrEmpty(condition.COLUMNTYPE) == false)
{
whereBuilder.Append(" AND COLUMNTYPE = @COLUMNTYPE ");
parameters.Add(new DataParameter { ParameterName = "COLUMNTYPE", DataType = DbType.String, Value = condition.COLUMNTYPE });
}
if (string.IsNullOrEmpty(condition.PRODUCELINE) == false)
{
whereBuilder.Append(" AND P.PRODUCELINE = @PRODUCELINE ");
parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE });
}
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 ExistsParameterConfigEntity(ParameterConfigEntity model)
{
string PID = "";
int count = 0;
StringBuilder sqlBuilder = new StringBuilder();
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_BD_PARAMETERCONFIG ");
sqlBuilder.AppendLine(" WHERE PID <> @PID AND FACTORY_CODE=@FACTORY_CODE AND MACHINECODDE=@MACHINECODDE");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange,
new DataParameter("PID", PID),
new DataParameter("FACTORY_CODE", model.FACTORY_CODE),
new DataParameter { ParameterName = "MACHINECODDE", Value = model.MACHINECODDE }));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
//#region 判断设备编码是否被用
///// <summary>
///// 判断设备编号是否被用
///// </summary>
///// <param name="model">工位</param>
///// <returns>true:已用;false:未用。</returns>
//public bool IsUsedParameterConfigEntityCode(string[] pid)
//{
// int count = 0;
// StringBuilder sqlBuilder = new StringBuilder();
// try
// {
// List<DataParameter> paramList = new List<DataParameter>();
// sqlBuilder.Append(" SELECT COUNT(*) FROM T_BD_PARAMETERCONFIG WHERE ");
// sqlBuilder.Append(" MACHINECODDE IN ( ");
// sqlBuilder.Append(" SELECT MACHINECODDE FROM T_BD_PARAMETERCONFIG ");
// for (int i = 0; i < pid.Length; i++)
// {
// if (i == 0)
// {
// sqlBuilder.Append(" WHERE PID IN (");
// }
// else
// {
// sqlBuilder.Append(" ,");
// }
// string param = "PID" + i.ToString();
// sqlBuilder.Append(" @").Append(param);
// paramList.Add(new DataParameter(param, DbType.String, pid[i]));
// if (i == pid.Length - 1)
// {
// sqlBuilder.Append(" ) ");
// }
// }
// sqlBuilder.Append(" ) ");
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// // 对应多种数据库
// string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
// count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, paramList.ToArray()));
// }
// return count == 0 ? false : true;
// }
// catch (Exception ex)
// {
// RecordExceptionLog(ex, "判断设备编号是否被用");
// throw ex;
// }
//}
//#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(ParameterConfigEntity model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<ParameterConfigEntity>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "插入信息");
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(ParameterConfigEntity model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<ParameterConfigEntity>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "更新信息");
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">物料号信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(ParameterConfigEntity model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<ParameterConfigEntity>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "删除");
throw ex;
}
}
#endregion
#region 根据设备编码查找设备名称
/// <summary>
/// 根据设备编码查找设备名称
/// </summary>
/// <returns></returns>
public MachineInfo GetCoddeByName(string machinecodde)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = "SELECT * FROM [T_BD_MACHINEINFO] WHERE MACHINECODDE=@machinecodde";
var machine = session.Get<MachineInfo>(sql, new DataParameter("machinecodde", machinecodde));
return machine;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}