예제 #1
0
        public string GetNewGameListstr(string mWhereStr)
        {
            string mSql = "";
            //string mCSql = "";
            string mWhere = "";

            mSql = string.Format("SELECT * FROM tb_game ");
            //mCSql = string.Format("SELECT count(0) FROM tb_game where 1=1");
            if (mWhereStr != "")
            {
                mWhereStr = mWhereStr.Replace("year", "Year([buydate])");
                string[] mWhereArr = mWhereStr.Split(';');
                foreach (string War in mWhereArr)
                {
                    if (War.Split(':')[0] == "name")
                    {
                        mWhere += " and " + War.Split(':')[0] + " like '%" + War.Split(':')[1] + "%'";
                    }
                    else
                    {
                        mWhere += " and " + War.Split(':')[0] + " = '" + War.Split(':')[1] + "'";
                    }
                }
            }
            //mWhere = string.Format(" and console = '{0}'", console);
            mSql += mWhere + " order by tb_game.buydate desc";
            //mCSql += mWhere;
            //cmd.CommandText = mSql;
            //conn.Open();
            //connCount.Open();
            DataTable dt = new DataTable();

            dt = sh.getDT(mSql);
            string        result = "";
            StringBuilder sb     = new StringBuilder();

            result = sb.ToString();

            if (dt.Rows.Count > 0)
            {
                sb.Append("[");
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append("{");
                    sb.Append("\"id\": \"" + dr["id"].ToString() + "\",");
                    sb.Append("\"console\": \"" + dr["console"].ToString() + "\",");
                    sb.Append("\"name\": \"" + dr["name"].ToString() + "\",");
                    sb.Append("\"price\": \"" + dr["price"].ToString() + "\",");
                    sb.Append("\"buydate\": \"" + Convert.ToDateTime(dr["buydate"]).ToString("yyyy-MM-dd") + "\"");
                    sb.Append("},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("]");
            }
            //cmdCount.CommandText = mCSql;
            //string DCounts = sh.GetString(mCSql); // cmdCount.ExecuteScalar().ToString();


            result = sb.ToString();// + "&" + DCounts;

            return(result);
        }