wMemberMain.xaml.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Globalization;
  6. using System.Linq;
  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 System.Windows.Xps.Serialization;
  19. using System.Xml.Linq;
  20. using teaTime.class_es;
  21. using System.ComponentModel;
  22. using TeaTime;
  23. namespace teaTime
  24. {
  25. /// <summary>
  26. /// Логика взаимодействия для wMemberMain.xaml
  27. /// </summary>
  28. public partial class wMemberMain : Page
  29. {
  30. Member member = new Member();
  31. public wMemberMain(Member user)
  32. {
  33. InitializeComponent();
  34. member = user;
  35. loadedCalendar();
  36. loadedData();
  37. loadedColorData();
  38. changeEventDescription(DateTime.Now.ToString().Split(':')[0]);
  39. }
  40. private void bUserProfile_Click(object sender, RoutedEventArgs e)
  41. {
  42. NavigationService.Navigate(new wMemberUserPrifile(member));
  43. }
  44. private void bReg_Click(object sender, RoutedEventArgs e)
  45. {
  46. }
  47. private void b_Click(object sender, RoutedEventArgs e)
  48. {
  49. Button bt = (Button)sender;
  50. string day = bt.Content.ToString();
  51. int monthN = giveMonthNum(aMonth.Text.Split(' ')[0]);
  52. string month;
  53. if (int.Parse(day) < 10)
  54. {
  55. day = "0" + day;
  56. }
  57. if (monthN < 10)
  58. {
  59. month = "0" + monthN;
  60. }
  61. else
  62. {
  63. month = "" + monthN;
  64. }
  65. string dataheader = day + "." + month + "." + int.Parse(aMonth.Text.Split(' ')[1]);
  66. changeEventDescription(dataheader);
  67. //MessageBox.Show((sender as Button).Name);//отображение названия кнопки
  68. }
  69. private void loadedCalendar()
  70. {
  71. string dateNow = DateTime.Now.ToString(); //получение сегодняшней даты
  72. string yearNow = (dateNow.Split(' ')[0]).Split('.')[2];
  73. aMonth.Text = giveMonthName(int.Parse(dateNow.Split('.')[1])) + yearNow;
  74. int countDay = DateTime.DaysInMonth(int.Parse(yearNow), int.Parse(dateNow.Split('.')[1])); // количество дней в месяце
  75. int day = (int)DateTime.Parse("01." + (dateNow.Split('.')[1]) + "." + yearNow).DayOfWeek;
  76. if (day == 0)
  77. {
  78. day = 7;
  79. }
  80. nullValueButton();
  81. writeValueButton(countDay, day);
  82. }
  83. private void bRight_Click(object sender, RoutedEventArgs e)
  84. {
  85. string month = aMonth.Text.Split(' ')[0];
  86. int year = int.Parse(aMonth.Text.Split(' ')[1]);
  87. int numMonth = giveMonthNum(month);
  88. if (numMonth == 12)
  89. {
  90. year++;
  91. numMonth = 1;
  92. }
  93. else
  94. {
  95. numMonth++;
  96. }
  97. aMonth.Text = giveMonthName(numMonth) + year;
  98. nullValueButton();
  99. int countDay = DateTime.DaysInMonth(year, numMonth); // количество дней в месяце
  100. int day = (int)DateTime.Parse("01." + numMonth + "." + year).DayOfWeek;
  101. if (day == 0)
  102. {
  103. day = 7;
  104. }
  105. writeValueButton(countDay, day);
  106. nullColorDate();
  107. loadedColorData();
  108. }
  109. private void bLeft_Click(object sender, RoutedEventArgs e)
  110. {
  111. string month = aMonth.Text.Split(' ')[0];
  112. int year = int.Parse(aMonth.Text.Split(' ')[1]);
  113. int numMonth = giveMonthNum(month);
  114. if (numMonth == 1)
  115. {
  116. year--;
  117. numMonth = 12;
  118. }
  119. else
  120. {
  121. numMonth--;
  122. }
  123. aMonth.Text = giveMonthName(numMonth) + year;
  124. nullValueButton();
  125. int countDay = DateTime.DaysInMonth(year, numMonth); // количество дней в месяце
  126. int day = (int)DateTime.Parse("01." + numMonth + "." + year).DayOfWeek;
  127. if (day == 0)
  128. {
  129. day = 7;
  130. }
  131. writeValueButton(countDay, day);
  132. nullColorDate();
  133. loadedColorData();
  134. }
  135. private void nullValueButton()
  136. {
  137. for (int i = 0; i < 6; i++)
  138. {
  139. for (int j = 1; j < 8; j++)
  140. {
  141. string nameButton = "b" + i + j;
  142. changeContentButton(nameButton, "", false);
  143. }
  144. }
  145. }
  146. private void writeValueButton(int countDay, int day)
  147. {
  148. int week = 0;
  149. int num = 1;
  150. try
  151. {
  152. while (countDay > num)
  153. {
  154. for (int j = day; j <= 7; j++)
  155. {
  156. string nameButton = "b" + week + j;
  157. changeContentButton(nameButton, Convert.ToString(num), true);
  158. if (num < countDay)
  159. {
  160. num++;
  161. }
  162. else
  163. {
  164. break;
  165. }
  166. }
  167. day = 1;
  168. if (week > 5)
  169. {
  170. break;
  171. }
  172. else
  173. {
  174. week++;
  175. }
  176. }
  177. }
  178. catch (Exception ex)
  179. {
  180. MessageBox.Show(ex.Message);
  181. }
  182. }
  183. private void changeContentButton(string name, string value, bool flag)
  184. {
  185. Button bt = (Button)this.FindName(name);
  186. bt.Content = value;
  187. if (flag)
  188. {
  189. bt.Visibility = Visibility.Visible;
  190. }
  191. else
  192. {
  193. bt.Visibility = Visibility.Hidden;
  194. }
  195. }
  196. private string giveMonthName(int num)
  197. {
  198. string nameMonth = "";
  199. switch (num) //выбор месяца
  200. {
  201. case (1):
  202. nameMonth = "Январь ";
  203. break;
  204. case (2):
  205. nameMonth = "Февраль ";
  206. break;
  207. case (3):
  208. nameMonth = "Март ";
  209. break;
  210. case (4):
  211. nameMonth = "Апрель ";
  212. break;
  213. case (5):
  214. nameMonth = "Май ";
  215. break;
  216. case (6):
  217. nameMonth = "Июнь ";
  218. break;
  219. case (7):
  220. nameMonth = "Июль ";
  221. break;
  222. case (8):
  223. nameMonth = "Август ";
  224. break;
  225. case (9):
  226. nameMonth = "Сентябрь ";
  227. break;
  228. case (10):
  229. nameMonth = "Октябрь ";
  230. break;
  231. case (11):
  232. nameMonth = "Ноябрь ";
  233. break;
  234. case (12):
  235. nameMonth = "Декабрь ";
  236. break;
  237. }
  238. return nameMonth;
  239. }
  240. private int giveMonthNum(string name)
  241. {
  242. switch (name)
  243. {
  244. case ("Январь"):
  245. return 1;
  246. case ("Февраль"):
  247. return 2;
  248. case ("Март"):
  249. return 3;
  250. case ("Апрель"):
  251. return 4;
  252. case ("Май"):
  253. return 5;
  254. case ("Июнь"):
  255. return 6;
  256. case ("Июль"):
  257. return 7;
  258. case ("Август"):
  259. return 8;
  260. case ("Сентябрь"):
  261. return 9;
  262. case ("Октябрь"):
  263. return 10;
  264. case ("Ноябрь"):
  265. return 11;
  266. case ("Декабрь"):
  267. return 12;
  268. default:
  269. return 0;
  270. }
  271. }
  272. /// <summary>
  273. /// новый код !!!
  274. /// </summary>
  275. List<DataTimeEvent> dataTime = new List<DataTimeEvent>();
  276. private void loadedData()
  277. {
  278. //цикл с загрузкой даты и ее описания
  279. dataTime.Add(new DataTimeEvent { Data = "15.05.2023", Time = "15:00", Name = "Proba 1", Theme = "Proba 1", Description = "Proba 1" });
  280. dataTime.Add(new DataTimeEvent { Data = "25.05.2023", Time = "15:00", Name = "Proba 2", Theme = "Proba 2", Description = "Proba 2" });
  281. dataTime.Add(new DataTimeEvent { Data = "10.04.2023", Time = "15:00", Name = "Proba 3", Theme = "Proba 3", Description = "Proba 3" });
  282. dataTime.Add(new DataTimeEvent { Data = "28.06.2023", Time = "15:00", Name = "Proba 4", Theme = "Proba 4", Description = "Proba 4" });
  283. dataTime.Add(new DataTimeEvent { Data = "02.06.2023", Time = "15:00", Name = "Proba 5", Theme = "Proba 5", Description = "Proba 5" });
  284. }
  285. Color Green = (Color)ColorConverter.ConvertFromString("#D3DB94");
  286. Color Yellow = (Color)ColorConverter.ConvertFromString("#FAEDCD");
  287. Color Brown = (Color)ColorConverter.ConvertFromString("#A77748");
  288. private void loadedColorData()
  289. {
  290. foreach (DataTimeEvent date in dataTime)
  291. {
  292. //string[] line = date.Data.Split('.');
  293. if (aMonth.Text == giveMonthName(int.Parse(date.Data.Split('.')[1])) + date.Data.Split('.')[2])
  294. {
  295. for (int i = 1; i < 8; i++)
  296. {
  297. for (int j = 0; j < 6; j++)
  298. {
  299. string name = "b" + j + i;
  300. Button bt = (Button)this.FindName(name);
  301. string contentButton = bt.Content.ToString().Replace('b', ' ').Trim();
  302. string locDate = date.Data.Split('.')[0];
  303. if (locDate[0] == '0')
  304. {
  305. locDate = locDate.Replace("0", "");
  306. }
  307. if (contentButton == locDate)
  308. {
  309. try
  310. {
  311. colorRectangle(Green, name);
  312. }
  313. catch (Exception ex)
  314. {
  315. MessageBox.Show(ex.Message);
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. private void nullColorDate()
  324. {
  325. for (int i = 1; i < 8; i++)
  326. {
  327. for (int j = 0; j < 6; j++)
  328. {
  329. string name = "b" + j + i;
  330. colorRectangle(Yellow, name);
  331. }
  332. }
  333. }
  334. private void colorRectangle(Color colorName, string name)
  335. {
  336. Button bt = (Button)this.FindName(name);
  337. bt.Background = new SolidColorBrush(colorName);
  338. }
  339. private void changeEventDescription(string dateHeader)
  340. {
  341. noColorTextBlock();
  342. string header;
  343. bool flag = true;
  344. if (dateHeader == DateTime.Now.ToString().Split(':')[0])
  345. {
  346. header = "Сегодня";
  347. }
  348. else
  349. {
  350. header = dateHeader;
  351. }
  352. foreach (DataTimeEvent data in dataTime)
  353. {
  354. if (data.Data == dateHeader)
  355. {
  356. header += " в " + data.Time;
  357. aData.Text = header;
  358. aName.Text = data.Name;
  359. aDescript.Text = data.Description;
  360. aTheme.Text = data.Theme;
  361. aData.Visibility = Visibility.Visible;
  362. aName0.Visibility = Visibility.Visible;
  363. aTheme0.Visibility = Visibility.Visible;
  364. aDescript0.Visibility = Visibility.Visible;
  365. aName.Visibility = Visibility.Visible;
  366. aTheme.Visibility = Visibility.Visible;
  367. aDescript.Visibility = Visibility.Visible;
  368. if (DateTime.Parse(dateHeader) <= DateTime.Parse(DateTime.Now.ToString().Split(' ')[0]))
  369. {
  370. bReg.Visibility = Visibility.Hidden;
  371. }
  372. else
  373. {
  374. bReg.Visibility = Visibility.Visible;
  375. }
  376. flag = false;
  377. break;
  378. }
  379. }
  380. if (flag)
  381. {
  382. aData.Text = header;
  383. aData.Visibility = Visibility.Visible;
  384. aNoEvent.Visibility = Visibility.Visible;
  385. bReg.Visibility = Visibility.Hidden;
  386. }
  387. }
  388. private void noColorTextBlock()
  389. {
  390. aName0.Visibility = Visibility.Hidden;
  391. aTheme0.Visibility = Visibility.Hidden;
  392. aDescript0.Visibility = Visibility.Hidden;
  393. aData.Visibility = Visibility.Hidden;
  394. aName.Visibility = Visibility.Hidden;
  395. aTheme.Visibility = Visibility.Hidden;
  396. aDescript.Visibility = Visibility.Hidden;
  397. aNoEvent.Visibility = Visibility.Hidden;
  398. bReg.Visibility = Visibility.Hidden;
  399. }
  400. }
  401. }