예제 #1
0
파일: upload.aspx.cs 프로젝트: zymITsky/pms
        protected void btnDownload_Click2(object sender, EventArgs e)
        {
            //int id = GetQueryIntValue("id1");
            TSM.Model.pms_Attachment modelpms_Attachment = m_bllpms_Attachment.GetModel2(26);
            if (modelpms_Attachment == null)
            {
                // 参数错误,首先弹出Alert对话框然后关闭弹出窗口
                Alert.Show("工艺员没有上传过附件!");
                return;
            }
            string shortName = modelpms_Attachment.AttachmentName;

            shortName = shortName.Remove(0, 19); //去掉字符串的前19个字符

            string filename = Server.MapPath("~/upload/attachment/" + modelpms_Attachment.AttachmentName);

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(shortName, Encoding.UTF8));

            Response.TransmitFile(filename);
            Response.End();
        }
예제 #2
0
        private void SaveAttachment()
        {
            if (fileUpload.HasFile)
            {
                int id = int.Parse(lbProID.Text); //产品id
                //获取当前登录用户uid
                var    cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                var    ticket = FormsAuthentication.Decrypt(cookie.Value);
                string uid    = ticket.UserData;

                string fileName = fileUpload.ShortFileName;
                //把附件报存在服务器上
                fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
                fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
                fileUpload.SaveAs(Server.MapPath("~/upload/attachment/" + fileName));
                TSM.Model.pms_Attachment modelpms_Attachment   = new TSM.Model.pms_Attachment();
                TSM.BLL.pms_Attachment   m_bllpms_Attachment   = new TSM.BLL.pms_Attachment();
                TSM.Model.pms_Attachment modelpms_Attachment_1 = m_bllpms_Attachment.GetModel2(id); //以产品id获取工艺员上传附件
                if (modelpms_Attachment_1 == null)
                {
                    // 为空则ADD
                    modelpms_Attachment.ProductInfoID    = id;
                    modelpms_Attachment.UploadUid        = int.Parse(uid);
                    modelpms_Attachment.AttachmentName   = fileName;
                    modelpms_Attachment.AttachmentAddr   = "~/upload/attachment/" + fileName;
                    modelpms_Attachment.UploadPermission = "工艺员";
                    modelpms_Attachment.UploadTime       = DateTime.Now.Date;
                    m_bllpms_Attachment.Add(modelpms_Attachment);
                }
                else
                {
                    //非空则UPDATE
                    modelpms_Attachment.AttachmentID     = modelpms_Attachment_1.AttachmentID;
                    modelpms_Attachment.ProductInfoID    = id;
                    modelpms_Attachment.UploadUid        = int.Parse(uid);
                    modelpms_Attachment.AttachmentName   = fileName;
                    modelpms_Attachment.AttachmentAddr   = "~/upload/attachment/" + fileName;
                    modelpms_Attachment.UploadPermission = "工艺员";
                    modelpms_Attachment.UploadTime       = DateTime.Now.Date;
                    m_bllpms_Attachment.Update(modelpms_Attachment);
                }

                // 清空文件上传组件
                fileUpload.Reset();
            }
        }