Esempio n. 1
0
        public string createAttachment(string fileStore, string type, string name, FileUpload fileUpload, int id)
        {
            int    nextVersion = getNextVersion(fileStore, type, id);
            string nextPath    = fileStore + "\\" + type + "_" + id.ToString() + "\\V" + nextVersion.ToString();

            try
            {
                fileUpload.PostedFile.SaveAs(nextPath + "\\" + fileUpload.FileName);
            }
            catch (Exception ex)
            {
                Logger.logmessage(classobject, "uploadfile", ex.Message + ex.StackTrace);
            }
            Su_Attachment_Version atv = new Su_Attachment_Version();
            Su_Attachment         at  = new Su_Attachment();

            at.name      = name;
            at.path      = nextPath + "\\" + fileUpload.FileName;
            at.mime_type = fileUpload.PostedFile.ContentType;
            dataContext.Su_Attachments.InsertOnSubmit(at);
            try
            {
                dataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                Logger.logmessage(classobject, "uploadfile Su_Attachment submit", ex.Message + ex.StackTrace);
            }
            if (ATTACHMENT_TYPE_VB.Equals(type))
            {
                Su_VanBan_Attachment vAt = new Su_VanBan_Attachment();
                vAt.attachment_id = at.id;
                vAt.vanban_id     = id;
                dataContext.Su_VanBan_Attachments.InsertOnSubmit(vAt);
                try
                {
                    dataContext.SubmitChanges();
                }
                catch (Exception ex)
                {
                    Logger.logmessage(classobject, "uploadfile Su_VanBan_Attachment submit", ex.Message + ex.StackTrace);
                }
            }
            else if (ATTACHMENT_TYPE_HS.Equals(type))
            {
                Su_HoSo_Attachment hAt = new Su_HoSo_Attachment();
                hAt.attachment_id = at.id;
                hAt.id_hoso       = id;
                dataContext.Su_HoSo_Attachments.InsertOnSubmit(hAt);
                try
                {
                    dataContext.SubmitChanges();
                }
                catch (Exception ex)
                {
                    Logger.logmessage(classobject, "uploadfile Su_HoSo_Attachment submit", ex.Message + ex.StackTrace);
                }
            }
            return(nextPath + "\\" + fileUpload.FileName);
        }
Esempio n. 2
0
 protected void downloadAttach(object sender, EventArgs e)
 {
     try
     {
         LinkButton btn           = sender as LinkButton;
         string     attachmentID  = btn.CommandArgument.Trim();
         int        iAttachmentID = 0;
         Int32.TryParse(attachmentID, out iAttachmentID);
         if (iAttachmentID > 0)
         {
             Su_Attachment at        = logic.getAttachmentByID(iAttachmentID);
             string[]      fileNames = at.path.Split('\\');
             if (at.mime_type == null || at.mime_type.Trim().Length == 0)
             {
                 Response.ContentType = "application/unknown";
             }
             else
             {
                 Response.ContentType = at.mime_type;
             }
             Response.AppendHeader("content-disposition",
                                   "attachment; filename=" + HttpUtility.UrlEncode(fileNames[fileNames.Length - 1], System.Text.Encoding.UTF8));
             Response.TransmitFile(at.path);
             Response.End();
         }
         else
         {
             throw new Exception("Attachment not found.");
         }
     }
     catch (Exception ex)
     {
         Logger.logmessage(classobject, "downloadAttach", "Download error: " + ex.Message);
     }
 }
Esempio n. 3
0
        public List <Su_Attachment> getAttachment(string type, int id)
        {
            List <Su_Attachment> lstRS = new List <Su_Attachment>();

            if (ATTACHMENT_TYPE_HS.Equals(type))
            {
                try
                {
                    List <Su_HoSo_Attachment> lstHA = dataContext.Su_HoSo_Attachments.Where(p => p.id_hoso == id).ToList();
                    foreach (Su_HoSo_Attachment sHA in lstHA)
                    {
                        try
                        {
                            Su_Attachment sA = dataContext.Su_Attachments.Where(p => p.id == sHA.attachment_id).First();
                            lstRS.Add(sA);
                        }
                        catch (Exception ex2)
                        {
                            logger.Error("Attachment logic getAttachment error: ", ex2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Attachment logic getAttachment error: ", ex);
                }
            }
            if (ATTACHMENT_TYPE_VB.Equals(type))
            {
                try
                {
                    List <Su_VanBan_Attachment> lstHA = dataContext.Su_VanBan_Attachments.Where(p => p.vanban_id == id).ToList();
                    foreach (Su_VanBan_Attachment sHA in lstHA)
                    {
                        try
                        {
                            Su_Attachment sA = dataContext.Su_Attachments.Where(p => p.id == sHA.attachment_id).First();
                            lstRS.Add(sA);
                        }
                        catch (Exception ex2)
                        {
                            logger.Error("Attachment logic getAttachment error: ", ex2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Attachment logic getAttachment error: ", ex);
                }
            }
            return(lstRS);
        }