protected bool PrepareOldWeighingForSorting()
        {
            // check whether this weighing may be deleted. If this is not the case then inform the user that this weighing is already processed.
            ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);
            bool Success = false;

            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    // add weighing materual as sorting material
                    Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext);


                    frg.RecalcTotalWeightFromWeighing();

                    foreach (FreightWeighing fw in frg.FreightWeighing)
                    {
                        foreach (FreightWeighingMaterial fwm in fw.FreightWeighingMaterial)
                        {
                            FreightSortingMaterial fsm = new FreightSortingMaterial();

                            fsm.Material    = fwm.Material;
                            fsm.Weight      = fwm.NetWeight;
                            fsm.GrossWeight = fwm.GrossWeight;
                            fsm.TarraWeight = fwm.TarraWeight;
                            fsm.Freight     = frg;

                            ControlObjectContext.AddToFreightSortingMaterialSet(fsm);
                        }
                    }

                    frg.RecalcTotalWeightFromSorting();

                    // and save to persistent storage
                    ControlObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);

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

                    // inform user
                    Common.InformUserOnTransactionFail(ex, Page);
                }
            }
            return(Success);
        }