private void OkClick(object sender, RoutedEventArgs e) { string sia = (string)xNation.SelectedItem; string namea = sia.Substring(0, sia.IndexOf("..") - 1); StatNationPopup fa = A.Find(l => l.NameNation == namea); if (fa != null) { fa.Qty += 1; RepositoryStatNationPopup.Update(fa); } string sib = (string)xPlaceArround.SelectedItem; string nameb = sib.Substring(0, sib.IndexOf("..") - 1); StatPlaceArrond fb = B.Find(l => l.NamePlaceArrond == nameb); if (fb != null) { fb.Qty += 1; RepositoryStatPlaceArrond.Update(fb); } StatNation sn = new StatNation(Guid.NewGuid(), DateTime.Now, Global.Config.CustomerId, fa != null ? fa.CustomerId : Guid.Empty, fb != null ? fb.CustomerId : Guid.Empty); RepositoryStatNation.Add(sn); Close(); }
private static void SaveFile() { var root = new XElement("StatNationPopups"); foreach (var statNationPopup in StatNationPopups) { root.Add(StatNationPopup.ToXElement(statNationPopup)); } File.WriteAllText(Path, new XDocument(root).ToString()); }
private static void LoadFile() { if (File.Exists(Path)) { var document = XDocument.Load(Path); StatNationPopups.Clear(); foreach (var element in document.GetXElements("StatNationPopups", "rec")) { StatNationPopups.Add(StatNationPopup.FromXElement(element)); } } }
public static void Add(StatNationPopup statNationPopup) { StatNationPopups.Add(statNationPopup); var document = XDocument.Load(Path); var statNationPopupsElement = document.GetXElement("StatNationPopups"); statNationPopupsElement.Add(StatNationPopup.ToXElement(statNationPopup)); const string query = "INSERT INTO StatNationPopup VALUES (@CustomerId, @NameNation, @Qty)"; using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(query, statNationPopup); }
public static void Delete(StatNationPopup statNationPopup) { var current = StatNationPopups.First(s => s.CustomerId == statNationPopup.CustomerId); StatNationPopups.Remove(current); var document = XDocument.Load(Path); var statNationPopupElement = document.GetXElements("StatNationPopups", "rec").First(p => p.GetXElementValue("CustomerId").ToGuid() == statNationPopup.CustomerId); statNationPopupElement.Remove(); document.Save(Path); const string query = "DELETE FROM StatNationPopup WHERE IdCustomer = @CustomerId"; using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(query, new { statNationPopup.CustomerId }); }
private void ButtonClick(object sender, RoutedEventArgs e) { var name = xNameNation.Text; var qtyText = xQTY.Text; if (name.Length == 0) { FunctionsService.ShowMessageTime("Пустое знаение "); } else { if (Snp.Find(l => l.NameNation == name) != null) { FunctionsService.ShowMessageTime("Такое имя сущ-ет "); } else { int qty = 0; if (int.TryParse(qtyText, out qty)) { var sn = new StatNationPopup(Guid.NewGuid(), name, qty); RepositoryStatNationPopup.Add(sn); Snp.Add(sn); CollectionViewSource.GetDefaultView((Owner as WGrid).dataGrid.ItemsSource).Refresh(); foreach (Window window in Application.Current.Windows) { if (window.GetType() == typeof(WStat)) { WStat w = (window as WStat); w.Reload(); } } Close(); } else { FunctionsService.ShowMessageTime("Неверое значние поля QTY "); } } } }
public static void Update(StatNationPopup statNationPopup) { var document = XDocument.Load(Path); var element = document.GetXElements("StatNationPopups", "rec").First(el => el.GetXElementValue("CustomerId").ToGuid() == statNationPopup.CustomerId); StatNationPopup.SetXmlValues(element, statNationPopup); document.Save(Path); if (SyncData.IsConnect) { const string query = @"UPDATE StatNationPopup SET NameNation = @NameNation, QTY = @Qty WHERE IdCustomer = @CustomerId"; using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(query, new { statNationPopup.NameNation, statNationPopup.Qty, statNationPopup.CustomerId }); } var idx = StatNationPopups.FindIndex(ds => ds.CustomerId == statNationPopup.CustomerId); StatNationPopups[idx] = statNationPopup; }