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 Delete(int id)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IRegisterTempService   registerTempSrv = IoC.Resolve <IRegisterTempService>();
            IPublishInvoiceService publishInvSrv   = IoC.Resolve <IPublishInvoiceService>();

            try
            {
                if (publishInvSrv.GetPubOfReg(id, currentCom.id).Count > 0)
                {
                    Messages.AddErrorFlashMessage("Không được xóa mẫu hóa đơn đang sử dụng.");
                    return(RedirectToAction("Index"));
                }
                RegisterTemp model = registerTempSrv.Getbykey(id);
                registerTempSrv.Delete(model);
                registerTempSrv.CommitChanges();
                Messages.AddFlashMessage("Xóa mẫu hóa đơn thành công.");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
            }
            return(RedirectToAction("Index"));
        }
        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));
        }
 public ResultHelper Post([FromBody] RegisterTemp RegisterTemp)
 {
     if (RegisterTemp == null)
     {
         return(new ResultHelper(true, RegisterTemp.RegisterTempID, ResultHelper.UnSuccessMessage));
     }
     registerTempService.Create(RegisterTemp);
     return(new ResultHelper(true, RegisterTemp.RegisterTempID, ResultHelper.SuccessMessage));
 }
        public ResultHelper Put(int id, [FromBody] RegisterTemp RegisterTemp)
        {
            if (RegisterTemp == null)
            {
                return(new ResultHelper(true, RegisterTemp.RegisterTempID, ResultHelper.UnSuccessMessage));
            }


            registerTempService.Set(RegisterTemp);
            return(new ResultHelper(true, RegisterTemp.RegisterTempID, ResultHelper.SuccessMessage));
        }
        public ResultHelper Delete(int id)
        {
            RegisterTemp RegisterTemp = registerTempService.Get(id);

            if (RegisterTemp == null)
            {
                return(new ResultHelper(true, RegisterTemp.RegisterTempID, ResultHelper.UnSuccessMessage));
            }

            registerTempService.Delete(RegisterTemp);
            return(new ResultHelper(true, RegisterTemp.RegisterTempID, ResultHelper.SuccessMessage));
        }
示例#8
0
        public string CertifyReplace(string pattern, IList <IInvoice> invoices, Company currentCompany, bool resend = false)
        {
            string           ErrorMessages    = "";
            RegisterTemp     temp             = InvServiceFactory.GetRegister(pattern, currentCompany.id);
            ICertifyProvider _CertifyProvider = IoC.Resolve(Type.GetType(temp.ICertifyProvider)) as ICertifyProvider;

            /// Xac thuc hoa don
            string errCertify = _CertifyProvider.CertifyReplace(pattern, invoices, currentCompany);

            if (!string.IsNullOrWhiteSpace(errCertify))
            {
                ErrorMessages = errCertify;
            }
            return("value");
        }
