using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Common; using HH.MData; using MongoDB.Driver; using MongoDB.Driver.Builders; namespace HW.DAL.Common { public class CommonDAL : BaseDAL { MongoDBHelper dbHelper = null; #region 新增一个集合到mongo数据库 /// /// 新增一个集合到mongo数据库 /// /// 实体类 /// 实体类集合数据 /// 对象名称 /// public bool AddList(List lstEntity, string collectionName) { try { dbHelper = new MongoDBHelper(); bool result = dbHelper.Insert(lstEntity, collectionName); return result; } catch (Exception ex) { HanHe.Service.Log.Info("mongo error", ex.Message); return false; } } #endregion #region 根据物料编码删除 /// /// 根据物料编码删除 /// /// /// 物料编码 /// 集合名称 /// public bool RemoveDataByCode(string code, string collectionName) { dbHelper = new MongoDBHelper(); IMongoQuery query = Query.EQ("S_60_C1", code); bool result = dbHelper.Remove(query, collectionName); return result; } #endregion #region 根据物料编码删除 /// /// 根据物料编码删除 /// /// /// 物料编码 /// 集合名称 /// public bool RemoveDataByCodeHc(string code, string collectionName) { dbHelper = new MongoDBHelper(); IMongoQuery query = Query.EQ("CN_S_ITEM_CODE", code); bool result = dbHelper.Remove(query, collectionName); return result; } #endregion #region 判断记录是否存在 /// /// 判断记录是否存在 /// /// /// 物料编码 /// 集合名称 /// public bool IsExistsMongo(string code, string collectionName) { dbHelper = new MongoDBHelper(); IMongoQuery query = Query.EQ("S_60_C1", code); long count = dbHelper.FindCount(query, collectionName); if (count > 0) return true; return false; } #endregion #region 判断记录是否存在 /// /// 判断记录是否存在 /// /// /// 物料编码 /// 集合名称 /// public bool IsExistsMongoHc(string code, string collectionName) { dbHelper = new MongoDBHelper(); IMongoQuery query = Query.EQ("CN_S_ITEM_CODE", code); long count = dbHelper.FindCount(query, collectionName); if (count > 0) return true; return false; } #endregion #region 新增一条实体记录到MONGO数据库 /// /// 新增一条实体记录到MONGO数据库 /// /// 实体 /// 实体数据 /// 对象名称 /// public bool Add(T entity, string collectionName) { dbHelper = new MongoDBHelper(); bool result = dbHelper.Insert(entity, collectionName); return result; } #endregion } }