protected void ButtonCloneOrder_Click(object sender, EventArgs e)
        {
            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    // clone order
                    Order NewOrder = (DataItem as Order).CloneToNew(ControlObjectContext, false, null, Common.CurrentClientDateTime(Session));

                    ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);

                    // commit the transaciton
                    TS.Complete();

                    // inform user
                    Page.RegisterClientScriptBlock("Alert", "<script>alert('De order is gekloond. De order wordt nu geopend.');</script>");

                    Response.Redirect("~\\WebFormPurchaseLedger.aspx?OrderNumber=" + NewOrder.OrderNumber.ToString(), false);
                }
                catch (Exception ex)
                {
                    // rollback
                    TS.Dispose();

                    // inform user
                    Common.InformUserOnTransactionFail(ex, Page);
                }
            }
        }
        protected void GridViewOrderLines_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            e.Cancel = true;

            OrderLine TempLine;

            try
            {
                TempLine                        = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.OrderLineSet", "Id", Guid.Parse(e.Keys[0].ToString()))) as OrderLine;
                TempLine.Description            = e.NewValues[0].ToString();
                TempLine.Amount                 = Math.Round(Convert.ToDouble(e.NewValues[1].ToString()), 4);
                TempLine.PricePerUnit           = Math.Round(Convert.ToDouble(e.NewValues[2].ToString()), 4);
                TempLine.AlreadyDeliveredAmount = Math.Round(Convert.ToDouble(e.NewValues[3].ToString()), 4);

                TempLine.Order.RecalcTotals();
            }
            catch { }

            try
            {
                ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);
            }
            catch (Exception ex)
            {
                Common.InformUserOnTransactionFail(ex, Page);
            }

            GridViewOrderLines.EditIndex = -1;

            RebindControls();
            DataBind();
        }
        protected void ButtonNew_Click(object sender, EventArgs e)
        {
            // first determine ledger & ledger booking code
            Ledger            TempLedger     = null;
            LedgerBookingCode TempLedgerCode = null;

            if (Request.Params["Id"] != null)
            {
                EntityKey TempKey = new EntityKey("ModelTMSContainer.LedgerSet", "Id", Guid.Parse(Request.Params["Id"]));
                TempLedger = ControlObjectContext.GetObjectByKey(TempKey) as Ledger;
            }
            else
            { // this must be linked to the ledgerbookingcodes ...
                EntityKey TempKey = new EntityKey("ModelTMSContainer.LedgerBookingCodeSet", "Id", Guid.Parse(Request.Params["LedgerBookingCodeId"]));
                TempLedgerCode = ControlObjectContext.GetObjectByKey(TempKey) as LedgerBookingCode;
            }

            // now create the ledger check
            LedgerCheck lc = new LedgerCheck();

            lc.Ledger            = TempLedger;
            lc.LedgerBookingCode = TempLedgerCode;
            lc.Description       = "Kascontrole " + lc.CheckDate.ToString();

            // and save
            ControlObjectContext.SaveChanges();


            // and show
            WebUserControlBookKeepingCheckBase1.KeyID   = lc.Id;
            WebUserControlBookKeepingCheckBase1.Visible = true;
        }
        protected void ButtonCorrect_Click(object sender, EventArgs e)
        {
            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    Invoice inv = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.InvoiceSet", "Id", new System.Guid(LabelGeneratedInvoiceId.Text))) as Invoice;

                    inv.UnprocessInvoice(ControlObjectContext, new System.Guid(LabelGroupId.Text), Common.CurrentClientDateTime(Session));

                    // save the data
                    ControlObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);

                    // commit the transaciton
                    TS.Complete();

                    CurrentPageNr--;
                    EnableCurrentPageElements();
                }
                catch (Exception ex)
                {
                    // rollback transaction
                    TS.Dispose();

                    // inform user
                    Common.InformUserOnTransactionFail(ex, Page);
                }
            }
        }
