I want to restore previous series after changing some Yvalues[0] multiple times in the chart. So I have implemented undo operation using memento pattern.
But it's not working and there is no error while running. Below is the originator, memento and caretaker.
public class Originator
{
private Series _series = new Series();
public Originator(Series series)
{
_series = series;
}
public Series OSeries
{
get
{
return _series;
}
set
{
_series = value;
}
}
public Memento SaveSeries()
{
return new Memento(_series);
}
public void RestoreSeries(Memento m)
{
this._series = m.MMseries;
}
}
public class Memento
{
private Series _series =new Series();
public Memento(Originator org)
{
this._series = org.OSeries;
}
public Memento(Series mseries)
{
_series = mseries;
}
public Series MMseries
{
get
{
return _series;
}
set
{
_series = value;
}
}
}
public class Caretaker
{
// private static Caretaker _instance;
// public Caretaker() { }
private Memento chartMemento;
public Memento Memento
{
get
{ return chartMemento; }
set
{ chartMemento = value; }
}
}
Created objects in public partial class Form1 : Form
Originator _org;
Caretaker taker = new Caretaker();
While loading the chart from a file, open_file function contains this code:
_org = new Originator(global_series); //For undo/redo operation
while (chart1.Series.Count > 0) { chart1.Series.RemoveAt(0); }
chart1.Series.Add(global_series);
taker.Memento = _org.SaveSeries();
For Undo_button:
_org.RestoreSeries(taker.Memento);
while (chart1.Series.Count > 0) { chart1.Series.RemoveAt(0); }
global_series = _org.OSeries;
chart1.Series.Add(global_series);
Aucun commentaire:
Enregistrer un commentaire