public static T Factory(DBHelperContext context)
        {
            //if (typeof(T) == typeof(IDemoService))
            //    return (T)DemoServiceImpl.Instance(context);

            throw new InvalidCastException("没有找到" + typeof(T) + "的实现");
        }
Beispiel #2
0
        public M_Data_Paging <M_CustomerInfo> Query(WhereFilter wherefilter, int iSIndex, int iEIndex)
        {
            using (DBHelperContext dbcon = new DBHelperContext())
            {
                //动态分配条件
                var predicate = PredicateBuilder.True <M_CustomerInfo>();
                if (wherefilter != null)
                {
                    foreach (Rules rule in wherefilter.rules)
                    {
                        if (rule.field.Equals("CusCode"))
                        {
                            predicate = predicate.And(p => p.CusCode.Contains(rule.value));
                        }
                        if (rule.field.Equals("CusName"))
                        {
                            predicate = predicate.And(p => p.CusName.Contains(rule.value));
                        }
                    }
                }

                var mcus      = dbcon.M_CustomerInfos.Where(predicate.Compile());
                int iRowCount = mcus.Count();
                var mcusb     = mcus.OrderBy(p => p.CusCode).Skip(iSIndex).Take(iEIndex - iSIndex).ToList();

                M_Data_Paging <M_CustomerInfo> mdp_Ccus = new M_Data_Paging <M_CustomerInfo>()
                {
                    RowCount = iRowCount,
                    lstTObj  = mcusb,
                };
                return(mdp_Ccus);
            }
        }
 public RepositoryBase()
 {
     if (_context == null)
     {
         _context = new DBHelperContext();
     }
     this._dbSet = _context.Set <T>();
 }
Beispiel #4
0
 public M_User Query(string userid)
 {
     using (DBHelperContext dbcon = new DBHelperContext())
     {
         var muser = dbcon.M_Users.Find(userid);
         return(muser);
     }
 }
Beispiel #5
0
 public M_CustomerInfo Query(string cuscode)
 {
     using (DBHelperContext dbcon = new DBHelperContext())
     {
         var mcus = dbcon.M_CustomerInfos.Find(cuscode);
         return(mcus);
     }
 }
Beispiel #6
0
 public bool Add(M_User t)
 {
     using (DBHelperContext dbcon = new DBHelperContext())
     {
         dbcon.M_Users.Add(t);
         int i = dbcon.SaveChanges();
         return(i > 0 ? true : false);
     }
 }
Beispiel #7
0
        public static void Initialize(IServiceProvider serviceProvider, DBHelperContext dBHelperContext)
        {
            //var context = serviceProvider.GetService<DbContext>();
            //dBHelperContext.Database

            var context = serviceProvider.GetService <DBHelperContext>();

            if (context.Database == null)
            {
                throw new Exception("DB is null");
            }
        }
Beispiel #8
0
 public bool Remove(List <string> keys)
 {
     using (DBHelperContext dbcon = new DBHelperContext())
     {
         foreach (string key in keys)
         {
             dbcon.M_Users.Remove(dbcon.M_Users.Where(p => p.UserID == key).FirstOrDefault());
         }
         int i = dbcon.SaveChanges();
         return(i > 0 ? true : false);
     }
 }
Beispiel #9
0
 public bool Add(List <M_User> lstUser)
 {
     using (DBHelperContext dbcon = new DBHelperContext())
     {
         foreach (var m in lstUser)
         {
             dbcon.M_Users.Add(m);
         }
         int i = dbcon.SaveChanges();
         return(i > 0 ? true : false);
     }
 }
Beispiel #10
0
        public bool Update(M_User t)
        {
            using (DBHelperContext dbcon = new DBHelperContext())
            {
                var modifyEntity = dbcon.Entry(t);
                modifyEntity.State = EntityState.Modified;

                List <MemberInfo> lstM = t.GetType().GetMembers().ToList();
                foreach (MemberInfo m in lstM)
                {
                    if (m.MemberType == MemberTypes.Property)
                    {
                        modifyEntity.Property(m.Name).IsModified = true;
                    }
                }
                int i = dbcon.SaveChanges();
                return(i > 0 ? true : false);
            }
        }
Beispiel #11
0
        public M_Data_Paging <M_User> Query(WhereFilter wherefilter, int iSIndex, int iEIndex)
        {
            using (DBHelperContext dbcon = new DBHelperContext())
            {
                //动态分配条件
                var predicate = PredicateBuilder.True <M_User>();
                //List<MemberInfo> lstM =typeof(M_User).GetMembers().ToList();
                //var lstC=(from c in lstM
                //         select new {
                //             colName=c.Name,
                //         }).ToList();

                //foreach (MemberInfo m in lstM)
                //{
                //    modifyEntity.Property(m.Name).IsModified = true;
                //}

                if (wherefilter != null)
                {
                    foreach (Rules rule in wherefilter.rules)
                    {
                        if (rule.field.Equals("UserID"))
                        {
                            predicate = predicate.And(p => p.UserID.Contains(rule.value));
                        }
                        if (rule.field.Equals("UserName"))
                        {
                            predicate = predicate.And(p => p.UserName.Contains(rule.value));
                        }
                    }
                }


                //if (string.IsNullOrEmpty(wherefilter.UserID))
                //{
                //    predicate = predicate.And(p => p.UserID.Contains(wherefilter.UserID));
                //}
                //if (string.IsNullOrEmpty(wherefilter.UserName))
                //{
                //    predicate = predicate.And(p => p.UserName.Contains(wherefilter.UserName));
                //}

                //predicate = predicate.And(p => p.UserActive.Equals(wherefilter.UserActive));

                //if (string.IsNullOrEmpty(wherefilter.Remark))
                //{
                //    predicate = predicate.And(p => p.Remark.Contains(wherefilter.Remark));
                //}

                var musers    = dbcon.M_Users.Where(predicate.Compile());
                int iRowCount = musers.Count();
                var muserb    = musers.OrderBy(p => p.UserID).Skip(iSIndex).Take(iEIndex - iSIndex).ToList();

                M_Data_Paging <M_User> mdp_Users = new M_Data_Paging <M_User>()
                {
                    RowCount = iRowCount,
                    lstTObj  = muserb,
                };
                return(mdp_Users);
            }
        }