private void GetAuthorDataForSpecificAuthor(int authorId) { _authorInfo = DatabaseWrapper.Instance.GetAuthorInfoElement(authorId); authorFullNameTextBox.Text = _authorInfo.Name; authorCountryOfOriginTextBox.Text = _authorInfo.Country; authorWebsiteTextBox.Text = _authorInfo.Website; if (_authorInfo.Birthday != null) authorDateOfBirthDateTimePicker.Value = (DateTime) _authorInfo.Birthday; }
public void SetAuthorInfoElement(AuthorInfo info) { if (info == null) return; using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) { connection.Open(); using (SQLiteCommand insertCommand = new SQLiteCommand(connection)) { insertCommand.CommandText = "INSERT INTO AUTHOR_INFO (AUTHOR_ID, AUTHOR_NAME, AUTHOR_NATIONALITY, " + "AUTHOR_BIRTHDAY, AUTHOR_WEBSITE ) VALUES (?, ?, ?, ?, ?)"; insertCommand.Parameters.AddWithValue(null, info.Id); insertCommand.Parameters.AddWithValue(null, info.Name); insertCommand.Parameters.AddWithValue(null, info.Country); insertCommand.Parameters.AddWithValue(null, info.Birthday); insertCommand.Parameters.AddWithValue(null, info.Website); insertCommand.ExecuteNonQuery(); } connection.Close(); } }
public AuthorInfo GetAuthorInfoElement(int authorId) { AuthorInfo returnData = new AuthorInfo(); if (authorId <= 0) { return returnData; } try { using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) { connection.Open(); using (SQLiteCommand selectCommand = new SQLiteCommand(connection)) { selectCommand.CommandText = "SELECT AUTHOR_NAME, AUTHOR_NATIONALITY, AUTHOR_BIRTHDAY, AUTHOR_WEBSITE " + "FROM AUTHOR_INFO " + "WHERE AUTHOR_ID = ?"; selectCommand.Parameters.AddWithValue(null, authorId); SQLiteDataReader reader = selectCommand.ExecuteReader(); DataTable dataTable = new DataTable(); dataTable.Load(reader); returnData.Name = dataTable.Rows[0][0].ToString(); returnData.Country = dataTable.Rows[0][1].ToString(); returnData.Birthday = DateTime.Parse(dataTable.Rows[0][2].ToString()); returnData.Website = dataTable.Rows[0][3].ToString(); reader.Close(); } connection.Close(); } } catch (Exception ex) { ErrorHandler.LogError(ex); } return returnData; }