Exemplo n.º 1
0
 private void notebookDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) // получение индекса выделенной строки и запись инф-и в окно
 {
     try
     {
         DataGrid        dg  = sender as DataGrid;
         Models.Notebook row = (Models.Notebook)dg.SelectedItems[0];
         index = Convert.ToInt32(row.ID_NB.ToString());
         using (Models.OrganizerDB context = new Models.OrganizerDB())
         {
             var notebook = context.Notebook.FirstOrDefault(s => s.ID_NB == index && s.User == Classes.SelectUser.SelectUserID);
             if (notebook != null)
             {
                 NoteTitle.Text = notebook.HeaderNB;
                 FlowDocument flow = new FlowDocument(new Paragraph(new Run(notebook.TextNotebook)));
                 NoteText.Document    = flow;
                 ChangeNote.IsEnabled = true;
                 DeleteNote.IsEnabled = true;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
 private bool DeleteNoteValidRequest(StreamWriter sw)
 {
     try
     {
         GoogleFirestoreConnectionManager.HandleLogin(userID1, displayName1, email1);
         Models.Notebook createdNotebook = GoogleFirestoreConnectionManager.CreateNotebook(userID1, notebook1.Title, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);
         Models.Note     createdNote     = GoogleFirestoreConnectionManager.CreateNote(userID1, createdNotebook.ID, text1);
         if (!GoogleFirestoreConnectionManager.DeleteNote(createdNote.ID))
         {
             sw.WriteLine("FAILED: DeleteNote(string noteID): Normal test case 1.");
             GoogleFirestoreConnectionManager.DeleteUser(userID1);
             return(false);
         }
         else
         {
             try
             {
                 GoogleFirestoreConnectionManager.GetNote(createdNote.ID);
             }
             catch (NotFoundException)
             {
                 GoogleFirestoreConnectionManager.DeleteUser(userID1);
                 return(true);
             }
             GoogleFirestoreConnectionManager.DeleteUser(userID1);
             return(false);
         }
     }
     catch
     {
         sw.WriteLine("FAILED: DeleteNote(string noteID): Normal test case 1 - unexpected exception.");
         return(false);
     }
 }
Exemplo n.º 3
0
 public Data.Notebook ReverseConvert(Models.Notebook value)
 {
     return(new Data.Notebook(value.Name)
     {
         ID = value.ID,
         Stacks = DataUtils.ValueOrDefault(value.Stacks).ConvertAll(input => stackConverter.Value.ReverseConvert(input))
     });
 }
        private bool GetNotesValidRequest(StreamWriter sw)
        {
            try
            {
                GoogleFirestoreConnectionManager.HandleLogin(userID1, displayName1, email1);
                Models.Notebook createdNotebook = GoogleFirestoreConnectionManager.CreateNotebook(userID1, notebook1.Title, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);

                Note created1 = GoogleFirestoreConnectionManager.CreateNote(userID1, createdNotebook.ID, note1.Text);
                Note created2 = GoogleFirestoreConnectionManager.CreateNote(userID1, createdNotebook.ID, note2.Text);
                Note created3 = GoogleFirestoreConnectionManager.CreateNote(userID1, createdNotebook.ID, note3.Text);
                List <Models.Note> createdNotes = GoogleFirestoreConnectionManager.GetNotebookNotes(createdNotebook.ID);

                List <Models.Note> expectedNotes = new List <Models.Note>
                {
                    new Note(created1.ID, userID1, createdNotebook.ID, text1, DateTime.Now, DateTime.Now),
                    new Note(created2.ID, userID1, createdNotebook.ID, text2, DateTime.Now, DateTime.Now),
                    new Note(created3.ID, userID1, createdNotebook.ID, text3, DateTime.Now, DateTime.Now)
                };

                if (createdNotes.Count != expectedNotes.Count)
                {
                    sw.WriteLine("FAILED: GetNotes(string notebookID): Normal test case, count mismatch.");
                    GoogleFirestoreConnectionManager.DeleteUser(userID1);
                    return(false);
                }
                else
                {
                    foreach (Models.Note n in createdNotes)
                    {
                        foreach (Models.Note t in expectedNotes)
                        {
                            if (t.Equals(n))
                            {
                                expectedNotes.Remove(t);
                                break;
                            }
                        }
                    }

                    if (expectedNotes.Count > 0)
                    {
                        sw.WriteLine("FAILED: GetNotes(string notebookID): Normal test case, Notes not the same.");
                        GoogleFirestoreConnectionManager.DeleteUser(userID1);
                        return(false);
                    }
                }
                GoogleFirestoreConnectionManager.DeleteUser(userID1);
            }
            catch
            {
                sw.WriteLine("FAILED: GetNotes(string notebookID): Normal test case - unexpected exception.");
                return(false);
            }
            return(true);
        }
 private bool CreateNotebookByDetailsTitleIsNull(StreamWriter sw)
 {
     try
     {
         Models.Notebook temp = CreateNotebook(userID1, null, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);
         sw.WriteLine("FAILED: CreateNotebook(string userID, string title, string author, string publisher, string publishDate): CreateNotebook by Book Details title is null test case.");
         DeleteNotebook(temp.ID);
         return(false);
     }
     catch { return(true); }
 }
 private bool CreateNotebookByDetailsUserDoesNotExist(StreamWriter sw)
 {
     try
     {
         Models.Notebook temp = CreateNotebook(userID1 + "NOTEXIST", notebook1.Title, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);
         sw.WriteLine("FAILED: CreateNotebook(string userID, string isbn): CreateNotebook by Book Details User does not exist test case.");
         DeleteNotebook(temp.ID);
         return(false);
     }
     catch { return(true); }
 }
Exemplo n.º 7
0
 private bool DeleteNotebookValidRequest(StreamWriter sw)
 {
     try
     {
         GoogleFirestoreConnectionManager.HandleLogin(userID1, displayName1, email1);
         Models.Notebook temp = GoogleFirestoreConnectionManager.CreateNotebook(userID1, notebook1.Title, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);
         if (!GoogleFirestoreConnectionManager.DeleteNotebook(temp.ID))
         {
             sw.WriteLine("FAILED: DeleteNotebook(string notebookID): Normal test case 1.");
             return(false);
         }
     }
     catch
     {
         sw.WriteLine("FAILED: DeleteNotebook(string notebookID): Normal test case 1 - unexpected exception.");
         return(false);
     }
     return(true);
 }
Exemplo n.º 8
0
        private void ChangeRecord_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (Models.OrganizerDB context = new Models.OrganizerDB())
                {
                    Models.Notebook notebook = context.Notebook.Find(index);

                    notebook.HeaderNB     = NoteTitle.Text;
                    notebook.TextNotebook = new TextRange(NoteText.Document.ContentStart, NoteText.Document.ContentEnd).Text;
                    notebook.DateTime     = DateTime.Today.ToString().Remove(10, 8);
                    context.SaveChanges();
                }
                FillTable();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private bool GetNotesNotebookHasNoNotes(StreamWriter sw)
 {
     try
     {
         GoogleFirestoreConnectionManager.HandleLogin(userID1, displayName1, email1);
         Models.Notebook    createdNotebook = GoogleFirestoreConnectionManager.CreateNotebook(userID1, notebook1.Title, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);
         List <Models.Note> tempNotes       = GoogleFirestoreConnectionManager.GetNotebookNotes(createdNotebook.ID);
         if (tempNotes == null || tempNotes.Count != 0)
         {
             sw.WriteLine("FAILED: GetNotes(string notebookID): Notebook has no notes test case.");
             GoogleFirestoreConnectionManager.DeleteUser(userID1);
             return(false);
         }
         GoogleFirestoreConnectionManager.DeleteUser(userID1);
     }
     catch
     {
         sw.WriteLine("FAILED: GetNotes(string notebookID): Notebook has no notes test case - unexpected exception.");
         return(false);
     }
     return(true);
 }
Exemplo n.º 10
0
        private void DeleteRecord_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (Models.OrganizerDB context = new Models.OrganizerDB())
                {
                    Models.Notebook notebook = context.Notebook.Find(index);
                    context.Notebook.Remove(notebook);
                    context.SaveChanges();
                }
                FillTable();
                ChangeNote.IsEnabled = false;
                DeleteNote.IsEnabled = false;

                NoteTitle.Text = "";
                FlowDocument flow = new FlowDocument(new Paragraph(new Run("")));
                NoteText.Document = flow;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 11
0
 private bool GetNoteValidRequest(StreamWriter sw)
 {
     try
     {
         GoogleFirestoreConnectionManager.HandleLogin(userID1, displayName1, email1);
         Models.Notebook createdNotebook = GoogleFirestoreConnectionManager.CreateNotebook(userID1, notebook1.Title, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);
         Note            createdNote     = GoogleFirestoreConnectionManager.CreateNote(userID1, createdNotebook.ID, note1.Text);
         Note            expectedNote    = new Note(createdNote.ID, userID1, createdNotebook.ID, note1.Text, DateTime.Now, DateTime.Now);
         if (!GoogleFirestoreConnectionManager.GetNote(createdNote.ID).Equals(expectedNote))
         {
             sw.WriteLine("FAILED: GetNote(string noteID): Normal test case.");
             GoogleFirestoreConnectionManager.DeleteUser(userID1);
             return(false);
         }
         GoogleFirestoreConnectionManager.DeleteUser(userID1);
     }
     catch
     {
         sw.WriteLine("FAILED: GetNote(string noteID): Normal test case - unexpected exception.");
         return(false);
     }
     return(true);
 }
Exemplo n.º 12
0
        private void AddRecord_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string emptyRichTxtBox = new TextRange(NoteText.Document.ContentStart, NoteText.Document.ContentEnd).Text;

                if (NoteTitle.Text == "")
                {
                    MessageBox.Show("Заголовок пуст!");
                    return;
                }

                if (emptyRichTxtBox.Length - 2 == 0)
                {
                    MessageBox.Show("Текстовое поле пусто!");
                    return;
                }

                using (Models.OrganizerDB context = new Models.OrganizerDB())
                {
                    Models.Notebook NewNote = new Models.Notebook();
                    NewNote.HeaderNB     = NoteTitle.Text;
                    NewNote.TextNotebook = new TextRange(NoteText.Document.ContentStart, NoteText.Document.ContentEnd).Text;
                    NewNote.DateTime     = DateTime.Today.ToString().Remove(10, 8);
                    NewNote.User         = Classes.SelectUser.SelectUserID;
                    context.Notebook.Add(NewNote);
                    context.SaveChanges();
                }
                FillTable();
                ChangeNote.IsEnabled = false;
                DeleteNote.IsEnabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 13
0
 private bool UpdateNoteValidRequest(StreamWriter sw)
 {
     try
     {
         GoogleFirestoreConnectionManager.HandleLogin(userID1, displayName1, email1);
         Models.Notebook createdNotebook      = GoogleFirestoreConnectionManager.CreateNotebook(userID1, notebook1.Title, notebook1.Author, notebook1.Isbn, notebook1.Publisher, notebook1.PublishDate, notebook1.CoverURL);
         Note            createdNote          = GoogleFirestoreConnectionManager.CreateNote(userID1, createdNotebook.ID, note1.Text);
         Note            updatedNote          = GoogleFirestoreConnectionManager.UpdateNote(createdNote.ID, createdNotebook.ID, text2);
         Note            retrievedUpdatedNote = GoogleFirestoreConnectionManager.GetNote(updatedNote.ID);
         if (retrievedUpdatedNote.Text != text2)
         {
             sw.WriteLine("FAILED: UpdateNote(string noteID, string noteText): Normal test case, note not updated.");
             GoogleFirestoreConnectionManager.DeleteUser(userID1);
             return(false);
         }
         GoogleFirestoreConnectionManager.DeleteUser(userID1);
     }
     catch
     {
         sw.WriteLine("FAILED: UpdateNote(string noteID, string noteText): Normal test case - unexpected exception.");
         return(false);
     }
     return(true);
 }
Exemplo n.º 14
0
        public static Data.Notebook ToDataNotebook(this Models.Notebook notebook)
        {
            NotebookConverter converter = new NotebookConverter();

            return(converter.ReverseConvert(notebook));
        }