예제 #1
0
        public string GetID(int id)
        {
            int          code = 1; int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();

            base.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");//允许跨域
            //throw new Exception("1234567");
            string         idParam = base.HttpContext.Request.Query["id"];
            string         sql     = string.Format(@"select * from  User where UserID={0}", idParam);
            MySqlParameter param   = new MySqlParameter("ArticleID", MySqlDbType.Int32);
            DataTable      dt      = MySqlHelper.GetDataSet(CommandType.Text, sql, param).Tables[0];

            if (dt == null)
            {
                code      = 1; message = "数据集为空";
                data.data = message;
            }
            else
            {
                data.data = JsonHelper.DataTableToJson(dt);
            }
            data.code = code;

            responseInfo.status  = status;
            responseInfo.data    = data;
            responseInfo.message = message;

            string strJson = JsonConvert.SerializeObject(responseInfo);

            return(strJson);
        }
예제 #2
0
        public string GetID(int id)
        {
            int          code = 1;  int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();

            base.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");//允许跨域
            //throw new Exception("1234567");
            string         idParam = base.HttpContext.Request.Query["id"];
            string         sql     = string.Format(@"select a.*, (select UserName from `User` where UserID = a.UserID) AS UserName,
   (SELECT ClassifyName FROM Classify WHERE ClassifyID = a.ClassifyID)as ClassifyName,
(select SiteName from Site where SiteID = a.SiteID) as SiteName
 from Article as a where ArticleID = {0}   ", idParam);
            MySqlParameter param   = new MySqlParameter("ArticleID", MySqlDbType.Int32);
            DataTable      dt      = MySqlHelper.GetDataSet(CommandType.Text, sql, param).Tables[0];

            if (dt == null)
            {
                code      = 1; message = "数据集为空";
                data.data = message;
            }
            else
            {
                data.data = JsonHelper.DataTableToJson(dt);
            }

            data.code = code;

            responseInfo.status  = status;
            responseInfo.data    = data;
            responseInfo.message = message;

            string strJson = JsonConvert.SerializeObject(responseInfo);

            // responseInfo.data = List<ExtendMethod.ToDataList<ArticleInfo>(dt)>;
            return(strJson);
        }
예제 #3
0
        public string Login(string json)
        {
            int          code = 1; int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();


            if (string.IsNullOrEmpty(json))
            {
                code = 1; status = 200; message = "传递参数不能为空";
                // data.data = "{\"Message\":\"传递参数不能为空!\"}";
                data.data = message;
            }
            else
            {
                UserInfo         info      = JsonConvert.DeserializeObject <UserInfo>(json);
                string           sql       = string.Format(@"select * from User where UserName='******' and  Password='******'");
                MySqlParameter[] sqlparams = { new MySqlParameter("UserName", info.UserName), new MySqlParameter("Password", info.Password) };
                DataTable        dt        = MySqlHelper.GetDataSet(CommandType.Text, sql, sqlparams).Tables[0];
                if (dt.Columns.Count > 0)
                {
                    //登录成功!
                    code = 1; status = 200; message = "登录成功!";
                }
                else
                {
                    code = 0; status = 200; message = "登录失败!";
                }
            }
            data.code            = code;
            data.data            = message;
            responseInfo.status  = status;
            responseInfo.data    = data;
            responseInfo.message = message;
            return(JsonConvert.SerializeObject(responseInfo));
        }