public string GetAll()
        {
            int          code = 1; int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();
            string       sql          = string.Format(@"select * from  Site  ");
            DataTable    dt           = MySqlHelper.GetDataSetNoP(CommandType.Text, sql).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);
        }
Example #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 * 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);
        }
        public string AddArticle(string jsons)
        {
            int          code = 1; int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();


            if (string.IsNullOrEmpty(jsons))
            {
                code = 1; status = 200;  message = "传递参数不能为空";
                // data.data = "{\"Message\":\"传递参数不能为空!\"}";
                data.data            = message;
                data.code            = code;
                responseInfo.status  = status;
                responseInfo.data    = data;
                responseInfo.message = message;
                // return "{\"status\":\"-1\",\"Message\":\"传递参数不能为空!\"}";
                return(JsonConvert.SerializeObject(responseInfo));
            }
            try
            {
                ArticleInfo      info      = JsonConvert.DeserializeObject <ArticleInfo>(jsons);
                string           sql       = string.Format(@"insert into Article(Title,Summary,Contents,Images,Keywords,Description,ClassifyID,SiteID,UserID,Status,Label,CreateTime)
VALUES ('{0}','{1}','{2}','{3}'.'{4}','{5}',{6},{7},{8},{9},'{10}',now())", info.Title, info.Summary, info.Contents, info.Images, info.Keywords, info.Description, info.ClassifyID, info.SiteID, info.ClassifyID, info.SiteID, 1, info.Label);
                MySqlParameter[] sqlparams = { new MySqlParameter("Title",      info.Title),      new MySqlParameter("Summary",  info.Summary),  new MySqlParameter("Contents",    info.Contents),
                                               new MySqlParameter("Images",     info.Images),     new MySqlParameter("Keywords", info.Keywords), new MySqlParameter("Description", info.Description),
                                               new MySqlParameter("ClassifyID", info.ClassifyID), new MySqlParameter("SiteID",   info.SiteID),   new MySqlParameter("UserID",      info.UserID),
                                               new MySqlParameter("Status",     info.Status),     new MySqlParameter("Label",    info.Label),    new MySqlParameter("CreateTime",  info.CreateTime) };

                int i = MySqlHelper.ExecuteNonQuery(CommandType.Text, sql, sqlparams);
                if (i > 0)
                {
                    message = "成功";
                    //return "{\"status\":\"1\",\"Message\":\"添加成功!\"}";
                }
                else
                {
                    code = 0; status = 200; message = "添加失败";
                    // return "{\"status\":\"0\",\"Message\":\"添加失败!\"}";
                }
            }
            catch (Exception ex)
            {
                code = 0; status = 500; message = "服务器内部错误:" + ex.Message;
                //return "{\"status\":\"-2\",\"Message\":\"异常:\"" + ex.Message + "}";
                //throw;
            }

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

            return(JsonConvert.SerializeObject(responseInfo));
        }
        public string Add(string jsons)
        {
            int          code = 1; int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();


            if (string.IsNullOrEmpty(jsons))
            {
                code = 1; status = 200; message = "传递参数不能为空";
                // data.data = "{\"Message\":\"传递参数不能为空!\"}";
                data.data            = message;
                data.code            = code;
                responseInfo.status  = status;
                responseInfo.data    = data;
                responseInfo.message = message;
                // return "{\"status\":\"-1\",\"Message\":\"传递参数不能为空!\"}";
                return(JsonConvert.SerializeObject(responseInfo));
            }
            try
            {
                SiteInfo         info      = JsonConvert.DeserializeObject <SiteInfo>(jsons);
                string           sql       = string.Format(@"insert into Site(SiteName,CreateTime)
VALUES ('{0}',now())", info.SiteName, info.CreateTime);
                MySqlParameter[] sqlparams = { new MySqlParameter("SiteName", info.SiteName), new MySqlParameter("CreateTime", info.CreateTime) };

                int i = MySqlHelper.ExecuteNonQuery(CommandType.Text, sql, sqlparams);
                if (i > 0)
                {
                    message = "成功";
                    //  return "{\"status\":\"1\",\"Message\":\"添加成功!\"}";
                }
                else
                {
                    code = 0; status = 200; message = "添加失败";
                    // return "{\"status\":\"0\",\"Message\":\"添加失败!\"}";
                }
            }
            catch (Exception ex)
            {
                code = 0; status = 500; message = "服务器内部错误:" + ex.Message;
                //return "{\"status\":\"-2\",\"Message\":\"异常:\"" + ex.Message + "}";
                //throw;
            }

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

            return(JsonConvert.SerializeObject(responseInfo));
        }
Example #5
0
        public string Add(string jsons)
        {
            int          code = 1; int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();

            if (string.IsNullOrEmpty(jsons))
            {
                code = 1; status = 200; message = "传递的参数不能为空";
                //return "{\"status\":\"-1\",\"Message\":\"传递的参数不能为空!\"}";
            }
            else
            {
                try
                {
                    ClassifyInfo   info       = JsonConvert.DeserializeObject <ClassifyInfo>(jsons);
                    string         sql        = string.Format(@"insert into Classify(ClassifyName,CreateTime)values('{0}',now())", info.ClassifyName);
                    MySqlParameter parameters = new MySqlParameter("ClassifyName", info.ClassifyName);
                    int            i          = MySqlHelper.ExecuteNonQuery(CommandType.Text, sql, parameters);
                    if (i > 0)
                    {
                        code = 1; status = 200; message = "添加分类成功";
                        //  return "{\"status\":\"1\",\"Message\":\"添加分类成功!\"}";
                    }
                    else
                    {
                        code = 0; status = 200; message = "添加分类失败";
                        // return "{\"status\":\"0\",\"Message\":\"添加分类失败!\"}";
                    }
                }
                catch (Exception ex)
                {
                    code = 0; status = 500; message = "服务器内部错误:" + ex.Message;
                    //return "{\"status\":\"-2\",\"Message\":\"异常:\"" + ex.Message + "}";
                    //throw;
                }
            }
            data.code            = code;
            data.data            = message;
            responseInfo.status  = status;
            responseInfo.data    = data;
            responseInfo.message = message;
            return(JsonConvert.SerializeObject(responseInfo));
        }
Example #6
0
        public string Edit(string jsons)
        {
            int          code = 1; int status = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();

            if (string.IsNullOrEmpty(jsons))
            {
                message = "传递的参数不能为空";
                // return "{\"status\":\"-1\",\"Message\":\"传递的参数不能为空!\"}";
            }
            else
            {
                try
                {
                    ClassifyInfo     info            = JsonConvert.DeserializeObject <ClassifyInfo>(jsons);
                    string           sql             = string.Format(@"update Classify set ClassifyName='{1}' where ClassifyID={0}", info.ClassifyID, info.ClassifyName);
                    MySqlParameter[] mySqlParameters = { new MySqlParameter("ClassifyID", info.ClassifyID), new MySqlParameter("ClassifyName", info.ClassifyName) };
                    int i = MySqlHelper.ExecuteNonQuery(CommandType.Text, sql, mySqlParameters);
                    if (i > 0)
                    {
                        code = 1; status = 200; message = "编辑分类成功";
                        // return "{\"status\":\"1\",\"Message\":\"编辑分类成功!\"}";
                    }
                    else
                    {
                        code = 0; status = 200; message = "编辑分类失败";
                        // return "{\"status\":\"0\",\"Message\":\"编辑分类失败!\"}";
                    }
                }
                catch (Exception ex)
                {
                    code = 0; status = 500; message = "服务器内部错误:" + ex.Message;;
                    //return "{\"status\":\"-2\",\"Message\":\"异常:\"" + ex.Message + "}";
                    //throw;
                }
            }
            data.code            = code;
            data.data            = message;
            responseInfo.status  = status;
            responseInfo.data    = data;
            responseInfo.message = message;
            return(JsonConvert.SerializeObject(responseInfo));
        }
        public string UpdateArticleStatus(int id, int status)
        {
            int          code = 1; int statusStr = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();

            if (string.IsNullOrEmpty(id.ToString()))
            {
                code                 = 1; statusStr = 200; message = "传递参数不能为空";
                data.data            = "{\"Message\":\"传递参数不能为空!\"}";
                data.code            = code;
                responseInfo.status  = statusStr;
                responseInfo.data    = data;
                responseInfo.message = message;
                // return "{\"status\":\"-1\",\"Message\":\"传递参数不能为空!\"}";
                return(JsonConvert.SerializeObject(responseInfo));
                //return "{\"status\":\"-1\",\"Message\":\"传递的参数不能为空!\"}";
            }

            base.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");//允许跨域
            string idParam = base.HttpContext.Request.Query["id"];
            string sql     = string.Format(@"update Article set Status={1} where ArticleID={0}", id, status);

            MySqlParameter[] sqlParameters = { new MySqlParameter("Status", status), new MySqlParameter("ArticleID", id) };
            int i = MySqlHelper.ExecuteNonQuery(CommandType.Text, sql, sqlParameters);

            if (i > 0)
            {
                code = 1; statusStr = 200; message = "更改文章状态成功";
                //  return "{\"status\":\"1\",\"Message\":\"更改文章状态成功!\"}";
            }
            else
            {
                code = 0; statusStr = 200; message = "更改文章状态失败";
                // return "{\"status\":\"0\",\"Message\":\"更改文章状态失败!\"}";
            }
            data.code            = code;
            data.data            = message;
            responseInfo.status  = statusStr;
            responseInfo.data    = data;
            responseInfo.message = message;
            return(JsonConvert.SerializeObject(responseInfo));
        }
        public string Delete(string jsons)
        {
            int          code = 1; int statusStr = 200; string message = "成功";
            ResponseInfo responseInfo = new Models.ResponseInfo();
            Data         data         = new Data();

            if (string.IsNullOrEmpty(jsons.ToString()))
            {
                code                 = 1; statusStr = 200; message = "传递参数不能为空";
                data.data            = "{\"Message\":\"传递参数不能为空!\"}";
                data.code            = code;
                responseInfo.status  = statusStr;
                responseInfo.data    = data;
                responseInfo.message = message;
                return(JsonConvert.SerializeObject(responseInfo));
            }
            SiteInfo info = JsonConvert.DeserializeObject <SiteInfo>(jsons);

            string sql = string.Format(@"delete  Site   where SiteID={0}", info.SiteID);

            MySqlParameter[] sqlParameters = { new MySqlParameter("SiteID", info.SiteID) };
            int i = MySqlHelper.ExecuteNonQuery(CommandType.Text, sql, sqlParameters);

            if (i > 0)
            {
                code = 1; statusStr = 200; message = "删除站点成功";
                //  return "{\"status\":\"1\",\"Message\":\"更改文章状态成功!\"}";
            }
            else
            {
                code = 0; statusStr = 200; message = "删除站点失败";
                // return "{\"status\":\"0\",\"Message\":\"更改文章状态失败!\"}";
            }
            data.code            = code;
            data.data            = message;
            responseInfo.status  = statusStr;
            responseInfo.data    = data;
            responseInfo.message = message;
            return(JsonConvert.SerializeObject(responseInfo));
        }
        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);
        }
Example #10
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));
        }