PageRenderTime 32ms CodeModel.GetById 20ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/pigeoncms/Admin/Documents.aspx.cs

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