コード例 #1
0
 /// <summary>
 /// Window containing all products in Products table
 /// </summary>
 public ProductsWindow()
 {
     InitializeComponent();
     db = new CaloriesEntities();
     db.Products.Load();
     ProductsLV.DataContext = db.Products.Local;
 }
コード例 #2
0
        /// <summary>
        /// Constructor of Window for adding new List
        /// </summary>
        public AddListWindow()
        {
            InitializeComponent();

            list = new Lists
            {
                Creation_date = DateTime.Now
            };

            prodList = new ObservableCollection <ProductsLists>();

            db = new CaloriesEntities();
            db.Products.Load();
            ProductsListsLV.DataContext = prodList;
            ProductsLVS.DataContext     = db.Products.Local;
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: zacny04/Calories
        /// <summary>
        /// Start window with listview showing products lists
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();


            Thread oTh = new Thread(new ThreadStart(() =>
            {
                db = new CaloriesEntities();
                db.Lists.Load();
                Dispatcher.Invoke(() =>
                {
                    ProductsListView.DataContext = db.Lists.Local;
                });
            }))
            {
                IsBackground = true
            };

            if (!oTh.IsAlive)
            {
                oTh.Start();
            }
        }
コード例 #4
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            Regex nameRegex = new Regex(namePattern), numberRegex = new Regex(numberPattern);

            if (nameRegex.IsMatch(pNameTextBox.Text) && numberRegex.IsMatch(pWeightTextBox.Text) && numberRegex.IsMatch(pCaloriesTextBox.Text))
            {
                using (CaloriesEntities db = new CaloriesEntities())
                {
                    if (_product.Id != 0)
                    {
                        var result = db.Products.SingleOrDefault(b => b.Id == _product.Id);
                        if (result != null)
                        {
                            result.Name = pNameTextBox.Text;
                            try
                            {
                                result.weight   = Int32.Parse(pWeightTextBox.Text);
                                result.calories = Int32.Parse(pCaloriesTextBox.Text);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                    }
                    else
                    {
                        _product.Name = pNameTextBox.Text;
                        try
                        {
                            _product.weight   = Int32.Parse(pWeightTextBox.Text);
                            _product.calories = Int32.Parse(pCaloriesTextBox.Text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        db.Products.Add(_product);
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                this.DialogResult = true;
            }
            else
            {
                SystemSounds.Hand.Play();
            }
        }