using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Sorted
{
public partial class Form1 : Form
{
Book[] books = new Book[10];
Random random = new Random();
public Form1()
{
InitializeComponent();
}
void PrintBookTitles(Book[] books)
{
rRead.Clear();
foreach (Book book in books)
{
rRead.Text += book + "\r\n";
}
}
void PrintBookTitlesSort(Book[] books)
{
rSort.Clear();
foreach (Book book in books)
{
rSort.Text += book + "\r\n";
}
}
private void b_Sort_Click_1(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
Array.Sort(books, delegate(Book a, Book b)
{
return a.Year.CompareTo(b.Year);
});
}
else if (radioButton2.Checked)
{
BubbleSort.Sort(books, delegate(Book a, Book b)
{
return a.Year.CompareTo(b.Year);
});
}
else if (radioButton3.Checked)
{
VstavSort.Sort(books, delegate(Book a, Book b)
{
return a.Year.CompareTo(b.Year);
});
}
PrintBookTitlesSort(books);
}
private void b_Random_Click_1(object sender, EventArgs e)
{
for (int i = 0; i < books.Length; i++)
{
books[i] = new Book(Teenager.Complain(), random.Next(2007));
}
PrintBookTitles(books);
}
private void gExit_Click_1(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click_1(object sender, EventArgs e)
{
rRead.Clear();
rSort.Clear();
}
private void b_Save_Click_1(object sender, EventArgs e)
{
if (rSort.Text.Length==0) MessageBox.Show(" Не сохранино");
else
{
SaveFileDialog svd = new SaveFileDialog();
svd.Filter = "Any files *.*|*.*|Zodiakfiles *.zod|*.zod";
if (svd.ShowDialog() == DialogResult.OK)
{
StreamWriter streamwriter =
new StreamWriter(svd.FileName, false, Encoding.Default);
streamwriter.Write(this.rRead.Text);
streamwriter.Close();
}
}
}
}
}