示例#9
0
        public IHttpActionResult ImportAndPublishInv(ApiPublish publish)
        {
            ILog log = LogManager.GetLogger(typeof(PublishController));
            //check valiadate xml
            XmlSchemaValidator validator = new XmlSchemaValidator();

            //xmlInvData = convertSpecialCharacter(xmlInvData);
            if (!validator.ValidXmlDoc(publish.xmlData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\VATInVoice_ws.xsd"))
            {
                log.Error(publish.xmlData);
                log.Error("ERR:3-" + validator.ValidationError);
                return(Ok("ERR:3-" + validator.ValidationError));  //du lieu dau vao khong hop le
            }

            if (publish.convert == 1)
            {
                publish.xmlData = DataHelper.convertTCVN3ToUnicode(publish.xmlData);
            }

            Company  _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IDeliver _DeliverService = _currentCompany.Config.ContainsKey("IDeliver") ? InvServiceFactory.GetDeliver(_currentCompany.Config["IDeliver"]) : null;
            int      comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return(NotFound());
            }
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            int    patternNull = string.IsNullOrEmpty(publish.pattern) ? 0 : 1;
            int    serialNull  = string.IsNullOrEmpty(publish.serial) ? 0 : 1;
            string nameInvoice = "";

            switch ((patternNull + serialNull))
            {
            case 0:
                PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
                if (pubinv != null)
                {
                    IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>();
                    RegisterTemp         rtemp    = regisSrv.Getbykey(pubinv.RegisterID);
                    publish.pattern = pubinv.InvPattern;
                    publish.serial  = pubinv.InvSerial;
                    nameInvoice     = rtemp.NameInvoice;
                    _PubInvSrv.UnbindSession(pubinv);
                    regisSrv.UnbindSession(rtemp);
                }
                else
                {
                    return(Ok("ERR:20"));     //tham so pattern va serial khong hop le
                }
                break;

            case 1:
                PublishInvoice pubFirst = null;
                try
                {
                    if (!string.IsNullOrWhiteSpace(publish.pattern))
                    {
                        pubFirst = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvPattern == publish.pattern) && (p.Status == 1 || p.Status == 2) select p).FirstOrDefault();
                    }
                    else
                    {
                        pubFirst = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvSerial == publish.serial) && (p.Status == 1 || p.Status == 2) select p).FirstOrDefault();
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    return(Ok("ERR:20"));      //khong can return cung duoc
                }
                if (pubFirst == null)
                {
                    return(Ok("ERR:20"));
                }
                else
                {
                    IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>();
                    RegisterTemp         rtemp    = regisSrv.Getbykey(pubFirst.RegisterID);
                    nameInvoice     = rtemp.NameInvoice;
                    publish.pattern = pubFirst.InvPattern;
                    publish.serial  = pubFirst.InvSerial;
                    _PubInvSrv.UnbindSession(pubFirst);
                    regisSrv.UnbindSession(rtemp);
                }
                break;

            case 2:
                // PublishInvoice pub = _PubInvSrv.CurrentPubInv(comID, pattern, serial, 1);
                PublishInvoice pub = null;
                try
                {
                    pub = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvPattern == publish.pattern) && (p.InvSerial == publish.serial) && (p.Status == 1 || p.Status == 2) select p).First();
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    return(Ok("ERR:20"));       //khong can return cung duoc
                }
                if (pub == null)
                {
                    return(Ok("ERR:20"));
                }
                else
                {
                    IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>();
                    RegisterTemp         rtemp    = regisSrv.Getbykey(pub.RegisterID);
                    nameInvoice = rtemp.NameInvoice;
                    _PubInvSrv.UnbindSession(pub);
                    regisSrv.UnbindSession(rtemp);
                }
                break;
            }
            log.Info("pattern-serial: " + publish.pattern + "-" + publish.serial);
            XElement               elem             = XElement.Parse(publish.xmlData);
            IList <IInvoice>       lstINV           = new List <IInvoice>();
            string                 invKeyAndNumList = "";
            IEnumerable <XElement> listTemp         = elem.Elements("Inv");
            IList <String>         lstKey           = new List <String>();

            //check xem con du so hoa don ko
            if (getMaxInvNumber(comID, publish.pattern, publish.serial) < listTemp.Count())
            {
                return(Ok("ERR:6"));    //khong con du so hoa don cho lo phat hanh
            }
            //check xem lo truyen vao lon hon MaxBlockInv hay ko
            int    maxBlockInv;
            string temp = System.Configuration.ConfigurationManager.AppSettings["MaxBlockInv"];

            if (string.IsNullOrEmpty(temp) || !Int32.TryParse(temp, out maxBlockInv))
            {
                maxBlockInv = 5000;
            }
            if (listTemp.Count() > maxBlockInv)
            {
                return(Ok("ERR:10"));    // lo hoa don truyen vao lon hon maxBlockInv;
            }
            try
            {
                foreach (XElement e in listTemp)
                {
                    XElement ele  = e.Element("Invoice");
                    string   fKey = e.Element("key").Value.Trim();
                    lstKey.Add(fKey);
                    IInvoice inv  = InvServiceFactory.NewInstance(publish.pattern, comID);
                    string   read = string.Concat(ele);
                    inv.DeserializeFromXML(read);
                    inv.Name     = nameInvoice;
                    inv.Pattern  = publish.pattern;
                    inv.Serial   = publish.serial;
                    inv.CreateBy = inv.CreateBy ?? System.Web.HttpContext.Current.User.Identity.Name;
                    inv.Fkey     = fKey;
                    lstINV.Add(inv);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Ok("ERR:5"));//loi phat hanh hoa don
            }

            try
            {
                Launcher.Instance.Launch(publish.pattern, publish.serial, lstINV.ToArray());
                if (_DeliverService != null)
                {
                    _DeliverService.PrepareDeliver(lstINV.ToArray(), _currentCompany);
                }
                for (int i = 0; i < lstINV.Count; i++)
                {
                    invKeyAndNumList += lstKey[i] + "_" + lstINV[i].No + ",";
                }
                //remove the last "," character
                invKeyAndNumList = invKeyAndNumList.Remove(invKeyAndNumList.Length - 1, 1);
                return(Ok("OK:" + publish.pattern + ";" + publish.serial + "-" + invKeyAndNumList));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Ok("ERR:13"));
            }
        }
