public DatedNoteForm(MainForm mainForm, NoteTable editedTable, Mode mode) : base(mainForm, editedTable, mode) { InitializeComponent(); Text = GetFormText(); submitButton.Text = GetSubmitButtonText(); DatedNote datedNote = _editedNote as DatedNote; if (datedNote != null) { nameTextBox.Text = datedNote.Name; yearTextBox.Text = (datedNote.Year == 0) ? "" : datedNote.Year.ToString(); stateComboBox.SelectedIndex = (int)datedNote.CurrentState; commentRichTextBox.Text = datedNote.Comment; } yearTextBox.KeyPress += new KeyPressEventHandler(InputEventHandler.CheckNumeric); KeyDown += delegate(object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control) { submitButton.PerformClick(); } }; }
private static List <Note> ReadDatedNotes(SQLiteDataReader reader) { try { List <Note> notes = new List <Note>(); while (reader.Read()) { DatedNote datedNote = new DatedNote(); datedNote.Id = reader.GetInt32(0); datedNote.Name = reader.GetString(1); datedNote.CurrentState = (Note.State)reader.GetInt32(2); datedNote.Comment = reader.GetString(3); datedNote.Year = reader.GetInt32(4); notes.Add(datedNote); } return(notes); } catch (Exception ex) { Log.Error(string.Format("Can not read dated notes:{0}{1}", Environment.NewLine, ex.ToString())); return(new List <Note>()); } }
private static bool InsertDatedNotes(List <Note> notes, SQLiteCommand datedNoteInsertCommand) { bool inserted = false; try { using (SQLiteConnection connection = Database.CreateConnection()) { connection.Open(); datedNoteInsertCommand.Connection = connection; if (connection.State == System.Data.ConnectionState.Open) { using (SQLiteTransaction transaction = connection.BeginTransaction()) { foreach (Note note in notes) { DatedNote datedNote = note as DatedNote; if (datedNote == null) { Log.Error("Try to insert incorrect note"); continue; } datedNoteInsertCommand.Parameters[0].Value = datedNote.Name; datedNoteInsertCommand.Parameters[1].Value = (int)datedNote.CurrentState; datedNoteInsertCommand.Parameters[2].Value = datedNote.Comment; datedNoteInsertCommand.Parameters[3].Value = datedNote.Year; datedNoteInsertCommand.Prepare(); datedNoteInsertCommand.ExecuteNonQuery(); datedNote.Id = (int)connection.LastInsertRowId; inserted = true; } transaction.Commit(); } } connection.Close(); datedNoteInsertCommand.Connection = null; } } catch (Exception ex) { Log.Error(string.Format("Can not execute command: {0}{1}{2}{3}", Environment.NewLine, (datedNoteInsertCommand != null) ? datedNoteInsertCommand.CommandText : "", Environment.NewLine, ex.ToString())); return(false); } return(inserted); }
private void submitButton_Click(object sender, EventArgs e) { DatedNote datedNote = (_editedNote != null && _editedNote is DatedNote) ? _editedNote as DatedNote : new DatedNote(); datedNote.Name = nameTextBox.Text; datedNote.Year = (yearTextBox.Text.Trim().Length == 0) ? 0 : Int32.Parse(yearTextBox.Text.Trim()); datedNote.CurrentState = (Note.State)stateComboBox.SelectedIndex; datedNote.Comment = commentRichTextBox.Text; SubmitNote(datedNote); Close(); }
public override void UpdateNote(Note note) { DatedNote datedNote = note as DatedNote; if (datedNote == null) { return; } CurrentRow.Cells[(int)Index.Name].Value = datedNote.Name; CurrentRow.Cells[(int)Index.Year].Value = (datedNote.Year == 0) ? "" : datedNote.Year.ToString(); CurrentRow.Cells[(int)Index.State].Value = States[(int)datedNote.CurrentState]; CurrentRow.Cells[(int)Index.Comment].Value = datedNote.Comment; }
public override Note GetNoteFromSelectedRow() { if (CurrentRow == null) { return(null); } DatedNote datedNote = new DatedNote(); datedNote.Id = CurrentRow.Cells[(int)Index.Id].Value.ToString().ToIntOrException(); datedNote.Name = CurrentRow.Cells[(int)Index.Name].Value.ToString(); datedNote.Year = CurrentRow.Cells[(int)Index.Year].Value.ToString().ToIntOrDefault(); datedNote.CurrentState = CurrentRow.Cells[(int)Index.State].Value.ToString().ToNoteState(); datedNote.Comment = CurrentRow.Cells[(int)Index.Comment].Value.ToString(); return(datedNote); }
private static List <Note> ReadOldFilms(SQLiteDataReader reader, Dictionary <int, Note.State> oldStates) { List <Note> notes = new List <Note>(); while (reader.Read()) { DatedNote film = new DatedNote(); film.Name = reader.GetString(1); film.Year = reader.GetInt32(2); film.CurrentState = oldStates[reader.GetInt32(3)]; film.Comment = reader.GetString(4); notes.Add(film); } return(notes); }
private static bool UpdateDatedNote(Note note, SQLiteCommand datedNoteUpdateCommand) { DatedNote datedNote = note as DatedNote; if (datedNote == null || datedNote.Id < 0) { Log.Error("Try to save incorrect dated note"); return(false); } datedNoteUpdateCommand.Parameters[0].Value = datedNote.Id; datedNoteUpdateCommand.Parameters[1].Value = datedNote.Name; datedNoteUpdateCommand.Parameters[2].Value = (int)datedNote.CurrentState; datedNoteUpdateCommand.Parameters[3].Value = datedNote.Comment; datedNoteUpdateCommand.Parameters[4].Value = datedNote.Year; datedNoteUpdateCommand.Prepare(); return(ExecuteNonQuery(datedNoteUpdateCommand) == 1); }
public override bool AddNote(Note note) { if (note is DatedNote) { DatedNote datedNote = note as DatedNote; Rows.Add(new string[] { datedNote.Id.ToString(), datedNote.Name, (datedNote.Year == 0) ? "" : datedNote.Year.ToString(), States[(int)datedNote.CurrentState], datedNote.Comment }); return(true); } return(false); }