Example #5
0
        protected Boolean StandardSaveHandler(object sender, EventArgs e, bool ExecuteSaveChanges)
        {
            Boolean result = false;

            try
            {
                SaveDataIntoDataItemFromControls();

                if (ExecuteSaveChanges)
                {
                    ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);
                }

                result = true;
            }
            catch (ControlArgumentException ex)
            {
                Page.RegisterClientScriptBlock("Alert", "<script>alert('Het opslaan van de gegevens is mislukt. Corrigeer de waarde in het veld waar de cursor staat.');</script>");
                ex.CausingControl.Focus();
            }
            catch (Exception ex)
            {
                // inform user
                Common.InformUserOnTransactionFail(ex, Page);

                KeyID = KeyID;
            }
            return(result);
        }
        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);
        }
        protected void ButtonAddMaterial_Click(object sender, EventArgs e)
        {
            OrderLine NewLine = new OrderLine();
            Material  MatItem;
            RelationPriceAgreement   PAItem;
            RelationContractMaterial ContractItem;

            DetermineCurrentSelectedMaterial(out MatItem, out PAItem, out ContractItem);

            NewLine.Order = (DataItem as Order);
            try
            {
                NewLine.PricePerUnit             = Convert.ToDouble(TextBoxPrice.Text);
                NewLine.Amount                   = Convert.ToDouble(TextBoxAmount.Text);
                NewLine.Material                 = MatItem;
                NewLine.Description              = MatItem.Description;
                NewLine.RelationPriceAgreement   = PAItem;
                NewLine.RelationContractMaterial = ContractItem;
                ControlObjectContext.AddToOrderLineSet(NewLine);

                (DataItem as Order).RecalcTotals();
            }
            catch { }

            try
            {
                ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);
            }
            catch (Exception ex)
            {
                Common.InformUserOnTransactionFail(ex, Page);
            }

            DataBind();
        }
        protected void GridViewOrderLines_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            e.Cancel = true;

            InvoiceLine il;

            il = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.InvoiceLineSet", "Id", Guid.Parse(e.Keys[0].ToString()))) as InvoiceLine;

            try
            {
                il.Description        = e.NewValues[0].ToString();
                il.Amount             = Convert.ToDouble(e.NewValues[1].ToString());
                il.PricePerUnit       = Convert.ToDouble(e.NewValues[2].ToString());
                il.DiscountPercentage = Convert.ToDouble(e.NewValues[3].ToString());
                il.VATPercentage      = Convert.ToDouble(e.NewValues[4].ToString());
                il.Invoice.RecalcTotals();
            }
            catch { }

            try
            {
                ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);
            }
            catch (Exception ex)
            {
                Common.InformUserOnTransactionFail(ex, Page);
            }

            RebindControls();
            DataBind();

            GridViewOrderLines.EditIndex = -1;
        }
        protected void ButtonCorrectInvoice_Click(object sender, EventArgs e)
        {
            // correct invoice, the user may decide whether or not to create a new invoice with these orders
            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    // process order
                    (DataItem as Invoice).UnprocessInvoice(ControlObjectContext, (DataItem as Invoice).GroupCode, Common.CurrentClientDateTime(Session));
                    (DataItem as Invoice).IsCorrected = true;

                    ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);

                    // commit the transaciton
                    TS.Complete();

                    // inform user
                    Page.RegisterClientScriptBlock("Alert", "<script>alert('De factuur en eventueel bijbehordende orders zijn volledig tegengeboekt. U kunt de factuur opnieuw aanmaken.');</script>");
                }
                catch (Exception ex)
                {
                    // rollback
                    TS.Dispose();

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

            RebindControls();
            DataBind();
        }
        private void ProcessPayment(Boolean IsCorrection)
        {
            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                // process payment
                try
                {
                    ClassCustomBinding.BindToObject("ModelTMSContainer." + SetName + "Set", KeyID, Controls, DataItem, ControlObjectContext);

                    if (!IsCorrection)
                    {
                        (DataItem as RelationAdvancePayment).PayOut(ControlObjectContext, Common.CurrentClientDateTime(Session));
                    }
                    else
                    {
                        (DataItem as RelationAdvancePayment).PayBack(ControlObjectContext, Common.CurrentClientDateTime(Session));
                    }
                    ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);

                    // commit transaction
                    TS.Complete();
                }
                catch (Exception ex)
                {
                    // rollback transaction
                    TS.Dispose();

                    // inform user
                    Common.InformUserOnTransactionFail(ex, Page);
                }
            }
        }
        protected void ButtonAddWorkCorrection_Click(object sender, EventArgs e)
        {
            StandardSaveHandler(sender, e, false);

            InvoiceLine il = new InvoiceLine();

            try
            {
                RelationWork RelWork = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RelationWorkSet", "Id", Guid.Parse(DropDownListWorkCorrection.SelectedValue))) as RelationWork;

                (DataItem as Invoice).AddWorkCorrection(ControlObjectContext,
                                                        RelWork,
                                                        Convert.ToDouble(TextBoxWorkCorrectionAmount.Text) * -1,
                                                        LabelWorkCorrection.Text + " " + RelWork.Description);

                (DataItem as Invoice).RecalcTotals();
            }
            catch { }

            try
            {
                ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);
            }
            catch (Exception ex)
            {
                Common.InformUserOnTransactionFail(ex, Page);
            }

            RebindControls();
            DataBind();
        }
        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();
            }
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CalendarControlStartDate.SelectedDate = Common.CurrentClientDate(Session).AddDays(-31);
                CalendarControlEndDate.SelectedDate   = Common.CurrentClientDate(Session);
                ButtonSearch_Click(null, null);

                // get the ledger description
                if (Request.Params["Id"] != null)
                {
                    EntityKey TempKey    = new EntityKey("ModelTMSContainer.LedgerSet", "Id", Guid.Parse(Request.Params["Id"]));
                    Ledger    TempLedger = ControlObjectContext.GetObjectByKey(TempKey) as Ledger;
                    LabelObjectName.Text = TempLedger.Description;

                    // check if we are actual with material closures
                    LedgerSet.CheckLedgerClosures(ControlObjectContext, Page);
                }
                else
                { // this must be linked to the ledgerbookingcodes ...
                    EntityKey         TempKey    = new EntityKey("ModelTMSContainer.LedgerBookingCodeSet", "Id", Guid.Parse(Request.Params["LedgerBookingCodeId"]));
                    LedgerBookingCode TempLedger = ControlObjectContext.GetObjectByKey(TempKey) as LedgerBookingCode;
                    LabelObjectName.Text = TempLedger.Description;

                    // check if we are actual with material closures
                    LedgerBookingCodeSet.CheckLedgerBookingCodeClosures(ControlObjectContext, Page);
                }
            }
        }
