using System; using System.Collections.Generic; using System.Data; using System.Data.OracleClient; using System.Linq; using System.Text; namespace PaysysInterfaceTest { public class PaysysBase { public OracleConnection conn = null; public OracleCommand cmd = null; /// <summary> /// 数据库初始化 /// </summary> /// <param name="DataSource">数据库源(Orlacle Client下的tnsnames.ora配置</param> /// <param name="DataUserId">数据库登录名</param> /// <param name="DataPassword">数据库登录密码</param> /// <returns></returns> public int PaysysInit(string DataSource, string DataUserId, string DataPassword) { var mConn = string.Format("Data Source={0};User Id={1};Password={2};", DataSource, DataUserId, DataPassword); conn = new OracleConnection(mConn); try { conn.Open(); cmd = new OracleCommand(); cmd.Connection = conn; } catch (Exception ex) { return 0; } return 1; } /// <summary> /// 调用的存储过程 /// </summary> /// <param name="interfaceName">存储过程名称</param> /// <returns></returns> public int CallInterface(string interfaceName) { var nResult = 0; var queryString = interfaceName; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = queryString; try { cmd.ExecuteNonQuery(); Console.WriteLine("Query Success!!"); nResult = Convert.ToInt32(cmd.Parameters["result"].Value); } catch (Exception ex) { Console.WriteLine("Query Error!!\r\n" + ex.Message); nResult = Convert.ToInt32(cmd.Parameters["result"].Value); ; } finally { cmd.Clone(); conn.Close(); Console.WriteLine("Close Db"); } return nResult; } } public class PlayerLogin : PaysysBase { public string s_account = ""; public string s_password = ""; /// <summary> /// 存储过程初始化参数 /// </summary> /// <param name="account">用户账号</param> /// <param name="password">用户密码</param> public void LoginInit(string account, string password) { s_account = account; s_password = password; InitParam(); } /// <summary> /// 初始化信息 /// </summary> private void InitParam() { //反回值 cmd.Parameters.Add("result", OracleType.Float); cmd.Parameters["result"].Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add("s_account", OracleType.VarChar); cmd.Parameters["s_account"].Direction = ParameterDirection.Input; cmd.Parameters["s_account"].Value = s_account; cmd.Parameters.Add("s_password", OracleType.VarChar); cmd.Parameters["s_password"].Direction = ParameterDirection.Input; cmd.Parameters["s_password"].Value = s_password; //==================out================== cmd.Parameters.Add("d_login_time", OracleType.DateTime); cmd.Parameters["d_login_time"].Direction = ParameterDirection.Output; cmd.Parameters.Add("d_last_login_time", OracleType.DateTime); cmd.Parameters["d_last_login_time"].Direction = ParameterDirection.Output; cmd.Parameters.Add("d_last_logout_time", OracleType.DateTime); cmd.Parameters["d_last_logout_time"].Direction = ParameterDirection.Output; } |