private async void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (comboBox1.SelectedIndex != -1)
            {
                Note note = new Note();
                note.RoomID     = int.Parse((comboBox1.SelectedItem as ComboBoxItem).Name);
                note.RoomName   = (comboBox1.SelectedItem as ComboBoxItem).Content.ToString();
                note.TextOfNote = textBox.Text;
                note.TimeOfNote = datePicker.Date.ToString("dd-MM-yyyy") + " " + timePicker.Time.ToString(@"hh\:mm");
                databaseHelper.InsertNote(note);

                TextBlock text = new TextBlock()
                {
                    FontSize = App.FontSize,
                    Text     = $"{note.TextOfNote}\nW dniu: {note.TimeOfNote.Insert(10, " o godzinie ")}\nMiejsce: {note.RoomName}\n",
                    Name     = "item" + note.ID
                };
                text.Tapped += Text_Tapped;
                if (ContentRoot.Children[0] is TextBlock)
                {
                    if ((ContentRoot.Children[0] as TextBlock).Name == "item0")
                    {
                        ContentRoot.Children.RemoveAt(0);
                    }
                }
                ContentRoot.Children.Insert(0, text);

                DateTime date = DateTime.ParseExact(note.TimeOfNote, @"dd-MM-yyyy HH\:mm", CultureInfo.InvariantCulture);
                if (date >= DateTime.Now)
                {
                    notifications.AddNotification(note);
                }
                GridAddNote.Visibility = Visibility.Collapsed;
            }
            else
            {
                MessageDialog message = new MessageDialog("Nie wybrano sali");
                await message.ShowAsync();
            }
        }
Beispiel #2
0
        private void ButtonAdd_Click(object sender, EventArgs e)
        {
            string errors = string.Empty;
            Note   note   = new Note();

            using (EditText dateEditText = FindViewById <EditText>(Resource.Id.editTextDate))
            {
                using (EditText timeEditText = FindViewById <EditText>(Resource.Id.editTextTime))
                {
                    DateTime date;
                    if (!DateTime.TryParseExact(dateEditText.Text + " " + timeEditText.Text, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                    {
                        errors += "Nieprawid³owa data lub godzina powiadomienia.\n";
                    }
                    else
                    {
                        note.TimeOfNote = date.ToString("dd-MM-yyyy HH:mm:ss");
                    }
                }
                using (Spinner spinner = FindViewById <Spinner>(Resource.Id.spinnerRoomID))
                {
                    note.RoomID = int.Parse(spinner.SelectedItem.ToString());
                }

                using (Spinner spinner = FindViewById <Spinner>(Resource.Id.spinner1))
                {
                    note.RoomName = spinner.SelectedItem.ToString();
                }
                using (var editText = FindViewById <EditText>(Resource.Id.editTextOfNote))
                {
                    if (string.IsNullOrEmpty(editText.Text))
                    {
                        errors += "Nie podano opisu notatki.\n";
                    }
                    else
                    {
                        note.TextOfNote = editText.Text;
                    }
                }
                if (!string.IsNullOrEmpty(errors))
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("B³¹d");
                    alert.SetMessage(errors);
                    Dialog dialog = alert.Create();
                    dialog.Show();
                    return;
                }

                notifications.AddNotification(note);
                databaseHelper.InsertNote(note);

                using (var layout = Window.DecorView.FindViewById <LinearLayout>(Resource.Id.linearLayout1))
                {
                    using (TextView txt = new TextView(this))
                    {
                        txt.ContentDescription = note.ID.ToString();;
                        txt.SetTextSize(ComplexUnitType.Sp, 16);
                        txt.SetText($"{note.TextOfNote}\nW dniu: {note.TimeOfNote/*.Insert(10, " o godzinie ")*/} w {note.RoomName}\n", TextView.BufferType.Normal);
                        txt.Click += NoteTextView_Click;
                        layout.AddView(txt, 1);
                    }
                }
            }
        }