private void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                if (Request["btnCancel"] != null)
                {
                    DocumentTransaction.End();
                    Response.Redirect("~/CloseWindow.html");
                    return;
                }
                PanPreview.Visible = false;

                if (!DocumentTransaction.IsActive())
                {
                    throw new BipFatalException();
                }

                doc = DocumentTransaction.Current.Document;
                lblFileName.Text = doc.FileName;
                if (Page.IsPostBack == false)
                {
                    ddlFileType.DataSource     = DocFileType.FindAll();
                    ddlFileType.DataTextField  = "Name";
                    ddlFileType.DataValueField = "Id";
                    ddlFileType.DataBind();
                    //ddlFileType.Items.Insert(0, new ListItem("", "0"));
                    ListUtils.SelectSingleListItem(ddlFileType.Items, doc.FileTypeId.ToString());
                }
                else
                {
                    int fileType = Convert.ToInt32(ddlFileType.SelectedItem.Value);
                    if (fileType == 0)
                    {
                        throw new BipGenericException(Bip.Components.BipResources.GetString("StMustSelectFileType"));
                    }
                    doc.ConfigureFileType(Convert.ToInt32(ddlFileType.SelectedItem.Value));
                }

                if (doc.Id > 0)
                {
                    btnBack.Visible = false;
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
        protected void LoadAttributes()
        {
            string docCategoryName = "", docTypeName = "", docSourceName = "", docFileType = "";



            if (doc.DocCategoryId > 0)
            {
                DocCategoryEnt docCategory = new DocCategoryEnt();
                try
                {
                    docCategory.Load(doc.DocCategoryId);
                    docCategoryName = docCategory.Name;
                }
                catch (BipObjectNotFoundException)
                {
                    docCategoryName = "";
                }
                docCategory.Dispose();
            }



            if (doc.DocTypeId > 0)
            {
                DocTypeEnt docType = new DocTypeEnt();
                try
                {
                    docType.Load(doc.DocTypeId);
                    docTypeName = docType.Name;
                }
                catch (BipObjectNotFoundException)
                {
                    docTypeName = "";
                }
                docType.Dispose();
            }

            if (doc.DocSourceId > 0)
            {
                DocSourceEnt docSource = new DocSourceEnt();
                try
                {
                    docSource.Load(doc.DocSourceId);
                    docSourceName = docSource.Name;
                }
                catch (BipObjectNotFoundException)
                {
                    docSourceName = "";
                }
                docSource.Dispose();
            }
            if (doc.FileTypeId > 0)
            {
                docFileType = DocFileType.GetTypeName(doc.FileTypeId);
            }



            lblDocCategory.Text = docCategoryName;
            lblDocType.Text     = docTypeName;
            lblDocSource.Text   = docSourceName;
            lblFileType.Text    = docFileType;

            if (doc.IsPublic)
            {
                lblIsPublic.Text = "Yes";
            }
            else
            {
                lblIsPublic.Text = "No";
            }

            lblDateReceived.Text     = Utils.DateToText(doc.DateReceived);
            lblDocumentDate.Text     = Utils.DateToText(doc.DocumentDate);
            lblIncomingNumber.Text   = doc.IncomingNumber;
            lblOutgoingNumber.Text   = doc.OutgoingNumber;
            lblSubject.Text          = doc.Subject;
            lblHeader.Text           = doc.Header;
            lblFileName.Text         = doc.FileName;
            lblArchiveFileNames.Text = doc.ArchiveFileNames;
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                bool isInFrame = (Request["frame"] != null);
                PanFileNotShown.Visible = false;
                try
                {
                    string s_id          = Request["Id"];
                    string s_transaction = Request["TC"];
                    bool   original      = true;
                    if (Request["Org"] == null || Request["Org"].Length == 0)
                    {
                        original = false;
                    }
                    bool isInline = (Request["inline"] != null &&
                                     Request["inline"].Length > 0);

                    DocumentEnt doc = new DocumentEnt();

                    if (s_id != null && s_id.Length > 0)
                    {
                        int id = Convert.ToInt32(s_id);
                        doc.Load(id);
                    }
                    else
                    if (s_transaction == "1" && DocumentTransaction.IsActive())
                    {
                        doc = DocumentTransaction.Current.Document;
                    }
                    else
                    {
                        throw new BipFatalException();
                    }



                    DocFileType fileType = new DocFileType(doc.FileTypeId);
                    bool        isText   = (fileType.ContentType.Trim().ToLower() == "text/plain");
                    if (isInline == false)
                    {
                        Response.Clear();
                        Response.ContentType = fileType.ContentType;
                        Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + doc.FileName + "\"");
                        Response.BinaryWrite(doc.DownloadFile(original));
                        Response.End();
                        return;
                    }

                    if (isText == false)
                    {
                        if (fileType.ShowInBrowser == false)
                        {
                            PanFileNotShown.Visible = true;
                            lblFileType.Text        = fileType.Name;
                            if (s_transaction == null)
                            {
                                hlDownload.NavigateUrl = "~/Documents/DocFileDownload.aspx?id=" + doc.Id.ToString();
                            }
                            else
                            {
                                hlDownload.NavigateUrl = "~/Documents/DocFileDownload.aspx?TC=1";
                            }
                            hlDownload.Text = doc.FileName;
                            return;
                        }

                        Response.Clear();
                        Response.ContentType = fileType.ContentType;
                        Response.AppendHeader("Content-Disposition", "inline; filename=\"" + doc.FileName + "\"");
                        Response.BinaryWrite(doc.DownloadFile(original));
                        Response.End();
                        return;
                    }


                    byte [] buffer = doc.DownloadFile(original);
                    // this should not be hardcoded
                    Decoder d     = Encoding.GetEncoding("Windows-1252").GetDecoder();
                    char [] chars = new char[buffer.Length];
                    d.GetChars(buffer, 0, buffer.Length, chars, 0);
                    textFileContents.InnerText = new string(chars);
                }
                catch (Exception ex)
                {
                    if (ex is System.Threading.ThreadAbortException ||
                        ex is System.Threading.ThreadInterruptedException)
                    {
                        throw ex;
                    }

                    if (!isInFrame)
                    {
                        throw ex;
                    }
                    Response.Clear();
                    Response.Redirect("~/Error.aspx?error=" + HttpUtility.UrlEncode(ex.Message));
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
            //HttpUtility.HtmlEncode(
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                if (!DocumentTransaction.IsActive())
                {
                    throw new BipFatalException();
                }

                doc = DocumentTransaction.Current.Document;

                if (Request["btnCancel"] != null)
                {
                    DocumentTransaction.End();
                    Response.Redirect("~/CloseWindow.html");
                    return;
                }


                if (Page.IsPostBack == false)
                {
                    if (doc.Id < 1)
                    {
                        PanExistingDocAttrs.Visible = false;
                        btnBack.Text  = "< " + BipResources.GetString("StrBtnBackCaption");
                        btnBack.Width = new Unit("100px");
                    }

                    LoadDropDownList(ddlDocCategory, DocCategoryEnt.FindAll());
                    LoadDropDownList(ddlDocType, DocTypeEnt.FindAll());
                    LoadDropDownList(ddlDocSource, DocSourceEnt.FindAll());

                    dlGroups.DataSource = Bip.Components.GroupEnt.FindAll();
                    dlGroups.DataBind();


                    LoadAttributes();
                }

                // ParentDocID ---------------------------------
                if (Page.IsPostBack == false ||
                    Request["_BIP_ACTION"] == "SelectParentDoc")
                {
                    if (Request["_BIP_ACTION"] == "SelectParentDoc")
                    {
                        doc.ParentId = Convert.ToInt32(Request["_BIP_ACTION_ARGS"]);
                    }
                    ShowParentDocLink(doc);
                }

                // PreviousVersionDocID ---------------------------------
                if (Page.IsPostBack == false ||
                    Request["_BIP_ACTION"] == "SelectPreviousVersionDoc")
                {
                    if (Request["_BIP_ACTION"] == "SelectPreviousVersionDoc")
                    {
                        doc.PreviousVersionId = Convert.ToInt32(Request["_BIP_ACTION_ARGS"]);
                    }
                    ShowPreviousVersionDocLink(doc);
                }

                // RelatedDocs ---------------------------------
                if (Page.IsPostBack == false ||
                    Request["_BIP_ACTION"] == "AddRelatedDoc" ||
                    Request["_BIP_ACTION"] == "RemoveRelatedDoc")
                {
                    if (Request["_BIP_ACTION"] == "AddRelatedDoc" ||
                        Request["_BIP_ACTION"] == "RemoveRelatedDoc")
                    {
                        ArrayList docEnum = new ArrayList();
                        if (doc.RefDocuments != null)
                        {
                            foreach (int ids in doc.RefDocuments)
                            {
                                docEnum.Add(ids);
                            }
                        }

                        int id = Convert.ToInt32(Request["_BIP_ACTION_ARGS"]);
                        if (Request["_BIP_ACTION"] == "AddRelatedDoc")
                        {
                            if (docEnum.IndexOf(id) == -1)
                            {
                                docEnum.Add(id);
                            }
                        }
                        else
                        {
                            docEnum.Remove(id);
                        }

                        doc.RefDocuments = docEnum;
                    }

                    grdDocRefRelated.DataSource = DocumentEnt.FindEnum(doc.RefDocuments);
                    grdDocRefRelated.DataBind();
                }

                string s1, s2;
                bool   showInBrowser = false;
                DocFileType.GetTypeInfo(doc.FileTypeId, out s1, out s2, out showInBrowser);
                btnShowHidePreview.Visible = showInBrowser;
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }