Exemple #1
0
        private object PurgeAll(DateTime deleteDate, BackgroundWorker worker, DoWorkEventArgs e)
        {
            (new CommonManager()).BeginBatchOperation();
            TransactionManager tm = new TransactionManager();
            //get a list of all customers
            List <Customer> customers = (new CustomerManager()).GetAllCustomers();

            foreach (Customer customer in customers)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                }
                else
                {
                    worker.ReportProgress((int)((double)customers.IndexOf(customer) / (double)customers.Count * 100.0), "Deleting Sale/Purchase data of " + customer.Name);
                    tm.DeleteAllTransactionsBefore(customer.ID, deleteDate, true);
                }
            }
            //now delete expenses till the date..
            ExpenseManager em       = new ExpenseManager();
            List <Expense> expenses = em.GetExpenses(new DateTime(1900, 1, 1), deleteDate);

            foreach (Expense expense in expenses)
            {
                em.DeleteExpenseById(expense.ID);
                worker.ReportProgress((int)((double)expenses.IndexOf(expense) / (double)expenses.Count * 100.0), "Deleting Expense Data of " + expense.TimeStamp.ToShortDateString());
            }
            (new CommonManager()).ConfirmBatchOperation();
            return(null);
        }