123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- 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;
- namespace Learn
- {
- /// <summary>
- /// Логика взаимодействия для DataList.xaml
- /// </summary>
- public partial class DataList : Page
- {
- bool flag = false;
- int countOfServices = 0;
- Entities DB = new Entities();
- public DataList()
- {
- InitializeComponent();
- ServiceData.ItemsSource = DB.Service.ToList();
- PromoFilter.ItemsSource = new List<string>() { "Все", "от 0% до 5%", "от 5% до 15%", "от 15% до 30%", "от 30% до 70%", "от 70% до 100%" };
- PromoFilter.SelectedIndex = 0;
- countOfServices = ServiceData.Items.Count;
- global.Text = "Количество записей " + countOfServices + " из " + DB.Service.Count();
- }
- public DataList(int i)
- {
- InitializeComponent();
- ServiceData.ItemsSource = DB.Service.ToList();
- PromoFilter.ItemsSource = new List<string>() { "Все", "от 0% до 5%", "от 5% до 15%", "от 15% до 30%", "от 30% до 70%", "от 70% до 100%" };
- PromoFilter.SelectedIndex = 0;
- countOfServices = ServiceData.Items.Count;
- global.Text = "Количество записей " + countOfServices + " из " + DB.Service.Count();
- flag = true;
- }
- private void Minutes(object sender, RoutedEventArgs e)
- {
- TextBlock min = (TextBlock)sender;
- int index = Convert.ToInt32(min.Uid);
- int mins = Convert.ToInt32(DB.Service.Where(x => x.ID == index).Select(x => x.DurationInSeconds).First()) / 60;
- min.Text = " за " + mins.ToString() + " минут";
- }
- private void Promo(object sender, RoutedEventArgs e)
- {
- TextBlock pro = (TextBlock)sender;
- int index = Convert.ToInt32(pro.Uid);
- int promo = Convert.ToInt32(Convert.ToDouble(DB.Service.Where(x => x.ID == index).Select(x => x.Discount).First()) * 100);
- if (promo > 0)
- {
- pro.Text = "* скидка " + promo + "%";
- }
- else
- {
- return;
- }
- }
- private void DelEditLoad(object sender, RoutedEventArgs e)
- {
- StackPanel deledit = (StackPanel)sender;
- if (flag == true)
- {
- deledit.Visibility = Visibility.Visible;
- }
- }
- private void AddS(object sender, RoutedEventArgs e)
- {
- Button add = (Button)sender;
- if (flag == true)
- {
- add.Visibility = Visibility.Visible;
- }
- }
- private void ViewR(object sender, RoutedEventArgs e)
- {
- Button view = (Button)sender;
- if (flag == true)
- {
- view.Visibility = Visibility.Visible;
- }
- }
- private void Strike(object sender, RoutedEventArgs e)
- {
- TextBlock OldPrice = (TextBlock)sender;
- int id = Convert.ToInt32(OldPrice.Uid);
- double enable = Convert.ToDouble(DB.Service.Where(x => x.ID == id).Select(x => x.Discount).First());
- if (enable != 0)
- {
- OldPrice.Visibility = Visibility.Visible;
- }
- else
- {
- OldPrice.Visibility = Visibility.Collapsed;
- }
- }
- private void PriceLoad(object sender, RoutedEventArgs e)
- {
- TextBlock Price = (TextBlock)sender;
- int id = Convert.ToInt32(Price.Uid);
- double disc = Convert.ToDouble(DB.Service.Where(x => x.ID == id).Select(x => x.Discount).First());
- double cost = Convert.ToDouble(DB.Service.Where(x => x.ID == id).Select(x => x.Cost).First());
- if (disc != 0)
- {
- Price.Text = Convert.ToString(cost - disc * cost + " рублей");
- }
- else
- {
- Price.Text = Convert.ToString(cost + " рублей");
- }
- }
- private void BackgroundLoad(object sender, RoutedEventArgs e)
- {
- Grid serv = (Grid)sender;
- int index = Convert.ToInt32(serv.Uid);
- if (DB.Service.Where(x => x.ID == index).Select(x => x.Discount).First() > 0)
- {
- serv.Background = new SolidColorBrush(Colors.LightGreen);
- }
- }
- private void Up_Checked(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void Down_Checked(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void PromoChange(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void SearchChange(object sender, TextChangedEventArgs e)
- {
- Filter();
- }
- private void Filter()
- {
- List<Service> servs = DB.Service.ToList();
- if (Up.IsChecked == true)
- {
- servs = servs.OrderBy(x => x.Cost).ToList();
- }
- if (Down.IsChecked == true)
- {
- servs = servs.OrderByDescending(x => x.Cost).ToList();
- }
- switch (PromoFilter.SelectedIndex)
- {
- case 1:
- servs = servs.Where(x => x.Discount == null || (x.Discount >= 0 && x.Discount < 0.05)).ToList();
- break;
- case 2:
- servs = servs.Where(x => x.Discount >= 0.05 && x.Discount < 0.15).ToList();
- break;
- case 3:
- servs = servs.Where(x => x.Discount >= 0.15 && x.Discount < 0.30).ToList();
- break;
- case 4:
- servs = servs.Where(x => x.Discount >= 0.30 && x.Discount < 0.70).ToList();
- break;
- case 5:
- servs = servs.Where(x => x.Discount >= 0.70 && x.Discount < 1).ToList();
- break;
- default:
- break;
- }
- if (!string.IsNullOrWhiteSpace(Search.Text))
- {
- servs = servs.Where(x => x.Title.ToLower().Contains(Search.Text.ToLower())).ToList();
- }
- ServiceData.ItemsSource = servs;
- countOfServices = ServiceData.Items.Count;
- global.Text = "Количество записей " + countOfServices + " из " + DB.Service.Count();
- }
- private void RedServ(object sender, RoutedEventArgs e)
- {
- Button but = (Button)sender;
- int index = Convert.ToInt32(but.Uid);
- ReductAdd wns = new ReductAdd(index);
- wns.ShowDialog();
- }
- private void DeleteServ(object sender, RoutedEventArgs e)
- {
- Entities DB = new Entities();
- Button butt = (Button)sender;
- int index = Convert.ToInt32(butt.Uid);
- Service serv = DB.Service.Where(x => x.ID == index).FirstOrDefault();
- switch (MessageBox.Show("Удалить?", "Serv", MessageBoxButton.YesNo, MessageBoxImage.Question))
- {
- case MessageBoxResult.Yes:
- DB.Service.Remove(serv);
- MessageBox.Show("Удалено");
- DB.SaveChanges();
- MainFrame.mframe.Navigate(new DataList());
- break;
- case MessageBoxResult.No:
- MessageBox.Show("Вы отменили удаление");
- break;
- }
- }
- private void Add(object sender, RoutedEventArgs e)
- {
- ReductAdd wns = new ReductAdd();
- wns.ShowDialog();
- }
- private void MakeReg(object sender, RoutedEventArgs e)
- {
- Button butt = (Button)sender;
- int index = Convert.ToInt32(butt.Uid);
- AddRegistration wns = new AddRegistration(index);
- wns.ShowDialog();
- }
- private void Login(object sender, RoutedEventArgs e)
- {
- Login Auth = new Login();
- Auth.ShowDialog();
- }
- }
- }
|