示例#10
0
        public IHttpActionResult ImportInv(ApiPublish publish)
        {
            ILog log = LogManager.GetLogger(typeof(PublishController));

            XmlSchemaValidator validator = new XmlSchemaValidator();

            //xmlInvData = convertSpecialCharacter(xmlInvData);
            if (!validator.ValidXmlDoc(publish.xmlData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\VATInVoice_ws.xsd"))
            {
                //customer xml string not valid, don't do any thing
                log.Error("ERR3: " + validator.ValidationError);
                return(Ok("ERR:3"));
            }

            if (publish.convert == 1)
            {
                publish.xmlData = DataHelper.convertTCVN3ToUnicode(publish.xmlData);
            }

            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID = _currentCompany.id;
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            string nameInvoice = "", serial = null;

            int patternNull = string.IsNullOrEmpty(publish.pattern) ? 0 : 1;

            switch (patternNull)
            {
            case 0:
                PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
                if (pubinv != null)
                {
                    IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>();
                    RegisterTemp         rtemp    = regisSrv.Getbykey(pubinv.RegisterID);
                    publish.pattern = pubinv.InvPattern;
                    nameInvoice     = rtemp.NameInvoice;
                    serial          = pubinv.InvSerial;
                    _PubInvSrv.UnbindSession(pubinv);
                    regisSrv.UnbindSession(rtemp);
                }
                else
                {
                    return(Ok("ERR:20"));     //tham so pattern va serial khong hop le
                }
                break;

            case 1:
                PublishInvoice pub = null;
                try
                {
                    pub = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvPattern == publish.pattern) && (p.Status == 1 || p.Status == 2) select p).FirstOrDefault();
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    return(Ok("ERR:20"));      //khong can return cung duoc
                }
                if (pub == null)
                {
                    return(Ok("ERR:20"));
                }
                else
                {
                    IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>();
                    RegisterTemp         rtemp    = regisSrv.Getbykey(pub.RegisterID);
                    nameInvoice = rtemp.NameInvoice;
                    serial      = pub.InvSerial;
                    _PubInvSrv.UnbindSession(pub);
                    regisSrv.UnbindSession(rtemp);
                }
                break;
            }

            XElement               elem             = XElement.Parse(publish.xmlData);
            IList <IInvoice>       lstINV           = new List <IInvoice>();
            string                 invKeyAndNumList = "";
            IEnumerable <XElement> listTemp         = elem.Elements("Inv");
            IList <String>         lstKey           = new List <String>();

            //check xem lo truyen vao lon hon MaxBlockInv hay ko
            int    maxBlockInv;
            string temp = System.Configuration.ConfigurationManager.AppSettings["MaxBlockInv"];

            if (string.IsNullOrEmpty(temp) || !Int32.TryParse(temp, out maxBlockInv))
            {
                maxBlockInv = 5000;
            }
            if (listTemp.Count() > maxBlockInv)
            {
                return(Ok("ERR:10"));    // lo hoa don truyen vao lon hon maxBlockInv;
            }
            try
            {
                int cc = listTemp.Count();
                foreach (XElement e in listTemp)
                {
                    XElement ele  = e.Element("Invoice");
                    string   fKey = e.Element("key").Value.Trim();
                    lstKey.Add(fKey);

                    IInvoice inv  = InvServiceFactory.NewInstance(publish.pattern, comID);
                    string   read = string.Concat(ele);
                    inv.DeserializeFromXML(read);
                    inv.No       = 0;
                    inv.Name     = nameInvoice;
                    inv.Pattern  = publish.pattern;
                    inv.Serial   = serial;
                    inv.CreateBy = System.Web.HttpContext.Current.User.Identity.Name;
                    inv.Fkey     = fKey;
                    lstINV.Add(inv);
                }
            }
            catch (Exception ex)
            {
                log.Error("ERR:5-", ex);
                return(Ok("ERR:5"));//loi phat hanh hoa don
            }

            string          mess     = "";
            bool            isImport = false;
            IInvoiceService t        = EInvoice.Core.InvServiceFactory.GetService(publish.pattern, _currentCompany.id);

            t.BeginTran();
            try
            {
                if (lstINV.Count > 50)
                {
                    t.isStateLess = true;
                }
                isImport = t.CreateInvoice(lstINV.ToArray(), out mess);
                t.CommitTran();
            }
            catch (Exception ex)
            {
                t.RolbackTran();
                log.Error(ex);
                return(Ok("ERR:5"));
            }
            finally
            {
                t.isStateLess = false;
            }
            if (isImport)
            {
                for (int i = 0; i < lstINV.Count; i++)
                {
                    invKeyAndNumList += lstKey[i] + ",";
                }
                //remove the last "," character
                invKeyAndNumList = invKeyAndNumList.Remove(invKeyAndNumList.Length - 1, 1);
                return(Ok("OK:" + publish.pattern + ";" + serial + "-" + invKeyAndNumList));
            }
            log.Error(mess);
            return(Ok("ERR:5"));
        }
