Esempio n. 1
0
        //delete one or more instruments
        private void DeleteInstrumentBtn_ItemClick(object sender, RoutedEventArgs routedEventArgs)
        {
            using (var entityContext = new MyDBContext())
            {
                var selectedInstruments = InstrumentsGrid.SelectedItems;
                if (selectedInstruments.Count == 0) return;

                if (selectedInstruments.Count == 1)
                {
                    var inst = (Instrument)selectedInstruments[0];
                    MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete {0} @ {1}?", inst.Symbol, inst.Datasource.Name),
                        "Delete", MessageBoxButton.YesNo);
                    if (res == MessageBoxResult.No) return;
                }
                else
                {
                    MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete {0} instruments?", selectedInstruments.Count),
                        "Delete", MessageBoxButton.YesNo);
                    if (res == MessageBoxResult.No) return;
                }

                List<Instrument> toRemove = new List<Instrument>();

                foreach (Instrument i in InstrumentsGrid.SelectedItems)
                {
                    entityContext.Instruments.Attach(i);
                    entityContext.Instruments.Remove(i);
                    toRemove.Add(i);
                }

                using (var localStorage = new LocalStorage())
                {
                    localStorage.Connect();

                    while (toRemove.Count > 0)
                    {
                        Instruments.Remove(toRemove[toRemove.Count - 1]);
                        localStorage.DeleteAllInstrumentData(toRemove[toRemove.Count - 1]);
                        toRemove.RemoveAt(toRemove.Count - 1);
                    }
                }

                entityContext.SaveChanges();
            }
        }
Esempio n. 2
0
        //delete data from selected instruments
        private void ClearDataBtn_ItemClick(object sender, RoutedEventArgs routedEventArgs)
        {
            var selectedInstruments = InstrumentsGrid.SelectedItems;
            if (selectedInstruments.Count == 0) return;

            if (selectedInstruments.Count == 1)
            {
                var inst = (Instrument)selectedInstruments[0];
                MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete all data from {0} @ {1}?", inst.Symbol, inst.Datasource.Name),
                    "Delete", MessageBoxButton.YesNo);
                if (res == MessageBoxResult.No) return;
            }
            else
            {
                MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete all data from {0} instruments?", selectedInstruments.Count),
                    "Delete", MessageBoxButton.YesNo);
                if (res == MessageBoxResult.No) return;
            }

            using (var storage = new LocalStorage())
            {
                foreach (Instrument i in selectedInstruments)
                {
                    try
                    {
                        storage.DeleteAllInstrumentData(i);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            StatusBarLabel.Content = "Instrument data deleted";
        }