/pigeoncms/Admin/Documents.aspx.cs

http://pigeoncms.googlecode.com/ · C# · 203 lines · 180 code · 22 blank · 1 comment · 17 complexity · bf8968c8a24dafa0be9a8299b3f8638f 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.Collections.Generic;
  12. using System.IO;
  13. using PigeonCms;
  14. using FredCK.FCKeditorV2;
  15. public partial class Admin_Documents : BasePage
  16. {
  17. const string DEFAULT_GROUP_NAME = "docs";
  18. protected void Page_Init(object sender, EventArgs e)
  19. {
  20. }
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. LblOk.Text = "";
  24. LblErr.Text = "";
  25. }
  26. protected void ObjDs1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
  27. {
  28. DocumentsFilter docFilter = new DocumentsFilter();
  29. docFilter.Visible = Utility.TristateBool.NotSet;
  30. docFilter.GroupName = DEFAULT_GROUP_NAME;
  31. docFilter.HasValidFile = Utility.TristateBool.NotSet;
  32. e.InputParameters["filter"] = docFilter;
  33. }
  34. protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
  35. {
  36. if (e.CommandName == "Select")
  37. {
  38. edit(int.Parse(e.CommandArgument.ToString()));
  39. }
  40. if (e.CommandName == "DeleteRow")
  41. {
  42. delete(int.Parse(e.CommandArgument.ToString()));
  43. }
  44. if (e.CommandName == "MoveDown")
  45. {
  46. moveRecord(int.Parse(e.CommandArgument.ToString()), Database.MoveRecordDirection.Down);
  47. }
  48. if (e.CommandName == "MoveUp")
  49. {
  50. moveRecord(int.Parse(e.CommandArgument.ToString()), Database.MoveRecordDirection.Up);
  51. }
  52. }
  53. protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
  54. {
  55. if (e.Row.RowType == DataControlRowType.Header)
  56. Utility.AddGlyph(Grid1, e.Row);
  57. }
  58. protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
  59. {
  60. if (e.Row.RowType == DataControlRowType.DataRow)
  61. {
  62. if (!(bool)DataBinder.Eval(e.Row.DataItem, "HasValidFile"))
  63. {
  64. Label lblValidFile = (Label)e.Row.FindControl("LblValidFile");
  65. lblValidFile.Text = Utility.GetLabel("", "Nessun file caricato");
  66. Image ImgDownload = (Image)e.Row.FindControl("ImgDownload");
  67. ImgDownload.Visible = false;
  68. }
  69. }
  70. }
  71. protected void BtnSave_Click(object sender, EventArgs e)
  72. {
  73. LblErr.Text = "";
  74. LblOk.Text = "";
  75. try
  76. {
  77. Document p1 = new Document();
  78. form2obj(p1);
  79. if (p1.DocId == 0)
  80. {
  81. p1 = DocumentsManager.Insert(p1);
  82. }
  83. else
  84. {
  85. DocumentsManager.Update(p1);
  86. }
  87. Grid1.DataBind();
  88. LblOk.Text = Utility.GetLabel("RECORD_SAVED_MSG");
  89. MultiView1.ActiveViewIndex = 0;
  90. }
  91. catch (Exception e1)
  92. {
  93. LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
  94. }
  95. finally
  96. {
  97. }
  98. }
  99. protected void BtnCancel_Click(object sender, EventArgs e)
  100. {
  101. MultiView1.ActiveViewIndex = 0;
  102. }
  103. protected void BtnNew_Click(object sender, EventArgs e)
  104. {
  105. edit(0);
  106. }
  107. #region private methods
  108. private void form2obj(Document obj1)
  109. {
  110. obj1.DocId = int.Parse(TxtId.Text);
  111. obj1.Name = TxtName.Text;
  112. obj1.Description = FckPageContent.Value;
  113. obj1.TagsList = TxtTagsList.Text;
  114. obj1.FilePath = TxtFilePath.Text;
  115. obj1.GroupName = DEFAULT_GROUP_NAME;
  116. obj1.Visible = ChkVisible.Checked;
  117. obj1.OrderId = int.Parse(TxtOrderId.Text);
  118. }
  119. private void obj2form(Document obj1)
  120. {
  121. TxtId.Text = obj1.DocId.ToString();
  122. TxtName.Text = obj1.Name;
  123. FckPageContent.Value = obj1.Description;
  124. TxtTagsList.Text = obj1.TagsList;
  125. TxtFilePath.Text = obj1.FilePath;
  126. //TxtGroupName.Text = obj1.GroupName;
  127. ChkVisible.Checked = obj1.Visible;
  128. TxtOrderId.Text = obj1.OrderId.ToString();
  129. }
  130. private void edit(int docId)
  131. {
  132. LblOk.Text = "";
  133. LblErr.Text = "";
  134. TxtId.Text = docId.ToString();
  135. TxtName.Text = "";
  136. FckPageContent.Value = "";
  137. TxtTagsList.Text = "";
  138. ChkVisible.Checked = true;
  139. TxtOrderId.Text = "0";
  140. if (docId != 0)
  141. {
  142. Document currObj = new Document();
  143. currObj = DocumentsManager.GetDocById(docId);
  144. obj2form(currObj);
  145. }
  146. MultiView1.ActiveViewIndex = 1;
  147. }
  148. private void delete(int docId)
  149. {
  150. LblOk.Text = "";
  151. LblErr.Text = "";
  152. try
  153. {
  154. DocumentsManager.DeleteById(docId);
  155. }
  156. catch (Exception e)
  157. {
  158. LblErr.Text = e.Message;
  159. }
  160. Grid1.DataBind();
  161. }
  162. protected void moveRecord(int docId, Database.MoveRecordDirection direction)
  163. {
  164. LblErr.Text = "";
  165. LblOk.Text = "";
  166. try
  167. {
  168. DocumentsManager.MoveRecord(docId, direction);
  169. Grid1.DataBind();
  170. MultiView1.ActiveViewIndex = 0;
  171. }
  172. catch (Exception e1)
  173. {
  174. LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
  175. }
  176. finally
  177. {
  178. }
  179. }
  180. #endregion
  181. }