public VariableTermManualViewModel() { if (!DesignerProperties.IsInDesignTool) { MainRowList = new SortableCollectionView <TblVariableTermManualViewModel>(); SelectedMainRow = new TblVariableTermManualViewModel(); Client.GetTblVariableTermManualCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblVariableTermManualViewModel(); newrow.EmpPerRow = new EmployeesView(); newrow.SalaryTerPerRow = new TblSalaryTerm(); newrow.EmpPerRow = EmpList.FirstOrDefault(w => w.Emplid == row.Emplid); newrow.SalaryTerPerRow = SalaryTermList.FirstOrDefault(w => w.Iserial == row.TermId); newrow.InjectFrom(row); MainRowList.Add(newrow); } Loading = false; if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } }; Client.UpdateOrInsertTblVariableTermManualCompleted += (s, x) => { var savedRow = (TblVariableTermManualViewModel)MainRowList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblVariableTermManualCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { MainRowList.Remove(oldrow); } }; GetEmpByStore(); Client.GetTblSalaryTermAsync(); Client.GetTblSalaryTermCompleted += (s, sv) => { SalaryTermList = sv.Result; }; Client.GetEmpTablebyStoreAndCompanyCompleted += (s, sv) => { EmpList = new ObservableCollection <EmployeesView>(); EmpList = sv.Result; Loading = false; Client.GetTblVariableTermManualAsync(new ObservableCollection <string>(EmpList.Select(x => x.Emplid))); }; } }
public VariableTermManualFactoryViewModel() { if (!DesignerProperties.IsInDesignTool) { PositionAllowed = true; TransportationLineAllow = Visibility.Visible; MainRowList = new SortableCollectionView <TblVariableTermManualFactoryViewModel>(); SelectedMainRow = new TblVariableTermManualFactoryViewModel(); GetPoisition(LoggedUserInfo.Code); GetEmpTransportationLine(LoggedUserInfo.Code); Client.GetEmpPositionCompleted += (s, sv) => { PositionList = sv.Result.ToList(); if (PositionList.Count() == 1) { SelectedMainRow.Position = PositionList.FirstOrDefault(); Position = PositionList.FirstOrDefault(); } }; Client.GetEmpTransportationLineCompleted += (s, sv) => { TransportationList = sv.Result.ToList(); if (TransportationList.Count() == 1) { SelectedMainRow.Transportation = TransportationList.FirstOrDefault(); Transportation = TransportationList.FirstOrDefault(); } }; Client.GetTblVariableTermManualCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblVariableTermManualFactoryViewModel { EmpPerRow = new EmployeesView(), SalaryTerPerRow = new TblSalaryTerm() }; newrow.EmpPerRow = EmpList.FirstOrDefault(w => w.Emplid == row.Emplid); newrow.SalaryTerPerRow = SalaryTermList.FirstOrDefault(w => w.Iserial == row.TermId); newrow.InjectFrom(row); MainRowList.Add(newrow); } Loading = false; if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } }; StoreVisibility = LoggedUserInfo.Company.Code == "HQ" ? Visibility.Collapsed : Visibility.Visible; PositionVisibility = LoggedUserInfo.Company.Code != "HQ" ? Visibility.Collapsed : Visibility.Visible; Client.UpdateOrInsertTblVariableTermManualCompleted += (s, x) => { var savedRow = (TblVariableTermManualFactoryViewModel)MainRowList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblVariableTermManualCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { MainRowList.Remove(oldrow); } }; Client.GetEmpByAttOperatorCompleted += (s, sv) => { MainRowList.Clear(); foreach (var emp in sv.Result) { MainRowList.Add(new TblVariableTermManualFactoryViewModel { EmpPerRow = emp, Emplid = emp.Emplid, Position = emp.Position, Transportation = emp.TransportationLine, TransDate = DayDate, SalaryTerPerRow = SalaryTerPerRow, Hours = Hours, Days = Days }); } Loading = false; }; Client.GetTblSalaryTermAsync(); Client.GetTblSalaryTermCompleted += (s, sv) => { SalaryTermList = sv.Result; }; Client.GetEmpTablebyStoreAndCompanyCompleted += (s, sv) => { EmpList = new ObservableCollection <EmployeesView>(); EmpList = sv.Result; Loading = false; Client.GetTblVariableTermManualAsync(new ObservableCollection <string>(EmpList.Select(x => x.Emplid))); }; } }