Ejemplo n.º 1
0
        protected bool UnstoreSorting()
        {
            Freight frg = null;

            bool Success = false;

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

                    // 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);
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SetName = "Freight";

            if (!IsPostBack)
            {
                if (Request.Params["FreightID"] != null)
                {
                    CurrentWeighingId = new Guid(Request.Params["FreightID"].ToString());
                    CurrentPageNr     = 22;

                    // locate the freight number and display it in the proper box
                    Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session));
                    if (frg != null)
                    {
                        TextBoxOrderNumber.Text = frg.OurReference.ToString();
                        //LoadFirstWeighingData(frg);
                    }

                    CurrentPageNr = 21;
                    EnableCorrectScreenElements();
                    CurrentPageNr = 22;
                    EnableCorrectScreenElements();

                    if (frg.FreightStatus != "2nd weighing")
                    {
                        Response.Redirect(Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.IndexOf("?")));
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ComboBoxWeighingLocation.DataBind();
                ComboBoxCustomer.DataBind();

                // parse the FreightId and link this one up to that freight
                if (Request.Params["FreightId"] != null)
                {
                    //ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);

                    CurrentWeighingId = new Guid(Request.Params["FreightId"].ToString());

                    Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext);

                    if ((frg.FreightStatus == "In sorting") && (frg.FreightSortingMaterial.Count == 0))
                    {
                        // only create a new sorting form for an existing weighing if this weighing is "In sorting" and not filled in yet
                        PrepareOldWeighingForSorting();

                        // show form
                        CurrentPageNr = 2;
                    }
                    else
                    {
                        CurrentWeighingId = Guid.Empty;
                    }
                }

                Common.LimitLocationList(ComboBoxWeighingLocation.Items, Session, ControlObjectContext);
                ShowCorrectCustomer();
            }
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // check if a freight is given on the Url
                if (Request.Params["FreightId"] != null)
                {
                    Freight frg = Freight.SelectFreightByFreightId(new Guid(Request.Params["FreightId"]), new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session));
                    if (frg != null)
                    {
                        TextBoxOrderNumber.Text = frg.OurReference.ToString();
                        CurrentPageNr           = 2;
                        EnableCorrectScreenElements();

                        if (Request.Params["Speed"] != null)
                        {
                            CurrentPageNr = 3;
                            EnableCorrectScreenElements();
                            if (WebUserControlCashPurchase1.Visible)
                            {
                                WebUserControlCashPurchase1.FreightSpeedCycle();
                            }
                            else
                            {
                                WebUserControlNonCashPurchase1.FreightSpeedCycle();
                            }
                        }
                    }
                }
            }
        }
        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);
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LabelMaterialData.Text = "";

                // if a freight id is given then immediately cycle to the weight panel
                if (Request.Params["FreightId"] != null)
                {
                    Freight frg = Freight.SelectFreightByFreightId(new Guid(Request.Params["FreightId"]), new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session));
                    if (frg != null)
                    {
                        TextBoxOrderNumber.Text = frg.OurReference.ToString();
                        CurrentPageNr           = 2;
                        EnableCorrectScreenElements();
                    }
                }
            }
            XmlDataSourceMaterials.Data = LabelMaterialData.Text;
        }
Ejemplo n.º 7
0
        protected void ButtonDestroyOrderAndBack_Click(object sender, EventArgs e)
        {
            // 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
                {
                    // delete freight
                    Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext);
                    ControlObjectContext.DeleteObject(frg);

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

                    // commit the transaciton
                    TS.Complete();
                    Success = true;

                    CurrentWeighingId = Guid.Empty;
                }
                catch (Exception ex) // commit or procedure failed somewhere
                {
                    // rollback transaction
                    TS.Dispose();

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

            if (Success)
            {
                // when success reverse panel
                CurrentPageNr--;
            }
        }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
