可以somone请帮我解决它把我逼疯!|嗨,这已经把我逼疯了几天现在我已经张贴在这里,但所有的建议似乎没有工作至今。下面是我的C#代码的XAML部分 - 如果有不再需要我将张贴任何在必要!
我明白提供任何帮助!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Collections.ObjectModel;
namespace WpfApplication4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
_DateLabel.Content = DateTime.Today;
}
private double _height, _weight, _target;
ObservableCollection<fooddata> _FoodDataCollection = new ObservableCollection<fooddata>();
public ObservableCollection<fooddata> FoodDataCollection
{ get { return _FoodDataCollection; } }
public class FoodData
{
public string Food_Name { get; set; }
public string Calories { get; set; }
public string Fat { get; set; }
public string Protein { get; set; }
public string Carbs { get; set; }
}
private void calendar1_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
_DateLabel.Content = calendar1.SelectedDate;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SqlConnection conn = new SqlConnection(WpfApplication4.Properties.Settings.Default.CalorieCounterConnectionString);
conn.Open();
using (SqlCommand command = new SqlCommand("SELECT TOP 1 User_Name,User_Height,User_Weight,User_Target,User_Target_Date FROM [User]", conn))
{
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
_userName.Content = reader.GetString(0);
_height = reader.GetDouble(1);
_weight = reader.GetDouble(2);
_target = reader.GetDouble(3);
_targetDate.Content = reader.GetDateTime(4);
}
}
_heightLbl.Content = _height;
_weightLbl.Content = _weight;
_targetWeight.Content = _target;
_toLose.Content = (_weight - _target);
_caloriesLeft.Content = ((_weight - _target) * 3500);
conn.Close();
using (DataClasses1DataContext dc = new DataClasses1DataContext())
{
listView1.ItemsSource = dc.Foods.ToList();
}
}
private void button6_Click(object sender, RoutedEventArgs e)
{
AddFood addfood = new AddFood();
addfood.Show();
addfood.Focus();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
DataSet dtSet = new DataSet();
using (SqlConnection conn = new SqlConnection(WpfApplication4.Properties.Settings.Default.CalorieCounterConnectionString))
{
conn.Open();
SqlCommand command = new SqlCommand("SELECT Food_Name,Food_Calories,Food_Fat,Food_Protein,Food_Carbs FROM [Food]", conn);