public InvoiceLine InsertLine(InvoiceLine nouveau, Invoice invoice)
 {
     try
     {
         if (nouveau.IDInvoice == 0)
         {
             throw new Exception();
         }
         nouveau.IDInvoice = invoice.IDInvoice;
         nouveau.IDAccount = invoice.IDAccount;
         //nouveau.LineTax = invoice.DefaultTaxeValue;
         // Insert
         nouveau["IDLine"] = DBNull.Value;
         this.InsertBubble(nouveau, false, true);
         return(nouveau);
     }
     catch (Exception ex)
     {
         throw new Exception("createLine " + ex.Message, ex);
     }
 }
        /// <summary>
        /// Update selon le nom sur différent objets
        /// </summary>
        public FORM.InvoiceDataUpdtAjaxPoco UpdateField(Invoice invoicepo, string Name, string Value, bool saveInBase = true)
        {
            FORM.InvoiceDataUpdtAjaxPoco retour = new InvoiceDataUpdtAjaxPoco();
            if (invoicepo.IDInvoice < 0)
            {
                saveInBase = false;                          // impossible de copier en base
            }
            List <string> nameAlloweds = new List <string>(new string[] { "Invoice", "RefInvoice", "DateInvoice", "BuyerAddress",
                                                                          "Adress1", "Adress2", "Adress3", "Postcode", "City", "Country", "postCode", "ContactMail", "ContactPhone", "Identity", "Compagny",
                                                                          "RefBuyer", "RefSeller", "SellerAddress", "Lines", "LineQuantity", "LineAmount", "LineLabel" });

            if (Name.Split('_').Count() < 2)
            {
                throw new Exception("Paramètres non autorisés");
            }
            string NameObject = Name.Split('_')[Name.Split('_').Count() - 2].Split('|')[0];
            string IdObject   = Name.Split('_')[Name.Split('_').Count() - 2].Split('|').Count() > 1 ? Name.Split('_')[Name.Split('_').Count() - 2].Split('|')[1] : "";
            string NameField  = Name.Split('_')[Name.Split('_').Count() - 1];


            if (!nameAlloweds.Contains(NameObject) || !nameAlloweds.Contains(NameField))
            {
                throw new Exception("Paramètres non autorisés");
            }
            switch (NameObject)
            {
            // Modification de la facture
            case "Invoice":
                invoicepo[NameField] = Value;
                if (saveInBase)
                {
                    this.UpdateBubble(invoicepo, NameField, Value);
                }
                break;

            // modification des ligne de la facture
            case "Lines":
                InvoiceLine line = invoicepo.Lines.FirstOrDefault(l => l.IDLine == int.Parse(IdObject));
                line[NameField] = Value;
                if (saveInBase)
                {
                    this.UpdateBubble(line, NameField, Value);
                }
                break;

            // Contact Acheteur
            case "BuyerAddress":
                if (invoicepo.BuyerAddress == null)
                {
                    invoicepo.BuyerAddress = new Address();
                }
                invoicepo.BuyerAddress[NameField] = Value;
                if (saveInBase)
                {
                    SOLUTIONS.INVOICES.CONTACT.AddressProvider addressProvide = new AddressProvider(this.Connector);
                    addressProvide.SaveAddress(invoicepo.BuyerAddress);
                    if (invoicepo.BuyerIDAddress != invoicepo.BuyerAddress.IDAddress)
                    {
                        this.UpdateBubble(invoicepo, "BuyerIDAddress", invoicepo.BuyerAddress.IDAddress);
                    }
                }
                break;

            // Contact Vendeur
            case "SellerAddress":
                if (invoicepo.SellerAddress == null)
                {
                    invoicepo.SellerAddress = new Address();
                }
                invoicepo.SellerAddress[NameField] = Value;
                if (saveInBase)
                {
                    SOLUTIONS.INVOICES.CONTACT.AddressProvider addressProvide = new AddressProvider(this.Connector);
                    addressProvide.SaveAddress(invoicepo.SellerAddress);
                    if (invoicepo.SellerIDAddress != invoicepo.SellerAddress.IDAddress)
                    {
                        this.UpdateBubble(invoicepo, "SellerIDAddress", invoicepo.SellerAddress.IDAddress);
                    }
                }
                break;

            //NA
            default:
                break;
            }

            // retour des données sur la factur (calcul montant)
            // !!! normalement ne devrai pas etre ici faire une méthode spécial dans le controlleur, qui retourne un JSON qui permet de mettre a jour la facture
            if (NameObject == "Lines")
            {
                InvoiceLine line  = invoicepo.Lines.FirstOrDefault(l => l.IDLine == int.Parse(IdObject));
                double      somme = invoicepo.Lines.Sum(ln => ln.LineQuantity * ln.LineAmount);
                invoicepo.FinalAmount = somme;
                if (saveInBase)
                {
                    this.UpdateBubble(invoicepo, "FinalAmount", somme);
                }
                retour.LastUpdtline = new InvoiceDataUpdtAjaxPoco.LineUpdtAjaxPoco();
                retour.LastUpdtline.FromPo(line);
                //return "€ " + (line.LineQuantity * line.LineAmount).ToString() + "|€ " + somme;
            }
            retour.FromPo(invoicepo);
            return(retour);
        }