PrintControlServices.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.TerminatePrinter;
  9. using EMIS.ViewModel.TerminatePrinter;
  10. using EMIS.ViewModel;
  11. using EMIS.Entities;
  12. namespace EMIS.CommonLogic.TerminatePrinter
  13. {
  14. public class PrintControlServices : BaseServices, IPrintControlServices
  15. {
  16. public PrintControlDAL PrintControlDAL { get; set; }
  17. public IGridResultSet<PrintControlView> GetPrintControlViewGrid(ConfiguretView conditionView, int? yearID, int? pageIndex, int? pageSize)
  18. {
  19. Expression<Func<Tem_PrintControl, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  20. if (yearID.HasValue)
  21. {
  22. exp = exp.And(x => x.YearID == yearID);
  23. }
  24. var query = PrintControlDAL.GetPrintControlViewQueryable(exp);
  25. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  26. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  27. query = query.OrderByDescending(x => x.YearID);
  28. return query.ToGridResultSet(pageIndex, pageSize);
  29. }
  30. public PrintControlView GetPrintControlView(Guid? printControlID)
  31. {
  32. return PrintControlDAL.GetPrintControlViewQueryable(x => x.PrintControlID == printControlID).FirstOrDefault();
  33. }
  34. public void Save(PrintControlView printControlView)
  35. {
  36. try
  37. {
  38. Tem_PrintControl dupPrintControl = PrintControlDAL.PrintControlRepository.Entities.Where(x =>
  39. x.YearID == printControlView.YearID &&
  40. x.PrintControlID != printControlView.PrintControlID).FirstOrDefault();
  41. if (dupPrintControl != null)
  42. {
  43. throw new Exception("已经存在" + printControlView.YearID.ToString() + "年级的设置,不能保存。");
  44. }
  45. Tem_PrintControl printControl = null;
  46. if (printControlView.PrintControlID == null || printControlView.PrintControlID == Guid.Empty)
  47. {
  48. printControl = new Tem_PrintControl();
  49. printControl.PrintControlID = Guid.NewGuid();
  50. SetNewStatus(printControl);
  51. UnitOfWork.Add(printControl);
  52. }
  53. else
  54. {
  55. printControl = this.PrintControlDAL.PrintControlRepository.GetSingle(x => x.PrintControlID == printControlView.PrintControlID);
  56. if (printControl == null)
  57. {
  58. throw new Exception("未找到相对应的等级成绩。");
  59. }
  60. SetModifyStatus(printControl);
  61. }
  62. printControl.YearID = printControlView.YearID;
  63. printControl.Times = printControlView.Times;
  64. UnitOfWork.Commit();
  65. }
  66. catch (Exception)
  67. {
  68. throw;
  69. }
  70. }
  71. public void Delete(IList<Guid?> printControlIDList)
  72. {
  73. if (printControlIDList.Count > 0)
  74. {
  75. UnitOfWork.Delete<Tem_PrintControl>(x => printControlIDList.Contains(x.PrintControlID));
  76. }
  77. }
  78. }
  79. }