using iWareCommon.Common.Entity; using iWareCommon.Common.Service; using iWareCommon.Utils; using iWareDataCore.BASE.Dao; using iWareDataCore.BASE.Entity; using iWareDataCore.ORM; using iWareDataCore.Properties; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace iWareDataCore.BASE.Service { public class InputMaterialService : CommonService { private static object Lock = new object(); private InputMaterialService() : base(InputMaterialDao.GetInstance()) { } private static InputMaterialService Instance = null; /// /// 获取单例的方法 /// /// 角色服务的单例实体 public static InputMaterialService GetInstance() { if (Instance == null) { lock (Lock) { if (Instance == null) { Instance = new InputMaterialService(); } } } return Instance; } /// /// 取得导入物料的id的集合 /// /// /// public List GetIds(List codes) { using (var DbModel = new DbModelCore()) { string msg = ""; try { var mid = DbModel.BASEMaterials.Where(x => codes.Contains(x.code)).ToList(); return mid; } catch (Exception ex) { msg = ex.Message; LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetIds", ex.Message); return null; } } } /// /// 每次加载时,如果有上次导入未生成的数据,全部删除 /// /// public int DeleteAll() { using (var DbModel = new DbModelCore()) { string msg = ""; try { var input = DbModel.BASEInputMaterials.Where(x => x.id != 0).ToList(); if (input.Count > 0) { DbModel.BASEInputMaterials.RemoveRange(input); DbModel.SaveChanges(); return 1; } else { return 0; } } catch (Exception ex) { msg = ex.Message; LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "DeleteAll", ex.Message); return -1; } } } } }