/// <summary>
    /// 注册
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="args"></param>
    public void db_register_account(MySqlConnection conn, CustomArgs args)
    {
        HttpListenerResponse response = args.GetParam("response") as HttpListenerResponse;
        string            account     = args.GetParam("account") as string;
        string            password    = args.GetParam("password") as string;
        DBStoredProcedCmd cmd         = new DBStoredProcedCmd("PRO_REGISTER_ACCOUNT", conn);

        cmd.AddParamVChar("account", account, account.Length);
        cmd.AddParamVChar("password", password, password.Length);
        string md5 = LibServer.Utility.Security.MD5(account + password + DateTime.Now.ToString());

        cmd.AddParamVChar("token", md5, md5.Length);
        cmd.AddOutParamInt("errcode");
        cmd.AddOutParamText("errmsg", LOGIN_DEFINE.VAR_CHAR_LENGHT_255);
        int bsuc = cmd.Execute();

        if (bsuc == 0)
        {
            RES_Common res = new RES_Common();
            res.errcode = (int)cmd.GetParam("errcode").Value;

            res.errmsg = cmd.GetParam("errmsg").Value as string;

            send(JsonConvert.SerializeObject(res), response);
            return;
            // 注册成功;
        }
        else
        {
            throw new Exception("执行存储过程 PRO_REGISTER_ACCOUNT 失败!");
        }
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="args"></param>
    public void db_login_account(MySqlConnection conn, CustomArgs args)
    {
        HttpListenerResponse response = args.GetParam("response") as HttpListenerResponse;
        string account  = args.GetParam("account") as string;
        string password = args.GetParam("password") as string;

        if (response == null)
        {
            return;
        }
        DBStoredProcedCmd cmd = new DBStoredProcedCmd("PRO_LOGIN_ACCOUNT", conn);

        cmd.AddParamVChar("account", account, account.Length);
        cmd.AddParamVChar("password", password, password.Length);
        string md5 = LibServer.Utility.Security.MD5(account + password + DateTime.Now.ToString());

        cmd.AddParamVChar("token", md5, md5.Length);
        cmd.AddOutParamInt("errcode");
        cmd.AddOutParamText("errmsg", LOGIN_DEFINE.VAR_CHAR_LENGHT_255);
        int bsuc = cmd.Execute();

        if (bsuc == 0)
        {
            int    nErrCode   = (int)cmd.GetParam("errcode").Value;
            string err_string = cmd.GetParam("errmsg").Value as string;
            if (nErrCode != 0)
            {
                RES_Common res = new RES_Common();
                res.errcode = nErrCode;
                res.errmsg  = err_string;
                send(JsonConvert.SerializeObject(res), response);
            }
            else
            {
                // 账号密码校验成功, 返回登录token
                RES_LoginSuc res = new RES_LoginSuc();
                res.errcode    = 0;
                res.errmsg     = "";
                res.token      = cmd.GetValue(0, "token") as string;;
                res.tokenstamp = (System.DateTime)cmd.GetValue(0, "tokenstamp");
                send(JsonConvert.SerializeObject(res), response);
            }
        }
        else
        {
            throw new Exception("执行存储过程 PRO_LOGIN_ACCOUNT 失败!");
        }
    }
Exemple #3
0
        static void Main(string[] args)
        {
            #region

            /*
             * Thread thread = new Thread(() =>
             * {
             *  while (true)
             *  {
             *      for (int i = 0; i < 2; i++)
             *      {
             *          DBhandler.addTask("select * from t_users where userid = 10", (MySqlDataReader reader, Object o) =>
             *          {
             *              while (reader.Read())
             *              {
             *                  int excuteIndex = (int)o;
             *                  string str = "";
             *                  for (int j = 0; j < reader.FieldCount; j++)
             *                  {
             *                      str += "-" + reader[j].ToString();
             *                  }
             *
             *                  Console.WriteLine(excuteIndex + " =====>" + str);
             *              }
             *          }, actionCount++);
             *      }
             *      Thread.Sleep(100);
             *  }
             * });
             * thread.Start();
             *
             * Thread thread2 = new Thread(() =>
             * {
             *  while (true)
             *  {
             *      for (int i = 0; i < 2; i++)
             *      {
             *          DBhandler1.addTask("select * from t_users where userid = 9", (MySqlDataReader reader, Object o) =>
             *          {
             *              while (reader.Read())
             *              {
             *                  int excuteIndex = (int)o;
             *                  string str = "";
             *                  for (int j = 0; j < reader.FieldCount; j++)
             *                  {
             *                      str += "-" + reader[j].ToString();
             *                  }
             *
             *                  Console.WriteLine(excuteIndex + " =====>" + str);
             *              }
             *          }, actionCount++);
             *      }
             *      Thread.Sleep(100);
             *  }
             * });
             * thread2.Start();
             *
             * Thread thread3 = new Thread(() =>
             * {
             *  while (true)
             *  {
             *      for (int i = 0; i < 2; i++)
             *      {
             *          DBhandler2.addTask("select * from t_users where userid = 9", (MySqlDataReader reader, Object o) =>
             *          {
             *              while (reader.Read())
             *              {
             *                  int excuteIndex = (int)o;
             *                  string str = "";
             *                  for (int j = 0; j < reader.FieldCount; j++)
             *                  {
             *                      str += "-" + reader[j].ToString();
             *                  }
             *
             *                  Console.WriteLine(excuteIndex + " =====>" + str);
             *              }
             *          }, actionCount++);
             *      }
             *      Thread.Sleep(100);
             *  }
             * });
             * thread3.Start();
             */
            #endregion

            #region
            MySqlConnection conn = DBConnPool.Instance.GetConn("Database=nodejs;Data Source=127.0.0.1;Port=3306;User Id=root;Password=000000;Charset=utf8;TreatTinyAsBoolean=false;");
            conn.Open();
            DBStoredProcedCmd cmd = new DBStoredProcedCmd("select_users", conn);
            cmd.AddParam("user_id", 9);
            cmd.Execute();

            for (int i = 0; i < cmd.DataResult().Rows.Count; i++)
            {
                Console.WriteLine("columsindex = " + i + "values ==>");
                string value = String.Empty;
                value += cmd.DataResult().Rows[i]["userid"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["account"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["name"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["sex"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["headimg"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["lv"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["exp"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["coins"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["gems"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["roomid"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["name"].ToString() + '\t';
                value += cmd.DataResult().Rows[i]["history"].ToString() + '\t';
                Console.WriteLine(value);
            }


            #endregion

            Console.ReadKey();
        }