public ActionResult Submit(AssetInventoryViewModel model) { string action = Request["Submit"]; if (action == "close") { if (model.InventoryId > 0) { this.AssetInventoryService.UpdateAssetInventoryStatus(model.InventoryId, AssetInventoryStatus.Closed); } } else if (action == "open") { if (model.InventoryId > 0) { this.AssetInventoryService.UpdateAssetInventoryStatus(model.InventoryId, AssetInventoryStatus.Open); } } else if (action == "exportNoScanInfo") { //导出某次盘点未扫描的资产信息 try { var assetInventory = this.AssetInventoryService.GetAssetInventory(model.InventoryId); var scanedAssetIds = new List <int>(); if (assetInventory != null && assetInventory.AssetInventoryRecords != null) { scanedAssetIds = assetInventory.AssetInventoryRecords.Where(it => it.AssetId.HasValue).Select(it => it.AssetId.Value).Distinct().ToList(); } var workbook = new Aspose.Cells.Workbook(); var descriptor = new ExportExcel <AssetModel>(); AssetSearchModel search = new AssetSearchModel() { BarCode = null, TypeId = null, BuyDate = null, UserName = null }; var assets = this.AssetService.List(search).Where(it => !scanedAssetIds.Contains(it.Id)).ToList(); descriptor.FillAssetData(assets, workbook, 0); var ms = new MemoryStream(); string fileName = assetInventory.Title + "(暂未扫描的资产信息)-" + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx"; workbook.Save(ms, Aspose.Cells.SaveFormat.Xlsx); return(File(ms.ToArray(), "application/vnd.ms-excel", fileName)); } catch (Exception ex) { ViewBag.Message = ex.Message; } } return(RedirectToAction("Index")); }
public ApiPagingListResponse <AssetModel> SearchAssets(AssetSearchModel search, int pageIndex = 0, int pageSize = 25) { var query = this.AssetService.SearchAssets(search, pageIndex, pageSize, this.Member.Id); HiddenAmount(query.Result); var result = new PaginationModel <AssetModel>(); //分页 result.Page = new Page() { PageIndex = query.PageIndex, PageSize = query.PageSize, TotalPages = query.TotalPages, TotalCount = query.TotalCount }; return(new ApiPagingListResponse <AssetModel> { Result = query.Result, Page = result.Page }); }
public ActionResult Index(string barCode, string userName, int?typeId, DateTime?buyDate, int page = 1) { AssetSearchModel search = new AssetSearchModel() { BarCode = barCode, TypeId = typeId, BuyDate = buyDate, UserName = userName }; var assets = this.AssetService.List(search); var attrs = this.AssetAttributeService.GetAll(); var barcodeAttr = attrs.Where(it => it.Name == "编号").FirstOrDefault(); if (Request["Submit"] != null) { string action = Request["Submit"]; //导出二维码 if (action == "exportQR") { try { if (barcodeAttr == null) { throw new Exception("资产属性没有配置编号"); } if (!Directory.Exists(Server.MapPath("~/QRImages/"))) { Directory.CreateDirectory(Server.MapPath("~/QRImages/")); } foreach (var item in assets) { var barcode = item.AssetInfoes.Where(it => it.AttributeId == barcodeAttr.Id).FirstOrDefault(); if (barcode != null) { string enCodeString = barcode.AttributeValue; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q; qrCodeEncoder.QRCodeScale = 3; Bitmap qrImg = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8); Bitmap resultImage = new Bitmap(qrImg.Width + 20, qrImg.Height + 20); Graphics gResult = Graphics.FromImage(resultImage); gResult.Clear(System.Drawing.Color.White); if (System.IO.File.Exists(Server.MapPath("~/Content/images/logo.jpg")))//如果有logo的话则添加logo { Bitmap btm = new Bitmap(Server.MapPath("~/Content/images/logo.jpg")); Bitmap copyImage = new Bitmap(btm, qrImg.Width / 3, qrImg.Height / 3); Graphics g = Graphics.FromImage(qrImg); int x = qrImg.Width / 2 - copyImage.Width / 2; int y = qrImg.Height / 2 - copyImage.Height / 2; g.DrawImage(copyImage, x, y); } gResult.DrawImage(qrImg, 10, 10); resultImage.Save(Server.MapPath("~/QRImages/") + barcode.AttributeValue + ".jpg"); } } string zipFile = ""; bool bol = ZipFile(ref zipFile); if (bol) { return(File(zipFile, "application/x-zip-compressed", "资产二维码-" + DateTime.Now.ToString("yyyy-MM-dd") + ".zip")); } } catch (Exception ex) { ViewBag.Message = ex.Message; } } //导出数据 else if (action == "export") { try { if (barcodeAttr == null) { throw new Exception("资产属性没有配置编号"); } var workbook = new Aspose.Cells.Workbook(); var descriptor = new ExportExcel <AssetModel>(); descriptor.FillAssetData(assets, workbook, barcodeAttr.Id); var ms = new MemoryStream(); string fileName = "资产信息-" + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx"; workbook.Save(ms, Aspose.Cells.SaveFormat.Xlsx); return(File(ms.ToArray(), "application/vnd.ms-excel", fileName)); } catch (Exception ex) { ViewBag.Message = ex.Message; } } } AssetList assetList = new AssetList() { BarCode = barCode, TypeId = typeId, BuyDate = buyDate, UserName = userName }; if (barcodeAttr != null) { assetList.BarCodeAttrId = barcodeAttr.Id; } else { assetList.BarCodeAttrId = 0; } int pageSize = 15; assetList.List = assets.AsEnumerable().ToPagedList(page, pageSize); return(View(assetList)); }
//执行查询 private List <AssetModel> QueryExecute(AssetSearchModel search, int?unIncludeUserId) { using (var dbContext = new MissionskyOAEntities()) { var query = dbContext.Assets.AsQueryable(); if (search != null) { if (!string.IsNullOrEmpty(search.BarCode)) { var barcodeAttribute = dbContext.AssetAttributes.Where(it => it.Name == "编号").FirstOrDefault(); if (barcodeAttribute != null) { var assetIds = dbContext.AssetInfoes.Where(it => it.AttributeId == barcodeAttribute.Id && it.AttributeValue.Contains(search.BarCode)) .Select(it => it.AssetId) .Distinct() .ToArray(); query = query.Where(it => assetIds.Contains(it.Id)); } } if (search.BuyDate.HasValue) { var buyDateAttribute = dbContext.AssetAttributes.Where(it => it.Name == "采购日期").FirstOrDefault(); if (buyDateAttribute != null) { var assetIdWithBuyDates = dbContext.AssetInfoes.Where(it => it.AttributeId == buyDateAttribute.Id && !string.IsNullOrEmpty(it.AttributeValue)) .Select(it => new { Id = it.AssetId, BuyDate = it.AttributeValue }) .Distinct() .ToArray(); var dt = DateTime.Now; var assetIds = assetIdWithBuyDates.Where(it => DateTime.TryParse(it.BuyDate, out dt) && DateTime.Parse(it.BuyDate).Year == search.BuyDate.Value.Year && DateTime.Parse(it.BuyDate).Month == search.BuyDate.Value.Month) .Select(it => it.Id) .ToArray(); query = query.Where(it => assetIds.Contains(it.Id)); } } if (search.Status.HasValue) { query = query.Where(it => it.Status.HasValue && it.Status.Value == (int)search.Status.Value); } if (search.TypeId.HasValue) { query = query.Where(it => it.TypeId == search.TypeId.Value); } if (unIncludeUserId.HasValue) { query = query.Where(it => it.UserId != unIncludeUserId.Value); } if (!string.IsNullOrEmpty(search.UserName)) { query = query.Where(it => it.User != null && it.User.EnglishName.ToLower().Contains(search.UserName.ToLower())); } } var result = new List <AssetModel>(); query.Include(it => it.User) .Include(it => it.AssetType) .Include(it => it.AssetInfoes).ToList().ForEach(it => { result.Add(it.ToModel(dbContext)); }); return(result); } }
public IPagedList <AssetModel> SearchAssets(AssetSearchModel search, int pageIndex, int pageSize, int?unIncludeUserId) { return(new PagedList <AssetModel>(QueryExecute(search, unIncludeUserId), pageIndex, pageSize)); }
public List <AssetModel> List(AssetSearchModel search) { return(QueryExecute(search, null)); }