Ejemplo n.º 1
0
        // generating capacities
        private void btnGenerate_Click(object sender, RoutedEventArgs e)
        {
            int capacityValue = 0;
            int.TryParse(txtCapacityValue.Text, out capacityValue);

            IEnumerable<Customer> selectedCustomers = customers.Where(c => c.IsSelected);

            #region Validation warning
            if (capacityValue == 0)
            {
                MessageBox.Show("Please set positive capacity value");
                return;
            }

            if (cboAnimationType.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select animation type");
                return;
            }

            if (cboItemType.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select item type");
                return;
            }

            if (cboPriority.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select priority");
                return;
            }

            if (selectedCustomers.Count() == 0)
            {
                MessageBox.Show("Please select at least one customer");
                return;
            }
            #endregion

            // warning before ovewriting
            DbDataContext simpleContext = new DbDataContext(false);
            LongTaskExecutor createCapacity = new LongTaskExecutor("");
  

            IEnumerable<Customer> customersWithCapacitiesAlreadyInDB = simpleContext.CustomerCapacities.Where(ca => ca.IDAnimationType == ((AnimationType)cboAnimationType.SelectedItem).ID
                && ca.IDItemType == ((ItemType)cboItemType.SelectedItem).ID               
                && ca.IDPriority == ((Priority)cboPriority.SelectedItem).ID
                && selectedCustomers.Contains((Customer)ca.Customer)).Select(ca => ca.Customer).Distinct().ToList();

            if (customersWithCapacitiesAlreadyInDB.Count() > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Customer a in customersWithCapacitiesAlreadyInDB)
                {
                    sb.AppendLine(String.Format("{0} {1}", a.AccountNumber, a.Name));
                }

                String warningMessage = String.Format("{0} \r\n{1}", SystemMessagesManager.Instance.GetMessage("OverwriteCustomerCapacity"), sb.ToString());

                if (MessageBox.Show(warningMessage, "Warning", MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }                    
                else
                {                    
                    createCapacity.DoWork += createCapacity_DoWork;
                    createCapacity.Run(selectedCustomers);
                }  
            }
           

            createCapacity.DoWork += createCapacity_DoWork;
            createCapacity.Run(selectedCustomers);

           
        }
Ejemplo n.º 2
0
 void ucAnimationList_EditAnimation(object sender, Animation animation)
 {
     LongTaskExecutor animationOpener = new LongTaskExecutor("Opening the animation - " + animation.Name);
     animationOpener.DoWork += new DoWorkEventHandler(animationOpener_DoWork);
     animationOpener.Run(animation);
 }
Ejemplo n.º 3
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            IEnumerable<Customer> selectedCustomers = customers.Where(c => c.IsSelected);

            #region Validation warning

            if (cboAnimationType.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select animation type");
                return;
            }

            if (cboItemType.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select item type");
                return;
            }

            if (cboPriority.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select priority");
                return;
            }

            if (selectedCustomers.Count() == 0)
            {
                MessageBox.Show("Please select at least one customer");
                return;
            }
            #endregion

            LongTaskExecutor deleteCapacity = new LongTaskExecutor("");
            deleteCapacity.DoWork += deleteCapacity_DoWork;
            deleteCapacity.Run(selectedCustomers);

        }
Ejemplo n.º 4
0
 private void Include()
 {
     LongTaskExecutor includeExecutor = new LongTaskExecutor("Including selected customer groups");
     includeExecutor.TaskFinished += new EventHandler(includeExecutor_TaskFinished);
     includeExecutor.DoWork += new DoWorkEventHandler(includeExecutor_DoWork);
     includeExecutor.Run();
 }
Ejemplo n.º 5
0
 private void IncludeAll()
 {
     LongTaskExecutor includeAllExecutor = new LongTaskExecutor("Including all customer groups into animation");
     includeAllExecutor.TaskFinished += new EventHandler(includeAllExecutor_TaskFinished);
     includeAllExecutor.DoWork += new DoWorkEventHandler(includeAllExecutor_DoWork);
     includeAllExecutor.Run();
 }
Ejemplo n.º 6
0
 private void recreateAllocationsForProduct(AnimationProduct animationProduct)
 {
     LongTaskExecutor recreateAllocationsExecutor = new LongTaskExecutor("Recreating allocations");
     recreateAllocationsExecutor.DoWork += new DoWorkEventHandler(recreateAllocationsForProductExecutor_DoWork);
     recreateAllocationsExecutor.Run(animationProduct);
 }
Ejemplo n.º 7
0
 public void RecalculateAnimationProduct(RecalculationType calcType, AnimationProduct entity = null)
 {
     if (calcType == RecalculationType.CalculateTotal)
     {
         LongTaskExecutor recalculationExecutor = new LongTaskExecutor("Recalculating capacities ...");
         recalculationExecutor.DoWork += new DoWorkEventHandler(recalculationExecutor_DoWork);
         recalculationExecutor.Run(entity);
     }
     else if (calcType == RecalculationType.CalculateActiveAnimations)
     {
         LongTaskExecutor calcActiveAnimationExecutor = new LongTaskExecutor("Recalculating active animations ...");
         calcActiveAnimationExecutor.DoWork += new DoWorkEventHandler(calcActiveAnimationExecutor_DoWork);
         calcActiveAnimationExecutor.Run();
     }
     else if (calcType == RecalculationType.CalculateTotalCapacity && entity != null)
     {
         LongTaskExecutor calcTotalCapacityExecutor = new LongTaskExecutor("Recalculating total capacity for " + entity.ProductIdentifier);
         calcTotalCapacityExecutor.DoWork += new DoWorkEventHandler(calcTotalCapacityExecutor_DoWork);
         calcTotalCapacityExecutor.Run();
     }
     else if (calcType == RecalculationType.CalculateProductRecieved && entity != null)
     {
         LongTaskExecutor calcTotalCapacityExecutor = new LongTaskExecutor("Recalculating product recieved  ");
         calcTotalCapacityExecutor.DoWork += new DoWorkEventHandler(calcProductRecievedExecutor_DoWork);
         calcTotalCapacityExecutor.Run();
     }
     else if (calcType == RecalculationType.CalculateTotalAnimationQuantity)
     {
         Animation.AnimationProducts.ToList().ForEach(ap => ap.TotalAnimationQuantity = -1);
     }
 }
