Files
TestApp/Pages/Results.cshtml.cs

365 lines
15 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.Data.Sqlite;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
public class ResultsModel : PageModel
{
public double _D { get; set; }
public double _dd { get; set; }
public double _H { get; set; }
public double _x { get; set; }
public double _y { get; set; }
public double _z { get; set; }
public double _Q { get; set; }
public double _onTO { get; set; }
public double H_Billet { get; private set; }
public int limit1 { get; private set; }
public double H_BilletWithBlank { get; private set; }
public int limit2 { get; private set; }
public double D_Detail { get; private set; }
public double D_Billet { get; private set; }
public int limit3 { get; private set; }
public double D_BilletWithBlank { get; private set; }
public int limit4 { get; private set; }
public double d_Detail { get; private set; }
public double d_Billet { get; private set; }
public int limit5 { get; private set; }
public double d_BilletWithBlank { get; private set; }
public int limit6 { get; private set; }
public double D_nom_1 { get; private set; }
public double r_nom_1 { get; private set; }
public double H_nom_1 { get; private set; }
public double V_nom_1 { get; private set; }
public double mDisk_nom_1 { get; private set; }
public double D_max_1 { get; private set; }
public double r_max_1 { get; private set; }
public double H_max_1 { get; private set; }
public double V_max_1 { get; private set; }
public double mDisk_max_1 { get; private set; }
public double D_O_nom_1 { get; private set; }
public double r_O_nom_1 { get; private set; }
public double H_O_nom_1 { get; private set; }
public double V_O_nom_1 { get; private set; }
public double mDisk_O_nom_1 { get; private set; }
public double D_O_max_1 { get; private set; }
public double r_O_max_1 { get; private set; }
public double H_O_max_1 { get; private set; }
public double V_O_max_1 { get; private set; }
public double mDisk_O_max_1 { get; private set; }
public double mDisk_nom_1_O { get; private set; }
public double mDisk_max_1_O { get; private set; }
public double D_nom_2 { get; private set; }
public double r_nom_2 { get; private set; }
public double H_nom_2 { get; private set; }
public double V_nom_2 { get; private set; }
public double mDisk_nom_2 { get; private set; }
public double D_max_2 { get; private set; }
public double r_max_2 { get; private set; }
public double H_max_2 { get; private set; }
public double V_max_2 { get; private set; }
public double mDisk_max_2 { get; private set; }
public double D_O_nom_2 { get; private set; }
public double r_O_nom_2 { get; private set; }
public double H_O_nom_2 { get; private set; }
public double V_O_nom_2 { get; private set; }
public double mDisk_O_nom_2 { get; private set; }
public double D_O_max_2 { get; private set; }
public double r_O_max_2 { get; private set; }
public double H_O_max_2 { get; private set; }
public double V_O_max_2 { get; private set; }
public double mDisk_O_max_2 { get; private set; }
public double mDisk_nom_2_O { get; private set; }
public double mDisk_max_2_O { get; private set; }
public string? ResultImagePath { get; set; }
public void OnGet(double _D, double _dd, double _H, double _x, double _y, double _z, double _Q, double _onTO)
{
double h1 = _H * _x + (_y * _z) + _onTO;
double h2 = _H * _x + (_y * _z) + _Q + _onTO;
#region Расчет размеров поковки
// H заготовки = (Н1+б)+-∆/2
// Размер
H_Billet = h1 + SearchLimit(_D, h1).Item1;
// Допуск на размер +-
limit1 = SearchLimit(_D, h1).Item2;
// H заготовки с пробой = (Н2+б)+-∆/2
H_BilletWithBlank = h2 + SearchLimit(_D, h2).Item1;
// Допуск на размер +-
limit2 = SearchLimit(_D, h2).Item2;
// D дет = D+напуск на ТО
D_Detail = _D + _onTO;
// D заг = (D+б)+-∆/2+напуск на ТО
D_Billet = D_Detail + SearchLimit(_D, h1).Item1 + _onTO;
limit3 = SearchLimit(_D, h1).Item2;
// D заг с пробой= (D+б)+-∆/2+напуск на ТО
D_BilletWithBlank = D_Detail + SearchLimit(_D, h2).Item1 + _onTO;
limit4 = SearchLimit(_D, h2).Item2;
// d дет=d-напуск на ТО
d_Detail = _dd + _onTO;
// d заг =(dдет-б)+-3б
d_Billet = d_Detail - SearchLimit(_D, h1).Item1;
limit5 = SearchLimit(_D, h1).Item2 * 3;
//d заг с пробой =(dдет-б)+-3б
d_BilletWithBlank = d_Detail - SearchLimit(_D, h2).Item1;
limit6 = SearchLimit(_D, h2).Item2 * 3;
#endregion
#region Расчет массы поковки без пробы
// Диск номинал
D_nom_1 = D_Billet;
r_nom_1 = D_nom_1 / 2;
H_nom_1 = H_Billet;
V_nom_1 = 3.14 * (r_nom_1 * r_nom_1) * H_nom_1;
mDisk_nom_1 = Math.Round(V_nom_1 * 0.78 / 100000000, 3);
// Диск максимал
D_max_1 = D_Billet + limit3;
r_max_1 = D_max_1 / 2;
H_max_1 = H_Billet + limit1;
V_max_1 = 3.14 * (r_max_1 * r_max_1) * H_max_1;
mDisk_max_1 = Math.Round(V_max_1 * 0.78 / 100000000, 3);
// Отверстие номинал
D_O_nom_1 = d_Billet;
r_O_nom_1 = d_Billet / 2;
H_O_nom_1 = H_Billet;
V_O_nom_1 = 3.14 * (r_O_nom_1 * r_O_nom_1) * H_O_nom_1;
mDisk_O_nom_1 = Math.Round(V_O_nom_1 * 0.78 / 100000000, 3);
// Отверстие максимал
D_O_max_1 = d_Billet - limit5;
r_O_max_1 = D_O_max_1 / 2;
H_O_max_1 = H_Billet + limit1;
V_O_max_1 = 3.14 * (r_O_max_1 * r_O_max_1) * H_O_max_1;
mDisk_O_max_1 = Math.Round(V_O_max_1 * 0.78 / 100000000, 3);
// m диск с отв
mDisk_nom_1_O = mDisk_nom_1 - mDisk_O_nom_1;
mDisk_max_1_O = mDisk_max_1 - mDisk_O_max_1;
#endregion
#region Расчет массы поковки c пробой
// Диск номинал
D_nom_2 = D_BilletWithBlank;
r_nom_2 = D_nom_2 / 2;
H_nom_2 = H_BilletWithBlank;
V_nom_2 = 3.14 * (r_nom_2 * r_nom_2) * H_nom_2;
mDisk_nom_2 = Math.Round(V_nom_2 * 0.78 / 100000000, 3);
// Диск максимал
D_max_2 = D_BilletWithBlank + limit4;
r_max_2 = D_max_2 / 2;
H_max_2 = H_BilletWithBlank + limit2;
V_max_2 = 3.14 * (r_max_2 * r_max_2) * H_max_2;
mDisk_max_2 = Math.Round(V_max_2 * 0.78 / 100000000, 3);
// Отверстие номинал
D_O_nom_2 = d_BilletWithBlank;
r_O_nom_2 = D_O_nom_2 / 2;
H_O_nom_2 = H_BilletWithBlank;
V_O_nom_2 = 3.14 * (r_O_nom_2 * r_O_nom_2) * H_O_nom_2;
mDisk_O_nom_2 = Math.Round(V_O_nom_2 * 0.78 / 100000000, 3);
// Отверстие максимал
D_O_max_2 = d_BilletWithBlank - limit6;
r_O_max_2 = D_O_max_2 / 2;
H_O_max_2 = H_BilletWithBlank + limit2;
V_O_max_2 = 3.14 * (r_O_max_2 * r_O_max_2) * H_O_max_2;
mDisk_O_max_2 = Math.Round(V_O_max_2 * 0.78 / 100000000, 3);
// m диск с отв
mDisk_nom_2_O = mDisk_nom_2 - mDisk_O_nom_2;
mDisk_max_2_O = mDisk_max_2 - mDisk_O_max_2;
#endregion
ResultImage("Result_WithoutBlank", mDisk_nom_1_O, mDisk_max_1_O, _dd, d_Billet, limit5, _H, H_Billet, _D, D_Billet, limit3);
ResultImage("Result_WithBlank", mDisk_nom_2_O, mDisk_max_2_O, _dd, d_BilletWithBlank, limit6, _H, H_BilletWithBlank, _D, D_BilletWithBlank, limit4);
}
public (int Delta, int Tolerance) SearchLimit(double D, double H)
{
using var connection = new SqliteConnection("Data Source=tolerances.db");
connection.Open();
var command = connection.CreateCommand();
command.CommandText = @"
SELECT Delta, Tolerance
FROM Tolerances
WHERE @height > HeightFrom
AND @height <= HeightTo
AND @diameter > DiameterFrom
AND @diameter <= DiameterTo
LIMIT 1";
command.Parameters.AddWithValue("@height", H);
command.Parameters.AddWithValue("@diameter", D);
using var reader = command.ExecuteReader();
if (reader.Read())
{
return (reader.GetInt32(0), reader.GetInt32(1));
}
return (-1, -1);
}
/*
private (int, int) SearchLimit(double D, double H)
{
// Диапазоны высоты H
double[] heightRanges = new double[]
{
100, 150, 200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1400, 1600, 1800, 2000, 2250, 2500
};
// Диапазоны диаметра D
double[] diameterRanges = new double[]
{
499, 500, 630, 800, 1000, 1250, 1400, 1600, 1800, 2000, 2250, 2500, 2800, 3150, 3500, 4000, 4500, 5000
};
(int, int)[,] limits = new (int, int)[,]
{
// Св. 100 до 150 включ.
{ (24,9), (25,9), (27,10), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1) },
// Св. 150 до 200
{ (24,9), (25,9), (27,10), (29,11), (31,11), (35,13), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1) },
// Св. 200 до 250
{ (25,9), (26,9), (28,10), (30,11), (32,12), (36,13), (38,14), (40,15), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1) },
// Св. 250 до 315
{ (27,10), (28,10), (30,11), (32,12), (34,13), (38,14), (41,15), (44,16), (47,18), (51,19), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1) },
// Св. 315 до 400
{ (28,10), (29,11), (31,11), (33,12), (35,13), (40,15), (42,16), (46,17), (49,19), (53,20), (57,21), (61,23), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1) },
// Св. 400 до 500
{ (29,11), (30,11), (31,11), (34,13), (36,13), (41,15), (44,16), (48,18), (51,19), (55,21), (59,22), (63,24), (67,25), (71,27), (-1,-1), (-1,-1), (-1,-1) },
// Св. 500 до 630
{ (30,11), (31,11), (33,12), (35,13), (37,14), (43,16), (46,17), (50,19), (53,20), (57,21), (61,23), (65,25), (69,26), (75,28), (80,30), (95,37), (-1,-1) },
// Св. 630 до 800
{ (-1,-1), (33,12), (36,13), (38,14), (41,15), (46,17), (50,19), (54,20), (57,21), (61,23), (65,25), (71,27), (77,29), (83,31), (89,34), (98,39), (105,43) },
// Св. 800 до 1000
{ (-1,-1), (-1,-1), (37,14), (40,15), (43,16), (48,18), (52,20), (56,21), (59,22), (63,24), (68,26), (74,28), (80,30), (86,33), (92,36), (101,41), (108,46) },
// Св. 1000 до 1250
{ (-1,-1), (-1,-1), (-1,-1), (44,16), (46,17), (52,20), (56,21), (60,23), (64,24), (68,26), (74,28), (81,30), (86,33), (92,36), (98,39), (105,43), (112,48) },
// Св. 1250 до 1400
{ (-1,-1), (-1,-1), (-1,-1), (-1,-1), (47,18), (54,20), (58,22), (62,23), (67,25), (72,27), (78,29), (83,31), (89,34), (95,37), (101,41), (108,45), (115,50) },
// Св. 1400 до 1600
{ (-1,-1), (-1,-1), (-1,-1), (-1,-1), (48,18), (56,21), (60,23), (65,24), (69,26), (75,28), (81,30), (87,34), (93,36), (99,39), (104,42), (110,47), (119,51) },
// Св. 1600 до 1800
{ (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (58,22), (63,23), (67,25), (73,27), (79,29), (85,33), (91,35), (97,38), (102,41), (106,43), (113,48), (120,52) },
// Св. 1800 до 2000
{ (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (64,23), (68,25), (75,28), (81,30), (87,34), (92,36), (98,38), (103,41), (107,43), (115,50), (121,52) },
// Св. 2000 до 2250
{ (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (69,26), (76,28), (82,30), (88,34), (94,37), (100,40), (104,42), (110,47), (116,50), (122,52) },
// Св. 2250 до 2500
{ (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (-1,-1), (82,30), (85,32), (91,35), (97,38), (100,41), (108,43), (114,49), (119,51), (125,53) }
};
int FindIndex(double val, double[] ranges)
{
for (int i = 0; i < ranges.Length; i++)
{
if (val <= ranges[i])
return i - 1;
}
return -1;
}
int hIndex = FindIndex(H, heightRanges);
int dIndex = FindIndex(D, diameterRanges);
if (D < 499)
dIndex = 0;
if (hIndex == -1 || dIndex == -1)
return (-1, -1);
return limits[hIndex, dIndex];
}
*/
private string ResultImage(string imageName, double weightNom, double weightMax, double d, double d_Billet,
double limit5, double H, double H_Billet, double D, double D_Billet, double limit3)
{
string templatePath = Path.Combine("wwwroot", "images", "Template.png");
string outputPath = Path.Combine("wwwroot", "images", $"{imageName}.png");
#pragma warning disable CA1416
using (var image = Image.FromFile(templatePath) as Bitmap)
{
var privateFontCollection = new PrivateFontCollection();
string fontPath = Path.Combine("wwwroot", "fonts", "MyFont.ttf");
privateFontCollection.AddFontFile(fontPath);
var fontFamily = privateFontCollection.Families[0];
var font = new Font(fontFamily, 12);
using (var graphics = Graphics.FromImage(image))
{
var brush = new SolidBrush(Color.Black);
graphics.DrawString("Выше стрелки - размеры детали,", font, brush, new PointF(30, 20));
graphics.DrawString("Ниже стрелки - размеры поковки", font, brush, new PointF(30, 35));
graphics.DrawString($"Масса номинал: {Math.Round(weightNom, 3)} тонн", font, brush, new PointF(510, 20));
graphics.DrawString($"Масса максимал: {Math.Round(weightMax, 3)} тонн", font, brush, new PointF(510, 35));
graphics.DrawString($"⌀{Math.Round(d)}", font, brush, new PointF(355, 50));
graphics.DrawString($"{Math.Round(d_Billet)} +-{limit5}", font, brush, new PointF(340, 70));
graphics.DrawString($"⌀{Math.Round(D)}", font, brush, new PointF(350, 210));
graphics.DrawString($"{Math.Round(D_Billet)} +-{limit3}", font, brush, new PointF(335, 230));
graphics.TranslateTransform(710, 155);
graphics.RotateTransform(270);
graphics.DrawString($"{Math.Round(H)}", font, brush, new PointF(0, 0));
graphics.DrawString($"{Math.Round(H_Billet)}", font, brush, new PointF(-5, 25));
}
image.Save(outputPath, ImageFormat.Png);
}
#pragma warning restore CA1416
return outputPath.Replace("wwwroot", "");
}
}