コード例 #1
0
 public ActionResult ajxPreview(int idInvoice, string pattern)
 {
     try
     {
         Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         IInvoiceService IInvSrv    = InvServiceFactory.GetService(pattern, currentCom.id);
         logtest.Info("call: " + idInvoice + " pattern: " + pattern + " company: " + currentCom.id);
         IInvoice oInvoice = IInvSrv.Getbykey <IInvoice>(idInvoice);
         //IViewer _iViewerSrv = IoC.Resolve<IViewer>();
         IViewer _iViewerSrv = InvServiceFactory.GetViewer(pattern, currentCom.id);
         if (oInvoice.Status != InvoiceStatus.NewInv)
         {
             IRepositoryINV _iRepoSrv = IoC.Resolve <IRepositoryINV>();
             byte[]         data      = _iRepoSrv.GetData(oInvoice);
             return(Json(new { invData = _iViewerSrv.GetHtml(data), status = oInvoice.Status }));
         }
         else
         {
             return(Json(new { invData = _iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(oInvoice.GetXMLData())), status = 0 }));
         }
     }
     catch (Exception ex)
     {
         logtest.Error(ex);
         return(Json(new { invData = "Có lỗi xảy ra, vui lòng thực hiện lại.", status = 0 }));
     }
 }
コード例 #2
0
        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))));
        }
コード例 #3
0
ファイル: PublishController.cs プロジェクト: war-man/vInvoice
        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))));
        }
コード例 #4
0
        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));
            }
        }