Esempio n. 1
0
        public void Fill(int indexFrom, int limiCount, NewsStatusGroup newsStatusGroup)
        {
            FillNews(indexFrom, limiCount, newsStatusGroup);
            var newsIdsArray = GetNewsIds();

            FillComments(newsIdsArray);
            var commentsIdsArray = GetCommentsIds();

            FillAttachments(newsIdsArray);
            FillCommentsAttachments(commentsIdsArray);
        }
Esempio n. 2
0
        private void FillNewsStatusGroups()
        {
            _newsStatusGroups.Clear();

            const string sqlCommandText = @"SELECT NewsStatusGroupID, NewsStatusGroupName 
                                            FROM FAIINewsFeed.NewsStatusGroups";

            using (var sqlConn = new MySqlConnection(_connectionString))
            {
                var sqlCommand = new MySqlCommand(sqlCommandText, sqlConn);

                try
                {
                    sqlConn.Open();
                    using (var sqlReader = sqlCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            int newsStatusGroupId;
                            Int32.TryParse(sqlReader["NewsStatusGroupID"].ToString(), out newsStatusGroupId);
                            var newsStatusGroupName = sqlReader["NewsStatusGroupName"].ToString();

                            var newsStatusesForGroup =
                                NewsStatuses.Where(ns => ns.NewsStatusGroupId == newsStatusGroupId);
                            var statusesForGroup = newsStatusesForGroup as List <NewsStatus> ??
                                                   newsStatusesForGroup.ToList();

                            var newsStatusGroup = new NewsStatusGroup(newsStatusGroupId, newsStatusGroupName)
                            {
                                NewsStatuses = statusesForGroup
                            };
                            _newsStatusGroups.Add(newsStatusGroup);
                        }
                    }
                }
                catch (MySqlException)
                {
                }
                finally
                {
                    sqlConn.Close();
                    sqlCommand.Dispose();
                }
            }
        }
Esempio n. 3
0
        private void FillNews(int indexFrom, int limitCount, NewsStatusGroup newsStatusGroup)
        {
            var filter = GetFilterString(newsStatusGroup);

            var sqlCommandText =
                @"SELECT NewsID, NewsDate, NewsText, NewsStatus, WorkerID, GlobalID, LastEditing, ProdStatusID 
                  FROM FAIINewsFeed.NewsFeed " + filter +
                " ORDER BY LastEditing DESC, NewsDate DESC limit " + indexFrom + "," + limitCount;

            _newsAdapter = new MySqlDataAdapter(sqlCommandText, _connectionString);
            new MySqlCommandBuilder(_newsAdapter);
            try
            {
                _news = new DataTable();
                _newsAdapter.Fill(_news);
            }
            catch (MySqlException)
            {
            }
        }
Esempio n. 4
0
        public int GetNewsCount(NewsStatusGroup showAllGroup)
        {
            var rowsCount = 0;
            var filter    = GetFilterString(showAllGroup);

            var sql = "SELECT COUNT(*) FROM FAIINewsFeed.NewsFeed " + filter;

            using (var conn = new MySqlConnection(_connectionString))
            {
                var cmd = new MySqlCommand(sql, conn);
                try
                {
                    conn.Open();
                    rowsCount = Convert.ToInt32(cmd.ExecuteScalar());
                    conn.Close();
                }
                catch (MySqlException)
                {
                }
            }
            return(rowsCount);
        }
Esempio n. 5
0
        private string GetFilterString(NewsStatusGroup newsStatusGroup)
        {
            var newsStatusIds = newsStatusGroup.NewsStatuses.Any()
                ? (newsStatusGroup.NewsStatuses
                   .Aggregate(string.Empty, (current, newsStatus) => current + ", " + newsStatus.NewsStatusId))
                                .Remove(0, 2)
                : "-1";
            var filterString = string.Format("WHERE NewsStatus IN ({0})", newsStatusIds);

            // Return all messages if user is administrator
            if (AdministrationClass.IsAdministrator)
            {
                return(filterString);
            }

            if (newsStatusGroup.NewsStatusGroupId == 2)
            {
                var fullAccess = AdministrationClass.HasFullAccess(AdministrationClass.Modules.WorkerRequests);
                if (!fullAccess)
                {
                    // Get news statuses without worker requests
                    newsStatusIds = newsStatusGroup.NewsStatuses.Where(newsStatus => newsStatus.NewsStatusId != 9).Any()
                    ? (newsStatusGroup.NewsStatuses.Where(newsStatus => newsStatus.NewsStatusId != 9)
                       .Aggregate(string.Empty, (current, newsStatus) => current + ", " + newsStatus.NewsStatusId))
                                    .Remove(0, 2)
                    : "-1";

                    filterString = string.Format("WHERE (NewsStatus IN ({0})", newsStatusIds);

                    // Get personal worker requests
                    var workerRequestsGlobalIdsString = GetPersonalWorkerRequestsGlobalIds();
                    filterString += " OR GlobalID IN (" + workerRequestsGlobalIdsString + "))";
                }

                // Geting available production statuses for worker
                //var workerGroups = GetWorkerGroupsIds(AdministrationClass.CurrentWorkerId);
                //if(workerGroups.All(g => g != 1))
                //{
                var workerProdStatuses = GetWorkerProdStatuses(AdministrationClass.CurrentWorkerId);
                if (workerProdStatuses.Any())
                {
                    var workerProdStatusesString = workerProdStatuses.Aggregate(string.Empty, (current, prodStatus) => current + ", " + prodStatus).Remove(0, 2);
                    filterString += " AND (ProdStatusID IN (" + workerProdStatusesString + ") OR ProdStatusID IS NULL)";
                }
                else
                {
                    filterString += " AND ProdStatusID IS NULL";
                }
                //}
            }

            if (newsStatusGroup.NewsStatusGroupId == 3)
            {
                // Get GlobalIds of personal messages

                var globalIdsString = GetPersonalTasksGlobalIds();

                filterString += " AND GlobalID IN (" + globalIdsString + ")";
            }

            return(filterString);
        }