/// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// Page_Load runs when the control is loaded 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {

                // Determine ItemId of DocumentsExchangeModule to Update
                if ((Request.QueryString["ItemId"] != null))
                {
                    ItemId = Int32.Parse(Request.QueryString["ItemId"]);
                }

                // If this is the first visit to the page, bind the role data to the datalist
                if (Page.IsPostBack == false)
                {

                    cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");

                    if (!Null.IsNull(ItemId))
                    {
                        // get content
                        DocumentsExchangeModuleController objDocumentsExchangeModules = new DocumentsExchangeModuleController();
                        DocumentsExchangeModuleInfo objDocumentsExchangeModule = objDocumentsExchangeModules.GetDocumentsExchangeModule(ModuleId, ItemId);
                        if ((objDocumentsExchangeModule != null))
                        {
                            txtContent.Text = objDocumentsExchangeModule.Content;
                            ctlAudit.CreatedByUser = objDocumentsExchangeModule.CreatedByUserName;
                            ctlAudit.CreatedDate = objDocumentsExchangeModule.CreatedDate.ToString();
                        }
                        else
                        {
                            // security violation attempt to access item not related to this Module
                            Response.Redirect(Globals.NavigateURL(), true);
                        }
                    }
                    else
                    {
                        cmdDelete.Visible = false;
                        ctlAudit.Visible = false;
                    }
                }
            }

            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// cmdDelete_Click runs when the delete button is clicked 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void cmdDelete_Click(object sender, EventArgs e)
        {
            try
            {
                // Only attempt to delete the item if it exists already
                if (!Null.IsNull(ItemId))
                {

                    DocumentsExchangeModuleController objDocumentsExchangeModules = new DocumentsExchangeModuleController();
                    objDocumentsExchangeModules.DeleteDocumentsExchangeModule(ModuleId, ItemId);

                }

                // Redirect back to the portal home page
                Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// cmdUpdate_Click runs when the update button is clicked 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                DocumentsExchangeModuleController objDocumentsExchangeModules = new DocumentsExchangeModuleController();

                DocumentsExchangeModuleInfo objDocumentsExchangeModule = new DocumentsExchangeModuleInfo();

                objDocumentsExchangeModule.ModuleId = ModuleId;
                objDocumentsExchangeModule.ItemId = ItemId;
                objDocumentsExchangeModule.Content = txtContent.Text;
                objDocumentsExchangeModule.CreatedByUser = this.UserId;

                if (Null.IsNull(ItemId))
                {
                    // add the content within the DocumentsExchangeModule table
                    objDocumentsExchangeModules.AddDocumentsExchangeModule(objDocumentsExchangeModule);
                }
                else
                {
                    // update the content within the DocumentsExchangeModule table
                    objDocumentsExchangeModules.UpdateDocumentsExchangeModule(objDocumentsExchangeModule);
                }

                // Redirect back to the portal home page
                Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        private void UpdateNavigationControls(int? parentFolderId)
        {
            if (parentFolderId.HasValue && parentFolderId.Value < 1)
            {
                parentFolderId = null;
            }

            DocumentsExchangeModuleController moduleController =
                new DocumentsExchangeModuleController();

            lstFolders.DataSource = moduleController.GetFolders(parentFolderId);
            lstFolders.DataBind();

            lstFiles.DataSource = moduleController.GetFiles(parentFolderId);
            lstFiles.DataBind();

            List<int?> foldersTrace = ViewState[FOLDERS_TRACE] as List<int?> ??
                            new List<int?>();

            if (!foldersTrace.Contains(parentFolderId))
            {
                foldersTrace.Add(parentFolderId);
            }
            else
            {
                if (foldersTrace.IndexOf(parentFolderId) < foldersTrace.Count - 1)
                {
                    foldersTrace.RemoveRange(foldersTrace.IndexOf(parentFolderId) + 1,
                        foldersTrace.Count - 1 - foldersTrace.IndexOf(parentFolderId));
                }
            }

            ViewState[FOLDERS_TRACE] = foldersTrace;

            StringBuilder foldersTraceString = new StringBuilder();
            foreach (var folderId in foldersTrace)
            {
                foldersTraceString.Append(folderId.HasValue
                                              ? String.Format(">{0}", folderId.Value)
                                              : String.Format("{0}", "ROOT"));
            }
            lblFoldersTrace.Text = foldersTraceString.ToString();

            UpdateUpButtonVisibility();
        }
        private void ShowFileVersions(int fileId)
        {
            if (fileId < 1)
            {
                return;
            }

            DocumentsExchangeModuleController moduleController =
                new DocumentsExchangeModuleController();
            String currentFileName = moduleController.GetOriginalFileName(fileId);
            lblCurrentFileDescription.Text = String.Format("Versions of file \"{0}\":", currentFileName);
            lstVersions.DataSource = moduleController.GetVersions(fileId);
            lstVersions.DataBind();
            multiView.SetActiveView(versionsPage);
        }
        protected void lbtnVersionComment_Click(Object sender, EventArgs e)
        {
            int currentFileId = int.Parse((String)ViewState[CURRENT_FILE_ID]);
            DocumentsExchangeModuleController moduleController =
                new DocumentsExchangeModuleController();
            String fileContentType = moduleController.GetFileContentType(currentFileId);
            String originalFileName = moduleController.GetOriginalFileName(currentFileId);
            int versionId = int.Parse(lstVersions.DataKeys
                                            [((DataListItem)((Control)sender).NamingContainer).ItemIndex]
                                            .ToString());
            String localFileName = moduleController.GetVersionLocalName(versionId);

            if (!String.IsNullOrWhiteSpace(fileContentType) &&
                !String.IsNullOrWhiteSpace(localFileName))
            {
                (new DocumentsExchangeModuleController()).
                        DownloadFile(Server.MapPath(UPLOADS_FOLDER_RELATIVE_PATH),
                             localFileName,
                             originalFileName,
                             fileContentType,
                             Response);
            }
        }
 protected void lbtnFileName_Click(object sender, EventArgs e)
 {
     int fileId = int.Parse(lstFiles.
                             DataKeys[
                                 ((DataListItem)((LinkButton)sender).
                                         NamingContainer).ItemIndex]
                             .ToString());
     DocumentsExchangeModuleController moduleController =
         new DocumentsExchangeModuleController();
     String fileContentType = moduleController.GetFileContentType(fileId);
     String originalFileName = moduleController.GetOriginalFileName(fileId);
     String localFileName = moduleController.GetFileLastVersionLocalName(fileId);
     if (!String.IsNullOrWhiteSpace(fileContentType) &&
         !String.IsNullOrWhiteSpace(localFileName))
     {
         (new DocumentsExchangeModuleController()).
                 DownloadFile(Server.MapPath(UPLOADS_FOLDER_RELATIVE_PATH),
                      localFileName,
                      originalFileName,
                      fileContentType,
                      Response);
     }
 }