Example #14
0
        private void DetermineCurrentSelectedMaterial(out Material MatItem, out RelationPriceAgreement PAItem, out RelationContractMaterial ContractItem)
        {
            // locate the material, price agreement or contract in the entitydatasource
            Guid SelID = Guid.Parse(DropDownListMaterials.SelectedValue);

            // try to load the data from material, relationcontract or relationpriceagreement
            MatItem      = null;
            PAItem       = null;
            ContractItem = null;
            EntityKey TempKey = new EntityKey("ModelTMSContainer.MaterialSet", "Id", SelID);

            try { MatItem = ControlObjectContext.GetObjectByKey(TempKey) as Material; }
            catch { };
            if (MatItem == null)
            {
                TempKey = new EntityKey("ModelTMSContainer.RelationPriceAgreementSet", "Id", SelID);
                try
                {
                    PAItem  = ControlObjectContext.GetObjectByKey(TempKey) as RelationPriceAgreement;
                    MatItem = PAItem.Material;
                }
                catch { };
            }
            if ((MatItem == null) && (PAItem == null))
            {
                TempKey = new EntityKey("ModelTMSContainer.RelationContractMaterialSet", "Id", SelID);
                try
                {
                    ContractItem = ControlObjectContext.GetObjectByKey(TempKey) as RelationContractMaterial;
                    MatItem      = ContractItem.Material;
                }
                catch { };
            }
        }
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            // save the role memberships into the staffmember
            StaffMember sm = (DataItem as StaffMember);

            sm.SecurityRole.Load();
            if (sm != null)
            {
                foreach (SecurityRole sr in sm.SecurityRole.ToArray <SecurityRole>())
                {
                    sm.SecurityRole.Remove(sr);
                }

                foreach (ListItem ListI in CheckBoxListRoleMemberships.Items)
                {
                    if (ListI.Selected)
                    {
                        SecurityRole sr = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.SecurityRoleSet", "Id", new Guid(ListI.Value))) as SecurityRole;
                        sm.SecurityRole.Add(sr);
                    }
                }
            }


            // check if the nr of staffmembers does not exceed the max amount of allowed staff members
            if ((CheckBox_HasVMSAccount_Checked.Checked) && (CheckBoxOldVMSAccount.Checked != CheckBox_HasVMSAccount_Checked.Checked) &&
                ((StaffMemberSet.AmountOfStaffMembersWithTMSLogin(ControlObjectContext) + 1) > SystemSettingSet.GetAmountOfUserLicenses(ControlObjectContext)))
            {
                Common.InformUser(Page, "Het maximale aantal TMS logins is opgebruikt. U kunt niet nog een TMS gebruiker toevoegen. Breidt uw licentie uit of ontneem de TMS licentie van een bestaande gebruiker.");
                CheckBox_HasVMSAccount_Checked.Checked = false;
            }

            StandardButtonSaveClickHandler(sender, e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // set the correct filters
                CalendarControlStartDate.SelectedDate = new DateTime(Common.CurrentClientDateTime(Session).Year, 1, 1);
                CalendarControlEndDate.SelectedDate   = Common.CurrentClientDateTime(Session).Date;

                ButtonSearch_Click(sender, e);

                if (Request.Params["MutationNumber"] != null)
                {
                    TextBoxOrderNo.Text = Request.Params["MutationNumber"];
                    EntityDataSourceStockMutationLedger.CommandParameters["MutationNumber"].DefaultValue = TextBoxOrderNo.Text;
                    EntityDataSourceStockMutationLedger.DataBind();

                    if (GridViewSelectedMutations.Rows.Count == 1)
                    {
                        GridViewSelectedMutations.SelectedIndex = 0;
                        GridViewSelectedMutations_SelectedIndexChanged(null, null);
                    }
                }

                if (Request.Params["Id"] != null)
                {
                    // load material to show in the header
                    Material Mat = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.MaterialSet", "Id", new Guid(Request.Params["Id"]))) as Material;
                    LabelObjectName.Text = Mat.Description;
                }
            }
        }
