using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace HCI_Application { public partial class Nutritional : Form { int carb = 0; int protein = 0; int fat = 0; OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\Event Driven Programming\\HCI Application\\Nutrients.accdb"); public Nutritional() { InitializeComponent(); } private void chart1_Click(object sender, EventArgs e) { } private void Nutritional_Load(object sender, EventArgs e) { int maintenance = Convert.ToInt32(CalorieCalculator.intake); int fatloss = maintenance - 500; int gain = maintenance + 500; lblIntake.Text = "BMR: " + CalorieCalculator.intake.ToString(); lblMaintenance.Text = "Maintenance: " + maintenance.ToString(); lblFatloss.Text = "Fat Loss: " + fatloss.ToString(); lblGain.Text = "Weight Gain: " + gain.ToString(); this.nutrientsTableAdapter.Fill(this.nutrientsDataSet.Nutrients); cmbDiet.Items.Add("Standard Diet (60-30-10)"); cmbDiet.Items.Add("Ketogenic Diet (10-45-45)"); cmbDiet.Items.Add("Bodybuilding Diet (50-30-20)"); cmbDiet.Items.Add("High Protein Diet (25-50-25)"); cmbDiet.Items.Add("Zone Diet (40-30-30)"); cmbDiet.SelectedIndex = 0; } private void cmbDiet_SelectedIndexChanged(object sender, EventArgs e) { switch (cmbDiet.SelectedIndex) { case 0: carb = 60; protein = 30; fat = 10; break; case 1: carb = 10; protein = 45; fat = 45; break; case 2: carb = 50; protein = 30; fat = 20; break; case 3: carb = 25; protein = 50; fat = 25; break; case 4: carb = 40; protein = 30; fat = 30; break; } connection.Open(); OleDbCommand updateValues = new OleDbCommand("UPDATE Nutrients SET Percentage='" + carb + "' WHERE Nutrient = 'Carbohydrates'", connection); updateValues.ExecuteNonQuery(); updateValues.CommandText = "UPDATE Nutrients SET Percentage='" + protein + "' WHERE Nutrient = 'Protein'"; updateValues.ExecuteNonQuery(); updateValues.CommandText= "UPDATE Nutrients SET Percentage='" + fat + "' WHERE Nutrient = 'Fat'"; updateValues.ExecuteNonQuery(); DrawChart(); connection.Close(); } private void DrawChart() { DietChart.Series["NutrientSeries"].XValueMember = "Nutrient"; DietChart.Series["NutrientSeries"].YValueMembers = "Percentage"; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)