forked from AlexanderIVth/Simple-IMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditItem.xaml.cs
55 lines (49 loc) · 1.73 KB
/
EditItem.xaml.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
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes;
namespace SimpleIMS
{
/// <summary>
/// Interaction logic for EditItem.xaml
/// </summary>
public partial class EditItem : Window
{
public ItemsEntities db = new ItemsEntities();
public MainWindow imsWindow;
public Item selectedItem;
public EditItem(MainWindow mainWindow)
{
InitializeComponent();
this.imsWindow = mainWindow;
this.selectedItem = mainWindow.dGItems.SelectedItems[0] as Item;
this.txtBoxName.Text = selectedItem.ItemName;
this.txtBoxDescription.Text = selectedItem.ItemDescription;
this.dPAdded.SelectedDate = selectedItem.DateAdded;
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void buttonConfirm_Click(object sender, RoutedEventArgs e)
{
Item i = (from d in db.Items where d.Id == selectedItem.Id select d).SingleOrDefault();
i.ItemName = txtBoxName.Text;
i.ItemDescription = txtBoxDescription.Text;
i.DateAdded = dPAdded.SelectedDate.Value;
db.Items.AddOrUpdate(i);
db.SaveChanges();
this.imsWindow.dGItems.ItemsSource = (from d in db.Items select d).ToList();
}
}
}