public bool buyProduct(Product pt, int amount, Person p) { bool b = false; int nwamountstore; int nwamountperson; int nwsaldoperson; int nwsaldostore; int price = pt.ProductPrice * amount; if (checkStoreAmount(pt.ProductID, amount)) { if (getSaldoPerson(p.Id) >= price) { if (searchProductPerson(pt.ProductID, p.Id)) { nwsaldoperson = getSaldoPerson(p.Id) - price; nwsaldostore = getSaldoStore() + price; nwamountstore = getAmountStore(pt.ProductID) - amount; nwamountperson = getAmountPerson(p.Id, pt.ProductID) + amount; buyUProductPerson(nwamountperson, p.Id, pt.ProductID, nwsaldoperson); buyUProductStore(nwamountstore, 1, pt.ProductID,nwsaldostore); b = true; } else { nwsaldoperson = getSaldoPerson(p.Id) - price; nwsaldostore = getSaldoStore() + price; nwamountstore = getAmountStore(pt.ProductID) - amount; buyIProductPerson(amount, p.Id, pt.ProductID, nwsaldoperson); buyUProductStore(nwamountstore, 1, pt.ProductID,nwsaldostore); b = true; } } else { b = false; } } else { b = false; Console.WriteLine("store amount is false"); } return b; }
public List<Product> setPersonProduct(int pid) { List<Product> pdlist = new List<Product>(); List<int> prdtids = getProductids(pid); String connectionString = String.Format(@"DATA SOURCE=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ondora01.hu.nl)(PORT=8521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=cursus01.hu.nl)));PASSWORD={1};PERSIST SECURITY INFO=True;USER ID={0}", "stud1529990", // hier je username, "stud1529990" // hier je password ); OracleConnection conn = new OracleConnection(connectionString); try { foreach (int i in prdtids) { conn.Open(); OracleCommand cmd3 = conn.CreateCommand(); cmd3.CommandText = "select * from PRODUCT where PRODUCT_ID =" + i; OracleDataReader myReader = cmd3.ExecuteReader(); while (myReader.Read()) { Product pr = new Product(); pr.ProductID = int.Parse(myReader["PRODUCT_ID"].ToString().Trim()); pr.ProductName = myReader["PRODUCT_NAME"].ToString().Trim(); pr.ProductPrice = int.Parse(myReader["PRODUCT_PRICE"].ToString().Trim()); pdlist.Add(pr); } conn.Close(); } } catch (Exception e) { Console.WriteLine("setpersonproducts error" + e.Message); } return pdlist; }