예제 #1
0
 private PhotoInfo FormatPhotoByRow(DataRow _row)
 {
     PhotoInfo _photo = null;
     try
     {
         //AlbumNo,AlbumName,AlbumRootPath,AlbumRemark,AlbumTitleImg,CreateDate,UpdateDate,PhotoTols
         if (_row["PhotoNO"] != DBNull.Value && !string.IsNullOrEmpty(_row["PhotoNO"].ToString()))
         {
             _photo = new PhotoInfo();
             _photo.PhotoNO = _row["PhotoNO"].ToString();
             if (_row["PhotoName"] != DBNull.Value)
             {
                 _photo.PhotoName = _row["PhotoName"].ToString();
             }
             if (_row["PhotoRemark"] != DBNull.Value)
             {
                 _photo.PhotoRemark = _row["PhotoRemark"].ToString();
             }
             if (_row["PhotoData"] != DBNull.Value)
             {
                 _photo.PhotoData = _row["PhotoData"].ToString();
             }
             if (_row["PhotoMiniData"] != DBNull.Value)
             {
                 _photo.PhotoMiniData = _row["PhotoMiniData"].ToString();
             }
             if (_row["IsTitleImg"] != DBNull.Value)
             {
                 if (Convert.ToInt32(_row["IsTitleImg"]) == 1)
                 {
                     _photo.IsTitleImg = true;
                 }
                 else
                 {
                     _photo.IsTitleImg = false;
                 }
             }
             if (_row["PhotoCreateDate"] != DBNull.Value)
             {
                 _photo.PhotoCreateDate = _row["PhotoCreateDate"].ToString();
             }
             if (_row["PhotoUpdateDate"] != DBNull.Value)
             {
                 _photo.PhotoUpdateDate =_row["PhotoUpdateDate"].ToString();
             }
         }
     }
     catch
     {
     }
     return _photo;
 }
        /// <summary>
        ///添加照片至相册
        /// </summary>
        /// <param name="Photos"></param>
        /// <param name="_alumobj"></param>
        private void AddPhotosToAlume(List<string> Photos, Album _alumobj)
        {
            if (Photos != null && Photos.Count > 0)
            {
                string strImgPath = "";
                string strImgName = "";
                FileInfo tempfile = null;
                System.Drawing.Image newimg = null;
                string miniImgtempRoot = Path.Combine(rootPath, "miniImgtemp//" + _alumobj.AlbumName);
                if (!Directory.Exists(miniImgtempRoot))
                {
                    Directory.CreateDirectory(miniImgtempRoot);
                }
                string miniPath="";
                PhotoInfo newphoto = null;

                PhotoManager manager=new PhotoManager ();

                #region 逐一存储照片

                foreach (string _strImgName in Photos)
                {
                    miniPath="";
                    strImgPath = _strImgName;
                    if (File.Exists(strImgPath))
                    {
                        tempfile = new FileInfo(strImgPath);
                        miniPath=Path.Combine(miniImgtempRoot,tempfile.Name);//缩略图名称

                        strImgName = tempfile.Name.Substring(0, tempfile.Name.LastIndexOf("."));
                        tempfile = null;

                        newphoto = new PhotoInfo(strImgName,"");
                        newphoto.PhotoData = strImgPath;

                        bool bolstate = ImgManager.Instance.MakeThumbnail(strImgPath, miniPath, 100, 100);
                        if (bolstate)
                        {
                            #region 缩略图处理成功后存储照片信息
                            newphoto.PhotoMiniData = miniPath;
                            ManagerStateMsg msg = manager.AddPhoto(_alumobj.AlbumNO, newphoto);//添加照片至相册
                           if (msg.Statevalue)
                           {
                               if (AddPhotoEvent != null)
                               {
                                   AddPhotoEvent(_alumobj.AlbumName, strImgName, true);
                               }
                               else
                               {
                                   if (AddPhotoEvent != null)
                                   {
                                       AddPhotoEvent(_alumobj.AlbumName, strImgName, false);
                                   }
                               }
                           }
                            #endregion
                        }
                        else
                        {
                            newphoto = null;
                            if (AddPhotoEvent != null)
                            {
                                AddPhotoEvent(_alumobj.AlbumName, strImgName, false);
                            }
                        }
                        System.Threading.Thread.Sleep(500);
                    }
                }
                #endregion
            }
        }