// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // .Net StockTrader Sample WCF Application for Benchmarking, Performance Analysis and Design Considerations for Service-Oriented Applications //=============================================================================================== // Customer is part of the SQLServer DAL for StockTrader. This is called from the // BSL to execute commands against the database. It is constructed to use one SqlConnection per // instance. Hence, BSLs that use this DAL should always be instanced properly. // The DAL will work with both ADO.NET and System.Transactions or ServiceComponents/Enterprise // Services attributed transactions [autocomplete]. When using ADO.NET transactions, // The BSL will control the transaction boundaries with calls to dal.BeginTransaction(); // dal.CommitTransaction(); dal.RollbackTransaction(). //=============================================================================================== //====================================================================================================== // Code originally contributed by Microsoft Corporation. // This contribution to the Stonehenge project is limited strictly // to the source code that is submitted in this submission. // Any technology, including underlying platform technology, // that is referenced or required by the submitted source code // is not a part of the contribution. // For example and not by way of limitation, // any systems/Windows libraries (WPF, WCF, ASP.NET etc.) // required to run the submitted source code is not a part of the contribution //====================================================================================================== using System; using System.Collections.Generic; using System.Text; using System.Data; using MySql.Data.MySqlClient; using MySql.Data.Types; using Trade.PassiveStsIDal; using Trade.PassiveStsModelClasses; using Trade.Utility; namespace Trade.PassiveStsDalMySql { public class Customer : ICustomer { public Customer() { } //Constructor for internal DAL-DAL calls to use an existing DB connection. public Customer(MySqlConnection conn, MySqlTransaction trans) { _internalConnection = conn; } private MySqlConnection _internalConnection; public void Open(string connString) { if (_internalConnection == null) _internalConnection = new MySqlConnection(connString); if (_internalConnection.State != ConnectionState.Open) _internalConnection.Open(); } public void Close() { if (_internalConnection != null && _internalConnection.State != ConnectionState.Closed) _internalConnection.Close(); } private const string SQL_SELECT_CUSTOMERPROFILE_BYUSERID = "SELECT accountprofile.USERID, accountprofile.PASSWORD FROM accountprofile WHERE accountprofile.USERID = ?UserId"; //Parameters private const string PARM_USERID = "?UserId"; public AccountDataModel login(string userid, string password) { try { MySqlParameter parm1 = new MySqlParameter(PARM_USERID, MySqlDbType.VarChar, 20); parm1.Value = userid; MySqlDataReader rdr = MySQLHelper.ExecuteReaderSingleRowSingleParm(_internalConnection, null, CommandType.Text, SQL_SELECT_CUSTOMERPROFILE_BYUSERID, parm1); if (rdr.Read()) { string userPassword = rdr.GetString(1); rdr.Close(); if (userPassword.Equals(password)) { AccountDataModel customer = new AccountDataModel(userid); return customer; } rdr.Close(); } return null; } catch { throw; } } } }