public static void CheckMaterialClosures(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.GetLastMaterialClosureDateTime(Context);

            // 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 (Material mat in Context.MaterialSet.Where <Material>(m => m.IsActive))
                        {
                            //if ((mat.IsActive) && (mat.GetMaterialStockPosition(Context) == mat))
                            if (mat.IsActive)
                            {
                                MaterialClosure mc = new MaterialClosure();

                                mc.Material        = mat;
                                mc.Description     = mat.Description;
                                mc.ClosureDateTime = LastClosureDateTime;
                                mc.RecalcTotals(Context);

                                Context.AddToMaterialClosureSet(mc);
                            }
                        }     //foreach

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

                        // 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
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (DataItem != null)
            {
                MaterialClosure mc = (DataItem as MaterialClosure);

                LabelMaterialName.Text = mc.Material.Description;

                TextBox_MaterialStockLevel.Enabled       = (mc.ClosureDateTime > Common.CurrentClientDate(Session).AddDays(-1));
                TextBox_MaterialStockPrice.Enabled       = (mc.ClosureDateTime > Common.CurrentClientDate(Session).AddDays(-1));
                TextBox_MaterialTotalBought.Enabled      = (mc.ClosureDateTime > Common.CurrentClientDate(Session).AddDays(-1));
                TextBox_MaterialTotalBoughtPrice.Enabled = (mc.ClosureDateTime > Common.CurrentClientDate(Session).AddDays(-1));
                TextBox_MaterialTotalSold.Enabled        = (mc.ClosureDateTime > Common.CurrentClientDate(Session).AddDays(-1));
                TextBox_MaterialTotalSoldPrice.Enabled   = (mc.ClosureDateTime > Common.CurrentClientDate(Session).AddDays(-1));
            }
        }