/// <summary> /// 编辑照片信息 /// </summary> /// <param name="_AlbumNo"></param> /// <param name="_photoinfo"></param> /// <returns></returns> public Model.ManagerStateMsg EditPhoto(string _AlbumNo, Model.PhotoInfo _photoinfo) { Model.ManagerStateMsg msg = new Model.ManagerStateMsg(false, "方法 EditPhoto 执行出现错误!"); IObjectContainer db = DataHelper.Instance.GetDbObj(typeof(RootAlbum)); try { IObjectSet _result = db.Query(typeof(RootAlbum)); RootAlbum root = (RootAlbum)_result.Next(); if (root.SubAlbums != null && root.SubAlbums.Count > 0) { foreach (Album _abm in root.SubAlbums) { if (_abm.AlbumNO == _AlbumNo) { int Imgindex = GetPhotoIndex(_abm.SubPhotos, _photoinfo.PhotoName);//返回照片索引 if (Imgindex > -1) { _abm.SubPhotos[Imgindex].PhotoName = _photoinfo.PhotoName; _abm.SubPhotos[Imgindex].PhotoRemark = _photoinfo.PhotoRemark; _abm.UpdateDate = DateTime.Now; msg.Statevalue = true; msg.MsgInfo = "编辑信息保存 成功!"; } else { msg.Statevalue = false; msg.MsgInfo = "未找到符合条件的照片!"; } break; } } if (msg.Statevalue) { db.Store(root);//保存 db.Commit(); } } else { msg.Statevalue = false; msg.MsgInfo = "不存在任何相册!"; } } catch (Exception ex) { msg.Statevalue = false; msg.MsgInfo = ex.Message; } finally { db.Close(); } return(msg); }
/// <summary> /// 添加照片 /// </summary> /// <param name="_AlbumNo">照片编号</param> /// <param name="_photoinfo">照片信息</param> /// <returns></returns> public Model.ManagerStateMsg AddPhoto(string _AlbumNo, Model.PhotoInfo _photoinfo) { Model.ManagerStateMsg msg = new Model.ManagerStateMsg(false, "方法 AddPhoto 执行出现错误!"); IObjectContainer db = DataHelper.Instance.GetDbObj(typeof(RootAlbum)); try { IObjectSet _result = db.Query(typeof(RootAlbum)); RootAlbum root = (RootAlbum)_result.Next(); if (root.SubAlbums != null && root.SubAlbums.Count > 0) { foreach (Album _abm in root.SubAlbums) { if (_abm.AlbumNO == _AlbumNo) { if (_abm.SubPhotos == null) { _abm.SubPhotos = new List <PhotoInfo>(); } if (_abm.SubPhotos.Count == 0) { _abm.AlbumTitleImg = _photoinfo.PhotoMiniData; _photoinfo.IsTitleImg = true; } _abm.SubPhotos.Add(_photoinfo); break; } } db.Store(root); db.Commit(); msg.ReturnValue = _photoinfo; msg.Statevalue = true; msg.MsgInfo = "保存成功"; } else { msg.Statevalue = false; msg.MsgInfo = "不存在任何相册!"; } } catch (Exception ex) { msg.Statevalue = false; msg.MsgInfo = ex.Message; } finally { db.Close(); } return(msg); }
/// <summary> /// 编辑照片信息 /// </summary> /// <param name="_AlbumNo"></param> /// <param name="_photoinfo"></param> /// <returns></returns> public Model.ManagerStateMsg EditPhoto(string _AlbumNo, Model.PhotoInfo _photoinfo) { Model.ManagerStateMsg msg = new Model.ManagerStateMsg(false, "方法 EditPhoto 执行出现错误!"); try { SQLiteParameter[] pars = null; pars = new SQLiteParameter[4]; pars[0] = new SQLiteParameter("@PhotoName", DbType.String); pars[0].Value = _photoinfo.PhotoName; pars[1] = new SQLiteParameter("@PhotoRemark", DbType.String); pars[1].Value = _photoinfo.PhotoRemark; pars[2] = new SQLiteParameter("@PhotoUpdateDate", DbType.String); pars[2].Value = _photoinfo.PhotoUpdateDate; pars[3] = new SQLiteParameter("@PhotoNO", DbType.String); pars[3].Value = _photoinfo.PhotoNO; string strQuerySQL = "update Photo set PhotoName=@PhotoName,PhotoRemark=@PhotoRemark,PhotoUpdateDate=@PhotoUpdateDate where PhotoNO=@PhotoNO"; int _upRowscount = SQLiteHelper.Instance.ExecuteNonQuery(strQuerySQL, pars); if (_upRowscount > 0) { msg.MsgInfo = "编辑信息保存成功!"; msg.Statevalue = true; } else { msg.MsgInfo = "更新照片信息失败!"; } } catch (Exception ex) { msg.Statevalue = false; msg.MsgInfo = ex.Message; } return(msg); }
/// <summary> /// 添加照片 /// </summary> /// <param name="_AlbumNo">照片编号</param> /// <param name="_photoinfo">照片信息</param> /// <returns></returns> public Model.ManagerStateMsg AddPhoto(string _AlbumNo, Model.PhotoInfo _photoinfo) { Model.ManagerStateMsg msg = new Model.ManagerStateMsg(false, "方法 AddPhoto 执行出现错误!"); try { SQLiteParameter[] Ablumpars = new SQLiteParameter[1]; Ablumpars[0] = new SQLiteParameter("@AlbumNo", DbType.String); Ablumpars[0].Value = _photoinfo.PhotoNO; string strAblumTols = "select count(PhotoNO) as 'PhotoTols' from Photo where AlbumNo=@AlbumNo group by AlbumNo"; DataTable dt = SQLiteHelper.Instance.ExecuteDataTable(strAblumTols, Ablumpars); int AblumPhotosCount = 0; if (dt != null && dt.Rows.Count > 0) { AblumPhotosCount = Convert.ToInt32(dt.Rows[0]["PhotoTols"]); } SQLiteParameter[] pars = new SQLiteParameter[9]; pars[0] = new SQLiteParameter("@PhotoNO", DbType.String); pars[0].Value = _photoinfo.PhotoNO; pars[1] = new SQLiteParameter("@AlbumNo", DbType.String); pars[1].Value = _AlbumNo; pars[2] = new SQLiteParameter("@PhotoName", DbType.String); pars[2].Value = _photoinfo.PhotoName; pars[3] = new SQLiteParameter("@PhotoRemark", DbType.String); pars[3].Value = _photoinfo.PhotoRemark; pars[4] = new SQLiteParameter("@IsTitleImg", DbType.Int32); if (AblumPhotosCount != 0) { pars[4].Value = 0; } else { pars[4].Value = 1; } pars[5] = new SQLiteParameter("@PhotoData", DbType.String); pars[5].Value = _photoinfo.PhotoData; pars[6] = new SQLiteParameter("@PhotoMiniData", DbType.String); pars[6].Value = _photoinfo.PhotoMiniData; pars[7] = new SQLiteParameter("@PhotoCreateDate", DbType.String); pars[7].Value = _photoinfo.PhotoCreateDate; pars[8] = new SQLiteParameter("@PhotoUpdateDate", DbType.String); pars[8].Value = _photoinfo.PhotoUpdateDate; string strSQL = @"insert into Photo (PhotoNO,AlbumNo,PhotoName,PhotoRemark,IsTitleImg,PhotoData,PhotoMiniData,PhotoCreateDate,PhotoUpdateDate) values (@PhotoNO,@AlbumNo,@PhotoName,@PhotoRemark,@IsTitleImg,@PhotoData,@PhotoMiniData,@PhotoCreateDate,@PhotoUpdateDate)"; int _uprows = SQLiteHelper.Instance.ExecuteNonQuery(strSQL, pars); if (_uprows > 0) { if (AblumPhotosCount == 0) { AlbumManager manager = new AlbumManager(); manager.ChangeTitleImg(_AlbumNo, _photoinfo.PhotoNO); } msg.ReturnValue = _photoinfo; msg.Statevalue = true; msg.MsgInfo = "保存成功"; } else { msg.MsgInfo = "写入数据库失败!"; } msg.ReturnValue = _photoinfo; msg.Statevalue = true; msg.MsgInfo = "保存成功"; } catch (Exception ex) { msg.Statevalue = false; msg.MsgInfo = ex.Message; } return(msg); }