public List<Money> FetchMoney(int moneyTableIndex, int howManyMoney) { List<Money> listMoney = new List<Money>(); SqlConnection CON = new SqlConnection(CONNECTION_STR); SqlCommand cmd = new SqlCommand(); Money money; string id; int value; cmd.CommandText = "SELECT TOP " + howManyMoney + "* FROM " + MONEY_TABLE_NAME_ARRAY[moneyTableIndex]; cmd.Connection = CON; try { CON.Open(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { id = reader["Id"].ToString(); value = (int)reader["Value"]; money = new Money(id, value); listMoney.Add(money); } } } catch (Exception) { throw new Exception("Exception while fetching money from table " + MONEY_TABLE_NAME_ARRAY[moneyTableIndex]); } finally { CON.Close(); } return listMoney; }
public static bool GenerateMoney(Consignment consignment) { Dictionary<int, List<Money>> moneyDictionary = new Dictionary<int, List<Money>>(); int value; int[] moneyMultiplier = GetMultiplierArray(consignment); try { for (var i = 0; i < moneyMultiplier.Length; i++) { List<Money> moneyList = new List<Money>(); value = MoneySequence[i]; for (var j = 0; j < moneyMultiplier[i]; j++) { Money money = new Money(value); moneyList.Add(money); } moneyDictionary.Add(value, moneyList); } MoneyBankDBTool mdDBTool = new MoneyBankDBTool(); mdDBTool.InsertMoney(moneyDictionary); } catch (Exception) { return false; } return true; }