Файл MainWindow.xaml(клиентская часть приложения WPF) 


Мы поможем в написании ваших работ!



ЗНАЕТЕ ЛИ ВЫ?

Файл MainWindow.xaml(клиентская часть приложения WPF)



<Window x:Class="П3_ТП.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="П3. WPF/C#: Метод Монте-Карло ABCE Асинхронный" Height="600" Width="600" MinWidth="600" MinHeight="600" SnapsToDevicePixels="False" MaxWidth="600" MaxHeight="600" Loaded="Window_Loaded">

<Grid Height="509">

<GroupBox Header="Контрольные примеры" Height="54" Name="groupBox1" VerticalAlignment="Bottom" Margin="0,0,0,-10" FontStyle="Normal" FontWeight="Normal">

<WrapPanel Height="26" Name="wrapPanel2" Width="523">

<Button Height="23" Name="button1" Width="104" Click="button1_Click" Content="№1(C&gt;E)"></Button>

<Button Height="23" Name="button2" Width="104" Click="button2_Click" Content="№2(C=E)"></Button>

<Button Height="23" Name="button3" Width="104" Click="button3_Click" Content="№3(C&gt;E)"></Button>

<Button Height="23" Name="button4" Width="104" Click="button4_Click" Content="rand №4(C&lt;E)"></Button>

<Button Height="23" Name="button5" Width="104" Click="button5_Click" Content="rand №5(C&gt;E)"></Button>

</WrapPanel>

</GroupBox>

<GroupBox Header="Таблица результатов" Margin="0,229,0,43" Name="groupBox2">

<WrapPanel Height="186" Name="wrapPanel1" Width="521">

<TextBox Height="50.347" Name="textBox1" Width="104" IsReadOnly="True" MinLines="1" MaxLines="2" TextWrapping="WrapWithOverflow" CharacterCasing="Normal" AutoWordSelection="False" AcceptsTab="False" AcceptsReturn="False" TextDecorations="None" TextAlignment="Center">Количество точек</TextBox>

<TextBox Height="50.339" Name="textBox2" Width="104" IsReadOnly="True" TextAlignment="Center" TextWrapping="WrapWithOverflow">Количество попавших точек</TextBox>

<TextBox Height="50.339" Name="textBox3" Width="104" IsReadOnly="True" TextAlignment="Center" TextWrapping="WrapWithOverflow">Рассчитанная площадь</TextBox>

<TextBox Height="50.344" Name="textBox4" Width="104" IsReadOnly="True" TextAlignment="Center" TextWrapping="WrapWithOverflow">Погрешность, %</TextBox>

<TextBox Height="50.334" Name="textBox5" Width="104" IsReadOnly="True" TextAlignment="Center" TextWrapping="WrapWithOverflow">Время, ms</TextBox>

<TextBox Height="23" Name="textBox6" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox7" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox8" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox9" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox10" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox11" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox12" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox13" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox14" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox15" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox16" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox17" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox18" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox19" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox20" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox21" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox22" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox23" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox24" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox25" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox26" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox27" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox28" Width="104" IsReadOnly="True" />

<TextBox Height="23" Name="textBox29" Width="104" IsReadOnly="True" />

<TextBox Height="23" IsReadOnly="True" Name="textBox36" Width="104" />

<TextBox Height="23" IsReadOnly="True" Name="textBox37" Width="159" Text="Площадь прямоугольника:"></TextBox>

<TextBox Height="23" IsReadOnly="True" Name="textBox38" Width="104" />

<TextBox Height="23" IsReadOnly="True" Name="textBox39" Width="153" TextChanged="textBox39_TextChanged" Text="Математическая площадь"></TextBox>

<TextBox Height="23" IsReadOnly="True" Name="textBox40" Width="105" />

</WrapPanel>

</GroupBox>

<GroupBox Header="Рисунок" Height="211" Margin="0,0,280,0" Name="groupBox3" VerticalAlignment="Top">

<Image Height="169" Name="image1" Stretch="Fill" Width="257" HorizontalAlignment="Center" OpacityMask="Black" />

</GroupBox>

<GroupBox Header="Входные параметры" Height="230" Name="groupBox4" VerticalAlignment="Top" VerticalContentAlignment="Top" HorizontalAlignment="Right" Width="274" Margin="0,12,0,0"></GroupBox>

<Label Height="29" HorizontalAlignment="Right" Margin="0,199,232,0" Name="label4" VerticalAlignment="Top" Width="22">N:</Label>

<TextBox Height="25" HorizontalAlignment="Right" Margin="0,26,154,0" Name="textBox30" VerticalAlignment="Top" Width="93.5" TextChanged="textBox30_TextChanged">0</TextBox>

