예제 #1
0
        protected void LoadSortingMaterials()
        {
            if (LabelMaterialData.Text != "")
            {
                StringReader  TempData        = new StringReader(LabelMaterialData.Text);
                XmlTextReader CurrentMaterial = new XmlTextReader(TempData);
                MaterialLines = new List <FreightSortingMaterial>();
                Double TotalWeight = 0;

                while (CurrentMaterial.Read())
                {
                    if (CurrentMaterial.Name == "MaterialLine")
                    {
                        // process this orderline
                        FreightSortingMaterial TempFSMLine = new FreightSortingMaterial();

                        TempFSMLine.Id          = Guid.Parse(CurrentMaterial.GetAttribute("id"));
                        TempFSMLine.Description = CurrentMaterial.GetAttribute("description");
                        TempFSMLine.GrossWeight = Convert.ToDouble(CurrentMaterial.GetAttribute("GrossAmount"));
                        TempFSMLine.TarraWeight = Convert.ToDouble(CurrentMaterial.GetAttribute("NetAmount"));
                        TempFSMLine.Material    = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.MaterialSet", "Id", Guid.Parse(CurrentMaterial.GetAttribute("materialid")))) as Material;
                        TempFSMLine.RecalcTotals();
                        TotalWeight = TotalWeight + TempFSMLine.Weight;
                        MaterialLines.Add(TempFSMLine);
                    }
                }

                LabelTotalWeightInOrder.Text = TotalWeight.ToString();
                CurrentMaterial.Close();
            }
        }
        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);
        }
예제 #3
0
        protected void InitSortingMaterials()
        {
            if (LabelMaterialData.Text == "")
            {
                // get the current freight
                Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext);

                // enumerate all materials for this collection
                string Query = "select value it from MaterialSet as it where it.IsActive and (not it.IsWorkInsteadOfMaterial) and it.Location.Id = @LocationId and ((it.InvoiceType = @InvoiceType) or (it.InvoiceType = \"Both\")) order by it.Description";
                ObjectQuery <Material> query = new ObjectQuery <Material>(Query, ControlObjectContext).Include("Location");
                query.Parameters.Add(new ObjectParameter("LocationId", new Guid(ComboBoxWeighingLocation.SelectedValue)));
                query.Parameters.Add(new ObjectParameter("InvoiceType", LabelMaterialInvoiceType.Text));
                ObjectResult <Material> MaterialList = query.Execute(MergeOption.AppendOnly);

                foreach (Material Mat in MaterialList)
                {
                    FreightSortingMaterial fsm = new FreightSortingMaterial();

                    fsm.Material = Mat;

                    if (frg != null)
                    {
                        FreightSortingMaterial existing_fsm = frg.CheckForSortingMaterial(Mat, ControlObjectContext);
                        if (existing_fsm != null)
                        {
                            fsm = existing_fsm;
                        }
                    }

                    fsm.Description = Mat.Description;

                    MaterialLines.Add(fsm);
                }

                SaveSortingMaterials();
            }
        }
예제 #4
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);
        }
예제 #5
0
        protected void SaveSortingMaterials()
        {
            StringWriter  TempData        = new StringWriter();
            XmlTextWriter CurrentMaterial = new XmlTextWriter(TempData);
            Double        TotalWeight     = 0;

            CurrentMaterial.WriteStartElement("MaterialLines");
            for (int i = 0; i < MaterialLines.Count; i++)
            {
                FreightSortingMaterial CurrLine = MaterialLines[i] as FreightSortingMaterial;

                GridViewRow gvr = null;
                try
                {
                    if (GridViewMaterials.Rows.Count > i)
                    {
                        gvr = GridViewMaterials.Rows[i];
                    }
                }
                catch { };

                CurrentMaterial.WriteStartElement("MaterialLine");

                if (gvr != null)
                {
                    try { CurrLine.GrossWeight = Convert.ToDouble((gvr.Cells[2].Controls[1] as TextBox).Text.ToString()); }
                    catch { };
                    try { CurrLine.TarraWeight = Convert.ToDouble((gvr.Cells[3].Controls[1] as TextBox).Text.ToString()); }
                    catch { };
                }

                CurrentMaterial.WriteAttributeString("id", CurrLine.Id.ToString());
                CurrentMaterial.WriteAttributeString("GrossAmount", CurrLine.GrossWeight.ToString());
                CurrentMaterial.WriteAttributeString("NetAmount", CurrLine.TarraWeight.ToString());
                CurrLine.RecalcTotals();
                TotalWeight = TotalWeight + CurrLine.Weight;
                CurrentMaterial.WriteAttributeString("TotalAmount", CurrLine.Weight.ToString());
                CurrentMaterial.WriteAttributeString("description", CurrLine.Description);
                CurrentMaterial.WriteAttributeString("materialid", CurrLine.Material.Id.ToString());

                CurrentMaterial.WriteEndElement();
            }
            CurrentMaterial.WriteEndElement();

            LabelTotalWeightInOrder.Text           = TotalWeight.ToString();
            LabelTotalUnassignedWeightInOrder.Text = "0";
            CheckBoxSubtractOverweight.Checked     = false;
            CheckBoxSubtractOverweight.Visible     = false;
            try
            {
                double TotalNetWeight = Convert.ToDouble(TextBoxTotalNetWeight.Text);
                LabelTotalUnassignedWeightInOrder.Text = (TotalNetWeight - TotalWeight).ToString();
                double  UnassignedWeight = Convert.ToDouble(LabelTotalUnassignedWeightInOrder.Text);
                long    FreightNr        = Convert.ToInt64(TextBoxOrderNumber.Text);
                Freight frg = Freight.SelectFreightByFreightNr(FreightNr, ControlObjectContext);
                if ((UnassignedWeight < 0) && (frg.FreightWeighing.Count > 0) && (TotalNetWeight != 0))
                {
                    CheckBoxSubtractOverweight.Visible = true;
                    CheckBoxSubtractOverweight.Checked = true;
                    // 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;
                    CheckBoxSubtractOverweight.Text = string.Format("Te veel gesorteerd gewicht aftrekken van {0}.", OrgMat.Description);
                }
            }
            catch { }
            TempData.Close();
            LabelMaterialData.Text = TempData.ToString();
        }