//添加COA报告 public void AddCOA(ChemCloud_COA model) { context.ChemCloud_COA.Add(model); context.SaveChanges(); foreach (var item in model.ChemCloud_COADetails) { context.ChemCloud_COADetails.Add(item); context.SaveChanges(); } }
public JsonResult AddCOA(string json) { Result result = new Result(); try { ChemCloud_COA model = Newtonsoft.Json.JsonConvert.DeserializeObject <ChemCloud_COA>(json); //序列化json model.Supplier = base.CurrentSellerManager.UserName; model.DATEOFRELEASE = DateTime.Now; ServiceHelper.Create <ICOAService>().AddCOA(model); result.success = true; } catch (Exception exception) { result.msg = exception.Message; } return(Json(result)); }
public JsonResult AddPdfByHtml(string CoANo, string Html, string titles, string CASNo, string Specification) { titles = titles.Substring(0, titles.Length - 1); Specification = Specification.Substring(0, Specification.Length - 1); ChemCloud_COA model = Newtonsoft.Json.JsonConvert.DeserializeObject <ChemCloud_COA>(Html); List <string> titlelist = titles.Split(';').ToList <string>(); List <string> SpecificationList = Specification.Split(';').ToList <string>(); string serverFilepath = Server.MapPath(string.Format("/Storage/PDF/{0}/ ", base.CurrentUser.Id)); if (!System.IO.Directory.Exists(serverFilepath)) { System.IO.Directory.CreateDirectory(serverFilepath); } string serverFileName = "CoAReports" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".pdf"; Result res = new Result(); iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.A4); try { iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(serverFilepath + serverFileName, FileMode.Create)); document.Open(); iTextSharp.text.pdf.BaseFont bfChinese = iTextSharp.text.pdf.BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED); iTextSharp.text.Font Titlefont = new iTextSharp.text.Font(bfChinese, 16, iTextSharp.text.Font.BOLD); iTextSharp.text.Font titleDetial = new iTextSharp.text.Font(bfChinese, 11, iTextSharp.text.Font.BOLD); iTextSharp.text.Font normall = new iTextSharp.text.Font(bfChinese, 11, iTextSharp.text.Font.NORMAL); iTextSharp.text.Font newtable = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.BOLD); iTextSharp.text.Font newtableInner = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL); Paragraph p = new Paragraph("CERTIFICATE OF ANALYSIS" + "\n\n", Titlefont); p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(p); PdfPTable table = new PdfPTable(4); table.DefaultCell.MinimumHeight = 30; table.SetWidths(new int[] { 35, 15, 35, 15 }); PdfPCell cell; cell = new PdfPCell(); Paragraph pCell; pCell = new Paragraph("CertificateNumber", titleDetial); table.AddCell(pCell); pCell = new Paragraph(model.CertificateNumber, normall); table.AddCell(pCell); pCell = new Paragraph("Suppiler", titleDetial); table.AddCell(pCell); pCell = new Paragraph(ServiceHelper.Create <IShopService>().GetShopName(base.CurrentSellerManager.ShopId), normall); table.AddCell(pCell); cell = new PdfPCell(); pCell = new Paragraph("Product Code", titleDetial); table.AddCell(pCell); pCell = new Paragraph(model.ProductCode, normall); table.AddCell(pCell); pCell = new Paragraph("Manufacturer's Batch #", titleDetial); table.AddCell(pCell); pCell = new Paragraph(model.ManufacturersBatchNo, normall); table.AddCell(pCell); cell = new PdfPCell(); pCell = new Paragraph("Product", titleDetial); table.AddCell(pCell); pCell = new Paragraph(model.ProductName, normall); table.AddCell(pCell); pCell = new Paragraph("Sydco's Lab.Batch #", titleDetial); table.AddCell(pCell); pCell = new Paragraph(model.SydcosLabBatchNo, normall); table.AddCell(pCell); cell = new PdfPCell(); pCell = new Paragraph("Date of Manufacture", titleDetial); table.AddCell(pCell); pCell = new Paragraph(model.DateofManufacture.ToShortDateString(), normall); table.AddCell(pCell); pCell = new Paragraph("ExpiryDate", titleDetial); table.AddCell(pCell); pCell = new Paragraph(model.ExpiryDate.ToShortDateString(), normall); table.AddCell(pCell); document.Add(table); Paragraph pfoot = new Paragraph("\n The undersigned hereby certifies the following data to be true specification" + "\n\n\n\n\n", titleDetial); p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(pfoot); foreach (ChemCloud_COADetails item in model.ChemCloud_COADetails) { PdfPTable table1 = new PdfPTable(3); table1.DefaultCell.MinimumHeight = 30; table1.SetWidths(new int[] { 40, 20, 35 }); pCell = new Paragraph("Tests", newtable); table1.AddCell(pCell); pCell = new Paragraph("Results", newtable); table1.AddCell(pCell); pCell = new Paragraph("Specifications(BP)", newtable); table1.AddCell(pCell); pCell = new Paragraph(titlelist[0], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Appearance, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[0], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[1], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.IIdentity, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[1], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[2], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Carbonates, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[2], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[3], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Solubility, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[3], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[4], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Ammonium, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[4], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[5], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Calcium, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[5], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[6], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Arsenic, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[6], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[7], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.HeavyMetals, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[7], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[8], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Iron, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[8], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[9], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Sulphates, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[9], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[10], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Chlorides, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[10], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[11], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.Appearanceofsolution, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[11], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(titlelist[12], newtableInner); table1.AddCell(pCell); pCell = new Paragraph(item.MicroStatus, newtableInner); table1.AddCell(pCell); pCell = new Paragraph(SpecificationList[12], newtableInner); table1.AddCell(pCell); document.Add(table1); Paragraph ppp = new Paragraph("\n\n\n\n\n\n", titleDetial); ppp.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(ppp); } } catch (Exception de) { res.success = false; return(Json(res)); } document.Close(); res.success = true; //string pdfpath1 = string.Format("/Storage/PDF/{0}/", base.CurrentUser.Id); string str = ImgHelper.PostImg(serverFilepath + serverFileName, "coapic"); COAList cr = new COAList() { Addtime = DateTime.Now, CoANo = CoANo, URL = str, UserId = base.CurrentUser.Id, AddUserType = 2, CASNo = CASNo }; ServiceHelper.Create <ICOAListService>().AddCoAReportInfo(cr); return(Json(res)); }