public string GetGridModel(string query, int idCurrentProject)
        {
            ConnectionDB connect;

            if (User.Identity.IsAuthenticated)
            {
                var connectionsCurrentProject = _serviceConnection.GetConnectionDBs(idCurrentProject);
                connect = connectionsCurrentProject.FirstOrDefault();
            }
            else
            {
                connect = new ConnectionDB
                {
                    DatabaseName = DefaultDatabaseConstants.DatabaseName,
                    LoginDB      = DefaultDatabaseConstants.Login,
                    ServerName   = DefaultDatabaseConstants.ServerName,
                    PasswordDB   = Rijndael.EncryptStringToBytes(DefaultDatabaseConstants.Password)
                };
            }

            var dataTable = new DataTable();

            if (connect != null)
            {
                var connectionString = $"Data source= {connect.ServerName};Initial catalog= {connect.DatabaseName}; UID= {connect.LoginDB}; Password= {Rijndael.DecryptStringFromBytes(connect.PasswordDB)};";

                var resultQuery = SqlExecuteData.SqlReturnDataFromQuery(query, connectionString);

                if (!resultQuery.HasError)
                {
                    dataTable = resultQuery.ResultData;
                }
                else
                {
                    return(JsonConvert.SerializeObject(resultQuery.ErrorText));
                }
            }

            Session["datatableForGrid"] = dataTable;

            var header = (from DataColumn column in dataTable.Columns
                          select new DataGridModel
            {
                Name = column.ColumnName,
                Index = column.ColumnName,
                Sortable = true,
                Align = "center"
            }).ToList();

            if (User.Identity.IsAuthenticated)
            {
                _queryHistoryModel.QueryDate = DateTime.Now;
                _queryHistoryModel.QueryBody = query;
                _queryHistoryModel.ProjectID = idCurrentProject;

                var newQuery = Mapper.Map <QueryHistoryViewModel, QueryHistory>(_queryHistoryModel);
                _serviceQueryHistory.SaveQueryHistory(newQuery);
            }

            return(JsonConvert.SerializeObject(header));
        }
Ejemplo n.º 2
0
 private void ClickMethodRunQuerryCommand()
 {
     ResultTable = SqlExecuteData.SqlReturnDataFromQuery(SqlQuerry, MainWindowData.StringConnect).ResultData;
     OnPropertyChanged("ResultTable");
 }