StaffGrade.razor.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. private List<wispro.sp.entity.StaffGrade> staffGrades;
  18. IEnumerable<wispro.sp.entity.StaffGrade> selectedRows;
  19. ITable table;
  20. int _pageIndex = 1;
  21. int _pageSize = 10;
  22. int _total = 0;
  23. bool _loading = false;
  24. wispro.sp.entity.StaffGrade EditingStaff = null;
  25. bool _visible = false;
  26. bool _isAdd = false;
  27. protected override async Task OnInitializedAsync()
  28. {
  29. _loading = true;
  30. List<wispro.sp.entity.StaffGrade> data = await _sfService.GetAll();// await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  31. _loading = false;
  32. staffGrades = data;
  33. _total = data.Count;
  34. }
  35. private void HandlePageChange(PaginationEventArgs args)
  36. {
  37. if (_pageIndex != args.Page)
  38. {
  39. _pageIndex = args.Page;
  40. }
  41. if (_pageSize != args.PageSize)
  42. {
  43. _pageSize = args.PageSize;
  44. }
  45. }
  46. Dictionary<string, object> OnRow(RowData<wispro.sp.entity.StaffGrade> row)
  47. {
  48. Dictionary<string, object> ret = new Dictionary<string, object>();
  49. ret.Add("id", row.Data.Id);
  50. ret.Add("onclick", ((Action)delegate
  51. {
  52. //_message.Info($"row {row.Data.Grade} was clicked");
  53. }));
  54. return ret;
  55. }
  56. public void RemoveSelection(int id)
  57. {
  58. //var selected = selectedRows.Where(x => x.Id != id);
  59. //selectedRows = selected;
  60. }
  61. private void Delete(int id)
  62. {
  63. var rList = staffGrades.Where(x => x.Id == id).ToList();
  64. if (rList.Count() > 0)
  65. {
  66. EditingStaff = rList[0];
  67. _isAdd = false;
  68. _visible = true;
  69. }
  70. else
  71. {
  72. }
  73. _total = staffGrades.Count;
  74. }
  75. private void Edit(int id)
  76. {
  77. var rList = staffGrades.Where(x => x.Id == id).ToList();
  78. if (rList.Count() > 0)
  79. {
  80. EditingStaff = rList[0];
  81. _isAdd = false;
  82. _visible = true;
  83. }
  84. else
  85. {
  86. }
  87. _total = staffGrades.Count;
  88. }
  89. private void AddNew()
  90. {
  91. EditingStaff = new entity.StaffGrade();
  92. _isAdd = true;
  93. _visible = true;
  94. }
  95. private async Task HandleOk(MouseEventArgs e)
  96. {
  97. ApiSaveResponse result = await _sfService.Save(EditingStaff);
  98. if (result.Success)
  99. {
  100. await _message.Success("数据已保存!");
  101. }
  102. else
  103. {
  104. await _message.Error($"{result.ErrorMessage}");
  105. }
  106. _visible = false;
  107. }
  108. private void HandleCancel(MouseEventArgs e)
  109. {
  110. //Console.WriteLine(e);
  111. _visible = false;
  112. }
  113. }
  114. }