/pigeoncms/Admin/Documents.aspx.cs
http://pigeoncms.googlecode.com/ · C# · 203 lines · 180 code · 22 blank · 1 comment · 17 complexity · bf8968c8a24dafa0be9a8299b3f8638f MD5 · raw file
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Collections.Generic;
- using System.IO;
- using PigeonCms;
- using FredCK.FCKeditorV2;
-
- public partial class Admin_Documents : BasePage
- {
- const string DEFAULT_GROUP_NAME = "docs";
-
- protected void Page_Init(object sender, EventArgs e)
- {
- }
-
- protected void Page_Load(object sender, EventArgs e)
- {
- LblOk.Text = "";
- LblErr.Text = "";
- }
-
- protected void ObjDs1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
- {
- DocumentsFilter docFilter = new DocumentsFilter();
- docFilter.Visible = Utility.TristateBool.NotSet;
- docFilter.GroupName = DEFAULT_GROUP_NAME;
- docFilter.HasValidFile = Utility.TristateBool.NotSet;
- e.InputParameters["filter"] = docFilter;
- }
-
- protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName == "Select")
- {
- edit(int.Parse(e.CommandArgument.ToString()));
- }
- if (e.CommandName == "DeleteRow")
- {
- delete(int.Parse(e.CommandArgument.ToString()));
- }
- if (e.CommandName == "MoveDown")
- {
- moveRecord(int.Parse(e.CommandArgument.ToString()), Database.MoveRecordDirection.Down);
- }
- if (e.CommandName == "MoveUp")
- {
- moveRecord(int.Parse(e.CommandArgument.ToString()), Database.MoveRecordDirection.Up);
- }
- }
-
- protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.Header)
- Utility.AddGlyph(Grid1, e.Row);
- }
-
- protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- if (!(bool)DataBinder.Eval(e.Row.DataItem, "HasValidFile"))
- {
- Label lblValidFile = (Label)e.Row.FindControl("LblValidFile");
- lblValidFile.Text = Utility.GetLabel("", "Nessun file caricato");
-
- Image ImgDownload = (Image)e.Row.FindControl("ImgDownload");
- ImgDownload.Visible = false;
- }
- }
- }
-
- protected void BtnSave_Click(object sender, EventArgs e)
- {
- LblErr.Text = "";
- LblOk.Text = "";
-
- try
- {
- Document p1 = new Document();
- form2obj(p1);
- if (p1.DocId == 0)
- {
- p1 = DocumentsManager.Insert(p1);
-
- }
- else
- {
- DocumentsManager.Update(p1);
- }
- Grid1.DataBind();
- LblOk.Text = Utility.GetLabel("RECORD_SAVED_MSG");
- MultiView1.ActiveViewIndex = 0;
- }
- catch (Exception e1)
- {
- LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
- }
- finally
- {
- }
- }
-
- protected void BtnCancel_Click(object sender, EventArgs e)
- {
- MultiView1.ActiveViewIndex = 0;
- }
-
- protected void BtnNew_Click(object sender, EventArgs e)
- {
- edit(0);
- }
-
-
- #region private methods
- private void form2obj(Document obj1)
- {
- obj1.DocId = int.Parse(TxtId.Text);
-
- obj1.Name = TxtName.Text;
- obj1.Description = FckPageContent.Value;
- obj1.TagsList = TxtTagsList.Text;
- obj1.FilePath = TxtFilePath.Text;
- obj1.GroupName = DEFAULT_GROUP_NAME;
- obj1.Visible = ChkVisible.Checked;
- obj1.OrderId = int.Parse(TxtOrderId.Text);
- }
-
- private void obj2form(Document obj1)
- {
- TxtId.Text = obj1.DocId.ToString();
- TxtName.Text = obj1.Name;
- FckPageContent.Value = obj1.Description;
- TxtTagsList.Text = obj1.TagsList;
- TxtFilePath.Text = obj1.FilePath;
- //TxtGroupName.Text = obj1.GroupName;
- ChkVisible.Checked = obj1.Visible;
- TxtOrderId.Text = obj1.OrderId.ToString();
- }
-
- private void edit(int docId)
- {
- LblOk.Text = "";
- LblErr.Text = "";
-
- TxtId.Text = docId.ToString();
- TxtName.Text = "";
- FckPageContent.Value = "";
- TxtTagsList.Text = "";
- ChkVisible.Checked = true;
- TxtOrderId.Text = "0";
- if (docId != 0)
- {
- Document currObj = new Document();
- currObj = DocumentsManager.GetDocById(docId);
- obj2form(currObj);
- }
- MultiView1.ActiveViewIndex = 1;
- }
-
- private void delete(int docId)
- {
- LblOk.Text = "";
- LblErr.Text = "";
-
- try
- {
- DocumentsManager.DeleteById(docId);
- }
- catch (Exception e)
- {
- LblErr.Text = e.Message;
- }
- Grid1.DataBind();
- }
-
- protected void moveRecord(int docId, Database.MoveRecordDirection direction)
- {
- LblErr.Text = "";
- LblOk.Text = "";
- try
- {
- DocumentsManager.MoveRecord(docId, direction);
- Grid1.DataBind();
- MultiView1.ActiveViewIndex = 0;
- }
- catch (Exception e1)
- {
- LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
- }
- finally
- {
- }
- }
- #endregion
- }