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("StatPlaceArronds"); foreach (var actionCash in StatPlaceArronds) { root.Add(StatPlaceArrond.ToXElement(actionCash)); } File.WriteAllText(Path, new XDocument(root).ToString()); }
private static void LoadFile() { if (File.Exists(Path)) { var document = XDocument.Load(Path); StatPlaceArronds.Clear(); foreach (var element in document.GetXElements("StatPlaceArronds", "rec")) { StatPlaceArronds.Add(StatPlaceArrond.FromXElement(element)); } } }
public static void Add(StatPlaceArrond statPlaceArrond) { StatPlaceArronds.Add(statPlaceArrond); var document = XDocument.Load(Path); var statPlaceArrondsElement = document.GetXElement("StatPlaceArronds"); statPlaceArrondsElement.Add(StatPlaceArrond.ToXElement(statPlaceArrond)); const string query = "INSERT INTO StatPlaceArrond VALUES (@CustomerId, @NamePlaceArrond, @QTY)"; using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(query, statPlaceArrond); }
public static void Delete(StatPlaceArrond statPlaceArrond) { var current = StatPlaceArronds.First(s => s.CustomerId == statPlaceArrond.CustomerId); StatPlaceArronds.Remove(current); var document = XDocument.Load(Path); var statPlaceArrondElement = document.GetXElements("StatPlaceArronds", "rec").First(p => p.GetXElementValue("CustomerId").ToGuid() == statPlaceArrond.CustomerId); statPlaceArrondElement.Remove(); document.Save(Path); const string query = "DELETE FROM StatPlaceArrond WHERE IdCustomer = @CustomerId"; using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(query, new { statPlaceArrond.CustomerId }); }
private void ButtonClick(object sender, RoutedEventArgs e) { string name = xNamePlaceArrond.Text; string qtyText = xQTY.Text; if (name.Length == 0) { FunctionsService.ShowMessageTime("Пустое знаение "); } else { if (Snp.Find(l => l.NamePlaceArrond == name) != null) { FunctionsService.ShowMessageTime("Такое имя сущ-ет "); } else { int qty; if (int.TryParse(qtyText, out qty)) { var sn = new StatPlaceArrond(Guid.NewGuid(), name, qty); RepositoryStatPlaceArrond.Add(sn); Snp.Add(sn); CollectionViewSource.GetDefaultView((this.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(StatPlaceArrond statPlaceArrond) { var document = XDocument.Load(Path); var element = document.GetXElements("StatPlaceArronds", "rec").First(el => el.GetXElementValue("CustomerId").ToGuid() == statPlaceArrond.CustomerId); StatPlaceArrond.SetXmlValues(element, statPlaceArrond); document.Save(Path); if (SyncData.IsConnect) { const string query = "UPDATE StatPlaceArrond SET NamePlaceArrond = @NamePlaceArrond, QTY = @QTY WHERE IdCustomer = @CustomerId"; using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(query, statPlaceArrond); } var idx = StatPlaceArronds.FindIndex(ds => ds.CustomerId == statPlaceArrond.CustomerId); StatPlaceArronds[idx] = statPlaceArrond; }