private String GetXSLTByTemplate(InvTemplate_GetTemplateInvoice_Result invtemp) { String xsltData = null; if ((invtemp.IsPub ?? false) && !string.IsNullOrWhiteSpace(invtemp.CssData)) { string xslt = invtemp.XsltFile; string tmp = "<style type=\"text/css\">"; StringBuilder sb = new StringBuilder(); if (!xslt.Contains(tmp)) { tmp = "<style type=\"text/css\" rel=\"stylesheet\">"; } if (xslt.Contains(tmp)) { string cssData = invtemp.CssData; string cssLogo = invtemp.CssLogo; string cssBackgr = invtemp.CssBackgr; if (invtemp != null) { cssData = invtemp.CssData; cssLogo = invtemp.CssLogo; cssBackgr = invtemp.CssBackgr; } string head = xslt.Substring(0, xslt.IndexOf(tmp) + tmp.Length); string foot = xslt.Substring(xslt.IndexOf("</style>")); sb.AppendFormat("{0}{1}{2}{3}{4}", head, cssData, cssLogo, cssBackgr, foot); } var ttt = sb.ToString(); xsltData = sb.ToString(); } else { xsltData = invtemp.XsltFile; } return(xsltData); }
public string GetHtml(byte[] invData, InvTemplate_GetTemplateInvoice_Result invtemp) { XmlDocument xDoc = new XmlDocument(); xDoc.PreserveWhitespace = true; xDoc.LoadXml(System.Text.Encoding.UTF8.GetString(invData)); StringWriter sw = new StringWriter(); XslCompiledTransform xct = new XslCompiledTransform(); XmlProcessingInstruction instruction = xDoc.SelectSingleNode("processing-instruction('xml-stylesheet')") as XmlProcessingInstruction; if (xDoc.GetElementsByTagName("Signature")[0] != null) { byte[] rawCert = Convert.FromBase64String(xDoc.GetElementsByTagName("X509Certificate")[0].InnerText); X509Certificate2 cert = new X509Certificate2(rawCert); XmlElement xe = xDoc.CreateElement("CNCom"); Match match = Regex.Match(cert.SubjectName.Name, @"CN=\s*(\w+\s?)+"); if (match.Success) { xe.InnerText = match.Groups[0].Value.Remove(0, 3); } xDoc.DocumentElement.AppendChild(xe); if (xDoc.GetElementsByTagName("Signature")[1] != null) { rawCert = Convert.FromBase64String(xDoc.GetElementsByTagName("X509Certificate")[1].InnerText); cert = new X509Certificate2(rawCert); xe = xDoc.CreateElement("CNCus"); match = Regex.Match(cert.SubjectName.Name, @"CN=\s*(\w+\s?)+"); if (match.Success) { xe.InnerText = match.Groups[0].Value.Remove(0, 3); } xDoc.DocumentElement.AppendChild(xe); } ImageGenerator.AddCompanyImage(xDoc, true, false); } if (instruction != null) { //XmlElement dummyPi = instruction.OwnerDocument.ReadNode(XmlReader.Create(new StringReader("<pi " + instruction.Value + "/>"))) as XmlElement; //string href = dummyPi.GetAttribute("href"); xct.Load(new XmlTextReader(new StringReader(GetXSLTByTemplate(invtemp)))); xct.Transform(xDoc, null, sw); } return(sw.ToString().Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "")); }
public InvTemplate_GetTemplateInvoice_Result InvTemplate_GetTemplateInvoice(String pattern, String taxCode) { InvTemplate_GetTemplateInvoice_Result obj = dbInvoice.db.InvTemplate_GetTemplateInvoice(pattern, taxCode).FirstOrDefault <InvTemplate_GetTemplateInvoice_Result>(); return(obj); }