public void AddNewMainRow(bool checkLastRow) { 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; } } if (AllowAdd != true) { MessageBox.Show(strings.AllowAddMsg); return; } var newrow = new TblCostCenterOrganizationUnitViewModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public void DeleteMainRow() { var res = MessageBox.Show("Are You To Delete SelectedRecords From Database ?", "Delete", MessageBoxButton.OKCancel); if (res == MessageBoxResult.OK) { if (SelectedMainRow.Iserial != 0) { if (AllowDelete != true) { MessageBox.Show(strings.AllowDeleteMsg); return; } Loading = true; Glclient.DeleteTblCostCenterOrganizationUnitAsync( (TblCostCenterOrganizationUnit) new TblCostCenterOrganizationUnit().InjectFrom(SelectedMainRow), 0, LoggedUserInfo.DatabasEname); } else { SelectedMainRow = new TblCostCenterOrganizationUnitViewModel(); } } }
public CostCenterOrganizationUnitViewModel() { if (!DesignerProperties.IsInDesignTool) { GetItemPermissions(PermissionItemName.CostCenterOrganizationUnit.ToString()); MainRowList = new ObservableCollection <TblCostCenterOrganizationUnitViewModel>(); //var CostCenterTypeClient = new GlServiceClient(); //CostCenterTypeClient.GetGenericCompleted += (s, sv) => { DepreciationMethodList = sv.Result; }; //CostCenterTypeClient.GetGenericAsync("TblDepreciationMethod", "%%", "%%", "%%", "Iserial", "ASC", // LoggedUserInfo.DatabasEname); Glclient.UpdateOrInsertTblCostCenterOrganizationUnitsCompleted += (s, x) => { if (x.Error != null) { MessageBox.Show(x.Error.Message); } try { MainRowList.ElementAt(x.outindex).InjectFrom(x.Result); } catch (Exception) { } Loading = false; }; Glclient.GetTblCostCenterAsync(0, int.MaxValue, null, "It.Iserial", null, null, LoggedUserInfo.DatabasEname, LoggedUserInfo.Iserial, 0, 0); Glclient.GetTblCostCenterCompleted += (s, sv) => { CostCenterList = sv.Result; }; Glclient.DeleteTblCostCenterOrganizationUnitCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } SelectedMainRow = new TblCostCenterOrganizationUnitViewModel(); }; Glclient.GetPayrollOrganizationUnitAsync(); Glclient.GetPayrollOrganizationUnitCompleted += (s, sv) => { PayrollOrganizationUnitList = sv.Result; }; Glclient.GetTblCostCenterOrganizationUnitCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblCostCenterOrganizationUnitViewModel(); newrow.InjectFrom(row); newrow.CostCenterPerRow = new TblCostCenter(); if (row.TblCostCenter1 != null) { newrow.CostCenterPerRow = row.TblCostCenter1; } //newrow.SumCostCenterPerRow = new TblCostCenter(); //if (row.TblCostCenter2 != null) newrow.SumCostCenterPerRow = row.TblCostCenter2; MainRowList.Add(newrow); } Loading = false; FullCount = sv.fullCount; if (MainRowList.Any() && (SelectedMainRow == null)) { SelectedMainRow = MainRowList.FirstOrDefault(); } if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } }; GetMaindata(); } }