Cart.xaml.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using examPrepare.ViewModels;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace examPrepare.Pages
  17. {
  18. /// <summary>
  19. /// Interaction logic for Cart.xaml
  20. /// </summary>
  21. public partial class Cart : Page
  22. {
  23. public CartViewModel cartData = new CartViewModel();
  24. public Cart()
  25. {
  26. InitializeComponent();
  27. DataContext = cartData;
  28. }
  29. private void setProductCount(string id, int value)
  30. {
  31. if (value == 0)
  32. {
  33. GlobalInfo.cart.Remove(id);
  34. cartData.Products.RemoveAll(p => p.Id == id);
  35. GlobalInfo.setUpProductCountFunc();
  36. cartData.notifyChange();
  37. return;
  38. }
  39. GlobalInfo.cart[id] = value;
  40. cartData.Products.ForEach(x => {
  41. if (x.Id == id)
  42. {
  43. x.count = value;
  44. }
  45. });
  46. GlobalInfo.setUpProductCountFunc();
  47. cartData.notifyChange();
  48. }
  49. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  50. {
  51. TextBox textBox = sender as TextBox;
  52. string id = textBox.Uid;
  53. if (textBox.Text == String.Empty)
  54. {
  55. setProductCount(id, 0);
  56. } else
  57. {
  58. int value = Convert.ToInt32(textBox.Text);
  59. setProductCount(id, value);
  60. }
  61. }
  62. private void Button_Click(object sender, RoutedEventArgs e)
  63. {
  64. Order order = new Order();
  65. order.OrderStatus = 1;
  66. order.OrderPickupPoint = 1;
  67. order.OrderCode = "321";
  68. order.OrderCreationDate = DateTime.Now;
  69. order.OrderDeliveryDate = DateTime.Now;
  70. // test
  71. GlobalInfo.conn.Order.Add(order);
  72. int rez = GlobalInfo.conn.SaveChanges();
  73. MessageBox.Show(rez.ToString());
  74. }
  75. }
  76. }