Пример #1
0
        public TblGlobalRetailBusinessBudgetMainDetailViewModel()
        {
            Client.GetTblBrandSectionLinkCompleted += (s, ev) =>
            {
                foreach (var row in ev.Result)
                {
                    if (Brandsection.All(x => x.Iserial != row.TblLkpBrandSection))
                    {
                        Brandsection.Add(row.TblLkpBrandSection1);
                    }
                }
            };
            var monthList = new Dictionary <int, string>();
            var names     = new[]
            {
                "Jan", "Feb", "Mar",
                "Apr", "May", "Jun",
                "Jul", "Aug", "Sep",
                "Oct", "Nov", "Dec"
            };

            for (int i = 1; i < names.Count() + 1; i++)
            {
                monthList.Add(i, names[i - 1]);
            }

            DetailsList = new SortableCollectionView <TblGlobalRetailBusinessBudgetDetailViewModel>();
            foreach (var variable in monthList)
            {
                DetailsList.Add(new TblGlobalRetailBusinessBudgetDetailViewModel
                {
                    Month = variable.Key,
                    TblGlobalRetailBusinessBudgetMainDetail = Iserial,
                });
            }
        }
Пример #2
0
        public BrandBudgetViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                TransactionHeader = new TblBrandBudgetsHeaderViewModel();
                GetItemPermissions(PermissionItemName.BrandBudget.ToString());

                MainRowList        = new SortableCollectionView <TblBrandBudgetsHeaderViewModel>();
                SelectedDetailRows = new ObservableCollection <TblBrandBudgetDetailViewModel>();
                SelectedDetailRow  = new TblBrandBudgetDetailViewModel();
                TransactionHeader.PropertyChanged += (sender, sv) =>
                {
                    if (sv.PropertyName == "Brand")
                    {
                        Brandsection.Clear();
                        lkpClient.GetTblBrandSectionLinkAsync(TransactionHeader.Brand, LoggedUserInfo.Iserial);
                    }
                    else if (sv.PropertyName == "TblLkpBrandSection")
                    {
                        // GetFamilyLink();
                        TransactionHeader.DirectionList.Clear();
                        GetDirectionLink();
                    }

                    else if (sv.PropertyName == "TblLkpDirection")
                    {
                        TransactionHeader.StyleCategoryList.Clear();
                        GetStyleCategoryLink();
                    }


                    DataGridName = "MainGrid";
                };

                var factorGroupClient = new CRUD_ManagerServiceClient();
                factorGroupClient.GetGenericCompleted += (s, sv) =>
                {
                    FactoryGroupList = sv.Result;
                };
                factorGroupClient.GetGenericAsync("TblFactoryGroup", "%%", "%%", "%%", "Iserial", "ASC");

                //lkpClient.GetTblFamilyLinkCompleted += (s, sv) =>
                //{
                //    foreach (var row in sv.Result)
                //    {
                //        if (TransactionHeader.FamilyList != null && (TransactionHeader != null && TransactionHeader.FamilyList.All(x => x.Iserial != row.TblFamily1.Iserial)))
                //        {
                //            TransactionHeader.FamilyList.Add( new TblFamily().InjectFrom( row.TblFamily1) as TblFamily);
                //        }
                //    }
                //};

                lkpClient.FamilyCategory_GetTblFamilyCategoryLinkCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (TransactionHeader.FamilyList != null && (TransactionHeader != null && TransactionHeader.FamilyList.All(x => x.Iserial != row.TblFamily1.Iserial)))
                        {
                            TransactionHeader.FamilyList.Add(new TblFamily().InjectFrom(row.TblFamily1) as TblFamily);
                        }
                    }
                };


                lkpClient.GetTblDirectionLinkCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (TransactionHeader.DirectionList != null && (TransactionHeader != null && TransactionHeader.DirectionList.All(x => x.Iserial != row.TblLkpDirection1.Iserial)))
                        {
                            TransactionHeader.DirectionList.Add(new TblLkpDirection().InjectFrom(row.TblLkpDirection1) as TblLkpDirection);
                        }
                    }
                };

                lkpClient.FamilyCategory_GetTblCategoryLinkCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (TransactionHeader.StyleCategoryList != null && (TransactionHeader != null && TransactionHeader.StyleCategoryList.All(x => x.Iserial != row.TblStyleCategory1.Iserial)))
                        {
                            TransactionHeader.StyleCategoryList.Add(new TblStyleCategory().InjectFrom(row.TblStyleCategory1) as TblStyleCategory);
                        }
                    }
                };


                //Client.GetTblSalesOrderColorThemeCompleted += (s, sv) =>
                //{
                //    foreach (var row in sv.Result)
                //    {
                //        if (TransactionHeader.ThemeList != null && (TransactionHeader != null && TransactionHeader.ThemeList.All(x => x.Iserial != row.Iserial)))
                //        {
                //            TransactionHeader.ThemeList.Add(row);
                //        }
                //    }
                //};
                Client.GetAllBrandsCompleted += (s, ev) =>
                {
                    Brands = ev.Result;
                };

                Client.GetAllBrandsAsync(LoggedUserInfo.Iserial);

                Client.GetAllSeasonsCompleted += (s, ev) =>
                {
                    Seasons = ev.Result;
                };
                Client.GetAllSeasonsAsync();

                lkpClient.GetTblBrandSectionLinkCompleted += (s, ev) =>
                {
                    foreach (var row in ev.Result)
                    {
                        if (Brandsection.All(x => x.Iserial != row.TblLkpBrandSection))
                        {
                            Brandsection.Add(row.TblLkpBrandSection1);
                        }
                    }
                };

                Client.DeleteTblBrandBudgetDetailCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

                    var oldrow = TransactionHeader.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        TransactionHeader.DetailsList.Remove(oldrow);
                    }
                };

                Client.UpdateOrInsertTblBrandBudgetDetailCompleted += (x, y) =>
                {
                    var savedRow = (TblBrandBudgetDetailViewModel)TransactionHeader.DetailsList.GetItemAt(y.outindex);

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(y.Result);
                        if (TransactionHeader.Iserial == 0)
                        {
                            TransactionHeader.Iserial = y.Result.TblBrandBudgetHeader;
                        }
                    }
                };
                Client.GetTblBrandBudgetDetailCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblBrandBudgetDetailViewModel();
                        newrow.InjectFrom(row);

                        if (row.TblFamily1 != null)
                        {
                            newrow.FamilyPerRow = row.TblFamily1;

                            if (TransactionHeader != null && TransactionHeader.FamilyList.All(x => x.Iserial != row.TblFamily1.Iserial))
                            {
                                TransactionHeader.FamilyList.Add(newrow.FamilyPerRow);
                            }
                        }

                        if (row.TblLkpDirection1 != null)
                        {
                            newrow.DirectionPerRow = row.TblLkpDirection1;

                            if (TransactionHeader != null && TransactionHeader.DirectionList.All(x => x.Iserial != row.TblLkpDirection1.Iserial))
                            {
                                TransactionHeader.DirectionList.Add(newrow.DirectionPerRow);
                            }
                        }

                        if (row.TblStyleCategory1 != null)
                        {
                            newrow.StyleCategoryPerRow = row.TblStyleCategory1;

                            if (TransactionHeader != null && TransactionHeader.StyleCategoryList.All(x => x.Iserial != row.TblStyleCategory1.Iserial))
                            {
                                TransactionHeader.StyleCategoryList.Add(newrow.StyleCategoryPerRow);
                            }
                        }
                        //if (row.TblSalesOrderColorTheme1 != null)
                        //{
                        //    newrow.ThemePerRow = row.TblSalesOrderColorTheme1;
                        //    if (TransactionHeader != null && TransactionHeader.ThemeList.All(x => x.Iserial != row.TblSalesOrderColorTheme))
                        //    {
                        //        TransactionHeader.ThemeList.Add(newrow.ThemePerRow);
                        //    }
                        //}

                        newrow.FactoryGroupPerRow = new GenericTable();
                        if (row.TblFactoryGroup1 != null)
                        {
                            newrow.FactoryGroupPerRow.InjectFrom(row.TblFactoryGroup1);
                        }
                        TransactionHeader.DetailsList.Add(newrow);
                    }
                    TransactionHeader.AddTotalRow();
                };

                Client.GetTblBrandBudgetHeaderCompleted += (y, v) =>
                {
                    foreach (var row in v.Result)
                    {
                        Loading = false;
                        var newrow = new TblBrandBudgetsHeaderViewModel();
                        newrow.InjectFrom(row);
                        newrow.BrandSectionPerRow = row.TblLkpBrandSection1;
                        newrow.SeasonPerRow       = row.TblLkpSeason1;
                        MainRowList.Add(newrow);
                    }
                };

                Client.UpdateOrInsertTblBrandBudgetHeaderCompleted += (s, x) =>
                {
                    if (x.Error == null)
                    {
                        TransactionHeader.InjectFrom(x.Result);
                        try
                        {
                            foreach (var item in TransactionHeader.DetailsList)
                            {
                                item.TblBrandBudgetHeader = x.Result.Iserial;
                                //    Client.UpdateOrInsertTblBrandBudgetDetailAsync(item, true,
                                //     LoggedUserInfo.Iserial);

                                TblBrandBudgetDetail myitem = new TblBrandBudgetDetail();
                                myitem.Amount     = item.Amount;
                                myitem.NoOfColors = item.NoOfColors;
                                myitem.NoOfStyles = item.NoOfStyles;
                                myitem.Retail     = item.Retail;
                                //   myitem.TblSalesOrderColorTheme = item.TblSalesOrderColorTheme;
                                //  myitem.PaymentDate = item.PaymentDate;
                                myitem.Qty = item.Qty;
                                myitem.TblBrandBudgetHeader = x.Result.Iserial;
                                myitem.TblFamily            = item.TblFamily;
                                myitem.TblLkpDirection      = item.TblLkpDirection;
                                myitem.TblStyleCategory     = item.TblStyleCategory;

                                Client.SaveBrandBudgetAsync(myitem, LoggedUserInfo.Iserial);
                            }
                            MessageBox.Show("All items have been saved successfully.", "Success", MessageBoxButton.OK);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Couldn't save listed items..", "Failed", MessageBoxButton.OK);
                        }
                    }
                    else
                    {
                        MessageBox.Show(x.Error.Message);
                    }
                    Loading = false;

                    //TransactionHeader.InjectFrom(x.Result);
                };
                Client.DeleteTblBrandBudgetHeaderCompleted += (w, k) =>
                {
                    Loading = false;
                    TransactionHeader.InjectFrom(new TblBrandBudgetsHeaderViewModel());
                };
            }
        }