示例#1
0
        public void AddNewMainRow(bool checkLastRow)
        {
            if (AllowAdd != true)
            {
                MessageBox.Show(strings.AllowAddMsg);
                return;
            }
            var currentRowIndex = (MainRowList.IndexOf(SelectedMainRow));

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

                var isvalid = Validator.TryValidateObject(SelectedMainRow,
                                                          new ValidationContext(SelectedMainRow, null, null), valiationCollection, true);

                if (!isvalid)
                {
                    return;
                }
            }
            var newrow = new TblSeasonCurrenciesViewModel();

            MainRowList.Insert(currentRowIndex + 1, newrow);
            SelectedMainRow = newrow;
        }
示例#2
0
        public SeasonCurrenciesViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                GetItemPermissions(PermissionItemName.SeasonCurrenciesForm.ToString());
                MainRowList     = new SortableCollectionView <TblSeasonCurrenciesViewModel>();
                SelectedMainRow = new TblSeasonCurrenciesViewModel();
                Client.GetTblCurrencyCompleted += (s, sv) =>
                {
                    CurrencyList = sv.Result;
                };
                Client.GetTblCurrencyAsync(0, int.MaxValue, "it.Iserial", null, null);
                var seasonClient = new CRUD_ManagerServiceClient();
                seasonClient.GetAllSeasonsCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (SeasonList.All(x => x.Iserial != row.Iserial))
                        {
                            SeasonList.Add(new TblLkpSeason().InjectFrom(row) as TblLkpSeason);
                        }
                    }
                    GetMaindata();
                };
                seasonClient.GetAllSeasonsAsync();

                Client.GetTblSeasonCurrencyCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblSeasonCurrenciesViewModel();
                        newrow.SeasonPerRow = new TblLkpSeason();
                        newrow.SeasonPerRow = SeasonList.FirstOrDefault(x => x.Iserial == row.TblLkpSeason);
                        newrow.InjectFrom(row);
                        MainRowList.Add(newrow);
                    }
                    Loading   = false;
                    FullCount = sv.fullCount;
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };

                Client.UpdateOrInsertTblSeasonCurrencyCompleted += (s, x) =>
                {
                    var savedRow = (TblSeasonCurrenciesViewModel)MainRowList.GetItemAt(x.outindex);
                    Loading = false;
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                };
                Client.DeleteTblSeasonCurrencyCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }
                    Loading = false;
                    var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        MainRowList.Remove(oldrow);
                    }
                };
            }
        }