Ejemplo n.º 1
0
        public void AddNewDetailRow(bool checkLastRow)
        {
            var currentRowIndex = (TransactionHeader.DetailsList.IndexOf(SelectedDetailRow));

            if (checkLastRow)
            {
                var valiationCollection = new List <ValidationResult>();

                var isvalid = SelectedDetailRow != null &&
                              Validator.TryValidateObject(SelectedDetailRow,
                                                          new ValidationContext(SelectedDetailRow, null, null), valiationCollection, true);
                if (!isvalid)
                {
                    return;
                }

                if (
                    TransactionHeader.DetailsList.Count(
                        x =>
                        x.Brand == SelectedDetailRow.Brand &&
                        x.TblLkpBrandSection == SelectedDetailRow.TblLkpBrandSection &&
                        x.TblLkpSeason == SelectedDetailRow.TblLkpSeason &&
                        SelectedDetailRow.TblBudgetItem == x.TblBudgetItem) > 1)
                {
                    MessageBox.Show("Cannot Duplicate The Full Criteria");
                    SelectedDetailRow.BrandSectionPerRow = null;
                    SelectedDetailRow.SeasonPerRow       = null;
                    SelectedDetailRow.BudgetItemPerRow   = null;

                    isvalid = false;
                }

                if (!isvalid)
                {
                    return;
                }
                if (AllowAdd != true)
                {
                    MessageBox.Show(strings.AllowAddMsg);
                    return;
                }
            }
            var newrow = new TblGlobalRetailBusinessBudgetMainDetailViewModel
            {
                TblGlobalRetailBusinessBudget = TransactionHeader.Iserial
            };

            TransactionHeader.DetailsList.Insert(currentRowIndex + 1, newrow);

            SelectedDetailRow = newrow;
        }
Ejemplo n.º 2
0
        public GlobalRetailBusinessBudgetViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                Client.GetTblBudgetItemAsync();
                Client.GetTblBudgetItemCompleted += (s, sv) =>
                {
                    BrandBudgetList = sv.Result;
                };
                YearList  = new List <int>();
                MonthList = new Dictionary <int, string>();
                for (var i = 0; i < 10; i++)
                {
                    const int yearNumber = 2014;
                    YearList.Add(yearNumber + i);
                }
                var names = new[]
                {
                    "Jan", "Feb", "Mar",
                    "Apr", "May", "Jun",
                    "Jul", "Aug", "Sep",
                    "Oct", "Nov", "Dec"
                };
                MonthTotallist = new ObservableCollection <MonthTotal>();
                for (int i = 1; i < names.Count() + 1; i++)
                {
                    MonthList.Add(i, names[i - 1]);
                    MonthTotallist.Add(new MonthTotal
                    {
                        Month  = i,
                        Amount = 0
                    });
                }
                TransactionHeader = new TblGlobalRetailBusinessBudgetViewModel();
                GetItemPermissions(PermissionItemName.GlobalRetailBusinessBudget.ToString());

                MainRowList        = new SortableCollectionView <TblGlobalRetailBusinessBudgetViewModel>();
                SelectedDetailRows = new ObservableCollection <TblGlobalRetailBusinessBudgetMainDetailViewModel>();
                SelectedDetailRow  = new TblGlobalRetailBusinessBudgetMainDetailViewModel();

                Client.GetAllBrandsCompleted += (s, ev) =>
                {
                    Brands = ev.Result;
                };

                Client.GetAllBrandsAsync(LoggedUserInfo.Iserial);

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

                Client.DeleteTblGlobalRetailBusinessBudgetMainDetailCompleted += (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.UpdateOrInsertTblGlobalRetailBusinessBudgetMainDetailCompleted += (x, y) =>
                {
                    var savedRow =
                        (TblGlobalRetailBusinessBudgetMainDetailViewModel)
                        TransactionHeader.DetailsList.GetItemAt(y.outindex);

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(y.Result);
                        if (TransactionHeader.Iserial == 0)
                        {
                            TransactionHeader.Iserial = y.Result.TblGlobalRetailBusinessBudget;
                        }
                        foreach (var variable in savedRow.DetailsList)
                        {
                            var newRow = y.Result.TblGlobalRetailBusinessBudgetDetails.FirstOrDefault(w => w.Month == variable.Month);
                            if (newRow != null)
                            {
                                variable.Iserial = newRow.Iserial;
                                variable.Month   = newRow.Month;
                                variable.TblGlobalRetailBusinessBudgetMainDetail =
                                    newRow.TblGlobalRetailBusinessBudgetMainDetail;
                            }
                        }
                    }
                };

                Client.GetTblGlobalRetailBusinessBudgetMainDetailCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblGlobalRetailBusinessBudgetMainDetailViewModel();
                        newrow.InjectFrom(row);
                        newrow.BrandSectionPerRow = row.TblLkpBrandSection1;
                        newrow.SeasonPerRow       = row.TblLkpSeason1;
                        newrow.BudgetItemPerRow   = row.TblBudgetItem1;
                        foreach (var variable in row.TblGlobalRetailBusinessBudgetDetails)
                        {
                            var oldRow = newrow.DetailsList.FirstOrDefault(w => w.Month == variable.Month);
                            if (oldRow != null)
                            {
                                oldRow.Iserial = variable.Iserial;
                                oldRow.Month   = variable.Month;
                                oldRow.Amount  = variable.Amount;
                                oldRow.TblGlobalRetailBusinessBudgetMainDetail = variable.TblGlobalRetailBusinessBudgetMainDetail;
                            }
                        }
                        newrow.TotalAmount = newrow.DetailsList.Sum(x => x.Amount);
                        TransactionHeader.DetailsList.Add(newrow);
                    }
                    TransactionHeader.AddTotalRow();
                    foreach (var row in TransactionHeader.MonthTotallist)
                    {
                        var total = 0;
                        foreach (var variable in TransactionHeader.DetailsList.Where(x => x.Iserial != 1))
                        {
                            total = (int)(total + variable.DetailsList.FirstOrDefault(x => x.Month == row.Month).Amount);
                        }

                        TransactionHeader.DetailsList.FirstOrDefault(x => x.Iserial == -1)
                        .DetailsList.FirstOrDefault(x => x.Month == row.Month)
                        .Amount = total;
                    }

                    TransactionHeader.DetailsList.FirstOrDefault(x => x.Iserial == -1).TotalAmount =
                        TransactionHeader.DetailsList.Where(x => x.Iserial != -1).Sum(x => x.TotalAmount);
                };

                Client.GetTblGlobalRetailBusinessBudgetCompleted += (y, v) =>
                {
                    foreach (var row in v.Result)
                    {
                        Loading = false;
                        var newrow = new TblGlobalRetailBusinessBudgetViewModel();
                        newrow.InjectFrom(row);

                        MainRowList.Add(newrow);
                    }
                    FullCount = v.fullCount;
                };

                Client.UpdateOrInsertTblGlobalRetailBusinessBudgetCompleted += (s, x) =>
                {
                    if (x.Error == null)
                    {
                        TransactionHeader.InjectFrom(x.Result);
                    }
                    else
                    {
                        MessageBox.Show(x.Error.Message);
                    }
                    Loading = false;

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