protected bool AddAnotherProducts(RegistrationOrder regOrd, int? locationId)
        {
            bool allesHatGutGelaufen = false;
            string ProduktId = "";
            string CostCenterId = "";
            int skipFirst = 0;
            foreach (RadTreeNode node in DienstleistungTreeView.Nodes)
            {
                if (skipFirst > 0)
                {
                    if (!String.IsNullOrEmpty(node.Value))
                    {
                        string[] splited = node.Value.Split(';');
                        if (splited.Length == 2)
                        {
                            try
                            {
                                DataClasses1DataContext dbContext = new DataClasses1DataContext(Int32.Parse(Session["CurrentUserId"].ToString()));
                                var orderNumber = regOrd.OrderNumber;
                                Price newPrice;
                                OrderItem newOrderItem1 = null;
                                OrderItem newOrderItem2 = null;
                                ProduktId = splited[0];
                                CostCenterId = splited[1];
                                if (!String.IsNullOrEmpty(ProduktId))
                                {
                                    var productId = Int32.Parse(ProduktId);
                                    int? costCenterId = null;
                                    KVSCommon.Database.Product newProduct = dbContext.Product.SingleOrDefault(q => q.Id == productId);
                                    if (RadComboBoxCustomer.SelectedIndex == 1 || locationId == null) //small
                                    {
                                        newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null);
                                    }
                                    else //large
                                    {
                                        costCenterId = Int32.Parse(CostCenterId);
                                        newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == locationId);
                                        if (newPrice == null)
                                            newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null);
                                    }
                                    var orderToUpdate = dbContext.Order.SingleOrDefault(q => q.OrderNumber == orderNumber);
                                    orderToUpdate.LogDBContext = dbContext;
                                    if (orderToUpdate != null)
                                    {
                                        if (RadComboBoxCustomer.SelectedIndex == 1)
                                        {
                                            newOrderItem1 = orderToUpdate.AddOrderItem(newProduct.Id, newPrice.Amount, 1, null, null, false, dbContext);

                                            if (newPrice.AuthorativeCharge.HasValue)
                                            {
                                                orderToUpdate.AddOrderItem(newProduct.Id, newPrice.AuthorativeCharge.Value, 1, null, newOrderItem1.Id, newPrice.AuthorativeCharge.HasValue, dbContext);
                                            }
                                        }
                                        else
                                        {
                                            CostCenter costCenter = null;
                                            if (costCenterId.HasValue)
                                            {
                                                costCenter = dbContext.CostCenter.FirstOrDefault(o => o.Id == costCenterId.Value);
                                            }

                                            newOrderItem1 = orderToUpdate.AddOrderItem(newProduct.Id, newPrice.Amount, 1, costCenter, null, false, dbContext);
                                            if (newPrice.AuthorativeCharge.HasValue)
                                            {
                                                orderToUpdate.AddOrderItem(newProduct.Id, newPrice.AuthorativeCharge.Value, 1, costCenter, newOrderItem1.Id,
                                                    newPrice.AuthorativeCharge.HasValue, dbContext);
                                            }
                                        }
                                        dbContext.SubmitChanges();
                                        allesHatGutGelaufen = true;
                                    }
                                }
                                if (allesHatGutGelaufen)
                                    dbContext.SubmitChanges();
                            }
                            catch (Exception ex)
                            {
                                return false;
                            }
                        }
                    }
                }
                else
                {
                    skipFirst = 1;
                }
            }
            return allesHatGutGelaufen;
        }
 protected void MakeInvoiceForSmallCustomer(int customerId, RegistrationOrder regOrder)
 {
     try
     {
         DataClasses1DataContext dbContext = new DataClasses1DataContext(Int32.Parse(Session["CurrentUserId"].ToString()));
         var newOrder = dbContext.Order.Single(q => q.CustomerId == customerId && q.OrderNumber == regOrder.OrderNumber);
         smallCustomerOrderHiddenField.Value = regOrder.OrderNumber.ToString();
         //updating order status
         newOrder.LogDBContext = dbContext;
         newOrder.Status = (int)OrderStatusTypes.Closed;
         //updating orderitems status
         foreach (OrderItem ordItem in newOrder.OrderItem)
         {
             ordItem.LogDBContext = dbContext;
             if (ordItem.Status != (int)OrderItemStatusTypes.Cancelled)
             {
                 ordItem.Status = (int)OrderItemStatusTypes.Closed;
             }
         }
         dbContext.SubmitChanges();
         //updating order und items status one more time to make it abgerechnet
         newOrder.LogDBContext = dbContext;
         newOrder.ExecutionDate = DateTime.Now;
         newOrder.Status = (int)OrderStatusTypes.Payed;
         dbContext.SubmitChanges();
         //opening window for adress
         string script = "function f(){$find(\"" + AddAdressRadWindow.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
         ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
         SetValuesForAdressWindow();
     }
     catch(Exception ex)
     {
         ErrorLeereTextBoxenLabel.Text = "Error: " + ex.Message;
         ErrorLeereTextBoxenLabel.Visible = true;
     }
 }
		private void attach_RegistrationOrder(RegistrationOrder entity)
		{
			this.SendPropertyChanging();
			entity.Registration = this;
		}
		private void detach_RegistrationOrder(RegistrationOrder entity)
		{
			this.SendPropertyChanging();
			entity.Vehicle = null;
		}
 partial void DeleteRegistrationOrder(RegistrationOrder instance);
 partial void UpdateRegistrationOrder(RegistrationOrder instance);
 partial void InsertRegistrationOrder(RegistrationOrder instance);
        //protected string CheckIfAllProduktsHavingPrice(int? locationId)
        //{
        //    string allesHatGutGelaufen = "";
        //    string ProduktId = "";
        //    string CostCenterId = "";
        //    foreach (RadTreeNode node in DienstleistungTreeView.Nodes)
        //    {
        //        if (!String.IsNullOrEmpty(node.Value))
        //        {
        //            string[] splited = node.Value.Split(';');
        //            if (splited.Length == 2)
        //            {
        //                try
        //                {
        //                    DataClasses1DataContext dbContext = new DataClasses1DataContext(Int32.Parse(Session["CurrentUserId"].ToString()));
        //                    Price newPrice;
        //                    ProduktId = splited[0];
        //                    CostCenterId = splited[1];
        //                    if (!String.IsNullOrEmpty(ProduktId))
        //                    {
        //                        var productId = Int32.Parse(ProduktId);
        //                        KVSCommon.Database.Product newProduct = dbContext.Product.SingleOrDefault(q => q.Id == productId);
        //                        if (locationId == null) //small
        //                        {
        //                            newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null);
        //                            if (newPrice == null)
        //                            {
        //                                allesHatGutGelaufen += " " + node.Text + " ";
        //                            }
        //                            else
        //                            {
        //                            }
        //                        }
        //                    }
        //                }
        //                catch
        //                {
        //                    return "";
        //                }
        //            }
        //        }
        //    }
        //    return allesHatGutGelaufen;
        //}
        protected void AddAnotherProducts(RegistrationOrder regOrd, int? locationId)
        {
            string ProduktId = "";
            int itemIndexValue = 0;
            decimal amount = 0;
            decimal authCharge = 0;
            var nodes = this.Request.Form.AllKeys.Where(q => q.Contains("txtItemPrice_"));
            foreach(var node in nodes)
            {
                if (!String.IsNullOrEmpty(node))
                {
                    DataClasses1DataContext dbContext = new DataClasses1DataContext(Int32.Parse(Session["CurrentUserId"].ToString()));
                    var orderNumber = regOrd.OrderNumber;
                    Price newPrice = null;
                    OrderItem newOrderItem1 = null;
                    ProduktId = node.Split('_')[1];
                    if (!String.IsNullOrEmpty(ProduktId))
                    {
                        var productId = Int32.Parse(ProduktId);

                        KVSCommon.Database.Product newProduct = dbContext.Product.SingleOrDefault(q => q.Id == productId);
                        if (locationId == null) //small
                        {
                            newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null);
                        }
                        var orderToUpdate = dbContext.Order.SingleOrDefault(q => q.OrderNumber == orderNumber);
                        orderToUpdate.LogDBContext = dbContext;
                        if (orderToUpdate != null)
                        {
                            if (this.Request.Form.GetValues(node) != null)
                            {
                                string itemPrice = this.Request.Form.GetValues(node)[0];
                                if (EmptyStringIfNull.IsNumber(itemPrice))
                                {
                                    amount = Convert.ToDecimal(itemPrice.Replace('.', ','));
                                }
                                else if (itemPrice == "")
                                {
                                    amount = 0;
                                }
                                else
                                {
                                    amount = newPrice.Amount;
                                }
                            }
                            else
                            {
                                amount = newPrice.Amount;
                            }
                            newOrderItem1 = orderToUpdate.AddOrderItem(newProduct.Id, amount, 1, null, null, false, dbContext);
                            if (newPrice!= null && newPrice.AuthorativeCharge.HasValue)
                            {
                                if (this.Request.Form.GetValues(node.Replace("txtItemPrice_", "txtAuthPrice_")) != null)
                                {
                                    string itemPrice = this.Request.Form.GetValues(node.Replace("txtItemPrice_", "txtAuthPrice_"))[0];
                                    if (EmptyStringIfNull.IsNumber(itemPrice))
                                    {
                                        amount = Convert.ToDecimal(itemPrice.Replace('.', ','));
                                    }
                                    else if (itemPrice == "")
                                    {
                                        amount = 0;
                                    }
                                    else
                                    {
                                        amount = newPrice.AuthorativeCharge.Value;
                                    }
                                }
                                else
                                {
                                    amount = newPrice.AuthorativeCharge.Value;
                                }
                                orderToUpdate.AddOrderItem(newProduct.Id, amount, 1, null, newOrderItem1.Id, newPrice.AuthorativeCharge.HasValue, dbContext);
                            }
                            itemIndexValue= itemIndexValue+1;
                            dbContext.SubmitChanges();
                        }
                    }
                }
            }
        }