Ejemplo n.º 8
0
 public void RecreateAllocations()
 {
     LongTaskExecutor recreateAllocationsExecutor = new LongTaskExecutor("Recreating allocations");
     recreateAllocationsExecutor.DoWork +=new DoWorkEventHandler(recreateAllocationsExecutor_DoWork);
     recreateAllocationsExecutor.Run();
 }
Ejemplo n.º 9
0
 public void Save()
 {
     LongTaskExecutor saveAnimationExecutor = new LongTaskExecutor("Saving animation");
     saveAnimationExecutor.DoWork += new DoWorkEventHandler(saveAnimationExecutor_DoWork);
     saveAnimationExecutor.Run();
 }
Ejemplo n.º 10
0
 private void RemoveAll()
 {
     removeAllExecutor = new LongTaskExecutor("Removing all customer groups from animation");
     removeAllExecutor.TaskFinished += new EventHandler(removeAllExecutor_TaskFinished);
     removeAllExecutor.DoWork += new DoWorkEventHandler(removeAllExecutor_DoWork);
     removeAllExecutor.Run();
 }
Ejemplo n.º 11
0
//        private void PreProcessBeforeRemove(AnimationCustomerGroup acg)
//        {
//            // delete customer allocations
//            string caDeleteString = @"Delete from CustomerAllocation
//                                      Where IDAnimationProductDetail in (Select ID from AnimationProductDetail Where IDAnimationProduct in (Select ID from AnimationProduct Where IDAnimation={0}) )
//                                      AND (Select IDCustomerGroup from Customer as C Where C.ID = IDCustomer) = {1}";
//            int rows = Db.ExecuteCommand(caDeleteString, acg.IDAnimation, acg.IDCustomerGroup);

//            // delete customer group allocations
//            string cgaDeleteString = @"Delete from CustomerGroupAllocation
//                                      Where IDAnimationProductDetail in (Select ID from AnimationProductDetail Where IDAnimationProduct in (Select ID from AnimationProduct Where IDAnimation={0}) )
//                                      AND IDCustomerGroup = {1}";
//            rows = Db.ExecuteCommand(cgaDeleteString, acg.IDAnimation, acg.IDCustomerGroup);
                
//        }

        private void Remove()
        {
            LongTaskExecutor removeExecutor = new LongTaskExecutor("Removing a customer group");
            removeExecutor.TaskFinished += new EventHandler(removeExecutor_TaskFinished);
            removeExecutor.DoWork += new DoWorkEventHandler(removeExecutor_DoWork);
            removeExecutor.Run();
        }
Ejemplo n.º 12
0
        private void btnRunAllocation_Click(object sender, RoutedEventArgs e)
        {
            tabResults.Items.Clear();

            if (cboeAnimations.SelectedItem != null)
            {
                Animation ani = cboeAnimations.SelectedItem as Animation;

                if (ani != null)
                {
                    // check if SAP order is created
                    if (ani.DateSAPOrderCreated != null)
                    {
                        if (MessageBox.Show(SystemMessagesManager.Instance.GetMessage("RunAllocationOrderCreated"), "Warning", MessageBoxButton.YesNo) == MessageBoxResult.No)
                            return;
                    }

                    LongTaskExecutor runAllocationExecutor = new LongTaskExecutor("Running allocation for "+ani.Name);
                    runAllocationExecutor.DoWork += new System.ComponentModel.DoWorkEventHandler(runAllocationExecutor_DoWork);
                    runAllocationExecutor.Run(ani);
                }
            }
            else
            {
                string systemMessage = SystemMessagesManager.Instance.GetMessage("RunAllocationOrderCreated");
                string warning = String.Empty;

                foreach (Animation animation in cboeAnimations.ItemsSource)
                {
                    if (animation.DateSAPOrderCreated != null)
                    {
                        warning += string.Format(systemMessage, animation.Name) + Environment.NewLine;
                    }
                }

                if (!String.IsNullOrEmpty(warning) && MessageBox.Show(warning, "Warning", MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }
                
                //Run for all animation in selected sales drive
                foreach (Animation animation in cboeAnimations.ItemsSource)
                {
                    if (animation != null)
                    {
                        // check if SAP order is created
                        if (animation.DateSAPOrderCreated != null)
                        {
                            if (System.Windows.MessageBox.Show(SystemMessagesManager.Instance.GetMessage("RunAllocationOrderCreated", animation.Name), "Warning", MessageBoxButton.YesNo) == MessageBoxResult.No)
                            {
                                return;
                            }
                        }

                        LongTaskExecutor runAllocationExecutor = new LongTaskExecutor("Running allocation for "+animation.Name);
                        runAllocationExecutor.DoWork += new System.ComponentModel.DoWorkEventHandler(runAllocationExecutor_DoWork);
                        runAllocationExecutor.Run(animation);
                    }
                }
            }

            if (tabResults.Items.Count > 0)
            {
                tabResults.SelectedIndex = 0;
            }
        }