示例#11
0
 partial void DeleteRegisterTemp(RegisterTemp instance);
示例#12
0
 partial void UpdateRegisterTemp(RegisterTemp instance);
示例#13
0
 partial void InsertRegisterTemp(RegisterTemp instance);
        public IHttpActionResult GetDigest(RemoteInvoice data)
        {
            ILog log = LogManager.GetLogger(typeof(RemoteLauncherController));
            XmlSchemaValidator validator = new XmlSchemaValidator();

            if (!validator.ValidXmlDoc(data.InvData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\VATInVoice_ws.xsd"))
            {
                log.Error("ERR:3-" + validator.ValidationError);
                return(Ok("ERR:3-" + validator.ValidationError));  //du lieu dau vao khong hop le
            }

            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return(Ok("ERR:4"));
            }
            string nameInvoice = "";
            IRegisterTempService   regisSrv = IoC.Resolve <IRegisterTempService>();
            IPublishInvoiceService pSrv     = IoC.Resolve <IPublishInvoiceService>();
            RegisterTemp           rtemp    = regisSrv.GetbyPattern(data.InvPattern, _currentCompany.id);

            nameInvoice = rtemp.NameInvoice;
            regisSrv.UnbindSession(rtemp);

            XElement               elem     = XElement.Parse(data.InvData);
            IList <IInvoice>       lstINV   = new List <IInvoice>();
            IEnumerable <XElement> listTemp = elem.Elements("Inv");
            IList <String>         lstKey   = new List <String>();

            if (listTemp.Count() > 10)
            {
                return(Ok("ERR:10"));    // lo hoa don truyen vao lon hon maxBlockInv;
            }
            try
            {
                foreach (XElement e in listTemp)
                {
                    XElement ele  = e.Element("Invoice");
                    string   fKey = e.Element("key").Value.Trim();
                    lstKey.Add(fKey);
                    IInvoice inv  = InvServiceFactory.NewInstance(data.InvPattern, comID);
                    string   read = string.Concat(ele);
                    inv.DeserializeFromXML(read);
                    inv.No       = 0;
                    inv.Name     = nameInvoice;
                    inv.Pattern  = data.InvPattern;
                    inv.Serial   = data.InvSerial;
                    inv.CreateBy = System.Web.HttpContext.Current.User.Identity.Name;
                    inv.Fkey     = fKey;
                    lstINV.Add(inv);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Ok("ERR:5"));
            }
            byte[]                       raw      = Convert.FromBase64String(data.CertBase64String);
            X509Certificate2             x509Cert = new X509Certificate2(raw);
            IDictionary <string, string> dict     = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(data.InvPattern, data.InvSerial, lstINV.ToArray(), x509Cert);

            return(Ok(dict));
        }
示例#15
0
        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))));
        }
示例#16
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));
            }
        }