From 819fb335b88ae3bb61b225040ef5d9a6d4835e0a Mon Sep 17 00:00:00 2001 From: Lev Rusanov <30170278+JDM170@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:01:41 +0700 Subject: [PATCH] Implemented compare Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com> --- Form1.Designer.cs | 138 ++++++++++++++++++++++++++++++++++++---------- Form1.cs | 56 +++++++++++++++++-- 2 files changed, 160 insertions(+), 34 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 19954cf..8b65dd9 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -28,13 +28,13 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend5 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series13 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint9 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 0D); - System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint10 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 0D); - System.Windows.Forms.DataVisualization.Charting.Series series14 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series15 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint3 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 0D); + System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint4 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 0D); + System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -59,6 +59,12 @@ this.del_by_name = new System.Windows.Forms.Button(); this.clean_graph = new System.Windows.Forms.Button(); this.compare = new System.Windows.Forms.Button(); + this.com_greater = new System.Windows.Forms.Button(); + this.com_less = new System.Windows.Forms.Button(); + this.com_gore = new System.Windows.Forms.Button(); + this.com_lore = new System.Windows.Forms.Button(); + this.com_equal = new System.Windows.Forms.Button(); + this.com_non_equal = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).BeginInit(); @@ -207,29 +213,29 @@ // // chart1 // - chartArea5.Name = "ChartArea1"; - this.chart1.ChartAreas.Add(chartArea5); - legend5.Name = "Legend1"; - this.chart1.Legends.Add(legend5); + chartArea2.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.chart1.Legends.Add(legend2); this.chart1.Location = new System.Drawing.Point(380, 12); this.chart1.Name = "chart1"; - series13.ChartArea = "ChartArea1"; - series13.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series13.Legend = "Legend1"; - series13.Name = "A1"; - series13.Points.Add(dataPoint9); - series13.Points.Add(dataPoint10); - series14.ChartArea = "ChartArea1"; - series14.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series14.Legend = "Legend1"; - series14.Name = "B2"; - series15.ChartArea = "ChartArea1"; - series15.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series15.Legend = "Legend1"; - series15.Name = "C3"; - this.chart1.Series.Add(series13); - this.chart1.Series.Add(series14); - this.chart1.Series.Add(series15); + series4.ChartArea = "ChartArea1"; + series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series4.Legend = "Legend1"; + series4.Name = "A1"; + series4.Points.Add(dataPoint3); + series4.Points.Add(dataPoint4); + series5.ChartArea = "ChartArea1"; + series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series5.Legend = "Legend1"; + series5.Name = "B2"; + series6.ChartArea = "ChartArea1"; + series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series6.Legend = "Legend1"; + series6.Name = "C3"; + this.chart1.Series.Add(series4); + this.chart1.Series.Add(series5); + this.chart1.Series.Add(series6); this.chart1.Size = new System.Drawing.Size(512, 440); this.chart1.TabIndex = 7; this.chart1.Text = "chart1"; @@ -293,19 +299,85 @@ // // compare // - this.compare.Location = new System.Drawing.Point(712, 458); + this.compare.Location = new System.Drawing.Point(701, 458); this.compare.Name = "compare"; - this.compare.Size = new System.Drawing.Size(155, 87); + this.compare.Size = new System.Drawing.Size(132, 31); this.compare.TabIndex = 14; this.compare.Text = "Сравнить"; this.compare.UseVisualStyleBackColor = true; this.compare.Click += new System.EventHandler(this.compare_Click); // + // com_greater + // + this.com_greater.Enabled = false; + this.com_greater.Location = new System.Drawing.Point(702, 496); + this.com_greater.Name = "com_greater"; + this.com_greater.Size = new System.Drawing.Size(40, 23); + this.com_greater.TabIndex = 15; + this.com_greater.Text = ">"; + this.com_greater.UseVisualStyleBackColor = true; + // + // com_less + // + this.com_less.Enabled = false; + this.com_less.Location = new System.Drawing.Point(702, 522); + this.com_less.Name = "com_less"; + this.com_less.Size = new System.Drawing.Size(40, 23); + this.com_less.TabIndex = 16; + this.com_less.Text = "<"; + this.com_less.UseVisualStyleBackColor = true; + // + // com_gore + // + this.com_gore.Enabled = false; + this.com_gore.Location = new System.Drawing.Point(747, 496); + this.com_gore.Name = "com_gore"; + this.com_gore.Size = new System.Drawing.Size(40, 23); + this.com_gore.TabIndex = 17; + this.com_gore.Text = ">="; + this.com_gore.UseVisualStyleBackColor = true; + // + // com_lore + // + this.com_lore.Enabled = false; + this.com_lore.Location = new System.Drawing.Point(747, 522); + this.com_lore.Name = "com_lore"; + this.com_lore.Size = new System.Drawing.Size(40, 23); + this.com_lore.TabIndex = 18; + this.com_lore.Text = "<="; + this.com_lore.UseVisualStyleBackColor = true; + // + // com_equal + // + this.com_equal.Enabled = false; + this.com_equal.Location = new System.Drawing.Point(793, 496); + this.com_equal.Name = "com_equal"; + this.com_equal.Size = new System.Drawing.Size(40, 23); + this.com_equal.TabIndex = 19; + this.com_equal.Text = "="; + this.com_equal.UseVisualStyleBackColor = true; + // + // com_non_equal + // + this.com_non_equal.Enabled = false; + this.com_non_equal.Location = new System.Drawing.Point(793, 522); + this.com_non_equal.Name = "com_non_equal"; + this.com_non_equal.Size = new System.Drawing.Size(40, 23); + this.com_non_equal.TabIndex = 20; + this.com_non_equal.Text = "/="; + this.com_non_equal.UseVisualStyleBackColor = true; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(904, 576); + this.Controls.Add(this.com_non_equal); + this.Controls.Add(this.com_equal); + this.Controls.Add(this.com_lore); + this.Controls.Add(this.com_gore); + this.Controls.Add(this.com_less); + this.Controls.Add(this.com_greater); this.Controls.Add(this.compare); this.Controls.Add(this.clean_graph); this.Controls.Add(this.del_by_name); @@ -360,6 +432,12 @@ private System.Windows.Forms.DataGridViewTextBoxColumn Column8; private System.Windows.Forms.DataGridViewTextBoxColumn Column9; private System.Windows.Forms.Button compare; + private System.Windows.Forms.Button com_greater; + private System.Windows.Forms.Button com_less; + private System.Windows.Forms.Button com_gore; + private System.Windows.Forms.Button com_lore; + private System.Windows.Forms.Button com_equal; + private System.Windows.Forms.Button com_non_equal; } } diff --git a/Form1.cs b/Form1.cs index 8ee01e9..e1136bd 100644 --- a/Form1.cs +++ b/Form1.cs @@ -16,9 +16,11 @@ namespace WindowsFormsApp1 InitializeComponent(); } + // Конвертирование объекта в double private double ConvertDGValue(object value) { return Convert.ToDouble(value); } + // Преобразование dataGridView в матрицу private double[,] ConvertDGtoMatrix(DataGridView dgv) { int rowCount = dgv.Rows.Count, @@ -30,6 +32,7 @@ namespace WindowsFormsApp1 return matrix; } + // Сортировка матрицы по возрастанию альфа-среза private double[,] SortMatrix(double[,] matrix) { int rowCount = matrix.GetLength(1), @@ -47,6 +50,7 @@ namespace WindowsFormsApp1 return matrix; } + // Вычисление неизвестного альфа-среза private Tuple GetUnknownAlpha(double[,] matrix1, double[,] matrix2) { double[,] matrix_low, matrix_high; @@ -83,7 +87,6 @@ namespace WindowsFormsApp1 } wrong = 0; } - matrix3 = SortMatrix(matrix3); int minCoord = 0, maxCoord = 0; double k, b; @@ -104,10 +107,10 @@ namespace WindowsFormsApp1 matrix3[2, i] = -(b - matrix3[0, i]) / k; } } - return Tuple.Create(matrix3, matrix_high); } + // Вывод графика private void PrintGraph(double[,] matrix, string chart_series) { DataPointCollection points = chart1.Series.FindByName(chart_series).Points; @@ -127,8 +130,8 @@ namespace WindowsFormsApp1 dataGridView2.Rows.Add(new object[] { 0, 1, 9 }); dataGridView2.Rows.Add(new object[] { 0.5, 3, 6 }); - dataGridView2.Rows.Add(new object[] { 0.2, 2, 7 }); dataGridView2.Rows.Add(new object[] { 1, 4, 5 }); + dataGridView2.Rows.Add(new object[] { 0.2, 2, 7 }); /*double[,] matrix = ConvertDGtoMatrix(dataGridView2); for (int row = 0; row < matrix.GetLength(1); row++) @@ -259,7 +262,52 @@ namespace WindowsFormsApp1 private void compare_Click(object sender, EventArgs e) { - // compare + double[,] matrixA = SortMatrix(ConvertDGtoMatrix(dataGridView1)), + matrixB = SortMatrix(ConvertDGtoMatrix(dataGridView2)); + int matrixARowCount = matrixA.GetLength(1), + matrixBRowCount = matrixB.GetLength(1); + double matrixASum = 0, matrixBSum = 0; + for (int i = 0; i < matrixARowCount; i++) + matrixASum += matrixA[1, i] + matrixA[2, i]; + matrixASum = matrixASum / matrixARowCount; + for (int i = 0; i < matrixBRowCount; i++) + matrixBSum += matrixB[1, i] + matrixB[2, i]; + matrixBSum = matrixBSum / matrixBRowCount; + if (matrixASum > matrixBSum) + { + com_greater.BackColor = Color.Green; + com_less.BackColor = Color.Red; + } + else + { + com_greater.BackColor = Color.Red; + com_less.BackColor = Color.Green; + } + if (matrixASum >= matrixBSum) + { + com_gore.BackColor = Color.Green; + com_lore.BackColor = Color.Red; + } + else + { + com_gore.BackColor = Color.Red; + com_lore.BackColor = Color.Green; + } + if (matrixASum == matrixBSum) + { + com_equal.BackColor = Color.Green; + com_non_equal.BackColor = Color.Red; + } + else + { + com_equal.BackColor = Color.Red; + com_non_equal.BackColor = Color.Green; + } + chart1.Series.FindByName("A1").Points.Clear(); + chart1.Series.FindByName("B2").Points.Clear(); + chart1.Series.FindByName("C3").Points.Clear(); + PrintGraph(matrixA, "A1"); + PrintGraph(matrixB, "B2"); } } }