public static int AddToDb(Tes tes) { if (SyncData.IsConnect) { using (var connection = ConnectionFactory.CreateConnection()) { connection.Open(); var trans = connection.BeginTransaction(); var result = connection.Execute(QueryTes, tes, trans); if (result < 0) { trans.Rollback(); return(result); } result = connection.Execute(QueryTesReglement, tes.TesReglaments, trans); if (result < 0) { trans.Rollback(); return(result); } result = connection.Execute(QueryTesProduct, tes.TesProducts, trans); if (result < 0) { trans.Rollback(); } trans.Commit(); return(result); } } return(0); }
private void button1_Click(object sender, EventArgs e) { Tes = new Tes(); Tes.Show(); this.Hide(); }
public static void XmlToDbSave(XDocument x) { var tes = new Tes { CustomerId = Guid.NewGuid(), ACodeFournisseur = 0, AFrtva = Pro.Frtva ?? string.Empty, AMail = Pro.Mail, AName = Pro.Name ?? string.Empty, ASex = Pro.SexToInt(Pro.Sex), ASurname = Pro.Surname ?? string.Empty, ANameCompany = Pro.NameCompany, AOfficeAddress = Pro.OfficeAddress ?? string.Empty, AOfficeCity = Pro.OfficeCity ?? string.Empty, AOfficeZipCode = Pro.OfficeZipCode ?? string.Empty, ASiret = Pro.Siret ?? string.Empty, ATelephone = Pro.Telephone }; tes.CustomerId = Guid.NewGuid(); tes.DateTime = DateTime.Now; tes.Description = string.Empty; tes.Id = RepositoryTes.MaxId(0) + 1; tes.Livraison = false; tes.Montant = x.GetXAttributeValue("check", "sum").ToDecimal(); tes.Nclient = Pro.Nclient.ToString(); tes.Payement = false; tes.Type = 0; tes.VAdresse = RepositoryEstablishment.Establishment.Adress; tes.VCodeNaf = "0"; tes.VCp = RepositoryEstablishment.Establishment.Cp; tes.VFax = RepositoryEstablishment.Establishment.Phone; tes.VFrtva = ""; tes.VMail = RepositoryEstablishment.Establishment.Mail; tes.VNameCompany = RepositoryEstablishment.Establishment.Name; tes.VPhone = RepositoryEstablishment.Establishment.Phone; tes.VSiret = ""; tes.VVille = RepositoryEstablishment.Establishment.Ville; var products = x.GetXElements("check", "product"); var p = new List <XElement>(); foreach (var product in products) { var pf = p.Find(l => l.GetXElementValue("CustomerId") == product.GetXElementValue("CustomerId")); if (pf == null || (pf.GetXElementValue("price") != product.GetXElementValue("price"))) { p.Add(product); } else { var qty = pf.GetXElementValue("qty").ToDecimal(); var qty1 = product.GetXElementValue("qty").ToDecimal(); var total = pf.GetXElementValue("total").ToDecimal(); var total1 = product.GetXElementValue("total").ToDecimal(); pf.GetXElement("qty").SetValue(qty + qty1); pf.GetXElement("total").SetValue(total + total1); } } x.GetXElements("check", "product").Remove(); foreach (var product in p) { x.GetXElement("check").Add(product); var prod = new TesProduct { Balance = product.GetXElementValue("balance").ToBool(), CodeBar = ReplaceCodeBare(product.GetXElementValue("CodeBare")), ConditionAchat = 1, CustomerId = -1, CustomerIdProduct = product.GetXElementValue("CustomerId").ToGuid(), Date = DateTime.Now, Description = Config.Name, Group = RepositoryGroupProduct.GetGroupNameById(product.GetXElementValue("grp").ToInt()), NameProduct = product.GetXElementValue("Name"), PrixHt = Math.Round(product.GetXElementValue("price").ToDecimal(), 2), ProductsWeb = product.GetXElementValue("ProductsWeb_CustomerId").ToGuid(), Qty = product.GetXElementValue("qty").Replace('.', ',').ToDecimal(), SubGroup = RepositoryGroupProduct.GetGroupNameById(product.GetXElementValue("grp").ToInt()), TesCustomerId = tes.CustomerId, Tva = RepositoryTva.GetById(product.GetXElementValue("tva").ToInt()) }; var tva = PrixTtcOnlyTva(product.GetXElementValue("price").ToDecimal(), prod.Tva); prod.PrixHt = prod.PrixHt - tva; prod.TotalHt = prod.Qty * prod.PrixHt; prod.TypeId = 1; tes.TesProducts.Add(prod); var qty = prod.Qty; var cusumerIdRealStock = product.GetXElementValue("cusumerIdRealStock").ToGuid(); RepositoryStockReal.AddProductCount(-qty, cusumerIdRealStock); } foreach (var type in RepositoryTypePay.TypePays) { var reglement = new TesReglament(); var r = RepositoryTypePay.TypePays.FirstOrDefault(l => l.NameCourt == type.NameCourt); var elm = x.GetXAttribute("check", type.NameCourt); if (elm != null && r != null) { reglement.Caisse = Config.NameTicket; reglement.CustomerId = Guid.NewGuid(); reglement.DateTime = DateTime.Now; if (r.Name == "En espèces") { var rendux = x.GetXAttribute("check", "Rendu"); if (rendux != null) { var rendu = rendux.Value.ToDecimal(); reglement.Montant = elm.Value.ToDecimal() + rendu; } else { reglement.Montant = elm.Value.ToDecimal(); } } else { reglement.Montant = elm.Value.ToDecimal(); } reglement.TesCustomerId = tes.CustomerId; reglement.TypePay = r.Name; tes.TesReglaments.Add(reglement); } tes.Payement = (tes.TesReglaments.Sum(l => l.Montant) >= tes.Montant); } if (tes.TesReglaments.Count > 0) { var newTes = new Tes { CustomerId = Guid.NewGuid(), ACodeFournisseur = (short)(Pro.Nclient), AFrtva = Pro.Frtva ?? string.Empty, AMail = Pro.Mail, AName = Pro.Name ?? string.Empty, ASex = Pro.SexToInt(Pro.Sex), ASurname = Pro.Surname ?? string.Empty, ANameCompany = Pro.NameCompany, AOfficeAddress = Pro.OfficeAddress ?? string.Empty, AOfficeCity = Pro.OfficeCity ?? string.Empty, AOfficeZipCode = Pro.OfficeZipCode ?? string.Empty, ASiret = Pro.Siret ?? string.Empty, ATelephone = Pro.Telephone, DateTime = DateTime.Now, Description = "{" + tes.CustomerId + "}{" + tes.Id + "}{" + tes.Type + "}", Id = RepositoryTes.MaxId(1) + 1, Livraison = tes.Livraison, Montant = decimal.Parse(x.Element("check").Attribute("sum").Value.Replace('.', ',')), Nclient = Pro.Nclient.ToString(), Payement = tes.Payement, Type = 1, VAdresse = tes.VAdresse, VCodeNaf = tes.VCodeNaf, VCp = tes.VCp, VFax = tes.VFax, VFrtva = tes.VFrtva, VMail = tes.VMail, VNameCompany = tes.VNameCompany, VPhone = tes.VPhone, VSiret = tes.VSiret, VVille = tes.VVille }; tes.Description = "{" + newTes.CustomerId + "}{" + newTes.Id + "}{" + newTes.Type + "}"; foreach (var t in tes.TesReglaments) { if (t.Montant > 0) { t.TesCustomerId = newTes.CustomerId; newTes.TesReglaments.Add(t); } } tes.TesReglaments.Clear(); RepositoryTes.AddToDb(newTes); } RepositoryTes.AddToDb(tes); Nfact = tes.Id ?? -1; FileMove(); }