예제 #1
0
        //**************************************************************************************************************************************************************//
        public async Task <bool> LoadBankAccountIntoList(DataTable dtBank)
        {
            if (BankAccountObs.Count > 0)
            {
                return(false);
            }
            //This DOES access the Bank/Account Class properties !!!!!
            for (int i = 0; i < dtBank.Rows.Count; ++i)
            {
                BankAccountObs.Add(new BankAccountViewModel
                {
                    Id      = Convert.ToInt32(dtBank.Rows[i][0]),
                    BankNo  = dtBank.Rows[i][1].ToString(),
                    CustNo  = dtBank.Rows[i][2].ToString(),
                    AcType  = Convert.ToInt32(dtBank.Rows[i][3]),
                    Balance = Convert.ToDecimal(dtBank.Rows[i][4]),
                    IntRate = Convert.ToDecimal(dtBank.Rows[i][5]),
                    ODate   = Convert.ToDateTime(dtBank.Rows[i][6]),
                    CDate   = Convert.ToDateTime(dtBank.Rows[i][7]),
                });
            }
            Console.WriteLine($"Sql data loaded into BankAccountObs [{BankAccountObs.Count}] ....");

            return(true);
        }
예제 #2
0
        //**************************************************************************************************************************************************************//
        public async Task LoadBankTask(int mode = -1)
        {
            //Create the one and only dtBank instance if not already there
            if (dtBank == null)
            {
                dtBank = new DataTable();
            }
            else
            {
                dtBank.Clear();
            }
            try
            {
                if (BankAccountObs != null && BankAccountObs.Count > 0)
                {
                    BankAccountObs.Clear();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"BankAccountObs Exception [{ex.Data}\r\n");
            }
            Console.WriteLine($"Starting AWAITED task to load Bank Data via Sql");
            DateTime date = DateTime.Now;

            // THIS ALL WORKS PERFECTLY - THANKS TO VIDEO BY JEREMY CLARKE OF JEREMYBYTES YOUTUBE CHANNEL
#if USETASK
            {
                int?        taskid     = Task.CurrentId;
                DateTime    start      = DateTime.Now;
                Task <bool> DataLoader = FillBankAccountDataGrid();
                DataLoader.ContinueWith
                (
                    task =>
                {
                    LoadBankAccountIntoList(dtBank);
                },
                    TaskScheduler.FromCurrentSynchronizationContext()
                );
                Console.WriteLine($"Completed AWAITED task to load BankAccount  Data via Sql\n" +
                                  $"task =Id is [ {taskid}], Completed status  [{DataLoader.IsCompleted}] in {(DateTime.Now - start)} Ticks\n");
            }
#else
            {
                await FillBankAccountDataGrid();
                await LoadBankAccountObsCollection();

                Task.WaitAll();
            }
#endif
            Mouse.OverrideCursor = Cursors.Arrow;
        }