コード例 #1
0
        public static bool Save(string filename, ObservableModelData obj)
        {
            bool       b          = true;
            FileStream fileStream = null;

            try
            {
                fileStream = File.Create(filename);
                BinaryFormatter binaryFormatter = new BinaryFormatter();

                binaryFormatter.Serialize(fileStream, obj);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
                b = false;
            }
            finally
            { if (fileStream != null)
              {
                  fileStream.Close();
              }
            }

            return(b);
        }
コード例 #2
0
        public static bool Load(string filename, ref ObservableModelData obj)
        {
            bool       b          = true;
            FileStream fileStream = null;

            try
            {
                fileStream = File.OpenRead(filename);
                BinaryFormatter binaryFormatter = new BinaryFormatter();

                obj = binaryFormatter.Deserialize(fileStream) as ObservableModelData;
            }
            catch (FileNotFoundException ex)
            {
                //obj.Log = new List<string>();
                b = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
                b = false;
            }
            finally
            { if (fileStream != null)
              {
                  fileStream.Close();
              }
            }

            return(b);
        }
コード例 #3
0
        private void Save(ObservableModelData t)
        {
            SaveFileDialog save_dialog = new SaveFileDialog();

            if (save_dialog.ShowDialog() == true)
            {
                t.Change = false;
                ObservableModelData.Save(save_dialog.FileName, t);
            }
        }
コード例 #4
0
        private void OpenCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            if (ModelDataOb.Change)
            {
                MessageBoxResult result = MessageBox.Show("Сохранить изменения?", "Сообщение", MessageBoxButton.YesNo, MessageBoxImage.Information);

                if (result == MessageBoxResult.Yes)
                {
                    Save(ModelDataOb);
                }
            }

            OpenFileDialog open_dialog = new OpenFileDialog();

            if (open_dialog.ShowDialog() == true)
            {
                ObservableModelData.Load(open_dialog.FileName, ref ModelDataOb);

                ModelDataOb.CollectionChanged += CollectionChangedEventHandler;

                ListBox1.ItemsSource = ModelDataOb;
            }
        }
コード例 #5
0
 public ModelDataView(ObservableModelData model_collection)
 {
 }