Exemple #1
0
        public Event(InputEventItem InEv, DateTime CurDate) : this(InEv.Name, InEv.Category, InEv.Status, InEv.Memo)
        {
            if (Event.LastId != 0)
            {
                this.Id = "E" + String.Format("{0:D7}", ++LastId);
            }

            DateTime date = CurDate;

            if (!String.IsNullOrEmpty(InEv.Date))
            {
                date = UltilityConvert.ToDate(InEv.Date);
            }
            Items.Add(new EventItem(InEv, date));
        }
Exemple #2
0
        public void Save(List <InputEventItem> CurEvs, DateTime CurDate)
        {
            foreach (var itr in CurEvs)
            {
                DateTime date;
                if (itr.Date == null)
                {
                    date = CurDate;
                }
                else
                {
                    date = UltilityConvert.ToDate(itr.Date);
                }
                double time = UltilityConvert.ToDoble(itr.Time);
                if (String.IsNullOrEmpty(itr.Status))
                {
                    itr.Status = "Current";
                }
                //event exist check
                bool isFound   = false;
                bool mergeFlag = false;
                foreach (var ev in this.Items)
                {
                    if (ev.Name == itr.Name)
                    {
                        if (String.IsNullOrEmpty(ev.Category))
                        {
                            ev.Category = itr.Category;
                            mergeFlag   = true;
                        }
                        if (ev.Category != itr.Category)
                        {
                            continue;
                        }

                        isFound = true;
                        if (ev.Status != itr.Status)
                        {
                            ev.Status = itr.Status;
                        }
                        bool isFoundItem = false;
                        foreach (var item in ev.Items)
                        {
                            if (item.Date == date)
                            {
                                isFoundItem = true;
                                if (time == -1.0)
                                {
                                    ev.Items.Remove(item);
                                    break;
                                }
                                else
                                {
                                    item.Time = time;
                                    item.Memo = itr.Memo;
                                }
                            }
                        }
                        if (!isFoundItem && time != 0.0)
                        {
                            ev.Items.Add(new EventItem(itr, CurDate));
                            ev.Items.Sort();
                        }
                        else
                        {
                            if (ev.Items.Count == 0)
                            {
                                this.Items.Remove(ev);
                            }
                        }
                        break;
                    }
                }
                if (mergeFlag)
                {
                    Event first     = null;
                    bool  firstFlag = true;
                    foreach (var ev in this.Items)
                    {
                        if (ev.Name == itr.Name)
                        {
                            if (firstFlag)
                            {
                                first     = ev;
                                firstFlag = false;
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(ev.Category) || ev.Category == first.Category)
                                {
                                    foreach (var item in ev.Items)
                                    {
                                        first.Items.Add(new EventItem(item));
                                    }
                                    first.Items.Sort();
                                    Items.Remove(ev);
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!isFound && time != 0.0)
                {
                    Event newEv = new Event(itr, CurDate);
                    this.Items.Add(newEv);
                }
            }
            this.Save();
        }