using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.FJC.Entity.MD; using QMFrameWork.Data; using System.Data; using QMAPP.Entity; using QMAPP.MD.Entity.Bucket; using QMAPP.MD.Entity.TianJin; namespace QMAPP.FJC.DAL.TianJin { /// /// 模块名称:库存日志信息 /// 作 者:张松男 /// 编写日期:2022年02月17日 /// public class MonitordataDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public Monitordata Get(Monitordata info) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 info = session.Get(info); } return info; } catch (Exception ex) { throw ex; } } /// /// 获取信息 /// /// 条件 /// *信息 public Monitordata Get(string materialcode) { try { string sql = "SELECT top1 * FROM [T_AW_Monitordata] WHERE [ProductCode]=@ProductCode"; List parameters = new List(); parameters.Add(new DataParameter("ProductCode", materialcode)); using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 var info = session.Get(sql, parameters.ToArray()); return info; } } catch (Exception ex) { throw ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(Monitordata condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); //分页关键字段及排序 page.KeyName = "id"; if (string.IsNullOrEmpty(page.SortExpression)) page.SortExpression = "RecordDate DESC"; using (IDataSession session = AppDataFactory.CreateMainSession()) { page = session.GetDataPage(sql, parameters.ToArray(), page); } return page; } catch (Exception ex) { throw ex; } } /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public List GetALL() { string sql = null; List parameters = new List(); try { sql = "SELECT * FROM T_AW_Monitordata "; //分页关键字段及排序 var LIST = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { LIST = session.GetList(sql, parameters.ToArray()).ToList(); } return LIST; } catch (Exception ex) { throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(Monitordata condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append("SELECT * "); sqlBuilder.Append("FROM monitordata "); if (string.IsNullOrEmpty(condition.QrCodeContent) == false) { whereBuilder.Append(" AND QrCodeContent = @QrCodeContent"); parameters.Add(new DataParameter { ParameterName = "QrCodeContent", DataType = DbType.String, Value = condition.QrCodeContent }); } if (condition.BeginTime != DateTime.MinValue) whereBuilder.Append($" and RecordDate >= '{condition.BeginTime}' "); if (condition.EndTime != DateTime.MinValue) whereBuilder.Append($" and RecordDate <= '{condition.EndTime}' "); //查询条件 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion #region 获取导出的数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(Monitordata model) { DataTable dt = null; string sql = null; List parameters = new List(); try { //构成查询语句 sql = this.GetQuerySql(model, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = "T_AW_Monitordata"; } return dt; } catch (Exception ex) { throw ex; } } #endregion } }