123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using teaTime.class_es;
- using TeaTime;
- namespace teaTime
- {
- /// <summary>
- /// Логика взаимодействия для wWorkerMain.xaml
- /// </summary>
- public partial class wWorkerMain : Page
- {
- Worker worker = new Worker();
- public wWorkerMain(Worker user)
- {
- InitializeComponent();
- worker = user;
- loadedCalendar();
- loadedData();
- loadedColorData();
- changeEventDescription(DateTime.Now.ToString().Split(' ')[0]);
- }
- private void bRead_Click(object sender, RoutedEventArgs e)
- {
- NavigationService.Navigate(new wEventSee(new DataTimeEvent
- {
- Data = aData.Text.Split(' ')[0],
- Time = aData.Text.Split(' ')[2],
- Name = aName.Text,
- Theme = aTheme.Text,
- Description = aDescript.Text
- }), worker);
- }
- private void bwrite_Click(object sender, RoutedEventArgs e)
- {
- NavigationService.Navigate(new wEventAdd((DateTime.Parse(aData.Text)), worker));
- }
- private void bUserProfile_Click(object sender, RoutedEventArgs e)
- {
- NavigationService.Navigate(new wWorkerUserPrifile(worker));
- }
- private void b_Click(object sender, RoutedEventArgs e)
- {
- Button bt = (Button)sender;
- string day = bt.Content.ToString();
- int monthN = giveMonthNum(aMonth.Text.Split(' ')[0]);
- string month;
- if (int.Parse(day) < 10)
- {
- day = "0" + day;
- }
- if (monthN < 10)
- {
- month = "0" + monthN;
- }
- else
- {
- month = "" + monthN;
- }
- string dataheader = day + "." + month + "." + int.Parse(aMonth.Text.Split(' ')[1]);
- changeEventDescription(dataheader);
- }
- private void loadedCalendar()
- {
- string dateNow = DateTime.Now.ToString(); //получение сегодняшней даты
- string yearNow = (dateNow.Split(' ')[0]).Split('.')[2];
- aMonth.Text = giveMonthName(int.Parse(dateNow.Split('.')[1])) + yearNow;
- int countDay = DateTime.DaysInMonth(int.Parse(yearNow), int.Parse(dateNow.Split('.')[1])); // количество дней в месяце
- int day = (int)DateTime.Parse("01." + (dateNow.Split('.')[1]) + "." + yearNow).DayOfWeek;
- if (day == 0)
- {
- day = 7;
- }
- nullValueButton();
- writeValueButton(countDay, day);
- }
- private void bRight_Click(object sender, RoutedEventArgs e)
- {
- string month = aMonth.Text.Split(' ')[0];
- int year = int.Parse(aMonth.Text.Split(' ')[1]);
- int numMonth = giveMonthNum(month);
- if (numMonth == 12)
- {
- year++;
- numMonth = 1;
- }
- else
- {
- numMonth++;
- }
- aMonth.Text = giveMonthName(numMonth) + year;
- nullValueButton();
- int countDay = DateTime.DaysInMonth(year, numMonth); // количество дней в месяце
- int day = (int)DateTime.Parse("01." + numMonth + "." + year).DayOfWeek;
- if (day == 0)
- {
- day = 7;
- }
- writeValueButton(countDay, day);
- nullColorDate();
- loadedColorData();
- }
- private void bLeft_Click(object sender, RoutedEventArgs e)
- {
- string month = aMonth.Text.Split(' ')[0];
- int year = int.Parse(aMonth.Text.Split(' ')[1]);
- int numMonth = giveMonthNum(month);
- if (numMonth == 1)
- {
- year--;
- numMonth = 12;
- }
- else
- {
- numMonth--;
- }
- aMonth.Text = giveMonthName(numMonth) + year;
- nullValueButton();
- int countDay = DateTime.DaysInMonth(year, numMonth); // количество дней в месяце
- int day = (int)DateTime.Parse("01." + numMonth + "." + year).DayOfWeek;
- if (day == 0)
- {
- day = 7;
- }
- writeValueButton(countDay, day);
- nullColorDate();
- loadedColorData();
- }
- private void nullValueButton()
- {
- for (int i = 0; i < 6; i++)
- {
- for (int j = 1; j < 8; j++)
- {
- string nameButton = "b" + i + j;
- changeContentButton(nameButton, "", false);
- }
- }
- }
- private void writeValueButton(int countDay, int day)
- {
- int week = 0;
- int num = 1;
- try
- {
- while (countDay > num)
- {
- for (int j = day; j <= 7; j++)
- {
- string nameButton = "b" + week + j;
- changeContentButton(nameButton, Convert.ToString(num), true);
- if (num < countDay)
- {
- num++;
- }
- else
- {
- break;
- }
- }
- day = 1;
- if (week > 5)
- {
- break;
- }
- else
- {
- week++;
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void changeContentButton(string name, string value, bool flag)
- {
- Button bt = (Button)this.FindName(name);
- bt.Content = value;
- if (flag)
- {
- bt.Visibility = Visibility.Visible;
- }
- else
- {
- bt.Visibility = Visibility.Hidden;
- }
- }
- private string giveMonthName(int num)
- {
- string nameMonth = "";
- switch (num) //выбор месяца
- {
- case (1):
- nameMonth = "Январь ";
- break;
- case (2):
- nameMonth = "Февраль ";
- break;
- case (3):
- nameMonth = "Март ";
- break;
- case (4):
- nameMonth = "Апрель ";
- break;
- case (5):
- nameMonth = "Май ";
- break;
- case (6):
- nameMonth = "Июнь ";
- break;
- case (7):
- nameMonth = "Июль ";
- break;
- case (8):
- nameMonth = "Август ";
- break;
- case (9):
- nameMonth = "Сентябрь ";
- break;
- case (10):
- nameMonth = "Октябрь ";
- break;
- case (11):
- nameMonth = "Ноябрь ";
- break;
- case (12):
- nameMonth = "Декабрь ";
- break;
- }
- return nameMonth;
- }
- private int giveMonthNum(string name)
- {
- switch (name)
- {
- case ("Январь"):
- return 1;
- case ("Февраль"):
- return 2;
- case ("Март"):
- return 3;
- case ("Апрель"):
- return 4;
- case ("Май"):
- return 5;
- case ("Июнь"):
- return 6;
- case ("Июль"):
- return 7;
- case ("Август"):
- return 8;
- case ("Сентябрь"):
- return 9;
- case ("Октябрь"):
- return 10;
- case ("Ноябрь"):
- return 11;
- case ("Декабрь"):
- return 12;
- default:
- return 0;
- }
- }
- List<DataTimeEvent> dataTime = new List<DataTimeEvent>();
- private void loadedData()
- {
- //цикл с загрузкой даты и ее описания
- using (KotkovaISazonovaEntities_ DB = new KotkovaISazonovaEntities_())
- {
- dataTime = Converter(DB.Event.ToList());
- }
- }
- public List<DataTimeEvent> Converter(List<Event> List)
- {
- List<DataTimeEvent> dataTimeEvents = new List<DataTimeEvent>();
- for (int i = 0; i < List.Count; i++)
- {
- dataTimeEvents.Add(new DataTimeEvent
- {
- Data = Convert.ToString(List[i].date).Split(' ')[0],
- Time = Convert.ToString(List[i].time).Split(':')[0] + ":" + Convert.ToString(List[i].time).Split(':')[1],
- Name = List[i].name,
- Description = List[i].description,
- Theme = List[i].theme
- });
- }
- return dataTimeEvents;
- }
- Color Green = (Color)ColorConverter.ConvertFromString("#D3DB94");
- Color Yellow = (Color)ColorConverter.ConvertFromString("#FAEDCD");
- Color Brown = (Color)ColorConverter.ConvertFromString("#A77748");
- private void loadedColorData()
- {
- foreach (DataTimeEvent date in dataTime)
- {
- //string[] line = date.Data.Split('.');
- if (aMonth.Text == giveMonthName(int.Parse(date.Data.Split('.')[1])) + date.Data.Split('.')[2])
- {
- for (int i = 1; i < 8; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- string name = "b" + j + i;
- Button bt = (Button)this.FindName(name);
- string contentButton = bt.Content.ToString().Replace('b', ' ').Trim();
- string locDate = date.Data.Split('.')[0];
- if (locDate[0] == '0')
- {
- locDate = locDate.Replace("0", "");
- }
- if (contentButton == locDate)
- {
- try
- {
- colorRectangle(Green, name);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
- }
- }
- }
- private void nullColorDate()
- {
- for (int i = 1; i < 8; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- string name = "b" + j + i;
- colorRectangle(Yellow, name);
- }
- }
- }
- private void colorRectangle(Color colorName, string name)
- {
- Button bt = (Button)this.FindName(name);
- bt.Background = new SolidColorBrush(colorName);
- }
- private void changeEventDescription(string dateHeader)
- {
- noColorTextBlock();
- string header;
- bool flag = true;
- if (dateHeader == DateTime.Now.ToString().Split(':')[0])
- {
- header = "Сегодня";
- }
- else
- {
- header = dateHeader;
- }
- foreach (DataTimeEvent data in dataTime)
- {
- if (data.Data == dateHeader)
- {
- header += " в " + data.Time;
- aData.Text = header;
- aName.Text = data.Name;
- aDescript.Text = data.Description;
- aTheme.Text = data.Theme;
- aData.Visibility = Visibility.Visible;
- aName0.Visibility = Visibility.Visible;
- aTheme0.Visibility = Visibility.Visible;
- aDescript0.Visibility = Visibility.Visible;
- aName.Visibility = Visibility.Visible;
- aTheme.Visibility = Visibility.Visible;
- aDescript.Visibility = Visibility.Visible;
- bRead.Visibility = Visibility.Visible;
- bWrite.Visibility = Visibility.Hidden;
- flag = false;
- break;
- }
- }
- if (flag)
- {
- aData.Text = header;
- aData.Visibility = Visibility.Visible;
- aNoEvent.Visibility = Visibility.Visible;
- bRead.Visibility = Visibility.Hidden;
- if (DateTime.Parse(dateHeader) <= DateTime.Parse(DateTime.Now.ToString().Split(' ')[0]))
- {
- bWrite.Visibility = Visibility.Hidden;
- }
- else
- {
- bWrite.Visibility = Visibility.Visible;
- }
- }
- }
- private void noColorTextBlock()
- {
- aName0.Visibility = Visibility.Hidden;
- aTheme0.Visibility = Visibility.Hidden;
- aDescript0.Visibility = Visibility.Hidden;
- aData.Visibility = Visibility.Hidden;
- aName.Visibility = Visibility.Hidden;
- aTheme.Visibility = Visibility.Hidden;
- aDescript.Visibility = Visibility.Hidden;
- aNoEvent.Visibility = Visibility.Hidden;
- bWrite.Visibility = Visibility.Hidden;
- bRead.Visibility = Visibility.Hidden;
- }
- }
- }
|