Exemplo n.º 1
0
        protected bool ProcessFirstWeighing()
        {
            ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);
            bool Success = false;

            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    // process freight
                    // setup base objects
                    Freight                 frg  = new Freight();
                    FreightWeighing         frgw = new FreightWeighing();
                    FreightWeighingMaterial frgm = new FreightWeighingMaterial();
                    frg.FreightWeighing.Add(frgw);
                    frgw.FreightWeighingMaterial.Add(frgm);

                    ControlObjectContext.AddToFreightSet(frg);

                    // save the first weighing data in the freight
                    SaveFirstWeighingData(frg, ControlObjectContext);

                    // assign the weighing number
                    frg.AssignFreightNumber(ControlObjectContext);
                    LabelFreightNr.Text = frg.OurReference.ToString();
                    CurrentWeighingId   = frg.Id;
                    frg.Description     = "Weegbon " + frg.OurReference + " / " + Common.CurrentClientDateTime(Session).ToString();
                    frg.FreightType     = "Weighing";

                    // 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);

                    // reset the weighing id when not saved
                    CurrentWeighingId = Guid.Empty;
                }
            }

            if (Success)
            {
                // when success advance panel
                CurrentPageNr++;
            }
            return(Success);
        }
        protected bool ProcessNewSorting()
        {
            // create a new (empty) freight
            ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);

            bool Success = false;

            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    Freight frg = new Freight();
                    frg.AssignFreightNumber(ControlObjectContext);
                    frg.Description      = "Sorteerbon " + frg.OurReference + " / " + Common.CurrentClientDateTime(Session);
                    frg.FreightDirection = "To warehouse";
                    if (RadioButtonListBuyOrSell.SelectedIndex == 1)
                    {
                        frg.FreightDirection = "To customer";
                    }
                    frg.FreightType = "Weighing";
                    frg.SourceOrDestinationLocation = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LocationSet", "Id", Guid.Parse(ComboBoxWeighingLocation.SelectedValue))) as Location;
                    frg.FromRelation  = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RelationSet", "Id", Guid.Parse(ComboBoxCustomer.SelectedValue))) as Relation;
                    frg.FreightStatus = "In sorting";

                    ControlObjectContext.AddToFreightSet(frg);

                    CurrentWeighingId = frg.Id;

                    // 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);
        }
Exemplo n.º 3
0
        protected bool StoreSorting()
        {
            Freight frg = null;

            bool Success = false;

            ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);

            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext);

                    if (frg == null)
                    {
                        // create new Freight
                        frg = new Freight();
                        frg.AssignFreightNumber(ControlObjectContext);
                        frg.Description   = "Sorteerbon " + frg.OurReference.ToString() + " / " + frg.FreightDateTime.ToString();
                        CurrentWeighingId = frg.Id;
                    }

                    frg.SourceOrDestinationLocation = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LocationSet", "Id", new Guid(ComboBoxWeighingLocation.SelectedValue))) as Location;
                    frg.FromRelation = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RelationSet", "Id", new Guid(ComboBoxCustomer.SelectedValue))) as Relation;
                    if (ComboBoxOurPlate.SelectedValue != "")
                    {
                        frg.OurTruck = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.TruckSet", "Id", new Guid(ComboBoxOurPlate.SelectedValue))) as Truck;
                    }
                    else
                    {
                        frg.OurTruck = null;
                    }

                    frg.FreightDirection = RadioButtonListBuyOrSell.SelectedIndex == 1 ? "To customer" : "To warehouse";
                    frg.FreightDateTime  = CalendarWithTimeControlDateTime1.SelectedDateTime;
                    frg.FreightType      = "Weighing";
                    try { frg.TotalNetWeight = Convert.ToDouble(TextBoxTotalNetWeight.Text); }
                    catch { }
                    //TextBoxPMV.Text = frg.FirstFreightWeighingDescription();
                    frg.YourTruckPlate = TextBoxCustomerPlate.Text;
                    frg.YourDriverName = TextBoxCustomerID.Text;

                    frg.FreightStatus = "To be invoiced";
                    foreach (FreightSortingMaterial fsm in frg.FreightSortingMaterial.ToArray <FreightSortingMaterial>())
                    {
                        ControlObjectContext.DeleteObject(fsm);
                    }
                    foreach (FreightSortingMaterial fsm in MaterialLines)
                    {
                        fsm.RecalcTotals();
                        if (fsm.RelevantLine())
                        {
                            FreightSortingMaterial fsmNew = new FreightSortingMaterial();
                            fsmNew.Material    = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.MaterialSet", "Id", fsm.Material.Id)) as Material;
                            fsmNew.Description = fsmNew.Material.Description;
                            fsmNew.GrossWeight = fsm.GrossWeight;
                            fsmNew.TarraWeight = fsm.TarraWeight;
                            fsmNew.Freight     = frg;
                            fsmNew.RecalcTotals();
                        }
                    }

                    // add dirt if required
                    Double RemainingDirt = Convert.ToDouble(LabelTotalUnassignedWeightInOrder.Text);
                    if ((RemainingDirt > 0) && (CheckBoxRestIsDirt.Checked))
                    {
                        FreightSortingMaterial Dirt = new FreightSortingMaterial();
                        Dirt.Material    = frg.SourceOrDestinationLocation.MaterialForDirt;
                        Dirt.Description = Dirt.Material.Description;
                        Dirt.GrossWeight = RemainingDirt;
                        Dirt.TarraWeight = 0;
                        Dirt.Freight     = frg;
                        Dirt.RecalcTotals();
                    }

                    // subtract overweight materials if required
                    if ((CheckBoxSubtractOverweight.Checked) && (RemainingDirt < 0))
                    {
                        // use the first material of the first freightweighing as a default. This method is not suitable for multiple weighings
                        Material OrgMat = frg.FreightWeighing.First <FreightWeighing>().FreightWeighingMaterial.First <FreightWeighingMaterial>().Material;

                        foreach (FreightSortingMaterial fsm in frg.FreightSortingMaterial)
                        {
                            if (fsm.Material == OrgMat)
                            {
                                fsm.GrossWeight = fsm.GrossWeight + RemainingDirt;
                                fsm.RecalcTotals();
                                break;
                            }
                        }
                    }
                    frg.RecalcTotalWeightFromSorting();

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

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

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