wEventAdd.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. using TeaTime;
  19. namespace teaTime
  20. {
  21. /// <summary>
  22. /// Логика взаимодействия для wEventAdd.xaml
  23. /// </summary>
  24. public class TeaTime : INotifyPropertyChanged
  25. {
  26. private string _endTea = "";
  27. private int _num;
  28. public int num
  29. {
  30. get
  31. {
  32. return _num;
  33. }
  34. set
  35. {
  36. _num = value;
  37. OnPropertyChanged("num");
  38. }
  39. }
  40. public string endTea
  41. {
  42. get
  43. {
  44. return _endTea;
  45. }
  46. set
  47. {
  48. _endTea = value;
  49. }
  50. }
  51. public List<string> value { get; set; }
  52. public event PropertyChangedEventHandler PropertyChanged;
  53. public void OnPropertyChanged([CallerMemberName] string prop = "")
  54. {
  55. if (PropertyChanged != null)
  56. PropertyChanged(this, new PropertyChangedEventArgs(prop));
  57. }
  58. }
  59. public partial class wEventAdd : Page
  60. {
  61. ObservableCollection<TeaTime> items = new ObservableCollection<TeaTime>();
  62. List<string> teaList = new List<string>();
  63. Worker worker = new Worker();
  64. public wEventAdd(DateTime data, Worker user)
  65. {
  66. InitializeComponent();
  67. dp.Text = data.ToString();
  68. //выгрузка из бд
  69. worker = user;
  70. nameTeaLoaded(teaList);
  71. }
  72. private void nMin_SelectionChanged(object sender, SelectionChangedEventArgs e)
  73. {
  74. string hour = nHour.Text;
  75. string min = nMin.SelectedItem.ToString();
  76. if (hour == "")
  77. {
  78. hour = "00";
  79. }
  80. aTime.Text = hour + ":" + min;
  81. }
  82. private void nHour_SelectionChanged(object sender, SelectionChangedEventArgs e)
  83. {
  84. string hour = nHour.SelectedItem.ToString();
  85. string min = nMin.Text;
  86. if (min == "")
  87. {
  88. min = "00";
  89. }
  90. aTime.Text = hour + ":" + min;
  91. }
  92. private void nMin_Initialized(object sender, EventArgs e)
  93. {
  94. for (int i = 0; i < 60; i++)
  95. {
  96. nMin.Items.Add(i.ToString());
  97. }
  98. }
  99. private void nHour_Initialized(object sender, EventArgs e)
  100. {
  101. for (int i = 9; i < 23; i++)
  102. {
  103. nHour.Items.Add(i.ToString());
  104. }
  105. }
  106. private void nameTeaLoaded(List<string> teaList)
  107. {
  108. try
  109. {
  110. using (KotkovaISazonovaEntities_ DB = new KotkovaISazonovaEntities_())
  111. {
  112. teaList = Converter(DB.Tea.ToList());
  113. items.Add(new TeaTime() { num = items.Count + 1, value = teaList });
  114. nameTea.ItemsSource = items;
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. MessageBox.Show(ex.Message);
  120. }
  121. }
  122. public List<string> Converter(List<Tea> teas)
  123. {
  124. List<string> teaListNew = new List<string>();
  125. for (int i = 0; i < teas.Count; i++)
  126. {
  127. teaListNew.Add(teas[i].name); ;
  128. }
  129. return teaListNew;
  130. }
  131. private void nameTea_SelectionChanged(object sender, SelectionChangedEventArgs e)
  132. {
  133. nameTeaLoaded(teaList);
  134. nameTea.ItemsSource = items;
  135. }
  136. private void bClose_Click(object sender, RoutedEventArgs e)
  137. {
  138. NavigationService.Navigate(new wWorkerMain(worker));
  139. }
  140. private void bwrite_Click(object sender, RoutedEventArgs e)
  141. {
  142. //записьмероприятия в бд
  143. foreach (TeaTime a in nameTea.ItemsSource)//какой чай
  144. {
  145. if (a.endTea != "")
  146. {
  147. string b = a.endTea;
  148. }
  149. }
  150. NavigationService.Navigate(new wWorkerMain(worker));
  151. }
  152. private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  153. {
  154. }
  155. private void DatePicker_Initialized(object sender, EventArgs e)
  156. {
  157. dp.BlackoutDates.AddDatesInPast();
  158. dp.BlackoutDates.Add(new CalendarDateRange(DateTime.Now));
  159. using (KotkovaISazonovaEntities_ DB = new KotkovaISazonovaEntities_())
  160. {
  161. List<Event> List = DB.Event.ToList();
  162. for (int i = 0; i < List.Count; i++)
  163. {
  164. dp.BlackoutDates.Add(new CalendarDateRange(List[i].date));
  165. }
  166. }
  167. }
  168. }
  169. }