<TextBox Height="25" HorizontalAlignment="Right" Margin="0,22,9.5,0" Name="textBox31" VerticalAlignment="Top" Width="104.5">0</TextBox>

<TextBox Height="25" HorizontalAlignment="Right" Margin="0,56,154,0" Name="textBox32" VerticalAlignment="Top" Width="93.5" Text="0"></TextBox>

<TextBox Height="25" HorizontalAlignment="Right" Margin="0,54,9.5,0" Name="textBox33" VerticalAlignment="Top" Width="104.5">0</TextBox>

<TextBox Height="25" HorizontalAlignment="Left" Margin="330,86,0,0" Name="textBox34" VerticalAlignment="Top" Width="93.5" Text="0"></TextBox>

<TextBox Height="25" HorizontalAlignment="Right" Margin="0,86,11.5,0" Name="textBox35" VerticalAlignment="Top" Width="102.5" Text="0"></TextBox>

<ComboBox Height="22.48" HorizontalAlignment="Right" Margin="0,201,13,0" Name="comboBox1" VerticalAlignment="Top" Width="205" Text="auto" SelectedValuePath="auto" SelectedIndex="0">

<ComboBoxItem Name="auto">auto</ComboBoxItem>

<ComboBoxItem Name="одна">1000</ComboBoxItem>

<ComboBoxItem ForceCursor="False" Name="десять">10000</ComboBoxItem>

<ComboBoxItem Name="сто">100000</ComboBoxItem>

<ComboBoxItem Name="тыща">1000000</ComboBoxItem>

<ComboBoxItem Name="десятьтыща">10000000</ComboBoxItem>

</ComboBox>

<Label Height="25" Name="label1" Width="22" HorizontalAlignment="Right" Margin="0,84,121,0" VerticalAlignment="Top" Content="Ex:"></Label>

<Button Height="25" Name="button6" Width="102.5" Click="button6_Click" Margin="420,170,13,314">Очистить</Button>

<Button Height="25" Name="button7" Width="102.5" Click="button7_Click" IsCancel="False" Padding="1" HorizontalContentAlignment="Center" FlowDirection="LeftToRight" AllowDrop="True" BorderThickness="1" ClipToBounds="False" IsTabStop="True" Margin="310,170,123,314">Рассчитать</Button>

<Label Content="Bx:" Height="25" HorizontalAlignment="Right" Margin="0,55,248,0" Name="label3" VerticalAlignment="Top" Width="22" />

<Label Height="25" Name="label2" Content="Ax:" Margin="308,24,248,460"></Label>

<Label Content="Ay:" Height="25" Margin="436,26,120,458" Name="label5" />

<Label Content="By:" Height="25" Margin="436,56,120,428" Name="label6" />

<Label Content="Cx:" Height="25" Margin="308,86,248,398" Name="label7" />

</Grid>

</Window>

 

 

Файл MainWindow.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

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;

using System.Threading;

using WpfApplication1.localhost;

namespace П3_ТП

