Exemplo n.º 1
0
    // Start 0000069, KuangWei, 2014-08-26
    public void loadPayGroups()
    {
        DBFilter  filter = new DBFilter();
        DataTable table  = EPayrollGroup.db.loadDataSet(dbConn, null, filter);
        DataView  view   = new DataView(table);

        PayGroups.DataSource = view;
        PayGroups.DataBind();
    }
Exemplo n.º 2
0
        //
        // ────────────────────────────────────────────────────────────────────────────────────
        //   :::::: P R I V A T E   F U N C T I O N S : :  :   :    :     :        :          :
        // ────────────────────────────────────────────────────────────────────────────────────
        //

        /// <summary>
        /// Update the football data in the database, pay the fb to the groups,
        /// do the weekly pay to the groups, remove the expired user session tokens,
        /// remove completely the users who wants to remove his account and clean the chat history
        /// </summary>
        /// <param name="state">A state object</param>
        private async void DoWork(object state)
        {
            //TODO initialize the database
            using (var scope = _scopeFactory.CreateScope())
            {
                try
                {
                    //Get the database context and the notification context
                    var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDBContext>();


                    //Initialize & update football data
                    InitializerVirtualDB initializer = new InitializerVirtualDB(dbContext, _configuration, _http);

                    await initializer.InitializeAsync("PL");

                    await initializer.InitializeAsync("PD");

                    await initializer.InitializeAsync("BL1");

                    await initializer.InitializeAsync("SA");

                    await initializer.InitializeAsync("FL1");
                }
                catch (Exception)
                {
                    //Restart the timer
                    _timer?.Change(nextTime(0), new TimeSpan(1, 0, 0, 0));
                }
            }

            //TODO initialize the database
            using (var scope = _scopeFactory.CreateScope())
            {
                try
                {
                    //Get the database context and the notification context
                    var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDBContext>();
                    var hub       = scope.ServiceProvider.GetRequiredService <IHubContext <NotificationHub> >();

                    // Pay the bets
                    dbContext.FootballBets.Where(fb => !fb.ended && !fb.cancelled).ToList().ForEach(bet =>
                    {
                        dbContext.Entry(bet).Reference("MatchDay").Load();
                        if (bet.MatchDay.status == "FINISHED")
                        {
                            CheckWinners.checkWinner(bet, dbContext, hub);
                            bet.ended = true;
                            dbContext.SaveChanges();
                        }
                    });
                }
                catch (Exception)
                {
                    //Restart the timer
                    _timer?.Change(nextTime(0), new TimeSpan(1, 0, 0, 0));
                }
            }

            //TODO initialize the database
            using (var scope = _scopeFactory.CreateScope())
            {
                try
                {
                    //Get the database context and the notification context
                    var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDBContext>();
                    var hub       = scope.ServiceProvider.GetRequiredService <IHubContext <NotificationHub> >();

                    //Remove session tokens
                    RemoveSessionTokens.remove(dbContext);

                    //Pay weekly coins
                    PayGroups.pay(dbContext, hub);

                    //Fully remove users
                    FullyRemoveUsers.remove(dbContext);

                    //Clean chats
                    CleanChats.clean(dbContext);
                }
                catch (Exception)
                {
                    //Restart the timer
                    _timer?.Change(nextTime(0), new TimeSpan(1, 0, 0, 0));
                }
            }

            //Re send the timer
            _timer = new Timer(
                DoWork,
                null,
                nextTime(0),
                new TimeSpan(1, 0, 0, 0) //The next day
                );
        }