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 Person login(String nm, String pw) { Person personlogin = new Person(); if (checkPassword(nm, pw)) { 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 { conn.Open(); OracleCommand cmd3 = conn.CreateCommand(); cmd3.CommandText = "select * from Person where NAME = '" + nm + "'"; OracleDataReader myReader = cmd3.ExecuteReader(); while (myReader.Read()) { personlogin.Id = int.Parse(myReader["PERSON_ID"].ToString().Trim()); personlogin.Name = myReader["NAME"].ToString().Trim(); personlogin.Password = myReader["PASSWORD"].ToString().Trim(); personlogin.Saldo = int.Parse(myReader["SALDO"].ToString().Trim()); } conn.Close(); personlogin.PersonsProducts = setPersonProduct(personlogin.Id); } catch (Exception e) { Console.WriteLine("login error" + e.Message); } } else { personlogin = null; } return personlogin; }