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 { /// /// 模块编号:M3-1 /// 作 用:投料记录数据层 /// 作 者:王丹丹 /// 编写日期:2015年06月05日 /// public class InjectionRecorderDAL:BaseDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public InjectionRecorder Get(InjectionRecorder model) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 model = session.Get(model); } return model; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "原材料投料-获取信息" }); throw; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(InjectionRecorder condition, DataPage page) { string sql = null; List parameters = new List(); 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(sql, parameters.ToArray(), page); } return page; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "原材料投料-获取列表" }); throw; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(InjectionRecorder condition, ref List 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; } } /// /// 获取最后的投料信息 /// /// /// /// private string GetLastInjectionRecorderSql(InjectionRecorder condition, ref List 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 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public int Insert(InjectionRecorder model) { int count = 0; try { if (this.BaseSession != null) { count = BaseSession.Insert(model); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(model); } } return count; } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public int Update(InjectionRecorder model) { int count = 0; try { if (this.BaseSession != null) { this.BaseSession.Update(model); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { //更新基本信息 count = session.Update(model); } } return count; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "原材料投料-更新信息" }); throw; } } #endregion #region 更新零件投料关联表 /// /// 更新零件投料关联表 /// /// /// 更新行数 public int UpdateProductInjection(InjectionRecorder model) { int count = 0; string sql = ""; List parameters = new List(); 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 删除 /// /// 删除信息 /// /// /// 删除个数 public int Delete(InjectionRecorder model) { StringBuilder sqlBuilder = new StringBuilder(); List parameters = new List(); 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 信息是否重复 /// /// 判断名称是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsInjectionRecorder(InjectionRecorder model) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); 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 判断零件投料关联表信息是否存在,如果存在不允许删除 /// /// 判断零件投料关联表信息是否存在,如果存在不允许删除 /// /// /// true:已存在;fasel:不存在。 public bool ExistsProductInJection(string iPid) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); 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 GetLastRecorder(InjectionRecorder condition) { List injectRecorderList = new List(); List parameters = new List(); string sql = ""; sql = this.GetLastInjectionRecorderSql(condition, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { injectRecorderList = session.GetList(sql, parameters.ToArray()).ToList(); } return injectRecorderList; } /// /// 获取浇注设备的最后投料信息 /// /// /// public List GetCastLastRecorder(InjectionRecorder condition) { List injectRecorderList = new List(); List parameters = new List(); 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(sql, parameters.ToArray()).ToList(); } return injectRecorderList; } #endregion #region WEB 搪塑、注塑投料记录 #region 获取搪塑、注塑投料记录SQL /// /// 获取搪塑、注塑投料记录SQL /// /// 查询条件 /// 参数 /// 查询语句 private string GetInjectionRecordSql(InjectionRecorder condition, ref List 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 获取搪塑、注塑投料记录列表 /// /// 获取搪塑、注塑投料记录列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetInjectionRecordList(InjectionRecorder condition, DataPage page) { string sql = null; List parameters = new List(); 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(sql, parameters.ToArray(), page); } return page; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "原材料投料-获取搪塑、注塑投料记录列表" }); throw; } } #endregion #endregion /// /// /// /// /// public bool CheckInjectMaterial(InjectionInfo recorders) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); 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(model); } else { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(model); } } return count; } catch (Exception ex) { throw ex; } } /// /// 查验是否存在此批次物料(楼上) /// /// /// public InjectionInfo GetInjectMaterial(InjectionInfo recorders) { InjectionInfo info = new InjectionInfo(); StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List parameters = new List(); 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(sqlBuilder.ToString(), parameters.ToArray()); } return info; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "原材料投料-校验绑定物料" }); throw; } } /// /// /// /// public List GetInjectHoleList() { List list = new List(); string sql = null; List parameters = new List(); try { sql = "select * from T_AW_INJECTHOLE"; using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql, parameters.ToArray()).ToList(); } return list; } catch (Exception ex) { throw ex; } } /// /// 获取浇注设备的最后投料信息 直接根据物料查 /// /// /// public List GetCastLastRecorderWithMAterial(InjectionRecorder condition) { List injectRecorderList = new List(); List parameters = new List(); 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(sql, parameters.ToArray()).ToList(); } return injectRecorderList; } } }