public int DisableAccounts() { ClearDataGrid(Viewer.DataGridView_Disable); int count = 0; foreach (var resign in DisableList) { if (Executioner.DisableAccount(resign, out string erorr)) { resign.Status = RecordStatus.Disabled; Viewer.AddToDisableGrid(resign, erorr, ActionOkColor); if (!Adapter.UpdateRecord(resign, out var error)) { throw new DbException(error); } count++; } else { resign.Status = RecordStatus.Erorr; Viewer.AddToDisableGrid(resign, erorr, ActionFailColor); resign.AppendErrorMessage(erorr); if (!Adapter.UpdateRecord(resign, out var error)) { throw new DbException(error); } } } DisableList.Clear(); return(count); }
public int DisableAccounts() { var disableList = Logic.GetTodayDisables().ToList(); _logger.Log($"Disable - total: {disableList.Count()}"); int count = 1; foreach (var resign in disableList) { if (Executioner.DisableAccount(resign, out string erorr)) { resign.Status = RecordStatus.Disabled; DisablesResults.Add(MakeRow(resign.Id.ToString(), resign.ADName, resign.HRCode, resign.ReceiveDate.ToString(DateStringFormat), resign.ResignDay.ToString(DateStringFormat), erorr, Code.I.ToString())); if (!Adapter.UpdateRecord(resign, out var dbError)) { throw new DbException(dbError); } _logger.Log($"Disable - OK: {resign.ADName}"); } else { resign.Status = RecordStatus.Erorr; DisablesResults.Add(MakeRow(resign.Id.ToString(), resign.ADName, resign.HRCode, resign.ReceiveDate.ToString(DateStringFormat), resign.ResignDay.ToString(DateStringFormat), erorr, Code.E.ToString())); resign.AppendErrorMessage(erorr); if (!Adapter.UpdateRecord(resign, out var dbError)) { throw new DbException(dbError); //unlikely to happen } _logger.Log($"Disable - Fail: {resign.ADName} reason: {erorr}"); } count++; } DisablesResults.Sort((item1, item2) => (item1.Last().CompareTo(item2.Last()))); return(count); }