示例#1
0
        void UpdatedRecord(DreamRecord previous, DreamRecord record)
        {
            //Console.WriteLine("received updated record");

            RemoveRecord(previous);
            AddNewRecord(record);
        }
示例#2
0
        void UpdatedRecord(DreamRecordPage sender, DreamRecord record)
        {
            Console.WriteLine("received updated record");

            if (record.HasNoTags(_tags))
            {
                _list.Remove(record);
            }
        }
示例#3
0
        void RecordUpdated(DreamRecord previous, DreamRecord record)
        {
            RemoveRecord(previous);

            if (record.DateRecorded.Month == _month.Date.Month)
            {
                AddNewRecord(record);
            }
        }
示例#4
0
        public DreamRecord(DreamRecord other)
        {
            ID           = other.ID;
            Title        = other.Title;
            Description  = other.Description;
            DateRecorded = other.DateRecorded;
            Emotion      = other.Emotion;

            Tags = other.Tags;
        }
示例#5
0
 public int SaveItem(DreamRecord item)
 {
     lock (_locker) {
         if (item.ID != 0)
         {
             _database.Update(item);
             return(item.ID);
         }
         else
         {
             return(_database.Insert(item));
         }
     }
 }
示例#6
0
        void RemoveRecord(DreamRecord record)
        {
            string         emotion = record.Emotion.ToString();
            ChartDataPoint point   = null;

            for (int index = 0; index < _points.Count; index++)
            {
                point = _points[index];

                //Console.WriteLine($"{point.XValue}  {record.DateRecorded}");

                if (point.XValue.Equals(emotion))
                {
                    _points.Remove(point);
                    point.YValue--;
                    _points.Add(point);
                    break;
                }
            }
        }
示例#7
0
        void RecordUpdated(DreamRecord previous, DreamRecord record)
        {
            if (record.DateRecorded.Month != previous.DateRecorded.Month)
            {
                JournalMonth month = null;
                for (int index = 0; index < _months.Count; index++)
                {
                    month = _months[index];

                    if (month.Date.Month == previous.DateRecorded.Month)
                    {
                        month.Records.Remove(record);
                        month.RecordCount--;
                    }
                    else if (month.Date.Month == record.DateRecorded.Month)
                    {
                        month.Records.Add(record);
                        month.RecordCount++;
                    }
                }
            }
        }
示例#8
0
        void RemoveRecord(DreamRecord record)
        {
            if (_seriesData.ContainsKey(record.Emotion))
            {
                ObservableCollection <ChartDataPoint> list = _seriesData[record.Emotion];

                ChartDataPoint point = null;
                for (int index = 0; index < list.Count; index++)
                {
                    point = list[index];

                    //Console.WriteLine($"{point.XValue}  {record.DateRecorded}");

                    if (point.XValue.Equals(record.DateRecorded))
                    {
                        list.Remove(point);
                        point.YValue--;
                        list.Add(point);
                        break;
                    }
                }
            }
        }
示例#9
0
 public static void SaveRecord(DreamRecord record)
 {
     _database.SaveItem(record);
 }
示例#10
0
 void NewRecord(DreamRecordPage sender, DreamRecord record)
 {
     //Console.WriteLine("received new record");
     AddNewRecord(record);
 }
示例#11
0
        public DreamRecordPage(DreamRecord record, bool newRecord)
        {
            _previousRecord = new DreamRecord(record);

            Entry title = new Entry()
            {
                Placeholder   = "Enter title...",
                HeightRequest = 50
            };

            title.BindingContext = record;
            title.SetBinding(Entry.TextProperty, "Title");

            Label descLabel = new Label()
            {
                Text = "Description",
                HorizontalTextAlignment = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold,
            };
            Editor description = new Editor()
            {
                //HeightRequest = 250,
                BackgroundColor = Color.Gray,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            description.BindingContext = record;
            description.SetBinding(Editor.TextProperty, "Description");

            DatePicker datePicker = new DatePicker()
            {
                Format = "D"
            };

            datePicker.BindingContext = record;
            datePicker.SetBinding(DatePicker.DateProperty, "DateRecorded");

            DateTime now = DateTime.Now;

            if (newRecord)
            {
                datePicker.Date = now;
            }
            else
            {
                datePicker.Date = record.DateRecorded;
            }

            datePicker.MinimumDate = datePicker.Date.AddYears(-1);
            datePicker.MaximumDate = now;

            Picker picker = new Picker()
            {
                Title = "Emotion"
            };

            picker.SelectedIndexChanged += (object sender, EventArgs e) =>
            {
                if (picker.SelectedIndex != -1)
                {
                    record.Emotion = (Emotion)picker.SelectedIndex;
                }
            };

            List <Emotion> emotions = DreamsAPI.GetEmotions();

            for (int index = 0; index < emotions.Count; index++)
            {
                picker.Items.Add((emotions[index]).ToString());
            }

            picker.SelectedIndex = (int)record.Emotion;

            Entry tags = new Entry()
            {
                Placeholder   = "Enter comma separated tags",
                HeightRequest = 50,
            };

            tags.BindingContext = record;
            tags.SetBinding(Entry.TextProperty, "Tags");

            Button submit = new Button();

            if (newRecord)
            {
                submit.Text = ADD;
            }
            else
            {
                submit.Text = UPDATE;
            }

            submit.Clicked += async(object sender, EventArgs e) =>
            {
                if (newRecord)
                {
                    DreamsAPI.SaveRecord(record);

                    MessagingCenter.Send <DreamRecordPage, DreamRecord>(this, "NewRecord", record);
                }
                else
                {
                    try
                    {
                        DreamsAPI.SaveRecord(record);

                        if ((_previousRecord.DateRecorded != record.DateRecorded ||
                             _previousRecord.Emotion != record.Emotion) && recordUpdated != null)
                        {
                            recordUpdated(_previousRecord, record);
                        }
                    }
                    catch (Exception er)
                    {
                        Console.WriteLine(er.Message);
                    }
                }

                await Navigation.PopAsync();
            };

            StackLayout descStack = new StackLayout()
            {
                Children =
                {
                    descLabel,
                    description,
                },
                VerticalOptions = LayoutOptions.FillAndExpand
            };
            StackLayout bottomStack = new StackLayout()
            {
                Children =
                {
                    datePicker,
                    picker,
                    tags,
                    submit
                },
                VerticalOptions = LayoutOptions.End
            };

            StackLayout layout = new StackLayout()
            {
                Children =
                {
                    title,
                    descStack,
                    bottomStack
                }
            };

            Content = layout;
        }