upgradeprocedure_2000.sql
上传用户:wenllgg125
上传日期:2020-04-09
资源大小:7277k
文件大小:179k
源码类别:

SCSI/ASPI

开发平台:

Others

  1. IF @pageindex = 1
  2. EXEC('SELECT TOP ' + @pagesize + '
  3. [dnt_posts1].[pid], 
  4. [dnt_posts1].[fid], 
  5. [dnt_posts1].[title], 
  6. [dnt_posts1].[layer],
  7. [dnt_posts1].[message], 
  8. [dnt_posts1].[ip], 
  9. [dnt_posts1].[lastedit], 
  10. [dnt_posts1].[postdatetime], 
  11. [dnt_posts1].[attachment], 
  12. [dnt_posts1].[poster], 
  13. [dnt_posts1].[posterid], 
  14. [dnt_posts1].[invisible], 
  15. [dnt_posts1].[usesig], 
  16. [dnt_posts1].[htmlon], 
  17. [dnt_posts1].[smileyoff], 
  18. [dnt_posts1].[parseurloff], 
  19. [dnt_posts1].[bbcodeoff], 
  20. [dnt_posts1].[rate], 
  21. [dnt_posts1].[ratetimes], 
  22. [dnt_users].[nickname],  
  23. [dnt_users].[username], 
  24. [dnt_users].[groupid], 
  25. [dnt_users].[spaceid],
  26. [dnt_users].[gender],
  27. [dnt_users].[bday],
  28. [dnt_users].[email], 
  29. [dnt_users].[showemail], 
  30. [dnt_users].[digestposts], 
  31. [dnt_users].[credits], 
  32. [dnt_users].[extcredits1], 
  33. [dnt_users].[extcredits2], 
  34. [dnt_users].[extcredits3], 
  35. [dnt_users].[extcredits4], 
  36. [dnt_users].[extcredits5], 
  37. [dnt_users].[extcredits6], 
  38. [dnt_users].[extcredits7], 
  39. [dnt_users].[extcredits8], 
  40. [dnt_users].[posts], 
  41. [dnt_users].[joindate], 
  42. [dnt_users].[onlinestate],
  43. [dnt_users].[lastactivity], 
  44. [dnt_users].[invisible],
  45. [dnt_users].[oltime],
  46. [dnt_users].[lastvisit], 
  47. [dnt_userfields].[avatar], 
  48. [dnt_userfields].[avatarwidth], 
  49. [dnt_userfields].[avatarheight],
  50. [dnt_userfields].[medals],
  51. [dnt_userfields].[sightml] AS signature, 
  52. [dnt_userfields].[location], 
  53. [dnt_userfields].[customstatus], 
  54. [dnt_userfields].[website], 
  55. [dnt_userfields].[icq], 
  56. [dnt_userfields].[qq], 
  57. [dnt_userfields].[msn], 
  58. [dnt_userfields].[yahoo], 
  59. [dnt_userfields].[skype] 
  60.  FROM [dnt_posts1] LEFT JOIN [dnt_users] ON [dnt_users].[uid]=[dnt_posts1].[posterid] LEFT JOIN [dnt_userfields] ON [dnt_userfields].[uid]=[dnt_users].[uid] WHERE [dnt_posts1].[tid]=' + @tid + ' AND [dnt_posts1].[invisible]<=0 ORDER BY [dnt_posts1].[pid]')
  61. ELSE
  62. EXEC('SELECT TOP ' + @pagesize + ' 
  63. [dnt_posts1].[pid], 
  64. [dnt_posts1].[fid], 
  65. [dnt_posts1].[title], 
  66. [dnt_posts1].[layer],
  67. [dnt_posts1].[message], 
  68. [dnt_posts1].[ip], 
  69. [dnt_posts1].[lastedit], 
  70. [dnt_posts1].[postdatetime], 
  71. [dnt_posts1].[attachment], 
  72. [dnt_posts1].[poster], 
  73. [dnt_posts1].[posterid], 
  74. [dnt_posts1].[invisible], 
  75. [dnt_posts1].[usesig], 
  76. [dnt_posts1].[htmlon], 
  77. [dnt_posts1].[smileyoff], 
  78. [dnt_posts1].[parseurloff], 
  79. [dnt_posts1].[bbcodeoff], 
  80. [dnt_posts1].[rate], 
  81. [dnt_posts1].[ratetimes],
  82. [dnt_users].[nickname],  
  83. [dnt_users].[username], 
  84. [dnt_users].[groupid], 
  85. [dnt_users].[spaceid],
  86. [dnt_users].[gender],
  87. [dnt_users].[bday],
  88. [dnt_users].[email], 
  89. [dnt_users].[showemail], 
  90. [dnt_users].[digestposts], 
  91. [dnt_users].[credits], 
  92. [dnt_users].[extcredits1], 
  93. [dnt_users].[extcredits2], 
  94. [dnt_users].[extcredits3], 
  95. [dnt_users].[extcredits4], 
  96. [dnt_users].[extcredits5], 
  97. [dnt_users].[extcredits6], 
  98. [dnt_users].[extcredits7], 
  99. [dnt_users].[extcredits8], 
  100. [dnt_users].[posts], 
  101. [dnt_users].[joindate], 
  102. [dnt_users].[onlinestate],
  103. [dnt_users].[lastactivity],
  104. [dnt_users].[oltime],
  105. [dnt_users].[lastvisit],  
  106. [dnt_users].[invisible] AS [userinvisible], 
  107. [dnt_userfields].[avatar], 
  108. [dnt_userfields].[avatarwidth], 
  109. [dnt_userfields].[avatarheight], 
  110. [dnt_userfields].[medals],
  111. [dnt_userfields].[sightml] AS [signature], 
  112. [dnt_userfields].[location], 
  113. [dnt_userfields].[customstatus], 
  114. [dnt_userfields].[website], 
  115. [dnt_userfields].[icq], 
  116. [dnt_userfields].[qq], 
  117. [dnt_userfields].[msn], 
  118. [dnt_userfields].[yahoo], 
  119. [dnt_userfields].[skype] 
  120. FROM [dnt_posts1] LEFT JOIN [dnt_users] ON [dnt_users].[uid]=[dnt_posts1].[posterid] LEFT JOIN [dnt_userfields] ON [dnt_userfields].[uid]=[dnt_users].[uid] WHERE [dnt_posts1].[tid]=' + @tid + ' AND [pid] > (SELECT MAX([pid]) FROM (SELECT TOP ' + @pagetop + ' [dnt_posts1].[pid] FROM [dnt_posts1] WHERE [dnt_posts1].[tid]=' + @tid + ' AND [dnt_posts1].[invisible]<=0 ORDER BY [dnt_posts1].[pid]) AS tblTmp) AND [dnt_posts1].[invisible]<=0 ORDER BY [dnt_posts1].[pid]')
  121. GO
  122. IF OBJECT_ID('[dnt_getpostlistbycondition1]','P') IS NOT NULL
  123. DROP PROC [dnt_getpostlistbycondition1]
  124. GO
  125. CREATE PROCEDURE [dnt_getpostlistbycondition1]
  126. @tid int,
  127. @pagesize int,
  128. @pageindex int,
  129. @posterid int
  130. AS
  131. DECLARE @pagetop int
  132. SET @pagetop = (@pageindex-1)*@pagesize
  133. IF @pageindex = 1
  134. EXEC('SELECT TOP ' + @pagesize + '
  135. [dnt_posts1].[pid], 
  136. [dnt_posts1].[fid], 
  137. [dnt_posts1].[title], 
  138. [dnt_posts1].[layer],
  139. [dnt_posts1].[message], 
  140. [dnt_posts1].[ip], 
  141. [dnt_posts1].[lastedit], 
  142. [dnt_posts1].[postdatetime], 
  143. [dnt_posts1].[attachment], 
  144. [dnt_posts1].[poster], 
  145. [dnt_posts1].[posterid], 
  146. [dnt_posts1].[invisible], 
  147. [dnt_posts1].[usesig], 
  148. [dnt_posts1].[htmlon], 
  149. [dnt_posts1].[smileyoff], 
  150. [dnt_posts1].[parseurloff], 
  151. [dnt_posts1].[bbcodeoff], 
  152. [dnt_posts1].[rate], 
  153. [dnt_posts1].[ratetimes], 
  154. [dnt_users].[nickname],  
  155. [dnt_users].[username], 
  156. [dnt_users].[groupid], 
  157. [dnt_users].[spaceid],
  158. [dnt_users].[gender],
  159. [dnt_users].[bday],
  160. [dnt_users].[email], 
  161. [dnt_users].[showemail], 
  162. [dnt_users].[digestposts], 
  163. [dnt_users].[credits], 
  164. [dnt_users].[extcredits1], 
  165. [dnt_users].[extcredits2], 
  166. [dnt_users].[extcredits3], 
  167. [dnt_users].[extcredits4], 
  168. [dnt_users].[extcredits5], 
  169. [dnt_users].[extcredits6], 
  170. [dnt_users].[extcredits7], 
  171. [dnt_users].[extcredits8], 
  172. [dnt_users].[posts], 
  173. [dnt_users].[joindate], 
  174. [dnt_users].[onlinestate],
  175. [dnt_users].[lastactivity],
  176. [dnt_users].[oltime],
  177. [dnt_users].[lastvisit],  
  178. [dnt_users].[invisible], 
  179. [dnt_userfields].[avatar], 
  180. [dnt_userfields].[avatarwidth],
  181. [dnt_userfields].[avatarheight],
  182. [dnt_userfields].[medals],
  183. [dnt_userfields].[sightml] AS signature, 
  184. [dnt_userfields].[location], 
  185. [dnt_userfields].[customstatus], 
  186. [dnt_userfields].[website], 
  187. [dnt_userfields].[icq], 
  188. [dnt_userfields].[qq], 
  189. [dnt_userfields].[msn], 
  190. [dnt_userfields].[yahoo], 
  191. [dnt_userfields].[skype] 
  192.  FROM [dnt_posts1] LEFT JOIN [dnt_users] ON [dnt_users].[uid]=[dnt_posts1].[posterid] LEFT JOIN [dnt_userfields] ON [dnt_userfields].[uid]=[dnt_users].[uid] WHERE [dnt_posts1].[tid]=' + @tid + ' AND [dnt_posts1].[invisible]=0 AND [posterid] = '+@posterid+' ORDER BY [dnt_posts1].[pid]')
  193. ELSE
  194. EXEC('SELECT TOP ' + @pagesize + ' 
  195. [dnt_posts1].[pid], 
  196. [dnt_posts1].[fid], 
  197. [dnt_posts1].[title], 
  198. [dnt_posts1].[layer],
  199. [dnt_posts1].[message], 
  200. [dnt_posts1].[ip], 
  201. [dnt_posts1].[lastedit], 
  202. [dnt_posts1].[postdatetime], 
  203. [dnt_posts1].[attachment], 
  204. [dnt_posts1].[poster], 
  205. [dnt_posts1].[posterid], 
  206. [dnt_posts1].[invisible], 
  207. [dnt_posts1].[usesig], 
  208. [dnt_posts1].[htmlon], 
  209. [dnt_posts1].[smileyoff], 
  210. [dnt_posts1].[parseurloff], 
  211. [dnt_posts1].[bbcodeoff], 
  212. [dnt_posts1].[rate], 
  213. [dnt_posts1].[ratetimes],
  214. [dnt_users].[nickname],  
  215. [dnt_users].[username], 
  216. [dnt_users].[groupid], 
  217. [dnt_users].[spaceid],
  218. [dnt_users].[gender],
  219. [dnt_users].[bday],
  220. [dnt_users].[email], 
  221. [dnt_users].[showemail], 
  222. [dnt_users].[digestposts], 
  223. [dnt_users].[credits], 
  224. [dnt_users].[extcredits1], 
  225. [dnt_users].[extcredits2], 
  226. [dnt_users].[extcredits3], 
  227. [dnt_users].[extcredits4], 
  228. [dnt_users].[extcredits5], 
  229. [dnt_users].[extcredits6], 
  230. [dnt_users].[extcredits7], 
  231. [dnt_users].[extcredits8], 
  232. [dnt_users].[posts], 
  233. [dnt_users].[joindate], 
  234. [dnt_users].[onlinestate], 
  235. [dnt_users].[lastactivity], 
  236. [dnt_users].[invisible],
  237. [dnt_users].[oltime],
  238. [dnt_users].[lastvisit], 
  239. [dnt_userfields].[avatar], 
  240. [dnt_userfields].[avatarwidth], 
  241. [dnt_userfields].[avatarheight], 
  242. [dnt_userfields].[medals],
  243. [dnt_userfields].[sightml] AS signature, 
  244. [dnt_userfields].[location], 
  245. [dnt_userfields].[customstatus], 
  246. [dnt_userfields].[website], 
  247. [dnt_userfields].[icq], 
  248. [dnt_userfields].[qq], 
  249. [dnt_userfields].[msn], 
  250. [dnt_userfields].[yahoo], 
  251. [dnt_userfields].[skype] 
  252. FROM [dnt_posts1] LEFT JOIN [dnt_users] ON [dnt_users].[uid]=[dnt_posts1].[posterid] LEFT JOIN [dnt_userfields] ON [dnt_userfields].[uid]=[dnt_users].[uid] WHERE [dnt_posts1].[tid]=' + @tid + ' AND [dnt_posts1].[invisible]=0 AND [posterid] = '+@posterid+'  AND [pid] > (SELECT MAX([pid]) FROM (SELECT TOP ' + @pagetop + ' [dnt_posts1].[pid] FROM [dnt_posts1] LEFT JOIN [dnt_users] ON [dnt_users].[uid]=[dnt_posts1].[posterid] LEFT JOIN [dnt_userfields] ON [dnt_userfields].[uid]=[dnt_users].[uid] WHERE [dnt_posts1].[tid]=@tid  AND [posterid] = '+@posterid+'  ORDER BY [dnt_posts1].[pid]) AS tblTmp) ORDER BY [dnt_posts1].[pid]')
  253. GO
  254. IF OBJECT_ID('dnt_getattachpaymentlogbyaid','P') IS NOT NULL
  255. DROP PROC [dnt_getattachpaymentlogbyaid]
  256. GO
  257. CREATE PROCEDURE [dnt_getattachpaymentlogbyaid]
  258. @aid int
  259. AS
  260. SELECT 
  261. [id],
  262. [uid],
  263. [username],
  264. [aid],
  265. [authorid],
  266. [postdatetime],
  267. [amount],
  268. [netamount]
  269. FROM [dnt_attachpaymentlog]
  270. WHERE [aid] = @aid
  271. GO
  272. IF OBJECT_ID('dnt_getonlineuercount','P') IS NOT NULL
  273. DROP PROC [dnt_getonlineuercount]
  274. GO
  275. CREATE PROCEDURE [dnt_getonlineuercount]
  276. AS
  277. SELECT COUNT(olid) FROM [dnt_online]
  278. GO
  279. IF OBJECT_ID('dnt_getalltoptopiclist','P') IS NOT NULL
  280. DROP PROC [dnt_getalltoptopiclist]
  281. GO
  282. CREATE PROCEDURE [dnt_getalltoptopiclist]
  283. AS
  284. SELECT 
  285. [tid],
  286. [displayorder],
  287. [fid] 
  288. FROM [dnt_topics] 
  289. WHERE [displayorder] > 0 ORDER BY [fid]
  290. GO
  291. IF OBJECT_ID('dnt_getnousedforumattachment','P') IS NOT NULL
  292. DROP PROC [dnt_getnousedforumattachment]
  293. GO
  294. CREATE PROCEDURE [dnt_getnousedforumattachment]
  295. AS
  296. SELECT 
  297. [aid],
  298. [uid],
  299. [tid],
  300. [pid],
  301. [postdatetime],
  302. [readperm],
  303. [filename],
  304. [description],
  305. [filetype],
  306. [filesize],
  307. [attachment],
  308. [downloads],
  309. [attachprice],
  310. [width],
  311. [height]
  312. FROM [dnt_attachments] 
  313. WHERE [tid]= 0 AND [pid]=0 AND DATEDIFF(n, postdatetime, GETDATE()) > 30 
  314. GO
  315. IF OBJECT_ID('dnt_deletenousedforumattachment','P') IS NOT NULL
  316. DROP PROC [dnt_deletenousedforumattachment]
  317. GO
  318. CREATE PROCEDURE [dnt_deletenousedforumattachment]
  319. AS
  320. DELETE FROM [dnt_attachments] 
  321. WHERE [tid]= 0 AND [pid]=0 AND DATEDIFF(n, postdatetime, GETDATE()) > 30
  322. GO
  323. IF OBJECT_ID('dnt_getnousedattachmentlistbytid','P') IS NOT NULL
  324. DROP PROC [dnt_getnousedattachmentlistbytid]
  325. GO
  326. CREATE PROCEDURE [dnt_getnousedattachmentlistbytid]
  327. @uid INT
  328. AS
  329. SELECT 
  330. [aid], 
  331. [attachment] 
  332. FROM [dnt_attachments] 
  333. WHERE [uid]= @uid AND [tid]=0 AND [pid]=0
  334. GO
  335. IF OBJECT_ID('dnt_updateattachmenttidtoanothertopic','P') IS NOT NULL
  336. DROP PROC [dnt_updateattachmenttidtoanothertopic]
  337. GO
  338. CREATE PROCEDURE [dnt_updateattachmenttidtoanothertopic]
  339. @tid INT,
  340. @oldtid INT
  341. AS
  342. UPDATE [dnt_attachments] SET [tid]=@tid WHERE [tid]=@oldtid
  343. GO
  344. IF OBJECT_ID('dnt_getfirstimageattachbytid','P') IS NOT NULL
  345. DROP PROC [dnt_getfirstimageattachbytid]
  346. GO
  347. CREATE PROCEDURE [dnt_getfirstimageattachbytid]
  348. @tid INT
  349. AS
  350. SELECT TOP 1 
  351. [aid],
  352. [uid],
  353. [tid],
  354. [pid],
  355. [postdatetime],
  356. [readperm],
  357. [filename],
  358. [description],
  359. [filetype],
  360. [filesize],
  361. [attachment],
  362. [downloads],
  363. [attachprice],
  364. [width],
  365. [height] 
  366. FROM [dnt_attachments] 
  367. WHERE [tid]=@tid AND LEFT([filetype], 5)='image' ORDER BY [aid]
  368. GO
  369. IF OBJECT_ID('dnt_getattachmentlistbypid','P') IS NOT NULL
  370. DROP PROC [dnt_getattachmentlistbypid]
  371. GO
  372. CREATE PROCEDURE [dnt_getattachmentlistbypid]
  373. @pidlist varchar(500)
  374. AS
  375. SELECT 
  376. [aid],
  377. [uid],
  378. [tid],
  379. [pid],
  380. [postdatetime],
  381. [readperm],
  382. [filename],
  383. [description],
  384. [filetype],
  385. [filesize],
  386. [attachment],
  387. [downloads],
  388. [attachprice],
  389. [width],
  390. [height] 
  391. FROM [dnt_attachments] 
  392. WHERE CHARINDEX(','+RTRIM([dnt_attachments].[pid])+',', ','+@pidlist+',')>0
  393. GO
  394. IF OBJECT_ID('dnt_getattachmentlistbyaid','P') IS NOT NULL
  395. DROP PROC [dnt_getattachmentlistbyaid]
  396. GO
  397. CREATE PROCEDURE [dnt_getattachmentlistbyaid]
  398. @aidlist varchar(500)
  399. AS
  400. SELECT 
  401. [aid],
  402. [tid],
  403. [pid],
  404. [filename]
  405. FROM [dnt_attachments] 
  406. WHERE CHARINDEX(','+RTRIM([dnt_attachments].[aid])+',', ','+@aidlist+',')>0
  407. GO
  408. IF OBJECT_ID('dnt_updateattachment','P') IS NOT NULL
  409. DROP PROC [dnt_updateattachment]
  410. GO
  411. CREATE PROCEDURE [dnt_updateattachment]
  412. @readperm INT,
  413. @description NCHAR(100),
  414. @attachprice INT,
  415. @aid INT
  416. AS
  417. UPDATE [dnt_attachments] 
  418. SET [readperm] = @readperm, [description] = @description, [attachprice] = @attachprice 
  419. WHERE [aid] = @aid
  420. GO
  421. IF OBJECT_ID('dnt_updateattachmentinfo','P') IS NOT NULL
  422. DROP PROC [dnt_updateattachmentinfo]
  423. GO
  424. CREATE PROCEDURE [dnt_updateattachmentinfo]
  425. @readperm INT,
  426. @description NCHAR(100),
  427. @aid INT
  428. AS
  429. UPDATE [dnt_attachments] 
  430. SET [readperm] = @readperm, [description] = @description 
  431. WHERE [aid] = @aid
  432. GO
  433. IF OBJECT_ID('dnt_updateallfieldattachmentinfo','P') IS NOT NULL
  434. DROP PROC [dnt_updateallfieldattachmentinfo]
  435. GO
  436. CREATE PROCEDURE [dnt_updateallfieldattachmentinfo]
  437. @postdatetime DATETIME,
  438. @readperm INT,
  439. @filename NCHAR(100),
  440. @filetype NCHAR(50),
  441. @description NCHAR(100),
  442. @filesize INT,
  443. @attachment NCHAR(100),
  444. @downloads INT,
  445. @tid INT,
  446. @pid INT,
  447. @aid INT,
  448. @attachprice INT,
  449. @width INT,
  450. @height INT
  451. AS
  452. UPDATE [dnt_attachments] 
  453. SET 
  454. [postdatetime] = @postdatetime, 
  455. [readperm] = @readperm, 
  456. [filename] = @filename, 
  457. [description] = @description, 
  458. [filetype] = @filetype, 
  459. [filesize] = @filesize, 
  460. [attachment] = @attachment, 
  461. [downloads] = @downloads, 
  462. [tid]=@tid, 
  463. [pid]=@pid, 
  464. [attachprice]=@attachprice, 
  465. [width]=@width, 
  466. [height]=@height 
  467. WHERE [aid]=@aid
  468. GO
  469. IF OBJECT_ID('dnt_deleteattachmentbypid','P') IS NOT NULL
  470. DROP PROC [dnt_deleteattachmentbypid]
  471. GO
  472. CREATE PROCEDURE [dnt_deleteattachmentbypid]
  473. @pid INT
  474. AS
  475. DELETE FROM [dnt_attachments] 
  476. WHERE [pid]=@pid
  477. GO
  478. IF OBJECT_ID('dnt_deleteattachmentbyaidlist','P') IS NOT NULL
  479. DROP PROC [dnt_deleteattachmentbyaidlist]
  480. GO
  481. CREATE PROCEDURE [dnt_deleteattachmentbyaidlist]
  482. @aidlist VARCHAR(500)
  483. AS
  484. DELETE FROM [dnt_attachments] WHERE CHARINDEX(','+RTRIM([aid])+',',','+@aidlist+',') > 0
  485. GO
  486. IF OBJECT_ID('dnt_deleteattachmentbyaid','P') IS NOT NULL
  487. DROP PROC [dnt_deleteattachmentbyaid]
  488. GO
  489. CREATE PROCEDURE [dnt_deleteattachmentbyaid]
  490. @aid INT
  491. AS
  492. DELETE FROM [dnt_attachments] 
  493. WHERE [aid]=@aid
  494. GO
  495. IF OBJECT_ID('dnt_deleteattachmentbytid','P') IS NOT NULL
  496. DROP PROC [dnt_deleteattachmentbytid]
  497. GO
  498. CREATE PROCEDURE [dnt_deleteattachmentbytid]
  499. @tid INT
  500. AS
  501. DELETE FROM [dnt_attachments] WHERE [tid] = @tid
  502. GO
  503. IF OBJECT_ID('dnt_deleteattachmentbytidlist','P') IS NOT NULL
  504. DROP PROC [dnt_deleteattachmentbytidlist]
  505. GO
  506. CREATE PROCEDURE [dnt_deleteattachmentbytidlist]
  507. @tidlist VARCHAR(500)
  508. AS
  509. DELETE FROM [dnt_attachments] WHERE CHARINDEX(','+RTRIM([tid])+',',','+@tidlist+',') > 0
  510. GO
  511. IF OBJECT_ID('dnt_getattachmentlistbytidlist','P') IS NOT NULL
  512. DROP PROC [dnt_getattachmentlistbytidlist]
  513. GO
  514. CREATE PROCEDURE [dnt_getattachmentlistbytidlist]
  515. @tidlist VARCHAR(500)
  516. AS
  517. SELECT 
  518. [aid],
  519. [filename] 
  520. FROM [dnt_attachments] 
  521. WHERE CHARINDEX(','+RTRIM([tid])+',',''+@tidlist+',') > 0
  522. GO
  523. IF OBJECT_ID('dnt_getattachmentlistbytid','P') IS NOT NULL
  524. DROP PROC [dnt_getattachmentlistbytid]
  525. GO
  526. CREATE PROCEDURE [dnt_getattachmentlistbytid]
  527. @tid INT
  528. AS
  529. SELECT 
  530. [aid],
  531. [filename] 
  532. FROM [dnt_attachments] 
  533. WHERE [tid] = @tid
  534. GO
  535. IF OBJECT_ID('dnt_updateattachmentdownloads','P') IS NOT NULL
  536. DROP PROC [dnt_updateattachmentdownloads]
  537. GO
  538. CREATE PROCEDURE [dnt_updateattachmentdownloads]
  539. @aid INT
  540. AS
  541. UPDATE [dnt_attachments] SET [downloads]=[downloads]+1 WHERE [aid]=@aid
  542. GO
  543. IF OBJECT_ID('dnt_getattachenmtlistbypid','P') IS NOT NULL
  544. DROP PROC [dnt_getattachenmtlistbypid]
  545. GO
  546. CREATE PROCEDURE [dnt_getattachenmtlistbypid]
  547. @pid INT
  548. AS
  549. SELECT 
  550. [aid],
  551. [uid],
  552. [tid],
  553. [pid],
  554. [postdatetime],
  555. [readperm],
  556. [filename],
  557. [description],
  558. [filetype],
  559. [filesize],
  560. [attachment],
  561. [downloads],
  562. [attachprice],
  563. [width],
  564. [height] 
  565. FROM [dnt_attachments] 
  566. WHERE [pid]=@pid
  567. GO
  568. IF OBJECT_ID('dnt_getattachmentcountbytid','P') IS NOT NULL
  569. DROP PROC [dnt_getattachmentcountbytid]
  570. GO
  571. CREATE PROCEDURE [dnt_getattachmentcountbytid]
  572. @tid INT
  573. AS
  574. SELECT COUNT([aid]) AS [acount] FROM [dnt_attachments] WHERE [tid]=@tid
  575. GO
  576. IF OBJECT_ID('dnt_getattachmentcountbypid','P') IS NOT NULL
  577. DROP PROC [dnt_getattachmentcountbypid]
  578. GO
  579. CREATE PROCEDURE [dnt_getattachmentcountbypid]
  580. @pid INT
  581. AS
  582. SELECT COUNT([aid]) AS [acount] FROM [dnt_attachments] WHERE [pid]=@pid
  583. GO
  584. IF OBJECT_ID('dnt_getattachenmtinfobyaid','P') IS NOT NULL
  585. DROP PROC [dnt_getattachenmtinfobyaid]
  586. GO
  587. CREATE PROCEDURE [dnt_getattachenmtinfobyaid]
  588. @aid INT
  589. AS
  590. SELECT TOP 1
  591. [aid],
  592. [uid],
  593. [tid],
  594. [pid],
  595. [postdatetime],
  596. [readperm],
  597. [filename],
  598. [description],
  599. [filetype],
  600. [filesize],
  601. [attachment],
  602. [downloads],
  603. [attachprice],
  604. [width],
  605. [height] 
  606. FROM [dnt_attachments] 
  607. WHERE [aid]=@aid
  608. GO
  609. IF OBJECT_ID('dnt_getpolllist','P') IS NOT NULL
  610. DROP PROC [dnt_getpolllist]
  611. GO
  612. CREATE PROCEDURE [dnt_getpolllist]
  613. @tid int
  614. AS
  615. SELECT 
  616. [pollid],
  617. [tid],
  618. [displayorder],
  619. [multiple],
  620. [visible],
  621. [maxchoices],
  622. [expiration],
  623. [uid],
  624. [voternames] 
  625. FROM [dnt_polls] 
  626. WHERE [tid]=@tid
  627. GO
  628. IF OBJECT_ID('dnt_gettaginfo','P') IS NOT NULL
  629. DROP PROC [dnt_gettaginfo]
  630. GO
  631. CREATE PROCEDURE [dnt_gettaginfo]
  632. @tagid int
  633. AS
  634. SELECT 
  635. [tagid],
  636. [tagname],
  637. [userid],
  638. [postdatetime],
  639. [orderid],
  640. [color],
  641. [count],
  642. [fcount],
  643. [pcount],
  644. [scount],
  645. [vcount],
  646. [gcount] 
  647. FROM [dnt_tags] 
  648. WHERE [tagid]=@tagid
  649. GO
  650. IF OBJECT_ID('dnt_setcurrenttopics','P') IS NOT NULL
  651. DROP PROC [dnt_setcurrenttopics]
  652. GO
  653. CREATE PROCEDURE [dnt_setcurrenttopics]
  654. @fid int
  655. AS
  656. UPDATE 
  657. [dnt_forums] 
  658. SET [curtopics] = (SELECT COUNT(tid) FROM [dnt_topics] WHERE [displayorder] >= 0 AND [fid]=@fid) WHERE [fid]=@fid
  659. GO
  660. IF OBJECT_ID('[dnt_createinvitecode]','P') IS NOT NULL
  661. DROP PROC [dnt_createinvitecode]
  662. GO
  663. CREATE PROCEDURE [dnt_createinvitecode]
  664.                     @code char(8),
  665.                     @creatorid int,
  666.                     @creator nchar(20),
  667.                     @createtime smalldatetime,
  668.                     @expiretime smalldatetime,
  669.                     @maxcount int,
  670.                     @invitetype int
  671.                     AS
  672.                     
  673.                     INSERT INTO [dnt_invitation]([invitecode],[creatorid],[creator],[createdtime],[expiretime],[maxcount],[invitetype])
  674.                      VALUES(@code,@creatorid,@creator,@createtime,@expiretime,@maxcount,@invitetype);SELECT SCOPE_IDENTITY()
  675. GO
  676. IF OBJECT_ID('[dnt_deleteinvitecode]','P') IS NOT NULL
  677. DROP PROC [dnt_deleteinvitecode]
  678. GO
  679. CREATE PROCEDURE [dnt_deleteinvitecode]
  680. @id int
  681. AS
  682. BEGIN
  683. UPDATE [dnt_invitation] SET [isdeleted]=1 WHERE [inviteid]=@id
  684. END
  685. GO
  686. IF OBJECT_ID('[dnt_clearexpireinvitecode]','P') IS NOT NULL
  687. DROP PROC [dnt_clearexpireinvitecode]
  688. GO
  689. CREATE PROCEDURE [dnt_clearexpireinvitecode]
  690. AS
  691. BEGIN
  692. DELETE [dnt_invitation] WHERE [invitetype]=3 AND [createdtime]<>[expiretime] AND ([expiretime]-GETDATE())<=0;
  693. DELETE [dnt_invitation] WHERE [isdeleted]=1 AND [createdtime]<(GETDATE()-1)
  694. END
  695. GO
  696. if exists (select * from sysobjects where id = object_id(N'[dnt_clearexpirecreditorders]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  697. drop procedure [dnt_clearexpirecreditorders]
  698. GO
  699. CREATE PROCEDURE [dnt_clearexpirecreditorders]
  700. AS
  701. BEGIN
  702.    DELETE [dnt_orders] WHERE [orderstatus] < 1 AND [createdtime] < (GETDATE()-15)
  703. END
  704. GO
  705. --2009-10-30 后台优化----------------------------------------------
  706. IF OBJECT_ID('dnt_getmaxandmintid','P') IS NOT NULL
  707. DROP PROC [dnt_getmaxandmintid]
  708. GO
  709. CREATE PROC [dnt_getmaxandmintid]
  710. @fid INT
  711. AS
  712. SELECT 
  713. MAX([tid]) AS [maxtid],
  714. MIN([tid]) AS [mintid] 
  715. FROM [dnt_topics] 
  716. WHERE 
  717. [fid] IN (SELECT [fid] 
  718.   FROM [dnt_forums] 
  719.   WHERE [fid]=@fid 
  720.   OR (CHARINDEX(',' + RTRIM(@fid) + ',', ',' + RTRIM(parentidlist) + ',') > 0))
  721. GO
  722. IF OBJECT_ID('dnt_getdesignatepostcount','P') IS NOT NULL
  723. DROP PROC [dnt_getdesignatepostcount]
  724. GO
  725. CREATE PROC [dnt_getdesignatepostcount]
  726. @fid INT,
  727. @posttablename VARCHAR(50)
  728. AS
  729. EXEC ('SELECT COUNT([pid]) AS [postcount] FROM [' + @posttablename + '] WHERE [fid] = ' + @fid)
  730. GO
  731. IF OBJECT_ID('dnt_getpostcountbyuid','P') IS NOT NULL
  732. DROP PROC [dnt_getpostcountbyuid]
  733. GO
  734. CREATE PROC [dnt_getpostcountbyuid]
  735. @uid INT,
  736. @posttablename VARCHAR(50)
  737. AS
  738. EXEC ('SELECT COUNT([pid]) AS [postcount] FROM [' + @posttablename + '] WHERE [posterid] = ' + @uid)
  739. GO
  740. IF OBJECT_ID('dnt_gettodaypostcountbyuid','P') IS NOT NULL
  741. DROP PROC [dnt_gettodaypostcountbyuid]
  742. GO
  743. CREATE PROC [dnt_gettodaypostcountbyuid]
  744. @uid INT,
  745. @posttablename VARCHAR(50)
  746. AS
  747. EXEC ('SELECT COUNT([pid]) AS [postcount] 
  748. FROM [' + @posttablename + '] 
  749. WHERE [posterid] = ' + @uid + ' AND DATEDIFF(day, [postdatetime], GETDATE()) = 0')
  750. GO
  751. IF OBJECT_ID('dnt_gettotaltopiccount','P') IS NOT NULL
  752. DROP PROC [dnt_gettotaltopiccount]
  753. GO
  754. CREATE PROC [dnt_gettotaltopiccount]
  755. AS
  756. SELECT COUNT([tid]) AS [topicscount] FROM [dnt_topics]
  757. GO
  758. IF OBJECT_ID('dnt_resetstatistic','P') IS NOT NULL
  759. DROP PROC [dnt_resetstatistic]
  760. GO
  761. CREATE PROC [dnt_resetstatistic]
  762. @totaltopic INT,
  763. @totalpost INT,
  764. @totalusers INT,
  765. @lastusername VARCHAR(20),
  766. @lastuserid INT
  767. AS
  768. UPDATE [dnt_statistics] 
  769. SET 
  770. [totaltopic]=@totaltopic,[totalpost]=@totalpost,[totalusers]=@totalusers,[lastusername]=@lastusername,[lastuserid]=@lastuserid
  771. GO
  772. IF OBJECT_ID('dnt_gettopusers','P') IS NOT NULL
  773. DROP PROC [dnt_gettopusers]
  774. GO
  775. CREATE PROC [dnt_gettopusers]
  776. @statcont INT,
  777. @lastuid INT
  778. AS
  779. EXEC('
  780. SELECT TOP '+@statcont+' [uid] FROM [dnt_users] WHERE [uid] > @lastuid
  781. ')
  782. GO
  783. IF OBJECT_ID('dnt_resetuserdigestposts','P') IS NOT NULL
  784. DROP PROC [dnt_resetuserdigestposts]
  785. GO
  786. CREATE PROC [dnt_resetuserdigestposts]
  787. @userid INT
  788. AS
  789. UPDATE [dnt_users] 
  790. SET [digestposts]=(SELECT COUNT(tid) AS [digestposts] FROM [dnt_topics] WHERE [dnt_topics].[posterid] = [dnt_users].[uid] AND [digest] > 0) WHERE [dnt_users].[uid] = @userid
  791. GO
  792. IF OBJECT_ID('dnt_getusers','P') IS NOT NULL
  793. DROP PROC [dnt_getusers]
  794. GO
  795. CREATE PROC [dnt_getusers]
  796. @start_uid INT,
  797. @end_uid INT
  798. AS
  799. SELECT [uid] FROM [dnt_users] WHERE [uid] >= @start_uid AND [uid]<=@end_uid
  800. GO
  801. IF OBJECT_ID('dnt_updateuserpostcount','P') IS NOT NULL
  802. DROP PROC [dnt_updateuserpostcount]
  803. GO
  804. CREATE PROC [dnt_updateuserpostcount]
  805. @postcount INT,
  806. @userid INT
  807. AS
  808. UPDATE [dnt_users] SET [posts]=@postcount WHERE [dnt_users].[uid] = @userid
  809. GO
  810. IF OBJECT_ID('dnt_getonlineregistercount','P') IS NOT NULL
  811. DROP PROC [dnt_getonlineregistercount]
  812. GO
  813. CREATE PROC [dnt_getonlineregistercount]
  814. AS
  815. SELECT COUNT(olid) FROM [dnt_online] WHERE [userid]>0
  816. GO
  817. IF OBJECT_ID('dnt_gettopictids','P') IS NOT NULL
  818. DROP PROC [dnt_gettopictids]
  819. GO
  820. CREATE PROC [dnt_gettopictids]
  821. @statcount INT,
  822. @lasttid INT
  823. AS
  824. EXEC('
  825. SELECT TOP '+@statcount+' [tid] FROM [dnt_topics] WHERE [tid] > @lasttid ORDER BY [tid]
  826. ')
  827. GO
  828. IF OBJECT_ID('dnt_updatelastpostoftopic','P') IS NOT NULL
  829. DROP PROC [dnt_updatelastpostoftopic]
  830. GO
  831. CREATE PROC [dnt_updatelastpostoftopic]
  832. @tid INT,
  833. @postcount INT,
  834. @lastpostid INT,
  835. @lastpost VARCHAR(20),
  836. @lastposterid INT,
  837. @lastposter VARCHAR(20)
  838. AS
  839. UPDATE [dnt_topics] 
  840. SET [lastpost]=@lastpost, [lastposterid]=@lastposterid, [lastposter]=@lastposter, [replies]=@postcount, [lastpostid]=@lastpostid 
  841. WHERE [tid] = @tid
  842. GO
  843. IF OBJECT_ID('dnt_updatetopiclastposterid','P') IS NOT NULL
  844. DROP PROC [dnt_updatetopiclastposterid]
  845. GO
  846. CREATE PROC [dnt_updatetopiclastposterid]
  847. @tid INT
  848. AS
  849. UPDATE [dnt_topics] 
  850. SET [lastposterid]=(SELECT ISNULL(MIN(lastpostid), -1)-1 FROM [dnt_topics] WHERE [tid] = @tid)
  851. GO
  852. IF OBJECT_ID('dnt_gettopics','P') IS NOT NULL
  853. DROP PROC [dnt_gettopics]
  854. GO
  855. CREATE PROC [dnt_gettopics]
  856. @start_tid INT,
  857. @end_tid INT
  858. AS
  859. SELECT [tid] 
  860. FROM [dnt_topics] 
  861. WHERE [tid] >= @start_tid AND [tid]<=@end_tid 
  862. ORDER BY [tid]
  863. GO
  864. IF OBJECT_ID('dnt_gettopforumfids','P') IS NOT NULL
  865. DROP PROC [dnt_gettopforumfids]
  866. GO
  867. CREATE PROC [dnt_gettopforumfids]
  868. @lastfid INT,
  869. @statcount INT
  870. AS
  871. EXEC('
  872. SELECT TOP(@statcount) [fid] FROM [dnt_forums] WHERE [fid] > @lastfid
  873. ')
  874. GO
  875. IF OBJECT_ID('dnt_getlastpostbyfid','P') IS NOT NULL
  876. DROP PROC [dnt_getlastpostbyfid]
  877. GO
  878. CREATE PROC [dnt_getlastpostbyfid]
  879. @fid INT,
  880. @posttablename VARCHAR(50)
  881. AS
  882. EXEC ('SELECT TOP 1 [tid], [title], [postdatetime], [posterid], [poster], [pid] 
  883. FROM [' + @posttablename + '] 
  884. WHERE [fid] = ' + @fid +
  885. 'ORDER BY [pid] DESC')
  886. GO
  887. IF OBJECT_ID('dnt_updateforum','P') IS NOT NULL
  888. DROP PROC [dnt_updateforum]
  889. GO
  890. CREATE PROC [dnt_updateforum]
  891. @lastfid INT,
  892. @topiccount INT,
  893. @postcount INT,
  894. @lasttid INT,
  895. @lasttitle NCHAR(80),
  896. @lastpost VARCHAR(20),
  897. @lastposterid INT,
  898. @lastposter NCHAR(20),
  899. @todaypostcount INT 
  900. AS
  901. UPDATE [dnt_forums] 
  902. SET [topics] = @topiccount, [posts]=@postcount, [todayposts] = @todaypostcount, [lasttid] = @lasttid, [lasttitle] = @lasttitle, [lastpost]=@lastpost, [lastposterid] = @lastposterid, [lastposter]=@lastposter 
  903. WHERE [dnt_forums].[fid] = @lastfid
  904. GO
  905. IF OBJECT_ID('dnt_resetclearmove','P') IS NOT NULL
  906. DROP PROC [dnt_resetclearmove]
  907. GO
  908. CREATE PROC [dnt_resetclearmove]
  909. AS
  910. DELETE FROM [dnt_topics] WHERE [closed] > 1
  911. GO
  912. IF OBJECT_ID('dnt_updatemytopic','P') IS NOT NULL
  913. DROP PROC [dnt_updatemytopic]
  914. GO
  915. CREATE PROC [dnt_updatemytopic]
  916. AS
  917. DELETE FROM [dnt_mytopics]
  918. INSERT INTO [dnt_mytopics]([uid], [tid], [dateline]) 
  919. SELECT [posterid],[tid],[postdatetime] 
  920. FROM [dnt_topics] 
  921. WHERE [posterid]<>-1
  922. GO
  923. IF OBJECT_ID('dnt_updatemypost','P') IS NOT NULL
  924. DROP PROC [dnt_updatemypost]
  925. GO
  926. CREATE PROC [dnt_updatemypost]
  927. @tablename VARCHAR(50)
  928. AS
  929. DELETE FROM [dnt_myposts]
  930. EXEC ('
  931. INSERT INTO [dnt_myposts]([uid], [tid], [pid], [dateline])
  932. SELECT [posterid],[tid],[pid],[postdatetime] FROM [' + @tablename + '] WHERE [posterid]<>-1
  933. ')
  934. GO
  935. IF OBJECT_ID('dnt_updateforumsinfo','P') IS NOT NULL
  936. DROP PROC [dnt_updateforumsinfo]
  937. GO
  938. CREATE PROC [dnt_updateforumsinfo]
  939. @parentid SmallInt,
  940. @layer Int,
  941. @pathlist NChar(3000),
  942. @parentidlist NChar(300),
  943. @subforumcount Int,
  944. @name NChar(50),
  945. @status Int,
  946. @colcount SmallInt,
  947. @displayorder Int,
  948. @templateid SmallInt,
  949. @topics Int,
  950. @curtopics Int,
  951. @posts Int,
  952. @todayposts Int,
  953. @lasttid Int,
  954. @lasttitle NChar(60),
  955. @lastpost DateTime,
  956. @lastposterid Int,
  957. @lastposter NChar(20),
  958. @allowsmilies Int,
  959. @allowrss Int,
  960. @allowhtml Int,
  961. @allowbbcode Int,
  962. @allowimgcode Int,
  963. @allowblog Int,
  964. @istrade Int,
  965. @allowpostspecial Int,
  966. @allowspecialonly Int,
  967. @alloweditrules Int,
  968. @allowthumbnail Int,
  969. @allowtag Int,
  970. @recyclebin Int,
  971. @modnewposts Int,
  972. @jammer Int,
  973. @disablewatermark Int,
  974. @inheritedmod Int,
  975. @autoclose SmallInt,
  976. @password NVarChar(16),
  977. @icon VarChar(255),
  978. @postcredits VarChar(255),
  979. @replycredits VarChar(255),
  980. @redirect VarChar(255),
  981. @attachextensions VarChar(255),
  982. @rules NText,
  983. @topictypes Text,
  984. @viewperm Text,
  985. @postperm Text,
  986. @replyperm Text,
  987. @getattachperm Text,
  988. @postattachperm Text,
  989. @moderators Text,
  990. @description NText,
  991. @applytopictype TinyInt,
  992. @postbytopictype TinyInt,
  993. @viewbytopictype TinyInt,
  994. @topictypeprefix TinyInt,
  995. @permuserlist NText,
  996. @seokeywords NVarChar(500),
  997. @seodescription NVarChar(500),
  998. @rewritename NVarChar(20),
  999. @fid Int
  1000. AS
  1001. UPDATE [dnt_forums] 
  1002. SET [parentid]=@parentid, [layer]=@layer, [pathlist]=@pathlist, 
  1003. [parentidlist]=@parentidlist, [subforumcount]=@subforumcount, [name]=@name, [status]=@status,
  1004. [colcount]=@colcount, [displayorder]=@displayorder,[templateid]=@templateid,[topics]=@topics,
  1005. [curtopics]=@curtopics,[posts]=@posts,[todayposts]=@todayposts,[lasttid]=@lasttid,[lasttitle]=@lasttitle,
  1006. [lastpost]=@lastpost,[lastposterid]=@lastposterid,[lastposter]=@lastposter,
  1007. [allowsmilies]=@allowsmilies ,[allowrss]=@allowrss, [allowhtml]=@allowhtml, [allowbbcode]=@allowbbcode, [allowimgcode]=@allowimgcode, 
  1008. [allowblog]=@allowblog,[istrade]=@istrade,[allowpostspecial]=@allowpostspecial,[allowspecialonly]=@allowspecialonly,
  1009. [alloweditrules]=@alloweditrules ,[allowthumbnail]=@allowthumbnail ,[allowtag]=@allowtag,
  1010. [recyclebin]=@recyclebin, [modnewposts]=@modnewposts,[jammer]=@jammer,[disablewatermark]=@disablewatermark,[inheritedmod]=@inheritedmod,
  1011. [autoclose]=@autoclose 
  1012. WHERE [fid]=@fid
  1013. UPDATE [dnt_forumfields] 
  1014. SET [password]=@password,[icon]=@icon,[postcredits]=@postcredits,
  1015.  [replycredits]=@replycredits,[redirect]=@redirect,[attachextensions]=@attachextensions,[rules]=@rules,[topictypes]=@topictypes,
  1016.  [viewperm]=@viewperm,[postperm]=@postperm,[replyperm]=@replyperm,[getattachperm]=@getattachperm,[postattachperm]=@postattachperm,
  1017.  [moderators]=@moderators,[description]=@description,[applytopictype]=@applytopictype,[postbytopictype]=@postbytopictype,
  1018.  [viewbytopictype]=@viewbytopictype,[topictypeprefix]=@topictypeprefix,[permuserlist]=@permuserlist,[seokeywords]=@seokeywords,
  1019.  [seodescription]=@seodescription,[rewritename]=@rewritename 
  1020.  WHERE [fid]=@fid
  1021. GO
  1022. IF OBJECT_ID('dnt_insertforumsinfo','P') IS NOT NULL
  1023. DROP PROC [dnt_insertforumsinfo]
  1024. GO
  1025. CREATE PROC [dnt_insertforumsinfo]
  1026. @parentid SmallInt,
  1027. @layer Int,
  1028. @pathlist NChar(3000),
  1029. @parentidlist NChar(300),
  1030. @subforumcount Int,
  1031. @name NChar(50),
  1032. @status Int,
  1033. @colcount SmallInt,
  1034. @displayorder Int,
  1035. @templateid SmallInt,
  1036. @allowsmilies Int,
  1037. @allowrss Int,
  1038. @allowhtml Int,
  1039. @allowbbcode Int,
  1040. @allowimgcode Int,
  1041. @allowblog Int,
  1042. @istrade Int,
  1043. @alloweditrules Int,
  1044. @allowthumbnail Int,
  1045. @allowtag Int,
  1046. @recyclebin Int,
  1047. @modnewposts Int,
  1048. @jammer Int,
  1049. @disablewatermark Int,
  1050. @inheritedmod Int,
  1051. @autoclose SmallInt,
  1052. @allowpostspecial Int,
  1053. @allowspecialonly Int,
  1054. @description NText,
  1055. @password VarChar(16),
  1056. @icon VarChar(255),
  1057. @postcredits VarChar(255),
  1058. @replycredits VarChar(255),
  1059. @redirect VarChar(255),
  1060. @attachextensions VarChar(255),
  1061. @moderators Text,
  1062. @rules NText,
  1063. @topictypes Text,
  1064. @viewperm Text,
  1065. @postperm Text,
  1066. @replyperm Text,
  1067. @getattachperm Text,
  1068. @postattachperm Text,
  1069. @seokeywords NVarChar(500),
  1070. @seodescription NVarChar(500),
  1071. @rewritename NVarChar(20)
  1072. AS
  1073. DECLARE @fid INT
  1074. INSERT INTO [dnt_forums] ([parentid],[layer],[pathlist],[parentidlist],[subforumcount],[name],
  1075. [status],[colcount],[displayorder],[templateid],[allowsmilies],[allowrss],[allowhtml],[allowbbcode],[allowimgcode],[allowblog],
  1076. [istrade],[alloweditrules],[recyclebin],[modnewposts],[jammer],[disablewatermark],[inheritedmod],[autoclose],[allowthumbnail],
  1077. [allowtag],[allowpostspecial],[allowspecialonly]) 
  1078. VALUES (@parentid,@layer,@pathlist,@parentidlist,@subforumcount,@name,@status, @colcount, @displayorder,
  1079. @templateid,@allowsmilies,@allowrss,@allowhtml,@allowbbcode,@allowimgcode,@allowblog,@istrade,@alloweditrules,@recyclebin,
  1080. @modnewposts,@jammer,@disablewatermark,@inheritedmod,@autoclose,@allowthumbnail,@allowtag,@allowpostspecial,@allowspecialonly)
  1081. --SET @fid=@@IDENTITY
  1082. SELECT @fid = ISNULL(MAX(fid), 0) FROM [dnt_forums]
  1083. INSERT INTO [dnt_forumfields] ([fid],[description],[password],[icon],[postcredits],[replycredits],[redirect],
  1084. [attachextensions],[moderators],[rules],[topictypes],[viewperm],[postperm],[replyperm],[getattachperm],[postattachperm],[seokeywords],[seodescription],[rewritename]) 
  1085. VALUES (@fid,@description,@password,@icon,@postcredits,@replycredits,@redirect,@attachextensions,@moderators,@rules,@topictypes,@viewperm,
  1086. @postperm,@replyperm,@getattachperm,@postattachperm,@seokeywords,@seodescription,@rewritename) 
  1087. GO
  1088. IF OBJECT_ID('dnt_getsubforumcount','P') IS NOT NULL
  1089. DROP PROC [dnt_getsubforumcount]
  1090. GO
  1091. CREATE PROC [dnt_getsubforumcount]
  1092. @fid INT
  1093. AS
  1094. SELECT COUNT(fid) FROM [dnt_forums] WHERE [parentid]=@fid
  1095. GO
  1096. IF OBJECT_ID('dnt_deleteforumsbyfid','P') IS NOT NULL
  1097. DROP PROC [dnt_deleteforumsbyfid]
  1098. GO
  1099. CREATE PROC [dnt_deleteforumsbyfid]
  1100. @fid INT,
  1101. @postname NVARCHAR(50)
  1102. AS
  1103. DECLARE @parentid INT,
  1104. @displayorder INT
  1105. SELECT TOP 1 @parentid=[parentid],@displayorder=[displayorder] FROM [dnt_forums] WHERE [fid]=@fid
  1106. UPDATE [dnt_forums] SET [displayorder]=[displayorder]-1 WHERE [displayorder]>@displayorder
  1107. UPDATE [dnt_forums] SET [subforumcount]=[subforumcount]-1 WHERE  [fid]=@parentid
  1108. DELETE FROM [dnt_forumfields] WHERE [fid]=@fid
  1109. DELETE FROM [dnt_polls] WHERE [tid] IN (SELECT [tid] FROM [dnt_topics] WHERE [fid]=@fid)
  1110. EXEC ('DELETE FROM [dnt_attachments] WHERE [tid] IN(SELECT [tid] FROM [dnt_topics] WHERE [fid]=' + @fid + ') OR [pid] IN(SELECT [pid] FROM [' + @postname + '] WHERE [fid]=' + @fid + ')')
  1111. EXEC ('DELETE FROM [' + @postname + '] WHERE [fid]=' + @fid)
  1112. DELETE FROM [dnt_topics] WHERE [fid]=@fid
  1113. DELETE FROM [dnt_forums] WHERE  [fid]=@fid
  1114. DELETE FROM [dnt_moderators] WHERE  [fid]=@fid
  1115. GO
  1116. IF OBJECT_ID('dnt_getparentidbyfid','P') IS NOT NULL
  1117. DROP PROC [dnt_getparentidbyfid]
  1118. GO
  1119. CREATE PROC [dnt_getparentidbyfid]
  1120. @fid INT
  1121. AS
  1122. SELECT [parentid] From [dnt_forums] WHERE [inheritedmod]=1 AND [fid]=@fid
  1123. GO
  1124. IF OBJECT_ID('dnt_updateforumsmoderators','P') IS NOT NULL
  1125. DROP PROC [dnt_updateforumsmoderators]
  1126. GO
  1127. CREATE PROC [dnt_updateforumsmoderators]
  1128. @displayorder INT,
  1129. @moderators VARCHAR(500),
  1130. @fid INT,
  1131. @inherited INT
  1132. AS
  1133. DECLARE @usernamelist VARCHAR(255),
  1134. @username VARCHAR(255),
  1135. @uid INT,
  1136. @len INT,
  1137. @b BIT,
  1138. @begin INT,
  1139. @end INT
  1140. SELECT @len=0,@begin=1,@end=1,@b=1,@usernamelist=''
  1141. WHILE @b=1
  1142. BEGIN
  1143. IF @end=1
  1144. SET @begin=@end
  1145. ELSE
  1146. SET @begin=@end+1
  1147. SET @end = CHARINDEX(',',@moderators,@begin)
  1148. IF @end=0
  1149. SET @end=LEN(@moderators)+1
  1150. SET @len=@end-@begin
  1151. IF @len>0
  1152. BEGIN
  1153. SET @username=SUBSTRING(@moderators,@begin,@len)
  1154. IF @username<>''
  1155. BEGIN
  1156. SELECT @uid=[uid] FROM [dnt_users] WHERE [groupid]<>7 AND [groupid]<>8 AND [username]=@username
  1157. IF @uid IS NOT NULL
  1158. BEGIN
  1159. INSERT INTO [dnt_moderators] ([uid],[fid],[displayorder],[inherited]) VALUES (@uid,@fid,@displayorder,@inherited)
  1160. SET @usernamelist=@usernamelist+@username+','
  1161. SET @displayorder=@displayorder+1
  1162. SET @uid=NULL
  1163. END
  1164. END
  1165. END
  1166. ELSE
  1167. SET @b=0
  1168. END
  1169. IF RIGHT(@usernamelist,1)=','
  1170. SET @usernamelist=LEFT(@usernamelist,LEN(@usernamelist)-1)
  1171. UPDATE [dnt_forumfields] SET [moderators]=@usernamelist WHERE [fid] =@fid
  1172. GO
  1173. IF OBJECT_ID('dnt_getforumstable','P') IS NOT NULL
  1174. DROP PROC [dnt_getforumstable]
  1175. GO
  1176. CREATE PROC [dnt_getforumstable]
  1177. AS
  1178. SELECT
  1179. [f].[fid],[f].[parentid],[f].[layer],[f].[pathlist],[f].[parentidlist],[f].[subforumcount],[f].[name],[f].[status],[f].[colcount],[f].[displayorder],[f].[templateid],[f].[topics],[f].[curtopics],[f].[posts],[f].[todayposts],[f].[lasttid],[f].[lasttitle],[f].[lastpost],[f].[lastposterid],[f].[lastposter],[f].[allowsmilies],[f].[allowrss],[f].[allowhtml],[f].[allowbbcode],[f].[allowimgcode],[f].[allowblog],[f].[istrade],[f].[allowpostspecial],[f].[allowspecialonly],[f].[alloweditrules],[f].[allowthumbnail],[f].[allowtag],[f].[recyclebin],[f].[modnewposts],[f].[jammer],[f].[disablewatermark],[f].[inheritedmod],[f].[autoclose],[ff].[password],[ff].[icon],[ff].[postcredits],[ff].[replycredits],[ff].[redirect],[ff].[attachextensions],[ff].[rules],[ff].[topictypes],[ff].[viewperm],[ff].[postperm],[ff].[replyperm],[ff].[getattachperm],[ff].[postattachperm],[ff].[moderators],[ff].[description],[ff].[applytopictype],[ff].[postbytopictype],[ff].[viewbytopictype],[ff].[topictypeprefix],[ff].[permuserlist],[ff].[seokeywords],[ff].[seodescription],[ff].[rewritename] 
  1180. FROM [dnt_forums] AS [f] 
  1181. LEFT JOIN [dnt_forumfields] AS [ff] 
  1182. ON [f].[fid]=[ff].[fid] 
  1183. ORDER BY [f].[displayorder]
  1184. GO
  1185. IF OBJECT_ID('dnt_getmainforum','P') IS NOT NULL
  1186. DROP PROC [dnt_getmainforum]
  1187. GO
  1188. CREATE PROC [dnt_getmainforum]
  1189. AS
  1190. SELECT
  1191. [fid],[parentid],[layer],[pathlist],[parentidlist],[subforumcount],[name],[status],[colcount],[displayorder],[templateid],[topics],[curtopics],[posts],[todayposts],[lasttid],[lasttitle],[lastpost],[lastposterid],[lastposter],[allowsmilies],[allowrss],[allowhtml],[allowbbcode],[allowimgcode],[allowblog],[istrade],[allowpostspecial],[allowspecialonly],[alloweditrules],[allowthumbnail],[allowtag],[recyclebin],[modnewposts],[jammer],[disablewatermark],[inheritedmod],[autoclose] 
  1192. FROM [dnt_forums] 
  1193. WHERE [layer]=0 
  1194. Order By [displayorder] ASC
  1195. GO
  1196. IF OBJECT_ID('dnt_getlastposttid','P') IS NOT NULL
  1197. DROP PROC [dnt_getlastposttid]
  1198. GO
  1199. CREATE PROC [dnt_getlastposttid]
  1200. @visibleforums VARCHAR(4000),
  1201. @fid INT
  1202. AS
  1203. IF @visibleforums=''
  1204. SELECT TOP 1 [tid] FROM [dnt_topics] AS t LEFT JOIN [dnt_forums] AS f  ON [t].[fid] = [f].[fid] 
  1205. WHERE [t].[closed]<>1 AND  [t].[displayorder] >=0  AND ([t].[fid] = @fid 
  1206. OR CHARINDEX(',' + CONVERT(NVARCHAR(10), @fid) + ',' , ',' + RTRIM([f].[parentidlist]) + ',') > 0 )  
  1207. ORDER BY [t].[lastpost] DESC
  1208. ELSE
  1209. EXEC('SELECT TOP 1 [tid] FROM [dnt_topics] AS t LEFT JOIN [dnt_forums] AS f  ON [t].[fid] = [f].[fid] 
  1210. WHERE [t].[closed]<>1 AND  [t].[displayorder] >=0  AND ([t].[fid] = ' + @fid +
  1211. 'OR CHARINDEX('','' + CONVERT(NVARCHAR(10), ' + @fid + ') + '','' , '','' + RTRIM([f].[parentidlist]) + '','') > 0 )  
  1212. AND [t].[fid] IN ('+@visibleforums+')  ORDER BY [t].[lastpost] DESC')
  1213. GO
  1214. IF OBJECT_ID('dnt_deluserallinf','P') IS NOT NULL
  1215. DROP PROC [dnt_deluserallinf]
  1216. GO
  1217. CREATE PROC [dnt_deluserallinf]
  1218. @uid INT,
  1219. @delPosts BIT,
  1220. @delPms BIT
  1221. AS
  1222. DECLARE @existuid INT
  1223. SELECT @existuid = COUNT([uid]) FROM [dnt_users] WHERE [uid]=@uid
  1224. IF @existuid <>0
  1225. BEGIN
  1226. DELETE FROM [dnt_users] WHERE [uid]=@uid                 
  1227. DELETE FROM [dnt_userfields] WHERE [uid]=@uid                 
  1228. DELETE FROM [dnt_onlinetime] WHERE [uid]=@uid                
  1229. DELETE FROM [dnt_polls] WHERE [uid]=@uid                 
  1230. DELETE FROM [dnt_favorites] WHERE [uid]=@uid
  1231. DECLARE @tableid INT,
  1232. @tablename NVARCHAR(20)
  1233. IF @delPosts = 1
  1234. BEGIN
  1235. DELETE FROM [dnt_topics] WHERE [posterid]=@uid
  1236. DECLARE tables_cursor CURSOR FOR SELECT [id] FROM [dnt_tablelist]
  1237. OPEN tables_cursor
  1238. FETCH NEXT FROM tables_cursor INTO @tableid
  1239. WHILE @@FETCH_STATUS = 0
  1240. BEGIN
  1241. SET @tablename = 'dnt_posts' + LTRIM(STR(@tableid))
  1242. EXEC ('DELETE FROM ' + @tablename + ' WHERE [posterid]='+@uid)
  1243. FETCH NEXT FROM tables_cursor INTO @tableid
  1244. END
  1245. CLOSE tables_cursor
  1246. DEALLOCATE tables_cursor
  1247. SET @tableid = 0
  1248. SET @tablename = ''
  1249. END
  1250. ELSE
  1251. BEGIN
  1252. UPDATE [dnt_topics] SET [poster]='该用户已被删除' Where [posterid]=@uid
  1253. UPDATE [dnt_topics] SET [lastposter]='该用户已被删除' Where [lastpostid]=@uid
  1254. DECLARE tables_cursor CURSOR FOR SELECT [id] FROM [dnt_tablelist]
  1255. OPEN tables_cursor
  1256. FETCH NEXT FROM tables_cursor INTO @tableid
  1257. WHILE @@FETCH_STATUS = 0
  1258. BEGIN
  1259. SET @tablename = 'dnt_posts' + LTRIM(STR(@tableid))
  1260. EXEC ('UPDATE ['+@tablename+'] SET [poster]=''该用户已被删除'' WHERE [posterid]='+@uid)
  1261. FETCH NEXT FROM tables_cursor INTO @tableid
  1262. END
  1263. CLOSE tables_cursor
  1264. DEALLOCATE tables_cursor
  1265. SET @tableid = 0
  1266. SET @tablename = ''
  1267. END
  1268. IF @delPms = 1
  1269. BEGIN
  1270. DELETE FROM [dnt_pms] WHERE [msgfromid]=@uid
  1271. END
  1272. ELSE
  1273. BEGIN
  1274. UPDATE [dnt_pms] SET [msgfrom]='该用户已被删除' WHERE [msgfromid]=@uid
  1275. UPDATE [dnt_pms] SET [msgto]='该用户已被删除' WHERE [msgtoid]=@uid
  1276. END
  1277. DELETE FROM [dnt_moderators] WHERE [uid]=@uid
  1278. UPDATE [dnt_statistics] SET [totalusers]=[totalusers]-1
  1279. DECLARE @lastuserid INT,@lastusername VARCHAR(50)
  1280. SELECT TOP 1 @lastuserid=[uid],@lastusername=[username] FROM [dnt_users] ORDER BY [uid] DESC
  1281. IF @lastuserid IS NOT NULL
  1282. UPDATE [dnt_Statistics] SET [lastuserid]=@lastuserid, [lastusername]=@lastusername
  1283. END
  1284. GO
  1285. IF OBJECT_ID('dnt_addusergroup','P') IS NOT NULL
  1286. DROP PROC [dnt_addusergroup]
  1287. GO
  1288. CREATE PROC [dnt_addusergroup]
  1289. @Radminid INT,
  1290. @Grouptitle NVARCHAR(50),
  1291. @Creditshigher INT,
  1292. @Creditslower INT,
  1293. @Stars INT,
  1294. @Color CHAR(7),
  1295. @Groupavatar NVARCHAR(60), 
  1296. @Readaccess INT,
  1297. @Allowvisit INT,
  1298. @Allowpost INT,
  1299. @Allowreply INT,
  1300. @Allowpostpoll INT,
  1301. @Allowdirectpost INT,
  1302. @Allowgetattach INT,
  1303. @Allowpostattach INT,
  1304. @Allowvote INT,
  1305. @Allowmultigroups INT, 
  1306. @Allowsearch INT,
  1307. @Allowavatar INT,
  1308. @Allowcstatus INT,
  1309. @Allowuseblog INT,
  1310. @Allowinvisible INT,
  1311. @Allowtransfer INT,
  1312. @Allowsetreadperm INT, 
  1313. @Allowsetattachperm INT,
  1314. @Allowhidecode INT,
  1315. @Allowhtml INT,
  1316. @Allowcusbbcode INT,
  1317. @Allownickname INT,
  1318. @Allowsigbbcode INT,
  1319. @Allowsigimgcode INT,
  1320. @Allowviewpro INT,
  1321. @Allowviewstats INT,
  1322. @Allowtrade INT,
  1323. @Allowdiggs INT,
  1324. @Allowdebate INT,
  1325. @Allowbonus INT,
  1326. @Minbonusprice INT,
  1327. @Maxbonusprice INT,
  1328. @Disableperiodctrl INT, 
  1329. @Reasonpm INT,
  1330. @Maxprice SMALLINT,
  1331. @Maxpmnum SMALLINT,
  1332. @Maxsigsize SMALLINT,
  1333. @Maxattachsize INT,
  1334. @Maxsizeperday INT,
  1335. @Attachextensions CHAR(100),
  1336. @Maxspaceattachsize INT,
  1337. @Maxspacephotosize INT, 
  1338. @Raterange CHAR(100)
  1339. AS
  1340. INSERT INTO [dnt_usergroups]  ([radminid],[grouptitle],[creditshigher],[creditslower],
  1341. [stars] ,[color], [groupavatar],[readaccess], [allowvisit],[allowpost],[allowreply],
  1342. [allowpostpoll], [allowdirectpost],[allowgetattach],[allowpostattach],[allowvote],[allowmultigroups],
  1343. [allowsearch],[allowavatar],[allowcstatus],[allowuseblog],[allowinvisible],[allowtransfer],
  1344. [allowsetreadperm],[allowsetattachperm],[allowhidecode],[allowhtml],[allowcusbbcode],[allownickname],
  1345. [allowsigbbcode],[allowsigimgcode],[allowviewpro],[allowviewstats],[allowtrade],[allowdiggs],[disableperiodctrl],[reasonpm],
  1346. [maxprice],[maxpmnum],[maxsigsize],[maxattachsize],[maxsizeperday],[attachextensions],[raterange],[maxspaceattachsize],
  1347. [maxspacephotosize],[allowdebate],[allowbonus],[minbonusprice],[maxbonusprice]) 
  1348. VALUES(
  1349. @Radminid,@Grouptitle,@Creditshigher,@Creditslower,@Stars,@Color,@Groupavatar,@Readaccess,@Allowvisit,@Allowpost,@Allowreply,
  1350. @Allowpostpoll,@Allowdirectpost,@Allowgetattach,@Allowpostattach,@Allowvote,@Allowmultigroups,@Allowsearch,@Allowavatar,@Allowcstatus,
  1351. @Allowuseblog,@Allowinvisible,@Allowtransfer,@Allowsetreadperm,@Allowsetattachperm,@Allowhidecode,@Allowhtml,@Allowcusbbcode,@Allownickname,
  1352. @Allowsigbbcode,@Allowsigimgcode,@Allowviewpro,@Allowviewstats,@Allowtrade,@Allowdiggs,@Disableperiodctrl,@Reasonpm,@Maxprice,@Maxpmnum,@Maxsigsize,@Maxattachsize, 
  1353. @Maxsizeperday,@Attachextensions,@Raterange,@Maxspaceattachsize,@Maxspacephotosize,@Allowdebate,@Allowbonus,@Minbonusprice,@Maxbonusprice)
  1354. GO
  1355. IF OBJECT_ID('dnt_updateusergroup','P') IS NOT NULL
  1356. DROP PROC [dnt_updateusergroup]
  1357. GO
  1358. CREATE PROC [dnt_updateusergroup]
  1359. @Radminid INT,
  1360. @Grouptitle NVARCHAR(50),
  1361. @Creditshigher INT,
  1362. @Creditslower INT, 
  1363. @Stars INT,
  1364. @Color CHAR(7),
  1365. @Groupavatar NVARCHAR(60),
  1366. @Readaccess INT,
  1367. @Allowvisit INT,
  1368. @Allowpost INT,
  1369. @Allowreply INT,
  1370. @Allowpostpoll INT,
  1371. @Allowdirectpost INT,
  1372. @Allowgetattach INT,
  1373. @Allowpostattach INT,
  1374. @Allowvote INT,
  1375. @Allowmultigroups INT,
  1376. @Allowsearch INT,
  1377. @Allowavatar INT,
  1378. @Allowcstatus INT,
  1379. @Allowuseblog INT,
  1380. @Allowinvisible INT,
  1381. @Allowtransfer INT,
  1382. @Allowsetreadperm INT,
  1383. @Allowsetattachperm INT,
  1384. @Allowhidecode INT,
  1385. @Allowhtml INT,
  1386. @Allowcusbbcode INT,
  1387. @Allownickname INT,
  1388. @Allowsigbbcode INT,
  1389. @Allowsigimgcode INT,
  1390. @Allowviewpro INT,
  1391. @Allowviewstats INT,
  1392. @Allowtrade INT,
  1393. @Allowdiggs INT,
  1394. @Disableperiodctrl INT,
  1395. @Allowdebate INT,
  1396. @Allowbonus INT,
  1397. @Minbonusprice INT,
  1398. @Maxbonusprice INT,
  1399. @Reasonpm INT,
  1400. @Maxprice SMALLINT,
  1401. @Maxpmnum SMALLINT,
  1402. @Maxsigsize SMALLINT,
  1403. @Maxattachsize INT,
  1404. @Maxsizeperday INT,
  1405. @Attachextensions CHAR(100),
  1406. @Maxspaceattachsize INT,
  1407. @Maxspacephotosize INT,
  1408. @Groupid INT
  1409. AS
  1410. UPDATE [dnt_usergroups]  
  1411. SET [radminid]=@Radminid,[grouptitle]=@Grouptitle,[creditshigher]=@Creditshigher,[creditslower]=@Creditslower,
  1412. [stars]=@Stars,[color]=@Color,[groupavatar]=@Groupavatar,[readaccess]=@Readaccess, 
  1413. [allowvisit]=@Allowvisit,[allowpost]=@Allowpost,[allowreply]=@Allowreply,[allowpostpoll]=@Allowpostpoll, 
  1414. [allowdirectpost]=@Allowdirectpost,[allowgetattach]=@Allowgetattach,[allowpostattach]=@Allowpostattach,
  1415. [allowvote]=@Allowvote,[allowmultigroups]=@Allowmultigroups,[allowsearch]=@Allowsearch,[allowavatar]=@Allowavatar,
  1416. [allowcstatus]=@Allowcstatus,[allowuseblog]=@Allowuseblog,[allowinvisible]=@Allowinvisible,
  1417. [allowtransfer]=@Allowtransfer,[allowsetreadperm]=@Allowsetreadperm,[allowsetattachperm]=@Allowsetattachperm,
  1418. [allowhidecode]=@Allowhidecode,[allowhtml]=@Allowhtml,[allowcusbbcode]=@Allowcusbbcode,
  1419. [allownickname]=@Allownickname,[allowsigbbcode]=@Allowsigbbcode,[allowsigimgcode]=@Allowsigimgcode,
  1420. [allowviewpro]=@Allowviewpro,[allowviewstats]=@Allowviewstats,[allowtrade]=@Allowtrade,[allowdiggs]=@Allowdiggs,
  1421. [disableperiodctrl]=@Disableperiodctrl,[allowdebate]=@Allowdebate,[allowbonus]=@Allowbonus,
  1422. [minbonusprice]=@Minbonusprice,[maxbonusprice]=@Maxbonusprice,[reasonpm]=@Reasonpm,[maxprice]=@Maxprice,
  1423. [maxpmnum]=@Maxpmnum,[maxsigsize]=@Maxsigsize,[maxattachsize]=@Maxattachsize,[maxsizeperday]=@Maxsizeperday,
  1424. [attachextensions]=@Attachextensions,[maxspaceattachsize]=@Maxspaceattachsize,
  1425. [maxspacephotosize]=@Maxspacephotosize  
  1426. WHERE [groupid]=@Groupid
  1427. GO
  1428. IF OBJECT_ID('dnt_getonlinegroupicontable','P') IS NOT NULL
  1429. DROP PROC [dnt_getonlinegroupicontable]
  1430. GO
  1431. CREATE PROC [dnt_getonlinegroupicontable]
  1432. AS
  1433. SELECT [groupid], [displayorder], [title], [img] FROM [dnt_onlinelist] WHERE [img] <> '' ORDER BY [displayorder]
  1434. GO
  1435. IF OBJECT_ID('dnt_getuserlistbygroupid','P') IS NOT NULL
  1436. DROP PROC [dnt_getuserlistbygroupid]
  1437. GO
  1438. CREATE PROC [dnt_getuserlistbygroupid]
  1439. @groupIdList VARCHAR(500)
  1440. AS
  1441. SELECT 
  1442. [uid],
  1443. [username],
  1444. [nickname],
  1445. [password],
  1446. [secques],
  1447. [spaceid],
  1448. [gender],
  1449. [adminid],
  1450. [groupid],
  1451. [groupexpiry],
  1452. [extgroupids],
  1453. [regip],
  1454. [joindate],
  1455. [lastip],
  1456. [lastvisit],
  1457. [lastactivity],
  1458. [lastpost],
  1459. [lastpostid],
  1460. [lastposttitle],
  1461. [posts],
  1462. [digestposts],
  1463. [oltime],
  1464. [pageviews],
  1465. [credits],
  1466. [extcredits1],
  1467. [extcredits2],
  1468. [extcredits3],
  1469. [extcredits4],
  1470. [extcredits5],
  1471. [extcredits6],
  1472. [extcredits7],
  1473. [extcredits8],
  1474. [avatarshowid],
  1475. [email],
  1476. [bday],
  1477. [sigstatus],
  1478. [tpp],
  1479. [ppp],
  1480. [templateid],
  1481. [pmsound],
  1482. [showemail],
  1483. [invisible],
  1484. [newpm],
  1485. [newpmcount],
  1486. [accessmasks],
  1487. [onlinestate],
  1488. [newsletter],
  1489. [salt]
  1490. FROM [dnt_users] WHERE [groupid] IN (@groupIdList)
  1491. GO
  1492. IF OBJECT_ID('dnt_passpost','P') IS NOT NULL 
  1493. DROP PROC [dnt_passpost]
  1494. GO
  1495. CREATE PROC [dnt_passpost]
  1496. @currentPostTableId INT,
  1497. @postcount INT,
  1498. @pidList NVARCHAR(500)
  1499. AS
  1500. DECLARE @count INT,
  1501. @begin INT,
  1502. @postdatetime DATETIME,
  1503. @poster NVARCHAR(50),
  1504. @posterid INT,
  1505. @fid INT,
  1506. @title NVARCHAR(20),
  1507. @tid INT
  1508.  
  1509. SET @begin=1
  1510. EXEC('UPDATE  [dnt_posts'+@currentPostTableId+']   SET [invisible]=0 WHERE [pid] IN ('+@pidList+')')
  1511. UPDATE  [dnt_statistics] SET [totalpost]= [totalpost] + @postcount
  1512. DECLARE @tempposttable TABLE 
  1513. (
  1514. [ROWID] INT IDENTITY(1,1),
  1515. [postdatetime] DATETIME,
  1516. [poster] NVARCHAR(50),
  1517. [posterid] INT,
  1518. [fid] INT,
  1519. [title] NVARCHAR(20),
  1520. [tid] INT
  1521. )
  1522. INSERT INTO @tempposttable 
  1523. EXEC('SELECT [postdatetime],[poster],[posterid],[fid],[title],[tid] FROM [dnt_posts'+@currentPostTableId+'] WHERE [pid] IN ('+@pidList+')')
  1524. SELECT @count=COUNT(1) FROM @tempposttable
  1525. WHILE @begin <= @count
  1526. BEGIN
  1527. SELECT @postdatetime = [postdatetime],
  1528. @poster = [poster],
  1529. @posterid = [posterid],
  1530. @fid = [fid],
  1531. @title = [title],
  1532. @tid = [tid]
  1533. FROM @tempposttable
  1534. UPDATE [dnt_forums] 
  1535. SET [posts]=[posts] + 1, 
  1536. [todayposts]=CASE WHEN datediff(day,'2008-10-22',getdate())=0 
  1537. THEN [todayposts] + 1
  1538. ELSE [todayposts] END,
  1539. [lastpost]=@postdatetime,
  1540. [lastposter]=@poster,
  1541. [lastposterid]=@posterid 
  1542. WHERE [fid]=@fid
  1543. UPDATE [dnt_users] 
  1544. SET [lastpost] = @postdatetime, 
  1545. [lastpostid] = @posterid, 
  1546. [lastposttitle] = @title, 
  1547. [posts] = [posts] + 1  
  1548. WHERE [uid] = @posterid
  1549. UPDATE [dnt_topics] 
  1550. SET [replies]=[replies]+1,
  1551. [lastposter]=@poster,
  1552. [lastposterid]=@posterid,
  1553. [lastpost]=@postdatetime 
  1554. WHERE [tid]=@tid
  1555. SET @begin = @begin + 1
  1556. END
  1557. GO
  1558. IF OBJECT_ID('dnt_getunauditnewtopic','P') IS NOT NULL
  1559. DROP PROC [dnt_getunauditnewtopic]
  1560. GO
  1561. CREATE PROC [dnt_getunauditnewtopic]
  1562. AS
  1563. SELECT 
  1564. [tid],
  1565. [fid],
  1566. [iconid],
  1567. [typeid],
  1568. [readperm],
  1569. [price],
  1570. [poster],
  1571. [posterid],
  1572. [title],
  1573. [attention],
  1574. [postdatetime],
  1575. [lastpost],
  1576. [lastpostid],
  1577. [lastposter],
  1578. [lastposterid],
  1579. [views],
  1580. [replies],
  1581. [displayorder],
  1582. [highlight],
  1583. [digest],
  1584. [rate],
  1585. [hide],
  1586. [attachment],
  1587. [moderated],
  1588. [closed],
  1589. [magic],
  1590. [identify],
  1591. [special]
  1592. FROM dnt_topics
  1593. WHERE [displayorder] = -2 OR [displayorder] = -3 
  1594. ORDER BY [tid] DESC
  1595. GO
  1596. IF OBJECT_ID('dnt_getunauditnewtopicbycondition','P') IS NOT NULL
  1597. DROP PROC [dnt_getunauditnewtopicbycondition]
  1598. GO
  1599. CREATE PROCEDURE [dnt_getunauditnewtopicbycondition]
  1600. @fidlist NVARCHAR(500),
  1601. @pagesize int,
  1602. @displayorder INT,
  1603. @pageindex int
  1604. AS
  1605. DECLARE @startRow NVARCHAR(3)
  1606. SET @startRow = (@pageindex - 1) * @pagesize
  1607. IF @fidlist = '0'
  1608. BEGIN
  1609. IF @pageindex = 1
  1610. BEGIN
  1611. EXEC('
  1612. SELECT 
  1613. TOP '+@pagesize+'
  1614. [dnt_topics].[rate], 
  1615. [dnt_topics].[fid], 
  1616. [dnt_topics].[tid],
  1617. [dnt_topics].[iconid],
  1618. [dnt_topics].[typeid],
  1619. [dnt_topics].[title],
  1620. [dnt_topics].[price],
  1621. [dnt_topics].[hide],
  1622. [dnt_topics].[readperm],
  1623. [dnt_topics].[poster],
  1624. [dnt_topics].[posterid],
  1625. [dnt_topics].[replies],
  1626. [dnt_topics].[views],
  1627. [dnt_topics].[postdatetime],
  1628. [dnt_topics].[lastpost],
  1629. [dnt_topics].[lastposter],
  1630. [dnt_topics].[lastpostid],
  1631. [dnt_topics].[lastposterid],
  1632. [dnt_topics].[highlight],
  1633. [dnt_topics].[digest],
  1634. [dnt_topics].[displayorder],
  1635. [dnt_topics].[attachment],
  1636. [dnt_topics].[closed],
  1637. [dnt_topics].[magic],
  1638. [dnt_topics].[special]
  1639. FROM [dnt_topics]
  1640. WHERE [displayorder] = @displayorder
  1641. ')
  1642. END
  1643. ELSE
  1644. BEGIN
  1645. EXEC('
  1646. SELECT 
  1647. TOP '+@pagesize+'
  1648. [dnt_topics].[rate], 
  1649. [dnt_topics].[fid], 
  1650. [dnt_topics].[tid],
  1651. [dnt_topics].[iconid],
  1652. [dnt_topics].[typeid],
  1653. [dnt_topics].[title],
  1654. [dnt_topics].[price],
  1655. [dnt_topics].[hide],
  1656. [dnt_topics].[readperm],
  1657. [dnt_topics].[poster],
  1658. [dnt_topics].[posterid],
  1659. [dnt_topics].[replies],
  1660. [dnt_topics].[views],
  1661. [dnt_topics].[postdatetime],
  1662. [dnt_topics].[lastpost],
  1663. [dnt_topics].[lastposter],
  1664. [dnt_topics].[lastpostid],
  1665. [dnt_topics].[lastposterid],
  1666. [dnt_topics].[highlight],
  1667. [dnt_topics].[digest],
  1668. [dnt_topics].[displayorder],
  1669. [dnt_topics].[attachment],
  1670. [dnt_topics].[closed],
  1671. [dnt_topics].[magic],
  1672. [dnt_topics].[special]
  1673. FROM [dnt_topics]
  1674. WHERE [displayorder] = '+@displayorder+' 
  1675. AND tid < (SELECT MIN(tid) FROM (SELECT TOP '+@startRow+' tid FROM [dnt_topics] WHERE displayorder='+@displayorder+') AS T)
  1676. ORDER BY tid DESC
  1677. ')
  1678. END
  1679. END
  1680. ELSE
  1681. BEGIN
  1682. IF @pageindex = 1
  1683. BEGIN
  1684. EXEC('
  1685. SELECT 
  1686. TOP '+@pagesize+'
  1687. [dnt_topics].[rate], 
  1688. [dnt_topics].[fid], 
  1689. [dnt_topics].[tid],
  1690. [dnt_topics].[iconid],
  1691. [dnt_topics].[typeid],
  1692. [dnt_topics].[title],
  1693. [dnt_topics].[price],
  1694. [dnt_topics].[hide],
  1695. [dnt_topics].[readperm],
  1696. [dnt_topics].[poster],
  1697. [dnt_topics].[posterid],
  1698. [dnt_topics].[replies],
  1699. [dnt_topics].[views],
  1700. [dnt_topics].[postdatetime],
  1701. [dnt_topics].[lastpost],
  1702. [dnt_topics].[lastposter],
  1703. [dnt_topics].[lastpostid],
  1704. [dnt_topics].[lastposterid],
  1705. [dnt_topics].[highlight],
  1706. [dnt_topics].[digest],
  1707. [dnt_topics].[displayorder],
  1708. [dnt_topics].[attachment],
  1709. [dnt_topics].[closed],
  1710. [dnt_topics].[magic],
  1711. [dnt_topics].[special]
  1712. FROM [dnt_topics]
  1713. WHERE [displayorder] = @displayorder AND fid IN ('+@fidlist+')
  1714. ')
  1715. END
  1716. ELSE
  1717. BEGIN
  1718. EXEC('
  1719. SELECT 
  1720. TOP '+@pagesize+'
  1721. [dnt_topics].[rate], 
  1722. [dnt_topics].[fid], 
  1723. [dnt_topics].[tid],
  1724. [dnt_topics].[iconid],
  1725. [dnt_topics].[typeid],
  1726. [dnt_topics].[title],
  1727. [dnt_topics].[price],
  1728. [dnt_topics].[hide],
  1729. [dnt_topics].[readperm],
  1730. [dnt_topics].[poster],
  1731. [dnt_topics].[posterid],
  1732. [dnt_topics].[replies],
  1733. [dnt_topics].[views],
  1734. [dnt_topics].[postdatetime],
  1735. [dnt_topics].[lastpost],
  1736. [dnt_topics].[lastposter],
  1737. [dnt_topics].[lastpostid],
  1738. [dnt_topics].[lastposterid],
  1739. [dnt_topics].[highlight],
  1740. [dnt_topics].[digest],
  1741. [dnt_topics].[displayorder],
  1742. [dnt_topics].[attachment],
  1743. [dnt_topics].[closed],
  1744. [dnt_topics].[magic],
  1745. [dnt_topics].[special]
  1746. FROM [dnt_topics]
  1747. WHERE [displayorder] = '+@displayorder+' AND fid IN ('+@fidlist+')
  1748. AND tid < (SELECT MIN(tid) FROM (SELECT TOP '+@startRow+' tid FROM [dnt_topics] WHERE displayorder='+@displayorder+' fid IN ('+@fidlist+')) AS T)
  1749. ORDER BY tid DESC
  1750. ')
  1751. END
  1752. END
  1753. IF OBJECT_ID('dnt_getunauditpost','P') IS NOT NULL
  1754. DROP PROC [dnt_getunauditpost]
  1755. GO
  1756. CREATE PROCEDURE [dnt_getunauditpost]
  1757. @lastposter NVARCHAR(20),
  1758. @lastposterid INT
  1759. AS
  1760. UPDATE [dnt_topics] 
  1761. SET [lastposter]=@lastposter  
  1762. WHERE [lastposterid]=@lastposterid
  1763. GO
  1764. IF OBJECT_ID('dnt_updatetopicposter','P') IS NOT NULL
  1765. DROP PROC [dnt_updatetopicposter]
  1766. GO
  1767. CREATE PROCEDURE [dnt_updatetopicposter]
  1768. @poster NVARCHAR(20),
  1769. @posterid INT
  1770. AS
  1771. UPDATE [dnt_topics] 
  1772. SET [poster]=@poster 
  1773. WHERE [posterid]=@posterid
  1774. GO
  1775. IF OBJECT_ID('dnt_updatepostposter','P') IS NOT NULL
  1776. DROP PROC [dnt_updatepostposter]
  1777. GO
  1778. CREATE PROCEDURE [dnt_updatepostposter]
  1779. @poster NVARCHAR(20),
  1780. @posterid INT
  1781. AS
  1782. DECLARE @count INT,
  1783. @begin INT,
  1784. @tableid INT
  1785. SET @begin = 1
  1786. DECLARE @tempposttable TABLE 
  1787. (
  1788. [ROWID] INT IDENTITY(1,1),
  1789. [tableid] INT
  1790. )
  1791. INSERT INTO @tempposttable 
  1792. SELECT id FROM dnt_tablelist
  1793. SELECT @count=COUNT(1) FROM @tempposttable
  1794. WHILE @begin <= @count
  1795. BEGIN
  1796. SELECT  @tableid = [tableid] FROM @tempposttable WHERE [ROWID] = @begin
  1797. EXEC('UPDATE [dnt_posts' + @tableid + '] SET [poster]=''' + @poster + ''' WHERE [posterid]=' + @posterid )
  1798. SET @begin = @begin + 1
  1799. END
  1800. GO
  1801. IF OBJECT_ID('dnt_updatemoderatorname','P') IS NOT NULL
  1802. DROP PROC [dnt_updatemoderatorname]
  1803. GO
  1804. CREATE PROC [dnt_updatemoderatorname]
  1805. @oldname NVARCHAR(20),
  1806. @newname VARCHAR(20)
  1807. AS
  1808. IF @newname <> ''
  1809. UPDATE dnt_forumfields 
  1810. SET MODERATORS=REPLACE(LTRIM(RTRIM(REPLACE(' '+REPLACE(CONVERT(NVARCHAR(500),MODERATORS),',',' ')+' ',' '+@oldname+' ',' '+@newname+' '))),' ',',')
  1811. WHERE CHARINDEX(','+@oldname+',',','+CONVERT(NVARCHAR(500),MODERATORS)+',') > 0
  1812. ELSE
  1813. UPDATE dnt_forumfields 
  1814. SET MODERATORS = REPLACE(LTRIM(RTRIM(REPLACE(REPLACE(','+CONVERT(NVARCHAR(500),MODERATORS)+',',','+@oldname+',',','),',',' '))),' ',',')
  1815. WHERE CHARINDEX(','+@oldname+',',','+CONVERT(NVARCHAR(500),MODERATORS)+',') > 0
  1816. GO
  1817. IF OBJECT_ID('dnt_updateonlinelist','P') IS NOT NULL
  1818. DROP PROC [dnt_updateonlinelist]
  1819. GO
  1820. CREATE PROC [dnt_updateonlinelist]
  1821. @title NVARCHAR(50),
  1822. @groupid INT
  1823. AS
  1824. UPDATE [dnt_onlinelist] SET [title]=@title WHERE [groupid]=@groupid
  1825. GO
  1826. --此存储过程的作用是更新总帖子数
  1827. IF OBJECT_ID('dnt_resetforumsposts','P') IS NOT NULL
  1828. DROP PROC [dnt_resetforumsposts]
  1829. GO
  1830. CREATE PROC [dnt_resetforumsposts]
  1831. AS
  1832. --清空forums表中的帖子数,以便重新统计
  1833. UPDATE dnt_forums SET posts=0
  1834. DECLARE @i INT,
  1835. @maxlayer INT,
  1836. @maxtableid INT,
  1837. @tablename NVARCHAR(50)
  1838. SET @i = 1
  1839. --取分表数
  1840. SELECT @maxtableid = MAX(id) FROM dnt_tablelist
  1841. --依次处理分表
  1842. WHILE @i <= @maxtableid
  1843. BEGIN
  1844. SET @tablename = 'dnt_posts' + CONVERT(NVARCHAR(2),@i)
  1845. --如果分表不存在则继续处理下一个
  1846. IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE id = OBJECT_ID(@tablename) AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  1847. CONTINUE
  1848. --取得每个版块在当前分表中的帖子数,累加并更新forums表中版块帖子数
  1849. EXEC('
  1850. UPDATE dnt_forums 
  1851. SET posts=posts+rightTable.fidcount 
  1852. FROM dnt_forums 
  1853. INNER JOIN (SELECT fid,COUNT(fid) fidcount FROM '+ @tablename +' GROUP BY fid) AS rightTable
  1854. ON dnt_forums.fid=rightTable.fid
  1855. WHERE dnt_forums.fid=rightTable.fid
  1856. ')
  1857. SET @i = @i + 1
  1858. END
  1859. --以下操作将子版块中的帖子总数累加并更新到父版块中
  1860. --取得版块的最大层数
  1861. SELECT @maxlayer = MAX(layer) FROM dnt_forums
  1862. --倒序更新,从最底层版块更新到最顶层
  1863. WHILE @maxlayer > 0
  1864. BEGIN
  1865. --将子版块中的帖子总数累加并更新到父版块中
  1866. UPDATE dnt_forums 
  1867. SET posts=posts+rightTable.sumposts 
  1868. FROM dnt_forums AS leftTable 
  1869. INNER JOIN (SELECT parentid,SUM(posts) sumposts FROM dnt_forums WHERE layer=@maxlayer GROUP BY parentid) AS rightTable
  1870. ON leftTable.fid=rightTable.parentid
  1871. WHERE leftTable.fid=rightTable.parentid
  1872. SET @maxlayer = @maxlayer - 1
  1873. END
  1874. GO
  1875. --此存储过程的作用是更新最后发帖
  1876. --测试代码:
  1877. --SELECT parentid,fid,lasttid,lasttitle,lastpost,lastposterid,lastposter FROM #tempTable2 ORDER BY parentid
  1878. --SELECT fid,lasttid,lasttitle,lastpost,parentid,lastposterid,lastposter FROM dnt_forums WHERE layer = 6 AND fid IN (245,256,260,259,273)
  1879. IF OBJECT_ID('dnt_resetlastpostinfo','P') IS NOT NULL
  1880. DROP PROC [dnt_resetlastpostinfo]
  1881. GO
  1882. CREATE PROC [dnt_resetlastpostinfo]
  1883. AS
  1884. --创建两个临时表#tempTable1,#tempTable2
  1885. CREATE TABLE #tempTable1 (
  1886. fid INT,
  1887. lasttid INT,
  1888. lasttitle NVARCHAR(60),
  1889. lastpost DATETIME,
  1890. parentid INT,
  1891. lastposterid INT,
  1892. lastposter NVARCHAR(30)
  1893.  )
  1894. CREATE table #tempTable2 (
  1895. fid INT,
  1896. lasttid INT,
  1897. lasttitle NVARCHAR(60),
  1898. lastpost DATETIME,
  1899. parentid INT,
  1900. lastposterid INT,
  1901. lastposter NVARCHAR(30)
  1902. )
  1903. DECLARE @maxlayer INT  -- 用来存放最大layer的变量
  1904. SELECT @maxlayer = MAX(layer) FROM dnt_forums;
  1905. --先初始化dnt_forums表中最后发帖等的信息
  1906. UPDATE dnt_forums SET lasttid = 0, lasttitle = '从未',lastpost = '1900-1-1',lastposterid=0,lastposter=''
  1907. --更新所有有主题的版块的最后发帖人等信息
  1908. UPDATE dnt_forums 
  1909. SET lasttid = rightTable.tid, lasttitle = rightTable.title, lastpost = rightTable.lastpost, lastposterid=rightTable.lastposterid, lastposter=rightTable.lastposter
  1910. FROM dnt_forums AS leftTable
  1911. INNER JOIN (SELECT fid,tid,title,lastpost,lastposter,lastposterid FROM dnt_topics WHERE tid IN( SELECT MAX(tid) FROM dnt_topics GROUP BY fid)) AS rightTable
  1912. ON leftTable.fid = rightTable.fid
  1913. WHERE leftTable.fid = rightTable.fid
  1914. WHILE @maxlayer > 0
  1915. BEGIN
  1916. --清空临时表#tempTable1,为了保证第二次循环时,表是空的
  1917. DELETE FROM #tempTable1;
  1918. --首先以dnt_forums表中的parentid字段分组,查询出每组最后回复时间最晚的记录;
  1919. --然后LEFT JOIN表dnt_forums,以两个表中parentid相等并且lastpost相等为条件,进行查询,
  1920. --并把结果插入到临时表#tempTable1中,以备临时表#tempTable2用
  1921. INSERT INTO #tempTable1 
  1922. SELECT fid,lasttid,lasttitle,a.lastpost,a.parentid,a.lastposterid,a.lastposter 
  1923. FROM (
  1924. SELECT parentid,MAX(lastpost) lastpost FROM dnt_forums a WHERE layer = @maxlayer GROUP BY parentid
  1925.  ) b 
  1926. LEFT JOIN dnt_forums a
  1927. ON a.parentid=b.parentid and a.lastpost=b.lastpost
  1928. --清空临时表#tempTable2,为了保证第二次循环时,表是空的
  1929. DELETE FROM #tempTable2;
  1930. --首先以#tempTable1表中的parentid分组,查询出组中的MAX(fid);
  1931. --然后以fid IN (子查询中查出的MAX(fid))为条件,查询出结果并插入到#tempTable2中
  1932. INSERT INTO #tempTable2 
  1933. SELECT * FROM #tempTable1
  1934. WHERE fid IN (SELECT MAX(fid) FROM #tempTable1 GROUP BY parentid,lastpost)
  1935. --根据临时表#tempTable2中的内容,更新dnt_forums表的最后发帖人等信息
  1936. UPDATE dnt_forums 
  1937. SET lastpost = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lastpost
  1938.    ELSE dnt_forums.lastpost END,
  1939. lasttitle = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lasttitle
  1940. ELSE dnt_forums.lasttitle END,
  1941. lasttid = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lasttid
  1942. ELSE dnt_forums.lasttid END,
  1943. lastposterid = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lastposterid
  1944. ELSE dnt_forums.lastposterid END,
  1945. lastposter = CASE WHEN #tempTable2.lastpost>dnt_forums.lastpost THEN #tempTable2.lastposter
  1946. ELSE dnt_forums.lastposter END
  1947. FROM dnt_forums 
  1948. INNER JOIN #tempTable2 
  1949. ON dnt_forums.fid=#tempTable2.parentid 
  1950. WHERE dnt_forums.fid=#tempTable2.parentid;
  1951. SET @maxlayer = @maxlayer - 1;
  1952. END
  1953. DROP TABLE #tempTable2;
  1954. DROP TABLE #tempTable1;
  1955. GO
  1956. /*
  1957. 此存储过程的作用:
  1958. 根据参数中传递过来的分表名更新主题的最后回复等信息
  1959. */
  1960. IF OBJECT_ID('dnt_resetLastRepliesInfoOftopics','P') IS NOT NULL
  1961. DROP PROC [dnt_resetLastRepliesInfoOftopics]
  1962. GO
  1963. CREATE PROC [dnt_resetLastRepliesInfoOftopics]
  1964. @posttable NVARCHAR(20)
  1965. AS
  1966. EXEC('
  1967. UPDATE dnt_topics 
  1968. SET dnt_topics.replies = lastPostTable.posts, 
  1969. lastpost = lastPostTable.postdatetime, 
  1970. lastposterid = lastPostTable.posterid, 
  1971. lastposter = lastPostTable.poster, 
  1972. lastpostid = lastPostTable.pid 
  1973. FROM dnt_topics
  1974. INNER JOIN  (
  1975. SELECT leftTable.tid,leftTable.posterid,leftTable.pid,leftTable.poster,leftTable.postdatetime,rightTable.posts FROM '+@posttable+' AS leftTable 
  1976. LEFT JOIN (SELECT tid,COUNT(*)-1 posts,MAX(pid) maxpid FROM '+@posttable+' GROUP BY tid) AS rightTable
  1977. ON leftTable.pid = rightTable.maxpid
  1978. WHERE leftTable.pid = rightTable.maxpid
  1979. ) AS lastPostTable
  1980. ON dnt_topics.tid = lastPostTable.tid
  1981. WHERE dnt_topics.tid = lastPostTable.tid AND dnt_topics.lastpostid <> lastPostTable.pid
  1982. ')
  1983. GO
  1984. /*
  1985. 此存储过程的作用:
  1986. 更新所有用户的精华帖数
  1987. */
  1988. IF OBJECT_ID('dnt_resetuserdigestposts','P') IS NOT NULL
  1989. DROP PROC [dnt_resetuserdigestposts]
  1990. GO
  1991. CREATE PROC [dnt_resetuserdigestposts]
  1992. AS
  1993. UPDATE dnt_users
  1994. SET [digestposts] = leftTable.topiccount 
  1995. FROM dnt_users 
  1996. INNER JOIN (SELECT COUNT(tid) topiccount,posterid FROM dnt_topics WHERE [digest] > 0 GROUP BY posterid) AS leftTable
  1997. ON dnt_users.[uid] = leftTable.posterid
  1998. WHERE dnt_users.[uid] = leftTable.posterid AND dnt_users.posts <> 0
  1999. GO
  2000. /*
  2001. 此存储过程的作用:
  2002. 根据参数中传递过来的分表名更新用户的帖子数
  2003. 后台更新所有用户帖子数时使用
  2004. */
  2005. IF OBJECT_ID('dnt_resetuserspostcount','P') IS NOT NULL
  2006. DROP PROC [dnt_resetuserspostcount]
  2007. GO
  2008. CREATE PROC [dnt_resetuserspostcount]
  2009. @posttablename NVARCHAR(50)
  2010. AS
  2011. EXEC('
  2012. UPDATE dnt_users
  2013. SET posts = posts + leftTable.postcount 
  2014. FROM dnt_users 
  2015. INNER JOIN (SELECT posterid,COUNT(pid) postcount FROM '+@posttablename+' GROUP BY posterid) AS leftTable
  2016. ON dnt_users.[uid] = leftTable.posterid
  2017. WHERE dnt_users.[uid] = leftTable.posterid
  2018. ')
  2019. GO
  2020. CREATE PROCEDURE [dnt_createinvitecode]
  2021.                     @code char(8),
  2022.                     @creatorid int,
  2023.                     @creator nchar(20),
  2024.                     @createtime smalldatetime,
  2025.                     @expiretime smalldatetime,
  2026.                     @maxcount int,
  2027.                     @invitetype int
  2028.                     AS
  2029.                     
  2030.                     INSERT INTO [dnt_invitation]([invitecode],[creatorid],[creator],[createdtime],[expiretime],[maxcount],[invitetype])
  2031.                      VALUES(@code,@creatorid,@creator,@createtime,@expiretime,@maxcount,@invitetype);SELECT SCOPE_IDENTITY()
  2032. GO
  2033. CREATE PROCEDURE [dnt_deleteinvitecode]
  2034. @id int
  2035. AS
  2036. BEGIN
  2037. UPDATE [dnt_invitation] SET [isdeleted]=1 WHERE [inviteid]=@id
  2038. END
  2039. GO
  2040. CREATE PROCEDURE [dnt_clearexpireinvitecode]
  2041. AS
  2042. BEGIN
  2043. DELETE [dnt_invitation] WHERE [invitetype]=3 AND [createdtime]<>[expiretime] AND ([expiretime]-GETDATE())<=0;
  2044. DELETE [dnt_invitation] WHERE [isdeleted]=1 AND [createdtime]<(GETDATE()-1)
  2045. END
  2046. GO
  2047. CREATE PROCEDURE [dnt_getinvitecode]
  2048. @searchtype nchar(10),
  2049. @searchkey nchar(20)
  2050. AS
  2051. BEGIN
  2052. IF @searchtype='uid'
  2053.    SELECT TOP 1 [inviteid],[invitecode],[invitetype],[createdtime],[creator],[creatorid],[expiretime],[maxcount],[successcount] 
  2054. FROM [dnt_invitation] WHERE [creatorid]=@searchkey AND [invitetype]=2 AND [isdeleted]=0 ORDER BY [inviteid] DESC
  2055. ELSE IF @searchtype='id'
  2056.    SELECT [inviteid],[invitecode],[invitetype],[createdtime],[creator],[creatorid],[expiretime],[maxcount],[successcount] FROM 
  2057. [dnt_invitation] WHERE [inviteid]=@searchkey AND [isdeleted]=0
  2058. ELSE IF @searchtype='code'
  2059.    SELECT [inviteid],[invitecode],[invitetype],[createdtime],[creator],[creatorid],[expiretime],[maxcount],[successcount] FROM 
  2060. [dnt_invitation] WHERE [invitecode]=@searchkey AND [isdeleted]=0
  2061. ELSE
  2062.    SELECT (1)
  2063. END
  2064. GO
  2065. IF OBJECT_ID('dnt_getinvitecodelistbyuid','P') IS NOT NULL
  2066. DROP PROC [dnt_getinvitecodelistbyuid]
  2067. GO
  2068. CREATE PROCEDURE [dnt_getinvitecodelistbyuid]
  2069. @creatorid int,
  2070. @pageindex int
  2071. AS
  2072. DECLARE @startRow int,
  2073. @endRow int
  2074. SET @startRow = (@pageIndex - 1) * 10
  2075. IF @pageindex = 1
  2076. BEGIN
  2077. SELECT 
  2078. TOP 10
  2079. [inviteid],
  2080. [invitecode],
  2081. [invitetype],
  2082. [createdtime],
  2083. [creator],
  2084. [creatorid],
  2085. [expiretime],
  2086. [maxcount],
  2087. [successcount]
  2088. FROM [dnt_invitation]
  2089. WHERE [creatorid]=@creatorid AND [invitetype]=3 AND [isdeleted]=0 ORDER BY [inviteid] DESC
  2090. END
  2091. ELSE
  2092. BEGIN
  2093. EXEC('
  2094. SELECT 
  2095. TOP 10
  2096. [inviteid],
  2097. [invitecode],
  2098. [invitetype],
  2099. [createdtime],
  2100. [creator],
  2101. [creatorid],
  2102. [expiretime],
  2103. [maxcount],
  2104. [successcount]
  2105. FROM [dnt_invitation]
  2106. WHERE [creatorid]=@creatorid AND [invitetype]=3 AND [isdeleted]=0
  2107. AND inviteid < (SELECT MIN(inviteid) FROM ( SELECT TOP '+@startRow+' inviteid 
  2108. FROM [dnt_invitation] 
  2109. WHERE [creatorid]=@creatorid AND [invitetype]=3 AND [isdeleted]=0
  2110. RDER BY [inviteid] DESC
  2111.    ) AS T
  2112. )
  2113. ORDER BY [inviteid] DESC
  2114. ')
  2115. END
  2116. GO
  2117. CREATE PROCEDURE [dnt_isinvitecodeexist]
  2118. @code nchar(8)
  2119. AS
  2120. BEGIN
  2121. SELECT COUNT(1) FROM [dnt_invitation] WHERE [invitecode]=@code AND [isdeleted] =0
  2122. END
  2123. GO
  2124. CREATE PROCEDURE [dnt_updateinvitecodesuccesscount]
  2125. @id int
  2126. AS
  2127. BEGIN
  2128. UPDATE [dnt_invitation] SET [successcount]=[successcount]+1 WHERE [inviteid]=@id
  2129. END
  2130. GO
  2131. CREATE PROCEDURE [dnt_getuserinvitecodecount]
  2132. @creatorid int
  2133. AS
  2134. BEGIN
  2135. SELECT COUNT(1) FROM [dnt_invitation] WHERE [creatorid]=@creatorid AND [invitetype]=3 AND [isdeleted]=0
  2136. END
  2137. GO
  2138. CREATE PROCEDURE [dnt_gettodayusercreatedinvitecode]
  2139. @creatorid int
  2140. AS
  2141. BEGIN
  2142. SELECT COUNT(1) FROM [dnt_invitation] WHERE [creatorid]=@creatorid AND [invitetype]=2 AND (GETDATE()- [createdtime])<1
  2143. END
  2144. GO
  2145. IF OBJECT_ID('dnt_getattachmentlistbypid','P') IS NOT NULL
  2146. DROP PROC [dnt_getattachmentlistbypid]
  2147. GO
  2148. CREATE PROCEDURE [dnt_getattachmentlistbypid]
  2149. @pidlist varchar(500)
  2150. AS
  2151. EXEC('SELECT 
  2152. [aid],
  2153. [uid],
  2154. [tid],
  2155. [pid],
  2156. [postdatetime],
  2157. [readperm],
  2158. [filename],
  2159. [description],
  2160. [filetype],
  2161. [filesize],
  2162. [attachment],
  2163. [downloads],
  2164. [attachprice],
  2165. [width],
  2166. [height] 
  2167. FROM [dnt_attachments] 
  2168. WHERE [pid] IN ('+@pidlist+')')
  2169. GO
  2170. IF OBJECT_ID('dnt_getattachmentlistbyaid','P') IS NOT NULL
  2171. DROP PROC [dnt_getattachmentlistbyaid]
  2172. GO
  2173. CREATE PROCEDURE [dnt_getattachmentlistbyaid]
  2174. @aidlist varchar(500)
  2175. AS
  2176. SELECT [aid], [tid], [pid], [filename] FROM [dnt_attachments] WITH (NOLOCK) WHERE [aid] IN (SELECT [item] FROM [dnt_split](@aidlist, ',') )
  2177. GO
  2178. IF OBJECT_ID('dnt_deleteattachmentbyaidlist','P') IS NOT NULL
  2179. DROP PROC [dnt_deleteattachmentbyaidlist]
  2180. GO
  2181. CREATE PROCEDURE [dnt_deleteattachmentbyaidlist]
  2182. @aidlist VARCHAR(500)
  2183. AS
  2184. EXEC('DELETE FROM [dnt_attachments] WHERE [aid] IN ('+@aidlist+')')
  2185. GO
  2186. IF OBJECT_ID('dnt_deleteattachmentbytidlist','P') IS NOT NULL
  2187. DROP PROC [dnt_deleteattachmentbytidlist]
  2188. GO
  2189. CREATE PROCEDURE [dnt_deleteattachmentbytidlist]
  2190. @tidlist VARCHAR(500)
  2191. AS
  2192. EXEC('DELETE FROM [dnt_attachments] WHERE [tid] IN ('+@tidlist+')')
  2193. GO
  2194. IF OBJECT_ID('dnt_getattachmentlistbytidlist','P') IS NOT NULL
  2195. DROP PROC [dnt_getattachmentlistbytidlist]
  2196. GO
  2197. CREATE PROCEDURE [dnt_getattachmentlistbytidlist]
  2198. @tidlist VARCHAR(500)
  2199. AS
  2200. SELECT 
  2201. [aid],
  2202. [filename] 
  2203. FROM [dnt_attachments] WITH (NOLOCK)
  2204. WHERE [tid] IN (SELECT [item]FROM [dnt_split](@tidlist, ','))
  2205. GO
  2206. IF OBJECT_ID('dnt_updateuseronlinestates','P') IS NOT NULL
  2207. DROP PROCEDURE [dnt_updateuseronlinestates]
  2208. GO
  2209. CREATE PROCEDURE [dnt_updateuseronlinestates] 
  2210. @uidlist varchar(5000) = '' 
  2211. AS
  2212. EXEC ('UPDATE [dnt_users] SET [onlinestate]=0,[lastactivity]=GETDATE() WHERE [uid] IN ('+@uidlist+')')
  2213. GO
  2214. /*
  2215. 修改时间:2009-11-23
  2216. 修改原因:将CHARINDEX替换成了IN
  2217. 测试代码:
  2218. exec [dnt_deletetopicbytidlist1] '1246471,1246472',1
  2219. */
  2220. IF OBJECT_ID('dnt_deletetopicbytidlist1','P') IS NOT NULL
  2221. DROP PROCEDURE [dnt_deletetopicbytidlist1]
  2222. GO
  2223. CREATE PROCEDURE [dnt_deletetopicbytidlist1]
  2224.     @tidlist AS VARCHAR(2000),
  2225.     @chanageposts AS BIT
  2226. AS
  2227.     DECLARE @postcount int
  2228.     DECLARE @topiccount int
  2229.     DECLARE @todaycount int
  2230.     DECLARE @sqlstr nvarchar(4000)
  2231.     DECLARE @fid varchar(2000)
  2232.     DECLARE @posterid varchar(200)
  2233.     DECLARE @tempFid int
  2234.     DECLARE @tempPosterid int
  2235.     DECLARE @tempLayer int
  2236.     DECLARE @temppostdatetime datetime
  2237.     DECLARE @tempfidlist AS VARCHAR(1000)
  2238.     SET @fid = ''
  2239.     SET @posterid = ''
  2240.     SET @postcount=0
  2241.     SET @topiccount=0
  2242.     SET @todaycount=0
  2243.     SET @tempfidlist = '';
  2244.     IF @tidlist<>''
  2245.         BEGIN
  2246.             EXEC('DECLARE cu_dnt_posts CURSOR FOR SELECT [fid],[posterid],[layer],[postdatetime] FROM [dnt_posts1] WHERE [dnt_posts1].[tid] IN ('+@tidlist+')')
  2247.             OPEN cu_dnt_posts
  2248.             FETCH NEXT FROM cu_dnt_posts into @tempFid,@tempPosterid,@tempLayer,@temppostdatetime
  2249.             WHILE @@FETCH_STATUS = 0
  2250.                 BEGIN
  2251.                     SET @postcount = @postcount + 1
  2252.                     IF @tempLayer = 0
  2253.                     BEGIN
  2254.                     SET @topiccount = @topiccount + 1
  2255.                     END
  2256.                     IF DATEDIFF(d,@temppostdatetime,GETDATE()) = 0
  2257.                     BEGIN
  2258.                     SET @todaycount = @todaycount + 1
  2259.                     END
  2260.                     IF CHARINDEX(',' + LTRIM(STR(@tempFid)) + ',',@fid + ',') = 0
  2261.                     BEGIN
  2262.                     --SET @fid = @fid + ',' + LTRIM(STR(@tempFid))
  2263.                     SELECT @tempfidlist = ISNULL([parentidlist],'') FROM [dnt_forums] WHERE [fid] = @tempFid
  2264.                     IF RTRIM(@tempfidlist)<>''
  2265.                     BEGIN
  2266.                     SET @fid = RTRIM(@fid) + ',' +  RTRIM(@tempfidlist) + ',' + CAST(@tempFid AS VARCHAR(10))
  2267.                     END
  2268.                     ELSE
  2269.                     BEGIN
  2270.                     SET @fid =RTRIM(@fid) + ',' +  CAST(@tempFid AS VARCHAR(10))
  2271.                     END
  2272.                     END
  2273.                     IF @chanageposts = 1
  2274.                     BEGIN
  2275.                     UPDATE [dnt_users] SET [posts] = [posts] - 1 WHERE [uid] = @tempPosterid
  2276.                     END
  2277.                     FETCH NEXT FROM cu_dnt_posts into @tempFid,@tempPosterid,@tempLayer,@temppostdatetime
  2278.                 END
  2279.             CLOSE cu_dnt_posts
  2280.             DEALLOCATE cu_dnt_posts
  2281.             IF LEN(@fid)>0
  2282.                 BEGIN
  2283.                     SET @fid = SUBSTRING(@fid,2,LEN(@fid)-1)
  2284.                     IF @chanageposts = 1
  2285.                     BEGIN
  2286.                     UPDATE [dnt_statistics] SET [totaltopic]=[totaltopic] - @topiccount, [totalpost]=[totalpost] - @postcount
  2287.                     EXEC('UPDATE [dnt_forums] 
  2288.                     SET [posts]=[posts] - ' + @postcount + ',  
  2289.                     [topics]=[topics] - ' + @topiccount + ', 
  2290.                     [todayposts] = [todayposts] - ' + @todaycount + ' 
  2291.                     WHERE [fid] IN ('+@fid+')')
  2292.                     END
  2293.                     EXEC('DELETE FROM [dnt_favorites] WHERE [tid] IN ('+@tidlist+') AND [typeid]=0')
  2294.                     EXEC('DELETE FROM [dnt_polls] WHERE [tid] IN ('+@tidlist+')')
  2295.                     EXEC('DELETE FROM [dnt_posts1] WHERE [tid] IN ('+@tidlist+')')
  2296.                     EXEC('DELETE FROM [dnt_mytopics] WHERE [tid] IN ('+@tidlist+')')
  2297.                 END
  2298.             EXEC('DELETE FROM [dnt_topics] WHERE [closed] IN ('+@tidlist+') OR [tid] IN ('+@tidlist+')')
  2299.             EXEC('UPDATE [dnt_tags] SET [count]=[count]-1, [fcount]=[fcount]-1 WHERE [tagid] IN (SELECT [tagid] FROM [dnt_topictags] WHERE [tid] IN ('+@tidlist+'))') 
  2300.             EXEC('DELETE FROM [dnt_topictags] WHERE [tid] IN ('+@tidlist+')')
  2301.             EXEC('DELETE FROM [dnt_topictagcaches] WHERE [tid] IN ('+@tidlist+') OR [linktid] IN ('+@tidlist+')')
  2302. END
  2303. GO
  2304. /*修改存储过程的名字*/
  2305. IF OBJECT_ID('dnt_getattachmentlistbypid','P') IS NOT NULL
  2306. DROP PROC [dnt_getattachmentlistbypid]
  2307. GO
  2308. IF OBJECT_ID('dnt_getattachmentlistbypidlist','P') IS NOT NULL
  2309. DROP PROC [dnt_getattachmentlistbypidlist]
  2310. GO
  2311. CREATE PROCEDURE [dnt_getattachmentlistbypidlist]
  2312. @pidlist varchar(500)
  2313. AS
  2314. SELECT 
  2315. [aid],
  2316. [uid],
  2317. [tid],
  2318. [pid],
  2319. [postdatetime],
  2320. [readperm],
  2321. [filename],
  2322. [description],
  2323. [filetype],
  2324. [filesize],
  2325. [attachment],
  2326. [downloads],
  2327. [attachprice],
  2328. [width],
  2329. [height] 
  2330. FROM [dnt_attachments] WITH (NOLOCK)
  2331. WHERE [dnt_attachments].[pid] IN (SELECT [item]FROM [dnt_split](@pidlist, ',') )
  2332. GO
  2333. /*修改存储过程的名字*/
  2334. IF OBJECT_ID('dnt_getattachenmtlistbypid','P') IS NOT NULL
  2335. DROP PROC [dnt_getattachenmtlistbypid]
  2336. GO
  2337. IF OBJECT_ID('dnt_getattachmentlistbypid','P') IS NOT NULL
  2338. DROP PROC [dnt_getattachmentlistbypid]
  2339. GO
  2340. CREATE PROCEDURE [dnt_getattachmentlistbypid]
  2341. @pid INT
  2342. AS
  2343. SELECT 
  2344. [aid],
  2345. [uid],
  2346. [tid],
  2347. [pid],
  2348. [postdatetime],
  2349. [readperm],
  2350. [filename],
  2351. [description],
  2352. [filetype],
  2353. [filesize],
  2354. [attachment],
  2355. [downloads],
  2356. [attachprice],
  2357. [width],
  2358. [height] 
  2359. FROM [dnt_attachments] 
  2360. WHERE [pid]=@pid
  2361. GO
  2362. IF OBJECT_ID('dnt_getattachpaymentlogbyuid','P') IS NOT NULL
  2363. DROP PROC [dnt_getattachpaymentlogbyuid]
  2364. GO
  2365. CREATE PROCEDURE [dnt_getattachpaymentlogbyuid]
  2366. @attachidlist varchar(500),
  2367. @uid int
  2368. AS
  2369. EXEC('
  2370. SELECT 
  2371. [aid]
  2372. FROM [dnt_attachpaymentlog] 
  2373. WHERE [uid] = '+@uid+' AND [dnt_attachpaymentlog].[aid] IN ('+@attachidlist+')
  2374. ')
  2375. GO
  2376. IF OBJECT_ID('dnt_getindexforumlist','P') IS NOT NULL
  2377. DROP PROC [dnt_getindexforumlist]
  2378. GO
  2379. CREATE PROCEDURE [dnt_getindexforumlist]
  2380. AS
  2381. SELECT CASE WHEN DATEDIFF(n, [lastpost], GETDATE())<600 THEN 'new' ELSE 'old' END AS [havenew],
  2382. [dnt_forums].[allowbbcode],
  2383. [dnt_forums].[allowblog],
  2384. [dnt_forums].[alloweditrules],
  2385. [dnt_forums].[allowhtml],
  2386. [dnt_forums].[allowimgcode],
  2387. [dnt_forums].[allowpostspecial],
  2388. [dnt_forums].[allowrss],
  2389. [dnt_forums].[allowsmilies],
  2390. [dnt_forums].[allowspecialonly],
  2391. [dnt_forums].[allowtag],
  2392. [dnt_forums].[allowthumbnail],
  2393. [dnt_forums].[autoclose],
  2394. [dnt_forums].[colcount],
  2395. [dnt_forums].[curtopics],
  2396. [dnt_forums].[disablewatermark],
  2397. [dnt_forums].[displayorder],
  2398. [dnt_forums].[fid],
  2399. [dnt_forums].[inheritedmod],
  2400. [dnt_forums].[istrade],
  2401. [dnt_forums].[jammer],
  2402. [dnt_forums].[lastpost],
  2403. [dnt_forums].[lastposter],
  2404. [dnt_forums].[lastposterid],
  2405. [dnt_forums].[lasttid],
  2406. [dnt_forums].[lasttitle],
  2407. [dnt_forums].[layer],
  2408. [dnt_forums].[modnewposts],
  2409. [dnt_forums].[name],
  2410. [dnt_forums].[parentid],
  2411. [dnt_forums].[parentidlist],
  2412. [dnt_forums].[pathlist],
  2413. [dnt_forums].[posts],
  2414. [dnt_forums].[recyclebin],
  2415. [dnt_forums].[status],
  2416. [dnt_forums].[subforumcount],
  2417. [dnt_forums].[templateid],
  2418. [dnt_forums].[todayposts],
  2419. [dnt_forums].[topics],
  2420. [dnt_forumfields].[applytopictype],
  2421. [dnt_forumfields].[attachextensions],
  2422. [dnt_forumfields].[description],
  2423. [dnt_forumfields].[fid],
  2424. [dnt_forumfields].[getattachperm],
  2425. [dnt_forumfields].[icon],
  2426. [dnt_forumfields].[moderators],
  2427. [dnt_forumfields].[password],
  2428. [dnt_forumfields].[permuserlist],
  2429. [dnt_forumfields].[postattachperm],
  2430. [dnt_forumfields].[postbytopictype],
  2431. [dnt_forumfields].[postcredits],
  2432. [dnt_forumfields].[postperm],
  2433. [dnt_forumfields].[redirect],
  2434. [dnt_forumfields].[replycredits],
  2435. [dnt_forumfields].[replyperm],
  2436. [dnt_forumfields].[rewritename],
  2437. [dnt_forumfields].[rules],
  2438. [dnt_forumfields].[seodescription],
  2439. [dnt_forumfields].[seokeywords],
  2440. [dnt_forumfields].[topictypeprefix],
  2441. [dnt_forumfields].[topictypes],
  2442. [dnt_forumfields].[viewbytopictype],
  2443. [dnt_forumfields].[viewperm]
  2444. FROM [dnt_forums] 
  2445. LEFT JOIN [dnt_forumfields] ON [dnt_forums].[fid]=[dnt_forumfields].[fid] 
  2446. WHERE [dnt_forums].[status] > 0 AND [layer] <= 1 
  2447. AND [dnt_forums].[parentid] NOT IN (SELECT [fid] FROM [dnt_forums] WHERE [status] < 1 AND [layer] = 0) ORDER BY [displayorder]
  2448. GO
  2449. IF OBJECT_ID('dnt_resetforumstopics','P') IS NOT NULL
  2450. DROP PROC [dnt_resetforumstopics]
  2451. GO
  2452. CREATE PROC [dnt_resetforumstopics]
  2453. AS
  2454. --更新所有版块的主题数,不包含子版块
  2455. UPDATE dnt_forums 
  2456. SET curtopics=rightTable.sumtopics,topics = rightTable.sumtopics
  2457. FROM dnt_forums 
  2458. INNER JOIN (SELECT fid,count(tid) sumtopics FROM dnt_topics GROUP BY fid) AS rightTable
  2459. ON dnt_forums.fid=rightTable.fid
  2460. WHERE dnt_forums.fid=rightTable.fid
  2461. DECLARE @maxlayer INT
  2462. SELECT @maxlayer = MAX(layer) FROM dnt_forums
  2463. --倒序更新,从最底层版块更新到最顶层
  2464. WHILE @maxlayer > 0
  2465. BEGIN
  2466. --将子版块中的帖子总数累加并更新到父版块中
  2467. UPDATE dnt_forums 
  2468. SET topics=topics+rightTable.sumtopics 
  2469. FROM dnt_forums AS leftTable 
  2470. INNER JOIN (SELECT parentid,SUM(topics) sumtopics FROM dnt_forums WHERE layer=@maxlayer GROUP BY parentid) AS rightTable
  2471. ON leftTable.fid=rightTable.parentid
  2472. WHERE leftTable.fid=rightTable.parentid
  2473. SET @maxlayer = @maxlayer - 1
  2474. END
  2475. GO
  2476. if exists (select * from sysobjects where id = object_id(N'[dnt_createorder]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2477. drop procedure [dnt_createorder]
  2478. GO
  2479. CREATE PROCEDURE [dnt_createorder]
  2480. @ordercode char(32),
  2481. @uid int,
  2482. @buyer char(20),
  2483. @paytype tinyint,
  2484. @price decimal(18,2),
  2485. @orderstatus tinyint,
  2486. @credit tinyint,
  2487. @amount int
  2488. AS
  2489. BEGIN
  2490. INSERT INTO [dnt_orders]([ordercode],[uid],[buyer],[paytype],[price],[orderstatus],
  2491. [credit],[amount]) VALUES(@ordercode,@uid,@buyer,@paytype,@price,@orderstatus,@credit,@amount)
  2492. END
  2493. GO
  2494. if exists (select * from sysobjects where id = object_id(N'[dnt_getorderbyordercode]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2495. drop procedure [dnt_getorderbyordercode]
  2496. GO
  2497. CREATE PROCEDURE [dnt_getorderbyordercode]
  2498. @ordercode char(32)
  2499. AS
  2500. BEGIN
  2501. SELECT [orderid],[ordercode],[uid],[buyer],[paytype],[tradeno],[price],[orderstatus],[createdtime],[confirmedtime]
  2502. ,[credit],[amount] FROM [dnt_orders] WHERE [ordercode]=@ordercode
  2503. END
  2504. GO
  2505. if exists (select * from sysobjects where id = object_id(N'[dnt_getorderlist]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2506. drop procedure [dnt_getorderlist]
  2507. GO
  2508. CREATE PROCEDURE [dnt_getorderlist]
  2509. @searchcondition varchar(1000)
  2510. AS
  2511. BEGIN
  2512. DECLARE @script VARCHAR(1000)
  2513. SET @script= 'SELECT TOP 20 [orderid],[ordercode],[uid],[buyer],[paytype],[tradeno],[price],[orderstatus],[createdtime],[confirmedtime]
  2514. ,[credit],[amount] FROM [dnt_orders] '+@searchcondition+' ORDER BY [orderid] DESC'
  2515. EXEC(@script)
  2516. END
  2517. GO
  2518. if exists (select * from sysobjects where id = object_id(N'[dnt_getorderscount]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2519. drop procedure [dnt_getorderscount]
  2520. GO
  2521. CREATE PROCEDURE [dnt_getorderscount]
  2522. @searchcondition varchar(1000)
  2523. AS
  2524. BEGIN
  2525. DECLARE @script VARCHAR(1000)
  2526. SET @script= 'SELECT COUNT([orderid]) FROM [dnt_orders] '+@searchcondition
  2527. EXEC(@script)
  2528. END
  2529. GO
  2530. if exists (select * from sysobjects where id = object_id(N'[dnt_updateorderinfo]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2531. drop procedure [dnt_updateorderinfo]
  2532. GO
  2533. CREATE PROCEDURE [dnt_updateorderinfo]
  2534. @orderid int,
  2535. @tradeno char(32),
  2536. @orderstatus tinyint,
  2537. @confirmedtime smalldatetime
  2538. AS
  2539. BEGIN
  2540.     UPDATE [dnt_orders] SET [tradeno]=@tradeno,[orderstatus]=@orderstatus,[confirmedtime]=@confirmedtime WHERE [orderid]=@orderid
  2541. END
  2542. GO
  2543. if exists (select * from sysobjects where id = object_id(N'[dnt_clearexpirecreditorders]') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
  2544. drop procedure [dnt_clearexpirecreditorders]
  2545. GO
  2546. CREATE PROCEDURE [dnt_clearexpirecreditorders]
  2547. AS
  2548. BEGIN
  2549.    DELETE [dnt_orders] WHERE [orderstatus] < 1 AND [createdtime] < (GETDATE()-15)
  2550. END
  2551. GO
  2552. IF OBJECT_ID('dnt_addparentforumtopics','P') IS NOT NULL
  2553. DROP PROC [dnt_addparentforumtopics]
  2554. GO
  2555. CREATE PROCEDURE [dnt_addparentforumtopics]
  2556. @topics int,
  2557. @fpidlist nvarchar(100)
  2558. AS
  2559.    UPDATE [dnt_forums] SET [topics] = [topics] + @topics WHERE [fid] IN (SELECT [item]FROM [dnt_split](@fpidlist, ',') )
  2560. GO
  2561. IF OBJECT_ID('dnt_updateusercredits','P') IS NOT NULL
  2562. DROP PROC [dnt_updateusercredits]
  2563. GO
  2564. CREATE PROCEDURE [dnt_updateusercredits]
  2565. @uid INT
  2566. AS
  2567. UPDATE [dnt_users] SET [credits] = extcredits1 + posts + digestposts* 5 WHERE [uid] = @uid
  2568. GO
  2569. IF OBJECT_ID('[dnt_gethottopicscount]','P')  IS NOT NULL
  2570. DROP PROC [dnt_gethottopicscount]
  2571. GO
  2572. CREATE PROCEDURE [dnt_gethottopicscount]
  2573. @fid int,
  2574. @timebetween int
  2575. AS
  2576. DECLARE @strSQL varchar(4000)
  2577. DECLARE @strSQLByFid nvarchar(200)
  2578. DECLARE @strSQLByDate nvarchar(200)
  2579. DECLARE @pagetop int
  2580. IF @fid<>0
  2581. SET @strSQLByFid=' AND [fid]='+STR(@fid)+'' 
  2582. IF @timebetween<>0
  2583. SET @strSQLByDate=' AND DATEDIFF(DAY,[postdatetime],GETDATE())<=' + STR(@timebetween)
  2584. SET @strSQL = 'SELECT COUNT(1) FROM [dnt_topics] WHERE 1=1 '+@strSQLByFid+@strSQLByDate
  2585. EXEC(@strSQL)
  2586. GO
  2587. IF OBJECT_ID('[dnt_gethottopicslist]','P')  IS NOT NULL
  2588. DROP PROC [dnt_gethottopicslist]
  2589. GO
  2590. CREATE PROCEDURE [dnt_gethottopicslist]
  2591. @pagesize int,
  2592. @pageindex int, 
  2593. @fid int,
  2594. @showtype varchar(100) , 
  2595. @timebetween int
  2596. AS
  2597. DECLARE @strSQL varchar(4000)
  2598. DECLARE @strSQLByFid nvarchar(200)=''
  2599. DECLARE @strSQLByDate nvarchar(200)=''
  2600. DECLARE @pagetop int
  2601. SET @pagetop = (@pageindex-1)*@pagesize
  2602. IF @fid<>0
  2603. BEGIN
  2604. SET @strSQLByFid='AND t.[fid]='+STR(@fid)
  2605. END
  2606. IF @timebetween<>0
  2607. SET @strSQLByDate=' AND DATEDIFF(DAY,[postdatetime],GETDATE())<=' + STR(@timebetween)
  2608. IF @pageindex=1
  2609. BEGIN
  2610. SET @strSQL = 'SELECT TOP ' + STR(@pagesize) +'  [t].[tid],[t].[fid],[t].[iconid],[t].[typeid],
  2611. [t].[readperm],[t].[price],[t].[poster],[t].[posterid],[t].[title],
  2612. [t].[attention],[t].[postdatetime],[t].[lastpost],[t].[lastpostid],[t].[lastposter],[t].[lastposterid],
  2613. [t].[views],[t].[replies],[t].[displayorder],[t].[highlight],[t].[digest],[t].[rate],[t].[hide],
  2614. [t].[attachment],[t].[moderated],[t].[closed],[t].[magic],[t].[identify],[t].[special],
  2615. f.[name] FROM [dnt_topics] t LEFT JOIN [dnt_forums] f ON t.[fid] = f.[fid] 
  2616. WHERE 1=1 '+@strSQLByFid+@strSQLByDate+' ORDER BY ['+@showtype+'] DESC'
  2617. END
  2618. ELSE
  2619. BEGIN
  2620. SET @strSQL = 'SELECT TOP ' + STR(@pagesize) +' [t].[tid],[t].[fid],[t].[iconid],[t].[typeid],[t].[readperm],[t].[price],
  2621. [t].[poster],[t].[posterid],[t].[title],[t].[attention],[t].[postdatetime],[t].[lastpost],[t].[lastpostid],
  2622. [t].[lastposter],[t].[lastposterid],[t].[views],[t].[replies],[t].[displayorder],[t].[highlight],[t].[digest],
  2623. [t].[rate],[t].[hide],[t].[attachment],[t].[moderated],[t].[closed],[t].[magic],[t].[identify],[t].[special],
  2624. f.[name] FROM [dnt_topics] t LEFT JOIN [dnt_forums] f ON t.[fid] = f.[fid] 
  2625. WHERE 1=1 ' +@strSQLByFid +@strSQLByDate+' AND [tid] NOT IN (SELECT TOP '+ STR(@pagetop)+' [tid] FROM [dnt_topics] 
  2626. WHERE 1=1 ' +@strSQLByFid +@strSQLByDate+' ORDER BY ['+@showtype+'] DESC) ORDER BY ['+@showtype+'] DESC'
  2627. END
  2628. EXEC(@strSQL)
  2629. GO
  2630. IF OBJECT_ID('dnt_resettodayposts','P') IS NOT NULL
  2631. DROP PROC [dnt_resettodayposts]
  2632. GO
  2633. CREATE PROC [dnt_resettodayposts]
  2634. AS
  2635. UPDATE dnt_forums SET todayposts = 0;
  2636. DECLARE @tableid int;
  2637. SELECT @tableid = MAX(id) FROM dnt_tablelist;
  2638. EXEC('
  2639. UPDATE dnt_forums 
  2640. SET todayposts=rightTable.pidcount 
  2641. FROM dnt_forums 
  2642. INNER JOIN (SELECT fid,COUNT(pid) pidcount FROM dnt_posts'+ @tableid +' WHERE DATEDIFF(DAY,postdatetime,GETDATE())=0 GROUP BY fid ) AS rightTable
  2643. ON dnt_forums.fid=rightTable.fid
  2644. WHERE dnt_forums.fid=rightTable.fid
  2645. ')