SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
ConfigureGraphs.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 
10 namespace SeciUserInterface.Dialogs.Graphs
11 {
12  public partial class ConfigureGraphs : Form
13  {
15  private int _maxGraphs;
16 
17  public ConfigureGraphs(int maxGraphs)
18  {
19  InitializeComponent();
20  _maxGraphs = maxGraphs;
21  }
22 
23  private void ConfigureGraphs_Load(object sender, EventArgs e)
24  {
25  if (Graphs == null)
26  {
27  Graphs = new List<Seci.Definitions.GraphDefinition>();
28  }
29  else
30  {
31  updateGraphList();
32  }
33  }
34 
35  private void btnAdd_Click(object sender, EventArgs e)
36  {
37  if (Graphs.Count < _maxGraphs)
38  {
39  ConfigureGraph add = new ConfigureGraph();
40  if (add.ShowDialog() == DialogResult.OK)
41  {
42  Graphs.Add(add.Graph);
43  updateGraphList();
44  }
45  }
46  else
47  {
48  MessageBox.Show("Maximum number of graphs allowed is " + _maxGraphs + ".");
49  }
50  }
51 
52  private void btnEdit_Click(object sender, EventArgs e)
53  {
54  if (lstGraphs.SelectedIndex != -1)
55  {
56  if (!String.IsNullOrEmpty(Graphs[lstGraphs.SelectedIndex].OwningComponent))
57  {
58  MessageBox.Show("This graph belongs to a Sub-Configuration and cannot be edited.", "Cannot Edit Graph", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
59  return;
60  }
61 
62  ConfigureGraph edit = new ConfigureGraph();
63  edit.Graph = Graphs[lstGraphs.SelectedIndex];
64  if (edit.ShowDialog() == DialogResult.OK)
65  {
66  Graphs[lstGraphs.SelectedIndex] = edit.Graph;
67  updateGraphList();
68  }
69  }
70  }
71 
72  private void btnDelete_Click(object sender, EventArgs e)
73  {
74  if (lstGraphs.SelectedIndex != -1)
75  {
76  if (!String.IsNullOrEmpty(Graphs[lstGraphs.SelectedIndex].OwningComponent))
77  {
78  MessageBox.Show("This graph belongs to a Sub-Configuration and cannot be deleted.", "Cannot Delete Graph", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
79  return;
80  }
81 
82  Graphs.RemoveAt(lstGraphs.SelectedIndex);
83  updateGraphList();
84  }
85  }
86 
87  private void updateGraphList()
88  {
89  lstGraphs.Items.Clear();
90 
91  foreach (Seci.Definitions.GraphDefinition graph in Graphs)
92  {
93  lstGraphs.Items.Add(graph.Title);
94  }
95  lstPlots.Items.Clear();
96 
97  }
98 
99  private void btnOK_Click(object sender, EventArgs e)
100  {
101  DialogResult = DialogResult.OK;
102  Close();
103  }
104 
105  private void lstGraphs_SelectedIndexChanged(object sender, EventArgs e)
106  {
107  lstPlots.Items.Clear();
108 
109  if (lstGraphs.SelectedIndex != -1)
110  {
111  for (int i = 0; i < Graphs[lstGraphs.SelectedIndex].Plots.Count; ++i)
112  {
113  lstPlots.Items.Add(Graphs[lstGraphs.SelectedIndex].Plots[i].BlockName);
114  }
115  }
116  }
117  }
118 }
This class is used for serializing the graphs for saving in the configuration.
void btnEdit_Click(object sender, EventArgs e)
List< Seci.Definitions.GraphDefinition > Graphs
void btnDelete_Click(object sender, EventArgs e)
void btnAdd_Click(object sender, EventArgs e)
void lstGraphs_SelectedIndexChanged(object sender, EventArgs e)
void ConfigureGraphs_Load(object sender, EventArgs e)
void btnOK_Click(object sender, EventArgs e)