Пример #1
0
        public JsonResult getTempsbyInvCateId(int invCateId)
        {
            IInvTemplateService _invTempSrc = IoC.Resolve <IInvTemplateService>();
            var listTemps = _invTempSrc.GetTempOfCate(invCateId);

            return(Json(new { listTemps }));
        }
Пример #2
0
        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"));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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"));
        }
Пример #5
0
        public ActionResult ChooseTemp()
        {
            RegisterTempChoiseModels model      = new RegisterTempChoiseModels();
            IInvCategoryService      invCateSrv = IoC.Resolve <IInvCategoryService>();
            IRegisterTempService     _regSrc    = IoC.Resolve <IRegisterTempService>();

            model.InvCategories = invCateSrv.Query.OrderBy(p => p.id).ToList();
            IInvTemplateService _invTempSrc = IoC.Resolve <IInvTemplateService>();

            model.CurrentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            return(View(model));
        }
Пример #6
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))));
        }
Пример #7
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));
            }
        }