public DirectInvoice PrepareDirectInvoice()
        {
            string        directinvoiceid = DirectInvoiceTools.GenerateDirectInvoice();
            DirectInvoice retour          = new DirectInvoice();

            retour.DateCreate        = DateTime.Now;
            retour.IdDirectInvoice   = directinvoiceid;
            retour.Invoice           = new INVOICE.Invoice();
            retour.Invoice.IDInvoice = -1; // indique que la facture n'est pas enregistré en base
            return(retour);
        }
        /// <summary>
        /// Génération du PDF
        /// </summary>
        /// <param name="DirectInvoiceid"></param>
        /// <returns></returns>
        public byte[] GenerateInvoice(DirectInvoice directInvoice)
        {
            try
            {
                if (directInvoice == null || directInvoice.Invoice == null)
                {
                    throw new Exception("Les données de la facture ne sont plus disponible");
                }
                byte[] retour = this.invoiceManager.GenerateInvoice(directInvoice.Invoice, false);

                return(retour);
            }
            catch (Exception ex)
            {
                throw new Exception("GenerateInvoice " + ex.Message, ex);
            }
        }
        /// <summary>
        /// Obtenir du cache partagé
        /// </summary>
        /// <param name="DirectInvoiceid"></param>
        /// <returns></returns>
        public DirectInvoice GetDirectInvoice(string iddirectinvoice)
        {
            DirectInvoice retour = null;

            try
            {
                // Obtien d'abord l'objet sur MemCached si Existe
                if (env != null)
                {
                    StackExchange.Redis.ConfigurationOptions redisconfig = new StackExchange.Redis.ConfigurationOptions();
                    redisconfig.EndPoints.Add("22ec9a54-2921-43af-a4e9-9b1e7aff2b9b.pdb.ovh.net", 21784);
                    redisconfig.Password = "******";

                    StackExchange.Redis.ConnectionMultiplexer redis   = StackExchange.Redis.ConnectionMultiplexer.Connect(redisconfig);
                    StackExchange.Redis.IDatabase             redisDb = redis.GetDatabase();


                    StackExchange.Redis.RedisKey key = iddirectinvoice;

                    StackExchange.Redis.RedisValue val = redisDb.StringGet(key, StackExchange.Redis.CommandFlags.None);
                    if (!string.IsNullOrWhiteSpace(val))
                    {
                        retour = new DirectInvoice();
                        retour.FromStringData(val);
                    }
                }

                // sinon regarde en base
                if (retour == null)
                {
                    Dictionary <string, object> ins = new Dictionary <string, object>();
                    ins.Add("iddirectinvoice", iddirectinvoice);
                    retour = this.GetOneDefault <DirectInvoice>(ins);
                }
                return(retour);
            }
            catch (Exception ex)
            {
                throw new Exception("GetDirectInvoice " + ex.Message, ex);
            }
        }
示例#4
0
        public void AddOutTest()
        {
            DataInvoice.GLOBAL.DataInvoiceEnv env = new GLOBAL.DataInvoiceEnv();


            DataInvoice.SOLUTIONS.INVOICES.DIRECTINVOICE.DirectInvoiceProvider directinvoiceprovide = new DataInvoice.SOLUTIONS.INVOICES.DIRECTINVOICE.DirectInvoiceProvider(env);

            DirectInvoice directinvoice   = directinvoiceprovide.PrepareDirectInvoice();
            string        iddirectinvoice = directinvoice.IdDirectInvoice;

            directinvoice.Invoice.InvoiceTitle = "invoice test 6sd5f";
            directinvoice.Invoice.DateInvoice  = DateTime.Now.Date;
            Console.WriteLine("ID " + iddirectinvoice);
            directinvoiceprovide.SaveDirectInvoice(directinvoice);

            DirectInvoice directinvoice2 = directinvoiceprovide.GetDirectInvoice(iddirectinvoice);

            if (directinvoice2.Invoice == null)
            {
                throw new Exception("obj null ...");
            }
        }
        /// <summary>
        /// enregistre en base et dans le cache partagé
        /// </summary>
        public void SaveDirectInvoice(DirectInvoice directinvoice)
        {
            try
            {
                // Enregistrement des clef (données persistantes) en bases
                System.Data.DataRowState rowstate = directinvoice.GetRow().RowState;
                if (rowstate == System.Data.DataRowState.Detached || rowstate == System.Data.DataRowState.Added)
                {
                    this.InsertBubble(directinvoice, true, false);
                }
                else
                {
                    this.SaveBubble(directinvoice);
                }

                // Enregistrement des données non persistantes sur MemCached
                if (env != null)
                {
                    StackExchange.Redis.ConnectionMultiplexer redis   = StackExchange.Redis.ConnectionMultiplexer.Connect(GetRedisConfig());
                    StackExchange.Redis.IDatabase             redisDb = redis.GetDatabase();

                    StackExchange.Redis.RedisValue val = directinvoice.ToStringData();
                    StackExchange.Redis.RedisKey   key = directinvoice.IdDirectInvoice;
                    redisDb.StringSet(key, val, null, StackExchange.Redis.When.Always, StackExchange.Redis.CommandFlags.None);



                    // redng75Oj82p

                    // !!! stocker dans memecached
                }
            }
            catch (Exception ex)
            {
                throw new Exception("SaveDirectInvoice " + ex.Message, ex);
            }
        }