StaffGrade.razor.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using AntDesign;
  2. using AntDesign.TableModels;
  3. using Microsoft.AspNetCore.Components;
  4. using Microsoft.AspNetCore.Components.Web;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Net.Http.Json;
  9. using System.Threading.Tasks;
  10. using wispro.sp.share;
  11. using wispro.sp.web.Services;
  12. namespace wispro.sp.web.Pages
  13. {
  14. public partial class StaffGrade
  15. {
  16. [Inject] public StaffGradeService _sfService { get; set; }
  17. [Inject] MessageService _message { get; set; }
  18. private List<wispro.sp.entity.StaffGrade> staffGrades;
  19. IEnumerable<wispro.sp.entity.StaffGrade> selectedRows;
  20. [Inject] protected IAuthService _authService { get; set; }
  21. ITable table;
  22. int _pageIndex = 1;
  23. int _pageSize = 10;
  24. int _total = 0;
  25. bool _loading = false;
  26. wispro.sp.entity.StaffGrade EditingStaff = null;
  27. bool _visible = false;
  28. bool _isAdd = false;
  29. protected override async Task OnInitializedAsync()
  30. {
  31. _authService.CanVisitResource();
  32. _loading = true;
  33. List<wispro.sp.entity.StaffGrade> data = await _sfService.GetAll();// await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  34. _loading = false;
  35. staffGrades = data;
  36. _total = data.Count;
  37. }
  38. private void HandlePageChange(PaginationEventArgs args)
  39. {
  40. if (_pageIndex != args.Page)
  41. {
  42. _pageIndex = args.Page;
  43. }
  44. if (_pageSize != args.PageSize)
  45. {
  46. _pageSize = args.PageSize;
  47. }
  48. }
  49. Dictionary<string, object> OnRow(RowData<wispro.sp.entity.StaffGrade> row)
  50. {
  51. Dictionary<string, object> ret = new Dictionary<string, object>();
  52. ret.Add("id", row.Data.Id);
  53. ret.Add("onclick", ((Action)delegate
  54. {
  55. //_message.Info($"row {row.Data.Grade} was clicked");
  56. }));
  57. return ret;
  58. }
  59. public void RemoveSelection(int id)
  60. {
  61. //var selected = selectedRows.Where(x => x.Id != id);
  62. //selectedRows = selected;
  63. }
  64. private void Delete(int id)
  65. {
  66. var rList = staffGrades.Where(x => x.Id == id).ToList();
  67. if (rList.Count() > 0)
  68. {
  69. EditingStaff = rList[0];
  70. _isAdd = false;
  71. _visible = true;
  72. }
  73. else
  74. {
  75. }
  76. _total = staffGrades.Count;
  77. }
  78. private void Edit(int id)
  79. {
  80. var rList = staffGrades.Where(x => x.Id == id).ToList();
  81. if (rList.Count() > 0)
  82. {
  83. EditingStaff = rList[0];
  84. _isAdd = false;
  85. _visible = true;
  86. }
  87. else
  88. {
  89. }
  90. _total = staffGrades.Count;
  91. }
  92. private void AddNew()
  93. {
  94. EditingStaff = new entity.StaffGrade();
  95. _isAdd = true;
  96. _visible = true;
  97. }
  98. private async Task HandleOk(MouseEventArgs e)
  99. {
  100. ApiSaveResponse result = await _sfService.Save(EditingStaff);
  101. if (result.Success)
  102. {
  103. await _message.Success("数据已保存!");
  104. }
  105. else
  106. {
  107. await _message.Error($"{result.ErrorMessage}");
  108. }
  109. _visible = false;
  110. }
  111. private void HandleCancel(MouseEventArgs e)
  112. {
  113. _visible = false;
  114. }
  115. }
  116. }