コード例 #1
0
    void InitializeScheduleTime()
    {
        var dayOfWeek = (int)DataManager.dateNewAppointment.DayOfWeek;

        limit = DataManager.currentResponsible.timeToFinishWork [dayOfWeek];
        begin = DataManager.currentResponsible.timeToBeginWork [dayOfWeek];
        List <AppointmentModel> appointmentList = new List <AppointmentModel> ();
        var         isOneInOneHour     = PlayerPreferences.oneInOneHour;
        int         index              = 0;
        bool        isResponsible      = false;
        var         newAppointmentDate = new DateTime(appointmentYear, appointmentMonth, appointmentDay);
        CultureInfo provider           = new CultureInfo("pt-BR");

        if (DataManager.currentResponsible.userID == DataManager.currentUser.userID)
        {
            isResponsible = true;
        }

        DataManager.responsibleAppointmentList.ForEach(x => {
            if (DateTime.ParseExact(x.data, Constants.dateformat, provider) == newAppointmentDate)
            {
                appointmentList.Add(x);
            }
        });

        if (appointmentList != null)
        {
            appointmentList.Sort((first, second) => ((new DateTime(appointmentYear, appointmentMonth, appointmentDay, first.hour, first.minute, 0)).CompareTo((new DateTime(appointmentYear, appointmentMonth, appointmentDay, second.hour, second.minute, 0)))));
        }

        if (!isOneInOneHour)
        {
            limit = (limit - begin) * 2;
        }
        var into = false;

        for (var i = 0; i < limit; i++)
        {
            if (appointmentList != null && index < appointmentList.Count)
            {
                var initAppointmentDateTime   = (new DateTime(appointmentYear, appointmentMonth, appointmentDay, appointmentList [index].hour, appointmentList [index].minute, 0));
                var finishAppointmentDateTime = (new DateTime(appointmentYear, appointmentMonth, appointmentDay, appointmentList [index].hour, appointmentList [index].minute, 0)).AddMinutes(appointmentList [index].durationInMinutes);

                if (into)
                {
                    if (finishAppointmentDateTime.CompareTo(dt) > 0)
                    {
                        var description = "";
                        if (isResponsible)
                        {
                            description = appointmentList [index].userName;
                        }
                        else
                        {
                            description = "Ocupado";
                        }
                        var cell = DayController.Instantiate(cellPrefabTransform, dt.Hour.ToString() + ":" + dt.Minute.ToString("00"), description, false);
                        cell.GetComponent <Button> ().interactable = false;
                        cellList.Add(cell);
                        into = true;
                        dt   = dt.AddMinutes(isOneInOneHour ? 60 : 30);
                    }
                    else
                    {
                        into = false;
                        limit++;
                        index++;
                    }
                }
                else
                {
                    if (initAppointmentDateTime.CompareTo(dt) == 0)
                    {
                        var description = "";
                        if (isResponsible)
                        {
                            description = appointmentList [index].userName;
                        }
                        else
                        {
                            description = "Ocupado";
                        }
                        var cell = DayController.Instantiate(cellPrefabTransform, dt.Hour.ToString() + ":" + dt.Minute.ToString("00"), description, false);
                        cell.GetComponent <Button> ().interactable = false;
                        cellList.Add(cell);
                        into = true;
                    }
                    else
                    {
                        cellList.Add(DayController.Instantiate(cellPrefabTransform, dt.Hour.ToString() + ":" + dt.Minute.ToString("00"), "Livre"));
                    }
                    dt = dt.AddMinutes(isOneInOneHour ? 60 : 30);
                }
            }
            else
            {
                cellList.Add(DayController.Instantiate(cellPrefabTransform, dt.Hour.ToString() + ":" + dt.Minute.ToString("00"), "Livre"));
                dt = dt.AddMinutes(isOneInOneHour ? 60 : 30);
            }
        }
    }