wWorkerMain.xaml.cs 15 KB

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