PageRenderTime 73ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/Default.aspx.cs

https://bitbucket.org/Offroadcode/usitebuilderimporter
C# | 735 lines | 448 code | 107 blank | 180 comment | 27 complexity | 9268ee0b60d9760a25ff9781437d7d35 MD5 | raw file
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="Default.aspx.cs" company="">
  3. //
  4. // </copyright>
  5. // <summary>
  6. // Defines the _Default type.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using System;
  10. using System.Configuration;
  11. using System.Data;
  12. using System.Data.SqlClient;
  13. using System.IO;
  14. using System.Text;
  15. using System.Web.UI;
  16. using Microsoft.ApplicationBlocks.Data;
  17. /// <summary>
  18. /// Default class
  19. /// </summary>
  20. public partial class Default : Page
  21. {
  22. #region Public Methods
  23. /// <summary>
  24. /// Get Templates Default Doc Type
  25. /// </summary>
  26. /// <param name="nodeid">
  27. /// The nodeid.
  28. /// </param>
  29. /// <returns>
  30. /// Node ID
  31. /// </returns>
  32. public static string GetTemplatesDefaultDocType(string nodeid)
  33. {
  34. string rtnText = string.Empty;
  35. string strSql =
  36. "SELECT cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsContentType.alias FROM cmsDocumentType INNER JOIN cmsContentType ON cmsDocumentType.contentTypeNodeId = cmsContentType.nodeId where isDefault=1 and templateNodeId="
  37. + nodeid;
  38. SqlDataReader dr = SqlHelper.ExecuteReader(
  39. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  40. while (dr.Read())
  41. {
  42. rtnText = ": Vega.USiteBuilder.TemplateBase<uSiteBuilderImport.Web.DocumentTypes." + dr["alias"] + ">";
  43. }
  44. dr.Close();
  45. return rtnText != string.Empty ? rtnText : ": Vega.USiteBuilder.TemplateBase";
  46. // return ": System.Web.UI.MasterPage";
  47. // return string.Empty;
  48. }
  49. /// <summary>
  50. /// The create child doc type.
  51. /// </summary>
  52. /// <param name="nodeid">
  53. /// The nodeid.
  54. /// </param>
  55. /// <param name="alias">
  56. /// The alias.
  57. /// </param>
  58. /// <param name="path">
  59. /// The path.
  60. /// </param>
  61. public void CreateChildDocType(string nodeid, string alias, string path)
  62. {
  63. // string strSQL = "SELECT [pk],[nodeId],[alias],[icon],[thumbnail],[description],[masterContentType] FROM [cmsContentType] where masterContentType=" + nodeid + " order by Alias";
  64. string strSql =
  65. "SELECT cmsContentType.pk, cmsContentType.nodeId, cmsContentType.alias, cmsContentType.icon, cmsContentType.thumbnail, cmsContentType.description, "
  66. + "cmsContentType.masterContentType, umbracoNode.text " + "FROM cmsContentType INNER JOIN "
  67. + "umbracoNode ON cmsContentType.nodeId = umbracoNode.id " + "WHERE cmsContentType.masterContentType = "
  68. + nodeid + " ORDER BY alias";
  69. SqlDataReader dr = SqlHelper.ExecuteReader(
  70. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  71. while (dr.Read())
  72. {
  73. // Start file
  74. var sb = new StringBuilder();
  75. this.Response.Write("Create Doc Type for child " + dr["alias"] + " (" + dr["nodeid"] + ")<br/>");
  76. sb.AppendLine("using System;");
  77. sb.AppendLine("using System.Collections.Generic;");
  78. sb.AppendLine("using System.Linq;");
  79. sb.AppendLine("using System.Web;");
  80. sb.AppendLine("using Vega.USiteBuilder;");
  81. sb.AppendLine("namespace uSiteBuilderImport.Web.DocumentTypes");
  82. sb.AppendLine("{");
  83. sb.AppendLine();
  84. sb.Append(
  85. "[DocumentType(Name=\"" + dr["text"] + "\",IconUrl=\"" + dr["icon"] + "\""
  86. + this.GetAllowedTemplates(dr["nodeid"].ToString()));
  87. sb.Append(GetAllowedContentType(dr["nodeid"].ToString()));
  88. sb.Append(")]");
  89. sb.AppendLine();
  90. sb.AppendLine("public class " + dr["alias"] + " : uSiteBuilderImport.Web.DocumentTypes." + alias);
  91. sb.AppendLine("{");
  92. sb.AppendLine(this.CreateProperties(dr["nodeid"].ToString()));
  93. sb.AppendLine("}");
  94. sb.AppendLine("}");
  95. if (!Directory.Exists(this.Server.MapPath("DocTypes/")))
  96. {
  97. Directory.CreateDirectory(this.Server.MapPath("DocumentTypes/"));
  98. }
  99. using (var writer = new StreamWriter(path + dr["alias"] + ".cs"))
  100. {
  101. writer.Write(sb.ToString());
  102. }
  103. // Make recursive call
  104. this.CreateChildDocType(dr["nodeid"].ToString(), dr["alias"].ToString(), path);
  105. }
  106. dr.Close();
  107. }
  108. /// <summary>
  109. /// Create Child Master Pages
  110. /// </summary>
  111. /// <param name="nodeid">
  112. /// The nodeid.
  113. /// </param>
  114. /// <param name="parentAlias">
  115. /// The parent alias.
  116. /// </param>
  117. public void CreateChildMasterPages(string nodeid, string parentAlias)
  118. {
  119. string strSql = "SELECT pk, nodeId, master, alias, design FROM cmsTemplate WHERE master =" + nodeid;
  120. SqlDataReader dr = SqlHelper.ExecuteReader(
  121. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  122. while (dr.Read())
  123. {
  124. string alias = dr["alias"].ToString().Replace(" ", string.Empty);
  125. this.Response.Write("Creating Child MasterPage: " + alias + " (" + dr["nodeId"] + ")</br>");
  126. var sb = new StringBuilder();
  127. // Create Master Page
  128. sb.AppendLine(
  129. "<%@ Master Language=\"C#\" MasterPageFile=\"~/MasterPages/" + parentAlias
  130. + ".master\" AutoEventWireup=\"true\" CodeBehind=\"" + alias
  131. + ".master.cs\" Inherits=\"uSiteBuilderImport.Web.MasterPages." + alias + "\" %>");
  132. // Get Markup
  133. sb.AppendLine(GetMarkUp(dr["nodeid"].ToString()));
  134. using (var writer = new StreamWriter(this.Server.MapPath("MasterPages/" + alias + ".Master")))
  135. {
  136. writer.Write(sb.ToString());
  137. }
  138. sb.Length = 0;
  139. // Create Code behind file
  140. sb.AppendLine("using System;");
  141. sb.AppendLine("using System.Collections.Generic;");
  142. sb.AppendLine("using System.Linq;");
  143. sb.AppendLine("using System.Web;");
  144. sb.AppendLine("using System.Web.UI;");
  145. sb.AppendLine("using System.Web.UI.WebControls;");
  146. sb.AppendLine("namespace uSiteBuilderImport.Web.MasterPages");
  147. sb.AppendLine("{");
  148. sb.AppendLine("public partial class " + alias + GetTemplatesDefaultDocType(dr["nodeId"].ToString()));
  149. sb.AppendLine("{");
  150. sb.AppendLine(" protected void Page_Load(object sender, EventArgs e)");
  151. sb.AppendLine("{");
  152. sb.AppendLine("}");
  153. sb.AppendLine("}");
  154. sb.AppendLine("}");
  155. string path = this.Server.MapPath("MasterPages/");
  156. using (var writer = new StreamWriter(path + alias + ".Master.cs"))
  157. {
  158. writer.Write(sb.ToString());
  159. }
  160. this.CreateChildMasterPages(dr["nodeId"].ToString(), alias);
  161. // Response.Write(getTemplatesDefaultDocType(dr["nodeId"].ToString()));
  162. }
  163. dr.Close();
  164. }
  165. /// <summary>
  166. /// Create Master Pages
  167. /// </summary>
  168. public void CreateMasterPages()
  169. {
  170. const string StrSQL =
  171. "SELECT pk, nodeId, master, alias, design FROM cmsTemplate WHERE (master IS NULL) order by alias";
  172. SqlDataReader dr = SqlHelper.ExecuteReader(
  173. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, StrSQL);
  174. while (dr.Read())
  175. {
  176. // string alias = dr["alias"].ToString().Replace(" ", "");
  177. string alias = dr["alias"].ToString();
  178. this.Response.Write(alias + " (" + dr["nodeId"] + ")</br>");
  179. var sb = new StringBuilder();
  180. // Create Master Page
  181. sb.AppendLine(
  182. "<%@ Master Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"" + alias
  183. + ".master.cs\" Inherits=\"uSiteBuilderImport.Web.MasterPages." + dr["alias"] + "\" %>");
  184. // Get Markup
  185. sb.AppendLine(GetMarkUp(dr["nodeid"].ToString()));
  186. // Clean MarkUp
  187. if (!Directory.Exists(this.Server.MapPath("MasterPages/")))
  188. {
  189. Directory.CreateDirectory(this.Server.MapPath("MasterPages/"));
  190. }
  191. using (var writer = new StreamWriter(this.Server.MapPath("MasterPages/") + alias + ".Master"))
  192. {
  193. writer.Write(sb.ToString());
  194. }
  195. sb.Length = 0;
  196. // Create Code behind file
  197. sb.AppendLine("using System;");
  198. sb.AppendLine("using System.Collections.Generic;");
  199. sb.AppendLine("using System.Linq;");
  200. sb.AppendLine("using System.Web;");
  201. sb.AppendLine("using System.Web.UI;");
  202. sb.AppendLine("using System.Web.UI.WebControls;");
  203. sb.AppendLine("namespace uSiteBuilderImport.Web.MasterPages");
  204. sb.AppendLine("{");
  205. sb.AppendLine("public partial class " + alias + GetTemplatesDefaultDocType(dr["nodeId"].ToString()));
  206. sb.AppendLine("{");
  207. sb.AppendLine(" protected void Page_Load(object sender, EventArgs e)");
  208. sb.AppendLine("{");
  209. sb.AppendLine("}");
  210. sb.AppendLine("}");
  211. sb.AppendLine("}");
  212. using (var writer = new StreamWriter(this.Server.MapPath("MasterPages/" + alias + ".Master.cs")))
  213. {
  214. writer.Write(sb.ToString());
  215. }
  216. this.CreateChildMasterPages(dr["nodeId"].ToString(), alias);
  217. }
  218. dr.Close();
  219. }
  220. #endregion
  221. #region Methods
  222. /// <summary>
  223. /// Page Load event
  224. /// </summary>
  225. /// <param name="sender">
  226. /// The sender.
  227. /// </param>
  228. /// <param name="e">
  229. /// The event arguments
  230. /// </param>
  231. protected void Page_Load(object sender, EventArgs e)
  232. {
  233. // Clear and create Directories
  234. string path = this.Server.MapPath("MasterPages/");
  235. if (Directory.Exists(path))
  236. {
  237. Directory.Delete(path, true);
  238. }
  239. Directory.CreateDirectory(path);
  240. path = this.Server.MapPath("DocumentTypes");
  241. if (Directory.Exists(path))
  242. {
  243. Directory.Delete(path, true);
  244. }
  245. Directory.CreateDirectory(path);
  246. this.Response.Write("<br/>-------------------------------------------------------------<br/>");
  247. this.Response.Write("Creating MasterPages");
  248. this.Response.Write("<br/>-------------------------------------------------------------<br/><br/>");
  249. this.CreateMasterPages();
  250. this.Response.Write("<br/>-------------------------------------------------------------<br/>");
  251. this.Response.Write("Creating DocTypes");
  252. this.Response.Write("<br/>-------------------------------------------------------------<br/><br/>");
  253. this.CreateDocTypes();
  254. this.Response.Write("<br/>-------------------------------------------------------------<br/>");
  255. this.Response.Write("End");
  256. this.Response.Write("<br/>-------------------------------------------------------------<br/><br/>");
  257. }
  258. /// <summary>
  259. /// The get allowed content type.
  260. /// </summary>
  261. /// <param name="nodeid">
  262. /// The nodeid.
  263. /// </param>
  264. /// <returns>
  265. /// The allowed content type.
  266. /// </returns>
  267. private static string GetAllowedContentType(string nodeid)
  268. {
  269. // string strSQL = "SELECT cmsContentTypeAllowedContentType.Id, cmsContentTypeAllowedContentType.AllowedId, umbracoNode.text FROM cmsContentTypeAllowedContentType INNER JOIN umbracoNode ON cmsContentTypeAllowedContentType.AllowedId = umbracoNode.id where cmsContentTypeAllowedContentType.id =" + nodeid;
  270. string strSql =
  271. "SELECT cmsContentTypeAllowedContentType.Id, cmsContentTypeAllowedContentType.AllowedId, cmsContentType.alias "
  272. + "FROM cmsContentTypeAllowedContentType INNER JOIN "
  273. +
  274. "cmsContentType ON cmsContentTypeAllowedContentType.AllowedId = cmsContentType.nodeId where cmsContentTypeAllowedContentType.id ="
  275. + nodeid;
  276. SqlDataReader dr = SqlHelper.ExecuteReader(
  277. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  278. var sb = new StringBuilder();
  279. while (dr.Read())
  280. {
  281. sb.Append("typeof(" + dr["alias"] + "),");
  282. // Response.Write("Here's an allowed type " + dr["text"].ToString() + "<br/>");
  283. }
  284. dr.Close();
  285. if (sb.ToString() != string.Empty)
  286. {
  287. return ",AllowedChildNodeTypes = new Type[] {" + sb.ToString().Remove(sb.Length - 1, 1) + "}";
  288. }
  289. return string.Empty;
  290. }
  291. /*
  292. /// <summary>
  293. /// The get allowed templates old code.
  294. /// </summary>
  295. /// <param name="nodeid">
  296. /// The nodeid.
  297. /// </param>
  298. /// <returns>
  299. /// The allowed templates old code.
  300. /// </returns>
  301. private string GetAllowedTemplatesOldCode(string nodeid)
  302. {
  303. var strSql =
  304. "SELECT cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias "
  305. + "FROM cmsDocumentType INNER JOIN "
  306. + "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId "
  307. + "WHERE (cmsDocumentType.IsDefault = 0) AND cmsDocumentType.contentTypeNodeId =" + nodeid;
  308. var dr = SqlHelper.ExecuteReader(
  309. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  310. var sb = new StringBuilder();
  311. while (dr.Read())
  312. {
  313. sb.Append("\"" + dr["alias"] + "\",");
  314. }
  315. dr.Close();
  316. if (sb.ToString() != string.Empty)
  317. {
  318. return ", AllowedTemplates = new string[] {" + sb.ToString().Remove(sb.Length - 1, 1) + "}";
  319. }
  320. else
  321. {
  322. return string.Empty;
  323. }
  324. }
  325. */
  326. /// <summary>
  327. /// The get data type.
  328. /// </summary>
  329. /// <param name="dataTypeId">
  330. /// The data type id.
  331. /// </param>
  332. /// <returns>
  333. /// The data type.
  334. /// </returns>
  335. private static string GetDataType(int dataTypeId)
  336. {
  337. var dt = (Enums.UmbracoPropertyType)dataTypeId;
  338. if (dt.ToString() != dataTypeId.ToString())
  339. {
  340. return "UmbracoPropertyType." + dt;
  341. }
  342. // Custom DataType
  343. string strSql = "SELECT [text] FROM [umbracoNode] where id=" + dataTypeId;
  344. SqlDataReader dr = SqlHelper.ExecuteReader(
  345. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  346. string rtnText = string.Empty;
  347. while (dr.Read())
  348. {
  349. rtnText = dr["text"].ToString();
  350. }
  351. dr.Close();
  352. return "UmbracoPropertyType.Other, OtherTypeName=\"" + rtnText + "\"";
  353. }
  354. /// <summary>
  355. /// The get default template doc type.
  356. /// </summary>
  357. /// <param name="nodeid">
  358. /// The nodeid.
  359. /// </param>
  360. /// <returns>
  361. /// The default template doc type.
  362. /// </returns>
  363. private static string GetDefaultTemplateDocType(string nodeid)
  364. {
  365. // At the moment this is switched off as default Doc Types is set via the allowed templates.
  366. // string strSQL = "SELECT cmsContentType.nodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsContentType.alias " +
  367. // "FROM cmsDocumentType INNER JOIN " +
  368. // "cmsContentType ON cmsDocumentType.contentTypeNodeId = cmsContentType.nodeId " +
  369. // "WHERE (cmsDocumentType.IsDefault = 1) and nodeid=" + nodeid;
  370. // string strSQL = "SELECT cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias " +
  371. // "FROM cmsDocumentType INNER JOIN " +
  372. // "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId " +
  373. // "WHERE (cmsDocumentType.IsDefault = 1) and contentTypeNodeID=" + nodeid;
  374. string strSql =
  375. "SELECT cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsContentType.alias "
  376. + "FROM cmsDocumentType INNER JOIN "
  377. + "cmsContentType ON cmsDocumentType.contentTypeNodeId = cmsContentType.nodeId "
  378. + "WHERE (cmsDocumentType.IsDefault = 1) and contentTypeNodeId=" + nodeid;
  379. SqlDataReader dr = SqlHelper.ExecuteReader(
  380. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  381. var sb = new StringBuilder();
  382. while (dr.Read())
  383. {
  384. sb.Append(dr["alias"].ToString());
  385. }
  386. dr.Close();
  387. return string.Empty;
  388. }
  389. /// <summary>
  390. /// The get mark up.
  391. /// </summary>
  392. /// <param name="nodeid">
  393. /// The nodeid.
  394. /// </param>
  395. /// <returns>
  396. /// The get mark up.
  397. /// </returns>
  398. private static string GetMarkUp(string nodeid)
  399. {
  400. string rtnText = string.Empty;
  401. string strSql = "SELECT pk, nodeId, master, alias, design FROM cmsTemplate where nodeid=" + nodeid;
  402. SqlDataReader dr = SqlHelper.ExecuteReader(
  403. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  404. while (dr.Read())
  405. {
  406. rtnText = dr["design"].ToString();
  407. }
  408. dr.Close();
  409. int startPos = rtnText.IndexOf(">");
  410. return rtnText.Substring(startPos + 1);
  411. }
  412. /// <summary>
  413. /// The get tab.
  414. /// </summary>
  415. /// <param name="tabid">
  416. /// The tabid.
  417. /// </param>
  418. /// <returns>
  419. /// The tab.
  420. /// </returns>
  421. private static string GetTab(string tabid)
  422. {
  423. if (tabid != string.Empty)
  424. {
  425. string strSql = "SELECT [id],[text],[sortorder] FROM [cmsTab] where id=" + tabid;
  426. SqlDataReader dr = SqlHelper.ExecuteReader(
  427. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  428. string tab = string.Empty;
  429. while (dr.Read())
  430. {
  431. tab = dr["text"].ToString();
  432. }
  433. dr.Close();
  434. if (tab != string.Empty)
  435. {
  436. return ", Tab=\"" + tab + "\"";
  437. }
  438. return string.Empty;
  439. }
  440. return string.Empty;
  441. }
  442. /// <summary>
  443. /// The get validation.
  444. /// </summary>
  445. /// <param name="isMandatory">
  446. /// The is mandatory.
  447. /// </param>
  448. /// <param name="rgx">
  449. /// The rgx.
  450. /// </param>
  451. /// <returns>
  452. /// The validation.
  453. /// </returns>
  454. private static string GetValidation(string isMandatory, string rgx)
  455. {
  456. var sb = new StringBuilder();
  457. sb.Append(isMandatory == "True" ? ",Mandatory=true" : ",Mandatory=false");
  458. if (rgx != string.Empty)
  459. {
  460. sb.Append(",ValidationRegExp=\"" + rgx.Replace("\\", "\\\\") + "\"");
  461. }
  462. return sb.ToString();
  463. }
  464. /// <summary>
  465. /// The create doc types.
  466. /// </summary>
  467. private void CreateDocTypes()
  468. {
  469. string path = this.Server.MapPath("DocumentTypes");
  470. path = path + "\\";
  471. const string StrSql =
  472. "SELECT cmsContentType.pk, cmsContentType.nodeId, cmsContentType.alias, cmsContentType.icon, cmsContentType.thumbnail, cmsContentType.description, "
  473. + "cmsContentType.masterContentType, umbracoNode.text FROM cmsContentType INNER JOIN "
  474. + "umbracoNode ON cmsContentType.nodeId = umbracoNode.id "
  475. + "WHERE (cmsContentType.masterContentType = 0) " + "ORDER BY cmsContentType.alias";
  476. SqlDataReader dr = SqlHelper.ExecuteReader(
  477. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, StrSql);
  478. while (dr.Read())
  479. {
  480. var sb = new StringBuilder();
  481. this.Response.Write("Create Doc Type for " + dr["text"] + " (" + dr["nodeid"] + ")<br/>");
  482. sb.AppendLine("using System;");
  483. sb.AppendLine("using System.Collections.Generic;");
  484. sb.AppendLine("using System.Linq;");
  485. sb.AppendLine("using System.Web;");
  486. sb.AppendLine("using Vega.USiteBuilder;");
  487. sb.AppendLine("namespace uSiteBuilderImport.Web.DocumentTypes");
  488. sb.AppendLine("{");
  489. // AllowedTemplates = new string[] { "Property" }
  490. sb.Append(
  491. "[DocumentType(Name=\"" + dr["text"] + "\",IconUrl=\"" + dr["icon"] + "\""
  492. + this.GetAllowedTemplates(dr["nodeid"].ToString()));
  493. sb.Append(GetAllowedContentType(dr["nodeid"].ToString()));
  494. sb.AppendLine( ")]");
  495. sb.AppendLine("public class " + dr["alias"] + " : Vega.USiteBuilder.DocumentTypeBase");
  496. sb.AppendLine("{");
  497. sb.AppendLine(this.CreateProperties(dr["nodeid"].ToString()));
  498. // Response.Write("Check if any child docs types of " + dr["nodeid"] + "<br/>");
  499. this.CreateChildDocType(dr["nodeid"].ToString(), dr["alias"].ToString(), path);
  500. sb.AppendLine("}");
  501. sb.AppendLine("}");
  502. using (var writer = new StreamWriter(path + dr["alias"] + ".cs"))
  503. {
  504. writer.Write(sb.ToString());
  505. }
  506. }
  507. dr.Close();
  508. }
  509. /// <summary>
  510. /// The create properties.
  511. /// </summary>
  512. /// <param name="nodeid">
  513. /// The nodeid.
  514. /// </param>
  515. /// <returns>
  516. /// The create properties.
  517. /// </returns>
  518. private string CreateProperties(string nodeid)
  519. {
  520. string strSql =
  521. "SELECT [id],[dataTypeId],[contentTypeId],[tabId],[Alias],[Name],[helpText],[sortOrder],[mandatory],[validationRegExp],[Description] FROM [cmsPropertyType] where contentTypeId="
  522. + nodeid + " order by sortOrder";
  523. var sb = new StringBuilder();
  524. SqlDataReader dr = SqlHelper.ExecuteReader(
  525. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  526. while (dr.Read())
  527. {
  528. sb.AppendLine(
  529. "[DocumentTypeProperty(" + GetDataType(Convert.ToInt32(dr["dataTypeId"])) + ",Name=\"" + dr["Name"]
  530. + "\",Description=\""
  531. + dr["Description"].ToString().Replace(Environment.NewLine, string.Empty).Replace("\"", "\\\"") + "\""
  532. + GetTab(dr["tabId"].ToString())
  533. + GetValidation(dr["mandatory"].ToString(), dr["validationRegExp"].ToString()) + ")]");
  534. sb.AppendLine("public string " + dr["alias"] + " { get; set; }");
  535. // Response.Write("Alias: " + dr["alias"] + " Name: " + dr["name"] + " Description: " + dr["Description"] + " Tab: " + getTab(dr["tabId"].ToString()) + " DataType: " + getDataType(Convert.ToInt32(dr["dataTypeId"])) + "<br/>");
  536. }
  537. dr.Close();
  538. return sb.ToString();
  539. }
  540. /// <summary>
  541. /// The get allowed templates.
  542. /// </summary>
  543. /// <param name="nodeid">
  544. /// The nodeid.
  545. /// </param>
  546. /// <returns>
  547. /// The allowed templates.
  548. /// </returns>
  549. private string GetAllowedTemplates(string nodeid)
  550. {
  551. // This code is correct from when we were only getting non default Templates, however now we want them all and we'll deal with the default one later
  552. // string strSQL = "SELECT cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias " +
  553. // "FROM cmsDocumentType INNER JOIN " +
  554. // "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId " +
  555. // "WHERE (cmsDocumentType.IsDefault = 0) AND cmsDocumentType.contentTypeNodeId =" + nodeid;
  556. string strSql =
  557. "SELECT cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias "
  558. + "FROM cmsDocumentType INNER JOIN "
  559. + "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId "
  560. + "WHERE cmsDocumentType.contentTypeNodeId =" + nodeid + " order by isDefault desc";
  561. SqlDataReader dr = SqlHelper.ExecuteReader(
  562. ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
  563. var sb = new StringBuilder();
  564. // int x = 0;
  565. while (dr.Read())
  566. {
  567. // x++;
  568. // if (x == 1)
  569. // {
  570. // //Check if this is default if so we mark it as such in the string and deal with it later
  571. // if (dr["isDefault"].ToString() == "True")
  572. // { sb.Append("\"xxxxxxxxxx" + dr["templateNodeId3"].ToString() + "\","); }
  573. // else { sb.Append("\"" + dr["alias"].ToString() + "\","); }
  574. // }
  575. // else
  576. // {
  577. sb.Append("\"" + dr["alias"] + "\",");
  578. // }
  579. }
  580. dr.Close();
  581. if (sb.ToString() != string.Empty)
  582. {
  583. // If there are more than one templates we have to specify default template
  584. return ", AllowedTemplates = new string[] {" + sb.ToString().Remove(sb.Length - 1, 1) + "}"
  585. + GetDefaultTemplateDocType(nodeid);
  586. // return string.Empty;
  587. }
  588. return string.Empty;
  589. }
  590. #endregion
  591. }