Ejemplo n.º 1
0
        public static bool Load(string filename, ref ObservableModelData obj)
        {
            bool       f  = true;
            FileStream fs = null;

            try
            {
                fs = File.OpenRead(filename);
                BinaryFormatter bf = new BinaryFormatter();
                obj = bf.Deserialize(fs) as ObservableModelData;
                obj.CollectionChanged += obj.CollectionChangedEventHandler;
            }
            catch (Exception ex)    //  мб другая обработка
            {
                MessageBox.Show(ex.Message);
                f = false;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return(f);
        }
Ejemplo n.º 2
0
        public static bool Save(string filename, ObservableModelData obj)
        {
            bool       f  = true;
            FileStream fs = null;

            try
            {
                obj.IsChanged = false;
                fs            = File.Open(filename, FileMode.OpenOrCreate);
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, obj);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                f = false;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return(f);
        }
Ejemplo n.º 3
0
        private void New_Command(object sender, ExecutedRoutedEventArgs e)
        {
            if (OMD.IsChanged)
            {
                if (MessageBox.Show("Do you want to save?", "title", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    if (sfd.ShowDialog() == true)
                    {
                        ObservableModelData.Save(sfd.FileName, OMD);
                    }
                    OMD.IsChanged = false;
                }
            }
            OMD.Clear();
            OMD.AddDefaults();
            MDView           = new ModelDataView(OMD);
            this.DataContext = OMD;
            DataTemplate tmpl = this.TryFindResource("VIEW") as DataTemplate;

            if (tmpl != null)
            {
                Element_p.ItemTemplate = tmpl;
            }
            Binding_Settings();
        }
Ejemplo n.º 4
0
        private void Open_Command(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            SaveFileDialog sfd = new SaveFileDialog();
            bool           flag;

            if (ofd.ShowDialog() == true)
            {
                if (OMD.IsChanged == true)
                {
                    if (MessageBox.Show("Do you want to save?", "Open", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        if (sfd.ShowDialog() == true)
                        {
                            if ((flag = ObservableModelData.Save(sfd.FileName, OMD)) == false)
                            {
                                MessageBox.Show("Error!");
                            }
                        }
                    }
                }
                ObservableModelData.Load(ofd.FileName, ref OMD);
                OMD.IsChanged    = false;
                this.DataContext = OMD;
            }
        }
Ejemplo n.º 5
0
 public ModelDataView(ObservableModelData M)
 {
     OMD       = M;
     ViewTypes = new List <string>(2);
     ViewTypes.Add("Line");
     ViewTypes.Add("Spline");
     Order = 1;
 }
Ejemplo n.º 6
0
        private void Save_Command(object sender, ExecutedRoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            if (sfd.ShowDialog() == true)
            {
                ObservableModelData.Save(sfd.FileName, OMD);
            }
            OMD.IsChanged = false;
        }
Ejemplo n.º 7
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (OMD.IsChanged)
     {
         if (MessageBox.Show("Do you want to save?", "Exit", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             SaveFileDialog sfd = new SaveFileDialog();
             if (sfd.ShowDialog() == true)
             {
                 ObservableModelData.Save(sfd.FileName, OMD);
             }
             OMD.IsChanged = false;
         }
     }
 }