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

1046 lines
45 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMAPP.FJC.Entity.Injection;
using QMFrameWork.Log;
using QMAPP.FJC.Entity;
using QMAPP.DAL;
namespace QMAPP.FJC.DAL.Injection
{
/// <summary>
/// 模块编号:M3-1
/// 作 用:投料记录数据层
/// 作 者:王丹丹
/// 编写日期:2015年06月05日
///</summary>
public class InjectionRecorderDAL:BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public InjectionRecorder Get(InjectionRecorder model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<InjectionRecorder>(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(InjectionRecorder 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("MATERIALTYPETXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("MATERIALTYPETXT", "MATERIALTYPE");
}
if (page.SortExpression.IndexOf("MACHINETYPETXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("MACHINETYPETXT", "MACHINETYPE");
}
if (page.SortExpression.IndexOf("PROCESSTYPETXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("PROCESSTYPETXT", "PROCESSTYPE");
}
}
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<InjectionRecorder>(sql, parameters.ToArray(), page);
}
return page;
}
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(InjectionRecorder condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT I.PID ");
sqlBuilder.AppendLine(" ,I.MATERIALNAME ");
sqlBuilder.AppendLine(" ,I.MATERIALCODE ");
sqlBuilder.AppendLine(" ,I.MATERIALTYPE ");
sqlBuilder.AppendLine(" ,I.MATERIALBATCH ");
sqlBuilder.AppendLine(" ,I.MACHINETYPE ");
sqlBuilder.AppendLine(" ,I.PROCESSTYPE ");
sqlBuilder.AppendLine(" ,I.MACHINENAME ");
sqlBuilder.AppendLine(" ,I.MACHINECODDE ");
sqlBuilder.AppendLine(" ,I.INJECTIONINDEX ");
sqlBuilder.AppendLine(" ,I.INJECTIONTERMINAL ");
sqlBuilder.AppendLine(" ,I.METERIALWEIGHT ");
sqlBuilder.AppendLine(" ,I.USEDWEIGHTSUM ");
sqlBuilder.AppendLine(" ,I.PRODUCESHIFTNAME ");
sqlBuilder.AppendLine(" ,I.PRODUCESHIFTTCODE ");
sqlBuilder.AppendLine(" ,I.PACKAGENO ");
sqlBuilder.AppendLine(" ,I.PRODUCELINE ");
sqlBuilder.AppendLine(" ,I.MAKEDATE ");
sqlBuilder.AppendLine(" ,I.VALIDDATE ");
sqlBuilder.AppendLine(" ,I.LIMITTIME ");
sqlBuilder.AppendLine(" ,I.CREATEUSER ");
sqlBuilder.AppendLine(" ,I.CREATEDATE ");
sqlBuilder.AppendLine(" ,I.UPDATEUSER ");
sqlBuilder.AppendLine(" ,I.UPDATEDATE ");
sqlBuilder.AppendLine(" ,O.OPERATOR AS CREATEUSERNAME ");
//sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" FROM T_AW_INJECTIONRECORDER I ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_OPERATORINFO O ON O.PID=I.CREATEUSER ");
//sqlBuilder.AppendLine(" LEFT JOIN T_BD_MACHINEINFO M ON M.MACHINECODDE=I.MACHINECODDE ");
//sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=I.CREATEUSER ");
//查询条件
//物料号
if (string.IsNullOrEmpty(condition.MATERIALCODE) == false)
{
whereBuilder.Append(" AND I.MATERIALCODE =@MATERIALCODE");
parameters.Add(new DataParameter { ParameterName = "MATERIALCODE", DataType = DbType.String, Value = condition.MATERIALCODE });
}
if (string.IsNullOrEmpty(condition.MATERIALCODETXT) == false)
{
whereBuilder.Append(" AND I.MATERIALCODE LIKE '%'+" + "@MATERIALCODETXT" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALCODETXT", DataType = DbType.String, Value = condition.MATERIALCODETXT });
}
//物料名称
if (string.IsNullOrEmpty(condition.MATERIALNAME) == false)
{
whereBuilder.Append(" AND I.MATERIALNAME LIKE '%'+" + "@MATERIALNAME" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALNAME", DataType = DbType.String, Value = condition.MATERIALNAME });
}
//物料类别
if (string.IsNullOrEmpty(condition.MATERIALTYPE) == false)
{
whereBuilder.Append(" AND I.MATERIALTYPE = @MATERIALTYPE");
parameters.Add(new DataParameter { ParameterName = "MATERIALTYPE", DataType = DbType.String, Value = condition.MATERIALTYPE });
}
//工序类别
if (string.IsNullOrEmpty(condition.PROCESSTYPE) == false)
{
whereBuilder.Append(" AND I.PROCESSTYPE =@PROCESSTYPE");
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
}
//班次编号
if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false)
{
whereBuilder.Append(" AND I.PRODUCESHIFTTCODE =@PRODUCESHIFTTCODE");
parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编号
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
{
whereBuilder.Append(" AND I.MACHINECODDE =@MACHINECODDE");
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//批次号
if (string.IsNullOrEmpty(condition.MATERIALBATCH) == false)
{
whereBuilder.Append(" AND I.MATERIALBATCH LIKE '%'+" + "@MATERIALBATCH" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALBATCH", DataType = DbType.String, Value = condition.MATERIALBATCH });
}
if (string.IsNullOrEmpty(condition.CREATEUSER) == false)
{
whereBuilder.Append(" AND I.CREATEUSER =" + "@CREATEUSER");
parameters.Add(new DataParameter { ParameterName = "CREATEUSER", DataType = DbType.String, Value = condition.CREATEUSER });
}
if (string.IsNullOrEmpty(condition.CreateDateStart) == false)
{
whereBuilder.Append(" AND I.CREATEDATE >= " + "@CreateDateStart");
parameters.Add(new DataParameter { ParameterName = "CreateDateStart", DataType = DbType.String, Value = condition.CreateDateStart });
}
if (string.IsNullOrEmpty(condition.CreateDateEnd) == false)
{
whereBuilder.Append(" AND I.CREATEDATE <= " + "@CreateDateEnd");
parameters.Add(new DataParameter { ParameterName = "CreateDateEnd", DataType = DbType.String, Value = condition.CreateDateEnd });
}
//搪塑投料记录0 注塑投料记录1
if (string.IsNullOrEmpty(condition.MACHINETYPE) == false)
{
whereBuilder.Append(" AND I.MACHINETYPE =@MACHINETYPE");
parameters.Add(new DataParameter { ParameterName = "MACHINETYPE", DataType = DbType.String, Value = condition.MACHINETYPE });
}
//Web端-搪塑投料记录使用
if (string.IsNullOrEmpty(condition.PROCESSTYPERECORD) == false)
{
whereBuilder.Append(" AND I.PROCESSTYPE = "+ EnumGeter.ProcessType.tangsu.GetHashCode().ToString()+"");
}
//Web端-注塑投料记录使用
if (string.IsNullOrEmpty(condition.PROCESSTYPES) == false)
{
whereBuilder.Append(" AND I.PROCESSTYPE IN ('" + condition.PROCESSTYPES.Replace(",", "','") + "')");
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取最后的投料信息
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
private string GetLastInjectionRecorderSql(InjectionRecorder condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT top 1 * ");
sqlBuilder.AppendLine(" FROM T_AW_INJECTIONRECORDER I ");
//查询条件
//物料号
if (string.IsNullOrEmpty(condition.MATERIALCODE) == false)
{
whereBuilder.Append(" AND I.MATERIALCODE LIKE '%'+" + "@MATERIALCODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALCODE", DataType = DbType.String, Value = condition.MATERIALCODE });
}
//物料名称
if (string.IsNullOrEmpty(condition.MATERIALNAME) == false)
{
whereBuilder.Append(" AND I.MATERIALNAME LIKE '%'+" + "@MATERIALNAME" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALNAME", DataType = DbType.String, Value = condition.MATERIALNAME });
}
//物料类别
if (string.IsNullOrEmpty(condition.MATERIALTYPE) == false)
{
whereBuilder.Append(" AND I.MATERIALTYPE = @MATERIALTYPE");
parameters.Add(new DataParameter { ParameterName = "MATERIALTYPE", DataType = DbType.String, Value = condition.MATERIALTYPE });
}
if (condition.INJECTIONTERMINAL>0)
{
whereBuilder.Append(" AND I.INJECTIONTERMINAL = @INJECTIONTERMINAL");
parameters.Add(new DataParameter { ParameterName = "INJECTIONTERMINAL", DataType = DbType.String, Value = condition.INJECTIONTERMINAL });
}
//工序类别
if (string.IsNullOrEmpty(condition.PROCESSTYPE) == false)
{
whereBuilder.Append(" AND I.PROCESSTYPE =@PROCESSTYPE");
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
}
//班次编号
if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false)
{
whereBuilder.Append(" AND I.PRODUCESHIFTTCODE =@PRODUCESHIFTTCODE");
parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编号
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
{
whereBuilder.Append(" AND I.MACHINECODDE =@MACHINECODDE");
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//批次号
if (string.IsNullOrEmpty(condition.MATERIALBATCH) == false)
{
whereBuilder.Append(" AND I.MATERIALBATCH LIKE '%'+" + "@MATERIALBATCH" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALBATCH", DataType = DbType.String, Value = condition.MATERIALBATCH });
}
if (string.IsNullOrEmpty(condition.CREATEUSER) == false)
{
whereBuilder.Append(" AND I.CREATEUSER =" + "@CREATEUSER");
parameters.Add(new DataParameter { ParameterName = "CREATEUSER", DataType = DbType.String, Value = condition.CREATEUSER });
}
if (string.IsNullOrEmpty(condition.CreateDateStart) == false)
{
whereBuilder.Append(" AND I.CREATEDATE >= " + "@CreateDateStart");
parameters.Add(new DataParameter { ParameterName = "CreateDateStart", DataType = DbType.String, Value = condition.CreateDateStart });
}
if (string.IsNullOrEmpty(condition.CreateDateEnd) == false)
{
whereBuilder.Append(" AND I.CREATEDATE <= " + "@CreateDateEnd");
parameters.Add(new DataParameter { ParameterName = "CreateDateEnd", DataType = DbType.String, Value = condition.CreateDateEnd });
}
//搪塑投料记录0 注塑投料记录1
if (string.IsNullOrEmpty(condition.MACHINETYPE) == false)
{
whereBuilder.Append(" AND I.MACHINETYPE =@MACHINETYPE");
parameters.Add(new DataParameter { ParameterName = "MACHINETYPE", DataType = DbType.String, Value = condition.MACHINETYPE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(" order by CREATEDATE desc");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(InjectionRecorder model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
count = BaseSession.Insert<InjectionRecorder>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<InjectionRecorder>(model);
}
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(InjectionRecorder model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
this.BaseSession.Update<InjectionRecorder>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<InjectionRecorder>(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 UpdateProductInjection(InjectionRecorder model)
{
int count = 0;
string sql = "";
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "UPDATE T_AW_PRODUCTINJECTION SET MATERIALBATCH=@MATERIALBATCH , UPDATEDATE=@UPDATEDATE WHERE IPID=@IPID";
parameters.Add(new DataParameter { ParameterName = "MATERIALBATCH", DataType = DbType.String, Value = model.MATERIALBATCH });
parameters.Add(new DataParameter { ParameterName = "IPID", DataType = DbType.String, Value = model.PID });
parameters.Add(new DataParameter { ParameterName = "UPDATEDATE", DataType = DbType.String, Value = model.UPDATEDATE });
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
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(InjectionRecorder model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE T_AW_INJECTIONRECORDER ");
sqlBuilder.Append("WHERE PID = @PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "原材料投料-逻辑删除"
});
throw;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsInjectionRecorder(InjectionRecorder model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(PID) FROM T_AW_INJECTIONRECORDER");
if (string.IsNullOrEmpty(model.PID) == false)
{
whereBuilder.Append(" AND PID =@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
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)
{
throw ex;
}
}
#endregion
#region 判断零件投料关联表信息是否存在,如果存在不允许删除
/// <summary>
/// 判断零件投料关联表信息是否存在,如果存在不允许删除
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsProductInJection(string iPid)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(IPID) FROM T_AW_PRODUCTINJECTION");
if (string.IsNullOrEmpty(iPid) == false)
{
whereBuilder.Append(" AND IPID =@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = iPid });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
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 获取最后一次的投料信息
public List<InjectionRecorder> GetLastRecorder(InjectionRecorder condition)
{
List<InjectionRecorder> injectRecorderList = new List<InjectionRecorder>();
List<DataParameter> parameters = new List<DataParameter>();
string sql = "";
sql = this.GetLastInjectionRecorderSql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
injectRecorderList = session.GetList<InjectionRecorder>(sql, parameters.ToArray()).ToList<InjectionRecorder>();
}
return injectRecorderList;
}
/// <summary>
/// 获取浇注设备的最后投料信息
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<InjectionRecorder> GetCastLastRecorder(InjectionRecorder condition)
{
List<InjectionRecorder> injectRecorderList = new List<InjectionRecorder>();
List<DataParameter> parameters = new List<DataParameter>();
string sql = string.Format(@"select t.* from T_AW_INJECTIONRECORDER t,
(SELECT max(I.CREATEDATE) as CREATEDATE,MATERIALCODE FROM T_AW_INJECTIONRECORDER I
where MACHINECODDE='{0}' group by MATERIALCODE)temp1
where t.MACHINECODDE='{0}' and t.CREATEDATE=temp1.CREATEDATE
and t.MATERIALCODE=temp1.MATERIALCODE", condition.MACHINECODDE);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
injectRecorderList = session.GetList<InjectionRecorder>(sql, parameters.ToArray()).ToList<InjectionRecorder>();
}
return injectRecorderList;
}
#endregion
#region WEB 搪塑、注塑投料记录
#region 获取搪塑、注塑投料记录SQL
/// <summary>
/// 获取搪塑、注塑投料记录SQL
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetInjectionRecordSql(InjectionRecorder condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT I.PID ");
sqlBuilder.AppendLine(" ,I.MATERIALNAME ");
sqlBuilder.AppendLine(" ,I.MATERIALCODE ");
sqlBuilder.AppendLine(" ,I.MATERIALTYPE ");
sqlBuilder.AppendLine(" ,I.MATERIALBATCH ");
sqlBuilder.AppendLine(" ,I.MACHINETYPE ");
sqlBuilder.AppendLine(" ,I.PROCESSTYPE ");
sqlBuilder.AppendLine(" ,I.MACHINENAME ");
sqlBuilder.AppendLine(" ,I.MACHINECODDE ");
sqlBuilder.AppendLine(" ,I.INJECTIONINDEX ");
sqlBuilder.AppendLine(" ,I.INJECTIONTERMINAL ");
sqlBuilder.AppendLine(" ,I.METERIALWEIGHT ");
sqlBuilder.AppendLine(" ,I.USEDWEIGHTSUM ");
sqlBuilder.AppendLine(" ,I.PRODUCESHIFTNAME ");
sqlBuilder.AppendLine(" ,I.PRODUCESHIFTTCODE ");
sqlBuilder.AppendLine(" ,I.PRODUCELINE ");
sqlBuilder.AppendLine(" ,I.PACKAGENO ");
sqlBuilder.AppendLine(" ,I.MAKEDATE ");
sqlBuilder.AppendLine(" ,I.VALIDDATE ");
sqlBuilder.AppendLine(" ,I.CREATEUSER ");
sqlBuilder.AppendLine(" ,I.CREATEDATE ");
sqlBuilder.AppendLine(" ,I.UPDATEUSER ");
sqlBuilder.AppendLine(" ,I.UPDATEDATE ");
sqlBuilder.AppendLine(" ,O.OPERATOR AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" FROM ");
sqlBuilder.AppendLine(" T_AW_INJECTIONRECORDER I ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_OPERATORINFO O ON O.pid=I.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M ON M.MATERIAL_CODE=I.MATERIALCODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE ");
#region 查询条件
//查询条件
//Web端-搪塑投料记录使用
if (string.IsNullOrEmpty(condition.PROCESSTYPERECORD) == false)
{
whereBuilder.Append(" AND I.PROCESSTYPE = " + EnumGeter.ProcessType.tangsu.GetHashCode().ToString() + "");
}
//Web端-注塑投料记录使用
if (string.IsNullOrEmpty(condition.PROCESSTYPES) == false)
{
whereBuilder.Append(" AND I.PROCESSTYPE IN ('" + condition.PROCESSTYPES.Replace(",", "','") + "')");
}
//工序类别
if (string.IsNullOrEmpty(condition.PROCESSTYPE) == false)
{
whereBuilder.Append(" AND I.PROCESSTYPE =@PROCESSTYPE");
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
}
//物料号
if (string.IsNullOrEmpty(condition.MATERIALCODE) == false)
{
whereBuilder.Append(" AND I.MATERIALCODE LIKE '%'+" + "@MATERIALCODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALCODE", DataType = DbType.String, Value = condition.MATERIALCODE });
}
//物料号
if (string.IsNullOrEmpty(condition.MATERIALCODETXT) == false)
{
whereBuilder.Append(" AND I.MATERIALCODE LIKE '%'+" + "@MATERIALCODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALCODE", DataType = DbType.String, Value = condition.MATERIALCODETXT });
}
//物料名称
if (string.IsNullOrEmpty(condition.MATERIALNAME) == false)
{
whereBuilder.Append(" AND I.MATERIALNAME LIKE '%'+" + "@MATERIALNAME" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALNAME", DataType = DbType.String, Value = condition.MATERIALNAME });
}
//物料类别
if (string.IsNullOrEmpty(condition.MATERIALTYPE) == false)
{
whereBuilder.Append(" AND I.MATERIALTYPE = @MATERIALTYPE");
parameters.Add(new DataParameter { ParameterName = "MATERIALTYPE", DataType = DbType.String, Value = condition.MATERIALTYPE });
}
//班次名称
if (string.IsNullOrEmpty(condition.PRODUCESHIFTNAME) == false)
{
whereBuilder.Append(" AND I.PRODUCESHIFTNAME =@PRODUCESHIFTNAME");
parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTNAME", DataType = DbType.String, Value = condition.PRODUCESHIFTNAME });
}
//班次编号
if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false)
{
whereBuilder.Append(" AND I.PRODUCESHIFTTCODE =@PRODUCESHIFTTCODE");
parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
}
//设备编号
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
{
whereBuilder.Append(" AND I.MACHINECODDE =@MACHINECODDE");
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
//批次号
if (string.IsNullOrEmpty(condition.MATERIALBATCH) == false)
{
whereBuilder.Append(" AND I.MATERIALBATCH LIKE '%'+" + "@MATERIALBATCH" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIALBATCH", DataType = DbType.String, Value = condition.MATERIALBATCH });
}
if (string.IsNullOrEmpty(condition.CreateDateStart) == false)
{
whereBuilder.Append(" AND I.CREATEDATE >= " + "@CreateDateStart");
parameters.Add(new DataParameter { ParameterName = "CreateDateStart", DataType = DbType.String, Value = condition.CreateDateStart });
}
if (string.IsNullOrEmpty(condition.CreateDateEnd) == false)
{
whereBuilder.Append(" AND I.CREATEDATE <= " + "@CreateDateEnd");
parameters.Add(new DataParameter { ParameterName = "CreateDateEnd", DataType = DbType.String, Value = condition.CreateDateEnd });
}
//whereBuilder.Append(" AND MC.MATERIAL_ATTRIBUTE = '3' ");
#endregion
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="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetInjectionRecordList(InjectionRecorder condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetInjectionRecordSql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
else
{
//按照标题排序
if (page.SortExpression.IndexOf("MATERIALTYPETXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("MATERIALTYPETXT", "MATERIALTYPE");
}
if (page.SortExpression.IndexOf("MACHINETYPETXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("MACHINETYPETXT", "MACHINETYPE");
}
if (page.SortExpression.IndexOf("PROCESSTYPETXT") > -1)
{
page.SortExpression = page.SortExpression.Replace("PROCESSTYPETXT", "PROCESSTYPE");
}
}
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<InjectionRecorder>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "原材料投料-获取搪塑、注塑投料记录列表"
});
throw;
}
}
#endregion
#endregion
/// <summary>
///
/// </summary>
/// <param name="recorders"></param>
/// <returns></returns>
public bool CheckInjectMaterial(InjectionInfo recorders)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(PID) FROM T_AW_INJECTWITHMATERIAL");
if (string.IsNullOrEmpty(recorders.CHARINGBARREL_CODE) == false)
{
whereBuilder.Append(" AND CHARINGBARREL_CODE =@CHARINGBARREL_CODE ");
parameters.Add(new DataParameter { ParameterName = "CHARINGBARREL_CODE", DataType = DbType.String, Value = recorders.CHARINGBARREL_CODE });
}
if (string.IsNullOrEmpty(recorders.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND MATERIAL_CODE =@MATERIAL_CODE ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = recorders.MATERIAL_CODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
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;
}
}
public int InsertNew(InjectionInfo model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
count = BaseSession.Insert<InjectionInfo>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<InjectionInfo>(model);
}
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 查验是否存在此批次物料(楼上)
/// </summary>
/// <param name="recorders"></param>
/// <returns></returns>
public InjectionInfo GetInjectMaterial(InjectionInfo recorders)
{
InjectionInfo info = new InjectionInfo();
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sqlBuilder.Append("SELECT * FROM T_AW_INJECTIONINFO");
if (string.IsNullOrEmpty(recorders.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND MATERIAL_CODE =@MATERIAL_CODE ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = recorders.MATERIAL_CODE });
}
if (string.IsNullOrEmpty(recorders.MATERIALBATCH) == false)
{
whereBuilder.Append(" AND MATERIALBATCH =@MATERIALBATCH ");
parameters.Add(new DataParameter { ParameterName = "MATERIALBATCH", DataType = DbType.String, Value = recorders.MATERIALBATCH });
}
if (string.IsNullOrEmpty(recorders.CHARINGBARREL_CODE) == false)
{
whereBuilder.Append(" AND CHARINGBARREL_CODE =@CHARINGBARREL_CODE ");
parameters.Add(new DataParameter { ParameterName = "CHARINGBARREL_CODE", DataType = DbType.String, Value = recorders.CHARINGBARREL_CODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(" ORDER BY CREATEDATE DESC");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
info = session.Get<InjectionInfo>(sqlBuilder.ToString(), parameters.ToArray());
}
return info;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "原材料投料-校验绑定物料"
});
throw;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public List<InjectHole> GetInjectHoleList()
{
List<InjectHole> list = new List<InjectHole>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "select * from T_AW_INJECTHOLE";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<InjectHole>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取浇注设备的最后投料信息 直接根据物料查
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<InjectionRecorder> GetCastLastRecorderWithMAterial(InjectionRecorder condition)
{
List<InjectionRecorder> injectRecorderList = new List<InjectionRecorder>();
List<DataParameter> parameters = new List<DataParameter>();
string sql = string.Format(@"select t.* from T_AW_INJECTIONRECORDER t,
(SELECT max(I.CREATEDATE) as CREATEDATE,MATERIALCODE FROM T_AW_INJECTIONRECORDER I
where MATERIALCODE='{0}' group by MATERIALCODE)temp1
where t.MATERIALCODE='{0}' and t.CREATEDATE=temp1.CREATEDATE
and t.MATERIALCODE=temp1.MATERIALCODE", condition.MATERIALCODE);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
injectRecorderList = session.GetList<InjectionRecorder>(sql, parameters.ToArray()).ToList<InjectionRecorder>();
}
return injectRecorderList;
}
}
}