示例#1
0
        private void include(List<CustomerGroup> groups, LongTaskExecutor executor)
        {
            try
            {

                for (int i = 0; i < groups.Count; i++)
                {
                    AnimationCustomerGroup cga = new AnimationCustomerGroup();
                    cga.IDCustomerGroup = groups[i].ID;
                    cga.IDAnimation = Animation.ID;

                    cga.OnCounterDate = Animation.OnCounterDate.HasValue? Animation.OnCounterDate.Value:DateTime.Now;
                    cga.PLVComponentDate = Animation.PLVComponentDate.HasValue? Animation.PLVComponentDate.Value:DateTime.Now;
                    cga.PLVDeliveryDate = Animation.PLVDeliveryDate.HasValue? Animation.PLVDeliveryDate.Value:DateTime.Now;
                    cga.StockDate = Animation.StockDate.HasValue? Animation.StockDate.Value:DateTime.Now;
                    cga.IncludeInAllocation = true;

                    // set the default retailer type
                    if (DefaultRetailerType != null)
                        cga.IDRetailerType = DefaultRetailerType.ID;

                    // set the default date for SAP Promotion Despatch Code
                    if (Animation != null)
                        cga.SAPDespatchCode = Animation.SAPDespatchCode;

                    // try to insert into DB if it is valid.
                    string errorMessage;
                    if (cga.IsValid(out errorMessage))
                    {
                        CustomerGroupInsertUpdate(cga);
                    }
                    else
                    {
                        continue;
                    }

                    Animation.ObservableAnimationCustomerGroups.Add(cga);

                    if (executor != null)
                    {
                        executor.SendProgressMessage(groups[i].Name + " is included into the animation.");
                    }
                }

                executor.SendProgressMessage("Recreating allocations");
                LongTaskExecutor.DoEvents();

                Db.up_recreateAllocationsAnimation(Animation.ID, false);
               
            }
            catch (SqlException sqlExc)
            {
                if (sqlExc.Number == 50000 && sqlExc.Class == 16 && sqlExc.State == 31)
                {
                    DbDataContext.MakeNewInstance();
                    this.Animation = GetByID(this.Animation.ID);
                }
                else
                {
                    MessageBox.Show(SystemMessagesManager.Instance.GetMessage("TableViewExceptionSql", Utility.GetExceptionsMessages(sqlExc)));
                }
            }

        }