0
        protected bool ProcessSecondWeighing()
        {
            ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);
            bool Success = false;

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

                    // add second weighing data
                    SaveFirstWeighingData(frg, ControlObjectContext);
                    SaveSecondWeighingData(frg, ControlObjectContext);

                    // generate the invoice for weighing if required
                    if (CheckBoxWeighingActionPay.Checked)
                    {
                        Invoice     inv  = new Invoice();
                        InvoiceLine invl = new InvoiceLine();

                        // create invoice
                        ControlObjectContext.AddToInvoiceSet(inv);
                        inv.Description    = frg.Description;
                        inv.InvoiceType    = "Buy";
                        inv.Relation       = frg.FromRelation;
                        inv.Location       = frg.SourceOrDestinationLocation;
                        inv.Ledger         = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LedgerSet", "Id", Guid.Parse(ComboBoxLedger.SelectedValue))) as Ledger;
                        invl.Invoice       = inv;
                        invl.Description   = "Wegen";
                        invl.OriginalPrice = frg.SourceOrDestinationLocation.DefaultWeighingTariff;
                        invl.VATPercentage = frg.SourceOrDestinationLocation.DefaultVATPercentage;
                        Location loc = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LocationSet", "Id", Guid.Parse(ComboBoxWeighingLocation.SelectedValue))) as Location;
                        invl.LedgerBookingCode = loc.DefaultWeighingTariffBookingCode;
                        inv.RecalcTotals();

                        // only process the invoice for cash ledgers
                        if (inv.Ledger.LedgerType == "Cash")
                        {
                            inv.ProcessInvoice(ControlObjectContext, inv.Id, true, Common.CurrentClientDateTime(Session));
                        }

                        LabelGeneratedInvoiceId.Text = inv.Id.ToString();
                    }

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

                    // commit the transaciton
                    TS.Complete();
                    Success = true;

                    CurrentWeighingId = frg.Id;
                }
                catch (Exception ex) // commit or procedure failed somewhere
                {
                    // rollback transaction
                    TS.Dispose();

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

            if (Success)
            {
                // when success advance panel
                CurrentPageNr++;
            }
            return(Success);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        private void EnableCorrectScreenElements()
        {
            WebUserControlCashPurchase1.Visible    = false;
            WebUserControlNonCashPurchase1.Visible = false;

            PanelSecondWeighingOrderNumber.Visible = true;
            PanelSecondWeighingOrderNumber.Enabled = false;
            PanelInvoiceInformation.Visible        = false;
            PanelInvoiceInformation.Enabled        = false;

            ButtonContinue.Visible = false;
            ButtonRevert.Visible   = false;

            switch (CurrentPageNr)
            {
            case 1:
                ButtonContinue.Visible = true;
                PanelSecondWeighingOrderNumber.Enabled = true;
                break;

            case 2:
                ButtonContinue.Visible          = true;
                ButtonRevert.Visible            = true;
                PanelInvoiceInformation.Visible = true;
                PanelInvoiceInformation.Enabled = true;

                // check if this is a valid freight number
                bool Success = false;
                try
                {
                    long    FreightNr = Convert.ToInt64(TextBoxOrderNumber.Text);
                    Freight frg       = Freight.SelectFreightByFreightNr(FreightNr, new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session));
                    if (frg != null)
                    {
                        CurrentWeighingId = frg.Id;
                        Success           = true;

                        string InvoiceType = "";
                        if (frg.FreightDirection == "To warehouse")
                        {
                            InvoiceType = "Buy";
                        }
                        else
                        {
                            InvoiceType = "Sell";
                        }

                        URLPopUpControlShowSorting.URLToPopup = "WebFormPopup.aspx?UC=ShowReport&d=DataSetSorting&r=ReportSortingA4&Id=" + CurrentWeighingId.ToString() + "&InvoiceType=" + InvoiceType;

                        if (frg.FreightStatus != "To be invoiced")
                        {
                            Common.InformUser(Page, "Deze vracht is nog niet uitgezocht of al gefactureerd. U kunt deze vracht nogmaals factureren. Deze wordt dan nogmaals op een factuur geplaatst.");
                        }
                    }
                    else
                    {
                        Common.InformUser(Page, "Geef aub een geldig nummer op voor de sorteerbon die nog niet verder is verwerkt.");
                    }
                }
                catch { }

                if (!Success)
                {
                    CurrentPageNr--;
                    EnableCorrectScreenElements();
                }

                break;

            case 3:
                PanelInvoiceInformation.Visible = true;

                switch (RadioButtonListInvoiceType.SelectedIndex)
                {
                case 0:
                    WebUserControlCashPurchase1.Visible = true;
                    WebUserControlCashPurchase1.LoadFromFreight(Freight.SelectFreightByFreightId(CurrentWeighingId, new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session)), false);
                    break;

                case 1:
                    WebUserControlNonCashPurchase1.Visible = true;
                    WebUserControlNonCashPurchase1.LoadFromFreight(Freight.SelectFreightByFreightId(CurrentWeighingId, new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session)), false);
                    break;
                }

                break;
            }
        }