123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Matrices
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- gr692_zrrEntities db = new gr692_zrrEntities();
- public MainWindow()
- {
- InitializeComponent();
- this.createGrid10x10();
- }
- int[,] a = new int[3, 4];
- int[,] b = new int[3, 4];
- public void Matrix(ref int[,] a, ref int[,] b)
- {
- try
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (nn == 2 && mm == 3)
- {
- a[0, 0] = Convert.ToInt32(i00.Text);
- a[0, 1] = Convert.ToInt32(i01.Text);
- a[0, 2] = Convert.ToInt32(i02.Text);
- a[1, 0] = Convert.ToInt32(i10.Text);
- a[1, 1] = Convert.ToInt32(i11.Text);
- a[1, 2] = Convert.ToInt32(i12.Text);
- b[0, 0] = Convert.ToInt32(b00.Text);
- b[0, 1] = Convert.ToInt32(b01.Text);
- b[0, 2] = Convert.ToInt32(b02.Text);
- b[1, 0] = Convert.ToInt32(b10.Text);
- b[1, 1] = Convert.ToInt32(b11.Text);
- b[1, 2] = Convert.ToInt32(b12.Text);
- }
- else if (nn == 1 && mm == 4)
- {
- a[0, 0] = Convert.ToInt32(i00.Text);
- a[0, 1] = Convert.ToInt32(i01.Text);
- a[0, 2] = Convert.ToInt32(i02.Text);
- a[0, 3] = Convert.ToInt32(i03.Text);
- b[0, 0] = Convert.ToInt32(b00.Text);
- b[0, 1] = Convert.ToInt32(b01.Text);
- b[0, 2] = Convert.ToInt32(b02.Text);
- b[0, 3] = Convert.ToInt32(b03.Text);
- }
- else
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- a[0, 0] = Convert.ToInt32(i00.Text);
- a[0, 1] = Convert.ToInt32(i01.Text);
- a[0, 2] = Convert.ToInt32(i02.Text);
- a[0, 3] = Convert.ToInt32(i03.Text);
- a[1, 0] = Convert.ToInt32(i10.Text);
- a[1, 1] = Convert.ToInt32(i11.Text);
- a[1, 2] = Convert.ToInt32(i12.Text);
- a[1, 3] = Convert.ToInt32(i13.Text);
- a[2, 0] = Convert.ToInt32(i20.Text);
- a[2, 1] = Convert.ToInt32(i21.Text);
- a[2, 2] = Convert.ToInt32(i22.Text);
- a[2, 3] = Convert.ToInt32(i23.Text);
- b[0, 0] = Convert.ToInt32(b00.Text);
- b[0, 1] = Convert.ToInt32(b01.Text);
- b[0, 2] = Convert.ToInt32(b02.Text);
- b[0, 3] = Convert.ToInt32(b03.Text);
- b[1, 0] = Convert.ToInt32(b10.Text);
- b[1, 1] = Convert.ToInt32(b11.Text);
- b[1, 2] = Convert.ToInt32(b12.Text);
- b[1, 3] = Convert.ToInt32(b13.Text);
- b[2, 0] = Convert.ToInt32(b20.Text);
- b[2, 1] = Convert.ToInt32(b21.Text);
- b[2, 2] = Convert.ToInt32(b22.Text);
- b[2, 3] = Convert.ToInt32(b23.Text);
- }
- }
- }
- catch
- {
- MessageBox.Show("Введите матрицы 2х3 или 3х4");
- }
- }
- private void Zapis()
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- int per;
- Matrix(ref a, ref b);
- for (int i = 0; i < nn; i++)
- {
- for (int j = 0; j < mm; j++)
- {
- per = a[i, j];
- IshodMassiv mat = new IshodMassiv()
- {
- Ishod = per
- };
- db.IshodMassiv.Add(mat);
- db.SaveChanges();
- }
- }
- }
- public void Itog(int[,] rezult)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (nn == 2 && mm == 3)
- {
- r00.Text = rezult[0, 0].ToString();
- r01.Text = rezult[0, 1].ToString();
- r02.Text = rezult[0, 2].ToString();
- r10.Text = rezult[1, 0].ToString();
- r11.Text = rezult[1, 1].ToString();
- r12.Text = rezult[1, 2].ToString();
- }
- else if (nn == 1 && mm == 4)
- {
- r00.Text = rezult[0, 0].ToString();
- r01.Text = rezult[0, 1].ToString();
- r02.Text = rezult[0, 2].ToString();
- r10.Text = rezult[1, 0].ToString();
- r11.Text = rezult[1, 1].ToString();
- r12.Text = rezult[1, 2].ToString();
- }
- else
- {
- r00.Text = rezult[0, 0].ToString();
- r01.Text = rezult[0, 1].ToString();
- r02.Text = rezult[0, 2].ToString();
- r03.Text = rezult[0, 3].ToString();
- r10.Text = rezult[1, 0].ToString();
- r11.Text = rezult[1, 1].ToString();
- r12.Text = rezult[1, 2].ToString();
- r13.Text = rezult[1, 3].ToString();
- r20.Text = rezult[2, 0].ToString();
- r21.Text = rezult[2, 1].ToString();
- r22.Text = rezult[2, 2].ToString();
- r23.Text = rezult[2, 3].ToString();
- }
- }
- public void Transpor(int[,] transpor)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (nn == 2 && mm == 3)
- {
- r00.Text = transpor[0, 0].ToString();
- r01.Text = transpor[0, 1].ToString();
- r10.Text = transpor[1, 0].ToString();
- r11.Text = transpor[1, 1].ToString();
- r20.Text = transpor[2, 0].ToString();
- r21.Text = transpor[2, 1].ToString();
- }
- else
- {
- r00.Text = transpor[0, 0].ToString();
- r01.Text = transpor[0, 1].ToString();
- r02.Text = transpor[0, 2].ToString();
- r10.Text = transpor[1, 0].ToString();
- r11.Text = transpor[1, 1].ToString();
- r12.Text = transpor[1, 2].ToString();
- r20.Text = transpor[2, 0].ToString();
- r21.Text = transpor[2, 1].ToString();
- r22.Text = transpor[2, 2].ToString();
- r30.Text = transpor[3, 0].ToString();
- r31.Text = transpor[3, 1].ToString();
- r32.Text = transpor[3, 2].ToString();
- }
- }
- private void Button_Click1(object sender, RoutedEventArgs e)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (string.IsNullOrEmpty(i00.Text)
- && string.IsNullOrEmpty(b00.Text))
- {
- Print();
- }
- else
- {
- int per;
- Matrix(ref a, ref b);
- int[,] sum = new int[nn, mm];
- for (int i = 0; i < nn; i++)
- {
- for (int j = 0; j < mm; j++)
- {
- sum[i, j] = a[i, j] + b[i, j];
- per = sum[i, j];
- Mat mat = new Mat()
- {
- matrix = per
- };
- db.Mat.Add(mat);
- db.SaveChanges();
- }
- }
- Zapis();
- Itog(sum);
- Vipolneno();
- }
- }
- private void Button_Click2(object sender, RoutedEventArgs e)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (string.IsNullOrEmpty(i00.Text)
- && string.IsNullOrEmpty(b00.Text))
- {
- Print();
- }
- else
- {
- int per;
- Matrix(ref a, ref b);
- int[,] sum = new int[nn, mm];
- for (int i = 0; i < nn; i++)
- {
- for (int j = 0; j < mm; j++)
- {
- sum[i, j] = a[i, j] - b[i, j];
- per = sum[i, j];
- //Mat mat = new Mat()
- //{
- // matrix = per
- //};
- //db.Mat.Add(mat);
- //db.SaveChanges();
- }
- }
- //Zapis();
- Itog(sum);
- Vipolneno();
- }
- }
- private void Button_Click3(object sender, RoutedEventArgs e)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (string.IsNullOrEmpty(i00.Text)
- && string.IsNullOrEmpty(Scalar.Text))
- {
- Print();
- }
- else
- {
- try
- {
- int Chislo = Convert.ToInt32(Scalar.Text);
- int per;
- Matrix(ref a, ref b);
- int[,] sum = new int[nn, mm];
- for (int i = 0; i < nn; i++)
- {
- for (int j = 0; j < mm; j++)
- {
- sum[i, j] = a[i, j] * Chislo;
- per = sum[i, j];
- //Mat mat = new Mat()
- //{
- // matrix = per
- //};
- //db.Mat.Add(mat);
- //db.SaveChanges();
- }
- }
- //Zapis();
- Itog(sum);
- Vipolneno();
- }
- catch
- {
- MessageBox.Show("Введите скалярное значение!!!");
- }
- }
- }
- private void Button_Click4(object sender, RoutedEventArgs e)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (string.IsNullOrEmpty(i00.Text)
- && string.IsNullOrEmpty(b00.Text))
- {
- Print();
- }
- else
- {
- int per;
- Matrix(ref a, ref b);
- int[,] sum = new int[nn+1, mm];
- for (int i = 0; i < mm; i++)
- {
- for (int j = 0; j < nn; j++)
- {
- sum[i, j] = a[j, i];
- per = sum[i, j];
- //Mat mat = new Mat()
- //{
- // matrix = per
- //};
- //db.Mat.Add(mat);
- //db.SaveChanges();
- }
- }
- //Zapis();
- Transpor(sum);
- Vipolneno();
- }
- }
- private void Button_Click5(object sender, RoutedEventArgs e)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (string.IsNullOrEmpty(i00.Text)
- && string.IsNullOrEmpty(b00.Text))
- {
- Print();
- }
- else
- {
- int per;
- Matrix(ref a, ref b);
- int[,] sum = new int[nn+1, mm+1];
- for (int i = 0; i < mm; i++)
- {
- for (int j = 0; j < nn; j++)
- {
- sum[i, j] = a[j, i] * a[j, i];
- per = sum[i, j];
- //Mat mat = new Mat()
- //{
- // matrix = per
- //};
- //db.Mat.Add(mat);
- //db.SaveChanges();
- }
- }
- //Zapis();
- Transpor(sum);
- Vipolneno();
- }
- }
- private void Button_Click6(object sender, RoutedEventArgs e)
- {
- int nn = Convert.ToInt32(n.Text);
- int mm = Convert.ToInt32(m.Text);
- if (string.IsNullOrEmpty(i00.Text)
- && string.IsNullOrEmpty(b00.Text))
- {
- Print();
- }
- else
- {
- int per, buf;
- Matrix(ref a, ref b);
- int[,] sum = new int[nn, mm];
- // перестановка строк
- for (int s = 0; s < nn; s++)
- for (int k = 0; k < mm; k++)
- {
- buf = a[s, k];
- a[s, k] = a[s + 1, k];
- a[s + 1, k] = buf;
- //per = sum[nn, mm];
- }
- //Mat mat = new Mat()
- //{
- // matrix = per
- //};
- //db.Mat.Add(mat);
- //db.SaveChanges();
- // перестановка столбцов
- //for (int s = 0; s < mm+1; s++)
- // for (int k = 0; k < nn+1; k++)
- // {
- // buf = a[s, k];
- // a[s, k] = a[s, k + 1];
- // a[s, k + 1] = buf;
- // }
- //Zapis();
- Itog(a);
- Vipolneno();
- }
- }
- private void _placeSingleColorColumn(Grid grid, Color color, int height, int colNum, int maxHeight)
- {
- Brush brush = new SolidColorBrush(color);
- Rectangle rect = new Rectangle();
- rect.Fill = brush;
- Grid.SetColumn(rect, colNum);
- Grid.SetRow(rect, maxHeight - height);
- Grid.SetRowSpan(rect, height);
- grid.Children.Add(rect);
- }
- //private void _createLabels(Grid grid, string[] labels)
- //{
- // RowDefinition rowDefnLabels = new RowDefinition();
- // grid.RowDefinitions.Add(rowDefnLabels);
- // for (int i = 0; i < labels.Length; i++)
- // {
- // TextBlock block = new TextBlock();
- // block.Text = labels[i];
- // block.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
- // Grid.SetColumn(block, i);
- // Grid.SetRow(block, grid.RowDefinitions.Count);
- // grid.Children.Add(block);
- // }
- //}
- public void createGrid10x10()
- {
-
- //string[] aLabels = "Dogs,Cats,Birds,Snakes,Rabbits,Hamsters,Horses,Rats,Bats,Unicorns".Split(',');
- //_createLabels(this.myGrid, aLabels);
- }
- private void Button_Click7(object sender, RoutedEventArgs e)
- {
- //int nn = Convert.ToInt32(str.Text);
- //int mm = Convert.ToInt32(stl.Text);
- Matrix(ref a, ref b);
- Random random = new Random();
- for (int i = 0; i < 10; i++)
- {
- ColumnDefinition colDef = new ColumnDefinition();
- myGrid.ColumnDefinitions.Add(colDef);
- RowDefinition rowDef = new RowDefinition();
- myGrid.RowDefinitions.Add(rowDef);
- Color color = i % 2 == 0 ? Colors.Red : Colors.Blue;
- _placeSingleColorColumn(this.myGrid, color, random.Next(1, 11), i, 10);
- }
- //Zapis();
- Vipolneno();
- }
- private void Button_ClickClear(object sender, RoutedEventArgs e)
- {
- i00.Clear();
- i01.Clear();
- i02.Clear();
- i03.Clear();
- i10.Clear();
- i11.Clear();
- i12.Clear();
- i13.Clear();
- i20.Clear();
- i21.Clear();
- i22.Clear();
- i23.Clear();
- b00.Clear();
- b01.Clear();
- b02.Clear();
- b03.Clear();
- b10.Clear();
- b11.Clear();
- b12.Clear();
- b13.Clear();
- b20.Clear();
- b21.Clear();
- b22.Clear();
- b23.Clear();
- stl.Clear();
- str.Clear();
- n.Clear();
- m.Clear();
- }
- private void Print()
- {
- if (string.IsNullOrEmpty(i00.Text)
- || string.IsNullOrEmpty(b00.Text))
- {
- MessageBox.Show("Введите матрицы");
- }
- else
- {
- MessageBox.Show("Выполнено");
- }
- }
- private void Vipolneno()
- {
- MessageBox.Show("Выполнено");
- }
- //private void Razmer(int nn, int mm)
- //{
- // try
- // {
- // nn = Convert.ToInt32(n.Text);
- // mm = Convert.ToInt32(m.Text);
- // }
- // catch
- // {
- // MessageBox.Show("Введите размеры матриц");
- // }
- //}
- public int[,] TestSumm(int [,] rezult)
- {
- var array = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
- var array2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- rezult[i, j] = array[i, j] + array2[i, j];
- }
- }
- return rezult;
- }
- public int[,] TestMinus(int[,] rezult)
- {
- var array = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
- var array2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- rezult[i, j] = array[i, j] - array2[i, j];
- }
- }
- return rezult;
- }
- public int[,] TestScalar(int[,] rezult)
- {
- var array = new int[2, 3] { { 1, 4, 3 }, { 15, 50, 60 } };
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- rezult[i, j] = array[i, j] * 5;
- }
- }
- return rezult;
- }
- public int[,] TestTranspor(int[,] rezult)
- {
- var array = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- rezult[i, j] = array[j, i];
- }
- }
- return rezult;
- }
- public int[,] TestTransporUMN(int[,] rezult)
- {
- var array = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- rezult[i, j] = array[j, i] * array[j, i];
- }
- }
- return rezult;
- }
- public int[,] TestPerestanovka(int[,] rezult)
- {
- var array = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
- int buf;
- for (int s = 0; s < 2; s++)
- for (int k = 0; k < 3; k++)
- {
- buf = array[s, k];
- array[s, k] = array[s + 1, k];
- array[s + 1, k] = buf;
- rezult[s, k] = buf;
- }
- return rezult;
- }
- //public bool TestIns(int ID, string Login, string Password)
- //{
- // if (ID == null || Login == "" || Password == "")
- // {
- // MessageBox.Show("Вы ввели не все данные");
- // return false;
- // }
- // else if (db.Reg.Select(item => item.ID).Contains(ID))
- // {
- // MessageBox.Show("Данный логин уже занят. Введите другой");
- // return false;
- // }
- // Reg newReg = new Reg()
- // {
- // ID = ID,
- // Login = Login,
- // Password = Password,
- // };
- // PersonBD BD = new PersonBD()
- // {
- // FirstName_person = FirstName,
- // LastName_person = LastName,
- // MiddleName_person = MiddleName
- // };
- // if (newReg == null)
- // {
- // MessageBox.Show("Аккаунт пользователя не создан");
- // return false;
- // }
- // db.Reg.Add(newReg);
- // db.PersonBD.Add(BD);
- // try
- // {
- // db.SaveChanges();
- // }
- // catch (Exception e)
- // {
- // MessageBox.Show(e.Message);
- // return false;
- // }
- // MessageBox.Show("Вы успешно зарегистрировались");
- // return true;
- //}
- }
- }
|