Esempio n. 1
0
 /// <summary>
 /// Inserts new item type.
 /// </summary>
 /// <param name="itemType">The item type.</param>
 /// <returns><c>true</c> on success.</returns>
 public bool InsertItemType(ItemType itemType)
 {
     Log.DebugFormat("InsertItemType '{0}'", itemType);
     using (dbConnection)
     {
         using (DbCommand dbCommand = dbConnection.CreateCommand())
         {
             dbConnection.Open();
             string commandText = String.Format(CultureInfo.InvariantCulture,
                                                "INSERT INTO ItemType (Name) VALUES('{0}')",
                                                itemType.Name);
             Log.Debug(commandText);
             dbCommand.CommandText = commandText;
             if (dbCommand.ExecuteNonQuery() == 1)
             {
                 return true;
             }
             Log.ErrorFormat("Failed to insert itemType [{0}]", itemType);
             return false;
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the item types.
 /// </summary>
 /// <returns></returns>
 public IList<ItemType> GetItemTypes()
 {
     Log.Debug("GetItemTypes");
     IList<ItemType> itemTypes = new List<ItemType>();
     using (dbConnection)
     {
         using (DbCommand dbCommand = dbConnection.CreateCommand())
         {
             dbConnection.Open();
             const string commandText = "SELECT * FROM ItemType";
             dbCommand.CommandText = commandText;
             Log.Debug(commandText);
             using (DbDataReader reader = dbCommand.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     ItemType itemType = new ItemType
                         {
                             Id = Int32.Parse(reader[0].ToString()),
                             Name = reader[1].ToString(),
                         };
                     itemTypes.Add(itemType);
                     Log.InfoFormat("Adding ItemType [{0}]", itemType);
                 }
             }
         }
     }
     return itemTypes;
 }