コード例 #1
0
ファイル: DataBase.cs プロジェクト: trippleflux/jezatools
 public List<Bank> BankGetAll(string commandText)
 {
     Log.Debug("BankGetAll: '{0}'", commandText);
     DataTable dataTable = GetDataTable(commandText);
     DataRowCollection dataRowCollection = dataTable.Rows;
     if (dataRowCollection.Count > 0)
     {
         List<Bank> list = new List<Bank>();
         foreach (DataRow dataRow in dataRowCollection)
         {
             object[] itemArray = dataRow.ItemArray;
             Bank bank = new Bank
                         {
                             Id = Misc.String2Number(itemArray[0].ToString()),
                             Name = itemArray[1].ToString(),
                             Owner = itemArray[2].ToString(),
                             AccountNumber = itemArray[3].ToString(),
                         };
             Log.Debug("Have bank: '{0}'", bank.Format());
             list.Add(bank);
         }
         return list;
     }
     return null;
 }
コード例 #2
0
ファイル: DataBase.cs プロジェクト: trippleflux/jezatools
 public int BankInsert(Bank bank)
 {
     try
     {
         const string commandText =
             @"INSERT INTO Bank (Name, Owner, AccountNumber) VALUES(@name, @owner, @accountNumber)";
         Log.Debug("BankInsert: [{0}], Bank={1}", commandText, bank.Format());
         using (sqLiteConnection)
         {
             using (SQLiteCommand sqLiteCommand = new SQLiteCommand(commandText, sqLiteConnection))
             {
                 sqLiteConnection.Open();
                 sqLiteCommand.Parameters.AddWithValue("@name", bank.Name);
                 sqLiteCommand.Parameters.AddWithValue("@owner", bank.Owner);
                 sqLiteCommand.Parameters.AddWithValue("@accountNumber", bank.AccountNumber);
                 int rowsInserted = sqLiteCommand.ExecuteNonQuery();
                 sqLiteConnection.Close();
                 return rowsInserted;
             }
         }
     }
     catch (Exception exception)
     {
         Log.Error(exception.ToString);
         return 0;
     }
 }
コード例 #3
0
ファイル: DataBase.cs プロジェクト: trippleflux/jezatools
 public int BankUpdate(Bank bank)
 {
     try
     {
         string commandText =
             @"UPDATE Bank SET Name = @name, Owner = @owner, AccountNumber = @accountNumber WHERE Id = " +
             bank.Id;
         Log.Debug("BankUpdate: [{0}], Bank={1}", commandText, bank.Format());
         using (sqLiteConnection)
         {
             using (SQLiteCommand sqLiteCommand = new SQLiteCommand(commandText, sqLiteConnection))
             {
                 sqLiteConnection.Open();
                 sqLiteCommand.Parameters.AddWithValue("@name", bank.Name);
                 sqLiteCommand.Parameters.AddWithValue("@owner", bank.Owner);
                 sqLiteCommand.Parameters.AddWithValue("@accountNumber", bank.AccountNumber);
                 int rowsUpdated = sqLiteCommand.ExecuteNonQuery();
                 sqLiteConnection.Close();
                 return rowsUpdated;
             }
         }
     }
     catch (Exception exception)
     {
         Log.Error(exception.ToString);
         return 0;
     }
 }