-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPresenter.cs
82 lines (74 loc) · 3.05 KB
/
MainPresenter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DfEditor;
using System.Drawing;
using System.IO;
namespace Physics
{
class MainPresenter
{
private readonly IMainForm _view;
private readonly IMessageService _messageService;
private readonly IParamCalc _paramCalc;
public MainPresenter(IMainForm view, IParamCalc paramCalc, IMessageService messageService)
{
_view = view;
_messageService = messageService;
_paramCalc = paramCalc;
_view.CalculateClick += new EventHandler(_view_CalculateClick);
_view.GraphClick += new EventHandler(_view_GraphClick);
}
void _view_CalculateClick(object sender, EventArgs e)
{
if (_paramCalc.Calc(_view.airTemp, _view.bottomTemp, _view.charSize, _view.length, _view.emissivity, _view.isHorizontal))
{
//выводим результаты
_view.avTemp = _paramCalc.AvTemp.ToString("F2");
_view.grashof = _paramCalc.Grashof.ToString("F3");
_view.rayleigh = _paramCalc.Rayleigh.ToString("F3");
_view.nusselt = _paramCalc.Nusselt.ToString("F3");
_view.heatTransferCoeff = _paramCalc.HeatTransfer.ToString("F3");
//File.Delete("Eq2ImgWinForms.gif");
//рендерим картинку и добавляем в окно
try
{
string path = Path.GetTempPath() + "Eq2ImgWinForms.gif";
_view.formula = null;
NativeMethods.CreateGifFromEq(_paramCalc.EqStr, path);
_view.formula = Image.FromFile(path);
_view.grButtonisEnabled = true;
}
catch (Exception ex)
{
_messageService.ShowExclamation(ex.Message);
}
}
else
{
_messageService.ShowExclamation("Проверьте корректность входных данных");
}
}
void _view_GraphClick(object sender, EventArgs e)
{
GraphForm form = new GraphForm();
form.data = _paramCalc.PlotData;
form.ShowDialog();
}
}
[System.Security.SuppressUnmanagedCodeSecurity()]
internal class NativeMethods
{
private NativeMethods()
{ //all methods in this class would be static
}
[System.Runtime.InteropServices.DllImport("MimeTex.dll")]
internal static extern int CreateGifFromEq(string expr, string fileName);
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
internal extern static IntPtr GetModuleHandle(string lpModuleName);
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
internal extern static bool FreeLibrary(IntPtr hLibModule);
}
}