Example #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // get the ledger description
                if (Request.Params["Id"] != null)
                {
                    EntityKey TempKey    = new EntityKey("ModelTMSContainer.LedgerSet", "Id", Guid.Parse(Request.Params["Id"]));
                    Ledger    TempLedger = ControlObjectContext.GetObjectByKey(TempKey) as Ledger;
                    LabelLedgerName.Text = TempLedger.Description;
                }
                else
                { // this must be linked to the ledgerbookingcodes ...
                    EntityKey         TempKey    = new EntityKey("ModelTMSContainer.LedgerBookingCodeSet", "Id", Guid.Parse(Request.Params["LedgerBookingCodeId"]));
                    LedgerBookingCode TempLedger = ControlObjectContext.GetObjectByKey(TempKey) as LedgerBookingCode;
                    LabelLedgerName.Text = TempLedger.Description;
                }

                // set the correct filters
                CalendarControlStartDate.SelectedDate = new DateTime(Common.CurrentClientDate(Session).Year, 1, 1);
                CalendarControlEndDate.SelectedDate   = Common.CurrentClientDate(Session);

                DropDownListBookingType.Items.Clear();
                DropDownListBookingType.Items.Add(new ListItem("Alle", ""));
                Common.AddLedgerBookingTypeList(DropDownListBookingType.Items, false);
                DropDownListBookingType.SelectedValue = "";

                ButtonSearch_Click(sender, e);
            }
        }
        public BocEnumValueControlObject([NotNull] ControlObjectContext context)
            : base(context)
        {
            var style = Scope[DiagnosticMetadataAttributesForObjectBinding.BocEnumValueStyle];

            _variantImpl = CreateVariant(style);
        }
        protected void ButtonCreateClonedInvoiceAndOrders_Click(object sender, EventArgs e)
        {
            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    // clone order
                    Invoice NewInvoice = (DataItem as Invoice).CloneToNew(ControlObjectContext, false, null, Common.CurrentClientDateTime(Session));

                    ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);

                    Response.Redirect(Request.AppRelativeCurrentExecutionFilePath + "?InvoiceNumber=" + NewInvoice.InvoiceNumber.ToString(), false);

                    // commit the transaciton
                    TS.Complete();

                    // inform user
                    Common.InformUser(Page, "De factuur en eventueel bijbehordende orders zijn gekloond. De factuur wordt nu geopend.");
                }
                catch (Exception ex)
                {
                    // rollback
                    TS.Dispose();

                    // inform user
                    Common.InformUserOnTransactionFail(ex, Page);
                }
            }
        }
