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

426 lines
16 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 QMAPP.DAL;
using System.Data;
namespace QMAPP.FJC.DAL.Basic
{
public class WorkCenterDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public WorkCenter Get(WorkCenter model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_BD_WORKCENTER WHERE '1'='1'";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
if (string.IsNullOrEmpty(model.WORKCENTER_CODE) == false)
{
sql += " AND WORKCENTER_CODE = @WORKCENTER_CODE";
parameters.Add(new DataParameter("WORKCENTER_CODE", model.WORKCENTER_CODE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<WorkCenter>(sql, parameters.ToArray());
}
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(WorkCenter condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "WORKCENTER_CODE ASC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<WorkCenter>(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<WorkCenter> GetList(WorkCenter condition)
{
List<WorkCenter> list = new List<WorkCenter>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<WorkCenter>(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(WorkCenter condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT W.PID ");
sqlBuilder.AppendLine(" ,W.FACTORY_PID ");
sqlBuilder.AppendLine(" ,W.WORKCENTER_CODE ");
sqlBuilder.AppendLine(" ,W.WORKCENTER_NAME ");
sqlBuilder.AppendLine(" ,PL.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,PL.FACTORY_NAME ");
sqlBuilder.AppendLine(" ,W.REMARK ");
sqlBuilder.AppendLine(" ,W.FLAGDEL ");
sqlBuilder.AppendLine(" ,W.CREATEUSR ");
sqlBuilder.AppendLine(" ,W.CREATEDATE ");
sqlBuilder.AppendLine(" ,W.UPDATEUSR ");
sqlBuilder.AppendLine(" ,W.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" FROM T_BD_WORKCENTER W ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_FACTORY PL ON PL.PID=W.FACTORY_PID ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=W.CREATEUSR ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=W.UPDATEUSR ");
whereBuilder.Append(" AND W.FLAGDEL='0'");
//查询条件
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
{
whereBuilder.Append(" AND WORKCENTER_CODE = @WORKCENTER_CODE ");
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
if (string.IsNullOrEmpty(condition.WORKCENTER_NAME) == false)
{
whereBuilder.Append(" AND W.WORKCENTER_NAME = @WORKCENTER_NAME ");
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_NAME", DataType = DbType.String, Value = condition.WORKCENTER_NAME });
}
if (string.IsNullOrEmpty(condition.FACTORY_PID) == false)
{
whereBuilder.Append(" AND W.FACTORY_PID = @FACTORY_PID ");
parameters.Add(new DataParameter { ParameterName = "FACTORY_PID", DataType = DbType.String, Value = condition.FACTORY_PID });
}
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 ExistsWorkCenter(WorkCenter 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_WORKCENTER ");
sqlBuilder.AppendLine(" WHERE PID <> @PID AND WORKCENTER_CODE=@WORKCENTER_CODE");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(),
new DataParameter("PID", PID),
new DataParameter { ParameterName = "WORKCENTER_CODE", Value = model.WORKCENTER_CODE }));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(WorkCenter model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WorkCenter>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(WorkCenter model)
{
string sql = null;
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//更新基本信息
count = session.Update<WorkCenter>(model);
////更新明细信息
//sql = "DELETE FROM T_MD_EQUIPMENT WHERE WORKCENTER_PID = @WORKCENTER_PID";
//session.ExecuteSql(sql, new DataParameter("WORKCENTER_PID", model.PID));
//if (model.Details != null)
// session.Insert<Equipment>(model.Details);
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
//提交事务
public int Delete(WorkCenter model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
string sql = null;
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//删除基本信息
sqlBuilder.Append("UPDATE T_BD_WORKCENTER ");
sqlBuilder.Append("SET FLAGDEL = '1'");
sqlBuilder.Append("WHERE PID = @PID");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
//删除
//sql = "UPDATE T_BD_MACHINEINFO SET FLAGDEL = '1' WHERE WORKCENTER_PID = @WORKCENTER_PID";
//session.ExecuteSql(sql, new DataParameter("WORKCENTER_PID", model.PID));
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 工作中心下拉
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<WorkCenter> GetWorkCenterList(WorkCenter condition)
{
List<WorkCenter> list = new List<WorkCenter>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<WorkCenter>(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>
// /// <returns>用户与区域关联信息</returns>
// public List<WcWithEquipment> GetWcWithEquipmentList(WcWithEquipment equipment)
// {
// StringBuilder sqlBuilder = new StringBuilder();
// string sql = null;
// List<DataParameter> parameters = new List<DataParameter>();
// List<WcWithEquipment> tmpuser = new List<WcWithEquipment>();
// try
// {
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// //获取信息
// sqlBuilder.Append(@" SELECT E.* FROM T_MD_WCWITHEQUIPMENT E
// WHERE E.WORKCENTERPID=@WORKCENTERPID ");
// parameters.Add(new DataParameter { ParameterName = "WORKCENTERPID", DataType = DbType.String, Value = equipment.WORKCENTERPID });
// sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
// tmpuser = session.GetList<WcWithEquipment>(sql, parameters.ToArray()).ToList();
// }
// return tmpuser;
// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// private string ChangeSqlByDB(string p, IDataSession session)
// {
// throw new NotImplementedException();
// }
// #endregion
//#region 获取工作中心编码、名称
///// <summary>
///// 获取工作中心编码、名称
///// </summary>
///// <param name="workOrder"></param>
///// <returns></returns>
//public WorkCenter Getworkcenter(WorkOrder workOrder)
//{
// WorkCenter workcenter = new WorkCenter();
// try
// {
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// workcenter = session.Get(new WorkCenter() { PID = workOrder.WORKCENTER_PID });
// }
// return workcenter;
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
//#endregion
}
}