-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm2.cs
190 lines (158 loc) · 7.97 KB
/
Form2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using static sampleconnection.Form1;
namespace sampleconnection
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
Food placeholder = new Food();
LabelFoods.Text = "";
LabelResult.Text = "Your daily caloric intake for maintaining your current weight should be around:\n" +
Form1.resultFinal.ToString() + " kcal";
int days = Form1.durationNumFinal * 30;
decimal caloricDeficitDecimal = (Form1.weightToLoseFinal * 7700M) / days;
caloricDeficitDecimal = Decimal.Round(caloricDeficitDecimal);
int caloricDeficit = Convert.ToInt32(caloricDeficitDecimal);
int caloricBalance = Form1.resultFinal - caloricDeficit;
decimal caloricBlanaceDecimal = Convert.ToDecimal(caloricBalance);
if (caloricDeficit >= Form1.resultFinal)
{
LabelInformation.Text = "This much weight is practically impossible to be shed in this much time.";
return;
}
else
{ LabelInformation.Text = "Your daily caloric intake for the next " +
days.ToString() + " days in order to shed " + Form1.weightToLoseFinal.ToString() +
" kgs should be around:\n" + (caloricBalance - caloricBalance%100).ToString() + "-" + (caloricBalance - caloricBalance % 100 + 100).ToString() + " kcal"; }
decimal IncreaseOrDecreaseFrom2000 = caloricBlanaceDecimal - 2000;
decimal percentage = (IncreaseOrDecreaseFrom2000 / 2000) * 100;
decimal caloriesPerGram;
int smallestNumForDimesion = Math.Min(Convert.ToInt32(Form1.idNum), Convert.ToInt32(Form1.idNumL));
smallestNumForDimesion = Math.Min(smallestNumForDimesion, Convert.ToInt32(Form1.idNumD));
decimal[,] matrix = new decimal[3, smallestNumForDimesion];
Food[,] matrix1 = new Food[3, smallestNumForDimesion];
for (int i = 0; i < smallestNumForDimesion; i++)
{
placeholder = Form1.Breakfast[i];
caloriesPerGram = placeholder.Calories / placeholder.PortionSize;
placeholder.PortionSize = placeholder.PortionSize + placeholder.PortionSize * (percentage / 100);
placeholder.PortionSize = Decimal.Round(placeholder.PortionSize);
if ((placeholder.PortionSize % 10) < 5)
{
placeholder.PortionSize = placeholder.PortionSize - (placeholder.PortionSize % 10);
}
else
{
placeholder.PortionSize = placeholder.PortionSize + (10 - (placeholder.PortionSize % 10));
}
placeholder.Calories = placeholder.PortionSize * caloriesPerGram;
placeholder.Calories = Decimal.Round(placeholder.Calories);
Form1.Breakfast[i] = placeholder;
matrix[0, i] = Form1.Breakfast[i].Calories;
matrix1[0, i] = Form1.Breakfast[i];
}
for (int i = 0; i < smallestNumForDimesion; i++)
{
placeholder = Form1.Lunch[i];
caloriesPerGram = placeholder.Calories / placeholder.PortionSize;
placeholder.PortionSize = placeholder.PortionSize + placeholder.PortionSize * (percentage / 100);
placeholder.PortionSize = Decimal.Round(placeholder.PortionSize);
if ((placeholder.PortionSize % 10) < 5)
{
placeholder.PortionSize = placeholder.PortionSize - (placeholder.PortionSize % 10);
}
else
{
placeholder.PortionSize = placeholder.PortionSize + (10 - (placeholder.PortionSize % 10));
}
placeholder.Calories = placeholder.PortionSize * caloriesPerGram;
placeholder.Calories = Decimal.Round(placeholder.Calories);
Form1.Lunch[i] = placeholder;
matrix[1, i] = Form1.Lunch[i].Calories;
matrix1[1, i] = Form1.Lunch[i];
}
for (int i = 0; i < smallestNumForDimesion; i++)
{
placeholder = Form1.Dinner[i];
caloriesPerGram = placeholder.Calories / placeholder.PortionSize;
placeholder.PortionSize = placeholder.PortionSize + placeholder.PortionSize * (percentage / 100);
placeholder.PortionSize = Decimal.Round(placeholder.PortionSize);
if ((placeholder.PortionSize % 10) < 5)
{
placeholder.PortionSize = placeholder.PortionSize - (placeholder.PortionSize % 10);
}
else
{
placeholder.PortionSize = placeholder.PortionSize + (10 - (placeholder.PortionSize % 10));
}
placeholder.Calories = placeholder.PortionSize * caloriesPerGram;
placeholder.Calories = Decimal.Round(placeholder.Calories);
Form1.Dinner[i] = placeholder;
matrix[2, i] = Form1.Dinner[i].Calories;
matrix1[2, i] = Form1.Dinner[i];
}
int[] Assignment(decimal[,] input)
{
decimal result0;
int[] Index = new int[6];
int counter1=0;
for (int i = 0; i < 3; i++)
{
result0 = input[i,0];
Index[counter1] = i;
Index[counter1 + 1] = 0;
for (int j = 0; j < smallestNumForDimesion; j++)
{
if (input[i, j] > result0)
{
result0 = input[i, j];
Index[counter1] = i;
Index[counter1 + 1] = j;
}
}
counter1 +=2;
}
return (Index);
}
int caloriesForDay;
string FinalResult = "";
for (int i = 0; i < smallestNumForDimesion; i++)
{
int[] result = Assignment(matrix);
FinalResult += "Day " + (i+1).ToString() + ":" + "\n";
FinalResult += matrix1[result[0], result[1]].Name + " "
+ matrix1[result[0], result[1]].PortionSize.ToString()
+ " " + matrix1[result[0], result[1]].Calories.ToString()
+ " " + matrix1[result[0], result[1]].Link + "\n";
FinalResult += matrix1[result[2], result[3]].Name
+ " " + matrix1[result[2], result[3]].PortionSize.ToString()
+ " " + matrix1[result[2], result[3]].Calories.ToString() + " "
+ matrix1[result[2], result[3]].Link + "\n";
FinalResult += matrix1[result[4], result[5]].Name + " "
+ matrix1[result[4], result[5]].PortionSize.ToString()
+ " " + matrix1[result[4], result[5]].Calories.ToString()
+ " " + matrix1[result[4], result[5]].Link + "\n";
caloriesForDay = Convert.ToInt32(matrix[result[0], result[1]] + matrix[result[2], result[3]]
+ matrix[result[4], result[5]]);
FinalResult += "->" + caloriesForDay.ToString() + " kcal for the day" + "\n";
FinalResult += "\n";
matrix[result[0], result[1]] = 0M;
matrix[result[2], result[3]] = 0M;
matrix[result[4], result[5]] = 0M;
}
LabelFoods.Text = FinalResult;
}
}
}