using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.MD.Entity; using QMFrameWork.Data; using System.Data; using QMAPP.DAL; using QMAPP.Entity; using QMAPP.Entity.Sys; using QMAPP.FJC.Entity.BZD; using QMAPP.FJC.DAL.BZD; namespace QMAPP.MD.DAL { /// /// 模块名称:条码补打记录 /// 作 者:张松男 /// 编写日期:2021年05月21日 /// public class BarCodeReplacementDAL : BaseDAL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// *信息 public BarCodeReplacement Get(BarCodeReplacement info) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 info = session.Get(info); } return info; } catch (Exception ex) { throw ex; } } public BarCodeReplacement GetRecord(BarCodeReplacement info) { try { List parameters = new List(); var sql = "SELECT * FROM T_AW_BarCode_Replacement WHERE 1=1 "; if (string.IsNullOrEmpty(info.PID) == false) { sql += " AND PID = @PID"; parameters.Add(new DataParameter("PID", info.PID)); } using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 var list = session.GetList(sql, parameters.ToArray()).ToList(); if (list.Count > 0) return list[0]; else return null; } } catch (Exception ex) { throw ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(BarCodeReplacement condition, DataPage page) { string sql = null; List parameters = new List(); try { sql = this.GetQuerySql2(condition, ref parameters); //分页关键字段及排序 page.KeyName = "PID"; if (string.IsNullOrEmpty(page.SortExpression)) page.SortExpression = "CreateTime DESC"; using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 //string sqlChange = this.ChangeSqlByDB(sql, session); page = session.GetDataPage(sql, parameters.ToArray(), page); } return page; } catch (Exception ex) { throw ex; } } #endregion #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql2(BarCodeReplacement condition, ref List parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { if (condition.BeginTime == Convert.ToDateTime("0001/1/1 00:00:00")) condition.BeginTime = DateTime.Now.AddDays(-1); if (condition.EndTime == Convert.ToDateTime("0001/1/1 00:00:00")) condition.EndTime = DateTime.Now; //构成查询语句 sqlBuilder.Append("select b.PID,b.Type,b.ProductCode,m.MAINCODE as 'BZDBarcode',m.MATERIAL_CODE as 'BZDMaterial_Code',t.MATERIAL_NAME as 'BZDMaterial_CodeName',b.CreateTime,b.CreateUser "); sqlBuilder.Append("from T_AW_BarCode_Replacement as b left join T_AW_MAIN as m on b.ProductCode = m.EPIDERMISCODE LEFT JOIN T_MD_MATERIAL as t on m.MATERIAL_CODE = t.MATERIAL_CODE "); //查询条件 //查询条件 if (string.IsNullOrEmpty(condition.ProductCode) == false) { whereBuilder.Append(" AND b.ProductCode like @ProductCode "); parameters.Add(new DataParameter { ParameterName = "ProductCode", DataType = DbType.String, Value = "%" + condition.ProductCode + "%" }); } //查询条件 if (string.IsNullOrEmpty(condition.Type) == false) { whereBuilder.Append(" AND b.Type like @Type "); parameters.Add(new DataParameter { ParameterName = "Type", DataType = DbType.String, Value = "%" + condition.Type + "%" }); } whereBuilder.Append($" AND b.CreateTime >= '{condition.BeginTime}' and b.CreateTime <= '{condition.EndTime}' "); if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return sqlBuilder.ToString(); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public int Insert(BarCodeReplacement info) { int count = 0; List parameters = new List(); try { var sql = $" insert into T_AW_BarCode_Replacement (PID,Type,ProductCode,CreateTime,CreateUser)" + $"VALUES('{info.PID}','{info.Type}','{info.ProductCode}','{DateTime.Now}','{info.CreateUser}')"; using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.ExecuteSql(sql, parameters.ToArray()); } return count; } catch (Exception ex) { throw ex; } } #endregion } }