Ejemplo n.º 1
0
        private static List <Note> ReadDescribedNotes(SQLiteDataReader reader)
        {
            try
            {
                List <Note> notes = new List <Note>();

                while (reader.Read())
                {
                    DescribedNote describedNote = new DescribedNote();

                    describedNote.Id           = reader.GetInt32(0);
                    describedNote.Name         = reader.GetString(1);
                    describedNote.CurrentState = (Note.State)reader.GetInt32(2);
                    describedNote.Comment      = reader.GetString(3);
                    describedNote.Description  = reader.GetString(4);

                    notes.Add(describedNote);
                }

                return(notes);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Can not read described notes:{0}{1}",
                                        Environment.NewLine, ex.ToString()));
                return(new List <Note>());
            }
        }
Ejemplo n.º 2
0
        public DescribedNoteForm(MainForm mainForm, NoteTable editedTable, Mode mode) :
            base(mainForm, editedTable, mode)
        {
            InitializeComponent();

            Text = GetFormText();
            submitButton.Text = GetSubmitButtonText();

            DescribedNote describedNote = _editedNote as DescribedNote;

            if (describedNote != null)
            {
                nameTextBox.Text            = describedNote.Name;
                descriptionRichTextBox.Text = describedNote.Description;
                stateComboBox.SelectedIndex = (int)describedNote.CurrentState;
                commentRichTextBox.Text     = describedNote.Comment;
            }

            KeyDown += delegate(object o, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
                {
                    submitButton.PerformClick();
                }
            };
        }
Ejemplo n.º 3
0
        private static bool InsertDescribedNote(List <Note> notes, SQLiteCommand describedNoteInsertCommand)
        {
            bool inserted = false;

            try
            {
                using (SQLiteConnection connection = Database.CreateConnection())
                {
                    connection.Open();
                    describedNoteInsertCommand.Connection = connection;

                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
                        {
                            foreach (Note note in notes)
                            {
                                DescribedNote describedNote = note as DescribedNote;
                                if (describedNote == null)
                                {
                                    Log.Error("Try to insert incorrect note");
                                    continue;
                                }

                                describedNoteInsertCommand.Parameters[0].Value = describedNote.Name;
                                describedNoteInsertCommand.Parameters[1].Value = (int)describedNote.CurrentState;
                                describedNoteInsertCommand.Parameters[2].Value = describedNote.Comment;
                                describedNoteInsertCommand.Parameters[3].Value = describedNote.Description;

                                describedNoteInsertCommand.Prepare();
                                describedNoteInsertCommand.ExecuteNonQuery();

                                describedNote.Id = (int)connection.LastInsertRowId;

                                inserted = true;
                            }

                            transaction.Commit();
                        }
                    }

                    connection.Close();
                    describedNoteInsertCommand.Connection = null;
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Can not execute command: {0}{1}{2}{3}",
                                        Environment.NewLine, (describedNoteInsertCommand != null) ? describedNoteInsertCommand.CommandText : "",
                                        Environment.NewLine, ex.ToString()));

                return(false);
            }

            return(inserted);
        }
Ejemplo n.º 4
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            DescribedNote describedNote = (_editedNote != null && _editedNote is DescribedNote) ? _editedNote as DescribedNote : new DescribedNote();

            describedNote.Name         = nameTextBox.Text;
            describedNote.Description  = descriptionRichTextBox.Text;
            describedNote.CurrentState = (Note.State)stateComboBox.SelectedIndex;
            describedNote.Comment      = commentRichTextBox.Text;

            SubmitNote(describedNote);

            Close();
        }
Ejemplo n.º 5
0
        public override void UpdateNote(Note note)
        {
            DescribedNote describedNote = note as DescribedNote;

            if (describedNote == null)
            {
                return;
            }

            CurrentRow.Cells[(int)Index.Name].Value        = describedNote.Name;
            CurrentRow.Cells[(int)Index.Description].Value = describedNote.Description;
            CurrentRow.Cells[(int)Index.State].Value       = States[(int)describedNote.CurrentState];
            CurrentRow.Cells[(int)Index.Comment].Value     = describedNote.Comment;
        }
Ejemplo n.º 6
0
        public override Note GetNoteFromSelectedRow()
        {
            if (CurrentRow == null)
            {
                return(null);
            }

            DescribedNote describedNote = new DescribedNote();

            describedNote.Id           = CurrentRow.Cells[(int)Index.Id].Value.ToString().ToIntOrException();
            describedNote.Name         = CurrentRow.Cells[(int)Index.Name].Value.ToString();
            describedNote.Description  = CurrentRow.Cells[(int)Index.Description].Value.ToString();
            describedNote.CurrentState = CurrentRow.Cells[(int)Index.State].Value.ToString().ToNoteState();
            describedNote.Comment      = CurrentRow.Cells[(int)Index.Comment].Value.ToString();

            return(describedNote);
        }
Ejemplo n.º 7
0
        private static bool UpdateDescribedNote(Note note, SQLiteCommand describedNoteUpdateCommand)
        {
            DescribedNote describedNote = note as DescribedNote;

            if (describedNote == null || describedNote.Id < 0)
            {
                Log.Error("Try to save incorrect described note note");
                return(false);
            }

            describedNoteUpdateCommand.Parameters[0].Value = describedNote.Id;
            describedNoteUpdateCommand.Parameters[1].Value = describedNote.Name;
            describedNoteUpdateCommand.Parameters[2].Value = (int)describedNote.CurrentState;
            describedNoteUpdateCommand.Parameters[3].Value = describedNote.Comment;
            describedNoteUpdateCommand.Parameters[4].Value = describedNote.Description;

            describedNoteUpdateCommand.Prepare();

            return(ExecuteNonQuery(describedNoteUpdateCommand) == 1);
        }
Ejemplo n.º 8
0
        public override bool AddNote(Note note)
        {
            if (note is DescribedNote)
            {
                DescribedNote describedNote = note as DescribedNote;

                Rows.Add(new string[]
                {
                    describedNote.Id.ToString(),
                    describedNote.Name,
                    describedNote.Description,
                    States[(int)describedNote.CurrentState],
                    describedNote.Comment
                });

                return(true);
            }

            return(false);
        }