public static void XmlToDbSaveD(XDocument x) { var infoClientsCustomerId = ModePro ? Pro.CustomerId : new Guid("87da7ba2-5e52-4d31-8def-5a2dad508e94"); var di = new DevisIdType(-1, DateTime.Now, false, infoClientsCustomerId, 0); 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(); di.DivisWebs = new List <DevisWebType>(); foreach (var product in p) { x.GetXElement("check").Add(product); var prixHt = Math.Round(product.GetXElementValue("price").ToDecimal(), 2); var tva = RepositoryTva.GetById(product.GetXElementValue("tva").ToInt()); var tva1 = PrixTtcOnlyTva(product.GetXElementValue("price").ToDecimal(), tva); var monPrixHt = product.GetXElementValue("contenance").ToDecimal(); var qty = product.GetXElementValue("qty").ToDecimal(); var prixHtValue = prixHt - tva1; var dw = new DevisWebType(Guid.NewGuid(), -1, prixHtValue, monPrixHt == 0 ? 1 : monPrixHt, qty, qty * prixHtValue, 0, true, product.GetXElementValue("CustomerId").ToGuid(), di.InfoClientsCustomerId ?? Guid.Empty); var cusumerIdRealStock = Guid.Parse(product.GetXElementValue("cusumerIdRealStock").Replace('.', ',')); RepositoryStockReal.AddProductCount(-dw.Qty, cusumerIdRealStock); RepositoryStockReal.UpdateProductCountByEstablishment(dw.Qty, Config.IdEstablishmentGros, dw.ProductsCustomerId); di.DivisWebs.Add(dw); } di.Total = di.DivisWebs.Sum(l => l.TotalHt); SyncService.InsDevis(di); FileMove(); }
private static void SaveFile() { var root = new XElement("DevisIds"); foreach (var devisId in DevisIds) { root.Add(DevisIdType.ToXElement(devisId)); } File.WriteAllText(Path, new XDocument(root).ToString()); }
private static void LoadFile() { if (File.Exists(Path)) { var document = XDocument.Load(Path); DevisIds.Clear(); foreach (var element in document.GetXElements("DevisIds", "rec")) { DevisIds.Add(DevisIdType.FromXElement(element)); } } }
public static int Add(DevisIdType di) { DevisIds.Add(di); var document = XDocument.Load(Path); document.GetXElement("DevisIds").Add(DevisIdType.ToXElement(di)); File.WriteAllText(Path, document.ToString()); if (SyncData.IsConnect) { using (var connection = ConnectionFactory.CreateConnection()) return(connection.Execute(InsertQuery, di)); } return(0); }
public static int InsDevis(DevisIdType di) { if (RepositoryDevisId.Add(di) == 1) { var id = RepositoryDevisId.GetMaxId(); ClassProMode.Ndevis = id; var count = RepositoryDevisWeb.AddRange(di.DivisWebs); if (count != di.DivisWebs.Count) { LogService.Log(TraceLevel.Error, 903); } return(di.DivisWebs.Count + 1); } return(0); }