示例#1
0
        public bool AddNewStandingOrder(int customerId, int seriesId)
        {
            var connection = _databaseConnectionManager.GetConnection();
            var sql        = $"INSERT INTO {StandingOrdersTableStructure.TableName} ({StandingOrdersTableStructure.CustomerId}, {StandingOrdersTableStructure.SeriesId}) values ({customerId}, {seriesId})";
            var command    = new SQLiteCommand(sql, connection);

            connection.Open();
            var returnCode = command.ExecuteNonQuery();

            connection.Close();
            return(returnCode == 1);
        }
示例#2
0
 private void BtnConnection_Click(object sender, System.EventArgs e)
 {
     using (var test = connectionManager.GetConnection())
     {
         test.Open();
     }
 }
        public bool AddNewSeries(ComicSeries series)
        {
            if (GetSeriesByName(series.Name) != null)
            {
                return(false);
            }

            var connection = _databaseConnectionManager.GetConnection();
            var sql        = $"INSERT INTO {ComicSeriesTableStructure.TableName} ({ComicSeriesTableStructure.Id}, {ComicSeriesTableStructure.Name}, {ComicSeriesTableStructure.Publisher}) values ({series.Id}, '{series.Name}', '{series.Publisher}')";
            var command    = new SQLiteCommand(sql, connection);

            connection.Open();
            var returnCode = command.ExecuteNonQuery();

            connection.Close();
            return(returnCode == 1);
        }
        public bool AddNewCustomer(Customer customer)
        {
            if (GetCustomerByName(customer.FirstName, customer.LastName) != null)
            {
                return(false);
            }

            var connection = _databaseConnectionManager.GetConnection();
            var sql        = $"INSERT INTO {CustomersTableStructure.TableName} ({CustomersTableStructure.Id}, {CustomersTableStructure.FirstName}, {CustomersTableStructure.LastName}, {CustomersTableStructure.Email}) values ({customer.Id}, '{customer.FirstName}', '{customer.LastName}', '{customer.Email}')";
            var command    = new SQLiteCommand(sql, connection);

            connection.Open();
            var returnCode = command.ExecuteNonQuery();

            connection.Close();
            return(returnCode == 1);
        }
示例#5
0
        private DownloadDetails AddDownloadDetails(DownloadDetails downloadDetails)
        {
            _downloadDetails.AddOrUpdate(downloadDetails.DownloadId ?? Int32.MaxValue, downloadDetails, (previous, current) => downloadDetails);

            var connection = DatabaseConnectionManager.GetConnection();

            connection.InsertOrReplace(downloadDetails);
            connection.Commit();

            return(downloadDetails);
        }
示例#6
0
        public void RemoveDownloadDetails(int downloadId)
        {
            if (_downloadDetails.ContainsKey(downloadId))
            {
                _downloadDetails.TryRemove(downloadId, out var downloadDetail);

                var connection = DatabaseConnectionManager.GetConnection();
                connection.Delete(downloadDetail);
                connection.Commit();
            }
        }
示例#7
0
        /// <summary>
        /// Retun all elements.
        /// If any error occur, RepositoryException will be throw
        /// </summary>
        /// <returns></returns>
        public List <T> GetAll()
        {
            List <T> list = new List <T>();
            var      con  = _databaseConnectionManager.GetConnection();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = $"SELECT * FROM `{_tableName}`";
                using (var dataR = comm.ExecuteReader())
                {
                    while (dataR.Read())
                    {
                        var element = ToObject(dataR);
                        list.Add(element);
                    }
                }
            }

            return(list);
        }
示例#8
0
        public void Restore()
        {
            _downloadDetails = new ConcurrentDictionary <int, DownloadDetails>();
            var connection = DatabaseConnectionManager.GetConnection();

            connection.CreateTable <DownloadDetails>(CreateFlags.ImplicitPK | CreateFlags.AutoIncPK);

            var downloadDetails = connection.Query <DownloadDetails>("SELECT * FROM DownloadDetails");

            foreach (var downloadDetail in downloadDetails)
            {
                downloadDetail.DownloadStatus = (int)GetInitialDownloadStatus((DownloadDetails.Status)downloadDetail.DownloadStatus);
                if (downloadDetail.DownloadId == null)
                {
                    continue;
                }

                _downloadDetails.AddOrUpdate(downloadDetail.DownloadId ?? 0, downloadDetail, (previous, current) => downloadDetail);
            }

            RestoreLastDownloadId();
        }