public static void SaveDeposit(Deposit deposit) { try { string query = "UPDATE [Deposit] SET "; query += "Name = '" + deposit.Name + "',"; query += "Amount = " + deposit.Amount + ","; query += "IsDeleted = '" + deposit.IsDeleted.ToString() + "' "; query += "WHERE DepositID = " + deposit.DepositID; SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { string errmsg = "Fehler beim Speichern des Artikels.\n\n"; errmsg += "DatabaseHandler.SaveArticle(article): " + ex.ToString(); throw new Exception(errmsg); } }
private static ObservableCollection<Deposit> GetDeposites() { List<Deposit> deposites = new List<Deposit>(); deposites.Add(Deposit.NullDeposit); try { SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * FROM Deposit WHERE IsDeleted = 0", connection); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Deposit deposit = new Deposit(); deposit = new Deposit(); deposit.DepositID = Convert.ToInt32(reader["DepositID"]); deposit.Name = reader["Name"].ToString(); deposit.Amount = Convert.ToDouble(reader["Amount"]); deposit.IsDeleted = Convert.ToBoolean(reader["IsDeleted"]); deposit.Created = Convert.ToDateTime(reader["Created"]); deposites.Add(deposit); } connection.Close(); } catch (Exception ex) { string errmsg = "Fehler beim Abrufen der Pfandobjekte eines Profils.\n\n"; errmsg += "DatabaseHandler.GetDeposites(profileID): " + ex.ToString(); throw new Exception(errmsg); } return new ObservableCollection<Deposit>(deposites); }
private static Deposit GetDeposit(string depositname) { Deposit deposit = null; try { SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * FROM Deposit WHERE Name = @name", connection); cmd.Parameters.AddWithValue("@name", depositname); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { deposit = new Deposit(); deposit.DepositID = Convert.ToInt32(reader["DepositID"]); deposit.Name = reader["Name"].ToString(); deposit.Amount = Convert.ToDouble(reader["Amount"]); deposit.IsDeleted = Convert.ToBoolean(reader["IsDeleted"]); deposit.Created = Convert.ToDateTime(reader["Created"]); } connection.Close(); } catch (Exception ex) { string errmsg = "Fehler beim Abrufen des Pfandes.\n\n"; errmsg += "DatabaseHandler.GetDeposit(depositname, profileID): " + ex.ToString(); throw new Exception(errmsg); } return deposit; }
public Article() { this.deposit = Deposit.NullDeposit; }