123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using DB.Classes;
- using System;
- using System.Collections.Generic;
- 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.Navigation;
- using System.Windows.Shapes;
- enum CreateState {Create, Update };
- namespace DB.Pages
- {
- /// <summary>
- /// Логика взаимодействия для AddChangePage.xaml
- /// </summary>
- public partial class AddChangePage : Page
- {
- CreateState state;
- Service service = new Service();
- public AddChangePage()
- {
- InitializeComponent();
- state = CreateState.Create;
- }
- public AddChangePage(int id)
- {
- InitializeComponent();
- state = CreateState.Update;
- service = DataBaseClass.entity.Service.FirstOrDefault(x => x.ID == id);
- TBTitle.Text = service.Title;
- TBCost.Text = service.Cost.ToString();
- BTNDio.Content = "Change";
- }
- private void BTNDio_Click(object sender, RoutedEventArgs e)
- {
- Service check = DataBaseClass.entity.Service.FirstOrDefault(x => x.Title.ToLower() == TBTitle.Text.ToLower());
- if(check != null)
- {
- MessageBox.Show("Такая запись уже есть!");
- return;
- }
- bool flag = true;
- while(flag)
- {
- if(state == CreateState.Create)
- {
- service.Title = TBTitle.Text;
- service.Cost = Convert.ToDecimal(TBCost.Text);
- DataBaseClass.entity.Service.Add(service);
- }
- else
- {
- service.Title = TBTitle.Text;
- service.Cost = Convert.ToDecimal(TBCost.Text);
- }
- if(state != CreateState.Update)
- {
- MessageBox.Show("Добавление!");
- }
- else
- {
- MessageBox.Show("Изменение!");
- }
- DataBaseClass.entity.SaveChanges();
- ListViewPage listViewPage = new ListViewPage();
- listViewPage.LVService.ItemsSource = DataBaseClass.entity.Service.ToList();
- FrameClass.MainFrame.Navigate(listViewPage);
- flag = false;
- }
- }
- }
- }
|