DefaultViewAndSpCreate.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using WePlatform.EF;
  2. namespace WePlatform.SeedData
  3. {
  4. public class DefaultViewAndSpCreate
  5. {
  6. private readonly WePlatformDbContext _context;
  7. public DefaultViewAndSpCreate(WePlatformDbContext context)
  8. {
  9. _context = context;
  10. }
  11. public void Create()
  12. {
  13. View();
  14. SqlProcedure();
  15. }
  16. private void View()
  17. {
  18. }
  19. private void SqlProcedure()
  20. {
  21. CreateView_();
  22. CreateSp_AppGuid();
  23. }
  24. #region View
  25. private void CreateView_()
  26. {
  27. //_context.Sql(@"DROP VIEW IF EXISTS [dbo].[]");
  28. //_context.Sql(@"
  29. // ");
  30. }
  31. #endregion
  32. #region Procedure
  33. private void CreateSp_AppGuid()
  34. {
  35. _context.Sql("DROP PROCEDURE IF EXISTS [dbo].[Sp_AppGuid]");
  36. _context.Sql(
  37. @"
  38. CREATE PROCEDURE [dbo].[Sp_AppGuid]
  39. @idType smallint,
  40. @nextId int output,
  41. @maxId int output
  42. AS
  43. SET noCount on
  44. SET rowCount 0
  45. SELECT @nextId=0
  46. SELECT @maxId=0
  47. DECLARE cursorId CURSOR FOR
  48. SELECT Step, LastID FROM Sys_AppGuids WHERE IDType=@idType
  49. FOR UPDATE
  50. OPEN cursorId
  51. IF @@error != 0
  52. BEGIN
  53. CLOSE cursorId
  54. DEALLOCATE cursorId
  55. RETURN -1
  56. END
  57. DECLARE @step smallint
  58. DECLARE @lastId int
  59. FETCH cursorId INTO @step, @lastId
  60. IF @@fetch_status = 0
  61. BEGIN
  62. SELECT @nextId=@lastId
  63. SELECT @maxId=@nextId + @step
  64. UPDATE Sys_AppGuids SET LastID=@maxId WHERE CURRENT OF cursorId
  65. IF @@error != 0 OR @@rowCount != 1
  66. BEGIN
  67. CLOSE cursorId
  68. DEALLOCATE cursorId
  69. RETURN -3
  70. END
  71. END
  72. ELSE RETURN -2
  73. CLOSE cursorId
  74. DEALLOCATE cursorId
  75. RETURN 0
  76. ");
  77. }
  78. #endregion
  79. }
  80. }