Beispiel #1
0
        public void InsertLogin(Logins login)
        {
            SqlConnection conn = new SqlConnection(ConnectionString);

            try
            {
                conn.Open();

                var populateLogin    = conn.CreateCommand();
                var populateCustomer = conn.CreateCommand();

                populateLogin.CommandText = "insert into login (LoginID, CustomerID, PasswordHash) values (@loginID, @customerID, @passwordHash)";
                populateLogin.Parameters.AddWithValue("loginID", login.LoginID);
                populateLogin.Parameters.AddWithValue("customerID", login.CustomerID);
                populateLogin.Parameters.AddWithValue("passwordHash", login.PasswordHash);

                populateLogin.ExecuteNonQuery();
            }
            catch (SqlException se)
            {
                Console.WriteLine("Exception: {0}", se.Message);
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
        // NEED: Method to map Login Table into Login object in the program
        public void DownloadLoginArray()
        {
            SqlConnection conn = new SqlConnection(ConnectionString);

            try
            {
                conn.Open();

                var LoginQuery = "select * from login";

                SqlDataReader ReadLogin;
                using (SqlCommand LoginCmd = new SqlCommand(LoginQuery, conn))
                {
                    using (ReadLogin = LoginCmd.ExecuteReader())
                    {
                        // Create new login object and add it into Logins List belonging to BankingSys
                        while (ReadLogin.Read())
                        {
                            Logins login = new Logins(ReadLogin["LoginID"].ToString(), int.Parse(ReadLogin["CustomerID"].ToString()), ReadLogin["PasswordHash"].ToString());
                            BankingSys.Instance().Logins.Add(login);
                        }
                    }
                }
            }
            catch (SqlException se)
            {
                Console.WriteLine("Exception: {0}", se.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }