public ActionResult GetXSLTbyTempName(string tempname) { IInvTemplateService src = IoC.Resolve <IInvTemplateService>(); InvTemplate temp = src.GetByName(tempname); byte[] xsltData = null; if (temp.IsPub) { string xslt = temp.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 head = xslt.Substring(0, xslt.IndexOf(tmp) + tmp.Length); string foot = xslt.Substring(xslt.IndexOf("</style>")); sb.AppendFormat("{0}{1}{2}{3}{4}", head, temp.CssData, temp.CssLogo, temp.CssBackgr, foot); } //InvTemplate temp = src.GetByName(tempname); xsltData = System.Text.Encoding.UTF8.GetBytes(sb.ToString()); } else { xsltData = System.Text.Encoding.UTF8.GetBytes(temp.XsltFile); } return(File(xsltData, "text/xsl")); }
public ActionResult Create(int tempid) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvTemplateService tempSrv = IoC.Resolve <IInvTemplateService>(); IInvCategoryService cateSrv = IoC.Resolve <IInvCategoryService>(); IRegisterTempService _regSrc = IoC.Resolve <IRegisterTempService>(); if (_regSrc.Query.Where(p => p.InvoiceTemp.Id == tempid && p.ComId == currentCom.id).Count() > 0) { Messages.AddErrorFlashMessage("Mẫu hóa đơn đã được đăng ký, vui lòng chọn mẫu khác."); return(RedirectToAction("Choosetemp")); } RegisterTempModels model = new RegisterTempModels(); InvTemplate invTemp = tempSrv.Getbykey(tempid); decimal i = _regSrc.GetMaxPatternOrder(invTemp.InvCateID, currentCom.id); RegisterTemp temp = new RegisterTemp(); temp.Name = invTemp.TemplateName; temp.NameInvoice = invTemp.InvCateName; temp.InvCateID = invTemp.InvCateID; temp.InvPattern = cateSrv.Getbykey(invTemp.InvCateID).InvPattern + "0"; temp.PatternOrder = i + 1; temp.CssData = invTemp.CssData; temp.IsCertify = invTemp.IsCertify; model.RegisTemp = temp; model.CurrentCom = currentCom; model.tempId = tempid; return(View(model)); }
public ActionResult GetXSLTbyPattern(string pattern) { Company currentComp = ((EInvoiceContext)FX.Context.FXContext.Current).CurrentCompany; RegisterTemp temp = InvServiceFactory.GetRegister(pattern, currentComp.id); InvTemplate invTemp = InvServiceFactory.GetTemplateByPattern(pattern, currentComp.id); 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 head = xslt.Substring(0, xslt.IndexOf(tmp) + tmp.Length); string foot = xslt.Substring(xslt.IndexOf("</style>")); if (!string.IsNullOrWhiteSpace(temp.CssData)) { sb.AppendFormat("{0}{1}{2}{3}{4}", head, temp.CssData, temp.CssLogo, temp.CssBackgr, foot); } else { sb.AppendFormat("{0}{1}{2}{3}{4}", head, invTemp.CssData, invTemp.CssLogo, invTemp.CssBackgr, foot); } } //InvTemplate temp = src.GetByName(tempname); byte[] xsltData = System.Text.Encoding.UTF8.GetBytes(sb.ToString()); return(File(xsltData, "text/xsl")); }
public ActionResult getXSLTbyTempName(string tempname) { IInvTemplateService src = IoC.Resolve <IInvTemplateService>(); InvTemplate temp = InvServiceFactory.GetTemplateByName(tempname); byte[] xsltData = System.Text.Encoding.UTF8.GetBytes(temp.XsltFile); return(File(xsltData, "text/xsl")); }
public ActionResult GetXSLT(string pattern) { Company currentComp = ((EInvoiceContext)FX.Context.FXContext.Current).CurrentCompany; byte[] xsltData; InvTemplate temp = new InvTemplate(); temp = InvServiceFactory.GetTemplateByPattern(pattern, currentComp.id); xsltData = System.Text.Encoding.UTF8.GetBytes(temp.XsltFile); return(File(xsltData, "text/xsl")); }
public static ValidationResult checkExistInvoiceTemplateTypeView(int Type) { InvTemplateDA ctlInvTemp = new InvTemplateDA(); InvTemplate objInv = ctlInvTemp.checkExistTypeView(Type, "XKTX"); if (objInv != null) { return(new ValidationResult(ConstantsMultiLanguageKey.E_InvoiceTemplate_Type)); } else { return(null); } }
public ActionResult previewTemplate(int tempId) { InvTemplate it = new InvTemplate(); IInvTemplateService _invTempSrc = IoC.Resolve <IInvTemplateService>(); it = _invTempSrc.Getbykey(tempId); XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(it.XmlFile); XmlProcessingInstruction newPI; String PItext = "type='text/xsl' href='" + FX.Utils.UrlUtil.GetSiteUrl() + "/InvoiceTemplate/GetXSLTbyTempName?tempname=" + it.TemplateName + "'"; newPI = xdoc.CreateProcessingInstruction("xml-stylesheet", PItext); xdoc.InsertBefore(newPI, xdoc.DocumentElement); IViewer _iViewerSrv = InvServiceFactory.GetViewer(it.TemplateName); return(Json(_iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(xdoc.OuterXml)))); }
public ActionResult AjxPreviewPubInv(int tempid, string serialNo) { IRegisterTempService regisTempSrv = IoC.Resolve <IRegisterTempService>(); Company currCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; RegisterTemp temp = regisTempSrv.Getbykey(tempid); InvTemplate it = temp.InvoiceTemp; XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(it.XmlFile); // if (xdoc.GetElementsByTagName("ComName")[0] != null) { xdoc.GetElementsByTagName("ComName")[0].InnerText = currCom.Name; } if (xdoc.GetElementsByTagName("ParentName")[0] != null) { xdoc.GetElementsByTagName("ParentName")[0].InnerText = currCom.ParentName; } if (xdoc.GetElementsByTagName("ComAddress")[0] != null) { xdoc.GetElementsByTagName("ComAddress")[0].InnerText = currCom.Address; } if (xdoc.GetElementsByTagName("ComPhone")[0] != null) { xdoc.GetElementsByTagName("ComPhone")[0].InnerText = currCom.Phone; } if (xdoc.GetElementsByTagName("ComFax")[0] != null) { xdoc.GetElementsByTagName("ComFax")[0].InnerText = currCom.Fax; } if (xdoc.GetElementsByTagName("ComBankName")[0] != null) { xdoc.GetElementsByTagName("ComBankName")[0].InnerText = currCom.BankName; } if (xdoc.GetElementsByTagName("ComBankNo")[0] != null) { xdoc.GetElementsByTagName("ComBankNo")[0].InnerText = currCom.BankNumber; } if (xdoc.GetElementsByTagName("ComTaxCode")[0] != null) { xdoc.GetElementsByTagName("ComTaxCode")[0].InnerText = currCom.TaxCode; } if (xdoc.GetElementsByTagName("SerialNo")[0] != null) { xdoc.GetElementsByTagName("SerialNo")[0].InnerText = serialNo; } XmlProcessingInstruction newPI; string urlPub = FX.Utils.UrlUtil.GetSiteUrl(); String PItext = "type='text/xsl' href='"; if (it.CssData != null) { PItext += urlPub + "/InvoiceTemplate/GetXSLTbyPattern/1?pattern=" + temp.InvPattern + "'"; } else { PItext += urlPub + "/InvoiceTemplate/GetXSLTbyTempName?tempname=" + it.TemplateName + "'"; } newPI = xdoc.CreateProcessingInstruction("xml-stylesheet", PItext); xdoc.InsertBefore(newPI, xdoc.DocumentElement); //logtest.Info("tempName: " + tempName + " href: " + PItext); // IViewer _iViewerSrv = IoC.Resolve<IViewer>(); IViewer _iViewerSrv = InvServiceFactory.GetViewer(it.TemplateName); return(Json(_iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(xdoc.OuterXml)))); }
public ActionResult Create(RegisterTemp temp, string actionName, int tempId) { HttpPostedFileBase logoImg = Request.Files["logoImg"]; HttpPostedFileBase bgrImg = Request.Files["bgrImg"]; string _logoFile = Request["logoFile"]; string _imgFile = Request["imgFile"]; Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvTemplateService tempSrv = IoC.Resolve <IInvTemplateService>(); IRegisterTempService regisTempSrv = IoC.Resolve <IRegisterTempService>(); string registerPattern = temp.InvPattern + "/" + temp.PatternOrder.ToString("000"); if (regisTempSrv.Query.Where(p => p.InvPattern.ToUpper() == registerPattern.ToUpper() && p.ComId == temp.ComId).Count() > 0) { Messages.AddErrorMessage(string.Format("Mẫu số [{0}] đã được đăng ký cho công ty.", registerPattern)); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; return(View(model)); } try { InvTemplate invTemp = tempSrv.Getbykey(tempId); temp.InvoiceTemp = invTemp; string logoKey = string.Format("{0}_{1}", currentCom.id, "logo"); string backgroudKey = string.Format("{0}_{1}", currentCom.id, "backgroud"); if (logoImg != null && logoImg.ContentLength > 0) { byte[] byteLogoImg = readContentFilePosted(logoImg); setCacheContext(logoKey, updateCss(invTemp.CssLogo, byteLogoImg)); } if (string.IsNullOrWhiteSpace(_logoFile) && !string.IsNullOrWhiteSpace(invTemp.CssLogo)) { setCacheContext(logoKey, invTemp.CssLogo); } if (bgrImg != null && bgrImg.ContentLength > 0) { byte[] bytebgrImg = readContentFilePosted(bgrImg); setCacheContext(backgroudKey, updateCss(invTemp.CssBackgr, bytebgrImg, false)); } if (string.IsNullOrWhiteSpace(_imgFile) && !string.IsNullOrWhiteSpace(invTemp.CssBackgr)) { setCacheContext(backgroudKey, invTemp.CssBackgr); } temp.CssData = !string.IsNullOrWhiteSpace(temp.CssData) ? temp.CssData : invTemp.CssData; if (actionName == "preview") { RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; StringBuilder sumSb = new StringBuilder(); sumSb.AppendFormat("{0}{1}{2}", temp.CssData, getCacheContext(logoKey), getCacheContext(backgroudKey)); XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(invTemp.XmlFile); if (xdoc.GetElementsByTagName("ComName")[0] != null) { xdoc.GetElementsByTagName("ComName")[0].InnerText = currentCom.Name; } if (xdoc.GetElementsByTagName("ComAddress")[0] != null) { xdoc.GetElementsByTagName("ComAddress")[0].InnerText = currentCom.Address; } if (xdoc.GetElementsByTagName("ComPhone")[0] != null) { xdoc.GetElementsByTagName("ComPhone")[0].InnerText = currentCom.Phone; } if (xdoc.GetElementsByTagName("ComBankNo")[0] != null) { //xdoc.GetElementsByTagName("ComFax")[0].InnerText = comFax; xdoc.GetElementsByTagName("ComBankNo")[0].InnerText = currentCom.BankNumber; } if (xdoc.GetElementsByTagName("ComTaxCode")[0] != null) { xdoc.GetElementsByTagName("ComTaxCode")[0].InnerText = currentCom.TaxCode; } XmlNode root = xdoc.DocumentElement; //Create a new node. XmlElement elem = xdoc.CreateElement("CssData"); elem.InnerText = sumSb.ToString(); //Add the node to the document. root.AppendChild(elem); XmlProcessingInstruction newPI; String PItext = "type='text/xsl' href='" + FX.Utils.UrlUtil.GetSiteUrl() + "/RegisterTemp/getXSLTbyTempName?tempname=" + invTemp.TemplateName + "'"; newPI = xdoc.CreateProcessingInstruction("xml-stylesheet", PItext); xdoc.InsertBefore(newPI, xdoc.DocumentElement); IViewer _iViewerSrv = InvServiceFactory.GetViewer(invTemp.TemplateName); ViewData["previewContent"] = _iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(xdoc.OuterXml)); return(View(model)); } temp.ICertifyProvider = temp.IsCertify ? temp.ICertifyProvider : ""; temp.InvPattern = registerPattern; if (regisTempSrv.GetbyPattern(temp.InvPattern, currentCom.id) != null) { Messages.AddErrorFlashMessage("Mẫu số đã được đăng ký, sử dụng mẫu số khác!"); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; return(View(model)); } temp.ComId = currentCom.id; temp.InvCateID = invTemp.InvCateID; temp.CssLogo = getCacheContext(logoKey); temp.CssBackgr = getCacheContext(backgroudKey); regisTempSrv.CreateNew(temp); regisTempSrv.CommitChanges(); Messages.AddFlashMessage("Đăng ký mẫu hóa đơn thành công!"); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; return(View(model)); } }