{

 

 

/// <summary>

/// Логика взаимодействия для Window1.xaml

/// </summary>

public partial class Window1: Window

{

BitmapImage bitmap1, bitmap2, bitmap3, bitmap4, bitmap5;

public Window1()

{

InitializeComponent();

Uri uri = new Uri(@"C:\images\image2_old.gif");

 

BitmapImage bitmap = new BitmapImage(uri);

image1.Source = bitmap;

 

Uri uri1 = new Uri(@"C:\images\image1.gif");

Uri uri2 = new Uri(@"C:\images\image2.gif");

Uri uri3 = new Uri(@"C:\images\image3.gif");

Uri uri4 = new Uri(@"C:\images\image4.gif");

Uri uri5 = new Uri(@"C:\images\image5.gif");

bitmap1 = new BitmapImage(uri1);

bitmap2 = new BitmapImage(uri2);

bitmap3 = new BitmapImage(uri3);

bitmap4 = new BitmapImage(uri4);

bitmap5 = new BitmapImage(uri5);

 

}

public double Ax;

public double Ay;

public double Bx;

public double By;

public double Cx;

public double Ex;

 

public delegate double[] ClassicDelegate(double Ax, double Ay, double Bx, double By, double Cx, double Ex, int n);

//obrabotchik sobitiya Vichislit

// private void HelloWorldCompleted(object sender,

// HelloWorldCompletedEventArgs e)

 

private void MonteCarloABCECompleted(object sender, MonteCarloABCECompletedEventArgs e)

{

button7.IsEnabled = true;

object[] result = new object[5];

result = e.Result;

double caser = (double)result[0];

 

if (caser == 1000.0)

{

textBox6.Text = System.Convert.ToString(result[0]);

textBox7.Text = System.Convert.ToString(result[1]);

textBox8.Text = System.Convert.ToString(result[2]);

textBox9.Text = System.Convert.ToString(result[3]);

textBox10.Text = System.Convert.ToString(result[4]);

 

// textBox40.Text = "10000";

}

if (caser == 10000.0)

{

textBox11.Text = System.Convert.ToString(result[0]);

textBox12.Text = System.Convert.ToString(result[1]);

textBox13.Text = System.Convert.ToString(result[2]);

textBox14.Text = System.Convert.ToString(result[3]);

textBox15.Text = System.Convert.ToString(result[4]);

 

// textBox40.Text = "100000";

}

 

if (caser == 100000.0)

{

textBox16.Text = System.Convert.ToString(result[0]);

textBox17.Text = System.Convert.ToString(result[1]);

textBox18.Text = System.Convert.ToString(result[2]);

textBox19.Text = System.Convert.ToString(result[3]);

textBox20.Text = System.Convert.ToString(result[4]);

 

// textBox40.Text = "1000000";

}

if (caser == 1000000.0)

{

textBox21.Text = System.Convert.ToString(result[0]);

textBox22.Text = System.Convert.ToString(result[1]);

textBox23.Text = System.Convert.ToString(result[2]);

textBox24.Text = System.Convert.ToString(result[3]);

textBox25.Text = System.Convert.ToString(result[4]);

 

// textBox40.Text = "10000000";

}

if (caser == 10000000.0)

{

textBox26.Text = System.Convert.ToString(result[0]);

textBox27.Text = System.Convert.ToString(result[1]);

textBox28.Text = System.Convert.ToString(result[2]);

textBox29.Text = System.Convert.ToString(result[3]);

textBox36.Text = System.Convert.ToString(result[4]);

 

// textBox40.Text = "Завершено успешно!";

}

}

private void button7_Click(object sender, RoutedEventArgs e)

{

try

{

Ax = System.Convert.ToDouble(textBox30.Text);

Ay = System.Convert.ToDouble(textBox31.Text);

Bx = System.Convert.ToDouble(textBox32.Text);

By = System.Convert.ToDouble(textBox33.Text);

Cx = System.Convert.ToDouble(textBox34.Text);

Ex = System.Convert.ToDouble(textBox35.Text);

}

catch

{

MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

return;

}

if (Ax > Bx || Bx > Cx || Ax > Ex || Ax > Cx || Ay > By)

{

MessageBox.Show("Проверьте правильность введенных данных", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

return;

}

if (Ax == 0 && Bx == 0 && Cx == 0 && Ex == 0 && Ay == 0 && By == 0)

{

MessageBox.Show("Проверьте правильность введенных данных", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

return;

}

 

double MaxX = 0;

double MaxY = 0;

double MinX = 0;

double MinY = 0;

double Cy = By;

double Ey = Ay;

MaxX = Math.Max(Math.Max(Ax, Bx), Math.Max(Cx, Ex));

MaxY = Math.Max(Math.Max(Ay, By), Math.Max(Cy, Ey));

MinX = Math.Min(Math.Min(Ax, Bx), Math.Min(Cx, Ex));

MinY = Math.Min(Math.Min(Ay, By), Math.Min(Cy, Ey));

double S_Rect_O = (MaxX - MinX) * (MaxY - MinY);

double S_Rect_Teor = (By - Ay) * (((Ex - Ax) + (Cx - Bx)) / 2);

double[] table_rez = new double[5];

textBox38.Text = System.Convert.ToString(S_Rect_O);

textBox40.Text = System.Convert.ToString(S_Rect_Teor);

//------------

 

//sozdanie proxy-class

// Service prefect = new Service();

int n;

if (comboBox1.Text == "auto")

{

n = 1000;

for (int i = 0; i < 5; i++)

{

Service proxy = new Service();

proxy.MonteCarloABCECompleted += new MonteCarloABCECompletedEventHandler(this.MonteCarloABCECompleted);

proxy.MonteCarloABCEAsync(Ax, Ay, Bx, By, Cx, Ex, n);

n *= 10;

}

}

else

{

n = System.Convert.ToInt32(comboBox1.Text);

Service proxy = new Service();

proxy.MonteCarloABCECompleted += new MonteCarloABCECompletedEventHandler(this.MonteCarloABCECompleted);

proxy.MonteCarloABCEAsync(Ax, Ay, Bx, By, Cx, Ex, n);

}

}

 

 

//slychai 1

private void button1_Click(object sender, RoutedEventArgs e)

{

Ax = 15; Ay = 10;

Bx = 30; By = 30;

Cx = 40; Ex = 50;

image1.Source = bitmap1;

//-------

textBox30.Text = Convert.ToString(Ax); textBox31.Text = Convert.ToString(Ay);

textBox32.Text = Convert.ToString(Bx); textBox33.Text = Convert.ToString(By);

textBox34.Text = Convert.ToString(Cx); textBox35.Text = Convert.ToString(Ex);

}

// slychai 2

private void button2_Click(object sender, RoutedEventArgs e)

{

Ax = 15; Ay = 10;

Bx = 30; By = 30;

Cx = 50; Ex = 50;

image1.Source = bitmap2;

 

//-------

textBox30.Text = Convert.ToString(Ax); textBox31.Text = Convert.ToString(Ay);

textBox32.Text = Convert.ToString(Bx); textBox33.Text = Convert.ToString(By);

textBox34.Text = Convert.ToString(Cx); textBox35.Text = Convert.ToString(Ex);

}

// slychai 3

private void button3_Click(object sender, RoutedEventArgs e)

{

Ax = 3; Ay = 14;

Bx = 7; By = 25;

Cx = 20; Ex = 16;

image1.Source = bitmap3;

//-------

textBox30.Text = Convert.ToString(Ax); textBox31.Text = Convert.ToString(Ay);

textBox32.Text = Convert.ToString(Bx); textBox33.Text = Convert.ToString(By);

textBox34.Text = Convert.ToString(Cx); textBox35.Text = Convert.ToString(Ex);

}

// slychai 1 random

private void button4_Click(object sender, RoutedEventArgs e)

{

Random input = new Random();

for (int i = 0; i < 1000000; i++)

{

Ax = Convert.ToInt32(input.NextDouble() * 1000);

Ay = Convert.ToInt32(input.NextDouble() * 1000);

Bx = Convert.ToInt32(input.NextDouble() * 1000);

By = Convert.ToInt32(input.NextDouble() * 1000);

Cx = Convert.ToInt32(input.NextDouble() * 1000);

Ex = Convert.ToInt32(input.NextDouble() * 1000);

if (Cx < Ex&&Ax<Bx&&Ay<By&&Bx<Cx&&Ax<Ex&&Ax<Cx)

{

break;

}

}

 

// RandX = (test.NextDouble() * (MaxX - MinX) + MinX);

 

image1.Source = bitmap4;

//-------

textBox30.Text = Convert.ToString(Ax); textBox31.Text = Convert.ToString(Ay);

textBox32.Text = Convert.ToString(Bx); textBox33.Text = Convert.ToString(By);

textBox34.Text = Convert.ToString(Cx); textBox35.Text = Convert.ToString(Ex);

}

// slychai 3 random

private void button5_Click(object sender, RoutedEventArgs e)

{

 

Random input = new Random();

for (int i = 0; i < 1000000; i++)

{

Ax = Convert.ToInt32(input.NextDouble() * 1000);

Ay = Convert.ToInt32(input.NextDouble() * 1000);

Bx = Convert.ToInt32(input.NextDouble() * 1000);

By = Convert.ToInt32(input.NextDouble() * 1000);

Cx = Convert.ToInt32(input.NextDouble() * 1000);

Ex = Convert.ToInt32(input.NextDouble() * 1000);

if (Cx > Ex && Ax < Bx && Ay < By && Bx < Cx&&Ax<Ex&&Ax<Cx)

{

break;

}

}

image1.Source = bitmap5;

//-------

textBox30.Text = Convert.ToString(Ax); textBox31.Text = Convert.ToString(Ay);

textBox32.Text = Convert.ToString(Bx); textBox33.Text = Convert.ToString(By);

textBox34.Text = Convert.ToString(Cx); textBox35.Text = Convert.ToString(Ex);

}

//Knopka Clears

private void button6_Click(object sender, RoutedEventArgs e)

{

textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = "";

textBox10.Text = ""; textBox11.Text = ""; textBox12.Text = ""; textBox13.Text = "";

textBox14.Text = ""; textBox15.Text = ""; textBox16.Text = ""; textBox17.Text = "";

textBox18.Text = ""; textBox19.Text = ""; textBox20.Text = ""; textBox21.Text = "";

textBox22.Text = ""; textBox23.Text = ""; textBox24.Text = ""; textBox25.Text = "";

textBox26.Text = ""; textBox27.Text = ""; textBox28.Text = ""; textBox29.Text = "";

textBox36.Text = "";

textBox30.Text = "";

textBox31.Text = "";

textBox32.Text = "";

textBox33.Text = "";

textBox34.Text = "";

textBox35.Text = "";

 

textBox38.Text = ""; textBox40.Text = "";

}

-

private void Window_Loaded(object sender, RoutedEventArgs e)

{

 

}

 

private void textBox39_TextChanged(object sender, TextChangedEventArgs e)

{

 

}

 

private void textBox30_TextChanged(object sender, TextChangedEventArgs e)

{

 

}

}

}

 



Поделиться:


Последнее изменение этой страницы: 2016-09-20; просмотров: 250; Нарушение авторского права страницы; Мы поможем в написании вашей работы!

infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 18.117.196.217 (0.117 с.)