/
MyNutrition.aspx.cs
206 lines (176 loc) · 9.79 KB
/
MyNutrition.aspx.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Main_MyNutrition : System.Web.UI.Page
{
#region Events
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindPersonalSummaryDetails();
if (Request.QueryString["msg"] != null)
{
if (Request.QueryString["msg"].ToString().Equals("ins"))
lblMsg.Text = "Record has been inserted successfully.";
else if (Request.QueryString["msg"].ToString().Equals("del"))
lblMsg.Text = "Record has been deleted successfully.";
else if (Request.QueryString["msg"].ToString().Equals("up"))
lblMsg.Text = "Record has been updated successfully.";
}
}
BindCMSDetails();
}
protected void lnkBtnUpdatePersonalSummary_Click(object sender, EventArgs e)
{
UpdatePersonalSummaryDetails();
}
protected void lnkBtnCalculate_Click(object sender, EventArgs e)
{
if (ViewState["isExists"] != null)
{
if (ViewState["isExists"].ToString().Equals("0"))
{
txtStartWaist.Text = txtWaist.Text;
txtStartWeight.Text = txtWeight.Text;
txtStartBMI.Text = AppLib.GetBMI(Convert.ToDecimal(txtWeight.Text), Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtStartBodyFAT.Text = AppLib.GetBodyFATPercentage(ddlGender.SelectedValue,
Convert.ToDecimal(txtWaist.Text),
Convert.ToDecimal(txtHips.Text),
Convert.ToDecimal(txtNeck.Text), Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtStartWaistToHeight.Text = (Convert.ToDecimal(txtHeight.Text) / Convert.ToDecimal(txtWaist.Text)).ToString("00.00");
txtStartWaistToHips.Text = (Convert.ToDecimal(txtHips.Text) / Convert.ToDecimal(txtWaist.Text)).ToString("00.00");
txtCurrentWaist.Text = txtWaist.Text;
txtCurrentWeight.Text = txtWeight.Text;
txtCurrentBMI.Text = AppLib.GetBMI(Convert.ToDecimal(txtWeight.Text), Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtCurrentBodyFAT.Text = AppLib.GetBodyFATPercentage(ddlGender.SelectedValue,
Convert.ToDecimal(txtWaist.Text),
Convert.ToDecimal(txtHips.Text),
Convert.ToDecimal(txtNeck.Text), Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtCurrentWaistToHeight.Text = (Convert.ToDecimal(txtWaist.Text) / Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtCurrentWaistToHips.Text = (Convert.ToDecimal(txtWaist.Text) / Convert.ToDecimal(txtHips.Text)).ToString("00.00");
}
else
{
txtCurrentWaist.Text = txtWaist.Text;
txtCurrentWeightPersonalSummary.Text = txtWeight.Text;
txtCurrentBMI.Text = AppLib.GetBMI(Convert.ToDecimal(txtWeight.Text), Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtCurrentBodyFAT.Text = AppLib.GetBodyFATPercentage(ddlGender.SelectedValue,
Convert.ToDecimal(txtWaist.Text),
Convert.ToDecimal(txtHips.Text),
Convert.ToDecimal(txtNeck.Text), Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtCurrentWaistToHeight.Text = (Convert.ToDecimal(txtWaist.Text) / Convert.ToDecimal(txtHeight.Text)).ToString("00.00");
txtCurrentWaistToHips.Text = (Convert.ToDecimal(txtWaist.Text) / Convert.ToDecimal(txtHips.Text)).ToString("00.00");
}
txtChangeWaist.Text = AppLib.GetPercentageIncreate(Convert.ToDecimal(txtStartWaist.Text), Convert.ToDecimal(txtCurrentWaist.Text)).ToString("00.00");
txtChangeWeight.Text = AppLib.GetPercentageIncreate(Convert.ToDecimal(txtStartWeight.Text), Convert.ToDecimal(txtCurrentWeightPersonalSummary.Text)).ToString("00.00");
txtChangeBMI.Text = AppLib.GetPercentageIncreate(Convert.ToDecimal(txtStartBMI.Text), Convert.ToDecimal(txtCurrentBMI.Text)).ToString("00.00");
txtChangeBodyFAT.Text = AppLib.GetPercentageIncreate(Convert.ToDecimal(txtStartBodyFAT.Text), Convert.ToDecimal(txtCurrentBodyFAT.Text)).ToString("00.00");
txtChangeWaistToHeight.Text = AppLib.GetPercentageIncreate(Convert.ToDecimal(txtStartWaistToHeight.Text), Convert.ToDecimal(txtCurrentWaistToHeight.Text)).ToString("00.00");
txtChangeWaistToHips.Text = AppLib.GetPercentageIncreate(Convert.ToDecimal(txtStartWaistToHips.Text), Convert.ToDecimal(txtCurrentWaistToHips.Text)).ToString("00.00");
}
}
private void UpdatePersonalSummaryDetails()
{
BackofficeClass objBackOfficeClass = new BackofficeClass();
DataSet DS = objBackOfficeClass.Mem_GET_UserInfo(AppLib.GetLoggedInUserName());
BLL.PersonalSummaryLib oPersonalSummaryLib = null;
Entity.PersonalSummaryInfo oPersonalSummaryInfo = null;
try
{
oPersonalSummaryLib = new BLL.PersonalSummaryLib();
oPersonalSummaryInfo = new Entity.PersonalSummaryInfo();
oPersonalSummaryInfo.DecBMI = Convert.ToDecimal(txtCurrentBMI.Text);
oPersonalSummaryInfo.DecBodyFATPercentage = Convert.ToDecimal(txtCurrentBodyFAT.Text);
oPersonalSummaryInfo.DecWaist = Convert.ToDecimal(txtCurrentWaist.Text);
oPersonalSummaryInfo.DecWaistToHeight = Convert.ToDecimal(txtCurrentWaistToHeight.Text);
oPersonalSummaryInfo.DecWaistToHip = Convert.ToDecimal(txtCurrentWaistToHips.Text);
oPersonalSummaryInfo.DecWeight = Convert.ToDecimal(txtCurrentWeight.Text);
oPersonalSummaryInfo.DtCreatedOn = DateTime.Now;
oPersonalSummaryInfo.GuidUserId = new Guid(DS.Tables[0].Rows[0]["USER_ID"].ToString());
oPersonalSummaryLib.SavePersonalSummaryDetails(oPersonalSummaryInfo);
Response.Redirect(AppConfig.GetBaseSiteUrl() + "Main/MyNutrition.aspx?msg=up");
}
catch (Exception ex) { throw ex; }
finally
{
oPersonalSummaryInfo = null;
oPersonalSummaryLib = null;
objBackOfficeClass = null;
DS = null;
}
}
#endregion
#region User Defined Functions
/// <summary>
/// BindDetails() function used to bind all the details that need to be display on the page load.
/// </summary>
private void BindCMSDetails()
{
SqlConnClass objSqlConnClass = new SqlConnClass();
TextAreaClass objTextAreaClass;
objTextAreaClass = new TextAreaClass(objSqlConnClass.OpenConnection());
DataSet DSCMS = objTextAreaClass.TxA_Get_TextAreas("MyNutritionOverview", "2");
try
{
if (DSCMS.Tables[0].Rows.Count > 0)//There needs to be at least 1 row
{
if (DSCMS.Tables[0].Rows[0]["TextAreaHTML"].ToString().Length > 900)
lblNutritionOverview.Text = DSCMS.Tables[0].Rows[0]["TextAreaHTML"].ToString().Substring(0, 900);
else
lblNutritionOverview.Text = DSCMS.Tables[0].Rows[0]["TextAreaHTML"].ToString();
}
}
catch { }
finally
{
objSqlConnClass.CloseConnection();
objSqlConnClass = null;
objTextAreaClass = null;
DSCMS = null;
}
}
/// <summary>
/// following function is used to bind the personal summary details.
/// </summary>
private void BindPersonalSummaryDetails()
{
lblCurrentPersonalSummary.Text = DateTime.Now.ToShortDateString();
BLL.PersonalSummaryLib oPersonalSummaryLib = null;
Entity.PersonalSummaryInfo oPersonalSummaryInfo = null;
BackofficeClass objBackOfficeClass = new BackofficeClass();
DataSet DS = objBackOfficeClass.Mem_GET_UserInfo(AppLib.GetLoggedInUserName());
try
{
oPersonalSummaryLib = new BLL.PersonalSummaryLib();
oPersonalSummaryInfo = new Entity.PersonalSummaryInfo();
oPersonalSummaryInfo = oPersonalSummaryLib.GetPersonalSummaryDetailsByUserId(new Guid(DS.Tables[0].Rows[0]["USER_ID"].ToString()));
if (oPersonalSummaryInfo != null)
{
ViewState["isExists"] = "1";
lblStartDatePersonalSummary.Text = oPersonalSummaryInfo.DtModifiedOn.ToShortDateString();
txtStartWeight.Text = oPersonalSummaryInfo.DecWeight.ToString("00.00");
txtStartWaistToHips.Text = oPersonalSummaryInfo.DecWaistToHip.ToString("00.00");
txtStartWaistToHeight.Text = oPersonalSummaryInfo.DecWaistToHeight.ToString("00.00");
txtStartWaist.Text = oPersonalSummaryInfo.DecWaist.ToString("00.00");
txtStartBodyFAT.Text = oPersonalSummaryInfo.DecBodyFATPercentage.ToString("00.00");
txtStartBMI.Text = oPersonalSummaryInfo.DecBMI.ToString("00.00");
}
else
ViewState["isExists"] = "0";
}
catch (Exception ex) { throw ex; }
finally
{
oPersonalSummaryLib = null;
oPersonalSummaryInfo = null;
objBackOfficeClass = null;
DS = null;
}
}
#endregion
}