Exemple #1
0
        public Utility.OpResult Deletes(int[] ids)
        {
            var op = new OpResult();

            try
            {
                var devices = DevicesRepository.GetQuery(o => ids.Contains(o.Id));
                if (!devices.Any())
                {
                    op.Message = "查不到数据";
                    return(op);
                }
                var delDeviceId = devices.Select(o => o.DeviceId);
                var authorize   = DeviceAuthorizeRepository.GetQuery(o => delDeviceId.Contains(o.DeviceId));
                if (authorize.Any())
                {
                    op.Message = "无法删除,设备授权包含了要删除的设备";
                    return(op);
                }

                DevicesRepository.RemoveRange(devices.ToList());
                op.Successed = true;
                LogEngine.WriteDelete("移除设备", LogModule.设备管理);
            }
            catch (Exception ex)
            {
                op.Message = ex.Message;
                LogEngine.WriteError(ex);
            }
            return(op);
        }
Exemple #2
0
        public IEnumerable <dynamic> GetPageList(System.Collections.Specialized.NameValueCollection nvl, out int recordCount)
        {
            //设备
            var query = DevicesRepository.GetQuery();
            //账户
            var userInfo = SysUserInfoRepository.GetQuery();
            //数据字典
            var dataDictionary = SysDataDictionaryRepository.GetQuery(o => o.Status);
            //设备授权信息
            var dAuthorize = DeviceAuthorizeRepository.GetQuery();



            //分类
            var CategoryId = (nvl["CategoryId"] ?? "").Trim();
            //品牌
            var Brand = (nvl["Brand"] ?? "").Trim();
            //维护人
            var FullName = (nvl["FullName"] ?? "").Trim();
            //设备名称
            var Title = (nvl["Title"] ?? "").Trim();

            if (!CategoryId.IsNullOrEmpty())
            {
                var c = short.Parse(CategoryId);
                query = query.Where(w => w.CategoryId == c);
            }
            if (!Brand.IsNullOrEmpty())
            {
                query = query.Where(w => w.Brand.Contains(Brand));
            }
            if (!Title.IsNullOrEmpty())
            {
                query = query.Where(w => w.Title.Contains(Title) || w.Spec.Contains(Title));
            }

            var q = from quer in query
                    let da = from dAu in dAuthorize where dAu.DeviceId == quer.DeviceId select dAu
                             join u in userInfo on quer.CreateUID equals u.UserId
                             into v
                             from w in v.DefaultIfEmpty()
                             join d in dataDictionary on quer.CategoryId equals d.DicSN
                             into x
                             from y in x.DefaultIfEmpty()
                             select new
            {
                quer.Id,
                quer.DeviceId,
                quer.CategoryId,
                quer.Title,
                quer.Brand,
                quer.Spec,
                number = da.Count(),
                quer.Status,
                quer.CreateDT,
                quer.CreateUID,
                dTitle   = y == null ? "" : y.Title,
                FullName = w == null ? "" : w.FullName
            };

            if (!FullName.IsNullOrEmpty() && FullName.Trim() != "全部")
            {
                q = q.Where(w => w.FullName.Contains(FullName));
            }

            recordCount = q.Count();
            return(q.ToPageList());
        }