public ResResultModel GetAssetInStoreModel(object Id) { try { Guid gId = Guid.Empty; if (Id != null) { Guid.TryParse(Id.ToString(), out gId); } if (gId.Equals(Guid.Empty)) { return(ResResult.Response(false, "请求参数值“" + Id + "”不正确", "")); } var bll = new AssetInStore(); var model = bll.GetModel(gId); if (model == null) { return(ResResult.Response(false, "参数值“" + Id + "”对应数据不存在或已被删除", "")); } return(ResResult.Response(true, "调用成功", JsonConvert.SerializeObject(model))); } catch (Exception ex) { return(ResResult.Response(false, ex.Message, "")); } }
public ResResultModel GetAssetInStore(AssetInStoreModel model) { try { if (model.PageIndex < 1) { model.PageIndex = 1; } if (model.PageSize < 1) { model.PageSize = 10; } int totalRecord = 0; var bll = new AssetInStore(); var list = bll.GetListByJoin(model.PageIndex, model.PageSize, out totalRecord, "", null); if (totalRecord == 0) { return(ResResult.Response(true, "", "{\"total\":0,\"rows\":[]}")); } var dgData = "{\"total\":" + totalRecord + ",\"rows\":" + JsonConvert.SerializeObject(list) + "}"; return(ResResult.Response(true, "", dgData)); } catch (Exception ex) { return(ResResult.Response(false, ex.Message, "")); } }
public ResResultModel DeleteAssetInStore(string itemAppend) { try { if (string.IsNullOrWhiteSpace(itemAppend)) { return(ResResult.Response(false, "未找到任何可删除的数据", "")); } var list = itemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList <object>(); if (list == null && list.Count == 0) { return(ResResult.Response(false, "未找到任何可删除的数据", "")); } var bll = new AssetInStore(); return(ResResult.Response(bll.DeleteBatch(list), "操作成功", "")); } catch (Exception ex) { return(ResResult.Response(false, "操作异常:" + ex.Message + "", "")); } }
private void Bind() { Guid gId = Guid.Empty; if (!string.IsNullOrWhiteSpace(Request.QueryString["Id"])) { Guid.TryParse(Request.QueryString["Id"], out gId); } if (!gId.Equals(Guid.Empty)) { var bll = new AssetInStore(); var model = bll.GetModel(gId); if (model != null) { hId.Value = model.Id.ToString(); hCategoryId.Value = model.CategoryId.ToString(); hUseCompanyId.Value = model.UseCompanyId.ToString(); hUseDepmtId.Value = model.UseDepmtId.ToString(); hOwnedCompanyId.Value = model.OwnedCompanyId.ToString(); hRegionId.Value = model.RegionId.ToString(); hPictureId.Value = model.PictureId.ToString(); txtBarcode.Value = model.Barcode; txtName.Value = model.Named; txtSpecModel.Value = model.SpecModel; txtSNCode.Value = model.SNCode; txtUnit.Value = model.Unit; txtPrice.Value = model.Price.ToString(); txtBuyDate.Value = model.BuyDate.ToString("yyyy-MM-dd"); txtUsePerson.Value = model.UsePerson; txtManager.Value = model.Manager; txtStoreLocation.Value = model.StoreLocation; txtUseExpireMonth.Value = model.UseExpireMonth.ToString(); txtSupplier.Value = model.Supplier; txtRFID.Value = model.RFID; txtRemark.Value = model.Remark; } } }
public ResResultModel SavePandianAsset(PdaPandianAssetFmModel model) { object userId = null; SecurityService.DoCheckLogin(model.AppKey, model.UserName, out userId); if (model == null) { return(ResResult.Response(false, "请求参数集为空字符串", "")); } var pandianId = Guid.Empty; if (model.PandianId == null || !Guid.TryParse(model.PandianId.ToString(), out pandianId)) { return(ResResult.Response(false, "参数PandianId值为“" + model.PandianId + "”无效", "")); } if (model.ItemList == null || model.ItemList.Count == 0) { return(ResResult.Response(false, "请求参数集为空字符串", "")); } var pdaBll = new PandianAsset(); var aisBll = new AssetInStore(); var pdBll = new Pandian(); var effect = 0; foreach (var item in model.ItemList) { PandianAssetInfo pdaModel = null; AssetInStoreInfo assetModel = null; var assetId = Guid.Empty; if (item.AssetId != null) { Guid.TryParse(item.AssetId.ToString(), out assetId); } if (assetId == Guid.Empty) { if (string.IsNullOrWhiteSpace(item.Barcode)) { continue; } if (pdaBll.IsExist(item.Barcode)) { assetModel = aisBll.GetModelByBarcode(item.Barcode); if (assetModel != null) { CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel); pdaModel.AssetId = assetModel.Id; pdaModel.PandianId = pandianId; assetModel.UserId = Guid.Parse(userId.ToString()); pdaModel.UserId = assetModel.UserId; effect += aisBll.Update(assetModel); effect += pdaBll.Update(pdaModel); } } else { CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel); assetModel.Id = Guid.NewGuid(); pdaModel.AssetId = assetModel.Id; pdaModel.PandianId = pandianId; assetModel.UserId = Guid.Parse(userId.ToString()); pdaModel.UserId = assetModel.UserId; effect += aisBll.InsertByOutput(assetModel); effect += pdaBll.Insert(pdaModel); } } else { assetModel = aisBll.GetModel(assetId); pdaModel = pdaBll.GetModel(pandianId, assetId); CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel); pdaModel.UserId = Guid.Parse(userId.ToString()); effect += pdaBll.Update(pdaModel); } } if (effect < 1) { return(ResResult.Response(false, "操作失败", "")); } return(ResResult.Response(true, "调用成功", "")); }
public ResResultModel SaveAssetInStore(AssetInStoreFmModel model) { try { if (model == null) { return(ResResult.Response(false, "未获取到任何可保存的数据", "")); } var modelInfo = new AssetInStoreInfo(); Guid gId = Guid.Empty; if (model.CategoryId != null) { Guid.TryParse(model.CategoryId.ToString(), out gId); } modelInfo.CategoryId = gId; if (model.UseCompanyId != null) { Guid.TryParse(model.UseCompanyId.ToString(), out gId); } modelInfo.UseCompanyId = gId; if (model.UseDepmtId != null) { Guid.TryParse(model.UseDepmtId.ToString(), out gId); } modelInfo.UseDepmtId = gId; if (model.RegionId != null) { Guid.TryParse(model.RegionId.ToString(), out gId); } modelInfo.RegionId = gId; if (model.OwnedCompanyId != null) { Guid.TryParse(model.OwnedCompanyId.ToString(), out gId); } modelInfo.OwnedCompanyId = gId; if (model.PictureId != null) { Guid.TryParse(model.PictureId.ToString(), out gId); } modelInfo.PictureId = gId; DateTime time = DateTime.MinValue; DateTime.TryParse(model.SBuyDate, out time); modelInfo.Barcode = model.Barcode; modelInfo.Named = model.Named; modelInfo.SpecModel = model.SpecModel; modelInfo.SNCode = model.SNCode; modelInfo.Unit = model.Unit; modelInfo.Price = model.Price; modelInfo.BuyDate = time == DateTime.MinValue ? DateTime.Parse("1754-01-01") : time; modelInfo.UsePerson = model.UsePerson; modelInfo.Manager = model.Manager; modelInfo.StoreLocation = model.StoreLocation; modelInfo.UseExpireMonth = model.UseExpireMonth; modelInfo.Supplier = model.Supplier; modelInfo.Remark = model.Remark; modelInfo.LastUpdatedDate = DateTime.Now; modelInfo.UserId = Guid.Parse(SecurityService.GetUserId().ToString()); if (model.Id != null) { Guid.TryParse(model.Id.ToString(), out gId); } modelInfo.Id = gId; var bll = new AssetInStore(); int effect = -1; if (modelInfo.Id.Equals(Guid.Empty)) { effect = bll.Insert(modelInfo); } else { effect = bll.Update(modelInfo); } if (effect < 1) { return(ResResult.Response(false, "操作失败,数据库操作异常,请稍后再重试", "")); } return(ResResult.Response(true, "操作成功", "")); } catch (Exception ex) { return(ResResult.Response(false, "操作异常:" + ex.Message + "", "")); } }
private void OnExportByAssetInStore(HttpContext context) { try { AssetInStore aisBll = new AssetInStore(); var list = aisBll.GetListByJoin(); if (list == null || list.Count == 0) { context.Response.Write(ResResult.ResJsonString(false, "无数据", "")); return; } var colAppend = "照片,资产条码,资产名称,资产类别,规格型号,SN号,计量单位,金额,使用公司,使用部门,使用人,区域,存放地点,管理员,所属公司,购入时间,供应商,使用期限"; var cols = colAppend.Split(','); var dt = new DataTable("dtAssetInStore"); foreach (var item in cols) { dt.Columns.Add(new DataColumn(item, System.Type.GetType("System.String"))); } foreach (var model in list) { var dr = dt.NewRow(); for (var i = 0; i < cols.Length; i++) { var text = ""; switch (i) { case 0: text = ""; break; case 1: text = model.Barcode; break; case 2: text = model.Named; break; case 3: text = model.CategoryName; break; case 4: text = model.SpecModel; break; case 5: text = model.SNCode; break; case 6: text = model.Unit; break; case 7: text = model.Price.ToString(); break; default: break; } dr[i] = text; } dt.Rows.Add(dr); } //NpoiHelper npoi = new NpoiHelper(); //var fileUrl = npoi.ExportExcel(dt, "资产列表.xlsx"); var fileUrl = ""; context.Response.Write(ResResult.ResJsonString(true, "", fileUrl)); } catch (Exception ex) { context.Response.Write(ResResult.ResJsonString(false, ex.Message, "")); } }
private void ImportByAssetInStore(HttpContext context, HttpPostedFile file) { //NpoiHelper npoi = new NpoiHelper(); //var dt = npoi.GetExcelData(Path.GetExtension(file.FileName), file.InputStream); var dt = new DataTable(); var drc = dt.Rows; if (drc.Count == 0) { context.Response.Write(ResResult.ResJsonString(false, "导入的数据不能为空字符串", "")); return; } Category cBll = new Category(); OrgDepmt odBll = new OrgDepmt(); Region rBll = new Region(); decimal d = decimal.MinValue; DateTime time = DateTime.MinValue; var list = new List <AssetInStoreInfo>(); foreach (DataRow dr in drc) { if (string.IsNullOrWhiteSpace(dr["资产条码"].ToString()) || string.IsNullOrWhiteSpace(dr["资产名称"].ToString()) || string.IsNullOrWhiteSpace(dr["资产类别编码"].ToString()) || string.IsNullOrWhiteSpace(dr["使用公司编码"].ToString()) || string.IsNullOrWhiteSpace(dr["存放地点"].ToString()) || string.IsNullOrWhiteSpace(dr["所属公司编码"].ToString()) || string.IsNullOrWhiteSpace(dr["购入时间"].ToString())) { throw new ArgumentException("带有“*”的列为必填项,请正确操作"); } var model = new AssetInStoreInfo(); model.Barcode = dr["资产条码"].ToString(); model.Named = dr["资产名称"].ToString(); var categoryModel = cBll.GetModelByCode(dr["资产类别编码"].ToString().Trim()); if (categoryModel == null) { throw new ArgumentException("资产类别编码“" + dr["资产类别编码"].ToString().Trim() + "”对应的数据不存在或已被删除"); } model.CategoryId = categoryModel.Id; if (!decimal.TryParse(dr["金额"].ToString(), out d)) { throw new ArgumentException("金额“" + dr["金额"].ToString() + "”不正确"); } model.Price = d; model.SpecModel = dr["规格型号"].ToString(); model.Unit = dr["计量单位"].ToString(); var useCompanyModel = odBll.GetModelByCode(dr["使用公司编码"].ToString()); if (useCompanyModel == null) { throw new ArgumentException("使用公司编码“" + dr["使用公司编码"].ToString() + "”对应的数据不存在或已被删除"); } var orgdModel = odBll.GetModelByCode(dr["使用部门编码"].ToString()); if (orgdModel == null) { throw new ArgumentException("使用部门编码“" + dr["使用部门编码"].ToString() + "”对应的数据不存在或已被删除"); } model.UseCompanyId = useCompanyModel.Id; model.UseDepmtId = orgdModel.Id; var rModel = rBll.GetModelByCode(dr["区域编码"].ToString()); if (rModel == null) { throw new ArgumentException("区域编码“" + dr["区域编码"].ToString() + "”对应的数据不存在或已被删除"); } model.RegionId = rModel.Id; var ownedCompanyModel = odBll.GetModelByCode(dr["所属公司编码"].ToString()); if (ownedCompanyModel == null) { throw new ArgumentException("所属公司编码“" + dr["所属公司编码"].ToString() + "”对应的数据不存在或已被删除"); } model.OwnedCompanyId = ownedCompanyModel.Id; model.UsePerson = dr["使用人"].ToString(); model.StoreLocation = dr["存放地点"].ToString(); model.Manager = dr["管理员姓名"].ToString(); if (!DateTime.TryParse(dr["购入时间"].ToString(), out time)) { throw new ArgumentException("购入时间“" + dr["购入时间"].ToString() + "”不正确"); } model.BuyDate = time; model.Supplier = dr["供应商"].ToString(); model.Remark = dr["备注"].ToString(); model.SNCode = dr["SN号"].ToString(); model.UseExpireMonth = 1200; model.PictureId = Guid.Empty; model.LastUpdatedDate = DateTime.Now; list.Add(model); } AssetInStore aisBll = new AssetInStore(); var index = 0; var userId = WebCommon.GetUserId(); foreach (var model in list) { model.UserId = userId; if (aisBll.Insert(model) < 1) { throw new ArgumentException(string.Format("{0}", index > 0 ? "部分数据已经成功导入,但是执行到第“" + index + "”行时发生异常" : "数据导入失败,行“" + index + "”发生异常")); } index++; } context.Response.Write(ResResult.ResJsonString(true, "导入成功", "")); }