public void SaveOldRow(TblSalaryApprovalHeaderModel oldRow) { if (oldRow != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(oldRow, new ValidationContext(oldRow, null, null), valiationCollection, true); if (isvalid) { var save = oldRow.Iserial == 0; if (AllowUpdate != true && !save) { MessageBox.Show(strings.AllowUpdateMsg); return; } var saveRow = new BankDepositService.TblSalaryApprovalHeader(); saveRow.InjectFrom(oldRow); BankDepositClient.UpdateOrInsertSalaryApprovalHeaderAsync(saveRow, MainRowList.IndexOf(oldRow), LoggedUserInfo.Iserial, LoggedUserInfo.DatabasEname); } } }
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 TblSalaryApprovalHeaderModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public SalaryApprovalViewModel() { if (!IsDesignTime) { GetItemPermissions(PermissionItemName.SalaryApproval.ToString()); MainRowList = new ObservableCollection <TblSalaryApprovalHeaderModel>(); SelectedMainRow = new TblSalaryApprovalHeaderModel(); BankDepositClient.GetSalaryApprovalHeaderCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblSalaryApprovalHeaderModel(); newrow.SalaryTypePerRow = row.TblSalaryType1; newrow.TblStore1 = row.TblStore1; newrow.InjectFrom(row); MainRowList.Add(newrow); } Loading = false; FullCount = sv.fullCount; if (MainRowList.Any() && (SelectedMainRow == null)) { SelectedMainRow = MainRowList.FirstOrDefault(); } if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } }; BankDepositClient.DeleteSalaryApprovalDetailCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } var oldrow = SelectedMainRow.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { SelectedMainRow.DetailsList.Remove(oldrow); } }; BankDepositClient.UpdateOrInsertSalaryApprovalHeaderCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } Loading = false; }; BankDepositClient.GetSalaryApprovalDetailCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblSalaryApprovalDetailModel(); newrow.EmpPerRow = sv.EmpList.FirstOrDefault(w => w.iserial == row.TblEmployee); newrow.InjectFrom(row); SelectedMainRow.DetailsList.Add(newrow); } Loading = false; DetailFullCount = sv.fullCount; if (SelectedMainRow.DetailsList.Any() && (SelectedDetailRow == null)) { SelectedDetailRow = SelectedMainRow.DetailsList.FirstOrDefault(); } if (DetailFullCount == 0 && SelectedMainRow.DetailsList.Count == 0) { AddNewDetailRow(false); } }; BankDepositClient.ImportSalaryApprovalCompleted += (s, sv) => { GetMaindata(); }; BankDepositClient.UpdateOrInsertSalaryApprovalDetailCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { SelectedMainRow.DetailsList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } }; GetMaindata(); } }