public Asset LoadAsset(int inAssetID)
{
Asset returnAsset;
int tempID = 0;
string tempname = "UNKNOWN/VOID";
decimal tempprice = 1000;
string tempdate = "01/01/1000";
decimal scrapvalue = 10;
int lifespan = 0;
string status = "false";
Domain.DecreciationType type = Domain.DecreciationType.Lineær;
SqlConnection conn = getConnection();
try
{
SqlCommand comd = new SqlCommand("spCompoundAssDesc", conn);
comd.CommandType = CommandType.StoredProcedure;
comd.Parameters.Add(new SqlParameter("@AssetId", inAssetID));
SqlDataReader rdr = comd.ExecuteReader();
while (rdr.Read())
{
tempID = int.Parse(rdr["AssetId"].ToString());
tempname = rdr["AssetName"].ToString();
tempprice = decimal.Parse(rdr["AssetPurchasePrice"].ToString());
tempdate = rdr["AssetPurchaseDate"].ToString();
scrapvalue = decimal.Parse(rdr["AssetScrapValue"].ToString());
lifespan = int.Parse(rdr["AssetLifeSpan"].ToString());
status = rdr["AssetStatus"].ToString();
string inType = rdr["DecreciationType"].ToString();
switch (inType)
{
case "Lineær":
type = Domain.DecreciationType.Lineær;
break;
case "Saldo":
type = Domain.DecreciationType.Saldo;
break;
case "Annuitet":
type = Domain.DecreciationType.Annuitet;
break;
}
}
}
catch (SqlException es)
{
Console.WriteLine("UPS " + es.Message);
Console.ReadLine();
}
finally
{
conn.Close();
}
returnAsset = new Asset(tempname, tempprice, tempdate, scrapvalue, lifespan, status, type);
returnAsset.SetID(tempID);
return returnAsset;
}