Exemplo n.º 1
0
        private void SaveAttachment()
        {
            if (filePhoto.HasFile)
            {
                //获取当前登录用户uid
                var    cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                var    ticket = FormsAuthentication.Decrypt(cookie.Value);
                string uid    = ticket.UserData;
                //获取附件名
                string fileName = filePhoto.ShortFileName;
                TSM.Model.pms_Attachment modelpms_Attachment = new TSM.Model.pms_Attachment();
                TSM.BLL.pms_Attachment   m_bllpms_Attachment = new TSM.BLL.pms_Attachment();
                fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");

                fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;

                filePhoto.SaveAs(Server.MapPath("~/upload/attachment/" + fileName));

                modelpms_Attachment.ProductInfoID    = m_bllpms_Product_Info.GetMaxId() - 1;
                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);

                // 清空文件上传组件
                filePhoto.Reset();
            }
        }
Exemplo n.º 2
0
        private void SaveAttachment()
        {
            if (fileUpload.HasFile)
            {
                int id = GetQueryIntValue("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.GetModel1(id);
                if (modelpms_Attachment_1 == null)
                {
                    // 为空则ADD
                    modelpms_Attachment.ProductInfoID    = GetQueryIntValue("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    = GetQueryIntValue("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();
            }
        }