Example #20
0
        /// <inheritdoc/>
        protected override BocAutoCompleteReferenceValueControlObject CreateControlObject(
            ControlObjectContext newControlObjectContext,
            ControlSelectionContext controlSelectionContext)
        {
            ArgumentUtility.CheckNotNull("controlSelectionContext", controlSelectionContext);
            ArgumentUtility.CheckNotNull("newControlObjectContext", newControlObjectContext);

            return(new BocAutoCompleteReferenceValueControlObject(newControlObjectContext));
        }
        /// <inheritdoc/>
        protected override BocListControlObject CreateControlObject(
            ControlObjectContext newControlObjectContext,
            ControlSelectionContext controlSelectionContext)
        {
            ArgumentUtility.CheckNotNull("controlSelectionContext", controlSelectionContext);
            ArgumentUtility.CheckNotNull("newControlObjectContext", newControlObjectContext);

            return(new BocListControlObject(newControlObjectContext));
        }
        private static UnspecifiedPageObject SelectMenuOrSubMenuItem(
            ControlObjectContext context,
            ElementScope menuItemScope,
            IWebTestActionOptions actionOptions)
        {
            var menuItemCommandScope = menuItemScope.FindLink();
            var menuItemCommand      = new CommandControlObject(context.CloneForControl(menuItemCommandScope));

            return(menuItemCommand.Click(actionOptions));
        }
        private void CheckAlternativeMaterialsSettings()
        {
            RentalType rt = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RentalTypeSet", "Id", new Guid(ComboBoxMaterialType.SelectedValue))) as RentalType;

            URLPopUpControlAlternativeMaterials.Visible    = rt.AlternativeRentalTypes.Count > 0;
            URLPopUpControlAlternativeMaterials.URLToPopup = "WebFormPopUp.aspx?uc=RentAlternativeMaterials&RentalType=" + ComboBoxMaterialType.SelectedValue +
                                                             "&LocationId=" + EntityDataSourceMaterials.CommandParameters["LocationId"].DefaultValue +
                                                             "&StartDate=" + EntityDataSourceMaterials.CommandParameters["StartDate"].DefaultValue +
                                                             "&EndDate=" + EntityDataSourceMaterials.CommandParameters["EndDate"].DefaultValue;
        }
