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

http://pigeoncms.googlecode.com/ · C# · 162 lines · 142 code · 20 blank · 0 comment · 14 complexity · bb452a4b464abde98b5121a30a538f99 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. public partial class Controls_Default : PigeonCms.BaseModuleControl
  15. {
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. if (!Page.IsPostBack)
  19. {
  20. }
  21. }
  22. protected void ObjDs1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
  23. {
  24. MenutypeFilter filter = new MenutypeFilter();
  25. e.InputParameters["filter"] = filter;
  26. }
  27. protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
  28. {
  29. if (e.CommandName == "Select")
  30. {
  31. editRow(int.Parse(e.CommandArgument.ToString()));
  32. }
  33. if (e.CommandName == "DeleteRow")
  34. {
  35. deleteRow(int.Parse(e.CommandArgument.ToString()));
  36. }
  37. }
  38. protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
  39. {
  40. if (e.Row.RowType == DataControlRowType.Header)
  41. Utility.AddGlyph(Grid1, e.Row);
  42. }
  43. protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
  44. {
  45. if (e.Row.RowType == DataControlRowType.DataRow)
  46. {
  47. }
  48. }
  49. protected void BtnNew_Click(object sender, EventArgs e)
  50. {
  51. editRow(0);
  52. }
  53. protected void BtnSave_Click(object sender, EventArgs e)
  54. {
  55. LblErr.Text = "";
  56. LblOk.Text = "";
  57. try
  58. {
  59. Menutype o1 = new PigeonCms.Menutype();
  60. if (base.CurrentId == 0)
  61. {
  62. form2obj(o1);
  63. o1 = new MenutypesManager().Insert(o1);
  64. }
  65. else
  66. {
  67. o1 = new MenutypesManager().GetByKey(base.CurrentId);
  68. form2obj(o1);
  69. new MenutypesManager().Update(o1);
  70. }
  71. Grid1.DataBind();
  72. LblOk.Text = Utility.GetLabel("RECORD_SAVED_MSG");
  73. MultiView1.ActiveViewIndex = 0;
  74. }
  75. catch (Exception e1)
  76. {
  77. LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
  78. }
  79. finally
  80. {
  81. }
  82. }
  83. protected void BtnCancel_Click(object sender, EventArgs e)
  84. {
  85. MultiView1.ActiveViewIndex = 0;
  86. }
  87. protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
  88. {
  89. if (MultiView1.ActiveViewIndex == 1) //edit view
  90. {
  91. }
  92. }
  93. #region private methods
  94. private void clearForm()
  95. {
  96. TxtMenuType.Text = "";
  97. TxtTitle.Text = "";
  98. TxtDescription.Text = "";
  99. }
  100. private void form2obj(Menutype obj)
  101. {
  102. obj.Id = base.CurrentId;
  103. obj.MenuType = TxtMenuType.Text;
  104. obj.Title = TxtTitle.Text;
  105. obj.Description = TxtDescription.Text;
  106. }
  107. private void obj2form(Menutype obj)
  108. {
  109. TxtMenuType.Text = obj.MenuType;
  110. TxtTitle.Text = obj.Title;
  111. TxtDescription.Text = obj.Description;
  112. }
  113. private void editRow(int recordId)
  114. {
  115. LblOk.Text = "";
  116. LblErr.Text = "";
  117. clearForm();
  118. base.CurrentId = recordId;
  119. if (base.CurrentId > 0)
  120. {
  121. Menutype obj = new Menutype();
  122. obj = new MenutypesManager().GetByKey(base.CurrentId);
  123. obj2form(obj);
  124. }
  125. MultiView1.ActiveViewIndex = 1;
  126. }
  127. private void deleteRow(int recordId)
  128. {
  129. LblOk.Text = "";
  130. LblErr.Text = "";
  131. try
  132. {
  133. new MenutypesManager().DeleteById(recordId);
  134. }
  135. catch (Exception e)
  136. {
  137. LblErr.Text = e.Message;
  138. }
  139. Grid1.DataBind();
  140. }
  141. #endregion
  142. }