using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using QMAPP.DAL; using QMAPP.FJC.Entity.MesB9; using QMAPP.FJC.Entity.ODS; using QMAPP.FJC.Entity.WarnManage; using QMFrameWork.Data; using QMFrameWork.Log; namespace QMAPP.FJC.DAL.ODS { public class VideoInfoDAL : BaseDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public VideoInfo Get(VideoInfo model) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 model = session.Get(model); } return model; } catch (Exception ex) { throw ex; } } #endregion public List GetAllList() { //DataParameter[] parameters; List parameters = new List(); //string sql = this.GetQuerySql(condition, ref parameters); string sql = "SELECT * FROM T_ODS_VideoInfo "; using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetList(sql, parameters.ToArray()).ToList(); } } protected string GetAllSql(VideoInfo condition,out DataParameter[] parameters) { List parametersList = new List(); StringBuilder sql = new StringBuilder(); sql.Append("SELECT * FROM T_ODS_VideoInfo "); parameters = parametersList.ToArray(); return sql.ToString(); } #region 获取页面 /// /// 播放视频 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetDataPageList(VideoInfo condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); //分页关键字段及排序 page.KeyName = "PID"; page.SortExpression = "UPDATEDATE DESC"; 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(VideoInfo condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append(@"SELECT PID ,VideoName ,VideoType ,VideoRule ,VideoUrl ,IsRepair ,MEMO ,CREATEDATE ,CREATEUSER ,UPDATEUSER ,UPDATEDATE FROM T_ODS_VideoInfo T "); //查询条件 //视频名称 if (string.IsNullOrEmpty(condition.VideoName) == false) { whereBuilder.Append(" AND VideoName LIKE '%'+" + "@VideoName" + "+'%'"); parameters.Add(new DataParameter { ParameterName = "VideoName", DataType = DbType.String, Value = condition.VideoName }); } //中心 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.WORKCELL_CODE) == false) { whereBuilder.Append(" AND WORKCELL_CODE = @WORKCELL_CODE "); parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = condition.WORKCELL_CODE }); } //工位 if (string.IsNullOrEmpty(condition.WORKLOC_CODE) == false) { whereBuilder.Append(" AND WORKLOC_CODE = @WORKLOC_CODE "); parameters.Add(new DataParameter { ParameterName = "WORKLOC_CODE", DataType = DbType.String, Value = condition.WORKLOC_CODE }); } //视频类型 if (string.IsNullOrEmpty(condition.VideoType) == false) { whereBuilder.Append(" AND VideoType = @VideoType "); parameters.Add(new DataParameter { ParameterName = "VideoType", DataType = DbType.String, Value = condition.VideoType }); } if (condition.STARTCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND CREATEDATE >= @STARTCREATEDATE"); parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") }); } if (condition.ENDCREATEDATE != DateTime.MinValue) { whereBuilder.Append(" AND CREATEDATE < @ENDCREATEDATE"); parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") }); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 public int Update(VideoInfo model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { count = session.Update(model); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public int Insert(VideoInfo model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(model); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 删除 /// /// 删除信息 /// /// /// 删除个数 public int Delete(VideoInfo model) { StringBuilder sqlBuilder = new StringBuilder(); List parameters = new List(); int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //删除基本信息 sqlBuilder.Append("DELETE T_ODS_VideoInfo "); 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) { throw ex; } } #endregion } }