Exemplo n.º 1
0
 private void Save_Func()
 {
     Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
     if (obj.IfChanged)
     {
         var result = MessageBox.Show("Save changes?", "Message", MessageBoxButton.YesNo);
         if (result == MessageBoxResult.Yes)
         {
             if (sfd.ShowDialog() == true)
             {
                 ObservableModelData.Save(sfd.FileName, ref obj);
             }
         }
         else
         {
             MessageBox.Show("Data may be lost!", "Message");
         }
     }
 }
Exemplo n.º 2
0
        public ViewM(IUIServises uiServices)
        {
            this.uiServices = uiServices;

            drawCommand = new RelayCommand(_ => uiServices.CanDraw(), _ => ModelView.Draw(chart, uiServices.SelectedItems()));

            deleteCommand = new RelayCommand(_ => { foreach (ModelData model in uiServices.SelectedItems())
                                                    {
                                                        if (!ModelDataOb.Contains(model))
                                                        {
                                                            return(false);
                                                        }
                                                    }
                                                    return(true); },
                                             _ => { foreach (ModelData model in uiServices.SelectedItems())
                                                    {
                                                        ModelDataOb.Remove(model);
                                                    }
                                             }
                                             );

            saveCommand = new RelayCommand(_ => ModelDataOb.Change,
                                           _ => {
                string path = uiServices.SavePath();
                if (path != null)
                {
                    ModelDataOb.Change = false;
                    ObservableModelData.Save(new SerializeAdapter(File.Create(path)), ModelDataOb);
                }
            }
                                           );

            addCommand = new RelayCommand(_ => uiServices.CanAdd(),
                                          _ => ModelDataOb.Add(new ModelData(model.N, model.P))
                                          );

            newCommand = new RelayCommand(_ => true,
                                          _ => {
                if (ModelDataOb.Change && uiServices.WantToSave())
                {
                    saveCommand.Execute(null);
                }
                ModelDataOb.Clear();
                ModelDataOb.Change = false;
            }
                                          );

            openCommand = new RelayCommand(_ => true,
                                           _ => {
                if (ModelDataOb.Change && uiServices.WantToSave())
                {
                    saveCommand.Execute(null);
                }
                string path = uiServices.OpenPath();
                if (path != null)
                {
                    ObservableModelData sample = new ObservableModelData();
                    ObservableModelData.Load(new DeserializeAdapter(File.OpenRead(path)), ref sample);
                    ModelDataOb.copy(sample);
                }
            }
                                           );
        }