/// <summary>
 /// 获取照片列表
 /// </summary>
 /// <param name="_AblumNo"></param>
 /// <param name="_page"></param>
 /// <param name="_size"></param>
 /// <returns></returns>
 public List<PhotoInfo> GetPhotosByPage(string _AblumNo, int _page, int _size)
 {
     List<PhotoInfo> photos = null;
     IPhotoManager manager = new PhotoManager();
     photos = manager.GetPagePhotosByAlbum(_page, _size, _AblumNo);
     foreach (PhotoInfo _ph in photos)
     {
         _ph.PhotoData = "";
         _ph.PhotoMiniData = "";
     }
     return photos;
 }
 /// <summary>
 /// 获取照片缩略图数据
 /// </summary>
 /// <param name="_PhotoNo"></param>
 /// <returns></returns>
 public string GetPhotoMiniImgData(string _PhotoNo)
 {
     string strMiniData = "";
     try
     {
         IPhotoManager manager = new PhotoApp.SQLitBLL.PhotoManager();
         PhotoInfo _photo = manager.GetPhotoInfoByNo(_PhotoNo);
         strMiniData = PhotoApp.SQLitBLL.ImgManager.Instance.GetImgData(_photo.PhotoMiniData, false);//获取缩略图数据
     }
     catch (Exception ex)
     {
     }
     return strMiniData;
 }
        /// <summary>
        /// 获取照片原图数据
        /// </summary>
        /// <param name="_PhotoNo"></param>
        /// <returns></returns>
        public string GetPhotoImgData(string _PhotoNo)
        {
            string strMiniData = "";

            try
            {
                IPhotoManager manager = new PhotoApp.SQLitBLL.PhotoManager();
                PhotoInfo     _photo  = manager.GetPhotoInfoByNo(_PhotoNo);
                strMiniData = PhotoApp.SQLitBLL.ImgManager.Instance.GetImgData(_photo.PhotoData, false);//获取原图数据
            }
            catch (Exception ex)
            {
            }
            return(strMiniData);
        }
        /// <summary>
        /// 更改相册封面
        /// </summary>
        /// <param name="_albumNo">相册编号</param>
        /// <param name="_photoNo">封面照片编号</param>
        /// <returns></returns>
        public ManagerStateMsg ChangeTitleImg(string _albumNo, string _photoNo)
        {
            ManagerStateMsg msg = new ManagerStateMsg(false, "方法 ChangeTitleImg 执行出现错误!");

            try
            {
                PhotoManager manager = new PhotoManager();
                PhotoInfo    _photo  = manager.GetPhotoInfoByNo(_photoNo);//获取照片信息
                if (_photo != null)
                {
                    string            strUpALLPhotoSQL = "update Photo set IsTitleImg=0 where AlbumNo=@AlbumNo";
                    SQLiteParameter[] photopars        = new SQLiteParameter[1];
                    photopars[0]       = new SQLiteParameter("@AlbumNo", DbType.String);
                    photopars[0].Value = _albumNo;

                    int uprowscount = SQLiteHelper.Instance.ExecuteNonQuery(strUpALLPhotoSQL, photopars);
                    photopars = null;
                    if (uprowscount > 0)
                    {
                        string            strQuerystr = "update Album set AlbumTitleImg=@AlbumTitleImg where AlbumNo=@AlbumNo;update Photo set IsTitleImg=1 where PhotoNO=@photoNO";
                        SQLiteParameter[] pars        = new SQLiteParameter[3];
                        pars[0]       = new SQLiteParameter("@AlbumTitleImg", DbType.String);
                        pars[0].Value = _photo.PhotoMiniData;
                        pars[1]       = new SQLiteParameter("@AlbumNo", DbType.String);
                        pars[1].Value = _albumNo;
                        pars[2]       = new SQLiteParameter("@PhotoNO", DbType.String);
                        pars[2].Value = _photoNo;
                        uprowscount   = SQLiteHelper.Instance.ExecuteNonQuery(strQuerystr, pars);
                        pars          = null;
                        if (uprowscount > 0)
                        {
                            msg.Statevalue = true;
                            msg.MsgInfo    = "更新成功!";
                        }
                        else
                        {
                            msg.MsgInfo = "更新失败!";
                        }
                    }
                    else
                    {
                        msg.MsgInfo = "恢复所有照片的首页状态失败!";
                    }
                }
                else
                {
                    msg.MsgInfo = "未找到符合条件的照片信息!";
                }


                msg.Statevalue = true;
                if (msg.Statevalue)
                {
                }
                else
                {
                    msg.MsgInfo = "未找到符合条件的相册!";
                }
            }
            catch (Exception ex)
            {
                msg.MsgInfo = ex.Message;
            }

            return(msg);
        }
        /// <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
            }
        }
        /// <summary>
        /// 更改相册封面
        /// </summary>
        /// <param name="_albumNo">相册编号</param>
        /// <param name="_photoNo">封面照片编号</param>
        /// <returns></returns>
        public ManagerStateMsg ChangeTitleImg(string _albumNo, string _photoNo)
        {
            ManagerStateMsg msg = new ManagerStateMsg(false, "方法 ChangeTitleImg 执行出现错误!");
            try
            {
                PhotoManager manager = new PhotoManager();
                PhotoInfo _photo = manager.GetPhotoInfoByNo(_photoNo);//获取照片信息
                if (_photo!=null)
                {
                    string strUpALLPhotoSQL = "update Photo set IsTitleImg=0 where AlbumNo=@AlbumNo";
                    SQLiteParameter[] photopars = new SQLiteParameter[1];
                    photopars[0] = new SQLiteParameter("@AlbumNo", DbType.String);
                    photopars[0].Value = _albumNo;

                    int uprowscount = SQLiteHelper.Instance.ExecuteNonQuery(strUpALLPhotoSQL, photopars);
                    photopars = null;
                    if (uprowscount > 0)
                    {
                        string strQuerystr = "update Album set AlbumTitleImg=@AlbumTitleImg where AlbumNo=@AlbumNo;update Photo set IsTitleImg=1 where PhotoNO=@photoNO";
                        SQLiteParameter[] pars = new SQLiteParameter[3];
                        pars[0] = new SQLiteParameter("@AlbumTitleImg", DbType.String);
                        pars[0].Value = _photo.PhotoMiniData;
                        pars[1] = new SQLiteParameter("@AlbumNo", DbType.String);
                        pars[1].Value = _albumNo;
                        pars[2] = new SQLiteParameter("@PhotoNO", DbType.String);
                        pars[2].Value = _photoNo;
                        uprowscount = SQLiteHelper.Instance.ExecuteNonQuery(strQuerystr, pars);
                        pars = null;
                        if (uprowscount > 0)
                        {
                            msg.Statevalue = true;
                            msg.MsgInfo = "更新成功!";
                        }
                        else
                        {
                            msg.MsgInfo = "更新失败!";
                        }
                    }
                    else
                    {
                        msg.MsgInfo = "恢复所有照片的首页状态失败!";
                    }

                }
                else
                {
                    msg.MsgInfo = "未找到符合条件的照片信息!";
                }

                msg.Statevalue = true;
                if (msg.Statevalue)
                {
                }
                else
                {
                    msg.MsgInfo = "未找到符合条件的相册!";
                }
            }
            catch (Exception ex)
            {
                msg.MsgInfo = ex.Message;
            }

            return msg;
        }