-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalMatrixForm.cs
More file actions
200 lines (174 loc) · 6.06 KB
/
Copy pathFinalMatrixForm.cs
File metadata and controls
200 lines (174 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Antropod.DataGridViewVirtual;
using Antropod;
using System.IO;
using System.Globalization;
namespace Antropod.MatrixMethod
{
public partial class FinalMatrixForm : Form
{
private HistogramForm histogramForm;
private ApplicationData appData;
//private Final subject;
private double[,] matrix;
private const string FILE_NAME = "program.dat";
private const string DIALOG_FILTER = "Файлы MX|*.mx";
private EditCombinedForm editCombinedForm;
private TwoDimensionalArrayView dataView;
public FinalMatrixForm()
{
InitializeComponent();
dataView = new TwoDimensionalArrayView(dataGridView2, null);
editCombinedForm = new EditCombinedForm();
histogramForm = new HistogramForm();
appData = ApplicationData.LoadFromFile(FILE_NAME);
appData.PropertyChanged += appData_PropertyChanged;
appData.NotifyChanged("");
}
void appData_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
listBox1.Items.Clear();
foreach (var part in appData.final.parts)
listBox1.Items.Add(part.name);
dataView.Data = null;
matrix = null;
propertyGrid1.SelectedObject = appData.stat;
}
public void MakeMatrix()
{
dataView.Data = null;
var indices = appData.final.maket.ComponentIndices().ToArray();
matrix = appData.final.UpdateMatrix(indices);
dataView.Data = matrix;
var names = appData.final.maket.ComponentNames().ToArray();
for (int i = 0; i < names.Length; ++i)
dataGridView2.Columns[i].HeaderText = names[i];
}
private void button2_Click(object sender, EventArgs e)
{
try
{
MakeMatrix();
}
catch (InterfaceException exc)
{
Utility.ExceptionMessageBox(exc);
}
}
private void Save()
{
Utility.Serialize(appData, FILE_NAME);
}
private void FinalMatrixForm_FormClosed(object sender, FormClosedEventArgs e)
{
Save();
}
private void changeComponent_Click(object sender, EventArgs e)
{
try
{
int index = listBox1.SelectedIndex;
if (index == -1) throw new InterfaceException("Выберите компонент");
var part = appData.final.parts[index];
editCombinedForm.ClearControls();
editCombinedForm.Subject = part;
var result = editCombinedForm.ShowDialog();
//if (result == DialogResult.OK)
}
catch (InterfaceException exc)
{
Utility.ExceptionMessageBox(exc);
}
}
private void saveData(object sender, EventArgs e)
{
try
{
var dialog = new SaveFileDialog();
dialog.Filter = DIALOG_FILTER;
dialog.FilterIndex = 1;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() != DialogResult.OK) return;
Utility.Serialize(appData, dialog.FileName);
}
catch(Exception exc)
{
Utility.ExceptionMessageBox(exc);
}
}
private void loadData(object sender, EventArgs e)
{
try
{
using(var dialog = new OpenFileDialog())
{
dialog.Filter = DIALOG_FILTER;
dialog.FilterIndex = 1;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() != DialogResult.OK) return;
appData = ApplicationData.LoadFromFile(dialog.FileName);
appData.PropertyChanged += appData_PropertyChanged;
appData.NotifyChanged("");
}
}
catch (Exception exc)
{
Utility.ExceptionMessageBox(exc);
}
}
private void newData(object sender, EventArgs e)
{
var result = MessageBox.Show("Вы уверены?", "Новый расчет",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result != DialogResult.Yes) return;
var editMaketForm = new EditMaketForm();
var maket = Maket.CreateDefault();
maket = editMaketForm.EditSubject(maket);
appData.final = new Final(maket);
}
private void button6_Click(object sender, EventArgs e)
{
try
{
MakeMatrix();
if (matrix == null) return;
appData.stat.Recalculate(matrix);
propertyGrid1.Refresh();
dataView.Data = appData.stat.newMatrix;
//dataView.Data = newMatrix;
//dataGridView2.Columns[dataGridView2.ColumnCount - 2].HeaderText = "Функция";
}
catch(Exception exc)
{
Utility.ExceptionMessageBox(exc);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
histogramForm.SetData(appData.stat.calculatedData, (int)numericUpDown1.Value);
histogramForm.Show();
histogramForm.Focus();
}
catch (InterfaceException exc)
{
Utility.ExceptionMessageBox(exc);
}
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}