public static void CheckLedgerBookingCodeClosures(ModelTMSContainer Context, System.Web.UI.Page PageX)
        // Note : in contrast to regular application architecture this method uses its own transactions !!!
        {
            bool     Success             = true;
            DateTime LastClosureDateTime = SystemSettingSet.GetLastLedgerClosureDateTime(Context, "LedgerBookingCode");

            // start the closure process until we are at today
            while ((LastClosureDateTime < DateTime.Today.AddDays(-1)) && (Success))
            {
                // start transaction
                using (TransactionScope TS = new TransactionScope())
                {
                    try
                    {
                        foreach (LedgerBookingCode led in Context.LedgerBookingCodeSet.Where <LedgerBookingCode>(m => m.IsActive))
                        {
                            LedgerClosure lc = new LedgerClosure();
                            lc.ClosureDate       = LastClosureDateTime;
                            lc.LedgerBookingCode = led;
                            lc.Description       = "Sluitstand " + led.Description;

                            lc.RecalcTotals(Context, true, true);
                        }

                        // next closure date please
                        LastClosureDateTime = LastClosureDateTime.AddDays(1);
                        SystemSettingSet.SetLastLedgerClosureDateTime(Context, LastClosureDateTime, "LedgerBookingCode");

                        // commit the transaciton
                        Context.SaveChanges();
                        TS.Complete();
                    }
                    catch (Exception ex) // commit or procedure failed somewhere
                    {
                        // rollback transaction
                        TS.Dispose();

                        // inform user
                        Common.InformUserOnTransactionFail(ex, PageX);

                        Success = false;
                    }
                } //using
            }     // while
        }
Exemple #2
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (DataItem != null)
            {
                LedgerClosure ls = DataItem as LedgerClosure;

                LabelLedgerDate.Text = ls.ClosureDate.ToString();
                if (ls.Ledger != null)
                {
                    LabelLedgerName.Text = ls.Ledger.Description;
                }
                else
                {
                    LabelLedgerName.Text = ls.LedgerBookingCode.Description;
                }

                TextBox_LedgerLevel.Enabled = ls.ClosureDate.AddDays(1) > Common.CurrentClientDateTime(Session);
            }
        }