1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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.Shapes;
- namespace Learn
- {
- /// <summary>
- /// Логика взаимодействия для ReductAdd.xaml
- /// </summary>
- public partial class ReductAdd : Window
- {
- Entities DB = new Entities();
- Service serv = new Service();
- bool flag = false;
- public ReductAdd()
- {
- InitializeComponent();
- flag = true;
- }
- public ReductAdd(int id)
- {
- InitializeComponent();
- serv = DB.Service.Where(x => x.ID == id).First();
- ServName.Text = serv.Title;
- Price.Text = serv.Cost.ToString();
- Duration.Text = serv.DurationInSeconds.ToString();
- Disc.Text = serv.Description;
- Promo.Text = serv.Discount.ToString();
- }
- private void FixChanges(object sender, RoutedEventArgs e)
- {
- if (Check(ServName.Text, Convert.ToInt32(Duration.Text)))
- {
- serv.Title = ServName.Text;
- serv.Cost = Convert.ToDecimal(Price.Text);
- serv.DurationInSeconds = Convert.ToInt32(Duration.Text);
- serv.Description = Disc.Text;
- serv.Discount = Convert.ToDouble(Promo.Text);
- if (flag)
- {
- DB.Service.Add(serv);
- DB.SaveChanges();
- }
- else
- {
- DB.SaveChanges();
- }
- MessageBox.Show("Класс добавлен");
- MainFrame.mframe.Navigate(new DataList());
- this.Close();
- }
- else
- {
- MessageBox.Show("Такой класс языка уже есть или он идёт больше 4 часов");
- }
- }
- public bool Check(string name, int seconds)
- {
- if (DB.Service.Where(x => x.Title == name).First() == null && seconds <= 14400 && seconds > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
|