Exemplo n.º 1
0
        /// <summary>
        /// 显示附件信息
        /// </summary>
        protected void LoadAttach()
        {
            DataTable dt = ImageStorageClass.GetAttachList(new Guid(this.Hidden_ImgItemId.Value));

            this.attList.DataSource = dt;
            this.attList.DataBind();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 上传附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpAttach_Click(object sender, EventArgs e)
        {
            string sourceFolder = Path.Combine(WebUI.UIBiz.CommonInfo.ImageRootPath, this.hiFolder.Value);

            sourceFolder = Path.Combine(sourceFolder, UIBiz.CommonInfo.AttachFolder);

            if (!Directory.Exists(sourceFolder))
            {
                Directory.CreateDirectory(sourceFolder);
            }

            string fileType = Path.GetExtension(this.attachFile.FileName);
            string fileName = Path.GetFileName(this.attachFile.FileName);
            //string NewfileName = fileName + fileType;

            string fileFullPath = Path.Combine(sourceFolder, fileName);

            if (fileName.Length > 255)
            {
                ShowMessage("附件名称过长,需小于255个字符!");
                return;
            }

            if (File.Exists(fileFullPath))
            {
                ShowMessage("附件名称重复,请删除原有附件重新上传!");
                return;
            }

            try
            {
                this.attachFile.SaveAs(fileFullPath);

                if (ImageStorageClass.AddAttach(new Guid(this.Hidden_ImgItemId.Value), fileName))
                {
                    ShowMessage("添加附件成功!");
                    LoadAttach();
                }
                else
                {
                    ShowMessage("添加附件失败!");
                }
            }
            catch (PathTooLongException pe)
            {
                ShowMessage("附件名称过长!");
            }
        }
Exemplo n.º 3
0
    private void uploadFile()
    {
        HttpPostedFile f             = Request.Files["Filedata"];
        string         filename      = f.FileName;
        string         filetype      = Path.GetExtension(filename).ToLower();
        string         imgseq        = ImageStorageClass.GetImageSeq(DateTime.Now);
        string         ImageRootPath = WebUI.UIBiz.CommonInfo.ImageRootPath;
        string         sourcePath    = ImageRootPath + "\\" + CurrentUser.UserLoginName + "\\" + imgseq + filetype;

        try {
            string sourceFolder = Path.Combine(ImageRootPath, CurrentUser.UserLoginName);
            if (!Directory.Exists(sourceFolder))
            {
                Directory.CreateDirectory(sourceFolder);
            }

            //保存原图

            f.SaveAs(sourcePath);
            Response.Write(imgseq + filetype + ":" + f.FileName);
        }
        catch { }
    }
Exemplo n.º 4
0
        protected void attList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sourceFolder = Path.Combine(WebUI.UIBiz.CommonInfo.ImageRootPath, this.hiFolder.Value);

            sourceFolder = Path.Combine(sourceFolder, UIBiz.CommonInfo.AttachFolder);


            string fileName = this.attList.Rows[e.RowIndex].Cells[0].Text;

            fileName = Path.Combine(sourceFolder, fileName);

            try
            {
                File.Delete(fileName);
                string key = this.attList.DataKeys[e.RowIndex].Value.ToString();
                ImageStorageClass.DeleteAttach(new Guid(key));
                LoadAttach();
            }
            catch (Exception ex)
            {
                LogWriter.WriteExceptionLog(ex);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 保存原图片与压缩图片 到磁盘
        /// </summary>
        /// <param name="path">上传图片绝对路径</param>
        /// <param name="oImageStorage">上传图片对象</param>
        /// <param name="imagetype">上传图片类型</param>
        /// <returns></returns>
        //private void saveImage(System.Drawing.Image image, IImageStorage oImageStorage)
        //{
        //    bool slImage;

        //    System.Drawing.Image objImg = image;//System.Drawing.Image.FromFile(path);

        //    ImageRootPath = WebUI.UIBiz.CommonInfo.ImageRootPath;

        //    //原图存储路径
        //    string sourcePath = ImageRootPath + "\\" + CurrentUser.UserLoginName + "\\" + oImageStorage.ItemSerialNum + oImageStorage.ImageType;
        //    try
        //    {
        //        string sourceFolder = Path.Combine(ImageRootPath, CurrentUser.UserLoginName);
        //        if (!Directory.Exists(sourceFolder))
        //        {
        //            // Directory.CreateDirectory(ImageRootPath + "\\" + CurrentUser.UserLoginName);
        //            Directory.CreateDirectory(sourceFolder);
        //        }

        //        //保存原图

        //        this.AttachFile.PostedFile.SaveAs(sourcePath);

        //        SlImageRootPath = WebUI.UIBiz.CommonInfo.SlImageRootPath170;
        //        if (!Directory.Exists(SlImageRootPath + "\\" + CurrentUser.UserLoginName))
        //        {
        //            Directory.CreateDirectory(SlImageRootPath + "\\" + CurrentUser.UserLoginName);
        //        }

        //        //   slImage = ImageController.ConvertImageToScale(sourcePath, 170, SlImageRootPath + "\\" + CurrentUser.UserLoginName + "\\" + oImageStorage.ItemSerialNum  + oImageStorage.ImageType);
        //        ArrayList sarray = new ArrayList();
        //        sarray.Add(sourcePath);
        //        ArrayList aarray = new ArrayList();
        //        aarray.Add(SlImageRootPath + "\\" + CurrentUser.UserLoginName + "\\" + oImageStorage.ItemSerialNum + oImageStorage.ImageType);
        //        ImageController.ToZipImage(sarray, aarray, 170);

        //        SlImageRootPath = WebUI.UIBiz.CommonInfo.SlImageRootPath400;
        //        if (!Directory.Exists(SlImageRootPath + "\\" + CurrentUser.UserLoginName))
        //        {
        //            Directory.CreateDirectory(SlImageRootPath + "\\" + CurrentUser.UserLoginName);
        //        }

        //        sarray = new ArrayList();
        //        sarray.Add(sourcePath);
        //        aarray = new ArrayList();
        //        aarray.Add(SlImageRootPath + "\\" + CurrentUser.UserLoginName + "\\" + oImageStorage.ItemSerialNum + oImageStorage.ImageType);
        //        ImageController.ToZipImage(sarray, aarray, 400);
        //        //   slImage = ImageController.ConvertImageToScale(sourcePath, 400, SlImageRootPath + "\\" + CurrentUser.UserLoginName + "\\" + oImageStorage.ItemSerialNum + oImageStorage.ImageType);

        //    }
        //    catch
        //    {
        //        Response.Write("保存图片出现错误");
        //    }
        //    finally
        //    {

        //    }

        //}


        protected void btnUpload_ServerClick(object sender, EventArgs e)
        {
            if (this.t_Date.Text.Trim() == string.Empty)
            {
                this.ShowMessage(this, "请选择时间");
                return;
            }
            else
            {
                if (Convert.ToDateTime(this.t_Date.Text) > DateTime.Now)
                {
                    this.ShowMessage(this, "拍摄时间应比现在早");
                    return;
                }
            }
            //验证日期
            DateTime sDate = new DateTime();
            DateTime eDate = new DateTime();

            if (this.Calendar_StartDate.Text != "")
            {
                sDate = Convert.ToDateTime(this.Calendar_StartDate.Text);
                if (sDate <= DateTime.Now)
                {
                    this.ShowMessage(this, "有效开始日期应比现在日期晚");
                    return;
                }
            }
            else
            {
                sDate = Convert.ToDateTime("1900-01-01");
            }
            if (this.Calendar_EndDate.Text != "")
            {
                eDate = Convert.ToDateTime(this.Calendar_EndDate.Text);

                if (sDate == Convert.ToDateTime("1900-01-01") && eDate < DateTime.Now)
                {
                    this.ShowMessage(this, "有效结束日期应至少比现在日期晚");
                    return;
                }
                else if (eDate < sDate)
                {
                    this.ShowMessage(this, "有效结束日期应比有效开始日期晚");
                    return;
                }
            }
            else
            {
                eDate = Convert.ToDateTime("1900-01-01");
            }

            //根节点
            TreeNode parentNode = catalogTree.RootNode;
            //获取checked的节点List
            ArrayList nodeList = new ArrayList();

            this.catalogTree.ArrCheckbox(nodeList, parentNode);

            ArrayList catalogIds = new ArrayList(nodeList.Count);

            foreach (TreeNode node in nodeList)
            {
                catalogIds.Add(new Guid(node.Value));
            }

            if (catalogIds.Count == 0)
            {
                this.ShowMessage(this, "没有选择分类,上传失败!");
                return;
            }

            ImageStorage img = new ImageStorage();

            //string uploadvalue = this.ImageUpload.Value.Trim();
            //string fileName = this.AttachFile.FileName; //获取上传文件的全路径 //uploadvalue.Substring(uploadvalue.Trim().LastIndexOf(@"\") + 1);//得到文件
            string fileName = "";

            if (!string.IsNullOrEmpty(Request["selectedFile"]))
            {
                fileName = Request["selectedFile"].ToString();
            }
            string uploadFileName = "";

            if (!string.IsNullOrEmpty(Request["uploadFileName"]))
            {
                uploadFileName = Request["uploadFileName"].ToString();
            }
            //Response.Write("selectedFile:" + fileName);
            //Response.Write("uploadFileName:" + uploadFileName);
            //Response.End();
            #region 组织数据

            img.ImageType = System.IO.Path.GetExtension(fileName).ToLower(); //获取扩展名

            img.FileName    = System.IO.Path.GetFileName(fileName);          //实际文件名称
            img.Keyword     = this.keyWord.Value;
            img.Description = this.imageDes.Value;
            img.shotDate    = Convert.ToDateTime(this.t_Date.Text);
            img.StartDate   = sDate;
            img.EndDate     = eDate;

            img.Caption    = this.txt_Caption.Value;
            img.Address    = this.txt_Address.Value;
            img.Character  = this.txt_Character.Value;
            img.FolderName = CurrentUser.UserLoginName;
            img.userId     = CurrentUser.UserId;
            img.ItemId     = Guid.NewGuid();
            //img.ItemSerialNum = ImageStorageClass.GetImageSeq(DateTime.Now);
            img.ItemSerialNum = Path.GetFileNameWithoutExtension(uploadFileName);
            img.GroupId       = CurrentUser.UserGroupId;
            #endregion
            //modify by dtf 08-06-16 (png,psd,ai)

            System.Drawing.Image m_Image = null;

            if (this.CheckImageType(img.ImageType))// is image format
            {
                if (img.ImageType == "ai")
                {
                    img.Hvsp = "s";
                }
                else
                {
                    // m_Image = System.Drawing.Image.FromFile(fileName);
                    ImageRootPath = WebUI.UIBiz.CommonInfo.ImageRootPath;
                    string sourcePath = ImageRootPath + "\\" + CurrentUser.UserLoginName + "\\" + uploadFileName;
                    //m_Image = System.Drawing.Image.FromStream(this.AttachFile.PostedFile.InputStream);

                    m_Image = System.Drawing.Image.FromFile(sourcePath);

                    Int32 height = Convert.ToInt32(m_Image.Height.ToString());
                    Int32 width  = Convert.ToInt32(m_Image.Width.ToString());

                    if (height > width)
                    {
                        img.Hvsp = "v";
                    }
                    else if (width > height)
                    {
                        img.Hvsp = "h";
                    }
                    else
                    {
                        img.Hvsp = "s";
                    }
                }
            }
            else
            {
                img.Hvsp = string.Empty;
            }

            //存储数据库记录
            // img.ItemSerialNum = ImageStorageClass.AddImageStorage(img);


            if (ImageStorageClass.AddImageStorage(img) == null)
            {
                this.ShowMessage(this, "上传失败");
                return;
            }

            //准能压缩文件
            try
            {
                if (!this.CheckImageType(img.ImageType) ||
                    img.ImageType == "ai")
                {
                    //uploadFile(img);//存储普通文件
                }
                else
                {
                    //saveImage(m_Image, img);//将imageID与catalogID保存到ImageStorage_Catalog表
                }



                ImageStorageClass imageClass = new ImageStorageClass();



                imageClass.CreateRelationshipImageAndCatalog(img.ItemId, (Guid[])catalogIds.ToArray(typeof(Guid)));

                this.t_Date.Text             = "";
                this.imageType.Value         = "";
                this.keyWord.Value           = "";
                this.imageDes.Value          = "";
                this.txt_Address.Value       = "";
                this.txt_Caption.Value       = "";
                this.txt_Character.Value     = "";
                this.Calendar_StartDate.Text = "";
                this.Calendar_EndDate.Text   = "";

                initCalendar();

                this.ShowMessage(this, "上传成功");
            }
            catch (Exception ex)
            {
                LogWriter.WriteExceptionLog(ex);
                this.ShowMessage(this, "上传失败");
            }
            finally
            {
                if (m_Image != null)
                {
                    m_Image.Dispose();
                }
            }
        }
Exemplo n.º 6
0
        private string UploadImage()
        {
            ImageStorage img = new ImageStorage();

            //string uploadvalue = this.ImageUpload.Value.Trim();
            string fileName = fuImage.FileName; //获取上传文件的全路径 //uploadvalue.Substring(uploadvalue.Trim().LastIndexOf(@"\") + 1);//得到文件


            #region 组织数据

            img.ImageType = System.IO.Path.GetExtension(fileName).ToLower(); //获取扩展名

            img.FileName    = System.IO.Path.GetFileName(fileName);          //实际文件名称
            img.Keyword     = this.txtTitle.Text.Trim();
            img.Description = this.txtRemark.Text.Trim();
            img.shotDate    = DateTime.Now;
            img.StartDate   = DateTime.Now;
            img.EndDate     = DateTime.Now.AddYears(5);

            img.Caption       = this.txtTitle.Text.Trim();
            img.FolderName    = CurrentUser.UserLoginName;
            img.userId        = CurrentUser.UserId;
            img.ItemId        = Guid.NewGuid();
            img.ItemSerialNum = ImageStorageClass.GetImageSeq(DateTime.Now);
            img.GroupId       = CurrentUser.UserGroupId;
            img.uploadDate    = DateTime.Now;

            img.FileSize = this.fuImage.PostedFile.ContentLength;

            #endregion
            //modify by dtf 08-06-16 (png,psd,ai)

            System.Drawing.Image m_Image = null;

            if (this.CheckImageType(img.ImageType))// is image format
            {
                if (img.ImageType == "ai")
                {
                    img.Hvsp = "s";
                }
                else
                {
                    // m_Image = System.Drawing.Image.FromFile(fileName);

                    m_Image = System.Drawing.Image.FromStream(this.fuImage.PostedFile.InputStream);

                    Int32 height = Convert.ToInt32(m_Image.Height.ToString());
                    Int32 width  = Convert.ToInt32(m_Image.Width.ToString());

                    if (height > width)
                    {
                        img.Hvsp = "v";
                    }
                    else if (width > height)
                    {
                        img.Hvsp = "h";
                    }
                    else
                    {
                        img.Hvsp = "s";
                    }
                }
            }
            else
            {
                img.Hvsp = string.Empty;
            }

            //存储数据库记录
            // img.ItemSerialNum = ImageStorageClass.AddImageStorage(img);

            string s = ImageStorageClass.AddImageStorage(img);
            if (s == null)
            {
                this.ShowMessage(this, "上传失败");
            }

            //准能压缩文件
            try
            {
                if (!this.CheckImageType(img.ImageType) ||
                    img.ImageType == "ai")
                {
                    uploadFile(img);//存储普通文件
                }
                else
                {
                    saveImage(m_Image, img);//将imageID与catalogID保存到ImageStorage_Catalog表
                }
            }
            catch (Exception ex)
            {
                LogWriter.WriteExceptionLog(ex);
                this.ShowMessage(this, "上传失败");
                return(null);
            }
            finally
            {
                if (m_Image != null)
                {
                    m_Image.Dispose();
                }
            }

            return(img.ItemId.ToString());
        }
Exemplo n.º 7
0
        //按文件编号查询,获取图片详细信息
        public void SearchItemSerialNum(string imgItemSerialNum)
        {
            IImageStorage oIImageStorage = null;


            try
            {
                //oIImageStorage = ImageStorageClass.GetImageInfoByNum(imgItemSerialNum);
                oIImageStorage = ImageStorageClass.GetImageInfoByItemId(new Guid(imgItemSerialNum), CurrentUser.UserId);



                this.yRootPath = UIBiz.CommonInfo.GetImageUrl(400, oIImageStorage);

                string imgSuffixStr = ",JPG,JPEG,GIF,BMP,TIFF,PCX,TGA,EXIF,FPX,";
                if (imgSuffixStr.IndexOf("," + oIImageStorage.ImageType.ToUpper() + ",") < 0)
                {
                    this.tr_Hvsp.Visible     = false;
                    this.tr_shotDate.Visible = false;
                }

                this.imgsrc.Src             = yRootPath;
                this.Hidden_ImgItemId.Value = oIImageStorage.ItemId.ToString();
                hiImgNum.Value           = oIImageStorage.ItemSerialNum;
                this.TxtDescription.Text = oIImageStorage.Description;
                this.lb_FileName.Text    = oIImageStorage.FileName;
                switch (oIImageStorage.Hvsp.ToUpper())
                {
                case "H": this.lb_Hvsp.Text = "横图"; break;

                case "V": this.lb_Hvsp.Text = "竖图"; break;

                case "S": this.lb_Hvsp.Text = "方图"; break;

                case "P": this.lb_Hvsp.Text = "全景图"; break;

                default: this.lb_Hvsp.Text = "横图"; break;
                }

                this.lb_ImageType.Text     = oIImageStorage.ImageType.ToUpper();
                this.lb_ItemSerialNum.Text = oIImageStorage.ItemSerialNum;
                this.TxtKeyword.Text       = oIImageStorage.Keyword;
                this.lb_uploadDate.Text    = oIImageStorage.uploadDate.ToString("yyyy-MM-dd");
                //
                this.txt_Caption.Text   = oIImageStorage.Caption;
                this.txt_Address.Text   = oIImageStorage.Address;
                this.txt_Character.Text = oIImageStorage.Character;
                this.hiFolder.Value     = oIImageStorage.FolderName;

                if (oIImageStorage.StartDate.ToString("yyyy-MM-dd") != "1900-01-01")
                {
                    this.Calendar_StartDate.Text = oIImageStorage.StartDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    this.Calendar_StartDate.Text = "";
                }
                if (oIImageStorage.EndDate.ToString("yyyy-MM-dd") != "1900-01-01")
                {
                    this.Calendar_EndDate.Text = oIImageStorage.EndDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    this.Calendar_EndDate.Text = "";
                }
                if (oIImageStorage.shotDate.ToString("yyyy-MM-dd") != "1900-01-01")
                {
                    this.Calendar_ShotDate.Text = oIImageStorage.shotDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    this.Calendar_ShotDate.Text = "";
                }

                using (DataSet ds = GetImageCatalog(oIImageStorage.ItemId.ToString()))
                {
                    if (ds != null && ds.Tables[0].Rows.Count != 0)
                    {
                        DataTable cataTable = ds.Tables[0];

                        for (int i = 0; i < cataTable.Rows.Count; i++)
                        {
                            OutString.Append(cataTable.Rows[i]["CatalogName"].ToString() + "   ");
                        }

                        lb_catalogs.Text = OutString.ToString();
                    }
                }
            }
            catch
            {
                this.imagePanel.Visible = false;
                Response.Write("<script language='javascript'>alert('不存在此图片!');window.close();</script>");
                Response.End();
            }
        }