Example #24
0
        protected void ButtonResetAvgSalesPrice_Click(object sender, EventArgs e)
        {
            Material Mat = (DataItem as Material);

            Mat.AvgSalesPriceTotalPrice  = 0;
            Mat.AvgSalesPriceTotalWeight = 0;
            Mat.AvgSalesPrice            = 0;
            ControlObjectContext.SaveChanges();
            RebindControls();
        }
Example #25
0
 public object GetDataItem(Guid IDKey)
 {
     if (SetName != "")
     {
         EntityKey TempKey = new EntityKey("ModelTMSContainer." + SetName + "Set", "Id", IDKey);
         return(ControlObjectContext.GetObjectByKey(TempKey));
     }
     else
     {
         return(null);
     }
 }
Example #26
0
        public void LoadOrderLines(bool SaveOrderLine = true)
        {
            LabelTotalWeight.Text   = "...";
            LabelTotalPrice.Text    = "...";
            LabelTotalPriceVAT.Text = "...";

            OrderLines.Clear();
            if (LabelOrderData.Text != "")
            {
                StringReader  TempData     = new StringReader(LabelOrderData.Text);
                XmlTextReader CurrentOrder = new XmlTextReader(TempData);
                OrderLines = new ArrayList();
                Double TotalWeight   = 0;
                Double TotalPrice    = 0;
                Double TotalPriceVAT = 0;

                while (CurrentOrder.Read())
                {
                    if (CurrentOrder.Name == "OrderLine")
                    {
                        // process this orderline
                        OrderLine TempOrderLine = new OrderLine();
                        TempOrderLine.Id                     = Guid.Parse(CurrentOrder.GetAttribute("id"));
                        TempOrderLine.Description            = CurrentOrder.GetAttribute("description");
                        TempOrderLine.Amount                 = Convert.ToDouble(CurrentOrder.GetAttribute("amount"));
                        TempOrderLine.AlreadyDeliveredAmount = Convert.ToDouble(CurrentOrder.GetAttribute("alreadydeliveredamount"));
                        TempOrderLine.PricePerUnit           = Convert.ToDouble(CurrentOrder.GetAttribute("priceperunit"));
                        TempOrderLine.PriceExVAT             = TempOrderLine.Amount * TempOrderLine.PricePerUnit;
                        TempOrderLine.Material               = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.MaterialSet", "Id", Guid.Parse(CurrentOrder.GetAttribute("materialid")))) as Material;
                        TotalWeight   = TotalWeight + TempOrderLine.AmountInKgs;
                        TotalPrice    = TotalPrice + TempOrderLine.PriceExVAT;
                        TotalPriceVAT = TotalPriceVAT + TempOrderLine.PriceWithVAT;
                        if (CurrentOrder.GetAttribute("priceagreementid") != "")
                        {
                            TempOrderLine.RelationPriceAgreement = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RelationPriceAgreementSet", "Id", Guid.Parse(CurrentOrder.GetAttribute("priceagreementid")))) as RelationPriceAgreement;
                        }
                        if (CurrentOrder.GetAttribute("contractmaterialid") != "")
                        {
                            TempOrderLine.RelationContractMaterial = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RelationContractMaterialSet", "Id", Guid.Parse(CurrentOrder.GetAttribute("contractmaterialid")))) as RelationContractMaterial;
                        }

                        OrderLines.Add(TempOrderLine);
                    }
                }
                LabelTotalWeight.Text   = TotalWeight.ToString();
                LabelTotalPrice.Text    = Math.Round(TotalPrice, 2).ToString();
                LabelTotalPriceVAT.Text = Math.Round(TotalPriceVAT, 2).ToString();
            }
            if (SaveOrderLine)
            {
                SaveOrderLines();
            }
        }
        protected void ButtonProcess_Click(object sender, EventArgs e)
        {
            Double MatPrice = 0, MatAmount = 0;

            try
            {
                MatPrice  = Convert.ToDouble(TextBoxPrice.Text);
                MatAmount = Convert.ToDouble(TextBoxAmount.Text);
            }
            catch
            {
            }

            if ((MatPrice.ToString() != TextBoxPrice.Text) || (MatAmount.ToString() != TextBoxAmount.Text))
            {
                Common.InformUser(Page, "De opgegeven getallen voor prijs en hoeveelheid kunnen niet worden herkend. Corrigeer deze naar de juiste waarde.");
                TextBoxPrice.Text  = MatPrice.ToString();
                TextBoxAmount.Text = MatAmount.ToString();
            }
            else
            {
                // process this as a Material Mutation
                MaterialMutation mt = new MaterialMutation();

                mt.Material     = (DataItem as Material);
                mt.Description  = "CORR / Correctie voorraad " + mt.Material.Description + " dd " + mt.CreateDateTime.ToString();
                mt.MutationType = RadioButtonListBuyOrSell.SelectedValue;
                mt.Amount       = MatAmount;
                mt.PricePerUnit = MatPrice;
                mt.TotalPrice   = MatPrice * mt.Amount;
                mt.GenerateMutationNumber(ControlObjectContext);

                if (mt.MutationType == "Sell")
                {
                    mt.Amount = -mt.Amount; // sales are always a negative amount
                }

                mt.RecalcTotals();
                mt.ProcessToStockLevel(false); // do not update average prices
                mt.ProcessToLedgerMutation(ControlObjectContext);

                if (mt.MutationType == "Sell")
                {
                    mt.TotalPrice = MatPrice * mt.Amount; // sales are stored as a negative price so that the total calculation will be correct on the daily closure
                }

                ControlObjectContext.AddToMaterialMutationSet(mt);
                ControlObjectContext.SaveChanges();
                Common.InformUser(Page, "Deze mutatie is succesvol doorgevoerd. U kunt dit popup scherm nu sluiten of nog een mutatie op dit materiaal doorvoeren.");
            }
        }
        protected void GridViewOrders_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UnlinkOrder")
            {
                if (GridViewOrderLines.Enabled)
                {
                    int Row         = Convert.ToInt32(e.CommandArgument);
                    int OrderNumber = Convert.ToInt32(GridViewOrders.Rows[Row].Cells[1].Text);

                    // load order
                    string Query = "SELECT VALUE it FROM OrderSet as it WHERE it.OrderNumber = @OrderNumber";
                    ObjectQuery <Order> query = new ObjectQuery <Order>(Query, ControlObjectContext);
                    query.Parameters.Add(new ObjectParameter("OrderNumber", OrderNumber));
                    ObjectResult <Order> ilines = query.Execute(MergeOption.AppendOnly);

                    Order TempOrder = ilines.First <Order>();

                    // start transaction
                    using (TransactionScope TS = new TransactionScope())
                    {
                        try
                        {
                            TempOrder.Invoice.RemoveOrderFromInvoice(ControlObjectContext, TempOrder);

                            // commit the transaciton
                            ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);
                            TS.Complete();

                            // inform user
                            Common.InformUser(Page, "De order is van de factuur ontkoppeld. De orderregels zijn van deze factuur verwijderd. U dient deze order nogmaals op ean factuur te plaatsen.");
                        }
                        catch (Exception ex)
                        {
                            // rollback
                            TS.Dispose();

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

                    // reload data in the interface
                    DataBind();
                    RebindControls();
                }
                else
                {
                    Common.InformUser(Page, "Deze order kan niet worden ontkoppeld. De factuur is reeds verwerkt.");
                }
            }
        }
        public void ConstructQuery()
        {
            RentalType rt = ControlObjectContext.GetObjectByKey(new System.Data.EntityKey("ModelTMSContainer.RentalTypeSet", "Id", new Guid(Request.Params["RentalType"]))) as RentalType;

            StringBuilder Query = new StringBuilder();

            Query.Append("select distinct it.Id, it.ItemNumber, it.Description, it.Description, it.BaseRentalPrice, it.RentPerDay, it.RentPerWeek, it.RentPerMonth, it.BailPrice, it.Location.Description as LocationDescription " +
                         "from RentalItemSet as it  " +
                         "where  " +
                         "it.IsActive and  " +
                         "( (it.ItemState = \"Available\") or (it.ItemState = \"Rented\") ) and " +
                         "( it not in ( " +
                         "	select value itx2.RentalItem  "+
                         "	from RentalItemActivitySet as itx2  "+
                         "	where itx2.RentalItem.Id = it.Id and "+
                         "	 (  "+
                         "	   ((@StartDate <= itx2.RentStartDateTime) and (@EndDate >= itx2.RentStartDateTime))  "+
                         "	 ) or "+
                         "	 ( "+
                         "	   ((@StartDate >= itx2.RentStartDateTime) and (@StartDate <= itx2.RentEndStartDateTime)) "+
                         "	 ) "+
                         "  ) " +
                         ") and  ( cast(it.RentalType.Id as System.String) in { ");
            // insert the alternative rental type ID's
            foreach (RentalType rtAlt in rt.AlternativeRentalTypes)
            {
                Query.Append("'" + rtAlt.Id.ToString() + "'");
            }
            Query.Append("} ) ");

            // insert the location ID if required
            if (CheckBoxIncludeAlternativeLocations.Checked)
            {
                if (ComboBoxLocations.SelectedValue != "")
                {
                    Query.Append(" and (it.Location.Id = @LocationId) ");
                    EntityDataSourceMaterials.CommandParameters["LocationId"].DefaultValue = ComboBoxLocations.SelectedValue;
                }
            }
            else
            {
                Query.Append(" and (it.Location.Id = @LocationId) ");
                EntityDataSourceMaterials.CommandParameters["LocationId"].DefaultValue = Request.Params["LocationId"];
            }

            // add the ordering
            Query.Append("order by Description, BaseRentalPrice");

            // set as commandtext
            EntityDataSourceMaterials.CommandText = Query.ToString();
        }