Beispiel #9
0
 private static void AddAnotherProducts(RegistrationOrder regOrd, Guid? locationId, ReadmissionWiederzulassungHeader ProductCostCenterListHeader, Guid currentUserId)
 {
     bool allesHatGutGelaufen = false;
     string ProduktId = "";
     string CostCenterId = "";
     int skipFirst = 0;
     foreach (var productCostCenterPair in ProductCostCenterListHeader.ProductCostCenterList)
     {
         if (skipFirst > 0)
         {
             if (!String.IsNullOrEmpty(productCostCenterPair.ProductId) && !String.IsNullOrEmpty(productCostCenterPair.CostCenterId))
             {
                 try
                 {
                     DataClasses1DataContext dbContext = new DataClasses1DataContext(currentUserId);
                     Guid orderId = regOrd.OrderId;
                     Price newPrice;
                     OrderItem newOrderItem1 = null;
                     ProduktId = productCostCenterPair.ProductId;
                     CostCenterId = productCostCenterPair.CostCenterId;
                     if (!String.IsNullOrEmpty(ProduktId))
                     {
                         Guid productId = new Guid(ProduktId);
                         Guid costCenterId = Guid.Empty;
                         KVSCommon.Database.Product newProduct = dbContext.Product.SingleOrDefault(q => q.Id == productId);
                         if (locationId == null) //small
                         {
                             newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null);
                         }
                         else //large
                         {
                             costCenterId = new Guid(CostCenterId);
                             newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == locationId);
                             if (newPrice == null)
                                 newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null);
                         }
                         var orderToUpdate = dbContext.Order.SingleOrDefault(q => q.Id == orderId);
                         orderToUpdate.LogDBContext = dbContext;
                         if (orderToUpdate != null)
                         {
                             newOrderItem1 = orderToUpdate.AddOrderItem(newProduct.Id, newPrice.Amount, 1, costCenterId, null, false, dbContext);
                             if (newPrice.AuthorativeCharge.HasValue)
                             {
                                 orderToUpdate.AddOrderItem(newProduct.Id, newPrice.AuthorativeCharge.Value, 1, costCenterId, newOrderItem1.Id, newPrice.AuthorativeCharge.HasValue, dbContext);
                             }
                             dbContext.SubmitChanges();
                             allesHatGutGelaufen = true;
                         }
                     }
                     if (allesHatGutGelaufen)
                         dbContext.SubmitChanges();
                 }
                 catch (Exception ex)
                 {
                     throw new Exception(ex.Message);
                 }
             }
         }
         else
         {
             skipFirst = 1;
         }
     }
 }