/pigeoncms/Modules/PigeonCms.PlaceholdersAdmin/views/Default.ascx.cs

http://pigeoncms.googlecode.com/ · C# · 181 lines · 156 code · 23 blank · 2 comment · 17 complexity · 287d9b4925f88ac15fb33477c7153ed9 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.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Web.Caching;
  12. using System.Collections.Generic;
  13. using PigeonCms;
  14. using PigeonCms.Core.Helpers;
  15. public partial class Controls_Default : PigeonCms.BaseModuleControl
  16. {
  17. protected string Name
  18. {
  19. get { return base.GetStringParam("Name", "", "Name"); }
  20. }
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. LblOk.Text = "";
  24. LblErr.Text = "";
  25. if (this.BaseModule.DirectEditMode)
  26. {
  27. if (string.IsNullOrEmpty(this.Name))
  28. throw new ArgumentException();
  29. if (string.IsNullOrEmpty(
  30. new PlaceholdersManager().GetByName(this.Name).Name))
  31. throw new ArgumentException();
  32. BtnNew.Visible = false;
  33. //BtnSave.OnClientClick = "closePopup();";
  34. BtnCancel.OnClientClick = "closePopup();";
  35. edit(this.Name);
  36. }
  37. }
  38. protected void ObjDs1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
  39. {
  40. PlaceholderFilter filter = new PlaceholderFilter();
  41. filter.Visible = Utility.TristateBool.NotSet;
  42. if (!string.IsNullOrEmpty(this.Name))
  43. filter.Name = this.Name;
  44. e.InputParameters["filter"] = filter;
  45. }
  46. protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
  47. {
  48. if (e.CommandName == "Select")
  49. {
  50. edit(e.CommandArgument.ToString());
  51. }
  52. if (e.CommandName == "DeleteRow")
  53. {
  54. delete(e.CommandArgument.ToString());
  55. }
  56. }
  57. protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
  58. {
  59. if (e.Row.RowType == DataControlRowType.Header)
  60. Utility.AddGlyph(Grid1, e.Row);
  61. }
  62. protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
  63. {
  64. if (this.BaseModule.DirectEditMode)
  65. {
  66. //list view not allowed (in case of js hacking)
  67. if (MultiView1.ActiveViewIndex == 0)
  68. MultiView1.ActiveViewIndex = 1;
  69. }
  70. }
  71. protected void BtnSave_Click(object sender, EventArgs e)
  72. {
  73. LblErr.Text = "";
  74. LblOk.Text = "";
  75. try
  76. {
  77. Placeholder p1 = new Placeholder();
  78. if (TxtId.Text == string.Empty)
  79. {
  80. form2obj(p1);
  81. p1 = new PlaceholdersManager().Insert(p1);
  82. }
  83. else
  84. {
  85. p1 = new PlaceholdersManager().GetByName(TxtName.Text);//precarico i campi esistenti e nn gestiti dal form
  86. form2obj(p1);
  87. new PlaceholdersManager().Update(p1);
  88. }
  89. new CacheManager<Placeholder>("PigeonCms.Placeholder").Remove(p1.Name);
  90. Grid1.DataBind();
  91. LblOk.Text = Utility.GetLabel("RECORD_SAVED_MSG");
  92. MultiView1.ActiveViewIndex = 0;
  93. }
  94. catch (Exception e1)
  95. {
  96. LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
  97. }
  98. finally
  99. {
  100. }
  101. }
  102. protected void BtnCancel_Click(object sender, EventArgs e)
  103. {
  104. MultiView1.ActiveViewIndex = 0;
  105. }
  106. protected void BtnNew_Click(object sender, EventArgs e)
  107. {
  108. edit("");
  109. }
  110. #region private methods
  111. private void form2obj(Placeholder obj1)
  112. {
  113. obj1.Name = TxtName.Text;
  114. obj1.Visible = ChkVisibile.Checked;
  115. obj1.Content = TxtContent.Text;
  116. }
  117. private void obj2form(Placeholder obj1)
  118. {
  119. TxtName.Text = obj1.Name;
  120. ChkVisibile.Checked = obj1.Visible;
  121. TxtContent.Text = obj1.Content;
  122. }
  123. private void edit(string name)
  124. {
  125. LblOk.Text = "";
  126. LblErr.Text = "";
  127. TxtName.Text = name;
  128. TxtName.Enabled = true;
  129. ChkVisibile.Checked = true;
  130. TxtId.Text = "";
  131. TxtContent.Text = "";
  132. if (name != "")
  133. {
  134. TxtId.Text = "1";
  135. TxtName.Enabled = false;
  136. Placeholder currObj = new Placeholder();
  137. currObj = new PlaceholdersManager().GetByName(name);
  138. obj2form(currObj);
  139. }
  140. MultiView1.ActiveViewIndex = 1;
  141. }
  142. private void delete(string name)
  143. {
  144. LblOk.Text = "";
  145. LblErr.Text = "";
  146. try
  147. {
  148. new PlaceholdersManager().Delete(name);
  149. new CacheManager<Placeholder>("PigeonCms.Placeholder").Remove(name);
  150. }
  151. catch (Exception e)
  152. {
  153. LblErr.Text = e.Message;
  154. }
  155. Grid1.DataBind();
  156. }
  157. #endregion
  158. }