예제 #1
0
        async Task ExecuteLoadVacationsCalendar()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var lista = await Service_Calendar.GetAllExpiredVacations();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    IsBusy = false;
                });
            }
        }
예제 #2
0
        public async void CreateAlertDate()
        {
            Button[] btn = new Button[31];

            //getting First Day and Last Day---------------------------------------

            DateTime startOfMonth = new DateTime(Convert.ToInt32(SelectedYear), SelectedMonthInt, 1);                                                                   //new DateTime(year, month, 1);

            DateTime endOfMonth = new DateTime(Convert.ToInt32(SelectedYear), SelectedMonthInt, DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), SelectedMonthInt)); //new DateTime(year, month, DateTime.DaysInMonth(year, month));

            // DateTime dtSelectedDate = DateTime.Now;
            string dtFirstDayOfMonth = startOfMonth.ToString("ddd");
            string dtLastDayOfMonth  = endOfMonth.ToString("ddd");

            int day = (int)startOfMonth.DayOfWeek;

            gridCalendar.Children.Clear();
            CreateGridCalendar();

            var lista = await Service_Calendar.GetAllExpiredVacations();

            AlertDates = new ObservableCollection <ExpiredVacations>(lista);

            var alertDatesToCreate = new List <DateTime>();

            foreach (var it in lista)
            {
                foreach (var d in it.ExpiringDates)
                {
                    if (d.Year == SelectedYear && d.Month == SelectedMonthInt)
                    {
                        alertDatesToCreate.Add(d);
                    }
                }
            }

            for (int i = startOfMonth.Day; i <= endOfMonth.Day; i++)
            {
                foreach (var d in alertDatesToCreate)
                {
                    if (SelectedYear == d.Year &&
                        SelectedMonthInt == d.Month &&
                        i == Convert.ToInt32(d.Day))
                    {
                        btn[i - 1] = new Button()
                        {
                            Text            = i.ToString(),
                            FontSize        = 12,
                            FontAttributes  = FontAttributes.Bold,
                            BackgroundColor = Color.White,
                            TextColor       = Color.Red
                        };
                        btn[i - 1].Clicked += Calendar_Clicked;
                    }
                    else
                    {
                        btn[i - 1] = new Button()
                        {
                            Text            = i.ToString(),
                            FontSize        = 12,
                            FontAttributes  = FontAttributes.None,
                            BackgroundColor = Color.Transparent,
                            TextColor       = Color.Black
                        };
                        btn[i - 1].Clicked += Calendar_Clicked;
                    }
                }
                if (btn[i - 1] == null)
                {
                    btn[i - 1] = new Button()
                    {
                        Text            = i.ToString(),
                        FontSize        = 12,
                        FontAttributes  = FontAttributes.None,
                        BackgroundColor = Color.Transparent,
                        TextColor       = Color.Black
                    };
                    btn[i - 1].Clicked += Calendar_Clicked;
                }
            }

            int r = 3;
            int c = 0;

            if (day == 1)
            {
                c = 1;
            }
            else if (day == 2)
            {
                c = 3;
            }
            else if (day == 3)
            {
                c = 5;
            }
            else if (day == 4)
            {
                c = 7;
            }
            else if (day == 5)
            {
                c = 9;
            }
            else if (day == 6)
            {
                c = 11;
            }
            else
            {
                c = 13;
            }


            int m = 1;

            // adding button to gridview

            for (int k = 1; k <= 7; k++)
            {
                for (int j = 1; j <= 7; j = j + 1)
                {
                    if (m > endOfMonth.Day)
                    {
                        break;
                    }
                    else
                    {
                        gridCalendar.Children.Add(btn[m - 1], c, r);
                        c = c + 2;
                        m++;

                        if (c == 15)
                        {
                            break;
                        }
                    }
                }
                c = 1;
                r = r + 2;
            }
            overlay.IsVisible = false;
        }