/CMSWebParts/Sharepoint/SharePointRepeater.ascx.cs

https://bitbucket.org/kudutest2/kenticogit · C# · 1156 lines · 824 code · 153 blank · 179 comment · 45 complexity · 7e2a9e9dbcf0a88ea378ae067007249a MD5 · raw file

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Xml;
  9. using System.Xml.Xsl;
  10. using CMS.CMSHelper;
  11. using CMS.GlobalHelper;
  12. using CMS.PortalControls;
  13. using CMS.SettingsProvider;
  14. using CMS.Controls;
  15. using CMS.SiteProvider;
  16. public partial class CMSWebParts_SharePoint_SharePointRepeater : CMSAbstractWebPart
  17. {
  18. #region "SharePoint data source properties"
  19. /// <summary>
  20. /// Gets or sets value of username.
  21. /// </summary>
  22. public string Username
  23. {
  24. get
  25. {
  26. return ValidationHelper.GetString(this.GetValue("Username"), SPDataSource.Username);
  27. }
  28. set
  29. {
  30. this.SetValue("Username", value);
  31. SPDataSource.Username = value;
  32. }
  33. }
  34. /// <summary>
  35. /// Gets or sets value of password.
  36. /// </summary>
  37. public string Password
  38. {
  39. get
  40. {
  41. return ValidationHelper.GetString(this.GetValue("Password"), SPDataSource.Password);
  42. }
  43. set
  44. {
  45. this.SetValue("Password", value);
  46. SPDataSource.Password = value;
  47. }
  48. }
  49. /// <summary>
  50. /// Gets or sets value of SharePoint list name.
  51. /// </summary>
  52. public string ListName
  53. {
  54. get
  55. {
  56. return ValidationHelper.GetString(this.GetValue("ListName"), SPDataSource.ListName);
  57. }
  58. set
  59. {
  60. this.SetValue("ListName", value);
  61. SPDataSource.ListName = value;
  62. }
  63. }
  64. /// <summary>
  65. /// Gets or sets URL of SharePoint service (Eg. Lists.asmx, Imaging.asmx).
  66. /// </summary>
  67. public string SPServiceURL
  68. {
  69. get
  70. {
  71. return ValidationHelper.GetString(this.GetValue("SPServiceURL"), SPDataSource.SPServiceURL);
  72. }
  73. set
  74. {
  75. this.SetValue("SPServiceURL", value);
  76. SPDataSource.SPServiceURL = value;
  77. }
  78. }
  79. /// <summary>
  80. /// Enables or disables showing CAML on output.
  81. /// </summary>
  82. public bool ShowReturnedCAML
  83. {
  84. get
  85. {
  86. return ValidationHelper.GetBoolean(this.GetValue("ShowReturnedCAML"), SPDataSource.ShowReturnedCAML);
  87. }
  88. set
  89. {
  90. this.SetValue("ShowReturnedCAML", value);
  91. SPDataSource.ShowReturnedCAML = value;
  92. }
  93. }
  94. /// <summary>
  95. /// Gets or set the row limit.
  96. /// </summary>
  97. public int RowLimit
  98. {
  99. get
  100. {
  101. return ValidationHelper.GetInteger(this.GetValue("RowLimit"), SPDataSource.RowLimit);
  102. }
  103. set
  104. {
  105. this.SetValue("RowLimit", value);
  106. SPDataSource.RowLimit = value;
  107. }
  108. }
  109. /// <summary>
  110. /// Gets or sets query to specify which document should be retrieved (like where condition).
  111. /// </summary>
  112. public string Query
  113. {
  114. get
  115. {
  116. return ValidationHelper.GetString(this.GetValue("Query"), SPDataSource.Query);
  117. }
  118. set
  119. {
  120. this.SetValue("Query", value);
  121. SPDataSource.Query = value;
  122. }
  123. }
  124. /// <summary>
  125. /// Gets or sets document fields which should be retrieved.
  126. /// </summary>
  127. public string ViewFields
  128. {
  129. get
  130. {
  131. return ValidationHelper.GetString(this.GetValue("ViewFields"), SPDataSource.ViewFields);
  132. }
  133. set
  134. {
  135. this.SetValue("ViewFields", value);
  136. SPDataSource.ViewFields = value;
  137. }
  138. }
  139. /// <summary>
  140. /// Enables or disables using of classic dataset as data source for ASCX transformation.
  141. /// </summary>
  142. public bool UseClassicDataset
  143. {
  144. get
  145. {
  146. return ValidationHelper.GetBoolean(this.GetValue("UseClassicDataset"), SPDataSource.UseClassicDataset);
  147. }
  148. set
  149. {
  150. this.SetValue("UseClassicDataset", value);
  151. SPDataSource.UseClassicDataset = value;
  152. }
  153. }
  154. /// <summary>
  155. /// Gets or sets fields which should be included in dataset
  156. /// Note: Only if UseClassicDataset is enabled
  157. /// </summary>
  158. public string Fields
  159. {
  160. get
  161. {
  162. return ValidationHelper.GetString(this.GetValue("Fields"), SPDataSource.Fields);
  163. }
  164. set
  165. {
  166. this.SetValue("Fields", value);
  167. SPDataSource.Fields = value;
  168. }
  169. }
  170. /// <summary>
  171. /// Gets or sets the mode which specifies what this webpart exactly do.
  172. /// </summary>
  173. public string Mode
  174. {
  175. get
  176. {
  177. return ValidationHelper.GetString(this.GetValue("Mode"), SPDataSource.Mode);
  178. }
  179. set
  180. {
  181. this.SetValue("Mode", value);
  182. SPDataSource.Mode = value;
  183. }
  184. }
  185. /// <summary>
  186. /// Gets or sets query string key name. Presence of the key in query string indicates,
  187. /// that some item should be selected. The item is determined by query string value.
  188. /// </summary>
  189. public string ItemIDField
  190. {
  191. get
  192. {
  193. return ValidationHelper.GetString(this.GetValue("ItemIDField"), SPDataSource.ItemIDField);
  194. }
  195. set
  196. {
  197. this.SetValue("ItemIDField", value);
  198. SPDataSource.ItemIDField = value;
  199. }
  200. }
  201. /// <summary>
  202. /// Gets or sets the field name which is used for selecting item. Case sensitive!
  203. /// </summary>
  204. public string SelectedItemFieldName
  205. {
  206. get
  207. {
  208. return ValidationHelper.GetString(this.GetValue("SelectedItemFieldName"), SPDataSource.SelectedItemFieldName);
  209. }
  210. set
  211. {
  212. this.SetValue("SelectedItemFieldName", value);
  213. SPDataSource.SelectedItemFieldName = value;
  214. }
  215. }
  216. /// <summary>
  217. /// Gets or sets the type of field for selecting item.
  218. /// </summary>
  219. public string ItemIDFieldType
  220. {
  221. get
  222. {
  223. return ValidationHelper.GetString(this.GetValue("ItemIDFieldType"), SPDataSource.ItemIDFieldType);
  224. }
  225. set
  226. {
  227. this.SetValue("ItemIDFieldType", value);
  228. SPDataSource.ItemIDFieldType = value;
  229. }
  230. }
  231. #endregion
  232. #region "Basic repeater properties"
  233. /// <summary>
  234. /// Gets or sets HideControlForZeroRows property.
  235. /// </summary>
  236. public bool HideControlForZeroRows
  237. {
  238. get
  239. {
  240. return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), BasicRepeater.HideControlForZeroRows);
  241. }
  242. set
  243. {
  244. SetValue("HideControlForZeroRows", value);
  245. BasicRepeater.HideControlForZeroRows = value;
  246. }
  247. }
  248. /// <summary>
  249. /// Gets or sets ZeroRowsText property.
  250. /// </summary>
  251. public string ZeroRowsText
  252. {
  253. get
  254. {
  255. return ValidationHelper.GetString(GetValue("ZeroRowsText"), BasicRepeater.ZeroRowsText);
  256. }
  257. set
  258. {
  259. SetValue("ZeroRowsText", value);
  260. BasicRepeater.ZeroRowsText = value;
  261. }
  262. }
  263. #endregion
  264. #region "Basic repeater template properties"
  265. /// <summary>
  266. /// Gets or sets ItemTemplate property.
  267. /// </summary>
  268. public string TransformationName
  269. {
  270. get
  271. {
  272. return ValidationHelper.GetString(this.GetValue("TransformationName"), "");
  273. }
  274. set
  275. {
  276. this.SetValue("TransformationName", value);
  277. }
  278. }
  279. /// <summary>
  280. /// Gets or sets AlternatingItemTemplate property.
  281. /// </summary>
  282. public string AlternatingItemTransformationName
  283. {
  284. get
  285. {
  286. return ValidationHelper.GetString(this.GetValue("AlternatingItemTransformationName"), "");
  287. }
  288. set
  289. {
  290. this.SetValue("AlternatingItemTransformationName", value);
  291. }
  292. }
  293. /// <summary>
  294. /// Gets or sets FooterTemplate property.
  295. /// </summary>
  296. public string FooterTransformationName
  297. {
  298. get
  299. {
  300. return ValidationHelper.GetString(this.GetValue("FooterTransformationName"), "");
  301. }
  302. set
  303. {
  304. this.SetValue("FooterTransformationName", value);
  305. }
  306. }
  307. /// <summary>
  308. /// Gets or sets HeaderTemplate property.
  309. /// </summary>
  310. public string HeaderTransformationName
  311. {
  312. get
  313. {
  314. return ValidationHelper.GetString(this.GetValue("HeaderTransformationName"), "");
  315. }
  316. set
  317. {
  318. this.SetValue("HeaderTransformationName", value);
  319. }
  320. }
  321. /// <summary>
  322. /// Gets or sets SeparatorTemplate property.
  323. /// </summary>
  324. public string SeparatorTransformationName
  325. {
  326. get
  327. {
  328. return ValidationHelper.GetString(this.GetValue("SeparatorTransformationName"), "");
  329. }
  330. set
  331. {
  332. this.SetValue("SeparatorTransformationName", value);
  333. }
  334. }
  335. /// <summary>
  336. /// Gets or sets SelectedItemStyle property.
  337. /// </summary>
  338. public string SelectedItemTransformationName
  339. {
  340. get
  341. {
  342. return ValidationHelper.GetString(this.GetValue("SelectedItemTransformationName"), "");
  343. }
  344. set
  345. {
  346. this.SetValue("SelectedItemTransformationName", value);
  347. }
  348. }
  349. /// <summary>
  350. /// Gets or sets FooterTemplate for selected item.
  351. /// </summary>
  352. public string SelectedItemFooterTransformationName
  353. {
  354. get
  355. {
  356. return ValidationHelper.GetString(this.GetValue("SelectedItemFooterTransformationName"), "");
  357. }
  358. set
  359. {
  360. this.SetValue("SelectedItemFooterTransformationName", value);
  361. }
  362. }
  363. /// <summary>
  364. /// Gets or sets HeaderTemplate for selected item.
  365. /// </summary>
  366. public string SelectedItemHeaderTransformationName
  367. {
  368. get
  369. {
  370. return ValidationHelper.GetString(this.GetValue("SelectedItemHeaderTransformationName"), "");
  371. }
  372. set
  373. {
  374. this.SetValue("SelectedItemHeaderTransformationName", value);
  375. }
  376. }
  377. #endregion
  378. #region "UniPager properties"
  379. /// <summary>
  380. /// Gets or sets the value that indicates whether pager should be hidden for single page.
  381. /// </summary>
  382. public bool HidePagerForSinglePage
  383. {
  384. get
  385. {
  386. return ValidationHelper.GetBoolean(GetValue("HidePagerForSinglePage"), pagerElem.HidePagerForSinglePage);
  387. }
  388. set
  389. {
  390. SetValue("HidePagerForSinglePage", value);
  391. pagerElem.HidePagerForSinglePage = value;
  392. }
  393. }
  394. /// <summary>
  395. /// Gets or sets the number of records to display on a page.
  396. /// </summary>
  397. public int PageSize
  398. {
  399. get
  400. {
  401. return ValidationHelper.GetInteger(GetValue("PageSize"), pagerElem.PageSize);
  402. }
  403. set
  404. {
  405. SetValue("PageSize", value);
  406. pagerElem.PageSize = value;
  407. }
  408. }
  409. /// <summary>
  410. /// Gets or sets the number of pages displayed for current page range.
  411. /// </summary>
  412. public int GroupSize
  413. {
  414. get
  415. {
  416. return ValidationHelper.GetInteger(GetValue("GroupSize"), pagerElem.GroupSize);
  417. }
  418. set
  419. {
  420. SetValue("GroupSize", value);
  421. pagerElem.GroupSize = value;
  422. }
  423. }
  424. /// <summary>
  425. /// Gets or sets the pager mode ('querystring' or 'postback').
  426. /// </summary>
  427. public string PagingMode
  428. {
  429. get
  430. {
  431. return ValidationHelper.GetString(GetValue("PagingMode"), pagerElem.PagerMode.ToString());
  432. }
  433. set
  434. {
  435. if (value != null)
  436. {
  437. SetValue("PagingMode", value);
  438. switch (value.ToLower())
  439. {
  440. case "postback": pagerElem.PagerMode = UniPagerMode.PostBack; break;
  441. default: pagerElem.PagerMode = UniPagerMode.Querystring; break;
  442. }
  443. }
  444. }
  445. }
  446. /// <summary>
  447. /// Gets or sets the querysting parameter.
  448. /// </summary>
  449. public string QueryStringKey
  450. {
  451. get
  452. {
  453. return ValidationHelper.GetString(GetValue("QueryStringKey"), pagerElem.QueryStringKey);
  454. }
  455. set
  456. {
  457. SetValue("QueryStringKey", value);
  458. pagerElem.QueryStringKey = value;
  459. }
  460. }
  461. /// <summary>
  462. /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view.
  463. /// </summary>
  464. public bool DisplayFirstLastAutomatically
  465. {
  466. get
  467. {
  468. return ValidationHelper.GetBoolean(GetValue("DisplayFirstLastAutomatically"), pagerElem.DisplayFirstLastAutomatically);
  469. }
  470. set
  471. {
  472. SetValue("DisplayFirstLastAutomatically", value);
  473. pagerElem.DisplayFirstLastAutomatically = value;
  474. }
  475. }
  476. /// <summary>
  477. /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view.
  478. /// </summary>
  479. public bool DisplayPreviousNextAutomatically
  480. {
  481. get
  482. {
  483. return ValidationHelper.GetBoolean(GetValue("DisplayPreviousNextAutomatically"), pagerElem.DisplayPreviousNextAutomatically);
  484. }
  485. set
  486. {
  487. SetValue("DisplayPreviousNextAutomatically", value);
  488. pagerElem.DisplayPreviousNextAutomatically = value;
  489. }
  490. }
  491. #endregion
  492. #region "UniPager Template properties"
  493. /// <summary>
  494. /// Gets or sets the pages template.
  495. /// </summary>
  496. public string PagesTemplate
  497. {
  498. get
  499. {
  500. return ValidationHelper.GetString(GetValue("Pages"), "");
  501. }
  502. set
  503. {
  504. SetValue("Pages", value);
  505. }
  506. }
  507. /// <summary>
  508. /// Gets or sets the current page template.
  509. /// </summary>
  510. public string CurrentPageTemplate
  511. {
  512. get
  513. {
  514. return ValidationHelper.GetString(GetValue("CurrentPage"), "");
  515. }
  516. set
  517. {
  518. SetValue("CurrentPage", value);
  519. }
  520. }
  521. /// <summary>
  522. /// Gets or sets the separator template.
  523. /// </summary>
  524. public string SeparatorTemplate
  525. {
  526. get
  527. {
  528. return ValidationHelper.GetString(GetValue("PageSeparator"), "");
  529. }
  530. set
  531. {
  532. SetValue("PageSeparator", value);
  533. }
  534. }
  535. /// <summary>
  536. /// Gets or sets the first page template.
  537. /// </summary>
  538. public string FirstPageTemplate
  539. {
  540. get
  541. {
  542. return ValidationHelper.GetString(GetValue("FirstPage"), "");
  543. }
  544. set
  545. {
  546. SetValue("FirstPage", value);
  547. }
  548. }
  549. /// <summary>
  550. /// Gets or sets the last page template.
  551. /// </summary>
  552. public string LastPageTemplate
  553. {
  554. get
  555. {
  556. return ValidationHelper.GetString(GetValue("LastPage"), "");
  557. }
  558. set
  559. {
  560. SetValue("LastPage", value);
  561. }
  562. }
  563. /// <summary>
  564. /// Gets or sets the previous page template.
  565. /// </summary>
  566. public string PreviousPageTemplate
  567. {
  568. get
  569. {
  570. return ValidationHelper.GetString(GetValue("PreviousPage"), "");
  571. }
  572. set
  573. {
  574. SetValue("PreviousPage", value);
  575. }
  576. }
  577. /// <summary>
  578. /// Gets or sets the next page template.
  579. /// </summary>
  580. public string NextPageTemplate
  581. {
  582. get
  583. {
  584. return ValidationHelper.GetString(GetValue("NextPage"), "");
  585. }
  586. set
  587. {
  588. SetValue("NextPage", value);
  589. }
  590. }
  591. /// <summary>
  592. /// Gets or sets the previous group template.
  593. /// </summary>
  594. public string PreviousGroupTemplate
  595. {
  596. get
  597. {
  598. return ValidationHelper.GetString(GetValue("PreviousGroup"), "");
  599. }
  600. set
  601. {
  602. SetValue("PreviousGroup", value);
  603. }
  604. }
  605. /// <summary>
  606. /// Gets or sets the next group template.
  607. /// </summary>
  608. public string NextGroupTemplate
  609. {
  610. get
  611. {
  612. return ValidationHelper.GetString(GetValue("NextGroup"), "");
  613. }
  614. set
  615. {
  616. SetValue("NextGroup", value);
  617. }
  618. }
  619. /// <summary>
  620. /// Gets or sets the layout template.
  621. /// </summary>
  622. public string LayoutTemplate
  623. {
  624. get
  625. {
  626. return ValidationHelper.GetString(GetValue("PagerLayout"), "");
  627. }
  628. set
  629. {
  630. SetValue("PagerLayout", value);
  631. }
  632. }
  633. /// <summary>
  634. /// Gets or sets the direct page template.
  635. /// </summary>
  636. public string DirectPageTemplate
  637. {
  638. get
  639. {
  640. return ValidationHelper.GetString(GetValue("DirectPage"), "");
  641. }
  642. set
  643. {
  644. SetValue("DirectPage", value);
  645. }
  646. }
  647. #endregion
  648. #region "Overridden properties"
  649. /// <summary>
  650. /// Gets or sets the cache item name.
  651. /// </summary>
  652. public override string CacheItemName
  653. {
  654. get
  655. {
  656. return base.CacheItemName;
  657. }
  658. set
  659. {
  660. base.CacheItemName = value;
  661. SPDataSource.CacheItemName = value;
  662. }
  663. }
  664. /// <summary>
  665. /// Cache dependencies, each cache dependency on a new line.
  666. /// </summary>
  667. public override string CacheDependencies
  668. {
  669. get
  670. {
  671. return ValidationHelper.GetString(base.CacheDependencies, SPDataSource.CacheDependencies);
  672. }
  673. set
  674. {
  675. base.CacheDependencies = value;
  676. SPDataSource.CacheDependencies = value;
  677. }
  678. }
  679. /// <summary>
  680. /// Gets or sets the cache minutes.
  681. /// </summary>
  682. public override int CacheMinutes
  683. {
  684. get
  685. {
  686. return base.CacheMinutes;
  687. }
  688. set
  689. {
  690. base.CacheMinutes = value;
  691. SPDataSource.CacheMinutes = value;
  692. }
  693. }
  694. /// <summary>
  695. /// Indicates if the control should perform the operations.
  696. /// </summary>
  697. public override bool StopProcessing
  698. {
  699. get
  700. {
  701. return base.StopProcessing;
  702. }
  703. set
  704. {
  705. base.StopProcessing = value;
  706. this.SPDataSource.StopProcessing = value;
  707. }
  708. }
  709. #endregion
  710. #region "Methods"
  711. /// <summary>
  712. /// Content loaded event handler.
  713. /// </summary>
  714. public override void OnContentLoaded()
  715. {
  716. base.OnContentLoaded();
  717. SetupControl();
  718. }
  719. /// <summary>
  720. /// Initializes the control properties.
  721. /// </summary>
  722. protected void SetupControl()
  723. {
  724. // Set stop processing to inner controls trough property setter
  725. StopProcessing = StopProcessing;
  726. if (this.StopProcessing)
  727. {
  728. // Do nothing
  729. }
  730. else
  731. {
  732. BasicRepeater.DataBindByDefault = false;
  733. pagerElem.PageControl = BasicRepeater.ID;
  734. if (!String.IsNullOrEmpty(TransformationName))
  735. {
  736. // Set SharePoint datasource properties
  737. SPDataSource.Username = this.Username;
  738. SPDataSource.Password = EncryptionHelper.DecryptData(this.Password);
  739. SPDataSource.ListName = this.ListName;
  740. SPDataSource.SPServiceURL = this.SPServiceURL;
  741. SPDataSource.ShowReturnedCAML = this.ShowReturnedCAML;
  742. SPDataSource.RowLimit = this.RowLimit;
  743. SPDataSource.Query = this.Query;
  744. SPDataSource.ViewFields = this.ViewFields;
  745. SPDataSource.UseClassicDataset = this.UseClassicDataset;
  746. SPDataSource.Fields = this.Fields;
  747. SPDataSource.Mode = this.Mode;
  748. SPDataSource.ItemIDField = this.ItemIDField;
  749. SPDataSource.SelectedItemFieldName = this.SelectedItemFieldName;
  750. SPDataSource.ItemIDFieldType = this.ItemIDFieldType;
  751. SPDataSource.CacheItemName = this.CacheItemName;
  752. SPDataSource.CacheDependencies = this.CacheDependencies;
  753. SPDataSource.CacheMinutes = this.CacheMinutes;
  754. // Classic repeater+dataset OR XSLT transformation
  755. if (this.UseClassicDataset)
  756. {
  757. // Basic repeater properties
  758. BasicRepeater.HideControlForZeroRows = HideControlForZeroRows;
  759. BasicRepeater.ZeroRowsText = ZeroRowsText;
  760. // UniPager properties
  761. pagerElem.PageSize = PageSize;
  762. pagerElem.GroupSize = GroupSize;
  763. pagerElem.QueryStringKey = QueryStringKey;
  764. pagerElem.DisplayFirstLastAutomatically = DisplayFirstLastAutomatically;
  765. pagerElem.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically;
  766. pagerElem.HidePagerForSinglePage = HidePagerForSinglePage;
  767. switch (PagingMode.ToLower())
  768. {
  769. case "postback":
  770. pagerElem.PagerMode = UniPagerMode.PostBack;
  771. break;
  772. default:
  773. pagerElem.PagerMode = UniPagerMode.Querystring;
  774. break;
  775. }
  776. #region "UniPager template properties"
  777. // UniPager template properties
  778. if (!string.IsNullOrEmpty(PagesTemplate))
  779. {
  780. pagerElem.PageNumbersTemplate = CMSDataProperties.LoadTransformation(pagerElem, PagesTemplate, false);
  781. }
  782. if (!string.IsNullOrEmpty(CurrentPageTemplate))
  783. {
  784. pagerElem.CurrentPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, CurrentPageTemplate,
  785. false);
  786. }
  787. if (!string.IsNullOrEmpty(SeparatorTemplate))
  788. {
  789. pagerElem.PageNumbersSeparatorTemplate = CMSDataProperties.LoadTransformation(pagerElem,
  790. SeparatorTemplate,
  791. false);
  792. }
  793. if (!string.IsNullOrEmpty(FirstPageTemplate))
  794. {
  795. pagerElem.FirstPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, FirstPageTemplate,
  796. false);
  797. }
  798. if (!string.IsNullOrEmpty(LastPageTemplate))
  799. {
  800. pagerElem.LastPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, LastPageTemplate, false);
  801. }
  802. if (!string.IsNullOrEmpty(PreviousPageTemplate))
  803. {
  804. pagerElem.PreviousPageTemplate = CMSDataProperties.LoadTransformation(pagerElem,
  805. PreviousPageTemplate, false);
  806. }
  807. if (!string.IsNullOrEmpty(NextPageTemplate))
  808. {
  809. pagerElem.NextPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextPageTemplate, false);
  810. }
  811. if (!string.IsNullOrEmpty(PreviousGroupTemplate))
  812. {
  813. pagerElem.PreviousGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem,
  814. PreviousGroupTemplate, false);
  815. }
  816. if (!string.IsNullOrEmpty(NextGroupTemplate))
  817. {
  818. pagerElem.NextGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextGroupTemplate,
  819. false);
  820. }
  821. if (!String.IsNullOrEmpty(DirectPageTemplate))
  822. {
  823. pagerElem.DirectPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, DirectPageTemplate, false);
  824. }
  825. if (!string.IsNullOrEmpty(LayoutTemplate))
  826. {
  827. pagerElem.LayoutTemplate = CMSDataProperties.LoadTransformation(pagerElem, LayoutTemplate, false);
  828. }
  829. #endregion
  830. }
  831. else
  832. {
  833. plcDataset.Visible = false;
  834. plcXSLT.Visible = true;
  835. }
  836. // Load and bind data
  837. BindData();
  838. }
  839. }
  840. }
  841. /// <summary>
  842. /// OnPreRender override.
  843. /// </summary>
  844. protected override void OnPreRender(EventArgs e)
  845. {
  846. if (!string.IsNullOrEmpty(SPDataSource.ErrorMessage))
  847. {
  848. ShowError(SPDataSource.ErrorMessage);
  849. plcDataset.Visible = false;
  850. plcXSLT.Visible = false;
  851. pagerElem.Visible = false;
  852. }
  853. else
  854. {
  855. //DataSet
  856. if (this.UseClassicDataset)
  857. {
  858. if (HideControlForZeroRows && !BasicRepeater.HasData())
  859. {
  860. this.Visible = false;
  861. }
  862. }
  863. // XSLT
  864. else
  865. {
  866. if (!SPDataSource.HasData)
  867. {
  868. // Hide or display zero rows message
  869. if (HideControlForZeroRows)
  870. {
  871. this.Visible = false;
  872. }
  873. else
  874. {
  875. Label lblZeroRowsText = new Label();
  876. lblZeroRowsText.Text = this.ZeroRowsText;
  877. Controls.Add(lblZeroRowsText);
  878. }
  879. }
  880. }
  881. }
  882. base.OnPreRender(e);
  883. }
  884. /// <summary>
  885. /// Reload data.
  886. /// </summary>
  887. public override void ReloadData()
  888. {
  889. base.ReloadData();
  890. SetupControl();
  891. BasicRepeater.ReloadData(true);
  892. }
  893. /// <summary>
  894. /// Binds data to basic repeater.
  895. /// </summary>
  896. protected void BindData()
  897. {
  898. // Dataset = connects repeater with data source
  899. if (this.UseClassicDataset)
  900. {
  901. BasicRepeater.DataSource = SPDataSource.DataSource;
  902. if (!DataHelper.DataSourceIsEmpty(BasicRepeater.DataSource))
  903. {
  904. // Set proper transformations
  905. LoadTransformations();
  906. BasicRepeater.DataBind();
  907. }
  908. }
  909. // XSLT
  910. else
  911. {
  912. XmlNode caml = SPDataSource.DataSource as XmlNode;
  913. string transName = this.TransformationName;
  914. // If selected item is set
  915. if (SPDataSource.IsSelected && !String.IsNullOrEmpty(this.SelectedItemTransformationName))
  916. {
  917. transName = this.SelectedItemTransformationName;
  918. }
  919. TransformationInfo ti = TransformationInfoProvider.GetTransformation(transName);
  920. if ((caml != null) && (ti != null))
  921. {
  922. // Check it is XSLT transformation
  923. if (ti.TransformationType != TransformationTypeEnum.Xslt)
  924. {
  925. ShowError(string.Format(GetString("sharepoint.XSL"), ti.TransformationFullName));
  926. return;
  927. }
  928. try
  929. {
  930. ltlTransformedOutput.Text = SharePointFunctions.TransformCAML(caml, ti);
  931. }
  932. catch (Exception ex)
  933. {
  934. ShowError(string.Format(GetString("sharepoint.XSLTError") + ResHelper.Colon + " " + ex.Message));
  935. ShowError("XSLT error: " + ex.Message);
  936. }
  937. }
  938. }
  939. }
  940. /// <summary>
  941. /// Load transformations with dependence on datasource type and datasource state.
  942. /// </summary>
  943. protected void LoadTransformations()
  944. {
  945. CMSBaseDataSource dataSource = this.SPDataSource as CMSBaseDataSource;
  946. if ((dataSource != null) && (dataSource.IsSelected) && (!String.IsNullOrEmpty(this.SelectedItemTransformationName)))
  947. {
  948. this.BasicRepeater.ItemTemplate = CMSDataProperties.LoadTransformation(this, this.SelectedItemTransformationName, false);
  949. if (!String.IsNullOrEmpty(this.SelectedItemFooterTransformationName))
  950. {
  951. this.BasicRepeater.FooterTemplate = CMSDataProperties.LoadTransformation(this, this.SelectedItemFooterTransformationName, false);
  952. }
  953. else
  954. {
  955. this.BasicRepeater.FooterTemplate = null;
  956. }
  957. if (!String.IsNullOrEmpty(this.SelectedItemHeaderTransformationName))
  958. {
  959. this.BasicRepeater.HeaderTemplate = CMSDataProperties.LoadTransformation(this, this.SelectedItemHeaderTransformationName, false);
  960. }
  961. else
  962. {
  963. this.BasicRepeater.HeaderTemplate = null;
  964. }
  965. }
  966. else
  967. {
  968. // Apply transformations if they exist
  969. if (!String.IsNullOrEmpty(this.TransformationName))
  970. {
  971. this.BasicRepeater.ItemTemplate = CMSDataProperties.LoadTransformation(this, this.TransformationName, false);
  972. }
  973. if (!String.IsNullOrEmpty(this.AlternatingItemTransformationName))
  974. {
  975. this.BasicRepeater.AlternatingItemTemplate = CMSDataProperties.LoadTransformation(this, this.AlternatingItemTransformationName, false);
  976. }
  977. if (!String.IsNullOrEmpty(this.FooterTransformationName))
  978. {
  979. this.BasicRepeater.FooterTemplate = CMSDataProperties.LoadTransformation(this, this.FooterTransformationName, false);
  980. }
  981. if (!String.IsNullOrEmpty(this.HeaderTransformationName))
  982. {
  983. this.BasicRepeater.HeaderTemplate = CMSDataProperties.LoadTransformation(this, this.HeaderTransformationName, false);
  984. }
  985. if (!String.IsNullOrEmpty(this.SeparatorTransformationName))
  986. {
  987. this.BasicRepeater.SeparatorTemplate = CMSDataProperties.LoadTransformation(this, this.SeparatorTransformationName, false);
  988. }
  989. }
  990. }
  991. /// <summary>
  992. /// Shows error with message.
  993. /// </summary>
  994. /// <param name="message">Message</param>
  995. private void ShowError(string message)
  996. {
  997. Label lblError = new Label();
  998. lblError.Text = message;
  999. lblError.CssClass = "ErrorLabel";
  1000. Controls.Add(lblError);
  1001. }
  1002. #endregion
  1003. }