Example #30
0
        protected Boolean StandardButtonDeleteClickMethod(object sender, EventArgs e)
        {
            Boolean result = false;

            // check if this object may be deleted
            Boolean AllowDel = AllowDelete();

            // if this object may not be deleted then warn about this
            if (!AllowDel)
            {
                Page.RegisterClientScriptBlock("Alert", "<script>alert('Dit gegeven kan niet worden verwijderd omdat dit elders in het systeem wordt gebruikt. Deactiveer het object ipv het te verwijderen.');</script>");
            }
            else // else delete this object
            {
                RefreshRequired = true; //request a refresh from the container

                try
                {
                    ControlObjectContext.DeleteObject(DataItem);

                    ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);

                    result = true;

                    Page.RegisterClientScriptBlock("Alert", "<script>alert('De gegevens zijn succesvol verwijderd.');</script>");
                }
                catch (ControlArgumentException ex)
                {
                    string tempStr = ex.Message.Replace("'", "\"").Replace("\n", "").Replace("\r", "");
                    Page.RegisterClientScriptBlock("Alert", "<script>alert('Het verwijderen van de gegevens is mislukt. Mogelijk heeft een andere medewerker dit gegeven al verwijderd. (" + tempStr + ")');</script>");
                }
                catch (Exception ex)
                {
                    string tempStr = "";
                    if (ex.InnerException == null)
                    {
                        tempStr = ex.Message.Replace("'", "\"").Replace("\n", "").Replace("\r", "");
                    }
                    else
                    {
                        tempStr = ex.Message + " / " + ex.InnerException.ToString();
                        tempStr = tempStr.Replace("'", "\"").Replace("\n", "").Replace("\r", "");
                    }
                    Page.RegisterClientScriptBlock("Alert", "<script>alert('Het opslaan van de gegevens is mislukt omdat iemand anders de gegevens al heeft verwijderd of omdat er nog relaties zijn naar ander informatie die niet meer verwijderd kunnen worden. Probeer het nogmaals. (" + tempStr + ")');</script>");
                    KeyID = KeyID;
                }
            }

            return(result);
        }