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

230 lines
8.7 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMFrameWork.Log;
using System.Data;
using QMAPP.DAL;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 模块名称:物料版本
/// 作 者:郭兆福
/// 编写日期:2017年05月10日
/// </summary>
public class MaterialRouteDAL : BaseDAL
{
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name=model"">物料号信息</param>
/// <returns>插入行数</returns>
public int Insert(MaterialRoute model)
{
int count = 0;
try
{
if (BaseSession != null)
{
//插入基本信息
count = BaseSession.Insert<MaterialRoute>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<MaterialRoute>(model);
}
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料加工工艺数据层-插入信息");
throw ex;
}
}
#endregion
#region 删除信息
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">物料号信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(MaterialRoute model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
//删除基本信息
sqlBuilder.Append("UPDATE T_MD_MATERIAL_ROUTE ");
sqlBuilder.Append("SET FLGDEL = '1'");
sqlBuilder.Append("WHERE PID = @PID");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
if (BaseSession != null)
{
//删除基本信息
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray());
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
count = session.ExecuteSql(sqlChange, parameters.ToArray());
}
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料加工工艺数据层-删除信息");
throw ex;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">Bom信息(ID)</param>
/// <returns>删除个数</returns>
public int DeleteMaterialRouteByPbomId(string pid)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder whereBuilder = new StringBuilder();
int count = 0;
try
{
//构成查询语句
sqlBuilder.AppendLine(" UPDATE T_MD_MATERIAL_ROUTE SET FLGDEL = '1' WHERE MATERIAL_CODE IN (SELECT T.MATERIAL_CODE FROM T_MD_PBOM T WHERE T.PID = @PID)");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = pid });
if (this.BaseSession != null)
{
string sqlChange = base.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
//删除基本信息
count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray());
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = base.ChangeSqlByDB(sqlBuilder.ToString(), session);
//删除基本信息
count = session.ExecuteSql(sqlChange, parameters.ToArray());
}
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "Bom信息维护数据层-删除BOM详细信息");
throw ex;
}
}
#endregion
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public MaterialRoute Get(MaterialRoute model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_MD_MATERIAL_ROUTE WHERE FLGDEL='0' ";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
if (string.IsNullOrEmpty(model.MATERIAL_CODE) == false)
{
sql += " AND MATERIAL_CODE = @MATERIAL_CODE";
parameters.Add(new DataParameter("MATERIAL_CODE", model.MATERIAL_CODE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<MaterialRoute>(sqlChange, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料加工工艺数据层-获取信息");
throw ex;
}
}
#endregion
#region 根据工序判断物料是否是产品
/// <summary>
/// 根据工序判断物料是否是产品
/// </summary>
/// <param name="materialCode">物料号</param>
/// <param name="workcellCode">工序</param>
/// <returns>true:是 false:否</returns>
public bool IsProductMatrial(string materialCode, string workcellCode)
{
int count = 0;
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sqlBuilder.Append(" SELECT COUNT(1)");
sqlBuilder.Append(" FROM T_MD_MATERIAL_ROUTE MR ");
sqlBuilder.Append(" JOIN T_MD_PROCESS_ROUTE_WORKCELL RW ");
sqlBuilder.Append(" ON MR.ROUTE_CODE = RW.ROUTE_CODE ");
sqlBuilder.Append(" AND RW.FLGDEL = '0' ");
sqlBuilder.Append(" AND MR.FLGDEL = '0' ");
sqlBuilder.Append(" AND MR.MATERIAL_CODE = @MATERIAL_CODE ");
sqlBuilder.Append(" AND RW.WORKCELL_CODE = @WORKCELL_CODE ");
parameters.Add(new DataParameter("MATERIAL_CODE", materialCode));
parameters.Add(new DataParameter("WORKCELL_CODE", workcellCode));
if (null != BaseSession)
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
//获取信息
count = Convert.ToInt32(BaseSession.ExecuteSqlScalar(sqlChange, parameters.ToArray()));
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
//获取信息
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, parameters.ToArray()));
}
}
return count == 0 ? false : true;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "根据工序判断物料是否是产品!");
throw ex;
}
}
#endregion
}
}