/// <summary> /// Go through every Product Picture for product with id=productId /// If does not exist we add it otherwise we save the PP Id /// </summary> /// <param name="image"></param> /// <param name="productId"></param> /// <param name="found"></param> /// <param name="pps"></param> /// <param name="ppsIds"></param> private void SyncPic(string image, JArray pictureLinks, int productId = 0) { if (String.IsNullOrWhiteSpace(image)) { return; } JObject json = new JObject(); try { Model.Picture pm = GetPicBase64(image); if (pm != null) { json = ParserJSon.GetPictureJson(pm.Base64, pm.ImageType, pm.Name); string result = WebService.Post(ENTITY, json); JObject newPicture = JObject.Parse(result); int picId = (int)newPicture["Id"]; JObject jsonResult = ParserJSon.getProductPictureJson(picId, productId); pictureLinks.Add(jsonResult); } return; } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Error parsing picture:" + json.ToString()); Program.log("Error parsing picture:" + json.ToString()); return; } }
/// <summary> /// 获得图片:图片ID /// </summary> /// <param name="id"></param> /// <returns></returns> public Model.Picture GetPictureByP_ID(int id) { string text = "select * from picture where p_id=:id"; Model.Picture p = new Model.Picture(); OracleParameter[] pars = new OracleParameter[] { new OracleParameter("id", id) }; OracleDataReader odr = OracleHelper.QueryMore(text, pars); if (odr.HasRows) { while (odr.Read()) { p.p_id = int.Parse(odr["P_ID"].ToString()); p.p_Name = odr["P_NAME"].ToString(); p.p_Description = odr["P_DESCRIPTION"].ToString(); p.p_Address = odr["p_address"].ToString(); p.u_id = int.Parse(odr["u_id"].ToString()); p.u_date = odr["u_date"].ToString(); } } odr.Close(); return(p); }
public void PlayPicture(Model.Picture media) { MediaElement.Stop(); MediaElement.Hide(); Image.Display(media.Path); Image.Show(); IsPlayingMedia = false; }
/// <summary> /// 添加图片 /// </summary> /// <param name="p"></param> /// <returns></returns> public int AddPicture(Model.Picture p) { string text = "insert into picture(P_NAME,P_DESCRIPTION,P_ADDRESS) values(:name,:description,:address)"; OracleParameter[] pars = new OracleParameter[3] { new OracleParameter("name", p.p_Name), new OracleParameter("description", p.p_Description), new OracleParameter("address", p.p_Address) }; return(OracleHelper.ExecuteNonQuery(text, pars)); }
public System.Collections.ObjectModel.ObservableCollection <Model.Playlist> GetPlaylists() { System.Collections.ObjectModel.ObservableCollection <Model.Playlist> playlistsCollection = new System.Collections.ObjectModel.ObservableCollection <Model.Playlist>(); try { IEnumerable <System.Xml.Linq.XElement> playlists = xelement.Elements("Playlist"); foreach (var playlist in playlists) { System.Collections.ObjectModel.ObservableCollection <Model.Media> medias = new System.Collections.ObjectModel.ObservableCollection <Model.Media>(); IEnumerable <System.Xml.Linq.XElement> elements = playlist.Elements("Element"); foreach (var elem in elements) { if (elem != null && elem.Element("Path") != null && elem.Element("Stream") != null && elem.Element("Type") != null) { Model.Media media = null; switch ((Model.Media.MediaType)Enum.Parse(typeof(Model.Media.MediaType), elem.Element("Type").Value)) { case Model.Media.MediaType.MUSIC: media = new Model.Music(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value)); break; case Model.Media.MediaType.PICTURE: media = new Model.Picture(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value)); break; case Model.Media.MediaType.VIDEO: media = new Model.Video(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value)); break; } if (media != null) { medias.Add(media); } } } playlistsCollection.Add(new Model.Playlist() { Name = playlist.Attribute("name").Value, Medias = medias }); } } catch { Console.WriteLine("FAILED GetPlaylists catch"); } return(playlistsCollection); }
public System.Collections.ObjectModel.ObservableCollection<Model.Playlist> GetPlaylists() { System.Collections.ObjectModel.ObservableCollection<Model.Playlist> playlistsCollection = new System.Collections.ObjectModel.ObservableCollection<Model.Playlist>(); try { IEnumerable<System.Xml.Linq.XElement> playlists = xelement.Elements("Playlist"); foreach (var playlist in playlists) { System.Collections.ObjectModel.ObservableCollection<Model.Media> medias = new System.Collections.ObjectModel.ObservableCollection<Model.Media>(); IEnumerable<System.Xml.Linq.XElement> elements = playlist.Elements("Element"); foreach (var elem in elements) { if ( elem != null && elem.Element("Path") != null && elem.Element("Stream") != null && elem.Element("Type") != null) { Model.Media media = null; switch ((Model.Media.MediaType)Enum.Parse(typeof(Model.Media.MediaType), elem.Element("Type").Value)) { case Model.Media.MediaType.MUSIC: media = new Model.Music(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value)); break; case Model.Media.MediaType.PICTURE: media = new Model.Picture(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value)); break; case Model.Media.MediaType.VIDEO: media = new Model.Video(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value)); break; } if (media != null) medias.Add(media); } } playlistsCollection.Add(new Model.Playlist() { Name = playlist.Attribute("name").Value, Medias = medias }); } } catch { Console.WriteLine("FAILED GetPlaylists catch"); } return playlistsCollection; }
public void LoadData() { Pictures = new System.Collections.ObjectModel.ObservableCollection <Model.Picture>(); PicturesTmp = new System.Collections.ObjectModel.ObservableCollection <Model.Picture>(); XML.MediaXML mediaXML = new XML.MediaXML(); mediaXML.Load("pictures.xml"); List <Tuple <String, Boolean> > medias = mediaXML.GetMedias(); foreach (var media in medias) { Model.Picture pics_1 = new Model.Picture(media.Item1, media.Item2); Model.Picture pics_2 = new Model.Picture(media.Item1, media.Item2); PicturesTmp.Add(pics_1); Pictures.Add(pics_2); } }
public void AddPicture(Model.Picture picture) { XML.MediaXML mediaXML = new XML.MediaXML(); mediaXML.Load("pictures.xml"); if (!mediaXML.HasMedia(picture.Path)) { mediaXML.Add(picture.Path, picture.Stream); mediaXML.WriteInFile("pictures.xml"); if (picture.Name.Contains(this._SearchInput)) { Pictures.Add(picture); } PicturesTmp.Add(picture); } }
public void RemovePicture(Model.Picture picture) { XML.MediaXML mediaXML = new XML.MediaXML(); mediaXML.Load("pictures.xml"); mediaXML.Remove(picture.Path); mediaXML.WriteInFile("pictures.xml"); String namePathFile = picture.Path; Pictures.Remove(picture); var medias = from media in PicturesTmp where media.Path.Contains(namePathFile) select media; var selected = picture; foreach (var media in medias) { selected = media; } PicturesTmp.Remove(selected); }
protected void imgbtnUpdateHeadPic_Click(object sender, ImageClickEventArgs e) { if (Request.Files.Count > 0) { HttpPostedFile picFile = Request.Files[0]; Model.Picture pic = BLL.PictureBll.GetUserHeadByPicNum((Session["LoginUser"] as Model.User).UserNum); pic.PicturesPath = "Image/UserPic/" + DateTime.Now.ToFileTime() + picFile.FileName.Substring(picFile.FileName.LastIndexOf(".")); if (BLL.PictureBll.UpdateHeadPic(pic) > 0) { Response.Write("<script>alert('修改成功!')</script>"); picFile.SaveAs(Server.MapPath(pic.PicturesPath)); imgLoginUserHead.ImageUrl = pic.PicturesPath; } else { Response.Write("<script>alert('修改失败,数据库操作错误,请联系管理员!')</script>"); } } }
public void LoadDynamicInfo() { if (Request.QueryString["DynamicID"] == null) { return; } Model.Dynamic dynamic = BLL.DynamicBll.GetDynamicByID(Request.QueryString["DynamicID"] as string); if (dynamic == null) { return; } Model.User user = BLL.UserBll.GetUserByUserNum(dynamic.UserNum); if (Session["LoginUser"] != null && BLL.FollowBll.CheckIsFollow((Session["LoginUser"] as Model.User).UserNum, dynamic.UserNum)) { btnFollow.Text = "已关注"; } if (Session["LoginUser"] != null && BLL.CollectionBll.CheckIsCollect((Session["LoginUser"] as Model.User).UserNum, dynamic.DynamicID)) { btnCollect.Text = "已收藏"; } if (Session["LoginUser"] != null && (Session["LoginUser"] as Model.User).UserNum == user.UserNum) { btnFollow.Visible = false; } Model.Picture userPic = BLL.PictureBll.GetUserHeadByPicNum(user.UserNum); List <Model.Picture> dynamicPic = BLL.PictureBll.GetPictureByDynamicID(dynamic.DynamicID); lblPublisherName.Text = user.UserName; imgPublishUserHead.ImageUrl = BLL.PictureBll.GetUserHeadByPicNum(user.UserNum).PicturesPath; lblUserRemark.Text = user.Remark; lblPublishDate.Text = dynamic.PublishDate.ToString(); lblDynamicTitle.Text = dynamic.DynamicTitle; lblDynamicContent.Text = " " + dynamic.DynamicContent; foreach (Model.Picture item in dynamicPic) { item.PicturesPath = "Image/UploadImg/watermark/" + item.PicturesPath; } dgPics.DataSource = dynamicPic; dgPics.DataBind(); BLL.DynamicBll.UpdateReadCount(dynamic); }
private Model.Picture FillPictureInfo(Model.Picture picture) { //查询图片的所有原始图和预览图 DataTable images = DB.Client.ExecuteDataTable("SELECT src.picPreview,src.picUrl FROM PictureSource src WHERE src.picId = @pid" , new SqlParameter("@pid", picture.PicId)); foreach (DataRow item in images.Rows) { picture.Images.Add(new PictureImage(item)); } //查询图片的标签 DataTable tags = DB.Client.ExecuteDataTable("SELECT tag.tagId,tag.tagName FROM PictureTag tag WHERE tag.tagId IN(SELECT map.tagId FROM PictureTagMap map WHERE map.picId = @pid)" , new SqlParameter("@pid", picture.PicId)); foreach (DataRow item in tags.Rows) { picture.Tags.Add(new Model.Tag(item)); } return(picture); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string fastName = context.Request.Form["txtFastName"].ToString(); BLL.PictureService pictureService = new BLL.PictureService(); Model.Picture picture = pictureService.readSingle(fastName); if (picture != null) { MemoryStream ms = new MemoryStream(picture.PictureBinary); // Image readResult = Image.FromStream(ms); string dir = "/Image/"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string filename = Path.GetFileName(picture.FastDfsFileName); string fullName = dir + filename; using (Image img = Image.FromStream(ms)) { using (Bitmap map = new Bitmap(img.Width, img.Height)) { using (Graphics g = Graphics.FromImage(map)) { g.DrawImage(img, 0, 0, img.Width, img.Height); map.Save(context.Request.MapPath(fullName)); } } } context.Response.Write("<html><body><img src='" + fullName + "'/></body></html>"); } else { context.Response.Write("未能正常读取图片。"); } }
public List <Model.Picture> GetPicture() { string text = "select * from picture "; List <Model.Picture> list = new List <Model.Picture>(); OracleDataReader odr = OracleHelper.QueryMore(text, null); if (odr.HasRows) { while (odr.Read()) { Model.Picture p = new Model.Picture(); p.p_id = int.Parse(odr["P_ID"].ToString()); p.p_Name = odr["P_NAME"].ToString(); p.p_Description = odr["P_DESCRIPTION"].ToString(); p.p_Address = odr["p_address"].ToString(); p.u_id = int.Parse(odr["u_id"].ToString()); p.u_date = odr["u_date"].ToString(); list.Add(p); } } odr.Close(); return(list); }
protected void btnAddNewDynamic_Click1(object sender, EventArgs e) { if (lblGG.Text == "选择话题") { Response.Write("<script>alert('请选择话题!')</script>"); return; } if (string.IsNullOrEmpty(textDynamicTitle.Text)) { Response.Write("<script>alert('请输入帖子标题!')</script>"); textDynamicTitle.Focus(); return; } if (string.IsNullOrEmpty(textDynamicContent.Text)) { Response.Write("<script>alert('请输入帖子内容!')</script>"); textDynamicContent.Focus(); return; } else if (textDynamicContent.Text.Length <= 6) { Response.Write("<script>alert('帖子内容不能少于6位!')</script>"); textDynamicContent.Focus(); return; } string code = textVerCode.Text; HttpCookie htco = Request.Cookies["ImageV"]; string scode = htco.Value.ToString(); if (string.IsNullOrEmpty(code) || textVerCode.Text.Length < 4 || code.ToLower() != scode.ToLower()) { Response.Write("<script>alert('验证码输入不正确!')</script>"); textVerCode.Text = ""; textVerCode.Focus(); return; } Model.Dynamic dynamic = new Model.Dynamic(); dynamic.DynamicID = "dynamic" + DateTime.Now.ToFileTime(); dynamic.DynamicTitle = textDynamicTitle.Text; dynamic.DynamicContent = textDynamicContent.Text; dynamic.PublishDate = DateTime.Now; dynamic.SectionID = BLL.SectionBll.GetSectionByName(lblGG.Text).SectionID; dynamic.UserNum = (Session["LoginUser"] as Model.User).UserNum; List <Model.Picture> picList = new List <Model.Picture>(); List <HttpPostedFile> fileList = Session["DynamicPicFiles"] as List <HttpPostedFile>; if (Session["DynamicPicFiles"] != null) { foreach (HttpPostedFile item in fileList) { Model.Picture pic = new Model.Picture(); pic.PictureNum = dynamic.DynamicID; pic.PicturesPath = DateTime.Now.ToFileTime() + item.FileName.Substring(item.FileName.LastIndexOf(".")); picList.Add(pic); } } if (BLL.DynamicBll.InsertDynamicAndPic(dynamic, picList) > 0) { Response.Write("<script>alert('发表成功!')</script>"); for (int i = 0; i < fileList.Count; i++) { fileList[i].SaveAs(Server.MapPath("Image/UploadImg/") + picList[i].PicturesPath); System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("Image/UploadImg/") + picList[i].PicturesPath); Graphics g = Graphics.FromImage(img); SolidBrush brush = new SolidBrush(Color.Blue); g.DrawString("@" + (Session["LoginUser"] as Model.User).UserName, new Font("宋体", 13f), brush, 0, 0); img.Save(Server.MapPath("Image/UploadImg/watermark/") + picList[i].PicturesPath); g.Dispose(); img.Dispose(); File.Delete(Server.MapPath("Image/UploadImg/") + picList[i].PicturesPath); } Session["DynamicPicFiles"] = null; } else { Response.Write("<script>alert('发表失败,数据操作错误,请联系管理员!')</script>"); } }
public void LoadData() { Pictures = new System.Collections.ObjectModel.ObservableCollection<Model.Picture>(); PicturesTmp = new System.Collections.ObjectModel.ObservableCollection<Model.Picture>(); XML.MediaXML mediaXML = new XML.MediaXML(); mediaXML.Load("pictures.xml"); List<Tuple<String, Boolean>> medias = mediaXML.GetMedias(); foreach (var media in medias) { Model.Picture pics_1 = new Model.Picture(media.Item1, media.Item2); Model.Picture pics_2 = new Model.Picture(media.Item1, media.Item2); PicturesTmp.Add(pics_1); Pictures.Add(pics_2); } }
public static int UpdateHeadPic(Model.Picture pic) { return(DAL.DBHelper.DataUpdateMethod <Model.Picture>(pic)); }
public void ProcessRequest(HttpContext context) { Dictionary <SqlConnection, SqlTransaction> MyDict = new Dictionary <SqlConnection, SqlTransaction>(); try { context.Response.ContentType = "text/plain"; //获取要删除的表的id int id = Convert.ToInt32(context.Request["Id"]); BLL.FarmlandMeg newFarmlandMegBll = new BLL.FarmlandMeg(); //删除操作 bool resultFarmlandMeg = newFarmlandMegBll.Delete(id, MyDict); BLL.SoilNutrientMeg newSoilNutrientMegBll = new BLL.SoilNutrientMeg(); List <Model.SoilNutrientMeg> newSoilNutrientMegModelList = newSoilNutrientMegBll.GetModelList(" All_id = " + id); bool resultSoilNutrientMeg = newSoilNutrientMegBll.Delete(newSoilNutrientMegModelList[0].Id, MyDict); BLL.CropsMeg newCropsMegBll = new BLL.CropsMeg(); List <Model.CropsMeg> newCropsMegModelList = newCropsMegBll.GetModelList(" All_id = " + id); bool resultCropsMeg = newCropsMegBll.Delete(newCropsMegModelList[0].Id, MyDict); BLL.FarmlandMSug newFarmlandMSugBll = new BLL.FarmlandMSug(); List <Model.FarmlandMSug> newFarmlandMSugModelList = newFarmlandMSugBll.GetModelList(" All_id = " + id); bool resultFarmlandMSug = newFarmlandMSugBll.Delete(newFarmlandMSugModelList[0].Id, MyDict); BLL.Picture newPictureBll = new BLL.Picture(); List <Model.Picture> newPictureModelList = newPictureBll.GetModelList(" All_id = " + id); List <bool> resultPictureList = new List <bool>(); //判断是否存在图片 if (newPictureModelList.Count > 0) { //用于存储图片绝对路径的集合 List <String> filesPath = new List <string>(); //如果存在将其删除 foreach (Model.Picture Pic in newPictureModelList) { Model.Picture newPictureModel = newPictureBll.GetModel(Pic.Id); //图片相对路径 string picPath = newPictureModel.picturePath; //图片绝对路径 string absolutePath = context.Request.MapPath(picPath); //将绝对路径添加到集合中 filesPath.Add(absolutePath); //将删除结果累计添加到集合中 resultPictureList.Add(newPictureBll.Delete(Pic.Id, MyDict)); } //删除图片操作 foreach (String path in filesPath) { if (File.Exists(path)) { //如果文件存在,则删除 File.Delete(path); } } } if (resultFarmlandMeg && resultSoilNutrientMeg && resultFarmlandMSug && resultCropsMeg && !resultPictureList.Contains(false)) { context.Response.Write("ok"); } else { context.Response.Write("删除失败"); } QuitConnTrans(MyDict); } catch (Exception E) { ExceptionQuitConnTrans(MyDict); //如有异常 将异常信息返回 context.Response.Write(E.Message); //将信息返回给客户端,停止该页的执行 context.Response.End(); } }