private void obrB_Click(object sender, EventArgs e) { if (ServiceFunctions.CheckMatrix(B)) { MometalShowMessage("Вычисление определителя матрицы B"); BlockButtonsOperations(); double detB = Operations.DeterminantReverseMatrix(B, ref ourHistory); message_history.Text = ourHistory.Print(n_sms); if (!Double.IsNaN(detB) && !Double.IsInfinity(detB)) { MometalShowMessage("Выполнение операции (B)^-1. Пожалуйста подождите..."); C = Operations.Reverse(B, C, ref ourHistory, detB); } else { MometalShowMessage("Обратная матрица не может быть вычислена!"); } ShowOnlyChangesInC(); BlockButtonsOperations(); } else { MometalShowMessage("Матрица B не задана"); } }
private void AmultB_Click(object sender, EventArgs e) { if (ServiceFunctions.Check2Matrix(A, B)) { MometalShowMessage("Выполнение операции A*B. Пожалуйста подождите..."); BlockButtonsOperations(); C = Operations.Multiply(A, B, C, ref ourHistory); ShowOnlyChangesInC(); BlockButtonsOperations(); } else { if (A.Type == Category.none && B.Type == Category.none) { MometalShowMessage("Ни одна матрица не задана"); } else if (A.Type == Category.none) { MometalShowMessage("Матрица А не задана"); } else { MometalShowMessage("Матрица B не задана"); } } }
private void button_make_Click(object sender, EventArgs e) { int n; double V; Category type; bool success; // проверяем категорию type = ServiceFunctions.TransformCategory(comboBox_type.SelectedIndex); success = type != Category.none; if (!success) { MessageBox.Show("Ошибка!\nНе выбран тип матрицы!"); comboBox_type.Focus(); return; } // проверяем введенную размерность success = Int32.TryParse(textBox_n.Text, out n); if (!success) { MessageBox.Show("Ошибка!\nНе верно введена размерность!"); textBox_n.Text = ""; textBox_n.Focus(); return; } if (n <= 1) { MessageBox.Show("Ошибка!\nРазмерность должна быть больше 1!"); textBox_n.Text = ""; textBox_n.Focus(); return; } // проверяем введенное значение V success = Double.TryParse(textBox_V.Text, out V); if (!success) { success = Double.TryParse(textBox_V.Text.Replace('.', ','), out V); if (!success) { MessageBox.Show("Ошибка!\nНе верно введено значение V!"); textBox_V.Text = ""; textBox_V.Focus(); return; } } // Отправляем данные DataTransfer.data[0] = n; DataTransfer.data[1] = V; DataTransfer.data[2] = type; // уничтожаем текущую форму this.Dispose(); }
private void ShowMatrix(Matrix A) { int n = prirost; int m = prirost; if (isLastYPage()) { n = A.N % prirost; } if (n == 0) { n = A.N; } if (isLastXPage()) { m = A.N % prirost; } if (m == 0) { m = A.N; } // очистка this.dataGridViewOutput.Rows.Clear(); // удаление всех строк int count = this.dataGridViewOutput.Columns.Count; for (int i = 0; i < count; i++) // цикл удаления всех столбцов { this.dataGridViewOutput.Columns.RemoveAt(0); } // создание новой DataGridViewTextBoxColumn[] column = new DataGridViewTextBoxColumn[m]; for (int i = 0; i < m; i++) { column[i] = new DataGridViewTextBoxColumn(); // выделяем память для объекта column[i].HeaderText = (i + 1 + left).ToString(); column[i].Name = (i + 1 + left).ToString(); } // задание новой this.dataGridViewOutput.Columns.AddRange(column); // добавление столбцов for (int i = 0; i < n; i++) { object[] row = new object[m]; for (int j = 0; j < m; j++) { row[j] = ServiceFunctions.DeletZerosInEndString(String.Format("{0:F" + Epsilon.value.ToString() + "}", Operations.getElement(up + i, left + j, A))); } dataGridViewOutput.Rows.Add(row);// добавление строк } foreach (DataGridViewColumn col in dataGridViewOutput.Columns) { col.SortMode = DataGridViewColumnSortMode.NotSortable; } }
private void safe_C_Click(object sender, EventArgs e) { if (ServiceFunctions.CheckMatrix(C)) { MometalShowMessage("Сохранение матрицы C"); Save_m(C, ref ourHistory); } else { MometalShowMessage("Для сохранения матрица должна быть задана"); } UpdateInfo(); }
private void B_on_C_Click(object sender, EventArgs e) { if (ServiceFunctions.Check1Matrix(B, C)) { MometalShowMessage("Выполнение операции " + B.Name + "<->" + C.Name); BlockButtonsOperations(); Operations.Replace_A_B(ref B, ref C, ref ourHistory); UpdateInfo(); BlockButtonsOperations(); } else { MometalShowMessage("Ни одна матрица не задана"); } }
private void A_on_B_Click(object sender, EventArgs e) { if (ServiceFunctions.Check1Matrix(A, B)) { MometalShowMessage("Выполнение операции " + A.Name + "<->" + B.Name); BlockButtonsOperations(); Operations.Replace_A_B(ref A, ref B, ref ourHistory); UpdateInfo(); BlockButtonsOperations(); } else { MometalShowMessage("Матрицы А и В не заданы"); } }
// Отображение матрицы С private void ShowMatrixC() { int n = Math.Min(20, C.N); int m = Math.Min(20, C.N); // очистка this.GridView_C.Rows.Clear(); // удаление всех строк int count = this.GridView_C.Columns.Count; for (int i = 0; i < count; i++) // цикл удаления всех столбцов { this.GridView_C.Columns.RemoveAt(0); } if (C.Type != Category.none) { // создание новой DataGridViewTextBoxColumn[] column = new DataGridViewTextBoxColumn[m]; for (int i = 0; i < m; i++) { column[i] = new DataGridViewTextBoxColumn(); // выделяем память для объекта column[i].HeaderText = (i + 1).ToString(); column[i].Name = (i + 1).ToString(); } // задание новой this.GridView_C.Columns.AddRange(column); // добавление столбцов for (int i = 0; i < n && i < C.N; i++) { object[] row = new object[m]; for (int j = 0; j < m; j++) { row[j] = ServiceFunctions.DeletZerosInEndString(String.Format("{0:F" + Epsilon.value.ToString() + "}", Operations.getElement(i, j, C))); } GridView_C.Rows.Add(row);// добавление строк } foreach (DataGridViewColumn col in GridView_C.Columns) { col.SortMode = DataGridViewColumnSortMode.NotSortable; } } }
// показать типы и размерности private void labelMatrixShow() { type_n_A.Text = ServiceFunctions.labelMatrix(A); type_n_B.Text = ServiceFunctions.labelMatrix(B); type_n_C.Text = ServiceFunctions.labelMatrix(C); }
// Обработка нажатия клавиши Готово private void button_ready_Click(object sender, EventArgs e) { int n; double V; Category type; double[] packed_form; double Diapazon_ot, Diapazon_do; bool success; // проверяем категорию type = ServiceFunctions.TransformCategory(comboBox_type.SelectedIndex); success = type != Category.none; if (!success) { MessageBox.Show("Ошибка!\nНе выбран тип матрицы!"); comboBox_type.Focus(); return; } // проверяем введенную размерность success = Int32.TryParse(textBox_n.Text, out n); if (!success) { MessageBox.Show("Ошибка!\nНе верно введена размерность!"); textBox_n.Text = ""; textBox_n.Focus(); return; } if (n <= 1) { MessageBox.Show("Ошибка!\nРазмерность должна быть больше 1!"); textBox_n.Text = ""; textBox_n.Focus(); return; } // проверяем введенное значение V success = Double.TryParse(textBox_V.Text, out V); if (!success) { success = Double.TryParse(textBox_V.Text.Replace('.', ','), out V); if (!success) { MessageBox.Show("Ошибка!\nНе верно введено значение V!"); textBox_V.Text = ""; textBox_V.Focus(); return; } } // проверяем диапазоны success = Double.TryParse(textBox_ot.Text, out Diapazon_ot); if (!success) { success = Double.TryParse(textBox_ot.Text.Replace('.', ','), out Diapazon_ot); if (!success) { MessageBox.Show("Ошибка!\nНе верно введено значение диапазона!"); textBox_ot.Text = ""; textBox_ot.Focus(); return; } } success = Double.TryParse(textBox_do.Text, out Diapazon_do); if (!success) { success = Double.TryParse(textBox_do.Text.Replace('.', ','), out Diapazon_do); if (!success) { MessageBox.Show("Ошибка!\nНе верно введено значение диапазона!"); textBox_do.Text = ""; textBox_do.Focus(); return; } } if (Diapazon_ot > Diapazon_do) { MessageBox.Show("Ошибка!\nЗначение нижней границы диапазона больше значения верхней границы!"); textBox_ot.Text = ""; textBox_do.Text = ""; textBox_ot.Focus(); return; } // заполнение случайными значениями packed_form = ServiceFunctions.rand_array(n * (n + 1) / 2, Diapazon_ot, Diapazon_do); // Отправка данных DataTransfer.data[0] = n; DataTransfer.data[1] = V; DataTransfer.data[2] = type; DataTransfer.data[3] = packed_form; // Возвращение на старую форму this.Dispose(); }
private void ShowMatrixAdress(Matrix A) { int n = prirost; int m = prirost; if (isLastYPage()) { n = A.N % prirost; } if (n == 0) { n = A.N; } if (isLastXPage()) { m = A.N % prirost; } if (m == 0) { m = A.N; } // очистка this.dataGridViewOutput.Rows.Clear(); // удаление всех строк int count = this.dataGridViewOutput.Columns.Count; for (int i = 0; i < count; i++) // цикл удаления всех столбцов { this.dataGridViewOutput.Columns.RemoveAt(0); } // создание новой DataGridViewTextBoxColumn[] column = new DataGridViewTextBoxColumn[m]; for (int i = 0; i < m; i++) { column[i] = new DataGridViewTextBoxColumn(); // выделяем память для объекта column[i].HeaderText = (i + 1 + left).ToString(); column[i].Name = (i + 1 + left).ToString(); } // задание новой this.dataGridViewOutput.Columns.AddRange(column); // добавление столбцов unsafe { uint Adress; for (int i = 0; i < n && i < A.N; i++) { object[] row = new object[m]; for (int j = 0; j < m; j++) { if (Operations.isV(i + up, j + left, A)) { fixed(double *p = &A.v) { Adress = (uint)p; row[j] = ServiceFunctions.DeletZerosInEndString( String.Format("{0:F" + Epsilon.value.ToString() + "}", A.V)) + " | " + "0x" + Adress.ToString("X2"); } } else { fixed(double *p = &A.Packed_form[Operations.getIndexK(i + up, j + left, A)]) { Adress = (uint)p; row[j] = ServiceFunctions.DeletZerosInEndString( String.Format("{0:F" + Epsilon.value.ToString() + "}", Operations.getElement(i + up, j + left, A))) + " | " + "0x" + Adress.ToString("X2"); } } } dataGridViewOutput.Rows.Add(row);// добавление строк } foreach (DataGridViewColumn col in dataGridViewOutput.Columns) { col.SortMode = DataGridViewColumnSortMode.NotSortable; } } }