Profile.xaml.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace mateo
  17. {
  18. public partial class Profile : Window
  19. {
  20. byte[] image;
  21. public Profile()
  22. {
  23. InitializeComponent();
  24. Update();
  25. }
  26. public void Update()
  27. {
  28. //фио
  29. var fio = DB.GetContext().Users.FirstOrDefault(x => x.IDUsers == DB.Iduser);
  30. name_profile.Text = fio.LastName + " " + fio.FirstName + " " + fio.MiddleName;
  31. //выводим баланс карты
  32. DB.Idcard = fio.FKCard;
  33. balance_profile.Text = String.Format("{0:0.00}", Convert.ToDecimal(DB.GetContext().Card.FirstOrDefault(x => x.IDCard == fio.FKCard).Balance));
  34. //выводим картинку из бд
  35. if (fio.Image != null)
  36. {
  37. image = fio.Image;
  38. MemoryStream ms = new MemoryStream(image);
  39. photo_profile.Source = BitmapFrame.Create(ms);
  40. }
  41. if (photo_profile.Source != null) btn_photo.Content = "изменить фото";
  42. }
  43. private void btnProfileClick(object sender, RoutedEventArgs e)
  44. {
  45. }
  46. private void btnUslugiClick(object sender, RoutedEventArgs e)
  47. {
  48. MainWindow mainWindow = new MainWindow();
  49. mainWindow.Show();
  50. this.Close();
  51. }
  52. private void btn_balance_Click(object sender, RoutedEventArgs e)
  53. {
  54. grid_balance.Visibility = Visibility.Visible;
  55. }
  56. private void btn_balanceplus_Click(object sender, RoutedEventArgs e)
  57. {
  58. //"пополняем баланс" типа
  59. if (txt_balanceplus.Text != "")
  60. {
  61. var a = DB.GetContext().Card.Where(x => x.IDCard == DB.Idcard).FirstOrDefault();
  62. a.Balance += Convert.ToDecimal(txt_balanceplus.Text);
  63. DB.GetContext().SaveChanges();
  64. grid_balance.Visibility = Visibility.Hidden;
  65. }
  66. var fio = DB.GetContext().Users.FirstOrDefault(x => x.IDUsers == DB.Iduser);
  67. DB.Idcard = fio.FKCard;
  68. balance_profile.Text = DB.GetContext().Card.FirstOrDefault(x => x.IDCard == fio.FKCard).Balance.ToString();
  69. Update();
  70. }
  71. private void btn_cancelblnc_Click(object sender, RoutedEventArgs e)
  72. {
  73. grid_balance.Visibility = Visibility.Hidden;
  74. }
  75. private void btn_photo_click(object sender, RoutedEventArgs e)
  76. {
  77. try
  78. {
  79. string imageLoc;
  80. OpenFileDialog dld = new OpenFileDialog();
  81. dld.Filter = "JPG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|JPEG Files (*.jpeg)|*.jpeg";
  82. dld.Title = "Выберите изображение пользователя";
  83. bool? result = dld.ShowDialog();
  84. if(result == true)
  85. {
  86. imageLoc = dld.FileName;
  87. photo_profile.Source = new BitmapImage(new Uri(imageLoc));
  88. FileStream fs = new FileStream(imageLoc, FileMode.Open, FileAccess.Read);
  89. BinaryReader br = new BinaryReader(fs);
  90. image = br.ReadBytes((int)fs.Length);
  91. var img = DB.GetContext().Users.Where(x => x.IDUsers == DB.Iduser).FirstOrDefault();
  92. img.Image = image;
  93. DB.GetContext().SaveChanges();
  94. }
  95. if (photo_profile.Source != null) btn_photo.Content = "изменить фото";
  96. }
  97. catch (Exception ex)
  98. {
  99. MessageBox.Show(ex.Message);
  100. }
  101. }
  102. private void btn_deletephoto_click(object sender, RoutedEventArgs e)
  103. {
  104. var fio = DB.GetContext().Users.FirstOrDefault(x => x.IDUsers == DB.Iduser);
  105. fio.Image = null;
  106. DB.GetContext().SaveChanges();
  107. photo_profile.Source = null;
  108. btn_photo.Content = "добавить фото";
  109. }
  110. #region соцсети
  111. private void btn_insta(object sender, RoutedEventArgs e)
  112. {
  113. }
  114. private void btn_vk(object sender, RoutedEventArgs e)
  115. {
  116. }
  117. private void btn_whatsapp(object sender, RoutedEventArgs e)
  118. {
  119. }
  120. private void btn_gmail(object sender, RoutedEventArgs e)
  121. {
  122. }
  123. #endregion
  124. private void btnExit(object sender, RoutedEventArgs e)
  125. {
  126. Application.Current.Shutdown();
  127. }
  128. private void btnLogout(object sender, RoutedEventArgs e)
  129. {
  130. First first = new First();
  131. first.Show();
  132. this.Close();
  133. }
  134. private void btnTickets(object sender, RoutedEventArgs e)
  135. {
  136. }
  137. }
  138. }