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 TblGeneratePurchaseHeaderCurrenciesViewModel
            {
                TblGeneratePurchaseHeader = _generatepurchasehaderIserial
            };

            MainRowList.Insert(currentRowIndex + 1, newrow);
            SelectedMainRow = newrow;
        }
        public GeneratePurchaseHeaderCurrenciesViewModel(int generatePurchaseHeader)
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                _generatepurchasehaderIserial = generatePurchaseHeader;
                GetItemPermissions(PermissionItemName.GeneratePurchase.ToString());
                MainRowList     = new SortableCollectionView <TblGeneratePurchaseHeaderCurrenciesViewModel>();
                SelectedMainRow = new TblGeneratePurchaseHeaderCurrenciesViewModel();
                Client.GetTblCurrencyCompleted += (s, sv) =>
                {
                    CurrencyList = sv.Result;
                };
                Client.GetTblCurrencyAsync(0, int.MaxValue, "it.Iserial", null, null);

                GetMaindata();
                Client.TblGeneratePurchaseHeaderCurrencyCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblGeneratePurchaseHeaderCurrenciesViewModel();
                        newrow.InjectFrom(row);
                        MainRowList.Add(newrow);
                    }
                    Loading   = false;
                    FullCount = sv.fullCount;
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };

                Client.UpdateOrInsertTblGeneratePurchaseHeaderCurrencyCompleted += (s, x) =>
                {
                    var savedRow = (TblGeneratePurchaseHeaderCurrenciesViewModel)MainRowList.GetItemAt(x.outindex);
                    Loading = false;
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                };
                Client.DeleteTblGeneratePurchaseHeaderCurrencyCompleted += (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);
                    }
                };
            }
        }