コード例 #1
0
        public static void DeleteNote(Note note)
        {
            var sql = string.Format ("DELETE FROM ITEMS WHERE Id = {0};", note.Id);

            using (var conn = GetConnection ()) {
                conn.Open ();

                using (var cmd = conn.CreateCommand ()) {
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery ();
                }
            }
        }
コード例 #2
0
		protected override async void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);

			// Set the layout for this activity.  You can find it in res/layout/note_editor.xml
			SetContentView (Resource.Layout.NoteEditor);

			// The text view for our note, identified by its ID in the XML file.
			text_view = FindViewById<EditText> (Resource.Id.note);

			// Get the note
			var note_id = Intent.GetLongExtra ("note_id", -1);

			if (note_id < 0)
				note = new Note ();
			else
				note =await NoteRepository.GetNoteAsync (note_id);
		}
コード例 #3
0
		public static void SaveNote (Note note)
		{
			using (var conn = GetConnection ()) {
				conn.Open ();

				using (var cmd = conn.CreateCommand ()) {

					if (note.Id < 0) {
						// Do an insert
						cmd.CommandText = "INSERT INTO ITEMS (Body, Modified) VALUES (@Body, @Modified); SELECT last_insert_rowid();";
						cmd.Parameters.AddWithValue ("@Body", note.Body);
						cmd.Parameters.AddWithValue ("@Modified", DateTime.Now);

						note.Id = (long)cmd.ExecuteScalar ();
					} else {
						// Do an update
						cmd.CommandText = "UPDATE ITEMS SET Body = @Body, Modified = @Modified WHERE Id = @Id";
						cmd.Parameters.AddWithValue ("@Id", note.Id);
						cmd.Parameters.AddWithValue ("@Body", note.Body);
						cmd.Parameters.AddWithValue ("@Modified", DateTime.Now);
					
						cmd.ExecuteNonQuery ();
					}
				}
			}
		}