public IHttpActionResult TestSelect(ReportAdd report)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequestError(ModelState));
            }
            if (string.IsNullOrEmpty(report.query))
            {
                return(BadRequest("Query is empty"));
            }
            DataSet data = DBConnection.GetQuery(@"SELECT [id]
                                                          ,[name]
                                                          ,[server]
                                                          ,[db]
                                                          ,[login]
                                                          ,[password]
                                                          ,[typeId]
                                                      FROM [ReportServer].[dbo].[Source]
                                                      where [id] = " + report.source.id);

            if (data == null)
            {
                return(BadRequest("Not connect to DB"));
            }
            string connString = "Data Source=" + data.Tables[0].Rows[0][2].ToString() + ";Initial Catalog=" + data.Tables[0].Rows[0][3].ToString() + ";User ID=" + data.Tables[0].Rows[0][4].ToString() + ";Password="******"";

            data = DBConnection.GetQuery(report.query, connString);
            if (data == null)
            {
                return(BadRequest("Not connect to DB"));
            }
            return(Ok());
        }
        public IHttpActionResult SaveReport(ReportAdd report)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequestError(ModelState));
            }
            if (string.IsNullOrEmpty(report.query))
            {
                return(BadRequest("Query is empty"));
            }
            DataSet data = DBConnection.GetQuery("select count(*) from [ReportServer].[dbo].[Urls] where [url] = '" + report.reportName + "'");

            if (data == null)
            {
                return(BadRequest("Not connect to DB"));
            }
            if (Convert.ToInt32(data.Tables[0].Rows[0][0]) > 0)
            {
                return(BadRequest("This name report is exist"));
            }
            data = DBConnection.GetQuery("select max(id) from [ReportServer].[dbo].[Report]");
            string id = "0";

            if (data.Tables[0].Rows[0][0].ToString() != "")
            {
                id = data.Tables[0].Rows[0][0].ToString();
            }
            data = DBConnection.GetQuery("insert into [ReportServer].[dbo].[Report] values(" + (Convert.ToInt32(id) + 1).ToString() + ",'" + report.query.Replace("'", "''") + "'," + report.source.id + ")");
            if (data == null)
            {
                return(BadRequest("Not connect to DB"));
            }
            data = DBConnection.GetQuery("select max([id]) from [ReportServer].[dbo].[Urls]");
            string idUrl = "0";

            if (data.Tables[0].Rows[0][0].ToString() != "")
            {
                idUrl = data.Tables[0].Rows[0][0].ToString();
            }
            data = DBConnection.GetQuery("insert into [ReportServer].[dbo].[Urls] values (" + (Convert.ToInt32(idUrl) + 1).ToString() + ",'" + report.reportName + "',1," + (Convert.ToInt32(id) + 1).ToString() + ")");
            if (data == null)
            {
                return(BadRequest("Not connect to DB"));
            }
            return(Ok());
        }