예제 #1
0
 public override void OnBackPressed() // BackPressed or Save button clicked
 {
     try
     {
         if (string.IsNullOrEmpty(workEditText.Text))
         {
             throw new ArgumentNullException();                                          // not saving if text is empty
         }
         if (work == null)
         {
             work = new Work();               // if not loaded creating new work
         }
         if (string.IsNullOrEmpty(titleEditText.Text))
         {
             titleEditText.Text = "Nowe dzieło (" + (SQLiteDb.GetWorks().Where(w => w.Title.Contains("Nowe dzieło")).Count() + 1) + ")"; // filling title if empty
         }
         if (work.Text != workEditText.Text || work.Title != titleEditText.Text)                                                         //saving work if changed or new
         {
             work.Text     = workEditText.Text;
             work.Title    = titleEditText.Text;
             work.Modified = DateTime.Now;
             SQLiteDb.SaveWork(work);
         }
         else
         {
             throw new ArgumentNullException();
         }
     }
     catch
     {
         Toast.MakeText(this, "Nie zapisano", ToastLength.Short).Show();
     }
     base.OnBackPressed();
 }