ScoreEditGrid.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Web.Controls.Mvc;
  7. using EMIS.Entities;
  8. using EMIS.Utility;
  9. using EMIS.ViewModel;
  10. namespace EMIS.Web.Controls.Score
  11. {
  12. public static class ScoreEditGridExtensions
  13. {
  14. public static MvcHtmlString ScoreEditGrid(this HtmlHelper htmlHelper,
  15. string id, bool isEditable, bool hasCheckbox, Guid finalExaminationID, IDictionary<string, string> htmlAttributes = null)
  16. {
  17. string formulaColumns = string.Empty;
  18. var gridOptions = new DataGridOptions
  19. {
  20. Columns = new List<DataGridColumn>()
  21. {
  22. new BoundFieldColumn { FieldName="UserID", HeaderText="学生ID", Align=AlignStyle.Center, IsHidden = true },
  23. new BoundFieldColumn { FieldName="No", HeaderText="序号", Align=AlignStyle.Center, Width=0.03 ,CustomFormatFun = "LoginIDColor" },
  24. new BoundFieldColumn { FieldName="LoginID", HeaderText="学号", Align=AlignStyle.Center, Width=0.1 ,CustomFormatFun = "LoginIDColor" },
  25. new BoundFieldColumn { FieldName="UserName", HeaderText="姓名", Align=AlignStyle.Center, Width=0.04 ,CustomFormatFun = "UserNameColor" },
  26. new BoundFieldColumn { FieldName="ExamsCategoryName", HeaderText="考试性质", Align=AlignStyle.Center, Width=0.05 ,CustomFormatFun = "ExamsCategoryNameColor" },
  27. },
  28. DataSourceUrl = UrlHelper.GenerateContentUrl("~/Score/GetStudentScoreInputView?finalExaminationID=" + finalExaminationID, htmlHelper.ViewContext.HttpContext),
  29. ID = id,
  30. IsPagination = false,
  31. IsPostBack = true
  32. };
  33. if (hasCheckbox)
  34. {
  35. gridOptions.Columns.Insert(0, new CheckBoxFieldColumn { HeaderText = "", FieldName = "UserID" });
  36. }
  37. var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
  38. foreach (var item in scoreDynamicTypes)
  39. {
  40. if (isEditable)
  41. {
  42. gridOptions.Columns.Add(new TextBoxColumn
  43. {
  44. FieldName = "ScoreDetail[" + item.Value.ToString() + "].Score",
  45. HeaderText = item.Name,
  46. Align = AlignStyle.Center,
  47. Width = 0.04,
  48. EnableFieldName = "ScoreDetail[" + item.Value.ToString() + "].IsCanEdit",
  49. Validator = new OnlyMoneyValidator() { Required = false }
  50. });
  51. }
  52. else
  53. {
  54. gridOptions.Columns.Add(new BoundFieldColumn
  55. {
  56. FieldName = "ScoreDetail[" + item.Value.ToString() + "].Score",
  57. HeaderText = item.Name,
  58. Align = AlignStyle.Center,
  59. Width = 0.04
  60. });
  61. }
  62. }
  63. gridOptions.Columns.Add(new BoundFieldColumn { FieldName = "TotalScore", HeaderText = "总成绩", Align = AlignStyle.Center, Width = 0.04, CustomFormatFun = "TotalScoreColor" });
  64. gridOptions.Columns.Add(new BoundFieldColumn { FieldName = "Credit", HeaderText = "学分", Align = AlignStyle.Center, Width = 0.03, CustomFormatFun = "CreditColor", Formatter = Formatter.OnlyYearMonthDay });
  65. gridOptions.Columns.Add(new BoundFieldColumn { FieldName = "GradePoint", HeaderText = "绩点", Align = AlignStyle.Center, Width = 0.03, CustomFormatFun = "GradePointColor" });
  66. if (isEditable)
  67. {
  68. gridOptions.Columns.Add(new DictionaryDropdownListColumn
  69. {
  70. EnableFieldName = isEditable ? "IsCanEdit" : "NotEnable",
  71. FieldName = "ExamsStateID",
  72. HeaderText = "考试状态",
  73. Align = AlignStyle.Center,
  74. DictionaryType = EMIS.ViewModel.DictionaryItem.CF_ExamsState,
  75. Width = 0.07
  76. });
  77. gridOptions.Columns.Add(new TextBoxColumn { FieldName = "Remarks", HeaderText = "备注", Align = AlignStyle.Center, Width = 0.1 });
  78. }
  79. else
  80. {
  81. gridOptions.Columns.Add(new BoundFieldColumn
  82. {
  83. FieldName = "ExamsStateName",
  84. HeaderText = "考试状态",
  85. Align = AlignStyle.Center,
  86. Width = 0.07
  87. });
  88. gridOptions.Columns.Add(new BoundFieldColumn { FieldName = "Remarks", HeaderText = "备注", Align = AlignStyle.Center, Width = 0.1 });
  89. }
  90. return htmlHelper.DataGrid(gridOptions, htmlAttributes);
  91. }
  92. }
  93. }