private static bool InsertAffairs(List <Note> notes) { bool inserted = false; try { using (SQLiteConnection connection = Database.CreateConnection()) { connection.Open(); _affairsInsertCommand.Connection = connection; if (connection.State == System.Data.ConnectionState.Open) { using (SQLiteTransaction transaction = connection.BeginTransaction()) { foreach (Note note in notes) { Affair affair = note as Affair; if (affair == null) { Log.Error("Try to insert incorrect note"); continue; } _affairsInsertCommand.Parameters[0].Value = affair.Name; _affairsInsertCommand.Parameters[1].Value = (int)affair.CurrentState; _affairsInsertCommand.Parameters[2].Value = affair.Comment; _affairsInsertCommand.Parameters[3].Value = affair.Description; _affairsInsertCommand.Parameters[4].Value = affair.IsDateSet; _affairsInsertCommand.Parameters[5].Value = affair.GetDate(); _affairsInsertCommand.Prepare(); _affairsInsertCommand.ExecuteNonQuery(); affair.Id = (int)connection.LastInsertRowId; inserted = true; } transaction.Commit(); } } connection.Close(); _affairsInsertCommand.Connection = null; } } catch (Exception ex) { Log.Error(string.Format("Can not execute command: {0}{1}{2}{3}", Environment.NewLine, (_affairsInsertCommand != null) ? _affairsInsertCommand.CommandText : "", Environment.NewLine, ex.ToString())); return(false); } return(inserted); }
public override void UpdateNote(Note note) { Affair affair = note as Affair; if (affair == null) { return; } CurrentRow.Cells[(int)Index.Name].Value = affair.Name; CurrentRow.Cells[(int)Index.Description].Value = affair.Description; CurrentRow.Cells[(int)Index.IsDateSet].Value = affair.IsDateSet; CurrentRow.Cells[(int)Index.Date].Value = affair.IsDateSet ? affair.GetDate().Replace(' ', '.') : ""; CurrentRow.Cells[(int)Index.State].Value = States[(int)affair.CurrentState]; CurrentRow.Cells[(int)Index.Comment].Value = affair.Comment; }
public override bool AddNote(Note note) { if (note is Affair) { Affair affair = note as Affair; Rows.Add( affair.Id.ToString(), affair.Name, affair.Description, affair.IsDateSet, affair.IsDateSet ? affair.GetDate().Replace(' ', '.') : "", States[(int)affair.CurrentState], affair.Comment ); return(true); } return(false); }
private static bool UpdateAffair(Note note) { Affair affair = note as Affair; if (affair == null || affair.Id < 0) { Log.Error("Try to save incorrect affair note"); return(false); } _affairsUpdateCommand.Parameters[0].Value = affair.Id; _affairsUpdateCommand.Parameters[1].Value = affair.Name; _affairsUpdateCommand.Parameters[2].Value = (int)affair.CurrentState; _affairsUpdateCommand.Parameters[3].Value = affair.Comment; _affairsUpdateCommand.Parameters[4].Value = affair.Description; _affairsUpdateCommand.Parameters[5].Value = affair.IsDateSet; _affairsUpdateCommand.Parameters[6].Value = affair.GetDate(); _affairsUpdateCommand.Prepare(); return(ExecuteNonQuery(_affairsUpdateCommand) == 1); }