Пример #1
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));
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IRegisterTempService   registerTempSrv = IoC.Resolve <IRegisterTempService>();
            IPublishInvoiceService publishInvSrv   = IoC.Resolve <IPublishInvoiceService>();

            if (publishInvSrv.GetPubOfReg(id, currentCom.id).Count > 0)
            {
                Messages.AddErrorFlashMessage("Không được sửa mẫu hóa đơn đang sử dụng.");
                return(RedirectToAction("Index"));
            }
            string             logoKey      = string.Format("{0}_{1}", currentCom.id, "logo");
            string             backgroudKey = string.Format("{0}_{1}", currentCom.id, "backgroud");
            RegisterTemp       registerTemp = registerTempSrv.Getbykey(id);
            RegisterTempModels model        = new RegisterTempModels();

            model.tempId     = registerTemp.InvoiceTemp.Id;
            model.CurrentCom = currentCom;
            model.logoFile   = model.imgFile = registerTemp.Name;
            model.RegisTemp  = registerTemp;
            if (!string.IsNullOrWhiteSpace(registerTemp.CssLogo))
            {
                setCacheContext(logoKey, registerTemp.CssLogo);
            }
            if (!string.IsNullOrWhiteSpace(registerTemp.CssBackgr))
            {
                setCacheContext(backgroudKey, registerTemp.CssBackgr);
            }
            return(View(model));
        }
Пример #3
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));
            }
        }