Ejemplo n.º 1
0
        public int RetornarDiasNutil(int dias)
        {
            string   data        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            DateTime Inicio      = Convert.ToDateTime(data);
            int      dias_nuteis = 0;

            while (dias_nuteis <= dias)
            {
                if (Inicio.DayOfWeek == DayOfWeek.Saturday || Inicio.DayOfWeek == DayOfWeek.Sunday)
                {
                    dias_nuteis++;

                    var calendar = new Indigo_Calendario();
                    calendar.id_data = Inicio.Day;
                    calendar.data    = Inicio;
                    dataInterface.Calendario(calendar);
                }
                else
                {
                    dias--;
                }

                Inicio = Inicio.AddDays(1);
            }

            return(dias_nuteis);
        }
Ejemplo n.º 2
0
 public void Calendario(Indigo_Calendario calendario)
 {
     try
     {
         var context = new Indigo_Controle_Licenca();
         context.Indigo_Calendario.AddOrUpdate(calendario);
         context.SaveChanges();
     }
     catch (Exception) { }
 }
Ejemplo n.º 3
0
        public int DiasUteis()
        {
            UserCredential credential;

            string path = Server.MapPath(@"~/Scripts/Google/").ToString();

            using (var stream =
                       new FileStream(path + "client_secret.json", FileMode.Open, FileAccess.Read))
            {
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "Check-in-out",
                    CancellationToken.None,
                    new FileDataStore(path, true)).Result;
            }


            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("en.brazilian#[email protected]");
            //request.TimeMin = DateTime.Now;
            request.ShowDeleted  = false;
            request.SingleEvents = true;
            request.MaxResults   = 100;
            request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;
            request.TimeZone     = "America/Sao_Paulo";

            // List events.
            Events events = new Events();

            events = request.Execute();

            List <string> h = new List <string>();

            if (events.Items != null && events.Items.Count > 0)
            {
                foreach (var eventItem in events.Items)
                {
                    if (eventItem.Start.Date.ToString().Contains(DateTime.Now.ToString("yyyy-MM")))
                    {
                        h.Add(eventItem.Description);

                        DateTime data = Convert.ToDateTime(eventItem.Start.Date);

                        if (data.Day == 1)
                        {
                            var calendar = new Indigo_Calendario();
                            calendar.id_data = data.Day;
                            calendar.data    = Convert.ToDateTime(eventItem.Start.Date);
                            dataInterface.Calendario(calendar);
                        }
                    }
                }
            }

            int dias       = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
            int dias_uteis = 0;


            dias_uteis = dias - RetornarDiasNutil(dias);

            var calendario = new Indigo_ConfigCalendario();

            calendario.id_qt          = 1;
            calendario.qt_diaUtil     = dias_uteis;
            calendario.qt_diaFeriado  = h.Count;
            calendario.qt_FimDeSemana = dias - dias_uteis;
            calendario.qt_targetTotal = (dias_uteis - h.Count()) * 8;

            dataInterface.ConfigCalendario(calendario);

            return(dias_uteis - h.Count());
        }