コード例 #1
0
        public static bool IsValidated(out string errorMessage)
        {
            Company currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;

            errorMessage = null;
            try
            {
                ICertificateService _certSrv  = IoC.Resolve <ICertificateService>();
                KeyStores           _keyStore = KeyStoresManagement.GetKeyStore(currentCompany.id);
                if (_keyStore == null)
                {
                    errorMessage = "Chưa đăng ký chữ ký số, liên hệ nhà cung cấp để được hỗ trợ.";
                    return(false);
                }
                if (_keyStore.KeyStoresOf == 1)
                {
                    return(true);
                }
                System.Security.Cryptography.X509Certificates.X509Certificate2 cert = _keyStore.OpenSession();
                if (DateTime.Parse(cert.GetExpirationDateString()) <= DateTime.Today.AddDays(7))
                {
                    errorMessage = "Chữ ký số sắp hết hạn, liên hệ nhà cung cấp để được hỗ trợ.";
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(true);
            }
        }
コード例 #2
0
 public ActionResult LaunchChoiceByPlugin(string cbid, string Pattern, string Serial, string certificate)
 {
     try
     {
         string[] idsStr = cbid.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
         int[]    ids    = (from s in idsStr select Convert.ToInt32(s)).ToArray();
         if (ids.Length < 0)
         {
             return(Json("ERROR:1"));
         }
         Company          currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         byte[]           raw            = Convert.FromBase64String(certificate);
         X509Certificate2 x509Cert       = new X509Certificate2(raw);
         KeyStores        _keyStore      = KeyStoresManagement.GetKeyStore(currentCompany.id);
         if (_keyStore == null)
         {
             log.Error("keyStores invalid");
             return(Json("ERROR:2"));
         }
         string serial4Keystore = _keyStore.SerialCert.TrimEnd().ToUpper();
         string serial4X509Cert = x509Cert.GetSerialNumberString().TrimEnd().ToUpper();
         if (serial4Keystore.CompareTo(serial4X509Cert) != 0)
         {
             log.Error("1|" + _keyStore.SerialCert.ToUpper());
             log.Error("2|" + x509Cert.GetSerialNumberString().ToUpper());
             return(Json("ERROR:2"));
         }
         if (DateTime.Parse(x509Cert.GetExpirationDateString()) < DateTime.Today)
         {
             return(Json("ERROR:3"));
         }
         IInvoiceService              IInvSrv       = InvServiceFactory.GetService(Pattern, currentCompany.id);
         IInvoice[]                   invoicesByIds = IInvSrv.GetByID(currentCompany.id, ids).OrderBy(p => p.id).ToArray();
         IList <InvoiceForPlugin>     data          = new List <InvoiceForPlugin>();
         IDictionary <string, string> dictHash      = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(Pattern, Serial, invoicesByIds, x509Cert);
         foreach (KeyValuePair <string, string> pair in dictHash)
         {
             data.Add(new InvoiceForPlugin()
             {
                 Key = pair.Key, Hash = pair.Value
             });
         }
         IInvSrv.UnbindSession();
         return(Json(new { hashdata = data }));
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return(Json("ERROR:4"));
     }
 }
コード例 #3
0
        public ActionResult LaunchReplaceByPlugin(string invData, string NewPattern, string NewSerial, int OriNo, string OriPattern, string OriSerial, string CertBase64String)
        {
            try
            {
                Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                int     comID           = _currentCompany.id;
                if (_currentCompany == null)
                {
                    return(Json(new { error = "ERR:2" }));
                }
                byte[]           raw       = Convert.FromBase64String(CertBase64String);
                X509Certificate2 x509Cert  = new X509Certificate2(raw);
                KeyStores        _keyStore = KeyStoresManagement.GetKeyStore(_currentCompany.id);
                if (_keyStore.SerialCert.ToUpper().CompareTo(x509Cert.GetSerialNumberString().ToUpper()) != 0)
                {
                    return(Json("ERROR:2"));
                }
                if (DateTime.Parse(x509Cert.GetExpirationDateString()) < DateTime.Today)
                {
                    return(Json("ERROR:3"));
                }

                IInvoiceService      invSrv   = InvServiceFactory.GetService(OriPattern, comID);
                IInvoice             OriInv   = invSrv.GetByNo(comID, OriPattern, OriSerial, OriNo);
                IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>();
                ICustomerService     _cusSvr  = IoC.Resolve <ICustomerService>();

                IInvoice inv = InvServiceFactory.NewInstance(NewPattern, comID);
                inv.DeserializeFromJSON(invData);
                inv.Pattern = NewPattern;
                inv.Serial  = NewSerial;
                inv.Status  = InvoiceStatus.NewInv;
                DateTime dt = OriInv.ArisingDate;

                string strReplace = (_currentCompany.Config.ContainsKey("ReplaceString")) ? _currentCompany.Config["ReplaceString"] : "Hóa đơn này thay thế hóa đơn số: @InvNo, Ký hiệu: @InvSerial, Gửi ngày @InvDay Tháng @InvMonth Năm @InvYear";
                strReplace         = strReplace.Replace("@InvNo", OriInv.No.ToString(Utils.MAX_NO_LENGTH)).Replace("@InvSerial", OriInv.Serial).Replace("@InvPattern", OriInv.Pattern).Replace("@InvDay", OriInv.ArisingDate.Day.ToString()).Replace("@InvMonth", OriInv.ArisingDate.Month.ToString()).Replace("@InvYear", OriInv.ArisingDate.Year.ToString());
                inv.ProcessInvNote = strReplace;
                inv.Type           = InvoiceType.ForReplace;
                var Typecus = (from c in _cusSvr.Query where c.ComID == comID && c.Code == inv.CusCode && c.CusType == 1 select c.CusType).SingleOrDefault();
                if (Typecus == 0)
                {
                    inv.CusSignStatus = cusSignStatus.NocusSignStatus;
                }
                else
                {
                    inv.CusSignStatus = cusSignStatus.NoSignStatus;
                }
                if (OriInv.Status == InvoiceStatus.SignedInv || OriInv.Status == InvoiceStatus.AdjustedInv)
                {
                    IDictionary <string, string> dict = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(OriPattern, OriSerial, new IInvoice[] { inv }, x509Cert);
                    if (dict.Count == 0)
                    {
                        return(Json("ERROR:4"));
                    }
                    var dictFirst = dict.FirstOrDefault();
                    invSrv.UnbindSession();
                    return(Json(new { hashdata = dictFirst }));
                }

                return(Json("ERROR:4"));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Json("ERROR:4"));
            }
        }