public long GetUser(string email, string hash) { long _result = -1; if (Connected) { using (SqlDataReader _reader = new SqlCommand(string.Format("Select * from MarketUser Where Email='{0}'", email), _sql).ExecuteReader()) { if (_reader.HasRows) { while (_reader.Read()) { if (_reader.GetString(_reader.GetOrdinal("Password")).Equals(hash)) { _result = _reader.GetInt64(_reader.GetOrdinal("UserId")); } } } } } return _result; }
public void readFromDataBase() { items.Clear(); SqlDataReader reader = new SqlCommand(string.Format("SELECT * FROM Items ORDER BY Id;SELECT * FROM Jobs ORDER BY Item;SELECT * FROM Jobs ORDER BY Item;"), cn).ExecuteReader(); //читаем лист items while (reader.Read()) { item newItem = new item(); newItem.id = reader.GetInt32(0); newItem.firstName = reader.GetString(1); newItem.lastName = reader.GetString(2); items.Add(newItem); } int i; int lastid; //читаем лист jobs reader.NextResult(); lastid = i = -1; while (reader.Read()) { int k = reader.GetInt32(4); if (lastid != k) { do ++i; while (k != items[i].id); lastid = reader.GetInt32(4); } items[i].jobs.Add(new job(reader.GetDateTime(0), reader.GetString(1), reader.GetString(2), reader.GetString(3))); } //читаем лист positions reader.NextResult(); lastid = i = -1; while (reader.Read()) { if (lastid != reader.GetInt32(4)) { do i++; while (reader.GetInt32(4) != items[i].id); lastid = reader.GetInt32(4); } items[i].positions.Add(new position(reader.GetInt64(0),reader.GetInt64(1),reader.GetInt32(2),reader.GetDateTime(3))); } reader.Close(); }