private void AddEvent(System.DateTime eventToAdd)
        {
            Model.Event ev = new Model.Event()
            {
                StartEvent = eventToAdd,
                EndEvent = eventToAdd.AddMinutes(1.0)
            };

            Model.Event overlappedEvent = OverlappedWithExistingEvent(ev, scheduler.Events.ToList());
            if (overlappedEvent != null)
            {
                MessageBox.Show(string.Format("No se puede agendar una cita a las {0} hrs."
                                    +"\nExiste una cita para el tratamiento de '{1}' que inicia a las {2} hrs"
                                    + " y termina a las {3} hrs.",
                                    eventToAdd.ToString("HH:mm"),
                                    overlappedEvent.Treatment.Name,
                                    overlappedEvent.StartEvent.ToString("HH:mm"),
                                    overlappedEvent.EndEvent.ToString("HH:mm")), 
                                "Advertencia", 
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);
                return;
            }
                
            new AddEventModal(scheduler, eventToAdd, _userLoggedIn).ShowDialog();   
        }
Ejemplo n.º 2
0
            route.Entrys.Add(e1);
            e1 = new Entry(EntryType.OPS_MARKER, "89,5", "", "", "Nohfelden Hp", "", "", c, "", c);
            route.Entrys.Add(e1);
            //e1 = new Entry(EntryType.OPS_MARKER, "88,1", "100", "", "", "", "", c, "", c);
            //route.Entrys.Add(e1);
        }

        public bool MoveViaTime(System.DateTime vtime, int verspaetung)
        {
            bool retval = false;
            if (route.Position < 0) return retval;

            System.DateTime mtime = vtime.AddMinutes(-verspaetung);

            System.DateTime date = new DateTime(1);

            for(int i = 0; i < route.Entrys.Count-1; i++)
            {
                // fetch the current position with time
                if (i < (int)route.Position) continue;
                Entry e = (Entry)route.Entrys[i];

                if (e.m_eta == "" && e.m_etd == "")
                {
                    // move backwards to find the last entry with time

                    for (int j = i; j > -1; j--)
                    {
                        e = (Entry)route.Entrys[j];
                        if (e.m_eta != "" || e.m_etd != "")
                            break;
                    }
                }

                // prefer the Depature Time
                if (e.m_etd != "")
                {
                    date = DateTime.Parse(vtime.Date.ToShortDateString() +" "+ e.m_etd);
                }
                else
                {
                    date = DateTime.Parse(vtime.Date.ToShortDateString() +" "+ e.m_eta);
                }

                long add = long.MaxValue, time_diff = long.MaxValue;

                Entry e_next = null;

                for (int k = i+1; k < route.Entrys.Count - 2; k++)
                {
                    // fetch the next value with time
                    DateTime date_next = new DateTime(0);
                    e_next = (Entry)route.Entrys[k];

                    if (e_next.m_eta != "" || e_next.m_etd != "")
                    {
                        // Time is given
                        // prefer the Arrival Time
                        if (e_next.m_eta != "")
                        {
                            date_next = DateTime.Parse(vtime.Date.ToShortDateString() +" "+ e_next.m_eta);
                        }
                        else
                        {
                            date_next = DateTime.Parse(vtime.Date.ToShortDateString() +" "+ e_next.m_etd);

                        }
                    }
                    else
                        continue;

                    // calculate half of the distance between
                    // this time and the next one
                    add = (date_next.Ticks - date.Ticks) / 2;
                    //Console.WriteLine("ADD:"+add.ToString());
                    break;
                }

                for (int k = i+1; k < route.Entrys.Count - 2; k++)
                {
                    if (e_next == null) break;
                    // fetch the next value with time
                    DateTime date_next = new DateTime(0);
                    Entry e_next_pos = (Entry)route.Entrys[k];

                    if ((e_next_pos.m_eta != "" || e_next_pos.m_etd != "") &&
                        (e_next.m_eta != "" || e_next.m_etd != "")
                        )
                        break;

                    double frac;

                    if (e_next_pos.m_eta == "" && e_next_pos.m_etd == "" && e_next_pos.m_position != "" && e_next_pos.m_position != "")
                    {
                        //continue;
                        // Only position is given
                        float pos_here = Convert.ToSingle(e.m_position.Replace(",","."));
                        float pos_next = Convert.ToSingle(e_next_pos.m_position.Replace(",","."));
                        float pos_diff = Math.Abs(pos_here - pos_next);

                        float pos_next_time = Convert.ToSingle(e_next.m_position.Replace(",","."));
                        float pos_diff_time = Math.Abs(pos_here - pos_next_time);

                        frac = pos_diff / pos_diff_time;
                    }
                    else
                        continue;

                    try
                    {
                        time_diff = Convert.ToInt64((double)add * 2 * frac);
                    }
                    catch(Exception)
                    {
                        time_diff = long.MaxValue;
                    }
                    break;
                }

                // calculate the time between this entry
                // and the current time and
                // move to the next entry when half of
                // the difference between them is over
                long diff;
                try
                {
                    if (time_diff == long.MaxValue)
                    {
                        diff = date.Ticks - mtime.Ticks + add;
                        if (diff < 0)
                        {
                            NextEntry();
                            retval = true;
                        }
                    }
                    else
                    {
                        diff = date.Ticks - mtime.Ticks + time_diff;
                        if (diff < 0)
                        {
                            NextEntry(false);
                            retval = true;
                        }
                    }