public ActionResult Download2(string id) { try { using (UnitOfWorkManager.NewUnitOfWork()) { Guid company_Id = WorkContext.CurrentMembershipUser.Company.Id; MSDS_Specification entity = _specificationService.Single(Guid.Parse(id), company_Id); string fileName = "安全告知" + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx"; string filePath = Server.MapPath("~/Content/ExportFiles/" + fileName); string templatePath = "~/Content/Templates/安全告知模板.xlsx"; string downloadName = "安全告知.xlsx"; System.IO.File.Copy(Server.MapPath(templatePath), filePath); if (entity != null) { ExportToTag_SecurityNotification(filePath, entity); return(File(filePath, "text/xls", downloadName)); } else { ErrorNotification(new Exception("未能查询到该化学品信息!")); return(View()); } } } catch (Exception ex) { ErrorNotification(ex); throw ex; } }
public ActionResult Download(string id, int size) { using (UnitOfWorkManager.NewUnitOfWork()) { try { Guid company_Id = WorkContext.CurrentMembershipUser.Company.Id; MSDS_Specification entity = _specificationService.Single(Guid.Parse(id), company_Id); string fileName = (entity.CN_Name ?? entity.Product_Name) + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx"; string filePath = Server.MapPath("~/Content/ExportFiles/" + fileName); string templatePath = "~/Content/Templates/"; switch (size) { case 1: templatePath += "GHS模板50-70.xlsx"; break; case 2: templatePath += "GHS模板75-100.xlsx"; break; case 3: templatePath += "GHS模板100-150.xlsx"; break; case 4: templatePath += "GHS模板150-200.xlsx"; break; case 5: templatePath += "GHS模板200-300.xlsx"; break; default: throw new Exception("未能找到对应的标签模板!"); } System.IO.File.Copy(Server.MapPath(templatePath), filePath); if (entity != null) { ExportToTag(filePath, entity); return(File(filePath, "text/xls", fileName)); } else { ErrorNotification(new Exception("未能查询到该化学品信息!")); return(View()); } } catch (Exception ex) { ErrorNotification(ex); throw ex; } } }
private void ExportToTag_SecurityNotification(string filePath, MSDS_Specification model) { Tag_SecurityNotification tag = new Tag_SecurityNotification(); tag.SheetName = "大标签"; tag.templateFilePath = filePath; tag.ProductName = model.CN_Name ?? model.Product_Name; #region 危险图标 List <string> imgPathList = new List <string>(); string strRootPath = Server.MapPath("~/Content/Images/"); if (model.IsExplosive) { imgPathList.Add(strRootPath + "Explosive.png"); } if (model.IsFlammable) { imgPathList.Add(strRootPath + "Flammable.png"); } if (model.IsCorrosive) { imgPathList.Add(strRootPath + "Corrosive.png"); } if (model.IsHealthHazard) { imgPathList.Add(strRootPath + "HealthHazard.png"); } if (model.IsToxic) { imgPathList.Add(strRootPath + "Toxic.png"); } if (model.IsOxidizing) { imgPathList.Add(strRootPath + "Oxidizing.png"); } if (model.IsGasUnderPressure) { imgPathList.Add(strRootPath + "GasUnderPressure.png"); } if (model.IsIrritant) { imgPathList.Add(strRootPath + "Irritant.png"); } if (model.IsDangerousToEnvironment) { imgPathList.Add(strRootPath + "DangerousToEnvironment.png"); } tag.WarningPicPaths = imgPathList; tag.BlankPicPath = strRootPath + "blank.png"; #endregion #region 个人防护图标 List <string> imgPathList_Protection = new List <string>(); if (model.IsProtection_FaceAndEye) { imgPathList_Protection.Add(strRootPath + "Product_Protection_FaceAndEye.png"); } if (model.IsProtection_Hand) { imgPathList_Protection.Add(strRootPath + "Product_Protection_Hand.png"); } if (model.IsProtection_Breathing) { imgPathList_Protection.Add(strRootPath + "Product_Protection_Breathing.png"); } if (model.IsProtection_Foot) { imgPathList_Protection.Add(strRootPath + "Product_Protection_Foot.png"); } if (model.IsProtection_Body) { imgPathList_Protection.Add(strRootPath + "Product_Protection_Body.png"); } if (model.IsProtection_Other) { imgPathList_Protection.Add(strRootPath + "Product_Protection_Other.png"); } tag.ProtectionPicPaths = imgPathList_Protection; #endregion char[] sp = new char[1] { ',' }; #region 危害简述 tag.HazardousDescription = ""; if (!string.IsNullOrEmpty(model.GHS_HazardouDes_Values)) { string[] names = model.GHS_HazardouDes_Values.Split(sp, StringSplitOptions.RemoveEmptyEntries); IList <MSDS_H_Statement> h_statments = _h_StatementService.GetListByNames(names); int i = 1; foreach (MSDS_H_Statement item in h_statments) { tag.HazardousDescription += "● " + item.Description + "\r\n"; i++; if (i > 3) { break; } } } else { tag.HazardousDescription = model.GHS_HazardouDes_Append; } #endregion tag.Product_ET_FaceAndEye = model.Product_ET_FaceAndEye?.Replace("\r\n", ""); tag.Product_ET_SkinAndHand = model.Product_ET_SkinAndHand?.Replace("\r\n", ""); tag.Product_ET_Inhalation = model.Product_ET_Inhalation?.Replace("\r\n", ""); tag.Product_ET_Ingestion = model.Product_ET_Ingestion?.Replace("\r\n", ""); _importExportService.ExportTagWithTemplate(tag); }
private void ExportToTag(string filePath, MSDS_Specification model) { Tag_ExportModel tag = new Tag_ExportModel(); tag.SheetName_Big = "大标签"; tag.SheetName_Small = "小标签"; tag.templateFilePath = filePath; tag.ProductName = model.CN_Name ?? model.Product_Name; #region 危险组分 tag.HS = "组分:"; if (model.HazardousSubstance != null && model.HazardousSubstance.Count > 0) { int i = 1; foreach (MSDS_HazardousSubstances hs in model.HazardousSubstance) { if (i > 1) { tag.HS += "/n"; } tag.HS += hs.HS_Name + hs.HS_MinPercent + "-" + hs.HS_MaxPercent + "%"; i++; } } else { tag.HS = ""; } #endregion #region 危险图标 List <string> imgPathList = new List <string>(); string strRootPath = Server.MapPath("~/Content/Images/"); if (model.IsExplosive) { imgPathList.Add(strRootPath + "Explosive.png"); } if (model.IsFlammable) { imgPathList.Add(strRootPath + "Flammable.png"); } if (model.IsCorrosive) { imgPathList.Add(strRootPath + "Corrosive.png"); } if (model.IsHealthHazard) { imgPathList.Add(strRootPath + "HealthHazard.png"); } if (model.IsToxic) { imgPathList.Add(strRootPath + "Toxic.png"); } if (model.IsOxidizing) { imgPathList.Add(strRootPath + "Oxidizing.png"); } if (model.IsGasUnderPressure) { imgPathList.Add(strRootPath + "GasUnderPressure.png"); } if (model.IsIrritant) { imgPathList.Add(strRootPath + "Irritant.png"); } if (model.IsDangerousToEnvironment) { imgPathList.Add(strRootPath + "DangerousToEnvironment.png"); } tag.WarningPicPaths = imgPathList; tag.BlankPicPath = strRootPath + "blank.png"; #endregion #region 危害警示 tag.WarningContent = model.GHS_Warning; #endregion char[] sp = new char[1] { ',' }; #region 危害简述 tag.HazardousDescription = ""; if (!string.IsNullOrEmpty(model.GHS_HazardouDes_Values)) { string[] names = model.GHS_HazardouDes_Values.Split(sp, StringSplitOptions.RemoveEmptyEntries); IList <MSDS_H_Statement> h_statments = _h_StatementService.GetListByNames(names); foreach (MSDS_H_Statement item in h_statments) { tag.HazardousDescription += "" + item.Description + ","; } tag.HazardousDescription = tag.HazardousDescription.Substring(0, tag.HazardousDescription.Length - 1); } else { tag.HazardousDescription = model.GHS_HazardouDes_Append; } #endregion #region 预防措施 tag.DefenceDes = ""; if (!string.IsNullOrEmpty(model.GHS_DefenceDes_Values)) { string[] names = model.GHS_DefenceDes_Values.Split(sp, StringSplitOptions.RemoveEmptyEntries); IList <MSDS_P_Statement> statements = _p_StatementService.GetListByNames(names); int i = 1; foreach (MSDS_P_Statement item in statements) { tag.DefenceDes += "● " + item.Description + "\r\n"; i++; if (i > 3) { break; } } } else { tag.DefenceDes = model.GHS_DefenceDes_Append; } #endregion #region 事故响应 tag.DealDES = ""; if (!string.IsNullOrEmpty(model.GHS_DealDES_Values)) { string[] names = model.GHS_DealDES_Values.Split(sp, StringSplitOptions.RemoveEmptyEntries); IList <MSDS_P_Statement> statements = _p_StatementService.GetListByNames(names); int i = 1; foreach (MSDS_P_Statement item in statements) { tag.DealDES += "● " + item.Description + "\r\n"; i++; if (i > 7) { break; } } } else { tag.DealDES = model.GHS_DealDES_Append; } #endregion #region 安全储存 //tag.StoreDes = ""; //if (!string.IsNullOrEmpty(model.GHS_StoreDes_Values)) //{ // string[] names = model.GHS_StoreDes_Values.Split(sp, StringSplitOptions.RemoveEmptyEntries); // IList<MSDS_P_Statement> statements = _p_StatementService.GetListByNames(names); // int i = 1; // foreach (MSDS_P_Statement item in statements) // { // tag.StoreDes += item.Description + ";"; // i++; // if (i > 3) break; // } //} //else //{ // tag.StoreDes = model.GHS_StoreDes_Append; //} //if (tag.StoreDes?.Length > 34) //{ // tag.StoreDes = tag.StoreDes.Substring(0, 34); //} tag.StoreDes = "存储化学品必须遵照国家法律、法规和其他有关的规定,化学品应有明显的标志。一般情况下,应避免阳光直射,保持通风良好,储存区域内严禁吸烟和使用明火。"; #endregion #region 废弃处置 //if (model.Product_WasteHanding?.Length > 95) //{ // tag.WasteHanding = model.Product_WasteHanding.Substring(0,95); //} //else //{ // tag.WasteHanding = model.Product_WasteHanding; //} tag.WasteHanding = "请遵从当地环保法规要求"; #endregion #region 供应商信息 tag.Supplier_Big = string.Format(@"供应商:{0} 地址:{1} 电话:{2} 应急电话:{3}", model.Supplier_Name, model.Supplier_Address, model.Supplier_Phone, model.Supplier_UrgencyCall); tag.Supplier_Small = string.Format(@"供应商:{0} 地址:{1} 电话:{2}", model.Supplier_Name, model.Supplier_Address, model.Supplier_Phone); #endregion _importExportService.ExportTagWithTemplate(tag); }
private void PrepareSpecificationViewModel(SpecificationViewModel model, MSDS_Specification entity) { #region 加载状态DropDownList List <Product_State> stateList = new List <Product_State>(); stateList.Add(new Product_State { State_Id = 0, State_Name = "" }); stateList.Add(new Product_State { State_Id = 1, State_Name = "气态" }); stateList.Add(new Product_State { State_Id = 2, State_Name = "液态" }); stateList.Add(new Product_State { State_Id = 3, State_Name = "固态" }); stateList.Add(new Product_State { State_Id = 4, State_Name = "气溶胶" }); stateList.Add(new Product_State { State_Id = 5, State_Name = "凝胶" }); stateList.Add(new Product_State { State_Id = 6, State_Name = "膏状物" }); stateList.Add(new Product_State { State_Id = 7, State_Name = "其他" }); List <string> warningSign = new List <string>(); warningSign.Add("警 告"); warningSign.Add("危 险"); IList <MSDS_H_Statement> statments = _h_StatementService.GetAll(); IList <MSDS_P_Statement> p_statments = _p_StatementService.GetAll(); foreach (var item in stateList) { model.ProductStateItems.Add(new SelectListItem { Text = item.State_Name, Value = item.State_Id.ToString(), Selected = entity != null && item.State_Id == entity.Product_State }); } foreach (var item in warningSign) { model.ProductWarningSignItems.Add(new SelectListItem { Text = item, Value = item, Selected = entity != null && item == entity.GHS_Warning }); } #endregion if (entity != null && entity.UnHazardousChemical.HasValue && !entity.UnHazardousChemical.Value) { model.UnHazardousChemicalItems.Add(new SelectListItem { Text = "是", Value = "true", Selected = false }); model.UnHazardousChemicalItems.Add(new SelectListItem { Text = "否", Value = "false", Selected = true }); } else { model.UnHazardousChemicalItems.Add(new SelectListItem { Text = "是", Value = "true", Selected = true }); model.UnHazardousChemicalItems.Add(new SelectListItem { Text = "否", Value = "false", Selected = false }); } if (entity != null) { model.Id = entity.Id; char[] sp = new char[1] { ',' }; #region foreach (MSDS_H_Statement item in statments) { string[] tempArray = entity.GHS_HazardouDes_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries); if (tempArray != null && tempArray.Any(o => o == item.Code)) { model.GHS_HazardouDes_String += item.Description + "\r\n"; } } foreach (MSDS_P_Statement item in p_statments) { string[] tempArray1 = entity.GHS_DefenceDes_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries); if (tempArray1 != null && tempArray1.Any(o => o == item.Code)) { model.GHS_DefenceDes_String += item.Description + "\r\n"; } string[] tempArray2 = entity.GHS_DealDES_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries); if (tempArray2 != null && tempArray2.Any(o => o == item.Code)) { model.GHS_DealDES_String += item.Description + "\r\n"; } string[] tempArray3 = entity.GHS_StoreDes_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries); if (tempArray3 != null && tempArray3.Any(o => o == item.Code)) { model.GHS_StoreDes_String += item.Description + "\r\n"; } } #endregion } }
public void Delete(MSDS_Specification entity) { _context.MSDS_Specification.Remove(entity); }
public void Add(MSDS_Specification entity) { _context.MSDS_Specification.Add(entity); }
public void Delete(MSDS_Specification entity) { _msds_SpecificationRepository.Delete(entity); }
public void Add(MSDS_Specification specification) { _msds_SpecificationRepository.Add(specification); }